Exemplo n.º 1
0
        private async void Consumer(object sender, BasicDeliverEventArgs args)
        {
            var processGuid = Guid.NewGuid();
            var userModel   = JsonConvert.DeserializeObject <UserModel>(Encoding.UTF8.GetString(args.Body));

            try
            {
                await _storageRepository.GetLatestUserData(userModel.Username, processGuid.ToString());

                await _storageRepository.GetLatestUserModel(userModel.Username, processGuid.ToString());

                _scriptRunner.Execute(new FeatureExtractionScript(_options.DataPreprocessingScriptPath,
                                                                  userModel.Username,
                                                                  processGuid.ToString()));
                _scriptRunner.Execute(new PredictionScript(_options.ModelPredictionScriptPath, userModel.Username,
                                                           processGuid.ToString()));

                var matchCoefficient = GetMatchCoefficent($"predictions_{processGuid}_{userModel.Username}");

                if (matchCoefficient < 0.51M)
                {
                    _emailHelper.SendEmail(userModel.Email);
                }
            }
            catch (Exception ex)
            {
                _logger.LogInformation(ex.Message);
            }
            finally
            {
                CleanDirectory(userModel.Username, processGuid.ToString());
            }
        }
Exemplo n.º 2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation(AppDomain.CurrentDomain.BaseDirectory);

            SetWorkingDirectory();

            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);

                try
                {
                    await GetStorageUserData();

                    _scriptRunner.Execute(new FeatureExtractionScript(_options.DataPreprocessingScriptPath));

                    _scriptRunner.Execute(new ModelGenerationScript(_options.ModelGenerationScriptPath));

                    PostUserModels();

                    _logger.LogInformation("Cleaning up at: {time}", DateTimeOffset.Now);
                }
                catch (Exception e)
                {
                    _logger.LogInformation(e.Message);
                }
                finally
                {
                    CleanDirectory();
                }

                await Task.Delay(TimeSpan.FromHours(_options.WorkerRefreshTime), stoppingToken);
            }
        }
Exemplo n.º 3
0
 public MenuViewModel(IEventAggregator eventAggregator, Func <TeapotViewModel> teapotBuilder, IScriptRunner script, ProjectManager manager)//, Func<ProjectExplorerViewModel> projectExplorerViewModelBuilder, Func<EventAggregatorDebugViewModel> eventsDebugBuilder,)
 {
     _eventAggregator = eventAggregator;
     Items            = new BindableCollection <MenuItemViewModel> {
         new MenuItemViewModel {
             Header = "_FILE",
             Items  = new BindableCollection <MenuItemViewModel> {
                 new MenuItemViewModel {
                     Header = "_Open",
                     Items  = new BindableCollection <MenuItemViewModel> {
                         new MenuItemViewModel {
                             Header = "_Project",
                             Action = () => _eventAggregator.Publish(new OpenProjectDialog())
                         },
                         new MenuItemViewModel {
                             Header = "Teapot",
                             Action = () => _eventAggregator.Publish(new AddTabViewCommand {
                                 Model = teapotBuilder()
                             })
                         },
                     }
                 },
                 new MenuItemViewModel {
                     Header = "Close",
                     Action = () => _eventAggregator.Publish(new DebugCommand("close"))
                 }
             }
         },
         new MenuItemViewModel {
             Header = "_EDIT"
         },
         new MenuItemViewModel {
             Header = "_VIEW"
         },
         new MenuItemViewModel {
             Header = "_BUILD",
             Items  = new BindableCollection <MenuItemViewModel> {
                 new MenuItemViewModel {
                     Header = "_Build Project",
                     Action = () => script.Execute(manager.Project)
                 },
                 new MenuItemViewModel {
                     Header = "Teapot",
                     Action = () => _eventAggregator.Publish(new AddTabViewCommand {
                         Model = teapotBuilder()
                     })
                 },
             }
         },
         new MenuItemViewModel {
             Header = "_WINDOW"
         },
         new MenuItemViewModel {
             Header = "_HELP"
         }
     };
 }
