示例#1
0
        public void SaveScheme(SchemeDefinition <XElement> scheme)
        {
            var definingParameters     = scheme.DefiningParameters;
            var definingParametersHash = HashHelper.GenerateStringHash(definingParameters);

            var dbcoll = Store.GetCollection <WorkflowProcessScheme>(MongoDBConstants.WorkflowProcessSchemeCollectionName);

            var oldSchemes =
                dbcoll.Find(
                    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
            };

            dbcoll.InsertOne(newProcessScheme);
        }
示例#2
0
        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);
            }
        }
        /// <summary>
        /// Saves scheme to a store
        /// </summary>
        /// <param name="scheme">Not parsed scheme of the process</param>
        /// <exception cref="SchemeAlredyExistsException"></exception>
        public void SaveScheme(SchemeDefinition <XElement> scheme)
        {
            var db = _connector.GetDatabase();


            var tran = db.CreateTransaction();

            if (!scheme.IsObsolete) //there is only one current scheme can exists
            {
                if (!scheme.RootSchemeId.HasValue)
                {
                    var key  = GetKeyForCurrentScheme(scheme.SchemeCode);
                    var hash = scheme.DefiningParameters;
                    tran.AddCondition(Condition.HashNotExists(key, hash));
                    tran.HashSetAsync(key, hash, string.Format("{0:N}", scheme.Id));
                }
            }

            var newProcessScheme = new WorkflowProcessScheme
            {
                DefiningParameters = scheme.DefiningParameters,
                Scheme             = scheme.Scheme.ToString(),
                SchemeCode         = scheme.SchemeCode,
                RootSchemeCode     = scheme.RootSchemeCode,
                RootSchemeId       = scheme.RootSchemeId,
                AllowedActivities  = scheme.AllowedActivities,
                StartingTransition = scheme.StartingTransition
            };

            var newSchemeValue = JsonConvert.SerializeObject(newProcessScheme);
            var newSchemeKey   = GetKeyForProcessScheme(scheme.Id);



            tran.AddCondition(Condition.KeyNotExists(newSchemeKey));

            tran.StringSetAsync(newSchemeKey, newSchemeValue);

            if (scheme.RootSchemeId.HasValue)
            {
                tran.HashSetAsync(GetKeySchemeHierarchy(scheme.RootSchemeId.Value), scheme.SchemeCode, scheme.Id.ToString("N"));
            }

            var result = tran.Execute();

            if (!result)
            {
                throw SchemeAlredyExistsException.Create(scheme.SchemeCode, SchemeLocation.WorkflowProcessScheme, scheme.DefiningParameters);
            }
        }
示例#4
0
        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();
            }
        }
        public void SaveScheme(SchemeDefinition <XElement> scheme)
        {
            var definingParameters     = scheme.DefiningParameters;
            var definingParametersHash = HashHelper.GenerateStringHash(definingParameters);

            var cache =
                Store.GetOrCreateCache <Guid, WorkflowProcessScheme>(IgniteConstants.WorkflowProcessSchemeCacheName);
            var schemeCode = scheme.SchemeCode;
            var isObsolete = scheme.IsObsolete;
            var oldSchemes =
                cache.AsCacheQueryable().Where(
                    wps =>
                    wps.Value.DefiningParametersHash == definingParametersHash &&
                    wps.Value.SchemeCode == schemeCode && wps.Value.IsObsolete == isObsolete).ToList();

            if (oldSchemes.Any())
            {
                if (oldSchemes.Any(oldScheme => oldScheme.Value.DefiningParameters == definingParameters))
                {
                    throw SchemeAlredyExistsException.Create(schemeCode, SchemeLocation.WorkflowProcessScheme, definingParameters);
                }
            }

            var newProcessScheme = new WorkflowProcessScheme
            {
                Id = scheme.Id,
                DefiningParameters     = definingParameters,
                DefiningParametersHash = definingParametersHash,
                Scheme             = scheme.Scheme.ToString(),
                SchemeCode         = schemeCode,
                RootSchemeCode     = scheme.RootSchemeCode,
                RootSchemeId       = scheme.RootSchemeId.HasValue ? scheme.RootSchemeId.Value.ToString("N") : null,
                AllowedActivities  = JsonConvert.SerializeObject(scheme.AllowedActivities),
                StartingTransition = scheme.StartingTransition,
                IsObsolete         = scheme.IsObsolete
            };

            cache.Put(newProcessScheme.Id, newProcessScheme);
        }