Beispiel #1
0
        private void Initialize(WorkflowHost host, string templateData)
        {
            _log   = ClassLogger.Create(GetType());
            _dblog = DebugOnlyLogger.Create(_log);

            _host = host;


            _workspaceContainerName = WorkflowShared.WorkflowInstanceWorkspaceName(Id);

            Workspace = Catalog.Preconfigure()
                        .Add(WorkspaceLocalConfig.WorkspaceName, _workspaceContainerName)
                        .ConfiguredResolve <IWorkspace>(_workflowWorkspaceKey);


            if (null == _wfLock)
            {
                _wfLock = ConstructLock(Id);
            }



            SpecifyUsingTemplate(templateData);

            var instance = new WorkflowInstanceInfo
            {
                Id                 = Id,
                TemplateName       = Name,
                LastActivity       = DateTime.UtcNow,
                NextActivationTime = DateTime.UtcNow,
                Status             = WorkflowStatus.Active.ToString(),
            };

            _instanceData.Store(instance);
        }
Beispiel #2
0
        private WorkflowAgent(WorkflowHost host, string existing, CancellationToken ct, IDistributedMutex dm,
                              string templateData, string workflowDataRepositoryKey, string workflowMessagingKey, string workflowWorkspaceKey)
        {
            Id      = existing;
            _ct     = ct;
            _wfLock = dm;

            _workflowDataRepositoryKey = workflowDataRepositoryKey;
            _workflowWorkspaceKey      = workflowWorkspaceKey;

            _instanceData = Catalog.Preconfigure().ConfigureWorkflowDataRepository <WorkflowInstanceInfo>()
                            .ConfiguredResolve <IDataRepositoryService <WorkflowInstanceInfo,
                                                                        WorkflowInstanceInfo,
                                                                        DataEnvelope <WorkflowInstanceInfo, NoMetadata>,
                                                                        NoMetadata,
                                                                        DatumEnvelope <WorkflowInstanceInfo, NoMetadata>,
                                                                        NoMetadata> >
                                (_workflowDataRepositoryKey);

            _triggers = Catalog.Preconfigure().ConfigureWorkflowDataRepository <WorkflowTrigger>()
                        .ConfiguredResolve <IDataRepositoryService <WorkflowTrigger,
                                                                    WorkflowTrigger,
                                                                    DataEnvelope <WorkflowTrigger, NoMetadata>,
                                                                    NoMetadata,
                                                                    DatumEnvelope <WorkflowTrigger, NoMetadata>,
                                                                    NoMetadata> >
                            (_workflowDataRepositoryKey);

            Initialize(host, templateData);
        }
Beispiel #3
0
 public static WorkflowAgent AcquireSleepingOnLocked(IDistributedMutex wfLock, WorkflowHost host, string id,
                                                     CancellationToken ct, string templateData, string wfdrk, string wfmk, string wfwsk)
 {
     return(new WorkflowAgent(host, id, ct, wfLock, templateData, wfdrk, wfmk, wfwsk));
 }
Beispiel #4
0
        public WorkflowAgent(WorkflowHost host, string newId, CancellationToken ct, string initialData,
                             string templateData, string workflowDataRepositoryKey, string workflowMessagingKey, string workflowWorkspaceKey)
        {
            Id  = newId;
            _ct = ct;

            _workflowDataRepositoryKey = workflowDataRepositoryKey;
            _workflowWorkspaceKey      = workflowWorkspaceKey;

            _instanceData = Catalog.Preconfigure().ConfigureWorkflowDataRepository <WorkflowInstanceInfo>()
                            .ConfiguredResolve <IDataRepositoryService <WorkflowInstanceInfo,
                                                                        WorkflowInstanceInfo,
                                                                        DataEnvelope <WorkflowInstanceInfo, NoMetadata>,
                                                                        NoMetadata,
                                                                        DatumEnvelope <WorkflowInstanceInfo, NoMetadata>,
                                                                        NoMetadata> >
                                (_workflowDataRepositoryKey);

            _triggers = Catalog.Preconfigure().ConfigureWorkflowDataRepository <WorkflowTrigger>()
                        .ConfiguredResolve <IDataRepositoryService <WorkflowTrigger,
                                                                    WorkflowTrigger,
                                                                    DataEnvelope <WorkflowTrigger, NoMetadata>,
                                                                    NoMetadata,
                                                                    DatumEnvelope <WorkflowTrigger, NoMetadata>,
                                                                    NoMetadata> >
                            (_workflowDataRepositoryKey);



            Initialize(host, templateData);

            if (!string.IsNullOrEmpty(initialData))
            {
                var initialDataSet = JsonConvert.DeserializeObject <Dictionary <string, string> >(initialData);



                try
                {
                    foreach (var id in _inputDefinitions.EmptyIfNull().Where(def => !def.Optional))
                    {
                        if (!initialDataSet.ContainsKey(id.WorkspaceKey))
                        {
                            throw new InvalidWorkflowInputsException(string.Format("workspace inputs require {0}, not found", id.WorkspaceKey));
                        }
                    }


                    if (!_wfLock.Wait(TimeSpan.FromSeconds(300.0)))
                    {
                        throw new SynchronizationLockException(string.Format("Timeout waiting for workspace data to {0}", Id));
                    }

                    Workspace.Batch(
                        wsd => initialDataSet.ForEach(datum => wsd.Put(datum.Key, datum.Value))
                        );
                }
                catch (Exception ex)
                {
                    var es = string.Format("Exception initializing workspace inputs, {0}", ex.Message);
                    _log.Error(es);
                    ex.TraceInformation();
                    var on = Catalog.Factory.Resolve <IApplicationAlert>();
                    on.RaiseAlert(ApplicationAlertKind.System, es);
                    throw;
                }
                finally
                {
                    _wfLock.Release();
                }
            }
        }