public void SavePersistenceParameters(ProcessInstance processInstance) { var parametersToPersistList = processInstance.ProcessParameters.Where(ptp => ptp.Purpose == ParameterPurpose.Persistence) .Select(ptp => { if (ptp.Type == typeof(UnknownParameterType)) { return new { Parameter = ptp, SerializedValue = (string)ptp.Value } } ; return(new { Parameter = ptp, SerializedValue = ParametersSerializer.Serialize(ptp.Value, ptp.Type) }); }) .ToList(); var dbcoll = Store.GetCollection <WorkflowProcessInstance>(MongoDBConstants.WorkflowProcessInstanceCollectionName); var process = dbcoll.Find(x => x.Id == processInstance.ProcessId).FirstOrDefault(); if (process != null && process.Persistence != null) { var persistedParameters = process.Persistence.ToList(); foreach (var parameterDefinitionWithValue in parametersToPersistList) { var persistence = persistedParameters.SingleOrDefault( pp => pp.ParameterName == parameterDefinitionWithValue.Parameter.Name); { if (persistence == null) { if (parameterDefinitionWithValue.SerializedValue != null) { persistence = new WorkflowProcessInstancePersistence { ParameterName = parameterDefinitionWithValue.Parameter.Name, Value = parameterDefinitionWithValue.SerializedValue }; process.Persistence.Add(persistence); } } else { if (parameterDefinitionWithValue.SerializedValue != null) { persistence.Value = parameterDefinitionWithValue.SerializedValue; } else { process.Persistence.Remove(persistence); } } } } Save(dbcoll, process, doc => doc.Id == process.Id); } }
public void SavePersistenceParameters(ProcessInstance processInstance) { var parametersToPersistList = processInstance.ProcessParameters.Where(ptp => ptp.Purpose == ParameterPurpose.Persistence).Select(ptp => new { Parameter = ptp, SerializedValue = _runtime.SerializeParameter(ptp.Value, ptp.Type) }) .ToList(); var persistenceParameters = processInstance.ProcessScheme.PersistenceParameters.ToList(); var dbcoll = Store.GetCollection <WorkflowProcessInstance>(MongoDBConstants.WorkflowProcessInstanceCollectionName); var process = dbcoll.FindOneById(processInstance.ProcessId); if (process != null && process.Persistence != null) { var persistedParameters = process.Persistence.Where( WorkflowProcessInstancep => persistenceParameters.Select(pp => pp.Name).Contains(WorkflowProcessInstancep.ParameterName)).ToList(); foreach (var parameterDefinitionWithValue in parametersToPersistList) { var persistence = persistedParameters.SingleOrDefault( pp => pp.ParameterName == parameterDefinitionWithValue.Parameter.Name); { if (persistence == null) { if (parameterDefinitionWithValue.SerializedValue != null) { persistence = new WorkflowProcessInstancePersistence() { ParameterName = parameterDefinitionWithValue.Parameter.Name, Value = parameterDefinitionWithValue.SerializedValue }; process.Persistence.Add(persistence); } } else { if (parameterDefinitionWithValue.SerializedValue != null) { persistence.Value = parameterDefinitionWithValue.SerializedValue; } else { process.Persistence.Remove(persistence); } } } } dbcoll.Save(process); } }