/// <summary>
        /// Service process called by the Program.Main
        /// </summary>
        /// <param name="unity"></param>
        public MacheteWindowsService()
        {
            this.ServiceName = EventViewerConfig.source;
            var bootstrapper = new ServiceBootstrapper();
            var cfg = ConfigurationManager.GetSection(AppConfig.sourceNode) as MacheteWindowsServiceConfiguration;

            // Report # of configs read
            // detect change and re-read?
            try
            {
                container = bootstrapper.Build(cfg.Instances);
            }
            catch (Exception e)
            {
                var eventhandler = new EventHandler();
                eventhandler.MWSEventLog.WriteEntry(e.ToString());
                throw e;
            }

            this.MWSEventLog = container.Resolve<IEventHandler>().MWSEventLog;
            //
            //
            // TODO some notice if the config file is empty
            foreach (Instance instanceCfg in cfg.Instances)
            {
                instances.Add(new MacheteInstance(container.Resolve<IEmailServiceProvider>(instanceCfg.Name), instanceCfg));
            }
        }
Ejemplo n.º 2
0
        public void Integration_ServiceBootStrapper_dbDisposeThenFactoryGet()
        {
            var sbs = new ServiceBootstrapper();
            var cfg = ConfigurationManager.GetSection("MacheteWindowsService") as MacheteWindowsServiceConfiguration;
            var container = sbs.Build(cfg.Instances);

            var foo = container.Resolve<IEmailServiceProvider>(cfg.Instances[0].Name);
            var bar = container.Resolve<IEmailServiceProvider>(cfg.Instances[1].Name);

            Assert.AreNotEqual(foo, bar);

            var dbf = container.Resolve<IDatabaseFactory>(cfg.Instances[0].Name);
            var db = dbf.Get();
            db.Dispose();
            // need to assert no exception of something
            var emailQueue1 = foo.GetQueueProvider();
            emailQueue1.ProcessQueue(cfg.Instances[0].EmailQueue.EmailServer);

            var emailQueue2 = bar.GetQueueProvider();
            emailQueue2.ProcessQueue(cfg.Instances[1].EmailQueue.EmailServer);
        }
Ejemplo n.º 3
0
        public void Integration_ServiceBootStrapper_testContextIDChange()
        {
            BindingFlags bindFlags = BindingFlags.Instance |
                         BindingFlags.Public |
                         BindingFlags.NonPublic |
                         BindingFlags.Static;
            FieldInfo field = typeof(SqlConnection).GetField("ObjectID", bindFlags);

            var sbs = new ServiceBootstrapper();
            var cfg = ConfigurationManager.GetSection("MacheteWindowsService") as MacheteWindowsServiceConfiguration;
            var container = sbs.Build(cfg.Instances);

            var dbf0 = container.Resolve<IDatabaseFactory>(cfg.Instances[0].Name);
            var db0 = dbf0.Get();
            var conn0 = (db0 as System.Data.Entity.DbContext).Database.Connection;
            var objid0 = field.GetValue(conn0);

            var dbf1 = container.Resolve<IDatabaseFactory>(cfg.Instances[1].Name);
            var db1 = dbf1.Get();
            var conn1 = (db1 as System.Data.Entity.DbContext).Database.Connection;
            var objid1 = field.GetValue(conn1);

            Assert.AreNotEqual(objid0, objid1);
        }
Ejemplo n.º 4
0
        public void Integration_ServiceBootStrapper_getMultipleUOWs()
        {
            var sbs = new ServiceBootstrapper();
            var cfg = ConfigurationManager.GetSection("MacheteWindowsService") as MacheteWindowsServiceConfiguration;
            var container = sbs.Build(cfg.Instances);

            Assert.AreNotEqual(
                container.Resolve<IUnitOfWork>(cfg.Instances[0].Name),
                container.Resolve<IUnitOfWork>(cfg.Instances[1].Name)
                );

            var foo = container.Resolve<IUnitOfWork>(cfg.Instances[0].Name);
            var bar = container.Resolve<IUnitOfWork>(cfg.Instances[0].Name);
        }
Ejemplo n.º 5
0
        public void Integration_ServiceBootStrapper_getMultipleDatabaseFactories()
        {
            var sbs = new ServiceBootstrapper();
            var cfg = ConfigurationManager.GetSection("MacheteWindowsService") as MacheteWindowsServiceConfiguration;
             var foo = cfg.Instances;
            var container = sbs.Build(foo);

            Assert.AreNotEqual(
                container.Resolve<IDatabaseFactory>(cfg.Instances[0].Name),
                container.Resolve<IDatabaseFactory>(cfg.Instances[1].Name)
                );
        }