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();
            }
        }
Example #2
0
        public SchemeDefinition <XElement> GetProcessSchemeWithParameters(string schemeCode, string definingParameters,
                                                                          Guid?rootSchemeId, bool ignoreObsolete)
        {
            IEnumerable <WorkflowProcessScheme> processSchemes;
            var hash = HashHelper.GenerateStringHash(definingParameters);

            using (var connection = new SqlConnection(ConnectionString))
            {
                processSchemes =
                    WorkflowProcessScheme.Select(connection, schemeCode, hash, ignoreObsolete ? false : (bool?)null,
                                                 rootSchemeId);
            }

            if (!processSchemes.Any())
            {
                throw SchemeNotFoundException.Create(schemeCode, SchemeLocation.WorkflowProcessScheme, definingParameters);
            }

            if (processSchemes.Count() == 1)
            {
                var scheme = processSchemes.First();
                return(ConvertToSchemeDefinition(scheme));
            }

            foreach (var processScheme in processSchemes.Where(processScheme => processScheme.DefiningParameters == definingParameters))
            {
                return(ConvertToSchemeDefinition(processScheme));
            }

            throw SchemeNotFoundException.Create(schemeCode, SchemeLocation.WorkflowProcessScheme, definingParameters);
        }
 public void SetSchemeIsObsolete(string schemeCode)
 {
     using (NpgsqlConnection connection = new NpgsqlConnection(ConnectionString))
     {
         WorkflowProcessScheme.SetObsolete(connection, schemeCode);
     }
 }
Example #4
0
        public void SaveScheme(SchemeDefinition <XElement> scheme)
        {
            var definingParameters     = scheme.DefiningParameters;
            var definingParametersHash = HashHelper.GenerateStringHash(definingParameters);


            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                var oldSchemes = WorkflowProcessScheme.Select(connection, scheme.SchemeCode, definingParametersHash,
                                                              scheme.IsObsolete, scheme.RootSchemeId);

                if (oldSchemes.Any())
                {
                    if (oldSchemes.Any(oldScheme => oldScheme.DefiningParameters == definingParameters))
                    {
                        throw new SchemeAlredyExistsException();
                    }
                }

                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
                };

                newProcessScheme.Insert(connection);
            }
        }
        public SchemeDefinition <XElement> GetProcessSchemeWithParameters(string schemeCode, IDictionary <string, object> parameters, bool ignoreObsolete)
        {
            IEnumerable <WorkflowProcessScheme> processSchemes = new List <WorkflowProcessScheme>();
            var definingParameters = SerializeParameters(parameters);
            var hash = HashHelper.GenerateStringHash(definingParameters);

            using (OracleConnection connection = new OracleConnection(ConnectionString))
            {
                processSchemes =
                    WorkflowProcessScheme.Select(connection, schemeCode, hash, ignoreObsolete);
            }

            if (processSchemes.Count() < 1)
            {
                throw new SchemeNotFoundException();
            }

            if (processSchemes.Count() == 1)
            {
                var scheme = processSchemes.First();
                return(new SchemeDefinition <XElement>(scheme.Id, scheme.SchemeCode, XElement.Parse(scheme.Scheme), scheme.IsObsolete));
            }

            foreach (var processScheme in processSchemes.Where(processScheme => processScheme.DefiningParameters == definingParameters))
            {
                return(new SchemeDefinition <XElement>(processScheme.Id, processScheme.SchemeCode, XElement.Parse(processScheme.Scheme), processScheme.IsObsolete));
            }

            throw new SchemeNotFoundException();
        }
