示例#1
0
        public async Task ChainNextActorAsync(ActorRequestContext nextActorRequestContext, object payload, Type typeOfPayload, ActorIdentity actorIdentity, CancellationToken cancellationToken)
        {
            if (actorIdentity?.ActorId == null || actorIdentity?.ActorServiceUri == null)
            {
                throw new ArgumentNullException($"MessagingActorClient failed at ChainNextActorAsync due to null of {nameof(actorIdentity)}. The client could not chain to next actor which is null.");
            }
            //put more logic on to the orchestration collection later. Now it is just get the single one
            var proxy = ActorProxy.Create <IBaseMessagingActor>(
                new ActorId(actorIdentity.ActorId),
                new Uri(actorIdentity.ActorServiceUri));

            var serializedPayload = _binaryMessageSerializer.SerializePayload(payload, typeOfPayload);

            try
            {
                await proxy.ChainProcessMessageAsync(nextActorRequestContext, serializedPayload, cancellationToken);
            }
            catch (System.Fabric.FabricServiceNotFoundException)
            {
                if (actorIdentity.ActorServiceUri.Equals(Constants.DetourConstants.DEFAULT_GENERIC_DETOUR_ACTOR,
                                                         StringComparison.OrdinalIgnoreCase))
                {
                    if ((dynamic)payload is DetourPayload detourPayload)
                    {
                        serializedPayload = _binaryMessageSerializer.SerializePayload(detourPayload.NextActorPayload);
                        proxy             = ActorProxy.Create <IBaseMessagingActor>(
                            new ActorId(detourPayload.NextActorId),
                            new Uri(detourPayload.DefaultNextActorUri));
                        await proxy.ChainProcessMessageAsync(nextActorRequestContext, serializedPayload, cancellationToken);
                    }
                }
                throw;
            }
        }
 protected virtual byte[] SerializePayload <T>(T entity)
 {
     try
     {
         return(BinaryMessageSerializer.SerializePayload(entity));
     }
     catch (Exception ex)
     {
         throw new ActorSerializationException($"{CurrentActor} failed to serialize data of type, error message {ex.Message}", ex, typeof(T));
     }
 }
        public Task <string> StoreMessageAsync(string key, object payload, Type typeOfPayload, CancellationToken cancellationToken)
        {
            var serializedData = BinaryMessageSerializer.SerializePayload(payload, typeOfPayload);
            var proxy          = ActorProxy.Create <IStorageActor>(new ActorId($"{NameCompositionResolver.ExtractFlowInstanceIdFromFlowVariableKey(key)}"), StorageServiceUri);

            return(proxy.SaveMessageAsync(new ActorRequestContext(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString()), key, serializedData, cancellationToken));
        }
        public async Task ChainNextActorAsync(ActorRequestContext nextActorRequestContext, object payload, Type typeOfPayload, ActorIdentity actorIdentity, CancellationToken cancellationToken)
        {
            if (actorIdentity?.ActorId == null || actorIdentity?.ActorServiceUri == null)
            {
                throw new ArgumentNullException($"MessagingActorClient failed at ChainNextActorAsync due to null of {nameof(actorIdentity)}. The client could not chain to next actor which is null.");
            }
            //put more logic on to the orchestration collection later. Now it is just get the single one
            var proxy = ActorProxy.Create <IBaseMessagingActor>(
                new ActorId(actorIdentity.ActorId),
                new Uri(actorIdentity.ActorServiceUri));

            var serializedPayload = _binaryMessageSerializer.SerializePayload(payload, typeOfPayload);
            await proxy.ChainProcessMessageAsync(nextActorRequestContext, serializedPayload, cancellationToken);
        }
        protected async Task ChainNextActorAsync(ActorRequestContext nextActorRequestContext, string startedPayload, object nextPayload, Type typeOfPayload, ExecutableOrchestrationOrder order, CancellationToken cancellationToken)
        {
            var flowInstanceId = nextActorRequestContext.FlowInstanceId;

            // var startedFlowInstanceId = new FlowInstanceId(Activity.Current.Id, (this.GetType().Name));
            var applicationName = Context.CodePackageActivationContext.ApplicationName;

            await TryCreateFlow(applicationName, flowInstanceId, startedPayload);

            var uri = new Uri(order.ActorServiceUri);

            //var startedFlowInstanceId = new FlowInstanceId(Activity.Current.Id, (this.GetType().Name));
            var proxy = ActorProxy.Create <IBaseMessagingActor>(order.ActorId == null ? ActorId.CreateRandom() : new ActorId(order.ActorId), uri);

            var payload = BinaryMessageSerializer.SerializePayload(nextPayload);
            await proxy.ChainProcessMessageAsync(nextActorRequestContext, payload, cancellationToken);
        }
示例#6
0
        /// <summary>
        /// This method will allow supports for Flow&Step involed in the implementation without a strong type expression of the interface
        /// This method also help when we have methodName resolved by a serialized Step
        /// </summary>
        /// <param name="methodName"></param>
        /// <param name="actorRequestContext"></param>
        /// <param name="arguments"></param>
        /// <returns></returns>
        private static async Task Invoke(string methodName, ActorRequestContext actorRequestContext, params object[] arguments)
        {
            if (actorRequestContext?.TargetActor == null)
            {
                throw new ArgumentNullException(INVALID_TARGET_ACTOR_ERROR_MESSAGE);
            }

            var serializableMethodInfo = new SerializableMethodInfo();

            serializableMethodInfo.MethodName = methodName;
            actorRequestContext.MethodName    = methodName;

            foreach (var arg in arguments)
            {
                serializableMethodInfo.Arguments.Add(new SerializableMethodArgument()
                {
                    ArgumentAssemblyType = arg.GetType().AssemblyQualifiedName,
                    Value = _binaryMessageSerializer.SerializePayload(arg)
                });
            }
            actorRequestContext.ActionName = actorRequestContext.ActionName;
            await _actorClient.ChainNextActorAsync <SerializableMethodInfo>(actorRequestContext, serializableMethodInfo, actorRequestContext.TargetActor, CancellationToken.None);
        }