Beispiel #1
0
        public Logic(ILifetimeScope autofac, IRepository repository, IMonik monik,
                     IMapper mapper, IArchiver archiver, ITelegramBotClient bot, IPackageBuilder builder)
        {
            this.autofac  = autofac;
            this.mapper   = mapper;
            this.monik    = monik;
            this.archiver = archiver;
            this.bot      = bot;
            bot.StartReceiving();
            this.repository = repository;
            packageBuilder  = builder;
            contextsInWork  = new Dictionary <long, IReportTaskRunContext>();

            checkScheduleAndExecuteScheduler =
                new Scheduler {
                Period = 60, TaskMethod = CheckScheduleAndExecute
            };

            tableView = this.autofac.ResolveNamed <IViewExecutor>("CommonTableViewEx");

            operTemplates    = new List <DtoOperTemplate>();
            recepientGroups  = new List <DtoRecepientGroup>();
            telegramChannels = new List <DtoTelegramChannel>();
            schedules        = new List <DtoSchedule>();
            tasks            = new List <IReportTask>();
            operations       = new List <DtoOperation>();

            this.bot.OnUpdate += OnBotUpd;
        } //ctor
Beispiel #2
0
 public TaskWorker(IRepository repository, IMapper mapper,
                   IMonik monik)
 {
     this.repository = repository;
     this.mapper     = mapper;
     this.monik      = monik;
 }
Beispiel #3
0
 // TODO: options - retry logic and immediatly execute at start
 private Scheduler(IMonik monik, Action work, IntervalType interval, string name)
 {
     _monik   = monik;
     _action  = work;
     _name    = name;
     Interval = interval;
 }
Beispiel #4
0
        public ReportTask(ILogic logic, ILifetimeScope autofac, IRepository repository, IMonik monik, int id,
                          string name, string parameters, string dependsOn, DtoSchedule schedule, List <DtoOperation> opers)
        {
            this.monik      = monik;
            this.repository = repository;
            Id         = id;
            Name       = name;
            Schedule   = schedule;
            Operations = new List <IOperation>();

            Parameters = new Dictionary <string, object>();
            if (!string.IsNullOrEmpty(parameters))
            {
                Parameters = JsonConvert
                             .DeserializeObject <Dictionary <string, object> >(parameters);
            }

            DependsOn = new List <TaskDependency>();
            if (!string.IsNullOrEmpty(dependsOn))
            {
                DependsOn = JsonConvert
                            .DeserializeObject <List <TaskDependency> >(dependsOn);
            }

            this.autofac = autofac;

            ParseDtoOperations(logic, opers);
        } //ctor
Beispiel #5
0
        public BoxViewModel(IMonik monik, IMapper mapper)
        {
            this.mon    = monik;
            this.mapper = mapper;

            Columns = new SourceList <ColumnViewModel>();
            Rows    = new SourceList <RowViewModel>();

            Boards = new SourceList <BoardViewModel>();
            Cards  = new SourceList <CardViewModel>();

            Cards
            .Connect()
            .AutoRefresh()
            .Subscribe(x => TotalTickets = Cards.Count);

            Boards
            .Connect()
            .AutoRefresh()
            .Subscribe(bvm =>
            {
                var lst   = Boards.Items.Select(x => x.Name).ToList();
                var str   = string.Join(",", lst);
                BoardList = str;
            });
        }
Beispiel #6
0
        public CacheKeepAlive(IRepository repository, ICacheSourceInstance cache, IMonik monik)
            : base(repository, cache, monik)
        {
            _cache = cache;

            _status = new Dictionary <int, KeepAlive_>();
        }
Beispiel #7
0
        public MessagePump(IMonikServiceSettings settings, ICacheSourceInstance cache, IMessageProcessor processor, IMonik monik)
        {
            _queueReaderSettings = settings.Readers;

            _cache     = cache;
            _processor = processor;
            _monik     = monik;
        }
Beispiel #8
0
        public AppModel(IShell shell, IMapper mp, IMonik m)
        {
            this.shell = shell;
            m.LogicVerbose("AppModel.ctor");

            BoxesCache.Connect()
            .Bind(out _boxes)
            .Subscribe();
        }
Beispiel #9
0
        public Worker(ILogger <Worker> logger, IConfiguration configuration)
        {
            _logger = logger;
            var settings = configuration.GetSection("Monik").Get <MonikSettings>();
            var sender   = CreateSender(settings.SenderType, settings.SenderSettings);

            _monik = new MonikClient(sender, settings.ClientSettings);
            _delay = settings.Delay;
        }