Exemplo n.º 4
0
        //, Func<ProjectExplorerViewModel> projectExplorerViewModelBuilder, Func<EventAggregatorDebugViewModel> eventsDebugBuilder,)
        public MenuViewModel(IEventAggregator eventAggregator, Func<TeapotViewModel> teapotBuilder, IScriptRunner script, ProjectManager manager)
        {
            _eventAggregator = eventAggregator;
            Items = new BindableCollection<MenuItemViewModel> {
                new MenuItemViewModel {
                    Header = "_FILE",
                    Items = new BindableCollection<MenuItemViewModel> {
                        new MenuItemViewModel {
                            Header = "_Open",
                            Items = new BindableCollection<MenuItemViewModel> {
                                new MenuItemViewModel {
                                    Header = "_Project",
                                    Action = () => _eventAggregator.Publish(new OpenProjectDialog())
                                },
                                new MenuItemViewModel {
                                    Header = "Teapot",
                                    Action = () => _eventAggregator.Publish(new AddTabViewCommand {Model = teapotBuilder()})
                                },

                            }
                        },
                        new MenuItemViewModel {
                            Header = "Close",
                            Action = () => _eventAggregator.Publish(new DebugCommand("close"))
                        }
                    }
                },
                new MenuItemViewModel {
                    Header = "_EDIT"
                },
                new MenuItemViewModel {
                    Header = "_VIEW"
                },
                new MenuItemViewModel {
                    Header = "_BUILD",
                    Items = new BindableCollection<MenuItemViewModel> {
                        new MenuItemViewModel {
                            Header = "_Build Project",
                            Action = () => script.Execute(manager.Project)
                        },
                        new MenuItemViewModel {
                            Header = "Teapot",
                            Action = () => _eventAggregator.Publish(new AddTabViewCommand {Model = teapotBuilder()})
                        },

                    }
                },
                new MenuItemViewModel {
                    Header = "_WINDOW"
                },
                new MenuItemViewModel {
                    Header = "_HELP"
                }
            };
        }
Exemplo n.º 5
0
        public void Migrate(IEnumerable <IStep> migrationSteps, DatabaseVersion currentVersion, long?targetVersion, IScriptRunner scriptRunner, string schema, string tablespace)
        {
            var steps = migrationSteps as IList <IStep> ?? migrationSteps.ToList();

            var forwardScripts  = steps.Select(m => m.ForwardScript).ToList();
            var backwardScripts = steps.Select(m => m.BackwardScript).ToList();

            var applicableScripts = forwardScripts.Where(s => currentVersion.IsNull() || s.Version > currentVersion.Version)
                                    .Where(s => !targetVersion.HasValue || s.Version <= targetVersion).ToArray();

            if (applicableScripts.IsNullOrEmpty())
            {
                Output.Warn("No migration scripts need to be run. Nothing will be done.");
            }
            else
            {
                Output.Info("The following scripts will be applied to the database:");
                foreach (var script in applicableScripts)
                {
                    Output.Info(script.Name, 1);
                }

                Output.EmptyLine();
                Prompt.ForAnyKey("Press any key to start the 'up' migration. Ctrl-C to abort.");

                foreach (var script in applicableScripts)
                {
                    Output.Info("Executing script: {0}".FormatWith(script.Path));

                    try
                    {
                        scriptRunner.Execute(script);
                    }
                    catch (SqlPlusException)
                    {
                        if (!_force)
                        {
                            throw;
                        }
                    }

                    Output.Info("Script '{0}' completed.".FormatWith(script.Name));

                    Output.Text("Adding version {0} for script '{1}' to version table".FormatWith(script.Version, script.Name));
                    _versionRespository.InsertVersion(script.AsDatabaseVersion(), schema);

                    Output.Text("Adding script contents for script '{0}' to applied scripts table".FormatWith(script.Name));
                    _appliedScriptsRepository.InsertAppliedScript(script.AsDatabaseVersion(), schema, script, backwardScripts.FirstOrDefault(m => m.IsNotNull() && m.Version == script.Version));
                }
            }
        }
