public void SaveScheme(SchemeDefinition <XElement> scheme) { var definingParameters = scheme.DefiningParameters; var definingParametersHash = HashHelper.GenerateStringHash(definingParameters); using (var connection = new NpgsqlConnection(ConnectionString)) { var oldSchemes = WorkflowProcessScheme.Select(connection, scheme.SchemeCode, definingParametersHash, scheme.IsObsolete, scheme.RootSchemeId); 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 = JsonConvert.SerializeObject(scheme.AllowedActivities), StartingTransition = scheme.StartingTransition, IsObsolete = scheme.IsObsolete }; newProcessScheme.Insert(connection); } }
public void SaveScheme(string schemeCode, Guid schemeId, XElement scheme, IDictionary <string, object> parameters) { var definingParameters = SerializeParameters(parameters); var definingParametersHash = HashHelper.GenerateStringHash(definingParameters); using (NpgsqlConnection connection = new NpgsqlConnection(ConnectionString)) { var oldSchemes = WorkflowProcessScheme.Select(connection, schemeCode, definingParametersHash, true); 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 }; newProcessScheme.Insert(connection); } }