Example #1
0
        public Service()
        {
            InitializeComponent();

            ObjectFactory.Initialize(x =>
            {
                x.For <IScheduleMessageHandler>()
                .AddInstances(i =>
                {
                    i.Type <HandlerAddSchedule>();
                    i.Type <HandlerChangeLogging>();
                    i.Type <HandlerChangeSchedule>();
                    i.Type <HandlerPublishConfiguration>();
                    i.Type <HandlerPublishSchedule>();
                    i.Type <HandlerRemoveSchedule>();
                    i.Type <HandlerResumeSchedule>();
                    i.Type <HandlerStopTask>();
                });

                x.Scan(s =>
                {
                    s.AssembliesFromApplicationBaseDirectory();
                    s.AddAllTypesOf <IMiramarTaskFactory>();
                });
            });

            logger        = InfrastructureFactory.CreateLogger("Service");
            serviceSource = new CancellationTokenSource();
        }
Example #2
0
        public ScheduleService(IMessageQueueFactory queueFactory, IMiramarTaskProvider taskProvider, IMiramarScheduleProvider scheduleProvider, IMiramarContextProvider contextProvider)
        {
            this.contextProvider  = contextProvider;
            this.queueFactory     = queueFactory;
            this.taskProvider     = taskProvider;
            this.scheduleProvider = scheduleProvider;

            logger = InfrastructureFactory.CreateLogger("ScheduleQueue");
        }
Example #3
0
        public MiramarController()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["BillingAdmin"].ConnectionString;

            adminDataAccess = new AdminDataAccess(connectionString);

            logger = InfrastructureFactory.CreateLogger("Controller");

            publisher     = new MiramarPublisher();
            allowMetaData = false;
        }
Example #4
0
        public MiramarScheduleProvider(TaskScheduleModel[] collection)
        {
            this.collection = new List <TaskScheduleModel>(collection);

            logger    = InfrastructureFactory.CreateLogger("Scheduler");
            publisher = new MiramarPublisher();

            schedules      = new Dictionary <string, DateTime>();
            executionPlans = new Dictionary <string, List <string> >();

            PushTasksForInitialConsideration(collection);
        }
Example #5
0
        static void Main(string[] args)
        {
            ObjectFactory.Initialize(x =>
            {
                x.For <IScheduleMessageHandler>()
                .AddInstances(i =>
                {
                    i.Type <HandlerAddSchedule>();
                    i.Type <HandlerChangeLogging>();
                    i.Type <HandlerChangeSchedule>();
                    i.Type <HandlerPublishConfiguration>();
                    i.Type <HandlerPublishSchedule>();
                    i.Type <HandlerRemoveSchedule>();
                    i.Type <HandlerResumeSchedule>();
                    i.Type <HandlerStopTask>();
                });

                x.Scan(s =>
                {
                    s.AssembliesFromApplicationBaseDirectory();
                    s.AddAllTypesOf <IMiramarTaskFactory>();
                });
            });

            var logger = InfrastructureFactory.CreateLogger("Console");

            logger.Debug("Starting up console application.");

            if (args.Length != 0)
            {
                logger.Info("Waiting on debugger attach. Press any key to continue.");
                Console.ReadKey();
            }

            var messageFactory = CreateMessageFactory(logger);

            if (!messageFactory.IsActive)
            {
                logger.InfoFormat("RabbitMQ is not active. Messaging will not be available.");
            }

            var source           = new CancellationTokenSource();
            var publisher        = new MiramarPublisher(messageFactory);
            var contextProvider  = new MiramarContextProvider();
            var taskProvider     = MiramarConfigurationParser.ParseConfiguration(publisher, "miramar.config");
            var scheduleProvider = MiramarSchedulingParser.ParseSchedule(publisher, "miramar.config");

            var controllerTask = new Task(() =>
            {
                logger.Info("Starting Miramar Controller.");

                var controller = new MiramarController(publisher, taskProvider, scheduleProvider, contextProvider, true);
                controller.ThreadRun(source.Token);
            });

            controllerTask.ContinueWith(x => logger.Info("Console application is shutting down."));

            var schedulerTask = new Task(() =>
            {
                logger.Info("Starting Miramar Scheduler.");

                var scheduler = new ScheduleService(messageFactory, taskProvider, scheduleProvider, contextProvider);
                scheduler.ThreadRun(source.Token);
            });

            schedulerTask.ContinueWith(x => logger.Info("Scheduler application is shutting down."));

            AddMiramarAdapter(messageFactory);

            controllerTask.Start();
            schedulerTask.Start();

            logger.Info("Miramar Controller is now running.");
            logger.Info("Miramar Scheduler is now running");
            logger.Info("Press CTRL+C or 'Q' to stop.");

            Console.CancelKeyPress += (s, e) =>
            {
                logger.Warn("CTRL+C detected. Attempting to quit.");
                CancelAndWait(source, messageFactory,
                              controllerTask, schedulerTask);
            };

            while (true)
            {
                var key = Console.ReadKey();
                if (key.Key != ConsoleKey.Q)
                {
                    continue;
                }

                logger.Warn("'Q' detected. Attempting to stop.");
                CancelAndWait(source, messageFactory,
                              controllerTask, schedulerTask);

                break;
            }
        }