Beispiel #10
0
        public CacheSourceInstance(IRepository repository, IMonik monik)
        {
            _repository = repository;
            _monik      = monik;

            _sources           = new Dictionary <string, Source>();
            _sourceMap         = new Dictionary <short, Source>();
            _instanceMap       = new Dictionary <int, Instance>();
            _sourceInstanceMap = new Dictionary <string, Instance>();
        }
Beispiel #11
0
        public ReportTask(ILogic logic, ILifetimeScope autofac, IRepository repository,
                          IMonik monik, int id,
                          string name, string parameters, DtoSchedule schedule, List <DtoOperation> opers)
        {
            this.monik      = monik;
            this.repository = repository;
            Id         = id;
            Name       = name;
            Schedule   = schedule;
            Operations = new List <IOperation>();

            Parameters = new Dictionary <string, object>();
            if (!string.IsNullOrEmpty(parameters))
            {
                Parameters = JsonConvert
                             .DeserializeObject <Dictionary <string, object> >(parameters);
            }

            foreach (var operation in opers)
            {
                IOperation newOper;

                var operType = operation.ImplementationType;

                if (logic.RegisteredImporters.ContainsKey(operType))
                {
                    newOper = autofac.ResolveNamed <IOperation>(operType,
                                                                new NamedParameter("config",
                                                                                   JsonConvert.DeserializeObject(operation.Config,
                                                                                                                 logic.RegisteredImporters[operType])));
                }

                else
                {
                    newOper = autofac.ResolveNamed <IOperation>(operType,
                                                                new NamedParameter("config",
                                                                                   JsonConvert.DeserializeObject(operation.Config,
                                                                                                                 logic.RegisteredExporters[operType])));
                }

                if (newOper == null)
                {
                    continue;
                }

                newOper.Properties.Id        = operation.Id;
                newOper.Properties.Number    = operation.Number;
                newOper.Properties.Name      = operation.Name;
                newOper.Properties.IsDefault = operation.IsDefault;

                Operations.Add(newOper);
            }

            this.autofac = autofac;
        } //ctor
Beispiel #12
0
        public MetricObject(IMonik monik, IRepository repository, IMessagePump pump)
        {
            _monik      = monik;
            _repository = repository;
            _pump       = pump;

            _dto      = null;
            _measures = null;

            window = null;
        }
        public Worker(IMonik monik, ILogic logic)
        {
            stringVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            Method = logic.CheckScheduleAndExecute;

            this.monik = monik;
            logic.Start();

            monik.ApplicationInfo("Worker.ctor");
            Console.WriteLine("HostHolder.ctor");
        }
Beispiel #14
0
        public HostHolder()
        {
            nancyHost = new NancyHost(
                new Uri("http://localhost:12345"),
                new Bootstrapper(),
                HostConfigs);

            stringVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            monik = Bootstrapper.Global.Resolve <IMonik>();
            monik.ApplicationInfo("HostHolder.ctor");
            Console.WriteLine("HostHolder.ctor");
        }
Beispiel #15
0
        public MessageProcessor(IMonikServiceSettings settings, IRepository repository, 
            ICacheLog cacheLog, ICacheKeepAlive cacheKeepAlive, ICacheMetric cacheMetric,
            IMonik monik)
        {
            _settings = settings;
            _repository = repository;
            _cacheLog = cacheLog;
            _cacheKeepAlive = cacheKeepAlive;
            _cacheMetric = cacheMetric;
            _monik = monik;

            _cleaner = Scheduler.CreatePerHour(_monik, CleanerTask, "cleaner");
            _statist = Scheduler.CreatePerHour(_monik, StatistTask, "statist");
        }
Beispiel #16
0
        private readonly ConcurrentDictionary <IMetricObject, byte> _metrics; // as HashSet, byte value is not used

        public CacheMetric(IRepository repository, ILifetimeScope autofac,
                           ICacheSourceInstance sourceCache, IMonik monik)
        {
            _repository  = repository;
            _autofac     = autofac;
            _sourceCache = sourceCache;
            _monik       = monik;

            _shedulerPerMin = Scheduler.CreatePerMinute(monik,
                                                        this.BackgroundIntervalPush, "CacheMetric.BackgroundIntervalPush");

            _shedulerPerSec = Scheduler.CreatePerSecond(monik,
                                                        this.BackgroundSecondPush, "CacheMetric.BackgroundSecondPush");

            _metrics = new ConcurrentDictionary <IMetricObject, byte>();

            _sourceCache.RemoveMetrics += OnRemoveMetrics;
        }
