示例#1
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 SchemeDefinition <XElement> GetProcessSchemeByProcessId(Guid processId)
        {
            WorkflowProcessInstance processInstance = null;
            var cache =
                Store.GetOrCreateCache <Guid, WorkflowProcessInstance>(IgniteConstants.WorkflowProcessInstanceCacheName);

            try
            {
                processInstance = cache.Get(processId);
            }
            catch (KeyNotFoundException)
            {
            }

            if (processInstance == null)
            {
                throw new ProcessNotFoundException(processId);
            }

            if (!processInstance.SchemeId.HasValue)
            {
                throw SchemeNotFoundException.Create(processId, SchemeLocation.WorkflowProcessInstance);
            }

            var schemeDefinition = GetProcessSchemeBySchemeId(processInstance.SchemeId.Value);

            schemeDefinition.IsDeterminingParametersChanged = processInstance.IsDeterminingParametersChanged;
            return(schemeDefinition);
        }
        /// <summary>
        /// Gets not parsed scheme by scheme name
        /// </summary>
        /// <param name="code">Name of the scheme</param>
        /// <returns>Not parsed scheme of the process</returns>
        /// <exception cref="SchemeNotFoundException"></exception>
        public XElement GetScheme(string code)
        {
            var scheme = _connector.GetDatabase().StringGet(GetKeyForScheme(code));

            if (!scheme.HasValue || string.IsNullOrEmpty(scheme))
            {
                throw SchemeNotFoundException.Create(code, SchemeLocation.WorkflowScheme);
            }

            return(XElement.Parse(scheme));
        }
示例#4
0
        public XElement GetScheme(string code)
        {
            var dbcoll = Store.GetCollection <WorkflowScheme>(MongoDBConstants.WorkflowSchemeCollectionName);
            var scheme = dbcoll.Find(c => c.Code == code).FirstOrDefault();

            if (scheme == null || string.IsNullOrEmpty(scheme.Scheme))
            {
                throw SchemeNotFoundException.Create(code, SchemeLocation.WorkflowScheme);
            }

            return(XElement.Parse(scheme.Scheme));
        }
        /// <summary>
        /// Gets not parsed scheme by scheme name and parameters
        /// </summary>
        /// <param name="schemeCode">Name of the scheme</param>
        /// <param name="parameters">Parameters for creating the scheme</param>
        /// <param name="rootSchemeId">Id of the root scheme in case of subprocess</param>
        /// <param name="ignoreObsolete">True if you need to ignore obsolete schemes</param>
        /// <returns>Not parsed scheme of the process</returns>
        /// <exception cref="SchemeNotFoundException"></exception>
        public SchemeDefinition <XElement> GetProcessSchemeWithParameters(string schemeCode, string parameters, Guid?rootSchemeId, bool ignoreObsolete)
        {
            var db = _connector.GetDatabase();

            if (rootSchemeId.HasValue)
            {
                var schemeIdValue = db.HashGet(GetKeySchemeHierarchy(rootSchemeId.Value), schemeCode);
                if (!schemeIdValue.HasValue)
                {
                    throw SchemeNotFoundException.Create(schemeCode, SchemeLocation.WorkflowProcessScheme);
                }
                var schemeId = Guid.Parse(schemeIdValue);

                var processSchemeValue = db.StringGet(GetKeyForProcessScheme(schemeId));

                if (!processSchemeValue.HasValue)
                {
                    throw SchemeNotFoundException.Create(schemeId, SchemeLocation.WorkflowProcessScheme);
                }

                var processScheme = JsonConvert.DeserializeObject <WorkflowProcessScheme>(processSchemeValue);
                var isObsolete    = !db.HashExists(GetKeyForCurrentScheme(processScheme.RootSchemeCode), parameters);

                if (!ignoreObsolete && isObsolete)
                {
                    throw SchemeNotFoundException.Create(schemeCode, SchemeLocation.WorkflowProcessScheme);
                }

                return(ConvertToSchemeDefinition(schemeId, isObsolete, processScheme));
            }
            else
            {
                var schemeIdValue = db.HashGet(GetKeyForCurrentScheme(schemeCode), parameters);

                if (!schemeIdValue.HasValue)
                {
                    throw SchemeNotFoundException.Create(schemeCode, SchemeLocation.WorkflowProcessScheme);
                }

                var schemeId = Guid.Parse(schemeIdValue);

                var processSchemeValue = db.StringGet(GetKeyForProcessScheme(schemeId));

                if (!processSchemeValue.HasValue)
                {
                    throw SchemeNotFoundException.Create(schemeId, SchemeLocation.WorkflowProcessScheme);
                }

                var processScheme = JsonConvert.DeserializeObject <WorkflowProcessScheme>(processSchemeValue);

                return(ConvertToSchemeDefinition(schemeId, false, processScheme));
            }
        }
