private void SetActivityProperties(WfActivityDescriptor actDesp, Dictionary <string, object> activityProperties, IDictionary <string, object> dictionary)
        {
            if (activityProperties.ContainsKey("Variables"))
            {
                var item = (WfVariableDescriptorCollection)activityProperties["Variables"];
                if (item != null)
                {
                    actDesp.Variables.CopyFrom(item);
                }
            }
            else if (dictionary.ContainsKey("Variables"))
            {
                WfVariableDescriptorCollection variables = JSONSerializerExecute.Deserialize <WfVariableDescriptorCollection>(dictionary["Variables"]);
                actDesp.Variables.CopyFrom(variables);
            }

            if (activityProperties.ContainsKey("Condition"))
            {
                var item = (WfConditionDescriptor)activityProperties["Condition"];
                if (item != null)
                {
                    actDesp.Condition = (WfConditionDescriptor)activityProperties["Condition"];
                }
                else
                {
                    actDesp.Condition.Owner = actDesp;
                }
            }
            else if (dictionary.ContainsKey("Condition"))
            {
                actDesp.Condition       = JSONSerializerExecute.Deserialize <WfConditionDescriptor>(dictionary["Condition"]);
                actDesp.Condition.Owner = actDesp;
            }

            if (activityProperties.ContainsKey("BranchProcessTemplates"))
            {
                var item = (WfBranchProcessTemplateCollection)activityProperties["BranchProcessTemplates"];
                if (item != null)
                {
                    actDesp.BranchProcessTemplates.CopyFrom(item);
                }
            }
            else if (dictionary.ContainsKey("BranchProcessTemplates"))
            {
                WfBranchProcessTemplateCollection templates = JSONSerializerExecute.Deserialize <WfBranchProcessTemplateCollection>(dictionary["BranchProcessTemplates"]);
                actDesp.BranchProcessTemplates.CopyFrom(templates);
            }

            if (activityProperties.ContainsKey("Resources"))
            {
                var item = (WfResourceDescriptorCollection)activityProperties["Resources"];
                if (item != null)
                {
                    actDesp.Resources.CopyFrom(item);
                }
            }
            else if (dictionary.ContainsKey("Resources"))
            {
                WfResourceDescriptorCollection resource = JSONSerializerExecute.Deserialize <WfResourceDescriptorCollection>(dictionary["Resources"]);
                actDesp.Resources.CopyFrom(resource);
            }

            if (activityProperties.ContainsKey("RelativeLinks"))
            {
                var item = (WfRelativeLinkDescriptorCollection)activityProperties["RelativeLinks"];
                if (item != null)
                {
                    actDesp.RelativeLinks.CopyFrom(item);
                }
            }
            else if (dictionary.ContainsKey("RelativeLinks"))
            {
                WfRelativeLinkDescriptorCollection relativeLinks = JSONSerializerExecute.Deserialize <WfRelativeLinkDescriptorCollection>(dictionary["RelativeLinks"]);
                actDesp.RelativeLinks.CopyFrom(relativeLinks);
            }

            if (activityProperties.ContainsKey("EnterEventReceivers"))
            {
                var item = (WfResourceDescriptorCollection)activityProperties["EnterEventReceivers"];
                if (item != null)
                {
                    actDesp.EnterEventReceivers.CopyFrom(item);
                }
            }
            else if (dictionary.ContainsKey("EnterEventReceivers"))
            {
                WfResourceDescriptorCollection resource = JSONSerializerExecute.Deserialize <WfResourceDescriptorCollection>(dictionary["EnterEventReceivers"]);
                actDesp.EnterEventReceivers.CopyFrom(resource);
            }

            if (activityProperties.ContainsKey("LeaveEventReceivers"))
            {
                var item = (WfResourceDescriptorCollection)activityProperties["LeaveEventReceivers"];
                if (item != null)
                {
                    actDesp.LeaveEventReceivers.CopyFrom(item);
                }
            }
            else if (dictionary.ContainsKey("LeaveEventReceivers"))
            {
                WfResourceDescriptorCollection resource = JSONSerializerExecute.Deserialize <WfResourceDescriptorCollection>(dictionary["LeaveEventReceivers"]);
                actDesp.LeaveEventReceivers.CopyFrom(resource);
            }

            if (activityProperties.ContainsKey("InternalRelativeUsers"))
            {
                var item = (WfResourceDescriptorCollection)activityProperties["InternalRelativeUsers"];
                if (item != null)
                {
                    actDesp.InternalRelativeUsers.CopyFrom(item);
                }
            }
            else if (dictionary.ContainsKey("InternalRelativeUsers"))
            {
                WfResourceDescriptorCollection interRelUser = JSONSerializerExecute.Deserialize <WfResourceDescriptorCollection>(dictionary["InternalRelativeUsers"]);
                actDesp.InternalRelativeUsers.CopyFrom(interRelUser);
            }

            if (activityProperties.ContainsKey("ExternalUsers"))
            {
                var item = (WfExternalUserCollection)activityProperties["ExternalUsers"];
                if (item != null)
                {
                    actDesp.ExternalUsers.CopyFrom(item);
                }
            }
            else if (dictionary.ContainsKey("ExternalUsers"))
            {
                WfExternalUserCollection externalUser = JSONSerializerExecute.Deserialize <WfExternalUserCollection>(dictionary["ExternalUsers"]);
                actDesp.ExternalUsers.CopyFrom(externalUser);
            }

            if (activityProperties.ContainsKey("EnterEventExecuteServices"))
            {
                var item = (WfServiceOperationDefinitionCollection)activityProperties["EnterEventExecuteServices"];
                if (item != null)
                {
                    actDesp.EnterEventExecuteServices.CopyFrom(item);
                }
            }
            else if (dictionary.ContainsKey("EnterEventExecuteServices"))
            {
                WfServiceOperationDefinitionCollection svcOperationDef =
                    JSONSerializerExecute.Deserialize <WfServiceOperationDefinitionCollection>(dictionary["EnterEventExecuteServices"]);
                actDesp.EnterEventExecuteServices.CopyFrom(svcOperationDef);
            }

            if (activityProperties.ContainsKey("LeaveEventExecuteServices"))
            {
                var item = (WfServiceOperationDefinitionCollection)activityProperties["LeaveEventExecuteServices"];

                if (item != null)
                {
                    actDesp.LeaveEventExecuteServices.CopyFrom(item);
                }
            }
            else if (dictionary.ContainsKey("LeaveEventExecuteServices"))
            {
                WfServiceOperationDefinitionCollection svcOperationDef =
                    JSONSerializerExecute.Deserialize <WfServiceOperationDefinitionCollection>(dictionary["LeaveEventExecuteServices"]);

                actDesp.LeaveEventExecuteServices.CopyFrom(svcOperationDef);
            }

            if (activityProperties.ContainsKey("WithdrawExecuteServices"))
            {
                var item = (WfServiceOperationDefinitionCollection)activityProperties["WithdrawExecuteServices"];

                if (item != null)
                {
                    actDesp.WithdrawExecuteServices.CopyFrom(item);
                }
            }
            else if (dictionary.ContainsKey("WithdrawExecuteServices"))
            {
                WfServiceOperationDefinitionCollection svcOperationDef =
                    JSONSerializerExecute.Deserialize <WfServiceOperationDefinitionCollection>(dictionary["WithdrawExecuteServices"]);

                actDesp.WithdrawExecuteServices.CopyFrom(svcOperationDef);
            }

            if (activityProperties.ContainsKey("BeWithdrawnExecuteServices"))
            {
                var item = (WfServiceOperationDefinitionCollection)activityProperties["BeWithdrawnExecuteServices"];

                if (item != null)
                {
                    actDesp.BeWithdrawnExecuteServices.CopyFrom(item);
                }
            }
            else if (dictionary.ContainsKey("BeWithdrawnExecuteServices"))
            {
                WfServiceOperationDefinitionCollection svcOperationDef =
                    JSONSerializerExecute.Deserialize <WfServiceOperationDefinitionCollection>(dictionary["BeWithdrawnExecuteServices"]);

                actDesp.BeWithdrawnExecuteServices.CopyFrom(svcOperationDef);
            }

            if (activityProperties.ContainsKey("ParametersNeedToBeCollected"))
            {
                var item = (WfParameterNeedToBeCollected)activityProperties["ParametersNeedToBeCollected"];
                if (item != null)
                {
                    actDesp.ParametersNeedToBeCollected.CopyFrom(item);
                }
            }
            else if (dictionary.ContainsKey("ParametersNeedToBeCollected"))
            {
                WfParameterNeedToBeCollected parameters =
                    JSONSerializerExecute.Deserialize <WfParameterNeedToBeCollected>(dictionary["ParametersNeedToBeCollected"]);
                actDesp.ParametersNeedToBeCollected.CopyFrom(parameters);
            }
        }
