예제 #1
0
        /// <summary>
        ///     开启定时任务操作
        /// </summary>
        public void StartTimerQuartzJobs()
        {
            if (_sched == null)
            {
                ISchedulerFactory sf = new StdSchedulerFactory(); //执行者
                _sched = sf.GetScheduler();
            }

            var msg = string.Format("{0} => {1}", DateTime.Now, "正在启动定时任务...");

            SafeSetText(msg, richTimerPush, false);

            //容器处理
            var creaters = WindsorHelper.ResolveAll <JobCreater>();

            foreach (var creater in creaters)
            {
                if (creater.CronExpression == "false")
                {
                    continue;
                }

                msg = string.Format("{0} => {1}", DateTime.Now, "启动任务:" + creater.JobType.FullName + "...");
                SafeSetText(msg, richTimerPush, false);

                //添加定时任务
                AddJobToSchedule(creater.JobType, creater.CronExpression);
            }

            _sched.Start();

            msg = string.Format("{0} => {1}", DateTime.Now, "定时任务启动成功...");
            SafeSetText(msg, richTimerPush, false);
        }
예제 #2
0
        public void ResolveType_ContainerWithoutTypeRegistered()
        {
            var helper = new WindsorHelper();

            var container = new WindsorContainer();

            ExceptionTester.CallMethodAndExpectException <NotSupportedException>(() => helper.ResolveType(container, typeof(ITestInterface)));
        }
예제 #3
0
        public void ResolveType_InvalidContainer()
        {
            var helper = new WindsorHelper();

            var container = new object();

            ExceptionTester.CallMethodAndExpectException <NotSupportedException>(() => helper.ResolveType(container, typeof(ITestInterface)));
        }
예제 #4
0
        public void IsValidContainer_ValidContainer()
        {
            var helper = new WindsorHelper();

            var container = new WindsorContainer();

            Assert.IsTrue(helper.IsValidContainer(container));
        }
예제 #5
0
        public void GetRegistrationInfo_InterfaceTypeNull()
        {
            var helper = new WindsorHelper();

            var container = new WindsorContainer();

            ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => helper.GetRegistrationInfo(container, null));
        }
예제 #6
0
        public void GetRegistrationInfo_InvalidContainer()
        {
            var helper = new WindsorHelper();

            var container = new object();

            ExceptionTester.CallMethodAndExpectException <NotSupportedException>(() => helper.GetRegistrationInfo(container, typeof(ITestInterface)));
        }
예제 #7
0
        public void RegisterInstance_InvalidContainer()
        {
            var helper = new WindsorHelper();

            var container = new object();

            ExceptionTester.CallMethodAndExpectException <NotSupportedException>(() => helper.RegisterInstance(container, typeof(ITestInterface), new TestClass1()));
        }
예제 #8
0
        public void GetRegistrationInfo_ContainerWithoutTypeRegistered()
        {
            var helper = new WindsorHelper();

            var container = new WindsorContainer();

            Assert.IsNull(helper.GetRegistrationInfo(container, typeof(ITestInterface)));
        }
예제 #9
0
        public void RegisterInstance_InstanceNull()
        {
            var helper = new WindsorHelper();

            var container = new WindsorContainer();

            ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => helper.RegisterInstance(container, typeof(ITestInterface), null));
        }
예제 #10
0
        public void RegisterInstance_InterfaceTypeNull()
        {
            var helper = new WindsorHelper();

            var container = new WindsorContainer();

            ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => helper.RegisterInstance(container, null, new TestClass1()));
        }
예제 #11
0
        public void RegisterType_InvalidContainer()
        {
            var helper = new WindsorHelper();

            var container = new object();

            ExceptionTester.CallMethodAndExpectException <NotSupportedException>(() => helper.RegisterType(container, typeof(ITestInterface), typeof(TestClass1), RegistrationType.Singleton));
        }
예제 #12
0
        public void RegisterType_ImplementingTypeNull()
        {
            var helper = new WindsorHelper();

            var container = new WindsorContainer();

            ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => helper.RegisterType(container, typeof(ITestInterface), null, RegistrationType.Singleton));
        }
예제 #13
0
        public void IsValidContainer_InvalidContainer()
        {
            var helper = new WindsorHelper();

            var container = new object();

            Assert.IsFalse(helper.IsValidContainer(container));
        }
예제 #14
0
        public void ResolveType_InterfaceTypeNull()
        {
            var helper = new WindsorHelper();

            var container = new WindsorContainer();

            ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => helper.ResolveType(container, null));
        }
