<commit_before>﻿using Appccelerate.EventBroker;
using Ninject;
using Redmine.Net.Api;
using Redmine.Net.Api.Types;
using RedmineLog.Common;
using RedmineLog.Logic.Common;
using System;
using System.Collections.Specialized;
using System.Linq;

namespace RedmineLog.Logic
{
    internal class SettingFormLogic : ILogic<Settings.IView>
    {
        private IDbConfig dbConfig;
        private IDbRedmine dbRedmine;
        private IDbCache dbCache;
        private Settings.IModel model;
        private IRedmineClient redmine;
        private Settings.IView View;

        [Inject]
        public SettingFormLogic(Settings.IView inView, Settings.IModel inModel, IEventBroker inEvents, IRedmineClient inClient, IDbRedmine inDbRedmine, IDbConfig inDbConfig, IDbCache inDbCache)
        {
            View = inView;
            model = inModel;
            redmine = inClient;
            dbRedmine = inDbRedmine;
            dbConfig = inDbConfig;
            dbCache = inDbCache;
            inEvents.Register(this);
        }

        [EventSubscription(Settings.Events.Connect, typeof(Subscribe<Settings.IView>))]
        public void OnConnectEvent(object sender, EventArgs arg)
        {
            dbRedmine.SetApiKey(model.ApiKey);
            dbRedmine.SetUrl(model.Url);
            dbConfig.SetIdUser(redmine.GetCurrentUser());
        }

        [EventSubscription(Settings.Events.Load, typeof(Subscribe<Settings.IView>))]
        public void OnLoadEvent(object sender, EventArgs arg)
        {
            model.ApiKey = dbRedmine.GetApiKey();
            model.Url = dbRedmine.GetUrl();

            model.Sync.Value(SyncTarget.View, "ApiKey");
            model.Sync.Value(SyncTarget.View, "Url");
        }

        [EventSubscription(Settings.Events.ReloadCache, typeof(Subscribe<Settings.IView>))]
        public void OnReloadCacheEvent(object sender, EventArgs arg)
        {
            dbCache.InitWorkActivities(redmine.GetWorkActivityTypes());

            var users = redmine.GetUsers().ToList();
            int myId = redmine.GetCurrentUser();
            var user = users.Where(x => x.Id == myId).First();
            user.IsDefault = true;
            dbCache.InitUsers(users);

            var trackers = redmine.GetTrackers();

            trackers = trackers.Where(x => x.Name.ToLower().StartsWith("zadanie")
                                            || x.Name.ToLower().Contains("błąd")).ToList();

            trackers.Where(x => x.Name.ToLower().Contains("dev")).First().IsDefault = true;

            dbCache.InitTrackers(trackers);
            dbCache.InitPriorities(redmine.GetPriorites());
        }
    }
}<commit_msg>fix error<commit_after>﻿using Appccelerate.EventBroker;
using Ninject;
using Redmine.Net.Api;
using Redmine.Net.Api.Types;
using RedmineLog.Common;
using RedmineLog.Logic.Common;
using System;
using System.Collections.Specialized;
using System.Linq;

namespace RedmineLog.Logic
{
    internal class SettingFormLogic : ILogic<Settings.IView>
    {
        private IDbConfig dbConfig;
        private IDbRedmine dbRedmine;
        private IDbCache dbCache;
        private Settings.IModel model;
        private IRedmineClient redmine;
        private Settings.IView View;

        [Inject]
        public SettingFormLogic(Settings.IView inView, Settings.IModel inModel, IEventBroker inEvents, IRedmineClient inClient, IDbRedmine inDbRedmine, IDbConfig inDbConfig, IDbCache inDbCache)
        {
            View = inView;
            model = inModel;
            redmine = inClient;
            dbRedmine = inDbRedmine;
            dbConfig = inDbConfig;
            dbCache = inDbCache;
            inEvents.Register(this);
        }

        [EventSubscription(Settings.Events.Connect, typeof(Subscribe<Settings.IView>))]
        public void OnConnectEvent(object sender, EventArgs arg)
        {
            dbRedmine.SetApiKey(model.ApiKey);
            dbRedmine.SetUrl(model.Url);
            dbConfig.SetIdUser(redmine.GetCurrentUser());
        }

        [EventSubscription(Settings.Events.Load, typeof(Subscribe<Settings.IView>))]
        public void OnLoadEvent(object sender, EventArgs arg)
        {
            model.ApiKey = dbRedmine.GetApiKey();
            model.Url = dbRedmine.GetUrl();

            model.Sync.Value(SyncTarget.View, "ApiKey");
            model.Sync.Value(SyncTarget.View, "Url");
        }

        [EventSubscription(Settings.Events.ReloadCache, typeof(Subscribe<Settings.IView>))]
        public void OnReloadCacheEvent(object sender, EventArgs arg)
        {
            dbCache.InitWorkActivities(redmine.GetWorkActivityTypes());

            var users = redmine.GetUsers().ToList();
            int myId = redmine.GetCurrentUser();
            var user = users.Where(x => x.Id == myId).First();
            user.IsDefault = true;
            dbCache.InitUsers(users);

            var trackers = redmine.GetTrackers();

            trackers = trackers.Where(x => x.Name.ToLower().StartsWith("zadanie")
                                            || x.Name.ToLower().Contains("błąd")).ToList();

            var tmpItem = trackers.Where(x => x.Name.ToLower().Contains("dev")).FirstOrDefault();

            if (tmpItem != null)
                tmpItem.IsDefault = true;

            dbCache.InitTrackers(trackers);
            dbCache.InitPriorities(redmine.GetPriorites());
        }
    }
}
{'fraction_non_alphanumeric': 0.10356347438752785, 'fraction_numerical': 0.0, 'mean_word_length': 2.3702313946216385, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6975949', 'n_tokens_mistral': 1544, 'n_tokens_neox': 1524, 'n_words': 273}