Example #6
0
        public IMiramarTask GetTask(IMiramarClientInfo clientInfo, string taskId)
        {
            var adminDataAccess = new AdminDataAccess(clientInfo.AdminConnection);

            var clientId  = clientInfo.ClientId;
            var logName   = string.Format("Client-{0}", clientId);
            var logTaskId = string.Format("client.{0}.{1}", clientId, taskId);
            var logger    = InfrastructureFactory.CreateLogger(clientId, logName, logTaskId);

            if (taskId.StartsWith("market.file", StringComparison.OrdinalIgnoreCase))
            {
                var clientDataAccess = new ClientDataAccess(clientInfo.ClientConnection);

                if (taskId.Equals("market.file.decrypt", StringComparison.OrdinalIgnoreCase))
                {
                    return(new DecryptFileTask(adminDataAccess, clientDataAccess, logger, clientId));
                }

                var marketDataAccess = new MarketDataAccess(clientInfo.MarketConnection);

                if (taskId.Equals("market.file.import", StringComparison.OrdinalIgnoreCase))
                {
                    return(new ImportMarketFileTask(adminDataAccess, marketDataAccess, logger, clientId));
                }

                if (taskId.Equals("market.file.export", StringComparison.OrdinalIgnoreCase))
                {
                    return(new ExportMarketFileTask(adminDataAccess, marketDataAccess, logger, clientId));
                }

                if (taskId.Equals("market.file.encrypt", StringComparison.OrdinalIgnoreCase))
                {
                    return(new EncryptFileTask(adminDataAccess, clientDataAccess, marketDataAccess, logger, clientId));
                }

                if (taskId.Equals("market.file.transmit", StringComparison.OrdinalIgnoreCase))
                {
                    return(new TransmitFileTask(adminDataAccess, clientDataAccess, marketDataAccess, logger, clientId));
                }
            }

            if (taskId.StartsWith("ercot.cbf", StringComparison.OrdinalIgnoreCase))
            {
                var clientDataAccess = new ClientDataAccess(clientInfo.ClientConnection);
                var marketDataAccess = new MarketDataAccess(clientInfo.MarketConnection);

                if (taskId.Equals("ercot.cbf.encrypt", StringComparison.OrdinalIgnoreCase))
                {
                    return(new ErcotEncryptFileTask(adminDataAccess, clientDataAccess, marketDataAccess, logger,
                                                    clientId));
                }

                if (taskId.Equals("ercot.cbf.transmit", StringComparison.OrdinalIgnoreCase))
                {
                    return(new ErcotTransmitFileTask(adminDataAccess, clientDataAccess, marketDataAccess, logger,
                                                     clientId));
                }
            }

            var message = string.Format("No Miramar Task could be identified for task \"{0}\".", taskId);

            throw new ArgumentOutOfRangeException("taskId", message);
        }