예제 #1
0
 /// <summary>
 /// Access process instance holding a write lock
 /// Process instance will be updated in the instance repository.
 /// </summary>
 /// <param name="instanceId"></param>
 /// <param name="dlg"></param>
 private void AccessProcessReadWriteLock(string instanceId, AccessProcessInstanceDelegate dlg)
 {
     bool ready = false;
     using (IResourceLock rl = LockManager.AcquireWriterLock(instanceId, TimeSpan.MaxValue))
     {
         ProcessInstance pi = InstanceRepository.GetProcessInstance(instanceId);
         if (pi == null)
         {
             log.Warn("Process instance not found: {0}", instanceId);
             dlg(null);
             return;
         }
         using (TransactionScope ts = new TransactionScope(_transactionOption))
         {
             try
             {
                 pi.Environment = this;
                 pi.Activate();
                 log.Info("Original: {0}", pi.SaveState().ToXmlString("Process"));
                 dlg(pi);
                 pi.Passivate();
                 log.Info("Modified: {0}", pi.SaveState().ToXmlString("Process"));
                 ready = pi.Status == ProcessStatus.Ready;
                 InstanceRepository.UpdateProcessInstance(pi);
                 ts.Complete();
             }
             catch (Exception ex)
             {
                 log.Error("Error updating process {0} : {1}", instanceId, ex);
                 throw;
             }
         }
     }
     if (ready)
     {
         NotifyReadyProcessSaved();
     }
 }
예제 #2
0
 /// <summary>
 /// Access process instance holding a readonly lock
 /// Process instance is not updated.
 /// </summary>
 /// <param name="instanceId"></param>
 /// <param name="dlg"></param>
 private void AccessProcessReadonlyLock(string instanceId, AccessProcessInstanceDelegate dlg)
 {
     using (IResourceLock rl = LockManager.AcquireReaderLock(instanceId, TimeSpan.MaxValue))
     {
         ProcessInstance pi = InstanceRepository.GetProcessInstance(instanceId);
         if (pi != null)
         {
             pi.Environment = this;
             pi.Activate();
         }
         dlg(pi);
     }
 }