示例#6
0
        public XElement GetScheme(string code)
        {
            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                WorkflowScheme scheme = WorkflowScheme.SelectByKey(connection, code);
                if (scheme == null || string.IsNullOrEmpty(scheme.Scheme))
                {
                    throw SchemeNotFoundException.Create(code, SchemeLocation.WorkflowProcessScheme);
                }

                return(XElement.Parse(scheme.Scheme));
            }
        }
示例#7
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));
            }
        }
示例#8
0
        public XElement GetScheme(string code)
        {
            using (var session = Store.OpenSession())
            {
                var wfscheme =
                    session.Query <WorkflowScheme>().Customize(c => c.WaitForNonStaleResultsAsOfNow()).FirstOrDefault(wps => wps.Code == code);

                if (wfscheme == null || string.IsNullOrEmpty(wfscheme.Scheme))
                {
                    throw SchemeNotFoundException.Create(code, SchemeLocation.WorkflowScheme);
                }
                return(XElement.Parse(wfscheme.Scheme));
            }
        }
示例#9
0
        public SchemeDefinition <XElement> GetProcessSchemeBySchemeId(Guid schemeId)
        {
            WorkflowProcessScheme processScheme;

            using (var session = Store.OpenSession())
            {
                processScheme = session.Load <WorkflowProcessScheme>(schemeId);
            }

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

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

            {
                processScheme = dbcoll.Find(x => x.Id == schemeId).FirstOrDefault();
            }

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

            return(ConvertToSchemeDefinition(processScheme));
        }
示例#11
0
        public SchemeDefinition <XElement> GetProcessSchemeWithParameters(string schemeCode, string definingParameters,
                                                                          Guid?rootSchemeId, bool ignoreObsolete)
        {
            var hash = HashHelper.GenerateStringHash(definingParameters);

            var cache =
                Store.GetOrCreateCache <Guid, WorkflowProcessScheme>(IgniteConstants.WorkflowProcessSchemeCacheName);
            var processSchemesQuery = ignoreObsolete
                ? cache.AsCacheQueryable().Where(
                pss =>
                pss.Value.SchemeCode == schemeCode && pss.Value.DefiningParametersHash == hash &&
                !pss.Value.IsObsolete)
                : cache.AsCacheQueryable().Where(
                pss =>
                pss.Value.SchemeCode == schemeCode && pss.Value.DefiningParametersHash == hash
                );

            if (rootSchemeId.HasValue)
            {
                var rootSchemeIdValue = rootSchemeId.Value.ToString("N");
                processSchemesQuery = processSchemesQuery.Where(c => c.Value.RootSchemeId == rootSchemeIdValue);
            }

            var processSchemes = processSchemesQuery.Select(c => c.Value).ToList();

            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);
        }
示例#12
0
        private static void UpdateSchemeTags(NpgsqlConnection connection, string schemeCode,
                                             Func <List <string>, List <string> > getNewTags, IWorkflowBuilder builder)
        {
            WorkflowScheme scheme = SelectByKey(connection, schemeCode);

            if (scheme == null)
            {
                throw SchemeNotFoundException.Create(schemeCode, SchemeLocation.WorkflowScheme);
            }

            List <string> newTags = getNewTags.Invoke(TagHelper.FromTagStringForDatabase(scheme.Tags));

            scheme.Tags   = TagHelper.ToTagStringForDatabase(newTags);
            scheme.Scheme = builder.ReplaceTagsInScheme(scheme.Scheme, newTags);

            scheme.Update(connection);
        }
        private static async Task UpdateSchemeTagsAsync(SqlConnection connection, string schemeCode,
                                                        Func <List <string>, List <string> > getNewTags, IWorkflowBuilder builder)
        {
            WorkflowScheme scheme = await SelectByKeyAsync(connection, schemeCode).ConfigureAwait(false);

            if (scheme == null)
            {
                throw SchemeNotFoundException.Create(schemeCode, SchemeLocation.WorkflowScheme);
            }

            List <string> newTags = getNewTags.Invoke(TagHelper.FromTagStringForDatabase(scheme.Tags));

            scheme.Tags   = TagHelper.ToTagStringForDatabase(newTags);
            scheme.Scheme = builder.ReplaceTagsInScheme(scheme.Scheme, newTags);

            await scheme.UpdateAsync(connection).ConfigureAwait(false);
        }
        private void UpdateSchemeTags(string schemeCode, Func <List <string>, List <string> > getNewTags)
        {
            IMongoCollection <WorkflowScheme> dbcoll =
                Store.GetCollection <WorkflowScheme>(MongoDBConstants.WorkflowSchemeCollectionName);
            WorkflowScheme scheme = dbcoll.Find(c => c.Code == schemeCode).FirstOrDefault();

            if (scheme == null)
            {
                throw SchemeNotFoundException.Create(schemeCode, SchemeLocation.WorkflowScheme);
            }

            List <string> newTags = getNewTags.Invoke(scheme.Tags);

            scheme.Scheme = _runtime.Builder.ReplaceTagsInScheme(scheme.Scheme, newTags);
            scheme.Tags   = newTags;

            Save(dbcoll, scheme, doc => doc.Id == scheme.Id);
        }
