Ejemplo n.º 1
0
        private async void button_AddNumbers_Click(object sender, EventArgs e)
        {
            //int number1 = int.Parse(textBox_Number1.Text);
            //int number2 = int.Parse(textBox_Number2.Text);

            //var uri = _evilMathServiceUri;

            int number1 = 10;
            int number2 = 100;

            Uri uri = new Uri("fabric:/SampleSFV2/EvilMathTeacherService");

            ServiceProxyFactory proxyFactory = new ServiceProxyFactory((c) =>
            {
                FabricTransportRemotingSettings settings = new FabricTransportRemotingSettings();
                return(new FabricTransportServiceRemotingClientFactory(settings));
            });

            try
            {
                IQuestionnaire service = proxyFactory.CreateServiceProxy <IQuestionnaire>(uri, listenerName: "Questionnaire_v2");
                int            result  = await service.AddTwoNumbers(number1, number2);

                MessageBox.Show("Result= " + result);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 2
0
        private static ActorRemotingSerializationManager IntializeSerializationManager(IServiceRemotingMessageSerializationProvider serializationProvider, FabricTransportRemotingSettings settings)
        {
            settings = settings ?? FabricTransportRemotingSettings.GetDefault();

            return(new ActorRemotingSerializationManager(serializationProvider,
                                                         new ActorRemotingMessageHeaderSerializer(settings.HeaderBufferSize, settings.HeaderMaxBufferCount)));
        }
        internal CorrelatingFabricTransportServiceRemotingClientFactory(
            FabricTransportRemotingSettings remotingSettings = null,
            IServiceRemotingCallbackMessageHandler remotingCallbackMessageHandler = null,
            IServicePartitionResolver servicePartitionResolver = null,
            IEnumerable <IExceptionHandler> exceptionHandlers  = null,
            string traceId = null,
            IServiceRemotingMessageSerializationProvider serializationProvider = null,
            IServiceRemotingClientFactory inner = null,
            Action <CallSummary> raiseSummary   = null,
            string remoteServiceName            = null)
        {
            if (inner == null)
            {
                inner = new FabricTransportServiceRemotingClientFactory(
                    remotingSettings,
                    remotingCallbackMessageHandler,
                    servicePartitionResolver,
                    exceptionHandlers,
                    traceId,
                    serializationProvider);
            }

            _inner             = inner;
            _raiseSummary      = raiseSummary;
            _remoteServiceName = remoteServiceName ?? "unknown";
        }
        private void Initialize(FabricTransportRemotingSettings remotingSettings,
                                IServiceRemotingCallbackMessageHandler remotingCallbackMessageHandler,
                                IServicePartitionResolver servicePartitionResolver,
                                IEnumerable <IExceptionHandler> exceptionHandlers,
                                string traceId,
                                IServiceRemotingMessageSerializationProvider serializationProvider,
                                IServiceRemotingMessageHeaderSerializer headerSerializer = null)
        {
            remotingSettings = remotingSettings ?? FabricTransportRemotingSettings.GetDefault();

            if (headerSerializer == null)
            {
                headerSerializer = new ServiceRemotingMessageHeaderSerializer(new BufferPoolManager(remotingSettings.HeaderBufferSize, remotingSettings.HeaderMaxBufferCount));
            }

            var serializersManager = new ServiceRemotingMessageSerializersManager(serializationProvider,
                                                                                  headerSerializer);


            this.Initialize(remotingSettings,
                            remotingCallbackMessageHandler,
                            servicePartitionResolver,
                            exceptionHandlers,
                            traceId,
                            serializersManager.GetSerializationProvider().CreateMessageBodyFactory(),
                            serializersManager);
        }
Ejemplo n.º 5
0
        public ValidationServiceStateless(StatelessServiceContext context, ILifetimeScope parentLifeTimeScope,
                                          ILogger logger, ITopicHelper topicHelper, ServiceBusOptions seviceBusOptions,
                                          Func <IValidationService> validationServiceFactory, IActorsHelper actorsHelper)
            : base(context)
        {
            _parentLifeTimeScope = parentLifeTimeScope;

            //get config values
            _queueName = seviceBusOptions.QueueName;
            _serviceBusConnectionString = seviceBusOptions.ServiceBusConnectionString;
            _fundingCalcSqlFilterValue  = seviceBusOptions.FundingCalcSqlFilterValue;

            _actorsHelper = actorsHelper;
            //using serviceremoting v2
            _valResultsServiceProxyFactory = new ServiceProxyFactory(
                (c) => new FabricTransportServiceRemotingClientFactory(
                    remotingSettings: FabricTransportRemotingSettings.LoadFrom("DataTransportSettings"),
                    remotingCallbackMessageHandler: null, servicePartitionResolver: null, exceptionHandlers: null,
                    traceId: null,
                    serializationProvider: new ServiceRemotingJsonSerializationProvider()));



//            _logger = logger;
            _topicHelper = topicHelper;

            _validationServiceFactory = validationServiceFactory;
        }
Ejemplo n.º 6
0
        private async void button_AddMathService_Click(object sender, EventArgs e)
        {
            int number1 = int.Parse(textBox_MathServiceNumber1.Text);
            int number2 = int.Parse(textBox_MathServiceNumber2.Text);

            //var uri = new Uri("fabric:/SampleSFV2/MathService");
            ServiceProxyFactory proxyFactory = new ServiceProxyFactory((c) =>
            {
                FabricTransportRemotingSettings settings = new FabricTransportRemotingSettings();
                return(new FabricTransportServiceRemotingClientFactory(settings));
            });

            try
            {
                IMathCalculator service = proxyFactory.CreateServiceProxy <IMathCalculator>(_mathServiceUri, listenerName: "MathCalculator_v2");

                int result = await service.Add(number1, number2);

                MessageBox.Show("Result= " + result);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 7
0
 public CorrelatingFabricTransportServiceRemotingClientFactory(
     FabricTransportRemotingSettings remotingSettings = null,
     IServiceRemotingCallbackMessageHandler remotingCallbackMessageHandler = null,
     IServicePartitionResolver servicePartitionResolver = null,
     IEnumerable <IExceptionHandler> exceptionHandlers  = null,
     string traceId = null,
     IServiceRemotingMessageSerializationProvider serializationProvider = null) :
     this(remotingSettings, remotingCallbackMessageHandler, servicePartitionResolver, exceptionHandlers, traceId, serializationProvider, null)
 {
 }
        /// <summary>
        ///  FabricTransportSettings returns the default Settings .Loads the configuration file from default Config Package"Config" , if not found then try to load from  default config file "ClientExeName.Settings.xml"  from Client Exe directory.
        /// </summary>
        /// <param name="sectionName">Name of the section within the configuration file. If not found section in configuration file, it will return the default Settings</param>
        /// <returns></returns>
        private static FabricTransportRemotingSettings GetDefaultFabricTransportSettings(string sectionName = "TransportSettings")
        {
            var settings = (FabricTransportRemotingSettings)null;

            if (!FabricTransportRemotingSettings.TryLoadFrom(sectionName, out settings, (string)null, (string)null))
            {
                settings = new FabricTransportRemotingSettings();
            }
            return(settings);
        }
Ejemplo n.º 9
0
        public static IServiceProxyFactory CreateProxyFactoryFabricTransport()
        {
            var settings = new FabricTransportRemotingSettings();

            settings.OperationTimeout = TimeSpan.FromMinutes(1);
            return(new ServiceProxyFactory(
                       (h) =>
            {
                return new FabricTransportServiceRemotingClientFactory(settings);
            }));
        }
        /// <summary>
        ///     Creates a service remoting client factory to connect to the remoted actor interfaces.
        /// </summary>
        /// <param name="callbackClient">
        ///     Client implementation where the callbacks should be dispatched.
        /// </param>
        /// <returns>
        ///     A <see cref="Microsoft.ServiceFabric.Actors.Remoting.FabricTransport.FabricTransportActorRemotingClientFactory "/>
        ///     as <see cref="Microsoft.ServiceFabric.Services.Remoting.Client.IServiceRemotingClientFactory"/>
        ///     that can be used with <see cref="Microsoft.ServiceFabric.Actors.Client.ActorProxyFactory"/> to
        ///     generate actor proxy to talk to the actor over remoted actor interface.
        /// </returns>
        public override IServiceRemotingClientFactory CreateServiceRemotingClientFactory(
            IServiceRemotingCallbackClient callbackClient)
        {
            var settings = FabricTransportRemotingSettings.GetDefault();

            settings.MaxMessageSize   = this.GetAndValidateMaxMessageSize(settings.MaxMessageSize);
            settings.OperationTimeout = this.GetandValidateOperationTimeout(settings.OperationTimeout);
            settings.KeepAliveTimeout = this.GetandValidateKeepAliveTimeout(settings.KeepAliveTimeout);
            settings.ConnectTimeout   = this.GetConnectTimeout(settings.ConnectTimeout);
            return(new FabricTransportActorRemotingClientFactory(settings, callbackClient));
        }
        private static ServiceProxyFactory CreateFactory()
        {
            if (!FabricTransportRemotingSettings.TryLoadFrom(
                    "TransportSettings",
                    out FabricTransportRemotingSettings transportSettings))
            {
                transportSettings = new FabricTransportRemotingSettings();
            }

            return(new ServiceProxyFactory(
                       handler => new ActivityServiceRemotingClientFactory(
                           new FabricTransportServiceRemotingClientFactory(transportSettings, handler))));
        }
Ejemplo n.º 12
0
        public async Task <int> AddTwoNumbers(int a, int b)
        {
            var uri          = new Uri("fabric:/SampleSFV2/MathService");
            var proxyFactory = new ServiceProxyFactory((c) =>
            {
                var settings = new FabricTransportRemotingSettings();
                return(new FabricTransportServiceRemotingClientFactory(settings));
            });

            var service = proxyFactory.CreateServiceProxy <IMathCalculator>(uri, listenerName: "MathCalculator_v2");

            return(await service.Add(a, b));
        }
        public static ServiceProxyFactory GetServiceProxyFactory()
        {
            FabricTransportRemotingSettings transportSettings = new FabricTransportRemotingSettings
            {
                OperationTimeout   = TimeSpan.FromSeconds(600),
                MaxMessageSize     = 1000000,
                MaxConcurrentCalls = 100
            };
            var retrySettings = new OperationRetrySettings(TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(3), 5);
            var clientFactory = new FabricTransportServiceRemotingClientFactory(transportSettings);

            return(new ServiceProxyFactory((c) => clientFactory, retrySettings));
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Constructs a fabric transport based actor remoting client factory.
 /// </summary>
 /// <param name="fabricTransportRemotingSettings">
 ///     The settings for the fabric transport. If the settings are not provided or null, default settings
 ///     with no security.
 /// </param>
 /// <param name="callbackClient">
 ///     The callback client that receives the callbacks from the service.
 /// </param>
 /// <param name="servicePartitionResolver">
 ///     Service partition resolver to resolve the service endpoints. If not specified, a default
 ///     service partition resolver returned by <see cref="ServicePartitionResolver.GetDefault"/> is used.
 /// </param>
 /// <param name="exceptionHandlers">
 ///     Exception handlers to handle the exceptions encountered in communicating with the actor.
 /// </param>
 /// <param name="traceId">
 ///     Id to use in diagnostics traces from this component.
 /// </param>
 public FabricTransportActorRemotingClientFactory(
     FabricTransportRemotingSettings fabricTransportRemotingSettings,
     IServiceRemotingCallbackClient callbackClient,
     IServicePartitionResolver servicePartitionResolver = null,
     IEnumerable <IExceptionHandler> exceptionHandlers  = null,
     string traceId = null) :
     base(
         fabricTransportRemotingSettings,
         callbackClient,
         servicePartitionResolver,
         GetExceptionHandlers(exceptionHandlers),
         traceId)
 {
 }
 public FabricTransportServiceRemotingClientFactoryImpl(
     Remoting.FabricTransport.FabricTransportRemotingSettings fabricTransportRemotingSettings = null,
     IServiceRemotingCallbackClient callbackHandler     = null,
     IServicePartitionResolver servicePartitionResolver = null,
     IEnumerable <IExceptionHandler> exceptionHandlers  = null,
     string traceId = null)
     : base(
         servicePartitionResolver,
         GetExceptionHandlers(exceptionHandlers),
         traceId)
 {
     this.settings = fabricTransportRemotingSettings ?? FabricTransportRemotingSettings.GetDefault();
     this.fabricTransportRemotingCallbackMessageHandler =
         new FabricTransportRemotingCallbackMessageHandler(callbackHandler);
 }
Ejemplo n.º 16
0
        public async Task <bool> CheckIfTwoNumbersAreEqual(int a, int b)
        {
            var text1 = a.ToString();
            var text2 = b.ToString();

            var uri          = new Uri("fabric:/SampleSFV2/MathService");
            var proxyFactory = new ServiceProxyFactory((c) =>
            {
                var settings = new FabricTransportRemotingSettings();
                return(new FabricTransportServiceRemotingClientFactory(settings));
            });

            var service = proxyFactory.CreateServiceProxy <ITextManipulator>(uri, listenerName: "TextManipulator_v2");

            return(await service.IfEqual(text1, text2));
        }
 internal FabricTransportServiceRemotingClientFactory(
     ServiceRemotingMessageSerializersManager serializersManager,
     FabricTransportRemotingSettings remotingSettings = null,
     IServiceRemotingCallbackMessageHandler remotingCallbackMessageHandler = null,
     IServicePartitionResolver servicePartitionResolver = null,
     IEnumerable <IExceptionHandler> exceptionHandlers  = null,
     string traceId = null)
 {
     this.Initialize(remotingSettings,
                     remotingCallbackMessageHandler,
                     servicePartitionResolver,
                     exceptionHandlers,
                     traceId,
                     serializersManager.GetSerializationProvider().CreateMessageBodyFactory(),
                     serializersManager);
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Constructs a fabric transport based actor remoting client factory.
        /// </summary>
        /// <param name="fabricTransportRemotingSettings">
        ///     The settings for the fabric transport. If the settings are not provided or null, default settings
        ///     with no security.
        /// </param>
        /// <param name="callbackMessageHandler">
        ///     The callback client that receives the callbacks from the service.
        /// </param>
        /// <param name="servicePartitionResolver">
        ///     Service partition resolver to resolve the service endpoints. If not specified, a default
        ///     service partition resolver returned by <see cref="ServicePartitionResolver.GetDefault"/> is used.
        /// </param>
        /// <param name="exceptionHandlers">
        ///     Exception handlers to handle the exceptions encountered in communicating with the actor.
        /// </param>
        /// <param name="traceId">
        ///     Id to use in diagnostics traces from this component.
        /// </param>
        /// <param name="serializationProvider"></param>
        public FabricTransportActorRemotingClientFactory(
            FabricTransportRemotingSettings fabricTransportRemotingSettings,
            IServiceRemotingCallbackMessageHandler callbackMessageHandler,
            IServicePartitionResolver servicePartitionResolver = null,
            IEnumerable <IExceptionHandler> exceptionHandlers  = null,
            string traceId = null,
            IServiceRemotingMessageSerializationProvider serializationProvider = null) :
            base(IntializeSerializationManager(serializationProvider, fabricTransportRemotingSettings),
                 fabricTransportRemotingSettings,
                 callbackMessageHandler,
                 servicePartitionResolver,
                 GetExceptionHandlers(exceptionHandlers),
                 traceId)

        {
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="remotingSettings"></param>
 /// <param name="remotingCallbackMessageHandler"></param>
 /// <param name="servicePartitionResolver"></param>
 /// <param name="exceptionHandlers"></param>
 /// <param name="traceId"></param>
 /// <param name="serializersManager"></param>
 public FabricTransportServiceRemotingClientFactoryImpl(
     ServiceRemotingMessageSerializersManager serializersManager,
     FabricTransportRemotingSettings remotingSettings,
     IServiceRemotingCallbackMessageHandler remotingCallbackMessageHandler = null,
     IServicePartitionResolver servicePartitionResolver = null,
     IEnumerable <IExceptionHandler> exceptionHandlers  = null,
     string traceId = null)
     : base(
         servicePartitionResolver,
         GetExceptionHandlers(exceptionHandlers),
         traceId)
 {
     this.settings           = remotingSettings ?? FabricTransportRemotingSettings.GetDefault();
     this.serializersManager = serializersManager;
     this.disposer           = new NativeFabricTransportMessageDisposer();
     this.fabricTransportRemotingCallbackMessageHandler = new FabricTransportRemotingCallbackMessageHandler(remotingCallbackMessageHandler, this.serializersManager);
 }
Ejemplo n.º 20
0
        /// <summary>
        ///     Creates a service remoting client factory to connect to the remoted actor interfaces.
        /// </summary>
        /// <param name="callbackClient">
        ///     Client implementation where the callbacks should be dispatched.
        /// </param>
        /// <returns>
        ///     A <see cref="T:Microsoft.ServiceFabric.Actors.Remoting.FabricTransport.FabricTransportActorRemotingClientFactory" />
        ///     as <see cref="T:Microsoft.ServiceFabric.Services.Remoting.Client.IServiceRemotingClientFactory" />
        ///     that can be used with <see cref="T:Microsoft.ServiceFabric.Actors.Client.ActorProxyFactory" /> to
        ///     generate actor proxy to talk to the actor over remoted actor interface.
        /// </returns>
        public override IServiceRemotingClientFactory CreateServiceRemotingClientFactory(IServiceRemotingCallbackClient callbackClient)
        {
            //Microsoft.ServiceFabric.Services.Remoting.FabricTransport.FabricTransportRemotingSettings
            FabricTransportRemotingSettings fabricTransportSettings = GetDefaultFabricTransportSettings("TransportSettings");

            fabricTransportSettings.MaxMessageSize   = this.GetAndValidateMaxMessageSize(fabricTransportSettings.MaxMessageSize);
            fabricTransportSettings.OperationTimeout = this.GetandValidateOperationTimeout(fabricTransportSettings.OperationTimeout);
            fabricTransportSettings.KeepAliveTimeout = this.GetandValidateKeepAliveTimeout(fabricTransportSettings.KeepAliveTimeout);
            var exceptionHandlers = GetExceptionHandlers();

            return((IServiceRemotingClientFactory) new CodeEffect.ServiceFabric.Actors.Remoting.FabricTransport.Client.FabricTransportActorRemotingClientFactory(
                       new FabricTransportActorRemotingClientFactory(
                           fabricTransportSettings,
                           callbackClient,
                           (IServicePartitionResolver)null,
                           exceptionHandlers,
                           traceId: (string)null), null));
        }
 private void Initialize(FabricTransportRemotingSettings remotingSettings,
                         IServiceRemotingCallbackMessageHandler remotingCallbackMessageHandler,
                         IServicePartitionResolver servicePartitionResolver,
                         IEnumerable <IExceptionHandler> exceptionHandlers,
                         string traceId,
                         IServiceRemotingMessageBodyFactory messageBodyFactory,
                         ServiceRemotingMessageSerializersManager serializersManager)
 {
     this.remotingMessageBodyFactory = messageBodyFactory;
     this.clientFactoryImpl          = new FabricTransportServiceRemotingClientFactoryImpl(
         serializersManager,
         remotingSettings,
         remotingCallbackMessageHandler,
         servicePartitionResolver,
         exceptionHandlers,
         traceId
         );
     this.clientFactoryImpl.ClientConnected    += this.OnClientConnected;
     this.clientFactoryImpl.ClientDisconnected += this.OnClientDisconnected;
 }
Ejemplo n.º 22
0
        internal CorrelatingFabricTransportServiceRemotingClientFactory(
            FabricTransportRemotingSettings remotingSettings = null,
            IServiceRemotingCallbackMessageHandler remotingCallbackMessageHandler = null,
            IServicePartitionResolver servicePartitionResolver = null,
            IEnumerable <IExceptionHandler> exceptionHandlers  = null,
            string traceId = null,
            IServiceRemotingMessageSerializationProvider serializationProvider = null,
            IServiceRemotingClientFactory inner = null)
        {
            if (inner == null)
            {
                inner = new FabricTransportServiceRemotingClientFactory(
                    remotingSettings,
                    remotingCallbackMessageHandler,
                    servicePartitionResolver,
                    exceptionHandlers,
                    traceId,
                    serializationProvider);
            }

            _inner = inner;
        }
        /// <summary>
        ///     Constructs a fabric transport based service remoting client factory.
        /// </summary>
        /// <param name="FabricTransportRemotingSettings">
        ///     The settings for the fabric transport. If the settings are not provided or null, default settings
        ///     with no security.
        /// </param>
        /// <param name="callbackClient">
        ///     The callback client that receives the callbacks from the service.
        /// </param>
        /// <param name="servicePartitionResolver">
        ///     Service partition resolver to resolve the service endpoints. If not specified, a default
        ///     service partition resolver returned by <see cref="ServicePartitionResolver.GetDefault"/> is used.
        /// </param>
        /// <param name="exceptionHandlers">
        ///     Exception handlers to handle the exceptions encountered in communicating with the service.
        /// </param>
        /// <param name="traceId">
        ///     Id to use in diagnostics traces from this component.
        /// </param>
        /// <remarks>
        ///     This factory uses an internal fabric transport exception handler to handle exceptions at the fabric TCP transport
        ///     level and a <see cref="ServiceRemotingExceptionHandler"/>, in addition to the exception handlers supplied to the
        ///     constructor.
        /// </remarks>
        public FabricTransportServiceRemotingClientFactory(
            FabricTransportRemotingSettings FabricTransportRemotingSettings = null,
            IServiceRemotingCallbackClient callbackClient      = null,
            IServicePartitionResolver servicePartitionResolver = null,
            IEnumerable <IExceptionHandler> exceptionHandlers  = null,
            string traceId = null)
        {
            if (traceId == null)
            {
                traceId = Guid.NewGuid().ToString();
            }


            this.impl = new FabricTransportServiceRemotingClientFactoryImpl(
                FabricTransportRemotingSettings,
                callbackClient,
                servicePartitionResolver,
                GetExceptionHandlers(exceptionHandlers, traceId),
                traceId
                );
            this.impl.FabricTransportClientConnected    += this.OnClientConnected;
            this.impl.FabricTransportClientDisconnected += this.OnClientDisconnected;
        }
Ejemplo n.º 24
0
        public static T CreateServiceProxyWithCorrelation <T>(string serviceAddress)
            where T : IService
        {
            var sfrRetryInterval = TimeSpan.Parse(ConfigurationManager.AppSettings.GetRefValue <string>("ServiceFabricRemoting_OperationRetryInterval"));
            var sfrRetryCount    = int.Parse(ConfigurationManager.AppSettings.GetRefValue <string>("ServiceFabricRemoting_OperationRetryCount"));
            var sfrTimeout       = TimeSpan.Parse(ConfigurationManager.AppSettings.GetRefValue <string>("ServiceFabricRemoting_OperationTimeout"));

            var fabricTransportRemotingSettings = new FabricTransportRemotingSettings
            {
                OperationTimeout = sfrTimeout
            };

            var operationRetrySettings = new OperationRetrySettings(sfrRetryInterval, sfrRetryInterval, sfrRetryCount);

            // read https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-communication-remoting
            // _dependencyClient = ServiceProxy.Create<IDependency>(new Uri(serviceAddress));

            var proxyFactory = new CorrelatingServiceProxyFactory(
                callbackClient => new FabricTransportServiceRemotingClientFactory(
                    callbackClient: callbackClient,
                    FabricTransportRemotingSettings: fabricTransportRemotingSettings), retrySettings: operationRetrySettings);

            return(proxyFactory.CreateServiceProxy <T>(new Uri(serviceAddress)));
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Constructs a fabric transport based actor remoting client factory.
 /// </summary>
 /// <param name="callbackMessageHandler">
 ///     The callback client that receives the callbacks from the service.
 /// </param>
 public FabricTransportActorRemotingClientFactory(
     IServiceRemotingCallbackMessageHandler callbackMessageHandler)
     : this(FabricTransportRemotingSettings.GetDefault(), callbackMessageHandler)
 {
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Constructs a fabric transport based actor remoting client factory.
 /// </summary>
 /// <param name="callbackClient">
 ///     The callback client that receives the callbacks from the service.
 /// </param>
 public FabricTransportActorRemotingClientFactory(
     IServiceRemotingCallbackClient callbackClient)
     : this(FabricTransportRemotingSettings.GetDefault(), callbackClient)
 {
 }
Ejemplo n.º 27
0
        /// <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.

                // Start with the trusty old container builder.
                var builder = new ContainerBuilder();

                // Register any regular dependencies.


                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();

                //get the config values and register in container
                var fundingActorOptions =
                    ConfigurationHelper.GetSectionValues <ActorOptions>("FundingActorsSection");
                builder.RegisterInstance(fundingActorOptions).As <ActorOptions>().SingleInstance();

                var dataServiceOptions =
                    ConfigurationHelper.GetSectionValues <DataServiceOptions>("DataServiceSection");
                builder.RegisterInstance(dataServiceOptions).As <DataServiceOptions>().SingleInstance();

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


                //store proxy factory in container
                var serviceProxyFactory = new ServiceProxyFactory(
                    (c) => new FabricTransportServiceRemotingClientFactory(
                        remotingSettings: FabricTransportRemotingSettings.LoadFrom("DataTransportSettings"),
                        remotingCallbackMessageHandler: null, servicePartitionResolver: null, exceptionHandlers: null,
                        traceId: null,
                        serializationProvider: new ServiceRemotingJsonSerializationProvider()));

                builder.RegisterInstance(serviceProxyFactory).As <ServiceProxyFactory>().SingleInstance();

                builder.RegisterType <FundingCalcManager>().As <IFundingCalcManager>().InstancePerLifetimeScope();


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

                builder.Register(c =>
                {
                    var ctx = c.Resolve <StatelessServiceContext>();
                    return(ctx.CodePackageActivationContext.ApplicationName);
                }).Named <string>("ApplicationName");

                //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 childlifetime = container.BeginLifetimeScope())
                    {
                        var s = childlifetime.Resolve <IFundingCalcManager>();
                    }

                    //var logger = container.Resolve<ESFA.DC.Logging.ILogger>();
                    ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(FundingCalcService).Name);

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