Пример #2
0
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            WfActivityDescriptor actDesp = (WfActivityDescriptor)base.Deserialize(dictionary, type, serializer);

            //actDesp.ActivityType = DictionaryHelper.GetValue(dictionary, "ActivityType", WfActivityType.NormalActivity);

            if (true == DictionaryHelper.GetValue(dictionary, "AllowEmptyCandidates", false))
            {
                actDesp.Properties.SetValue("AllowEmptyCandidates", true);
            }

            if (true == DictionaryHelper.GetValue(dictionary, "AllowInvalidCandidates", false))
            {
                if (actDesp.Properties.ContainsKey("AllowInvalidCandidates"))
                {
                    actDesp.Properties.SetValue("AllowInvalidCandidates", true);
                }
            }

            actDesp.Url      = DictionaryHelper.GetValue(dictionary, "Url", string.Empty);
            actDesp.CodeName = DictionaryHelper.GetValue(dictionary, "CodeName", string.Empty);

            WfVariableDescriptorCollection variables = JSONSerializerExecute.Deserialize <WfVariableDescriptorCollection>(dictionary["Variables"]);

            actDesp.Variables.Clear();
            actDesp.Variables.CopyFrom(variables);

            if (dictionary.ContainsKey("Condition"))
            {
                actDesp.Condition       = JSONSerializerExecute.Deserialize <WfConditionDescriptor>(dictionary["Condition"]);
                actDesp.Condition.Owner = actDesp;
            }

            if (dictionary.ContainsKey("BranchProcessTemplates"))
            {
                WfBranchProcessTemplateCollection templates = JSONSerializerExecute.Deserialize <WfBranchProcessTemplateCollection>(dictionary["BranchProcessTemplates"]);
                actDesp.BranchProcessTemplates.Clear();
                actDesp.BranchProcessTemplates.CopyFrom(templates);
            }

            if (dictionary.ContainsKey("Resources"))
            {
                WfResourceDescriptorCollection resource = JSONSerializerExecute.Deserialize <WfResourceDescriptorCollection>(dictionary["Resources"]);
                actDesp.Resources.Clear();
                actDesp.Resources.CopyFrom(resource);
            }

            if (dictionary.ContainsKey("RelativeLinks"))
            {
                WfRelativeLinkDescriptorCollection relativeLinks = JSONSerializerExecute.Deserialize <WfRelativeLinkDescriptorCollection>(dictionary["RelativeLinks"]);

                actDesp.RelativeLinks.Clear();
                actDesp.RelativeLinks.CopyFrom(relativeLinks);
            }

            if (dictionary.ContainsKey("EnterEventReceivers"))
            {
                WfResourceDescriptorCollection resource = JSONSerializerExecute.Deserialize <WfResourceDescriptorCollection>(dictionary["EnterEventReceivers"]);
                actDesp.EnterEventReceivers.Clear();
                actDesp.EnterEventReceivers.CopyFrom(resource);
            }

            if (dictionary.ContainsKey("LeaveEventReceivers"))
            {
                WfResourceDescriptorCollection resource = JSONSerializerExecute.Deserialize <WfResourceDescriptorCollection>(dictionary["LeaveEventReceivers"]);
                actDesp.LeaveEventReceivers.Clear();
                actDesp.LeaveEventReceivers.CopyFrom(resource);
            }

            if (dictionary.ContainsKey("InternalRelativeUsers"))
            {
                WfResourceDescriptorCollection interRelUser = JSONSerializerExecute.Deserialize <WfResourceDescriptorCollection>(dictionary["InternalRelativeUsers"]);
                actDesp.InternalRelativeUsers.Clear();
                actDesp.InternalRelativeUsers.CopyFrom(interRelUser);
            }

            if (dictionary.ContainsKey("ExternalUsers"))
            {
                WfExternalUserCollection externalUser = JSONSerializerExecute.Deserialize <WfExternalUserCollection>(dictionary["ExternalUsers"]);
                actDesp.ExternalUsers.Clear();
                actDesp.ExternalUsers.CopyFrom(externalUser);
            }

            if (dictionary.ContainsKey("EnterEventExecuteServices"))
            {
                WfServiceOperationDefinitionCollection svcOperationDef =
                    JSONSerializerExecute.Deserialize <WfServiceOperationDefinitionCollection>(dictionary["EnterEventExecuteServices"]);
                actDesp.EnterEventExecuteServices.Clear();
                actDesp.EnterEventExecuteServices.CopyFrom(svcOperationDef);
            }

            if (dictionary.ContainsKey("LeaveEventExecuteServices"))
            {
                WfServiceOperationDefinitionCollection svcOperationDef =
                    JSONSerializerExecute.Deserialize <WfServiceOperationDefinitionCollection>(dictionary["LeaveEventExecuteServices"]);
                actDesp.LeaveEventExecuteServices.Clear();
                actDesp.LeaveEventExecuteServices.CopyFrom(svcOperationDef);
            }

            if (dictionary.ContainsKey("WithdrawExecuteServices"))
            {
                WfServiceOperationDefinitionCollection svcOperationDef =
                    JSONSerializerExecute.Deserialize <WfServiceOperationDefinitionCollection>(dictionary["WithdrawExecuteServices"]);
                actDesp.WithdrawExecuteServices.Clear();
                actDesp.WithdrawExecuteServices.CopyFrom(svcOperationDef);
            }

            if (dictionary.ContainsKey("BeWithdrawnExecuteServices"))
            {
                WfServiceOperationDefinitionCollection svcOperationDef =
                    JSONSerializerExecute.Deserialize <WfServiceOperationDefinitionCollection>(dictionary["BeWithdrawnExecuteServices"]);
                actDesp.BeWithdrawnExecuteServices.Clear();
                actDesp.BeWithdrawnExecuteServices.CopyFrom(svcOperationDef);
            }

            return(actDesp);
        }