Example #6
0
        public void SaveScheme(string schemeCode, Guid schemeId, XElement scheme, IDictionary <string, object> parameters)
        {
            var definingParameters     = SerializeParameters(parameters);
            var definingParametersHash = HashHelper.GenerateStringHash(definingParameters);

            var dbcoll     = Store.GetCollection <WorkflowProcessScheme>(MongoDBConstants.WorkflowProcessSchemeCollectionName);
            var oldSchemes =
                dbcoll.Find(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
            };

            dbcoll.Insert(newProcessScheme);
        }
        public void SaveScheme(string schemeCode, Guid schemeId, XElement scheme, IDictionary <string, object> parameters)
        {
            var definingParameters     = SerializeParameters(parameters);
            var definingParametersHash = HashHelper.GenerateStringHash(definingParameters);

            using (OracleConnection connection = new OracleConnection(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);
                WorkflowProcessScheme.Commit(connection);
            }
        }
 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,
                                            JsonSerializer.DeserializeFromString <List <string> >(workflowProcessScheme.AllowedActivities), workflowProcessScheme.StartingTransition,
                                            workflowProcessScheme.DefiningParameters));
 }
 public void SetSchemeIsObsolete(string schemeCode)
 {
     using (OracleConnection connection = new OracleConnection(ConnectionString))
     {
         WorkflowProcessScheme.SetObsolete(connection, schemeCode);
         WorkflowProcessScheme.Commit(connection);
     }
 }
        public void SetSchemeIsObsolete(string schemeCode, IDictionary <string, object> parameters)
        {
            var definingParameters     = SerializeParameters(parameters);
            var definingParametersHash = HashHelper.GenerateStringHash(definingParameters);

            using (NpgsqlConnection connection = new NpgsqlConnection(ConnectionString))
            {
                WorkflowProcessScheme.SetObsolete(connection, schemeCode, definingParametersHash);
            }
        }
        public SchemeDefinition <XElement> GetProcessSchemeBySchemeId(Guid schemeId)
        {
            using (OracleConnection connection = new OracleConnection(ConnectionString))
            {
                WorkflowProcessScheme processScheme = WorkflowProcessScheme.SelectByKey(connection, schemeId);

                if (processScheme == null || string.IsNullOrEmpty(processScheme.Scheme))
                {
                    throw new SchemeNotFoundException();
                }

                return(new SchemeDefinition <XElement>(schemeId, processScheme.SchemeCode, XElement.Parse(processScheme.Scheme), processScheme.IsObsolete));
            }
        }
Example #12
0
        public SchemeDefinition <XElement> GetProcessSchemeBySchemeId(Guid schemeId)
        {
            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                WorkflowProcessScheme processScheme = WorkflowProcessScheme.SelectByKey(connection, schemeId);

                if (processScheme == null || string.IsNullOrEmpty(processScheme.Scheme))
                {
                    throw SchemeNotFoundException.Create(schemeId, SchemeLocation.WorkflowProcessScheme);
                }

                return(ConvertToSchemeDefinition(processScheme));
            }
        }
Example #13
0
        public SchemeDefinition <XElement> GetProcessSchemeBySchemeId(Guid schemeId)
        {
            WorkflowProcessScheme processScheme = new WorkflowProcessScheme();
            var dbcoll = Store.GetCollection <WorkflowProcessScheme>(MongoDBConstants.WorkflowProcessSchemeCollectionName);

            {
                processScheme = dbcoll.FindOneById(schemeId);
            }

            if (processScheme == null || string.IsNullOrEmpty(processScheme.Scheme))
            {
                throw new SchemeNotFoundException();
            }

            return(new SchemeDefinition <XElement>(schemeId, XElement.Parse(processScheme.Scheme), processScheme.IsObsolete));
        }
        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 scope = PredefinedTransactionScopes.SerializableSupressedScope)
            {
                using (var context = CreateContext())
                {
                    var oldSchemes =
                        context.WorkflowProcessSchemes.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 new SchemeAlredyExistsException();
                        }
                    }


                    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  = JsonSerializer.SerializeToString(scheme.AllowedActivities),
                        StartingTransition = scheme.StartingTransition
                        ,
                    };
                    context.WorkflowProcessSchemes.InsertOnSubmit(newProcessScheme);
                    context.SubmitChanges();
                }

                scope.Complete();
            }
        }
        public void SaveScheme(string schemeCode, Guid schemeId, XElement scheme, IDictionary <string, object> parameters)
        {
            var definingParameters     = SerializeParameters(parameters);
            var definingParametersHash = HashHelper.GenerateStringHash(definingParameters);

            using (var scope = PredefinedTransactionScopes.SerializableSupressedScope)
            {
                using (var context = CreateContext())
                {
                    var oldSchemes =
                        context.WorkflowProcessSchemes.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
                    };
                    context.WorkflowProcessSchemes.InsertOnSubmit(newProcessScheme);
                    context.SubmitChanges();
                }

                scope.Complete();
            }
        }
