Exemplo n.º 1
0
 public RuntimeTimer LoadTimer(Guid runtimeId)
 {
     string timer;
     using (TransactionScope readUncommittedSupressedScope = PredefinedTransactionScopes.ReadUncommittedSupressedScope)
     {
         using (WorkflowPersistenceModelDataContext workflowPersistenceModelDataContext = base.CreateContext())
         {
             WorkflowRuntime workflowRuntime = workflowPersistenceModelDataContext.WorkflowRuntimes.FirstOrDefault((WorkflowRuntime wr) => wr.RuntimeId == runtimeId);
             if (workflowRuntime == null)
             {
                 workflowRuntime = new WorkflowRuntime
                 {
                     RuntimeId = runtimeId,
                     Timer = string.Empty
                 };
                 workflowPersistenceModelDataContext.WorkflowRuntimes.InsertOnSubmit(workflowRuntime);
             }
             timer = workflowRuntime.Timer;
             workflowPersistenceModelDataContext.SubmitChanges();
         }
         readUncommittedSupressedScope.Complete();
     }
     if (string.IsNullOrEmpty(timer))
     {
         return new RuntimeTimer();
     }
     DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(Dictionary<TimerKey, DateTime>));
     RuntimeTimer result;
     using (StringReader stringReader = new StringReader(timer))
     {
         using (XmlReader xmlReader = XmlReader.Create(stringReader))
         {
             result = new RuntimeTimer(dataContractSerializer.ReadObject(xmlReader) as IDictionary<TimerKey, DateTime>);
         }
     }
     return result;
 }
Exemplo n.º 2
0
 public void SaveTimer(Guid runtimeId, RuntimeTimer timer)
 {
     DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(Dictionary<TimerKey, DateTime>));
     string timer2;
     using (StringWriter stringWriter = new StringWriter())
     {
         using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter))
         {
             dataContractSerializer.WriteObject(xmlWriter, timer.Timers);
             xmlWriter.Flush();
             timer2 = stringWriter.ToString();
         }
     }
     using (TransactionScope readUncommittedSupressedScope = PredefinedTransactionScopes.ReadUncommittedSupressedScope)
     {
         using (WorkflowPersistenceModelDataContext workflowPersistenceModelDataContext = base.CreateContext())
         {
             WorkflowRuntime workflowRuntime = workflowPersistenceModelDataContext.WorkflowRuntimes.FirstOrDefault((WorkflowRuntime wr) => wr.RuntimeId == runtimeId);
             if (workflowRuntime == null)
             {
                 workflowRuntime = new WorkflowRuntime
                 {
                     RuntimeId = runtimeId,
                     Timer = timer2
                 };
                 workflowPersistenceModelDataContext.WorkflowRuntimes.InsertOnSubmit(workflowRuntime);
             }
             else
             {
                 workflowRuntime.Timer = timer2;
             }
             workflowPersistenceModelDataContext.SubmitChanges();
         }
         readUncommittedSupressedScope.Complete();
     }
 }