Example #1
0
 /// <summary>
 /// Unfreeze the process
 /// </summary>
 /// <param name="processRuntimeId"></param>
 /// <param name="runtime"></param>
 /// <param name="nextStep"></param>
 /// <param name="collection"></param>
 /// <returns></returns>
 public override bool TryUnfreeze(Guid processRuntimeId,
                                  out IProcessRuntime runtime,
                                  out StepRuntime nextStep,
                                  out IPropertySetCollection collection)
 {
     runtime    = null;
     collection = null;
     nextStep   = null;
     using (var ctx = new ProcessDbContext())
     {
         var rtp = ctx.Process.Find(processRuntimeId);
         if (rtp == null)
         {
             return(false);
         }
         var definition =
             JsonConvert.DeserializeObject <ProcessDefinition>(rtp.ProcessDefinition.JsonProcessDefinition);
         definition.Id = rtp.ProcessDefinition.Id;
         collection    = rtp.PropertyCollection.Deserialize();
         if (!string.IsNullOrEmpty(rtp.NextStepId))
         {
             StepDefinition   stepDef = definition.Steps.Single(s => s.StepId == rtp.NextStepId);
             StepDefinitionId sid     = new StepDefinitionId(stepDef.Id, stepDef.StepId);
             LinkDefinition[] links   = definition.Links.Where(l => l.Source == sid).ToArray();
             nextStep = new StepRuntime(stepDef, links.Select(l => new LinkRuntime(l)).ToArray());
         }
         runtime = Create(rtp.Id, definition, rtp.SuspendedStepId, (ProcessStateEnum)rtp.Status);
     }
     return(true);
 }
        /// <summary>
        /// Un-freeze the runtime process
        /// </summary>
        /// <param name="processRuntimeId"></param>
        /// <param name="runtime"></param>
        /// <param name="nextStep"></param>
        /// <param name="collection"></param>
        /// <returns></returns>
        public override bool TryUnfreeze(Guid processRuntimeId, out IProcessRuntime runtime, out StepRuntime nextStep,
                                         out IPropertySetCollection collection)
        {
            runtime    = null;
            nextStep   = null;
            collection = null;
            var filter = Builders <MongoProcessRuntimePersistence> .Filter.Eq(r => r.Id, processRuntimeId);

            MongoProcessRuntimePersistence rtp = _collection.Find(filter).SingleOrDefault();

            if (rtp == null)
            {
                return(false);
            }
            var defFilter = Builders <ProcessDefinitionPersistence> .Filter.And(
                Builders <ProcessDefinitionPersistence> .Filter.Eq(r => r.FlowId, rtp.DefinitionFlowId),
                Builders <ProcessDefinitionPersistence> .Filter.Eq(r => r.Md5, rtp.DefinitionMd5)
                );

            ProcessDefinition    definition;
            ProcessDefStatusEnum status;

            AccountData[] accounts;
            if (!_processDefinitionService.TryFind(defFilter, out definition, out status, out accounts))
            {
                return(false);
            }
            collection = rtp.PropertyCollection.Deserialize();
            if (!string.IsNullOrEmpty(rtp.NextStepId))
            {
                StepDefinition   stepDef = definition.Steps.SingleOrDefault(s => s.StepId == rtp.NextStepId);
                StepDefinitionId sid     = new StepDefinitionId(stepDef.Id, stepDef.StepId);
                LinkDefinition[] links   = definition.Links.Where(l => l.Source == sid).ToArray();
                nextStep = new StepRuntime(stepDef, links.Select(l => new LinkRuntime(l)).ToArray());
            }
            runtime = Create(rtp.Id, definition, rtp.SuspendedStepId, (ProcessStateEnum)rtp.Status);
            return(true);
        }