Beispiel #17
0
        public AppConfig(IMonik m)
        {
            mon = m;

            // C:\Users\myuser\AppData\Roaming (travel with user profile)
            appConfigPath  = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            appConfigPath += @"\Kamban\kamban.config";

            FileInfo file = new FileInfo(appConfigPath);

            file.Directory.Create();

            if (file.Exists)
            {
                string data = File.ReadAllText(appConfigPath);
                appConfig = JsonConvert.DeserializeObject <AppConfigJson>(data);
            }
            else
            {
                appConfig = new AppConfigJson();
            }

            appConfig.StartNumber++;
            SaveConfig();

            recentList = new SourceList <RecentViewModel>();
            recentList.AddRange(appConfig.Feed.Select(x => new RecentViewModel
            {
                Uri = x.Uri, LastAccess = x.LastAccess, Pinned = x.Pinned
            }));

            RecentObservable = recentList.Connect().AutoRefresh();

            publicBoards = new SourceList <PublicBoardJson>();
            publicBoards
            .Connect()
            .Bind(out ReadOnlyObservableCollection <PublicBoardJson> temp)
            .Subscribe();

            PublicBoards = temp;

            GetStarted = this.WhenAnyValue(x => x.GetStartedValue);
            Basement   = this.WhenAnyValue(x => x.BasementValue);
        }
Beispiel #18
0
        protected override void InitializeTarget()
        {
            if (string.IsNullOrEmpty(ConnectionString))
            {
                throw new ArgumentNullException(nameof(ConnectionString));
            }
            if (string.IsNullOrEmpty(QueueName))
            {
                throw new ArgumentNullException(nameof(QueueName));
            }

            var sender   = new RabbitMqSender(ConnectionString, QueueName);
            var settings = new ClientSettings
            {
                SourceName          = Source,
                InstanceName        = Instance,
                AutoKeepAliveEnable = true
            };

            monikClient = new MonikClient(sender, settings);
        }
Beispiel #19
0
 public MonikTraceListener(IMonik monik)
 {
     _monik = monik;
 }
 public TaskWorker(IRepository repository, IMonik monik)
 {
     this.repository = repository;
     this.monik      = monik;
 }
        public PostgreSqlRepository(string connStr, IMonik monik)
        {
            connectionString = connStr;

            this.monik = monik;
        }
        public SqlServerRepository(string connStr, IMonik monik)
        {
            connectionString = connStr;

            this.monik = monik;
        }
Beispiel #23
0
        public AppConfig(IShell sh, IMonik m)
        {
            shell = sh;
            mon   = m;

            appConfigPath = GetRomaingPath("kamban.config");
            FileInfo file = new FileInfo(appConfigPath);

            if (file.Exists)
            {
                string data = File.ReadAllText(appConfigPath);
                appConfig = JsonConvert.DeserializeObject <AppConfigJson>(data);

                if (string.IsNullOrEmpty(appConfig.AppGuid))
                {
                    appConfig.AppGuid = Guid.NewGuid().ToString();
                }
            }
            else
            {
                appConfig         = new AppConfigJson();
                appConfig.AppGuid = Guid.NewGuid().ToString();
            }

            OpenLatestAtStartupValue = appConfig.OpenLatestAtStartup;
            ShowFileNameInTabValue   = appConfig.ShowFileNameInTab;

            appConfig.StartNumber++;
            SaveConfig();

            recentList = new SourceList <RecentViewModel>();
            recentList.AddRange(appConfig.Feed.Select(x => new RecentViewModel
            {
                Uri = x.Uri, LastAccess = x.LastAccess, Pinned = x.Pinned
            }));

            RecentObservable = recentList.Connect().AutoRefresh();

            publicBoards = new SourceList <PublicBoardJson>();
            publicBoards
            .Connect()
            .Bind(out ReadOnlyObservableCollection <PublicBoardJson> temp)
            .Subscribe();

            PublicBoards = temp;

            GetStarted = this.WhenAnyValue(x => x.GetStartedValue);
            Basement   = this.WhenAnyValue(x => x.BasementValue);
            OpenLatestAtStartupObservable = this.WhenAnyValue(x => x.OpenLatestAtStartupValue);
            ShowFileNameInTabObservable   = this.WhenAnyValue(x => x.ShowFileNameInTabValue);

            // Manage current opened boards for raise on next startup

            shell.DockingManager.ActiveContentChanged += (s, e) =>
            {
                var view = shell.DockingManager.ActiveContent as BoardView;
                if (view == null)
                {
                    return;
                }

                var vm = view.ViewModel as BoardEditViewModel;
                if (!appConfig.LatestOpenedAtStartup.Contains(vm.Box.Uri))
                {
                    appConfig.LatestOpenedAtStartup.Add(vm.Box.Uri);
                }
                SaveConfig();
            };

            shell.DockingManager.DocumentClosed += (s, e) =>
            {
                var view = e.Document.Content as BoardView;
                if (view == null)
                {
                    return;
                }

                var vm = view.ViewModel as BoardEditViewModel;
                appConfig.LatestOpenedAtStartup.Remove(vm.Box.Uri);
                SaveConfig();
            };
        }
