Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Logger appLogger = Logger.Instance;

            if (ReadResourcesList() && ConfigureLogger() && CreateWorkingFolders())
            {
                StatisticsToolbox statisticsToolbox = new StatisticsToolbox();
                MathToolbox mathToolbox = new MathToolbox();

                TaskPerformerContextManager provider = new TaskPerformerContextManager();
                provider.Add(statisticsToolbox);
                provider.Add(mathToolbox);

                TaskProcessingManager manager = TaskProcessingManager.Instance;
                manager.SetContextProvider(provider);

                ServiceHost host = null;
                try
                {
                    host = new ServiceHost(typeof(ProcessingService));
                    host.Open();

                    Console.WriteLine("The service ProcessingService is ready.");
                    Console.WriteLine("Press <Enter> to stop the service...");
                    Console.ReadLine();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error while starting the service: {0}", e.ToString());
                    Console.WriteLine();
                }
                finally
                {
                    if (host != null)
                    {
                        try
                        {
                            host.Close();
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error while stopping the service: {0}", e.ToString());
                            Console.WriteLine();
                            host.Abort();
                        }
                    }
                }
            }

            appLogger.Flush();
            appLogger.Cleanup();

            Console.WriteLine("Press <Enter> to close the application...");
            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Logger appLogger = Logger.Instance;
            Settings appConfig = Settings.Instance;

            // ======================================
            // TODO: replace with plugin architecture
            // ======================================
            List<ITaskPerformer> availableProcessingResources = new List<ITaskPerformer>();
            availableProcessingResources.Add(new MathToolbox());
            availableProcessingResources.Add(new StatisticsToolbox());
            // ======================================

            if (ReadResourcesList() && ConfigureLogger() && CreateWorkingFolders())
            {
                TaskPerformerContextManager provider = new TaskPerformerContextManager();
                foreach (var resource in availableProcessingResources)
                {
                    string resourceId = string.Format("{0}-{1}", resource.Name, resource.Version);
                    if (appConfig.Resources.Contains<string>(resourceId))
                    {
                        if (provider.Add(resource))
                        {
                            Console.WriteLine("{0} has been successfully loaded!", resourceId);
                        }
                    }
                }

                TaskProcessingManager scheduler = new TaskProcessingManager();
                scheduler.SetContextProvider(provider);

                IProcessingServiceContainer container = new ProcessingServiceContainer(
                    scheduler, appConfig.ReadyTasksFolder, appConfig.CompletedTasksFolder);

                ServiceHost host = null;
                try
                {
                    host = new ProcessingServiceHost(container);
                    host.Open();

                    Console.WriteLine("The service ProcessingService is ready.");
                    Console.WriteLine("Press <Enter> to stop the service...");
                    Console.ReadLine();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error while starting the service: {0}", e.ToString());
                    Console.WriteLine();
                }
                finally
                {
                    if (host != null)
                    {
                        try
                        {
                            host.Close();
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error while stopping the service: {0}", e.ToString());
                            Console.WriteLine();
                            host.Abort();
                        }
                    }
                }
            }

            appLogger.Flush();
            appLogger.Cleanup();

            Console.WriteLine("Press <Enter> to close the application...");
            Console.ReadLine();
        }