public void AddTask(object xcEvent, object publicMember, object internalMember,
                            object context, object sender, [CallerMemberName] string functionName = null)
        {
            RegisterSender(sender);

            var functionParameter = FunctionParameterFactory.CreateFunctionParameter(xcEvent,
                                                                                     publicMember,
                                                                                     internalMember,
                                                                                     context, ComponentName,
                                                                                     StateMachineName, functionName);

            string requestId = functionParameter.RequestId;

            _taskQueue.Enqueue(functionParameter);

            Action <FunctionResult> resultHandler = null;

            resultHandler = delegate(FunctionResult result)
            {
                if (result.RequestId == requestId)
                {
                    NewTaskFunctionResult -= resultHandler;

                    try
                    {
                        if (publicMember != null && result.PublicMember != null)
                        {
                            var newPublicMember = SerializationHelper.DeserializeObjectFromType(publicMember.GetType(), result.PublicMember);

                            XCClone.Clone(newPublicMember, publicMember);
                        }
                        if (internalMember != null && result.InternalMember != null)
                        {
                            var newInternalMember = SerializationHelper.DeserializeObjectFromType(internalMember.GetType(), result.InternalMember);
                            XCClone.Clone(newInternalMember, internalMember);
                        }
                    }
                    catch (Exception e)
                    {
                    }

                    lock (_senderWrapperBySender)
                    {
                        _senderWrapperBySender[sender].TriggerSender(result, context);
                    }
                }
            };

            NewTaskFunctionResult += resultHandler;
        }
        public void ApplyFunctionResult(FunctionResult result, object publicMember, object internalMember, object context, object sender)
        {
            if (result == null)
            {
                throw new ValidationException("Result should not be null");
            }

            if (!_senderWrapperBySender.ContainsKey(sender))
            {
                throw new ValidationException("Sender object received from worker not found in dictionary");
            }

            if (context == null)
            {
                throw new ValidationException("Context should not be null");
            }

            if (publicMember != null && result.PublicMember != null)
            {
                var newPublicMember = SerializationHelper.DeserializeObjectFromType(publicMember.GetType(), result.PublicMember);
                if (newPublicMember.GetType() == publicMember.GetType())
                {
                    XCClone.Clone(newPublicMember, publicMember);
                }
                else
                {
                    Trace.WriteLine($"Deserialized object type {newPublicMember.GetType()} doesn't match required type {publicMember.GetType()}");
                }
            }

            if (internalMember != null && result.InternalMember != null)
            {
                var newInternalMember = SerializationHelper.DeserializeObjectFromType(internalMember.GetType(), result.InternalMember);
                if (newInternalMember.GetType() == internalMember.GetType())
                {
                    XCClone.Clone(newInternalMember, publicMember);
                }
                else
                {
                    Trace.WriteLine($"Deserialized object type {newInternalMember.GetType()} doesn't match required type {internalMember.GetType()}");
                }
            }

            lock (_senderWrapperBySender)
            {
                _senderWrapperBySender[sender].TriggerSender(result, context);
            }
        }
 public static void ExecuteOn_Published_Through_PublishRequestResponse(XComponent.HistoryManager.UserObject.HistoryResponse historyResponse, XComponent.HistoryManager.UserObject.PublishedHistory publishedHistory, XComponent.HistoryManager.UserObject.PublishedHistoryInternalMember publishedHistoryInternalMember, RuntimeContext context, IPublishRequestResponseHistoryResponseOnPublishedPublishedHistorySenderInterface sender)
 {
     XCClone.Clone(historyResponse.PublishedHistory, publishedHistory);
     context.PrivateTopic = historyResponse.ResponseTopic;
 }
 public static void ExecuteOn_Published_Through_Send(XComponent.ChatManager.UserObject.SentMessage sentMessage, XComponent.ChatManager.UserObject.SentMessage sentMessage_PublicMember, object object_InternalMember, Context context, ISendSentMessageOnPublishedSentMessageSenderInterface sender)
 {
     XCClone.Clone(sentMessage, sentMessage_PublicMember);
 }