예제 #15
0
        public void RegisterType_Valid()
        {
            var helper = new WindsorHelper();

            var container = new WindsorContainer();

            Assert.IsNull(helper.GetRegistrationInfo(container, typeof(ITestInterface)));

            helper.RegisterType(container, typeof(ITestInterface), typeof(TestClass1), RegistrationType.Singleton);
            Assert.IsTrue(container.Resolve <ITestInterface>() != null);
        }
예제 #16
0
        public void GetRegistrationInfo_ContainerWithTransientTypeRegistered()
        {
            var helper = new WindsorHelper();

            var container = new WindsorContainer();

            container.Register(new IRegistration[] { new ComponentRegistration <ITestInterface>().ImplementedBy <TestClass1>().LifestyleTransient() });

            var registrationInfo = helper.GetRegistrationInfo(container, typeof(ITestInterface));

            Assert.AreEqual(typeof(ITestInterface), registrationInfo.DeclaringType);
            Assert.AreEqual(RegistrationType.Transient, registrationInfo.RegistrationType);
        }
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            config.DependencyResolver = WindsorHelper.GetDependencyResolver();
        }
예제 #18
0
        public void RegisterInstance_Valid()
        {
            var helper   = new WindsorHelper();
            var instance = new TestClass1()
            {
                Name = "test"
            };

            var container = new WindsorContainer();

            Assert.IsNull(helper.GetRegistrationInfo(container, typeof(ITestInterface)));

            helper.RegisterInstance(container, typeof(ITestInterface), instance);
            Assert.IsTrue(container.Resolve <ITestInterface>() != null);
            Assert.AreEqual(instance, container.Resolve <ITestInterface>());
        }
예제 #19
0
        private void FormQuartz_Load(object sender, EventArgs e)
        {
            //容器处理
            var creaters = WindsorHelper.ResolveAll <JobCreater>();

            var panel = new Panel
            {
                Dock       = DockStyle.Fill,
                AutoScroll = true,
                Width      = splitContainer1.Panel1.Width
            };

            var index = 0;

            foreach (var creater in creaters)
            {
                var button = new Button();
                if (creater.CronExpression == "false")
                {
                    button.Text = DoText + LeftImportText + creater.JobType.Name + RightImportText;
                }
                else
                {
                    button.Text = DoTextByScheduler + LeftImportText + creater.JobType.Name + RightImportText;
                }
                button.Tag    = creater;
                button.Click += button_Click;
                button.Width  = panel.Width - 30;
                button.Left   = 10;
                button.Top    = 5 + (index * (5 + button.Height));

                panel.Controls.Add(button);

                index++;
            }

            //添加到Panel
            splitContainer1.Panel1.Controls.Add(panel);

            //开始显示消息
            MessageCenter.PushMessage += MessageCenter_PushMessage;
        }
예제 #20
0
        public void ResolveType_Transient()
        {
            var helper = new WindsorHelper();

            var container = new WindsorContainer();

            container.Register(new IRegistration[] { new ComponentRegistration <ITestInterface>().ImplementedBy <TestClass1>().LifestyleTransient() });

            var resolvedInstance1 = helper.ResolveType(container, typeof(ITestInterface));

            Assert.IsNotNull(resolvedInstance1);
            Assert.IsInstanceOfType(resolvedInstance1, typeof(TestClass1));

            var resolvedInstance2 = helper.ResolveType(container, typeof(ITestInterface));

            Assert.IsNotNull(resolvedInstance2);
            Assert.IsInstanceOfType(resolvedInstance2, typeof(TestClass1));

            Assert.IsFalse(ReferenceEquals(resolvedInstance1, resolvedInstance2));
        }
예제 #21
0
        public void RegisterInstance_ContainerNull()
        {
            var helper = new WindsorHelper();

            ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => helper.RegisterInstance(null, typeof(ITestInterface), new TestClass1()));
        }
예제 #22
0
        public void IsValidContainer_Null()
        {
            var helper = new WindsorHelper();

            ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => helper.IsValidContainer(null));
        }
예제 #23
0
        public void ResolveType_ContainerNull()
        {
            var helper = new WindsorHelper();

            ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => helper.ResolveType(null, typeof(ITestInterface)));
        }
예제 #24
0
        public void GetRegistrationInfo_ContainerNull()
        {
            var helper = new WindsorHelper();

            ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => helper.GetRegistrationInfo(null, typeof(ITestInterface)));
        }
예제 #25
0
        public void RegisterType_ContainerNull()
        {
            var helper = new WindsorHelper();

            ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => helper.RegisterType(null, typeof(ITestInterface), typeof(TestClass1), RegistrationType.Singleton));
        }