Beispiel #24
0
        public static Scheduler CreatePerHour(IMonik monik, Action work, string name = "")
        {
            Scheduler result = new Scheduler(monik, work, IntervalType.Hour, name);

            return(result);
        }
        public StartupViewModel(IShell shell, IAppModel appModel, IDialogCoordinator dc,
                                IMapper mp, IAppConfig cfg, IMonik m)
        {
            this.shell    = shell as IShell;
            this.appModel = appModel;
            dialCoord     = dc;
            mapper        = mp;
            appConfig     = cfg;
            mon           = m;

            initialized = false;

            OpenRecentBoxCommand = ReactiveCommand.Create <RecentViewModel>(async(rvm) =>
            {
                if (await OpenBoardView(rvm.Uri))
                {
                    appConfig.UpdateRecent(rvm.Uri, rvm.Pinned);
                }
            });

            NewFileCommand = ReactiveCommand.Create(() =>
                                                    this.shell.ShowView <WizardView>(
                                                        new WizardViewRequest {
                ViewId = "Creating new file", Uri = null
            }));

            OpenFileCommand = ReactiveCommand.CreateFromTask(async _ =>
            {
                var dialog = new OpenFileDialog
                {
                    Filter = @"SQLite DataBase | *.kam",
                    Title  = @"Select exists database"
                };

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    var uri = dialog.FileName;

                    if (await OpenBoardView(uri))
                    {
                        appConfig.UpdateRecent(uri, false);
                    }
                }
            });

            OpenPublicBoardCommand = ReactiveCommand
                                     .CreateFromTask <PublicBoardJson>(OpenPublicBoardCommandExecute);

            ImportCommand = ReactiveCommand.Create(() =>
                                                   this.shell.ShowView <ImportView>(null, new UiShowOptions {
                Title = "Import"
            }));

            var whenBoardSelected = shell
                                    .WhenAny(x => x.SelectedView, x => x.Value?.ViewModel is BoardEditViewModel)
                                    .Publish();

            ExportCommand = ReactiveCommand.Create(() =>
                                                   this.shell.ShowView <ExportView>(null, new UiShowOptions {
                Title = "Export"
            }),
                                                   whenBoardSelected);

            PrintCommand = ReactiveCommand.Create(PrintCommandExecute, whenBoardSelected);

            whenBoardSelected.Connect();

            ShowStartupCommand = ReactiveCommand.Create(() =>
            {
                shell.ShowView <StartupView>(
                    viewRequest: new ViewRequest {
                    ViewId = StartupViewModel.StartupViewId
                },
                    options: new UiShowOptions {
                    Title = "Start Page", CanClose = false
                });
            });

            SettingsCommand = ReactiveCommand.Create(() =>
            {
                shell.ShowView <SettingsView>(
                    viewRequest: new ViewRequest {
                    ViewId = SettingsViewModel.StartupViewId
                },
                    options: new UiShowOptions {
                    Title = "Settings", CanClose = true
                });
            });

            ExitCommand = ReactiveCommand.Create(() => App.Current.Shutdown());

            Pinned = appConfig.RecentObservable
                     .Filter(x => x.Pinned);

            var notPinned = appConfig.RecentObservable
                            .Filter(x => !x.Pinned);

            Today = notPinned
                    .Filter(x => x.LastAccess.IsToday());

            Yesterday = notPinned
                        .Filter(x => x.LastAccess.IsYesterday());

            ThisMonth = notPinned
                        .Filter(x => !x.LastAccess.IsToday() && !x.LastAccess.IsYesterday() && x.LastAccess.IsThisMonth());

            Older = notPinned
                    .Filter(x => !x.LastAccess.IsToday() && !x.LastAccess.IsYesterday() && !x.LastAccess.IsThisMonth());

            // TODO: move autosaver to AppConfig

            appConfig.RecentObservable
            .WhenAnyPropertyChanged("Pinned")
            .Subscribe(x => appConfig.UpdateRecent(x.Uri, x.Pinned));

            appConfig.GetStarted.Subscribe(x => GetStarted = x);

            var ver = Assembly.GetExecutingAssembly().GetName();

            appConfig.Basement
            .Subscribe(x => Basement = x + $"v{ver.Version.Major}.{ver.Version.Minor}.{ver.Version.Build}");

            if (appConfig.OpenLatestAtStartup)
            {
                foreach (var uri in appConfig.LastOpenedAtStartup)
                {
                    Dispatcher.CurrentDispatcher.InvokeAsync(() => OpenBoardView(uri));
                }
            }
        } //ctor