Exemplo n.º 6
0
        private void DowngradeDatabase(IEnumerable <IScript> migrationScripts, DatabaseVersion currentVersion, long?targetVersionNumber, IScriptRunner scriptRunner, string schema)
        {
            var applicableScripts = migrationScripts.Where(s => currentVersion.IsNull() || s.Version <= currentVersion.Version)
                                    .Where(s => !targetVersionNumber.HasValue || s.Version > targetVersionNumber).ToArray();

            if (applicableScripts.IsNullOrEmpty())
            {
                Output.Warn("No migration scripts need to be run. Nothing will be done.");
            }
            else
            {
                Output.Info("The following scripts will be applied to the database:");
                foreach (var script in applicableScripts)
                {
                    Output.Info(script.Name, 1);
                }

                Output.EmptyLine();
                Prompt.ForAnyKey("Press any key to start the 'down' migration. Ctrl-C to abort.");

                foreach (var script in applicableScripts)
                {
                    Output.Info("Executing script: {0}".FormatWith(script.Path));

                    try
                    {
                        scriptRunner.Execute(script);
                    }
                    catch (SqlPlusException)
                    {
                        if (!_force)
                        {
                            throw;
                        }
                    }

                    Output.Info("Script '{0}' completed.".FormatWith(script.Name));

                    Output.Text("Removing script contents for script '{0}' from applied scripts table".FormatWith(script.Name));
                    _appliedScriptsRepository.RemoveAppliedScript(script.AsDatabaseVersion(), schema);

                    Output.Text("Removing version {0} for script '{1}' from version table".FormatWith(script.Version, script.Name));
                    _versionRespository.RemoveVersion(script.AsDatabaseVersion(), schema);
                }
            }
        }
Exemplo n.º 7
0
        private void DowngradeDatabase(IEnumerable<IScript> migrationScripts, DatabaseVersion currentVersion, long? targetVersionNumber, IScriptRunner scriptRunner, string schema)
        {
            var applicableScripts = migrationScripts.Where(s => currentVersion.IsNull() || s.Version <= currentVersion.Version)
                .Where(s => !targetVersionNumber.HasValue || s.Version > targetVersionNumber).ToArray();

            if (applicableScripts.IsNullOrEmpty())
            {
                Output.Warn("No migration scripts need to be run. Nothing will be done.");
            }
            else
            {
                Output.Info("The following scripts will be applied to the database:");
                foreach (var script in applicableScripts)
                {
                    Output.Info(script.Name, 1);
                }

                Output.EmptyLine();
                Prompt.ForAnyKey("Press any key to start the 'down' migration. Ctrl-C to abort.");

                foreach (var script in applicableScripts)
                {
                    Output.Info("Executing script: {0}".FormatWith(script.Path));

                    try
                    {
                        scriptRunner.Execute(script);
                    }
                    catch (SqlPlusException)
                    {
                        if (!_force)
                        {
                            throw;
                        }
                    }

                    Output.Info("Script '{0}' completed.".FormatWith(script.Name));

                    Output.Text("Removing script contents for script '{0}' from applied scripts table".FormatWith(script.Name));
                    _appliedScriptsRepository.RemoveAppliedScript(script.AsDatabaseVersion(), schema);

                    Output.Text("Removing version {0} for script '{1}' from version table".FormatWith(script.Version, script.Name));
                    _versionRespository.RemoveVersion(script.AsDatabaseVersion(), schema);
                }
            }
        }
Exemplo n.º 8
0
        private void InitialiseDatabase(IEnumerable <IScript> initScripts, IScriptRunner scriptRunner, string schema)
        {
            Output.Warn("*** Target database could not be found and needs to be initialised before the migration can be run... ***");
            Output.EmptyLine();

            var initScriptsList = initScripts as IList <IScript> ?? initScripts.ToList();

            if (initScriptsList.IsNullOrEmpty())
            {
                Output.Warn("No initialisation scripts found to create the database. Nothing will be done.");
            }
            else
            {
                Output.Info("The following scripts will be used to create and initialise the tablespace and schema:");
                foreach (var script in initScriptsList)
                {
                    Output.Info(script.Name, 1);
                }

                Output.EmptyLine();
                Output.Warn("Note: soothsayer assumes that the tablespace and schema share the same name, the versioning table will be created in tablespace '{0}'".FormatWith(schema));

                Prompt.ForAnyKey("Press any key to start the 'init' migration. Ctrl-C to abort.");

                foreach (var script in initScriptsList)
                {
                    Output.Info("Executing script: {0}".FormatWith(script.Path));
                    try
                    {
                        scriptRunner.Execute(script);
                    }
                    catch (SqlPlusException)
                    {
                        if (!_force)
                        {
                            throw;
                        }
                    }
                    Output.Info("Script '{0}' completed.".FormatWith(script.Name));
                }

                Output.Info("Initialisation scripts completed.");
            }

            Output.EmptyLine();
        }