示例#15
0
        public SchemeDefinition <XElement> GetProcessSchemeByProcessId(Guid processId)
        {
            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                var processInstance = WorkflowProcessInstance.SelectByKey(connection, processId);
                if (processInstance == null)
                {
                    throw new ProcessNotFoundException(processId);
                }

                if (!processInstance.SchemeId.HasValue)
                {
                    throw SchemeNotFoundException.Create(processId, SchemeLocation.WorkflowProcessInstance);
                }

                var schemeDefinition = GetProcessSchemeBySchemeId(processInstance.SchemeId.Value);
                schemeDefinition.IsDeterminingParametersChanged = processInstance.IsDeterminingParametersChanged;
                return(schemeDefinition);
            }
        }
示例#16
0
        /// <summary>
        /// Gets not parsed scheme of the process by process id
        /// </summary>
        /// <param name="processId">Id of the process</param>
        /// <returns>Not parsed scheme of the process</returns>
        /// <exception cref="ProcessNotFoundException"></exception>
        /// <exception cref="SchemeNotFoundException"></exception>
        public SchemeDefinition <XElement> GetProcessSchemeByProcessId(Guid processId)
        {
            var db = _connector.GetDatabase();
            var processInstanceValue = db.StringGet(GetKeyForProcessInstance(processId));

            if (!processInstanceValue.HasValue)
            {
                throw new ProcessNotFoundException(processId);
            }

            var processInstance = JsonConvert.DeserializeObject <WorkflowProcessInstance>(processInstanceValue);

            if (!processInstance.SchemeId.HasValue)
            {
                throw SchemeNotFoundException.Create(processId, SchemeLocation.WorkflowProcessInstance);
            }

            var schemeDefinition = GetProcessSchemeBySchemeId(processInstance.SchemeId.Value);

            schemeDefinition.IsDeterminingParametersChanged = processInstance.IsDeterminingParametersChanged;
            return(schemeDefinition);
        }
示例#17
0
        public XElement GetScheme(string code)
        {
            var cache = Store.GetOrCreateCache <string, WorkflowScheme>(IgniteConstants.WorkflowSchemeCacheName);


            WorkflowScheme scheme = null;

            try
            {
                scheme = cache.Get(code);
            }
            catch (KeyNotFoundException)
            {
            }

            if (scheme == null || string.IsNullOrEmpty(scheme.Scheme))
            {
                throw SchemeNotFoundException.Create(code, SchemeLocation.WorkflowScheme);
            }

            return(XElement.Parse(scheme.Scheme));
        }
示例#18
0
        public SchemeDefinition <XElement> GetProcessSchemeBySchemeId(Guid schemeId)
        {
            var cache =
                Store.GetOrCreateCache <Guid, WorkflowProcessScheme>(IgniteConstants.WorkflowProcessSchemeCacheName);

            WorkflowProcessScheme processScheme = null;

            try
            {
                processScheme = cache.Get(schemeId);
            }
            catch (KeyNotFoundException)
            {
            }

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

            return(ConvertToSchemeDefinition(processScheme));
        }
示例#19
0
        public SchemeDefinition <XElement> GetProcessSchemeWithParameters(string schemeCode, string definingParameters,
                                                                          Guid?rootSchemeId, bool ignoreObsolete)
        {
            var hash = HashHelper.GenerateStringHash(definingParameters);

            var dbcoll = Store.GetCollection <WorkflowProcessScheme>(MongoDBConstants.WorkflowProcessSchemeCollectionName);
            IEnumerable <WorkflowProcessScheme> processSchemes = ignoreObsolete
                ? dbcoll.Find(
                Query <WorkflowProcessScheme> .Where(
                    pss =>
                    pss.SchemeCode == schemeCode && pss.DefiningParametersHash == hash &&
                    pss.RootSchemeId == rootSchemeId &&
                    !pss.IsObsolete))
                                                                 .ToList()
                : dbcoll.Find(
                Query <WorkflowProcessScheme> .Where(
                    pss =>
                    pss.SchemeCode == schemeCode && pss.DefiningParametersHash == hash &&
                    pss.RootSchemeId == rootSchemeId)).ToList();

            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);
        }
