Ejemplo n.º 1
0
        /// <summary>
        /// Save process definition
        /// </summary>
        /// <param name="definition"></param>
        /// <param name="status"></param>
        /// <param name="version"></param>
        /// <param name="accounts">Security accounts that have access to the flow</param>
        public void Create(ProcessDefinition definition,
                           ProcessDefStatusEnum status,
                           int version, params AccountData[] accounts)
        {
            Md5CalcVisitor visitor = new Md5CalcVisitor();

            definition.Accept(visitor);
            var accountsList = new List <ProcessDefinitionAccount>();
            ProcessDefinitionPersistence pd = new ProcessDefinitionPersistence
            {
                Id                    = definition.Id,
                FlowId                = definition.FlowId,
                Version               = version,
                Name                  = definition.Name,
                Description           = definition.Description,
                LastModified          = DateTime.UtcNow,
                Status                = (int)status,
                Md5                   = visitor.CalculateMd5(),
                JsonProcessDefinition = JsonConvert.SerializeObject(definition),
                Accounts              = accountsList
            };

            try
            {
                using (var ctx = new ProcessDbContext())
                {
                    SetupAccounts(ctx, ctx.ProcessDefinition.Add(pd), accounts);
                    ctx.SaveChanges();
                }
            }
            catch (DbUpdateException ex)
            {
                throw new ArgumentException(ex.Message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create and persist runtime processor
        /// </summary>
        /// <param name="pd"></param>
        /// <param name="collection"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public override IProcessRuntime Create(ProcessDefinition pd, IPropertySetCollection collection)
        {
            IProcessRuntime runtime = base.Create(pd, collection);
            Md5CalcVisitor  visitor = new Md5CalcVisitor();

            pd.Accept(visitor);
            string md5 = visitor.CalculateMd5();

            using (var ctx = new ProcessDbContext())
            {
                var pdList = ctx.ProcessDefinition
                             .Where(p => p.FlowId == pd.FlowId && p.Md5 == md5).ToList();

                if (pdList.Count() != 1)
                {
                    throw new ArgumentException($"Process definition is not persisted.");
                }
                // save or update the collection
                PersistentPropertyCollection persistedCollection =
                    _propertySepPersistenceService.SaveCollection(ctx, runtime.Id, collection);
                ProcessRuntimePersistence rtp = new ProcessRuntimePersistence
                {
                    Id = runtime.Id,
                    SuspendedStepId    = runtime.LastExecutedStep?.StepId,
                    Status             = (int)runtime.State,
                    LastUpdated        = DateTime.UtcNow,
                    PropertyCollection = persistedCollection,
                    ProcessDefinition  = pdList.ElementAt(0)
                };
                ctx.Process.Add(rtp);
                ctx.SaveChanges();
            }
            return(new ProcessRuntimePersistenProxy(runtime, this));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Create Security Account Records
 /// </summary>
 /// <param name="accounts"></param>
 public void CreateAccounts(params AccountData[] accounts)
 {
     using (var ctx = new ProcessDbContext())
     {
         accounts.ToList().ForEach(a => ctx.Accounts.Add(a));
         ctx.SaveChanges();
     }
 }
        /// <summary>
        /// Store the collection
        /// </summary>
        /// <param name="collectionId"></param>
        /// <param name="collection"></param>
        public void SaveCollection(Guid collectionId, IPropertySetCollection collection)
        {
            List <PersistentSchemaElement>   schemaElements;
            List <PersistentPropertyElement> dataElements;

            collection.CreatePersistentSchemaElements(out schemaElements, out dataElements);
            using (ProcessDbContext ctx = new ProcessDbContext())
            {
                UpdateOrCreatePropertyCollection(collectionId, ctx, schemaElements, dataElements);
                ctx.SaveChanges();
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Set or update status
 /// </summary>
 /// <param name="id"></param>
 /// <param name="version"></param>
 /// <param name="status"></param>
 public bool SetStatus(Guid id, int version, ProcessDefStatusEnum status)
 {
     using (var ctx = new ProcessDbContext())
     {
         ProcessDefinitionPersistence pd = ctx.ProcessDefinition.Find(id, version);
         if (pd == null)
         {
             return(false);
         }
         pd.Status       = (int)status;
         pd.LastModified = DateTime.UtcNow;
         ctx.SaveChanges();
         return(true);
     }
 }
Ejemplo n.º 6
0
 public void RemoveRoles(Guid id, int version, params AccountData[] accounts)
 {
     using (var ctx = new ProcessDbContext())
     {
         ProcessDefinitionPersistence pd = ctx.ProcessDefinition.Find(id, version);
         if (pd == null)
         {
             throw new ArgumentException($"Process Definition id={id} version={version} not found.");
         }
         if (accounts != null)
         {
             SetupAccounts(ctx, pd, accounts);
         }
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 7
0
 public override void Freeze(IProcessRuntime runtime, IPropertySetCollection collection)
 {
     using (var ctx = new ProcessDbContext())
     {
         ProcessRuntimePersistence persistence = ctx.Process.Find(runtime.Id);
         if (persistence == null)
         {
             throw new ArgumentException("Invalid Workflow Id:" + runtime.Id.ToString());
         }
         _propertySepPersistenceService.SaveCollection(ctx, runtime.Id, collection);
         persistence.Status          = (int)runtime.State;
         persistence.LastUpdated     = DateTime.UtcNow;
         persistence.SuspendedStepId = runtime.SuspendedInStep?.StepId;
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 8
0
 protected virtual void OnExecute(IProcessRuntime runtime, Tuple <ExecutionResult, StepRuntime> result, IProcessRuntimeEnvironment env)
 {
     using (var ctx = new ProcessDbContext())
     {
         ProcessRuntimePersistence persistence = ctx.Process.Find(runtime.Id);
         if (persistence == null)
         {
             throw new ArgumentException("Invalid Workflow Id:" + runtime.Id);
         }
         _propertySepPersistenceService.SaveCollection(ctx, runtime.Id, env.PropertySet);
         persistence.Status          = (int)runtime.State;
         persistence.LastUpdated     = DateTime.UtcNow;
         persistence.SuspendedStepId = runtime.SuspendedInStep?.StepId;
         persistence.NextStepId      = runtime.State == ProcessStateEnum.Completed? null: result.Item2?.StepId;
         ctx.SaveChanges();
     }
 }