Ejemplo n.º 1
0
        private static void Main()
        {
            try
            {
                using (var terminationEvent = new ManualResetEvent(initialState: false))
                {
                    using (var diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("BookFast-Web-DiagnosticsPipeline"))
                    {
                        Console.CancelKeyPress += (sender, eventArgs) => Shutdown(diagnosticsPipeline, terminationEvent);

                        AppDomain.CurrentDomain.UnhandledException += (sender, unhandledExceptionArgs) =>
                        {
                            ServiceEventSource.Current.UnhandledException(unhandledExceptionArgs.ExceptionObject?.ToString() ?? "(no exception information)");
                            Shutdown(diagnosticsPipeline, terminationEvent);
                        };

                        ServiceRuntime.RegisterServiceAsync("WebAppType",
                                                            context => new WebApp(context)).GetAwaiter().GetResult();

                        ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(WebApp).Name);

                        terminationEvent.WaitOne();
                    }
                }
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                using (ManualResetEvent terminationEvent = new ManualResetEvent(initialState: false))
                    using (var diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("IoTDeviceSimulation-Cluster-DiagnosticsPipeline"))
                    {
                        // Ctrl-C signal is the standard way the Service Fabric runtime uses to notify service processes that they need to perform cleanup and exit.
                        // By default the process has 30 seconds to react.
                        // Using termination event lets event flow clean up ETW system-level events
                        Console.CancelKeyPress += (sender, eventArgs) => Shutdown(diagnosticsPipeline, terminationEvent);

                        AppDomain.CurrentDomain.UnhandledException += (sender, unhandledExceptionArgs) =>
                        {
                            ServiceEventSource.Current.UnhandledException(unhandledExceptionArgs.ExceptionObject?.ToString() ?? "(no exception information)");
                            Shutdown(diagnosticsPipeline, terminationEvent);
                        };

                        ServiceRuntime.RegisterServiceAsync("MonitoringServiceType",
                                                            context => new MonitoringService(context)).GetAwaiter().GetResult();

                        ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(MonitoringService).Name);

                        terminationEvent.WaitOne();
                    }
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 这是服务主机进程的入口点。
        /// </summary>
        private static void Main()
        {
            try
            {
                using (var pipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("SsoApp-ScanLoginService-DiagnosticsPipeline"))
                {
                    // ServiceManifest.XML 文件定义一个或多个服务类型名称。
                    // 注册服务会将服务类型名称映射到 .NET 类型。
                    // 在 Service Fabric 创建此服务类型的实例时,
                    // 会在此主机进程中创建类的实例。
                    var serviceType = typeof(Service).Namespace + "Type";
                    ServiceRuntime.RegisterServiceAsync(serviceType,
                                                        context => new Service(context, pipeline)).GetAwaiter().GetResult();

                    ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(Service).Name);

                    // 防止此主机进程终止,以使服务保持运行。
                    Thread.Sleep(Timeout.Infinite);
                }
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                // The ServiceManifest.XML file defines one or more service type names.
                // Registering a service maps a service type name to a .NET type.
                // When Service Fabric creates an instance of this service type,
                // an instance of the class is created in this host process.

                // **** Instantiate log collection via EventFlow
                using (var diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("ServiceFabricDemo.MailboxService-Mailbox"))
                {
                    ServiceRuntime.RegisterServiceAsync("MailboxType",
                                                        context => new Mailbox(context))
                    .GetAwaiter()
                    .GetResult();

                    ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id,
                                                                     typeof(Mailbox).Name);

                    // Prevents this host process from terminating so services keeps running.
                    Thread.Sleep(Timeout.Infinite);
                }
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        //private static void Main()
        //{
        //    using (var pipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("eventFlowConfig.json"))
        //    {
        //        ServiceRuntime.RegisterServiceAsync("ClusterMonitoringServiceType",
        //            context => new ClusterMonitoringService(context)).GetAwaiter().GetResult();

        //        // Prevents this host process from terminating so services keep running.
        //        Thread.Sleep(Timeout.Infinite);

        //    }
        //}

        public static void Main(string[] args)
        {
            try
            {
                using (ManualResetEvent terminationEvent = new ManualResetEvent(initialState: false))
                    using (var diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("MyApplication-MyService-DiagnosticsPipeline"))
                    {
                        Console.CancelKeyPress += (sender, eventArgs) => Shutdown(diagnosticsPipeline, terminationEvent);

                        AppDomain.CurrentDomain.UnhandledException += (sender, unhandledExceptionArgs) =>
                        {
                            ServiceEventSource.Current.UnhandledException(unhandledExceptionArgs.ExceptionObject?.ToString() ?? "(no exception information)");
                            Shutdown(diagnosticsPipeline, terminationEvent);
                        };

                        ServiceRuntime.RegisterServiceAsync("ClusterMonitoringServiceType",
                                                            context => new ClusterMonitoringService(context)).GetAwaiter().GetResult();

                        terminationEvent.WaitOne();
                    }
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                using (var pipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline(
                           "EapSfApp-AttachmentStateService-DiagnosticsPipeline"))
                {
                    // The ServiceManifest.XML file defines one or more service type names.
                    // Registering a service maps a service type name to a .NET type.
                    // When Service Fabric creates an instance of this service type,
                    // an instance of the class is created in this host process.

                    ServiceRuntime.RegisterServiceAsync("AttachmentStateServiceType",
                                                        context => new Service(context, pipeline)).GetAwaiter().GetResult();

                    ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(Service).Name);

                    // Prevents this host process from terminating so services keep running.
                    Thread.Sleep(Timeout.Infinite);
                }
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                // This line registers an Actor Service to host your actor class with the Service Fabric runtime.
                // The contents of your ServiceManifest.xml and ApplicationManifest.xml files
                // are automatically populated when you build this project.
                // For more information, see https://aka.ms/servicefabricactorsplatform
                // **** Instantiate log collection via EventFlow
                using (var diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("DCT.ILR.ValidationService.LearnerActor-pipeline"))
                {
                    // Start with the trusty old container builder.
                    var builder = new ContainerBuilder();

                    // Register any regular dependencies.
                    //builder.RegisterModule(new LoggerModule(ActorEventSource.Current.Message));
                    builder.RegisterModule <BusinessLogicAutofacModule>();
                    builder.RegisterModule <ValidationServiceServiceModuleSF>();

                    var config = new ESFA.DC.Logging.ApplicationLoggerSettings();
                    config.LoggerOutput = ESFA.DC.Logging.Enums.LogOutputDestination.SqlServer;
                    builder.RegisterType <ESFA.DC.Logging.SeriLogging.SeriLogger>().As <ESFA.DC.Logging.ILogger>()
                    .WithParameter(new TypedParameter(typeof(ESFA.DC.Logging.ApplicationLoggerSettings), config))
                    .InstancePerLifetimeScope();

                    builder.RegisterType <RuleManager>().As <IRuleManager>();
                    builder.RegisterType <RuleManagerValidationService>().As <IValidationService>().InstancePerLifetimeScope();


                    // Register the Autofac magic for Service Fabric support.
                    builder.RegisterServiceFabricSupport();

                    // Register the actor service.
                    builder.RegisterActor <LearnerActor>();

                    using (var container = builder.Build())
                    {
                        using (var childscope = container.BeginLifetimeScope())
                        {
                            var val = childscope.Resolve <IValidationService>();
                        }
                        Thread.Sleep(Timeout.Infinite);
                    }
                }

                // ActorRuntime.RegisterActorAsync<LearnerActor>(
                //(context, actorType) => new ActorService(context, actorType)).GetAwaiter().GetResult();
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            // The ServiceManifest.XML file defines one or more service type names.
            // Registering a service maps a service type name to a .NET type.
            // When Service Fabric creates an instance of this service type,
            // an instance of the class is created in this host process.
            using (var pipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("EventFlowDiagnosticPipeline"))
            {
                ServiceRuntime.RegisterServiceAsync("NodeDiagnosticsServiceType",
                                                    context => new NodeDiagnosticsService(context)).GetAwaiter().GetResult();

                // Prevents this host process from terminating so services keep running.
                Thread.Sleep(Timeout.Infinite);
            }
        }
        private void CodePackageActivationContext_ConfigurationPackageModifiedEvent(object sender, PackageModifiedEventArgs <ConfigurationPackage> e)
        {
            try
            {
                // Create diagnostic pipeline
                diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("LongRunningActors-EventCollectorService-DiagnosticsPipeline");

                // Log success
                ServiceEventSource.Current.Message("Diagnostics Pipeline successfully created.");
            }
            catch (Exception ex)
            {
                // Log exception
                ServiceEventSource.Current.Error(ex);
            }
        }
 /// <summary>
 /// This is the entry point of the service host process.
 /// </summary>
 private static void Main()
 {
     try
     {
         using (var diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("EventFlowTestApplication-Stateless1-DiagnosticsPipeline"))
         {
             ServiceRuntime.RegisterServiceAsync("Stateless1Type",
                                                 context => new Stateless1(context)).GetAwaiter().GetResult();
             ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(Stateless1).Name);
             Thread.Sleep(Timeout.Infinite);
         }
     }
     catch (Exception e)
     {
         ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
         throw;
     }
 }
        /// <summary>
        /// This is the main entry point for your service instance.
        /// </summary>
        /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service instance.</param>
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            try
            {
                while (true)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    if (diagnosticsPipeline == null)
                    {
                        try
                        {
                            // Create diagnostic pipeline
                            diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("LongRunningActors-EventCollectorService-DiagnosticsPipeline");

                            // Log success
                            ServiceEventSource.Current.Message("Diagnostics Pipeline successfully created.");
                        }
                        catch (Exception ex)
                        {
                            // Log exception
                            ServiceEventSource.Current.Error(ex);
                        }
                    }

                    await Task.Delay(TimeSpan.FromSeconds(10), cancellationToken);
                }
                // ReSharper disable once FunctionNeverReturns
            }
            finally
            {
                try
                {
                    diagnosticsPipeline?.Dispose();
                }
                catch (Exception ex)
                {
                    // Log exception
                    ServiceEventSource.Current.Error(ex);
                }
            }
        }
        /// <summary>
        /// is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                using (var diagnosticPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("Callcredit.Mastered-Data.Callcredit.Insolvencies.Service-Pipeline"))
                {
                    ServiceRuntime.RegisterServiceAsync("ApiType", context => new Service(context)).GetAwaiter().GetResult();

                    PlatformEventSource.Initialise("Callcredit.Mastered-Data.Callcredit.Insolvencies.Service.Platform");
                    PlatformEventSource.GetInstance().ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(Service).Name);

                    Thread.Sleep(Timeout.Infinite);
                }
            }
            catch (Exception e)
            {
                PlatformEventSource.GetInstance().ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                using (var pipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("EapSfApp-GroupFileService-DiagnosticsPipeline"))
                {
                    ServiceRuntime.RegisterServiceAsync("GroupFileServiceType",
                                                        context => new Service(context, pipeline)).GetAwaiter().GetResult();

                    ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(Service).Name);

                    // Prevents this host process from terminating so services keeps running.
                    Thread.Sleep(Timeout.Infinite);
                }
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }
        public static void Main(string[] args)
        {
            try
            {
                using (var pipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("PartyCluster.ClusterService"))
                {
                    ServiceRuntime.RegisterServiceAsync(
                        "ClusterServiceType",
                        context =>
                    {
                        IReliableStateManager stateManager = new ReliableStateManager(context);

                        return(new ClusterService(
#if LOCAL
                                   new FakeClusterOperator(stateManager),
                                   new FakeMailer(),
#else
                                   new ArmClusterOperator(context),
                                   new SendGridMailer(context),
#endif
                                   ServiceProxy.Create <IApplicationDeployService>(
                                       new ServiceUriBuilder("ApplicationDeployService").ToUri(),
                                       new ServicePartitionKey(0)),
                                   stateManager,
                                   context,
                                   new ClusterConfig()));
                    })
                    .GetAwaiter().GetResult();

                    ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(ClusterService).Name);

                    Thread.Sleep(Timeout.Infinite);
                }
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceHostInitializationFailed(e);
                throw;
            }
        }
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                // **** Instantiate log collection via EventFlow
                //
                using (var diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("StatelessWebType-DiagnosticsPipeline"))
                {
                    var loggerConfigurator = new EventFlowLoggerConfigurator(diagnosticsPipeline);

                    ServiceRuntime.RegisterServiceAsync("StatelessWebType", context => new StatelessWeb(context, loggerConfigurator)).GetAwaiter().GetResult();
                    ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(StatelessWeb).Name);

                    KeepServiceRunning();
                }
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                Program.UpdateEventFlowConfiguration();

                using (Program.DiagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("Azure.ServiceFabric.ASPNetCore.FriendsService"))
                {
                    ServiceRuntime.RegisterServiceAsync("FriendsServiceType", context => new FriendsService(context)).GetAwaiter().GetResult();

                    ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(FriendsService).Name);

                    // Prevents this host process from terminating so services keeps running.
                    Thread.Sleep(Timeout.Infinite);
                }
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                using (var pipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline(
                           "EapSfApp-NotifySessionActor-DiagnosticsPipeline"))
                {
                    // This line registers an Actor Service to host your actor class with the Service Fabric runtime.
                    // The contents of your ServiceManifest.xml and ApplicationManifest.xml files
                    // are automatically populated when you build this project.
                    // For more information, see https://aka.ms/servicefabricactorsplatform

                    ActorRuntime.RegisterActorAsync <TheActor>(
                        (context, actorType) => new TheActorService(context, actorType, pipeline)).GetAwaiter().GetResult();

                    Thread.Sleep(Timeout.Infinite);
                }
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                using (var pipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("PartyCluster.ApplicationDeployService"))
                {
                    ServiceRuntime.RegisterServiceAsync(
                        "ApplicationDeployServiceType",
                        context =>
                        new ApplicationDeployService(new ReliableStateManager(context), new FabricClientApplicationOperator(context), context)
                        )
                    .GetAwaiter().GetResult();

                    ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(ApplicationDeployService).Name);

                    Thread.Sleep(Timeout.Infinite); // Prevents this host process from terminating to keep the service host process running.
                }
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                // The ServiceManifest.XML file defines one or more service type names.
                // Registering a service maps a service type name to a .NET type.
                // When Service Fabric creates an instance of this service type,
                // an instance of the class is created in this host process.

                using (var diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("DCT.ILR.ValidationServiceStateless-pipeline"))
                {
                    // Start with the trusty old container builder.
                    var builder = new ContainerBuilder();

                    // Register any regular dependencies.
                    builder.RegisterModule <BusinessLogicAutofacModule>();
                    builder.RegisterModule <ValidationServiceServiceModuleSF>();

                    var config = new ESFA.DC.Logging.ApplicationLoggerSettings();
                    config.LoggerOutput = ESFA.DC.Logging.Enums.LogOutputDestination.SqlServer;
                    builder.RegisterType <ESFA.DC.Logging.SeriLogging.SeriLogger>().As <ESFA.DC.Logging.ILogger>()
                    .WithParameter(new TypedParameter(typeof(ESFA.DC.Logging.ApplicationLoggerSettings), config))
                    .InstancePerLifetimeScope();


                    var applicationInsightsKey = FabricRuntime.GetActivationContext()
                                                 .GetConfigurationPackageObject("Config")
                                                 .Settings
                                                 .Sections["ConfigurationSection"]
                                                 .Parameters["ApplicationInsightsKey"]
                                                 .Value;

                    var configurationOptions =
                        ConfigurationHelper.GetSectionValues <ConfigurationOptions>("ConfigurationSection");

                    var seviceBusOptions =
                        ConfigurationHelper.GetSectionValues <ServiceBusOptions>("ServiceBusSettings");


                    builder.RegisterInstance(configurationOptions).As <ConfigurationOptions>().SingleInstance();
                    builder.RegisterInstance(seviceBusOptions).As <ServiceBusOptions>().SingleInstance();



                    //var loggerFactory = new LoggerFactoryBuilder().CreateLoggerFactory(applicationInsightsKey);
                    //logger = loggerFactory.CreateLogger<MyStateless>();

                    builder.RegisterType <TopicHelper>().As <ITopicHelper>().InstancePerDependency();
                    builder.RegisterType <RuleManager>().As <IRuleManager>();
                    //builder.Register(c =>
                    //        new RuleManagerValidationService(c.Resolve<IRuleManager>(), c.Resolve<IFileData>()))
                    //    .As<IValidationService>().InstancePerLifetimeScope();
                    builder.RegisterType <RuleManagerValidationService>().As <IValidationService>().InstancePerLifetimeScope();

                    builder.RegisterInstance(new ActorsHelper()).As <IActorsHelper>();

                    // Register the Autofac magic for Service Fabric support.
                    builder.RegisterServiceFabricSupport();
                    // Register the stateless service.
                    builder.RegisterStatelessService <ValidationServiceStateless>("DCT.ILR.ValidationServiceStatelessType");

                    //ServiceRuntime.RegisterServiceAsync("DCT.ILR.VadationServiceStatefulType",
                    //    context => new VadationServiceStateful(context)).GetAwaiter().GetResult();

                    //ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(VadationServiceStateful).Name);

                    using (var container = builder.Build())
                    {
                        using (var newScope = container.BeginLifetimeScope())
                        {
                            var val = newScope.Resolve <IValidationService>();
                        }
                        ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(ValidationServiceStateless).Name);

                        // Prevents this host process from terminating so services keep running.
                        Thread.Sleep(Timeout.Infinite);
                    }
                }
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }