Пример #1
0
        ///// <summary>
        ///// 声明一个委托
        ///// </summary>
        ///// <param name="helloName"></param>
        //public delegate void SayHello(string helloName);

        ///// <summary>
        ///// 用中文对话
        ///// </summary>
        ///// <param name="helloName"></param>
        //public void HelloChinese(string helloName)
        //{
        //    Console.WriteLine("你好:" + helloName);
        //}

        ///// <summary>
        ///// 用英文对话
        ///// </summary>
        ///// <param name="helloName"></param>
        //public void HelloEnglish(string helloName)
        //{
        //    Console.WriteLine("Hello:" + helloName);
        //}

        ///// <summary>
        ///// 把委托传进来,根据委托用什么语言对话
        ///// </summary>
        ///// <param name="say">委托名(用什么语言)</param>
        ///// <param name="helloName">问好</param>
        //public void Hello(SayHello say, string helloName)
        //{
        //    say(helloName);
        //}

        #endregion

        static void Main(string[] args)
        {
            // 委托
            //Program p = new Program();
            //p.Hello(p.HelloChinese, "张三");
            //p.Hello(p.HelloEnglish, "Tim");
            //Console.ReadKey();

            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

            XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config"));

            HostFactory.Run(x =>
            {
                x.UseLog4Net();  //记录日志

                x.RunAsLocalSystem();

                x.SetDescription(Configuration.ServiceDescription); // 获取服务说明
                x.SetDisplayName(Configuration.ServiceDisplayName); // 获取windows服务名称
                x.SetServiceName(Configuration.ServiceName);        // 获取服务器名称

                x.Service(factory =>
                {
                    ThServer server = QuartzServerFactory.CreateServer();
                    server.Initialize();
                    return(server);
                });

                x.EnablePauseAndContinue();
            });
        }
