public void SaveScheme(string schemeCode, Guid schemeId, XElement scheme, IDictionary <string, object> parameters) { var definingParameters = SerializeParameters(parameters); var definingParametersHash = HashHelper.GenerateStringHash(definingParameters); using (var session = Store.OpenSession()) { var oldSchemes = session.Query <WorkflowProcessScheme>().Where( wps => wps.DefiningParametersHash == definingParametersHash && wps.SchemeCode == schemeCode && !wps.IsObsolete).ToList(); if (oldSchemes.Count() > 0) { foreach (var oldScheme in oldSchemes) { if (oldScheme.DefiningParameters == definingParameters) { throw new SchemeAlredyExistsException(); } } } var newProcessScheme = new WorkflowProcessScheme { Id = schemeId, DefiningParameters = definingParameters, DefiningParametersHash = definingParametersHash, Scheme = scheme.ToString(), SchemeCode = schemeCode }; session.Store(newProcessScheme); session.SaveChanges(); } }
private SchemeDefinition <XElement> ConvertToSchemeDefinition(WorkflowProcessScheme workflowProcessScheme) { return(new SchemeDefinition <XElement>(workflowProcessScheme.Id, workflowProcessScheme.RootSchemeId, workflowProcessScheme.SchemeCode, workflowProcessScheme.RootSchemeCode, XElement.Parse(workflowProcessScheme.Scheme), workflowProcessScheme.IsObsolete, false, workflowProcessScheme.AllowedActivities, workflowProcessScheme.StartingTransition, workflowProcessScheme.DefiningParameters)); }
public SchemeDefinition <XElement> GetProcessSchemeBySchemeId(Guid schemeId) { WorkflowProcessScheme processScheme = new WorkflowProcessScheme(); using (var session = Store.OpenSession()) { processScheme = session.Load <WorkflowProcessScheme>(schemeId); } if (processScheme == null || string.IsNullOrEmpty(processScheme.Scheme)) { throw new SchemeNotFoundException(); } return(new SchemeDefinition <XElement>(schemeId, processScheme.SchemeCode, XElement.Parse(processScheme.Scheme), processScheme.IsObsolete)); }
public void SaveScheme(SchemeDefinition <XElement> scheme) { var definingParameters = scheme.DefiningParameters; var definingParametersHash = HashHelper.GenerateStringHash(definingParameters); using (var session = Store.OpenSession()) { var oldSchemes = session.Query <WorkflowProcessScheme>() .Customize(c => c.WaitForNonStaleResultsAsOfNow()) .Where(wps => wps.DefiningParametersHash == definingParametersHash && wps.SchemeCode == scheme.SchemeCode && wps.IsObsolete == scheme.IsObsolete) .ToList(); if (oldSchemes.Any()) { if (oldSchemes.Any(oldScheme => oldScheme.DefiningParameters == definingParameters)) { throw SchemeAlredyExistsException.Create(scheme.SchemeCode, SchemeLocation.WorkflowProcessScheme, scheme.DefiningParameters); } } var newProcessScheme = new WorkflowProcessScheme { Id = scheme.Id, DefiningParameters = definingParameters, DefiningParametersHash = definingParametersHash, Scheme = scheme.Scheme.ToString(), SchemeCode = scheme.SchemeCode, RootSchemeCode = scheme.RootSchemeCode, RootSchemeId = scheme.RootSchemeId, AllowedActivities = scheme.AllowedActivities, StartingTransition = scheme.StartingTransition, IsObsolete = scheme.IsObsolete }; session.Store(newProcessScheme); session.SaveChanges(); } }