Esempio n. 1
0
 private static IDistributedMutex ConstructLock(string instanceId)
 {
     return(Catalog.Preconfigure()
            .Add(DistributedMutexLocalConfig.Name, WorkflowShared.WorkflowInstanceLockName(instanceId))
            .Add(DistributedMutexLocalConfig.UnusedExpirationSeconds, 60)
            .ConfiguredResolve <IDistributedMutex>());
 }
Esempio n. 2
0
        /// <summary>
        ///   Try to lock and host a pre-existing workflow.
        /// </summary>
        /// <param name="workflowId"> </param>
        /// <returns> </returns>
        private WorkflowAgent TryAcquireWorkflow(string workflowId)
        {
            WorkflowAgent acquired = null;
            var           wfMutex  = Catalog.Preconfigure()
                                     .Add(DistributedMutexLocalConfig.Name, WorkflowShared.WorkflowInstanceLockName(workflowId))
                                     .ConfiguredResolve <IDistributedMutex>();

            if (wfMutex.Open())
            {
                try
                {
                    var wftemp = GetWorkflowTemplate(workflowId);
                    if (!string.IsNullOrWhiteSpace(wftemp))
                    {
                        acquired = WorkflowAgent.AcquireSleepingOnLocked(wfMutex, this, workflowId, _ct, wftemp, _workflowDataRepositoryKey, _workflowMessagingKey, _workflowWorkspaceKey);
                        if (null != acquired)
                        {
                            if (_agents.TryAdd(workflowId, acquired))
                            {
                                acquired.Start();
                            }
                            else
                            {
                                _dblog.WarnFormat("Strange: locked workflow {0} but couldn't add it", workflowId);
                            }
                        }
                    }
                }
                catch (SynchronizationLockException)
                {
                    _dblog.InfoFormat("Synchronization lock exception while trying to acquire {0}", workflowId);
                    wfMutex.Release();
                }
                catch (WorkflowTemplateException wfex)
                {
                    var es = string.Format("Error loading template for workflow! {0}: {1}", workflowId, wfex);
                    _log.Error(es);
                    var on = Catalog.Factory.Resolve <IApplicationAlert>();
                    on.RaiseAlert(ApplicationAlertKind.Unknown, es);
                    wfMutex.Release();
                }
                catch (Exception ex)
                {
                    var es = string.Format("Error while acquiring workflow, {0}", ex);
                    _log.Error(es);
                    var on = Catalog.Factory.Resolve <IApplicationAlert>();
                    on.RaiseAlert(ApplicationAlertKind.Unknown, es);
                    wfMutex.Release();
                }
            }
            else
            {
                _dblog.InfoFormat("Could not lock {0}", workflowId);
            }

            return(acquired);
        }