public override IDictionary <string, object> Serialize(object obj, System.Web.Script.Serialization.JavaScriptSerializer serializer) { WfProcessDescriptor processDesp = (WfProcessDescriptor)obj; Dictionary <string, object> dictionary = (Dictionary <string, object>)base.Serialize(obj, serializer); DictionaryHelper.AddNonDefaultValue <string, object>(dictionary, "Version", processDesp.Version); DictionaryHelper.AddNonDefaultValue <string, object>(dictionary, "ApplicationName", processDesp.ApplicationName); DictionaryHelper.AddNonDefaultValue <string, object>(dictionary, "ProgramName", processDesp.ProgramName); DictionaryHelper.AddNonDefaultValue <string, object>(dictionary, "Url", processDesp.Url); DictionaryHelper.AddNonDefaultValue <string, object>(dictionary, "GraphDescription", processDesp.GraphDescription); dictionary.Add("Activities", processDesp.Activities); SetPropertiesValue(processDesp, "Variables", processDesp.Variables); SetPropertiesValue(processDesp, "RelativeLinks", processDesp.RelativeLinks); SetPropertiesValue(processDesp, "CancelEventReceivers", processDesp.CancelEventReceivers); SetPropertiesValue(processDesp, "CompleteEventReceivers", processDesp.CompleteEventReceivers); SetPropertiesValue(processDesp, "InternalRelativeUsers", processDesp.InternalRelativeUsers); SetPropertiesValue(processDesp, "ExternalUsers", processDesp.ExternalUsers); SetPropertiesValue(processDesp, "ParametersNeedToBeCollected", processDesp.ParametersNeedToBeCollected); SetPropertiesValue(processDesp, "CancelBeforeExecuteServices", processDesp.CancelBeforeExecuteServices); SetPropertiesValue(processDesp, "CancelAfterExecuteServices", processDesp.CancelAfterExecuteServices); ToTransitionsDescriptorCollection transitions = new ToTransitionsDescriptorCollection(); foreach (WfActivityDescriptor actDesp in processDesp.Activities) { transitions.CopyFrom(actDesp.ToTransitions); } dictionary.Add("Transitions", transitions); return(dictionary); }
public override object Deserialize(IDictionary <string, object> dictionary, Type type, System.Web.Script.Serialization.JavaScriptSerializer serializer) { //WfProcessDescriptor processDesp = (WfProcessDescriptor)base.Deserialize(dictionary, type, serializer); #region "base Deserialize" string key = DictionaryHelper.GetValue(dictionary, "Key", string.Empty); WfProcessDescriptor processDesp = (WfProcessDescriptor)CreateInstance(key, dictionary, type, serializer); processDesp.Name = DictionaryHelper.GetValue(dictionary, "Name", string.Empty);; processDesp.Enabled = DictionaryHelper.GetValue(dictionary, "Enabled", false); processDesp.Description = DictionaryHelper.GetValue(dictionary, "Description", string.Empty); Dictionary <string, object> processProperties = new Dictionary <string, object>(); Dictionary <string, Type> constKey = new Dictionary <string, Type>(); constKey.Add("RelativeLinks", typeof(WfRelativeLinkDescriptorCollection)); constKey.Add("CancelEventReceivers", typeof(WfResourceDescriptorCollection)); constKey.Add("CompleteEventReceivers", typeof(WfResourceDescriptorCollection)); constKey.Add("InternalRelativeUsers", typeof(WfResourceDescriptorCollection)); constKey.Add("ExternalUsers", typeof(WfExternalUserCollection)); constKey.Add("Variables", typeof(WfVariableDescriptorCollection)); constKey.Add("ParametersNeedToBeCollected", typeof(WfParameterNeedToBeCollected)); constKey.Add("CancelBeforeExecuteServices", typeof(WfServiceOperationDefinitionCollection)); constKey.Add("CancelAfterExecuteServices", typeof(WfServiceOperationDefinitionCollection)); if (dictionary.ContainsKey("Properties")) { PropertyValueCollection properties = JSONSerializerExecute.Deserialize <PropertyValueCollection>(dictionary["Properties"]); properties.Remove(p => string.Compare(p.Definition.Name, "ImportWfMatrix") == 0); processDesp.Properties.Clear(); foreach (PropertyValue pv in properties) { if (constKey.ContainsKey(pv.Definition.Name)) { var objValue = JSONSerializerExecute.DeserializeObject(pv.StringValue, constKey[pv.Definition.Name]); processProperties.Add(pv.Definition.Name, objValue); } else { processDesp.Properties.Add(pv); } } } #endregion processDesp.GraphDescription = DictionaryHelper.GetValue(dictionary, "GraphDescription", string.Empty); WfActivityDescriptorCollection activities = JSONSerializerExecute.Deserialize <WfActivityDescriptorCollection>(dictionary["Activities"]); processDesp.Activities.Clear(); processDesp.Activities.CopyFrom(activities); ClearAllProperties(processDesp); SetProcessProperties(processDesp, processProperties, dictionary); ToTransitionsDescriptorCollection transitions = JSONSerializerExecute.Deserialize <ToTransitionsDescriptorCollection>(dictionary["Transitions"]); foreach (WfTransitionDescriptor tranDesp in transitions) { WfActivityDescriptor fromActDesc = (WfActivityDescriptor)processDesp.Activities[tranDesp.FromActivityKey]; WfActivityDescriptor toActDesc = (WfActivityDescriptor)processDesp.Activities[tranDesp.ToActivityKey]; if (fromActDesc != null && toActDesc != null) { fromActDesc.ToTransitions.AddTransition(toActDesc, tranDesp); } } return(processDesp); }