Example #1
0
 static void Main()
 {
     Console.CancelKeyPress += Console_CancelKeyPress;
     _testRegistration       = _app.CreateAndRegisterSource(new ConsoleSourceFactory());
     _testRegistration.AttachProcessingGroup(new ConsoleProcessingFactory());
     _testRegistration.Start().Wait();
 }
Example #2
0
        private static void ConsoleProcessingMenu()
        {
            Console.Clear();
            StartFinishMenu();
            var consoleProcessingKey = Console.ReadKey();

            _testRegistration = _app.CreateAndRegisterSource(new ObservationSourceFactory());
            _testRegistration.AttachProcessingGroup(new ConsoleProcessingFactory());
            _testRegistration.Start().Wait();
        }
Example #3
0
        private static void SaveToFileProcessingMenu()
        {
            string filePath = null;

            while (string.IsNullOrEmpty(filePath))
            {
                Console.Clear();
                Console.WriteLine("Please enter file path. For example -  D:\\test.txt");
                filePath = Console.ReadLine();
            }

            StartFinishMenu();
            var saveToFileProcessingKey = Console.ReadKey();

            _testRegistration = _app.CreateAndRegisterSource(new ObservationSourceFactory());
            _testRegistration.AttachProcessingGroup(new SaveToFileProcessingFactory(filePath, new JsonSerializer <IEnergyObservation>()));
            _testRegistration.Start().Wait();
        }
Example #4
0
        private static void MainMenu()
        {
            //------------------------------------------Enumerator Check
            //var enumerator = sqlORM.GetEnumerator();
            //enumerator.MoveNext();
            //var current = enumerator.Current;
            //------------------------------------------

            //------------------------------------------MongoDB Check
            //var connectopn = ConfigurationManager.ConnectionStrings["MongoDBObservationConnection"].ConnectionString;
            //var newItem = new FlashObservation( 11, 23.3, new Coordinates(12, 12), DateTime.Now);

            //var mongoStorage = new MongoDBStorage<IEnergyObservation>(connectopn, "observation", "energyObservations");
            //mongoStorage.Add(newItem);

            //var analizer = new MongoDBAnalizer(mongoStorage.ObservationDBCollection);
            ////mongoStorage.Clear();
            ////mongoStorage.Remove(newItem);
            //Console.WriteLine(analizer.GetMinEnergy(new Coordinates(12, 12)));
            //var countItems = mongoStorage.Count;

            //-------------------------------------------------------

            //--------------------------------------API Plugin Check
            //var httpClient = new HttpClientService();
            //var apiStorage = new APIStorage<IEnergyObservation>(httpClient);
            //var analizer = new APIAnalizer(httpClient);
            //var newItem = new FlashObservation(5989, 11, 23.3, new Coordinates(5976, 12, 12), DateTime.Now);
            ////apiStorage.Remove(newItem);
            //IEnergyObservation[] array = new IEnergyObservation[45];
            //array[0] = newItem;
            //apiStorage.CopyTo(array, 1);

            //var result = analizer.GetAverageEnergy(DateTime.Now.AddDays(-2), DateTime.Now);
            //var result = analizer.GetAverageEnergy(new Coordinates(5979, 45, 19), new Coordinates(5980, 14, 14));
            //var result2 = analizer.GetDistributionByEnergyValue();
            //var result3 = analizer.GetDistributionByObservationTime();
            //var result4 = analizer.GetDistributionByCoordinates();
            //var result5 = analizer.GetMinEnergyPosition();
            //------------------------------------------------------

            LoadPlugin();
            ShowMainMenu();

            var key = Console.ReadKey();

            while (key.Key != ConsoleKey.D0)
            {
                if (key.Key == ConsoleKey.D1)
                {
                    Console.Clear();
                    ShowProcessorMenu();
                    do
                    {
                        var processorKey = Console.ReadKey();
                        if (processorKey.Key == ConsoleKey.D0)
                        {
                            break;
                        }
                        switch (processorKey.Key) //Processors not from plugins
                        {
                        case ConsoleKey.D1:
                            ConsoleProcessingMenu();
                            break;

                        case ConsoleKey.D2:
                            SaveToFileProcessingMenu();
                            break;
                        }
                        if (char.IsNumber(processorKey.KeyChar)) //Processors from plugins
                        {
                            Console.Clear();
                            StartFinishMenu();
                            var consoleProcessingKey = Console.ReadKey();

                            int processorIndexInMenu    = int.Parse(processorKey.KeyChar.ToString());
                            var plaginProcessingFactory = _app.ProcessingFactories.ElementAt(processorIndexInMenu + 1 - startPluginProcessorsIndexInMenu);
                            var plaginSourceFactory     = _app.SourceFactories.Where(sourceFactory => sourceFactory.GetType().ToString().StartsWith(selectedPluginDllName)).First();

                            _testRegistration       = _app.CreateAndRegisterSource(plaginSourceFactory);
                            attachedProcessingGroup = _testRegistration.AttachProcessingGroup(plaginProcessingFactory);

                            _testRegistration.Start().Wait();

                            ShowAnalizerResult(attachedProcessingGroup.Analizer);
                        }
                    } while (true);
                }
            }
        }
Example #5
0
        private static void ProcessFactoriesInApp()
        {
            Console.WriteLine("Choose source factory to work with.");
            int i = 0;

            foreach (var appSourceFactory in App.SourceFactories)
            {
                ++i;
                Console.WriteLine($"{i}: {appSourceFactory.GetType()}");
            }

            var userChoiceIsValid = false;
            ISourceFactory <FlashObservation> sourceFactory = null;

            if (App.SourceFactories.Count == 0)
            {
                sourceFactory = new RandomEnergySourceFactory(new Logger());
                Console.WriteLine($"The source factory is not defined in plugin, so it will be {nameof(RandomEnergySource)}");
            }
            else
            {
                while (!userChoiceIsValid)
                {
                    if (TryReadUserInput(0, App.SourceFactories.Count, out int userChoice))
                    {
                        userChoiceIsValid = true;
                        sourceFactory     = App.SourceFactories.ElementAt(userChoice - 1);
                    }
                }
            }

            Console.WriteLine("Choose processing factory to work with.");
            i = 0;
            foreach (var appProcessingFactory in App.ProcessingFactories)
            {
                ++i;
                Console.WriteLine($"{i}: {appProcessingFactory.GetType()}");
            }

            IProcessingFactory <FlashObservation> processingFactory = null;

            userChoiceIsValid = false;
            while (!userChoiceIsValid !)
            {
                if (TryReadUserInput(0, App.ProcessingFactories.Count, out int userChoice))
                {
                    userChoiceIsValid = true;
                    processingFactory = App.ProcessingFactories.ElementAt(userChoice - 1);
                }
            }

            Console.WriteLine($"Processing source factory {sourceFactory.GetType()}...");
            ISourceRegistration <FlashObservation> sourceRegistration = App.CreateAndRegisterSource(sourceFactory);
            IProcessingGroup <FlashObservation>    processingGroup    = sourceRegistration.AttachProcessingGroup(processingFactory);

            SourceRegistrations.Add(sourceRegistration);
            Console.WriteLine("Click Ctrl+C to stop generating values");
            sourceRegistration.Start().Wait();

            ProcessAnalyzer(processingGroup.Analizer);
        }