Beispiel #26
0
        public static Scheduler CreatePerSecond(IMonik monik, Action work, string name)
        {
            Scheduler result = new Scheduler(monik, work, IntervalType.Second, name);

            return(result);
        }
Beispiel #27
0
        public SecureNancyModule(ICacheMetric cacheMetric, ICacheSourceInstance sourceInstanceCache, IMonik monik)
        {
            this.RequiresAuthentication();

            Delete("/instances/{id:int}", args =>
            {
                try
                {
                    monik.ApplicationInfo($"Delete /instances/{args.id} by {Context.CurrentUser.Identity.Name}");
                    sourceInstanceCache.RemoveInstance(args.id);
                    return(HttpStatusCode.OK);
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method DELETE /instances/id : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Delete("/metrics/{id:int}", args =>
            {
                try
                {
                    monik.ApplicationInfo($"Delete /metrics/{args.id} by {Context.CurrentUser.Identity.Name}");
                    cacheMetric.RemoveMetric(args.id);
                    return(HttpStatusCode.OK);
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method DELETE /metrics/id : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Delete("/sources/{id:int}", args =>
            {
                try
                {
                    monik.ApplicationInfo($"Delete /sources/{args.id} by {Context.CurrentUser.Identity.Name}");
                    sourceInstanceCache.RemoveSource((short)args.id);
                    return(HttpStatusCode.OK);
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method DELETE /sources/id : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Post("/groups", args =>
            {
                try
                {
                    var group = this.Bind <Group_>();
                    monik.ApplicationInfo($"Post /groups {group.Name} by {Context.CurrentUser.Identity.Name}");
                    var result = sourceInstanceCache.CreateGroup(group);
                    return(Response.AsJson(result, HttpStatusCode.Created)
                           .WithHeader("Location", $"/groups/{result.ID}"));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method POST /groups : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });
            Delete("/groups/{id:int}", args =>
            {
                try
                {
                    monik.ApplicationInfo($"Delete /groups/{args.id} by {Context.CurrentUser.Identity.Name}");
                    var result = sourceInstanceCache.RemoveGroup((short)args.id);
                    return(result ? HttpStatusCode.OK : HttpStatusCode.NotFound);
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method DELETE /groups/id : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });
            Put("/groups/{groupId:int}/instances/{instanceId:int}", args =>
            {
                try
                {
                    monik.ApplicationInfo($"Put /groups/{args.groupId}/instances/{args.instanceId} by {Context.CurrentUser.Identity.Name}");
                    sourceInstanceCache.AddInstanceToGroup(args.instanceId, (short)args.groupId);
                    return(HttpStatusCode.OK);
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method PUT /groups/id/instances/id : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });
            Delete("/groups/{groupId:int}/instances/{instanceId:int}", args =>
            {
                try
                {
                    monik.ApplicationInfo($"Delete /groups/{args.groupId}/instances/{args.instanceId} by {Context.CurrentUser.Identity.Name}");
                    var result = sourceInstanceCache.RemoveInstanceFromGroup(args.instanceId, (short)args.groupId);
                    return(result ? HttpStatusCode.OK : HttpStatusCode.NotFound);
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method DELETE /groups/id/instances/id : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });
        }
Beispiel #28
0
 public override CacheKeepAlive CreateCache(IRepository repository, ICacheSourceInstance cache, IMonik monik)
 {
     return(new CacheKeepAlive(repository, cache, monik));
 }
Beispiel #29
0
 public UserIdentityProvider(IMonikServiceSettings settings, IMonik monik)
 {
     _settings = settings;
     _monik    = monik;
 }
Beispiel #30
0
 public CacheLog(IRepository repository, ICacheSourceInstance cache, IMonik monik)
     : base(repository, cache, monik)
 {
     _logs       = new ConcurrentQueue <Log_>();
     OldestLogId = 0;
 }