Exemplo n.º 9
0
        private void InitialiseDatabase(IEnumerable<IScript> initScripts, IScriptRunner scriptRunner, string schema)
        {
            Output.Warn("*** Target database could not be found and needs to be initialised before the migration can be run... ***");
            Output.EmptyLine();

            var initScriptsList = initScripts as IList<IScript> ?? initScripts.ToList();
            if (initScriptsList.IsNullOrEmpty())
            {
                Output.Warn("No initialisation scripts found to create the database. Nothing will be done.");
            }
            else
            {
                Output.Info("The following scripts will be used to create and initialise the tablespace and schema:");
                foreach (var script in initScriptsList)
                {
                    Output.Info(script.Name, 1);
                }

                Output.EmptyLine();
                Output.Warn("Note: soothsayer assumes that the tablespace and schema share the same name, the versioning table will be created in tablespace '{0}'".FormatWith(schema));

                Prompt.ForAnyKey("Press any key to start the 'init' migration. Ctrl-C to abort.");

                foreach (var script in initScriptsList)
                {
                    Output.Info("Executing script: {0}".FormatWith(script.Path));
                    try
                    {
                        scriptRunner.Execute(script);
                    }
                    catch (SqlPlusException)
                    {
                        if (!_force)
                        {
                            throw;
                        }
                    }
                    Output.Info("Script '{0}' completed.".FormatWith(script.Name));
                }

                Output.Info("Initialisation scripts completed.");
            }

            Output.EmptyLine();
        }
Exemplo n.º 10
0
        private void TerminateDatabase(IEnumerable <IScript> termScripts, IScriptRunner scriptRunner, string schema)
        {
            var termScriptsList = termScripts as IList <IScript> ?? termScripts.ToList();

            if (termScriptsList.IsNullOrEmpty())
            {
                Output.Warn("No termination scripts found to destroy the database. Nothing will be done.");
            }
            else
            {
                Output.Info("The following scripts will be used to terminate the tablespace and schema:");
                foreach (var script in termScriptsList)
                {
                    Output.Info(script.Name, 1);
                }

                Output.EmptyLine();
                Prompt.ForAnyKey("Press any key to start the 'term' migration. Ctrl-C to abort.");

                foreach (var script in termScriptsList)
                {
                    Output.Info("Executing script: {0}".FormatWith(script.Path));
                    try
                    {
                        scriptRunner.Execute(script);
                    }
                    catch (SqlPlusException)
                    {
                        if (!_force)
                        {
                            throw;
                        }
                    }
                    Output.Info("Script '{0}' completed.".FormatWith(script.Name));
                }

                Output.Info("Termination scripts completed.'".FormatWith(schema));
            }

            Output.EmptyLine();
        }
Exemplo n.º 11
0
        private void TerminateDatabase(IEnumerable<IScript> termScripts, IScriptRunner scriptRunner, string schema)
        {
            var termScriptsList = termScripts as IList<IScript> ?? termScripts.ToList();
            if (termScriptsList.IsNullOrEmpty())
            {
                Output.Warn("No termination scripts found to destroy the database. Nothing will be done.");
            }
            else
            {
                Output.Info("The following scripts will be used to terminate the tablespace and schema:");
                foreach (var script in termScriptsList)
                {
                    Output.Info(script.Name, 1);
                }

                Output.EmptyLine();
                Prompt.ForAnyKey("Press any key to start the 'term' migration. Ctrl-C to abort.");

                foreach (var script in termScriptsList)
                {
                    Output.Info("Executing script: {0}".FormatWith(script.Path));
                    try
                    {
                        scriptRunner.Execute(script);
                    }
                    catch (SqlPlusException)
                    {
                        if (!_force)
                        {
                            throw;
                        }
                    }
                    Output.Info("Script '{0}' completed.".FormatWith(script.Name));
                }

                Output.Info("Termination scripts completed.'".FormatWith(schema));
            }

            Output.EmptyLine();
        }