示例#20
0
        /// <summary>
        /// Gets not parsed scheme by id
        /// </summary>
        /// <param name="schemeId">Id of the scheme</param>
        /// <returns>Not parsed scheme of the process</returns>
        /// <exception cref="SchemeNotFoundException"></exception>
        public SchemeDefinition <XElement> GetProcessSchemeBySchemeId(Guid schemeId)
        {
            var db = _connector.GetDatabase();
            var processSchemeValue = db.StringGet(GetKeyForProcessScheme(schemeId));

            if (!processSchemeValue.HasValue)
            {
                throw SchemeNotFoundException.Create(schemeId, SchemeLocation.WorkflowProcessScheme);
            }

            var processScheme = JsonConvert.DeserializeObject <WorkflowProcessScheme>(processSchemeValue);

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

            var key = GetKeyForCurrentScheme(processScheme.RootSchemeId.HasValue ? processScheme.RootSchemeCode : processScheme.SchemeCode);

            var isObsolete = !db.HashExists(key, processScheme.DefiningParameters);

            return(ConvertToSchemeDefinition(schemeId, isObsolete, processScheme));
        }
示例#21
0
        public SchemeDefinition <XElement> GetProcessSchemeWithParameters(string schemeCode, string definingParameters,
                                                                          Guid?rootSchemeId, bool ignoreObsolete)
        {
            IEnumerable <WorkflowProcessScheme> processSchemes;
            var hash = HashHelper.GenerateStringHash(definingParameters);

            using (var session = Store.OpenSession())
            {
                processSchemes = ignoreObsolete
                    ? session.Query <WorkflowProcessScheme>().Customize(c => c.WaitForNonStaleResultsAsOfNow()).Where(pss =>
                                                                                                                      pss.SchemeCode == schemeCode && pss.DefiningParametersHash == hash &&
                                                                                                                      pss.RootSchemeId == rootSchemeId && !pss.IsObsolete)
                                 .ToList()
                    : session.Query <WorkflowProcessScheme>().Customize(c => c.WaitForNonStaleResultsAsOfNow()).Where(pss =>
                                                                                                                      pss.SchemeCode == schemeCode && pss.DefiningParametersHash == hash &&
                                                                                                                      pss.RootSchemeId == rootSchemeId)
                                 .ToList();
            }

            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);
        }
示例#22
0
        public XElement Generate(string schemeCode, Guid schemeId, IDictionary <string, object> parameters)
        {
            if (parameters.Count > 0)
            {
                throw new InvalidOperationException("Parameters not supported");
            }

            var code = !TemplateTypeMapping.ContainsKey(schemeCode.ToLower())
                ? schemeCode
                : TemplateTypeMapping[schemeCode.ToLower()];
            WorkflowScheme scheme;
            var            cache = Store.GetOrCreateCache <string, WorkflowScheme>(IgniteConstants.WorkflowSchemeCacheName);

            {
                scheme = cache.Get(code);
            }

            if (scheme == null)
            {
                throw SchemeNotFoundException.Create(code, SchemeLocation.WorkflowScheme);
            }

            return(XElement.Parse(scheme.Scheme));
        }
示例#23
0
        public SchemeDefinition <XElement> GetProcessSchemeByProcessId(Guid processId)
        {
            WorkflowProcessInstance processInstance;
            var dbcoll = Store.GetCollection <WorkflowProcessInstance>(MongoDBConstants.WorkflowProcessInstanceCollectionName);

            {
                processInstance = dbcoll.Find(x => x.Id == processId).FirstOrDefault();
            }

            if (processInstance == null)
            {
                throw new ProcessNotFoundException(processId);
            }

            if (!processInstance.SchemeId.HasValue)
            {
                throw SchemeNotFoundException.Create(processId, SchemeLocation.WorkflowProcessInstance);
            }

            var schemeDefinition = GetProcessSchemeBySchemeId(processInstance.SchemeId.Value);

            schemeDefinition.IsDeterminingParametersChanged = processInstance.IsDeterminingParametersChanged;
            return(schemeDefinition);
        }
示例#24
0
        public SchemeDefinition <XElement> GetProcessSchemeByProcessId(Guid processId)
        {
            WorkflowProcessInstance processInstance;

            using (var session = Store.OpenSession())
            {
                processInstance = session.Load <WorkflowProcessInstance>(processId);
            }

            if (processInstance == null)
            {
                throw new ProcessNotFoundException(processId);
            }

            if (!processInstance.SchemeId.HasValue)
            {
                throw SchemeNotFoundException.Create(processId, SchemeLocation.WorkflowProcessInstance);
            }

            var schemeDefinition = GetProcessSchemeBySchemeId(processInstance.SchemeId.Value);

            schemeDefinition.IsDeterminingParametersChanged = processInstance.IsDeterminingParametersChanged;
            return(schemeDefinition);
        }