Esempio n. 1
0
        private static void Main(string[] args)
        {
            //Initialize & erase database
            Initialize.Start();
            var logger = Initialize.GetLogger();

            PerformanceStats.Reset();
            logger.Debug("Database erased ...");
            logger.Debug("Initialized binding modules, automapper,infrastructure ...");

            //Import stocks
            logger.Debug("Import stocks ...");
            var stock = new ImportStock();

            stock.Start();
            logger.Debug("... finished importing stocks");

            //Import quotations
            logger.Debug("Import quotations ...");
            var quotations = new ImportQuotations();

            quotations.StockItems = stock.Items;
            quotations.Start();
            logger.Debug("... finished importing quotations");

            //Download quotations
            logger.Debug("Download quotations ...");
            var downloadQuotations = new DownloadQuotations();

            downloadQuotations.Start();
            logger.Debug("... finished importing quotations");

            //Import feedbacks
            logger.Debug("Import feedbacks ...");
            var feedback = new ImportFeedback();

            feedback.Start();
            logger.Debug("... finished importing feedbacks");

            //Import strategies
            logger.Debug("Import strategies ...");
            var strategy = new ImportStrategy();

            strategy.Start();
            logger.Debug("... finished importing strategies");

            //Import calculations
            logger.Debug("Import calculations ...");
            var calculation = new ImportCalculations();

            calculation.Start();
            logger.Debug("... finished importing calculations");

            //Import transactions
            logger.Debug("Import transactions ...");
            var transaction = new ImportTransaction
            {
                FeedbackItems = feedback.Items,
                StockItems    = stock.Items,
                StrategyItems = strategy.Items
            };

            transaction.Start();
            logger.Debug("... finished importing transactions");

            //Testing queries
            logger.Debug("Creating test queries ...");
            var testing = new TestQueries();

            testing.Start();
            logger.Debug("... finished testing");

            //Testing performance
            logger.Debug("Testing statistics ...");
            var stats = new TestPerformance(transaction.Items);

            stats.Start();
            logger.Debug("... finished testing statistics");

            //Testing open positions
            logger.Debug("Testing open positions ...");
            var openPositions = new TestOpenPositions(stock.Items, transaction.Items);

            openPositions.Start();
            logger.Debug("... finished testing statistics");

            //Statistics
            logger.Debug("Event Sourcing Performance");
            PerformanceStats.WriteToConsole();


            logger.Debug("Finished...Press any key to close program");
            Console.ReadKey();

            //Stopping everything
            Initialize.Stop();
        }
Esempio n. 2
0
        public IActionResult Migrate(int id)
        {
            var result = string.Empty;

            var stock       = new ImportStock();
            var feedback    = new ImportFeedback();
            var strategy    = new ImportStrategy();
            var transaction = new ImportTransaction();

            switch (id)
            {
            case 0:     //Erase Database
            {
                PerformanceStats.Reset();
                _modelRepositoryDeletionCoordinator.DeleteAll();
                result = "Deleted data from current application database";
                break;
            }

            case 1:     //Import stocks
            {
                stock.Start();
                result = "Imported stocks";
                new MigrationItemPersister <StockDto>("stock").Set(stock.Items);
                new MigrationItemPersister <StockDto>("dividendstock").Set(stock.DividendItems);
                break;
            }

            case 2:     //Import quotations
            {
                //var quotations = new ImportQuotations();
                //quotations.StockItems = new MigrationItemPersister<StockDto>("stock").Get();
                //quotations.Start();

                result = "Imported quotations";
                break;
            }

            case 3:     //Download quotations
            {
                //var downloadQuotations = new DownloadQuotations();
                //downloadQuotations.Start();
                result = "Downloaded quotations";
                break;
            }

            case 4:     //Import feedbacks
            {
                feedback.Start();
                result = "Imported feedbacks";
                new MigrationItemPersister <FeedbackDto>("feedback").Set(feedback.Items);
                break;
            }

            case 5:     //Import strategies
            {
                strategy.Start();
                result = "Imported strategies";
                new MigrationItemPersister <StrategyDto>("strategy").Set(strategy.Items);
                break;
            }

            case 6:     //Import calculations
            {
                var calculation = new ImportCalculations();
                calculation.Start();
                result = "Imported calculations";
                break;
            }

            case 7:     //Import transactions
            {
                transaction.FeedbackItems      = new MigrationItemPersister <FeedbackDto>("feedback").Get();
                transaction.StockItems         = new MigrationItemPersister <StockDto>("stock").Get();
                transaction.StrategyItems      = new MigrationItemPersister <StrategyDto>("strategy").Get();
                transaction.DividendStockItems = new MigrationItemPersister <StockDto>("dividendstock").Get();

                transaction.Start();
                result = "Imported transactions";
                new MigrationItemPersister <ITransactionDto>("transaction").Set(transaction.Items);
                break;
            }

            case 8:     //Testing queries
            {
                var testing = new TestQueries();
                testing.Start();
                result = "Tested results with queries";
                break;
            }

            case 9:     //Testing performance
            {
                var stats = new TestPerformance(new MigrationItemPersister <ITransactionDto>("transaction").Get());
                stats.Start();
                result = "Finished testing statistics";
                break;
            }

            case 10:     //Testing open positions
            {
                var openPositions = new TestOpenPositions(new MigrationItemPersister <StockDto>("stock").Get(), new MigrationItemPersister <ITransactionDto>("transaction").Get());
                openPositions.Start();
                result = "Finished testing open positions";
                break;
            }

            case 11:     //Statistics
            {
                PerformanceStats.WriteToConsole();
                result = "Flushed performance statistis";
                break;
            }

            default:
            {
                break;
            }
            }


            return(Json(result));
        }
