예제 #1
0
        public async Task SetTitleAsync(string title, CancellationToken cancellationToken)
        {
            _actorDomainLoggerFactory().TitleSet(title);

            await this.StateManager.AddOrUpdateStateAsync(DomainStateName, new Person()
            {
                Name = this.GetActorId().GetStringId(), Title = title
            }, (key, value) => new Person()
            {
                Name = value.Name, Title = title
            }, CancellationToken.None);

            var serviceProxyFactory = new FG.ServiceFabric.Services.Remoting.Runtime.Client.ServiceProxyFactory(_communicationLoggerFactory());
            var serviceProxy        = serviceProxyFactory.CreateServiceProxy <ITitleService>(
                new Uri($"{this.ActorService.Context.CodePackageActivationContext.ApplicationName}/TitleService"),
                new ServicePartitionKey(0));

            await serviceProxy.UpdateTitleAsync(this.GetActorId().GetStringId(), title, cancellationToken);
        }
예제 #2
0
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            while (true)
            {
                foreach (var name in ObjectMother.Names)
                {
                    var correlationId = Guid.NewGuid().ToString();
                    using (new ServiceRequestContextWrapperX(correlationId, Environment.UserName))
                    {
                        var serviceLogger       = _serviceLoggerFactory();
                        var communicationLogger = _communicationLoggerFactory();
                        using (serviceLogger.RunAsyncLoop())
                        {
                            try
                            {
                                var serviceProxyFactory = new FG.ServiceFabric.Services.Remoting.Runtime.Client.ServiceProxyFactory(communicationLogger);
                                var serviceProxy        = serviceProxyFactory.CreateServiceProxy <ITitleService>(
                                    new Uri($"{this.Context.CodePackageActivationContext.ApplicationName}/TitleService"),
                                    new ServicePartitionKey(0));
                                var titles = await serviceProxy.GetTitlesAsync(cancellationToken);

                                var title = titles[Environment.TickCount % titles.Length];

                                var actorProxyFactory = new ActorProxyFactory(communicationLogger);
                                var proxy             = actorProxyFactory.CreateActorProxy <IPersonActor>(new ActorId(name));
                                await proxy.SetTitleAsync(title, cancellationToken);

                                serviceLogger.PersonGenerated(name, title);
                            }
                            catch (Exception ex)
                            {
                                serviceLogger.RunAsyncLoopFailed(ex);
                            }
                        }
                    }

                    await Task.Delay(10000, cancellationToken);
                }
            }
        }