Пример #1
0
 public HandlerEventSession(DEServer server, DEEventHandler eventHandler, string pathFilter, string[] eventFilter)
     : base(server)
 {
     this.eventHandler = new WeakReference <DEEventHandler>(eventHandler ?? throw new ArgumentNullException(nameof(eventHandler)));
     this.pathFilter   = pathFilter;
     SetEventFilter(eventFilter);
 }             // ctor
Пример #2
0
            public EventSession(DEServer server, IDEWebSocketContext context)
            {
                this.server  = server;
                this.context = context;

                server.AddEventSession(this);
            }             // ctor
Пример #3
0
            public SocketEventSession(DEServer server, IDEWebSocketScope context)
                : base(server)
            {
                this.context = context ?? throw new ArgumentNullException(nameof(context));

                synchronizationContext = SynchronizationContext.Current ?? throw new ArgumentNullException("SynchronizationContext.Current");
            }             // ctor
Пример #4
0
 public DEQueueScheduler(DEServer server)
     : base(server, "des_main")
 {
     this.server = server;
     this.cancellationTokenSource = new CancellationTokenSource();
     this.factory = new TaskFactory(cancellationTokenSource.Token, TaskCreationOptions.None, TaskContinuationOptions.ExecuteSynchronously, new QueueScheduler(this));
 }         // ctor
Пример #5
0
            public Service(string serviceName, DEServer app)
            {
                this.app            = app;
                this.app.ServiceLog = this;

                this.ServiceName                 = serviceName;
                this.AutoLog                     = true;
                this.CanHandlePowerEvent         = false;
                this.CanHandleSessionChangeEvent = false;
                this.CanPauseAndContinue         = false;
                this.CanShutdown                 = false;
                this.CanStop                     = true;
            }             // ctor
Пример #6
0
            public Service(string serviceName, DEServer app)
            {
                this.app            = app ?? throw new ArgumentNullException(nameof(app));
                this.app.ServiceLog = this;

                this.ServiceName                 = serviceName ?? throw new ArgumentNullException(nameof(serviceName));
                this.AutoLog                     = true;
                this.CanHandlePowerEvent         = false;
                this.CanHandleSessionChangeEvent = false;
                this.CanPauseAndContinue         = false;
                this.CanShutdown                 = false;
                this.CanStop                     = true;
            }             // ctor
Пример #7
0
        }         // proc AddToProcessEnvironment

        /// <summary>Eintrittspunkt in die Anwendung.</summary>
        /// <param name="args">Parameter die übergeben werden. Ungenutzt.</param>
        public static void Main(string[] args)
        {
#if DEBUG
            var readlineAtTheEnd = false;
#endif

            var printHeader = new Action(() =>
            {
                Console.WriteLine(HeadingInfo.Default.ToString());
                Console.WriteLine(CopyrightInfo.Default.ToString());
#if DEBUG
                readlineAtTheEnd = true;
#endif
            });

            try
            {
                var parser = new CommandLine.Parser(s =>
                {
                    s.CaseSensitive          = false;
                    s.IgnoreUnknownArguments = false;
                    s.HelpWriter             = null;
                    s.ParsingCulture         = CultureInfo.InvariantCulture;
                });

                // work with arguments
                var r = parser.ParseArguments(args, new Type[] { typeof(RunOptions), typeof(RegisterOptions), typeof(UnregisterOptions) });
                r.MapResult <RunOptions, RegisterOptions, UnregisterOptions, bool>(
                    opts =>                      // run
                {
                    // print heading
                    if (opts.Verbose)
                    {
                        printHeader();
                    }

                    // validate arguments
                    opts.Validate();

                    // execute the service
                    var app = new DEServer(opts.ConfigurationFile, opts.Properties);
                    if (opts.Verbose)                             // Run the console version of the service
                    {
                        app.ServiceLog = new ConsoleLog();
                        app.OnStart();
                        Console.WriteLine("Service is started.");
                        Console.ReadLine();
                        app.OnStop();
                    }
                    else
                    {
                        ServiceBase.Run(new Service(ServicePrefix + opts.ServiceName, app));                                 // Start as a windows service
                    }

                    return(true);
                },
                    opts =>                     // register
                {
                    // print heading
                    printHeader();

                    // validate arguments
                    opts.Validate();

                    // form the run command line
                    var runOpts            = new RunOptions(opts);
                    var serviceCommandLine = parser.FormatCommandLine(runOpts, o => { o.PreferShortName = true; });

                    // register the service
                    RegisterService(opts.ServiceName, serviceCommandLine);
                    Console.WriteLine("Service '{0}{1}' created/modified.", ServicePrefix, opts.ServiceName);

                    return(true);
                },
                    opts =>                     // unregister
                {
                    // print heading
                    printHeader();

                    UnregisterService(opts.ServiceName);
                    Console.WriteLine("Service '{0}{1}' removed.", ServicePrefix, opts.ServiceName);

                    return(true);
                },
                    errors =>
                {
                    // print help
                    var help = CommandLine.Text.HelpText.AutoBuild(r);

                    if (errors.FirstOrDefault(e => e is HelpVerbRequestedError) != null)
                    {
                        help.AddPreOptionsLine(Environment.NewLine + "Usage:");
                        help.AddPreOptionsLine("  DEServer.exe run -v -c [configuration file] -n [name] {properties}");
                        help.AddPreOptionsLine("  DEServer.exe register -c [configuration file] -n [name] {properties}");
                        help.AddPreOptionsLine("  DEServer.exe unregister --name [name] ");
                    }
                    if (errors.FirstOrDefault(e => e is VersionRequestedError) != null)
                    {
                        // todo: add detailed version info
                        help.AddPostOptionsLine("Assembly version: todo");
                    }

                    Console.WriteLine(help.ToString());
                    return(false);
                }
                    );
            }
            catch (Exception e)
            {
                Console.WriteLine(e.GetMessageString());
#if DEBUG
                if (readlineAtTheEnd)
                {
                    Console.ReadLine();
                }
#endif
            }
        } // proc Main
Пример #8
0
            protected EventSession(DEServer server)
            {
                this.server = server ?? throw new ArgumentNullException(nameof(server));

                server.AddEventSession(this);
            }             // ctor
Пример #9
0
 public DEQueueScheduler(DEServer server)
     : base(server, "des_main", priority: ThreadPriority.BelowNormal)
 {
     this.server = server;
 }         // ctor