Esempio n. 3
0
        public async Task <IActionResult> Migrate(int id)
        {
            var result = string.Empty;

            var stock       = new ImportStock();
            var feedback    = new ImportFeedback();
            var strategy    = new ImportStrategy();
            var transaction = new ImportTransaction();

            var quotationJob = _jobs.FirstOrDefault(j => j.Name == "Update Quotations");

            //TODO: Application is not able to handle multithreading properly, we need to make sure nothing else is importing
            for (var numberOfTry = 0; numberOfTry < 10; numberOfTry++)
            {
                try
                {
                    //TODO: Check all jobs
                    if (quotationJob?.Status != ScheduledJobStatus.Running)
                    {
                        break;
                    }
                }
                catch
                {
                    // ignored
                }

                await Task.Delay(10000);
            }


            switch (id)
            {
            case 0:     //Erase Database
            {
                PerformanceStats.Reset();
                _modelRepositoryDeletionCoordinator.DeleteAll();
                result = "Deleted data from current application database";
                break;
            }

            case 1:     //Import stocks
            {
                stock.Start();
                result = "Imported stocks";
                new MigrationItemPersister <StockDto>("stock").Set(stock.Items);
                new MigrationItemPersister <StockDto>("dividendstock").Set(stock.DividendItems);
                break;
            }

            case 2:     //Import quotations
            {
                var quotations = new ImportQuotations();
                quotations.StockItems = new MigrationItemPersister <StockDto>("stock").Get();
                quotations.Start();

                result = "Imported quotations";
                break;
            }

            case 3:     //Download quotations
            {
                var downloadQuotations = new DownloadQuotations();
                downloadQuotations.Start();
                result = "Downloaded quotations";
                break;
            }

            case 4:     //Import feedbacks
            {
                feedback.Start();
                result = "Imported feedbacks";
                new MigrationItemPersister <FeedbackDto>("feedback").Set(feedback.Items);
                break;
            }

            case 5:     //Import strategies
            {
                strategy.Start();
                result = "Imported strategies";
                new MigrationItemPersister <StrategyDto>("strategy").Set(strategy.Items);
                break;
            }

            case 6:     //Import calculations
            {
                var calculation = new ImportCalculations();
                calculation.Start();
                result = "Imported calculations";
                break;
            }

            case 7:     //Import transactions
            {
                transaction.FeedbackItems      = new MigrationItemPersister <FeedbackDto>("feedback").Get();
                transaction.StockItems         = new MigrationItemPersister <StockDto>("stock").Get();
                transaction.StrategyItems      = new MigrationItemPersister <StrategyDto>("strategy").Get();
                transaction.DividendStockItems = new MigrationItemPersister <StockDto>("dividendstock").Get();

                transaction.Start();
                result = "Imported transactions";
                new MigrationItemPersister <ITransactionDto>("transaction").Set(transaction.Items);
                break;
            }

            case 8:     //Testing queries
            {
                var testing = new TestQueries();
                testing.Start();
                result = "Tested results with queries";
                break;
            }

            case 9:     //Testing performance
            {
                var stats = new TestPerformance(new MigrationItemPersister <ITransactionDto>("transaction").Get());
                stats.Start();
                result = "Finished testing statistics";
                break;
            }

            case 10:     //Testing open positions
            {
                var openPositions = new TestOpenPositions(new MigrationItemPersister <StockDto>("stock").Get(),
                                                          new MigrationItemPersister <ITransactionDto>("transaction").Get());
                openPositions.Start();
                result = "Finished testing open positions";
                break;
            }

            case 11:     //Statistics
            {
                PerformanceStats.WriteToConsole();
                result = "Flushed performance statistics";
                break;
            }

            default:
            {
                break;
            }
            }


            return(Json(result));
        }