Пример #2
0
        public TYDNewsService()
        {
            InitializeComponent();

            server = QuartzServerFactory.CreateServer();

            server.Initialize();
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="QuartzService"/> class.
        /// </summary>
        public QuartzService()
        {
            logger = LogManager.GetLogger(GetType());

            logger.Debug("Obtaining instance of an IQuartzServer");
            server = QuartzServerFactory.CreateServer();

            logger.Debug("Initializing server");
            server.Initialize();
            logger.Debug("Server initialized");
        }
Пример #4
0
        public virtual void Run()
        {
            ILog log = LogManager.GetLogger(typeof(HelloRun));

            log.Info("------- Initializing ----------------------");

            // First we must get a reference to a scheduler
            //ISchedulerFactory sf = new StdSchedulerFactory();
            //IScheduler sched = sf.GetScheduler();
            IQuartzServer server = QuartzServerFactory.CreateServer();

            server.Initialize();
            IScheduler sched = server.GetScheduler();

            log.Info("------- Initialization Complete -----------");


            // computer a time that is on the next round minute
            DateTimeOffset runTime = DateBuilder.EvenMinuteDate(DateTimeOffset.UtcNow);

            log.Info("------- Scheduling Job  -------------------");

            // define the job and tie it to our HelloJob class
            IJobDetail job = JobBuilder.Create <HelloJob>()
                             .WithIdentity("job1", "group1")
                             .Build();

            // Trigger the job to run on the next round minute
            ITrigger trigger = TriggerBuilder.Create()
                               .WithIdentity("trigger1", "group1")
                               .StartAt(runTime)
                               .Build();

            // Tell quartz to schedule the job using our trigger
            sched.ScheduleJob(job, trigger);
            log.Info(string.Format("{0} will run at: {1}", job.Key, runTime.ToString("r")));

            // Start up the scheduler (nothing can actually run until the
            // scheduler has been started)
            sched.Start();
            log.Info("------- Started Scheduler -----------------");

            // wait long enough so that the scheduler as an opportunity to
            // run the job!
            log.Info("------- Waiting 65 seconds... -------------");

            // wait 65 seconds to show jobs
            Thread.Sleep(TimeSpan.FromSeconds(65));

            // shut down the scheduler
            log.Info("------- Shutting Down ---------------------");
            sched.Shutdown(true);
            log.Info("------- Shutdown Complete -----------------");
        }
Пример #5
0
        /// <summary>
        /// Main.
        /// </summary>
        public static void Main(string[] args)
        {
            // change from service account's dir to more logical one
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

            // TODO: Add DI config
            // TODO: Add Logger Config

            HostFactory.Run(x => {
                x.RunAsLocalSystem();

                x.SetDescription(Configuration.ServiceDescription);
                x.SetDisplayName(Configuration.ServiceDisplayName);
                x.SetServiceName(Configuration.ServiceName);

                x.Service(factory => {
                    QuartzServer server = QuartzServerFactory.CreateServer();
                    server.Initialize().GetAwaiter().GetResult();
                    return(server);
                });
            });
        }
Пример #6
0
        static void Main()
        {
            IQuartzServer server;

            try
            {
                server = QuartzServerFactory.CreateServer();
                server.Initialize();
                server.Start();
            }
            catch (Exception e)
            {
                System.Console.Write("Error starting server: " + e.Message);
                System.Console.WriteLine(e.ToString());
                System.Console.WriteLine("Hit any key to close");
                System.Console.Read();
                return;
            }

            System.Console.WriteLine(Environment.NewLine);
            System.Console.WriteLine("The scheduler will now run until you type \"exit\"");
            System.Console.WriteLine("   If it was configured to export itself via remoting,");
            System.Console.WriteLine("   then other process may now use it.");
            System.Console.WriteLine();

            while (true)
            {
                System.Console.WriteLine("Type 'exit' to shutdown the server: ");
                if ("exit".Equals(System.Console.ReadLine()))
                {
                    break;
                }
            }

            System.Console.WriteLine(Environment.NewLine + "...Shutting down server...");

            server.Stop();
        }
Пример #7
0
        public static void Initialize()
        {
            var container = new WindsorContainer();

            container
            .Register(Component.For <IJsonSerializer>().ImplementedBy <JsonSerializer>())
            .Register(Component.For <ExceptionInterceptor>().LifeStyle.PerWcfOperation())
            .Kernel.AddFacility <WcfFacility>();


            // WCF Config

            //Enables debugging and help information features for a Windows Communication Foundation (WCF) service.
            var returnFaults = new ServiceDebugBehavior
            {
                IncludeExceptionDetailInFaults = true,
                HttpHelpPageEnabled            = true
            };

            //Configures run-time throughput settings that enable you to tune service performance.
            var serviceThrottlingBehavior = new ServiceThrottlingBehavior
            {
                MaxConcurrentCalls     = 16,
                MaxConcurrentInstances = 10,
                MaxConcurrentSessions  = Int32.MaxValue
            };

            container.Register(Component.For <IServiceBehavior>().Instance(returnFaults));
            container.Register(Component.For <IServiceBehavior>().Instance(serviceThrottlingBehavior));


            container.Register(Component.For <ISchedulerService>()
                               .ImplementedBy <SchedulerService>().LifestyleTransient()
                               .Interceptors(InterceptorReference.ForType <ExceptionInterceptor>()).Anywhere
                               .AsWcfService(new DefaultServiceModel()
                                             .AddEndpoints(WcfEndpoint.BoundTo(new BasicHttpBinding
            {
                MaxReceivedMessageSize = 200000,
                MaxBufferSize          = 200000,
                MaxBufferPoolSize      = 200000,
            }
                                                                               ).At(ConfigurationManager.AppSettings.Get("QuartzSoapAddress") + "BasicHttpEndPoint"))
                                             .AddBaseAddresses(ConfigurationManager.AppSettings.Get("QuartzServiceUrl"))
                                             .PublishMetadata(extension => extension.EnableHttpGet())
                                             ));

            bool isAllValid = true;

            foreach (IHandler handler in container.Kernel.GetAssignableHandlers(typeof(object)))
            {
                if (handler.CurrentState != HandlerState.Valid)
                {
                    Console.WriteLine("HandlerState NOT Valid for : " + handler.ComponentModel.ComponentName + " - " + handler.CurrentState);
                    isAllValid = false;
                }
            }
            if (!isAllValid)
            {
                throw new Exception("Invalid components !");
            }
            IQuartzServer server = QuartzServerFactory.CreateServer();

            server.Initialize();

            server.Start();
        }