Example #17
0
        /// <summary>
        /// 保存新的WorkflowProcessScheme,可以动态的修改参数后保存
        /// </summary>
        /// <param name="processName"></param>
        /// <param name="schemeId"></param>
        /// <param name="scheme"></param>
        /// <param name="parameters"></param>
        public void SaveScheme(string processName, Guid schemeId, XElement scheme, IDictionary <string, IEnumerable <object> > parameters)
        {
            string text = this.SerializeParameters(parameters);
            string definingParametersHash = HashHelper.GenerateStringHash(text);

            using (TransactionScope serializableSupressedScope = PredefinedTransactionScopes.SerializableSupressedScope)
            {
                using (WorkflowPersistenceModelDataContext workflowPersistenceModelDataContext = base.CreateContext())
                {
                    List <WorkflowProcessScheme> list = (
                        from wps in workflowPersistenceModelDataContext.WorkflowProcessSchemes
                        where wps.DefiningParametersHash == definingParametersHash && wps.ProcessName == processName && !wps.IsObsolete
                        select wps).ToList <WorkflowProcessScheme>();
                    if (list.Count <WorkflowProcessScheme>() > 0)
                    {
                        foreach (WorkflowProcessScheme current in list)
                        {
                            if (current.DefiningParameters == text)
                            {
                                throw new SchemeAlredyExistsException();
                            }
                        }
                    }
                    WorkflowProcessScheme entity = new WorkflowProcessScheme
                    {
                        Id = schemeId,
                        DefiningParameters     = text,
                        DefiningParametersHash = definingParametersHash,
                        Scheme      = scheme.ToString(),
                        ProcessName = processName
                    };
                    workflowPersistenceModelDataContext.WorkflowProcessSchemes.InsertOnSubmit(entity);
                    workflowPersistenceModelDataContext.SubmitChanges();
                }
                serializableSupressedScope.Complete();
            }
        }
Example #18
0
        /// <summary>
        /// 根据公文流转处理流程名称processName,以及参数获取适配的SchemeDefinition
        /// 注意这里没有processId
        /// </summary>
        /// <param name="processName"></param>
        /// <param name="parameters">参数,转换为hash在WorkflowProcessScheme中的DefiningParametersHash进行比较</param>
        /// <param name="ignoreObsolete"></param>
        /// <returns></returns>
        public SchemeDefinition <XElement> GetProcessSchemeWithParameters(string processName, IDictionary <string, IEnumerable <object> > parameters, bool ignoreObsolete)
        {
            string definingParameters = this.SerializeParameters(parameters);
            string hash = HashHelper.GenerateStringHash(definingParameters);
            IEnumerable <WorkflowProcessScheme> source;

            using (WorkflowPersistenceModelDataContext workflowPersistenceModelDataContext = base.CreateContext())
            {
                source = (
                    from pss in workflowPersistenceModelDataContext.WorkflowProcessSchemes
                    where pss.ProcessName == processName && pss.DefiningParametersHash == hash && (!ignoreObsolete || !pss.IsObsolete)
                    select pss).ToList <WorkflowProcessScheme>();
            }
            if (!source.Any()) // 表示数据表WorkflowProcessScheme中没有匹配的WorkflowProcessScheme记录,source.Count<WorkflowProcessScheme>() < 1 卢远宗修改
            {
                throw new SchemeNotFoundException();
            }
            if (source.Count <WorkflowProcessScheme>() == 1)
            {
                var workflowProcessScheme = source.First <WorkflowProcessScheme>();
                return(new SchemeDefinition <XElement>(workflowProcessScheme.Id, XElement.Parse(workflowProcessScheme.Scheme), workflowProcessScheme.IsObsolete));
            }

            //如果有多个匹配项的WorkflowProcessScheme
            using (IEnumerator <WorkflowProcessScheme> enumerator = (
                       from processScheme in source
                       where processScheme.DefiningParameters == definingParameters
                       select processScheme).GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    WorkflowProcessScheme current = enumerator.Current;
                    return(new SchemeDefinition <XElement>(current.Id, XElement.Parse(current.Scheme), current.IsObsolete));
                }
            }
            throw new SchemeNotFoundException();
        }
 partial void InsertWorkflowProcessScheme(WorkflowProcessScheme instance);
 partial void DeleteWorkflowProcessScheme(WorkflowProcessScheme instance);
 partial void UpdateWorkflowProcessScheme(WorkflowProcessScheme instance);