Exemple #1
0
        private bool SaveWorkflow(InstancePersistenceContext context, SaveWorkflowCommand command)
        {
            if (context.InstanceVersion == -1)
            {
                context.BindAcquiredLock(0);
            }

            if (command.CompleteInstance)
            {
                context.CompletedInstance();
            }
            else
            {
                string instanceType = "";

                const string InstanceTypeXName = "{urn:schemas-microsoft-com:System.Runtime.DurableInstancing/4.0/metadata}InstanceType";
                InstanceValue instanceTypeInstanceValue;
                if (command.InstanceMetadataChanges.TryGetValue(InstanceTypeXName, out instanceTypeInstanceValue))
                {
                    instanceType = instanceTypeInstanceValue.Value.ToString();
                }

                Dictionary<string, object> fullInstanceData = new Dictionary<string, object>();
                fullInstanceData.Add("instanceId", context.InstanceView.InstanceId);
                fullInstanceData.Add("instanceOwnerId", context.InstanceView.InstanceOwner.InstanceOwnerId);
                fullInstanceData.Add("instanceData", SerializeablePropertyBag(command.InstanceData));
                fullInstanceData.Add("instanceMetadata", SerializeInstanceMetadata(context, command));

                foreach (KeyValuePair<XName, InstanceValue> property in command.InstanceMetadataChanges)
                {
                    context.WroteInstanceMetadataValue(property.Key, property.Value);
                }

                context.PersistedInstance(command.InstanceData);

                _stores.Save(WorkflowStoreComponents.Definition
                                                | WorkflowStoreComponents.Metadata
                                                | WorkflowStoreComponents.Streams
                                                | WorkflowStoreComponents.TerminatingError
                                                | WorkflowStoreComponents.Timer
                                                | WorkflowStoreComponents.ActivityState 
                                                | WorkflowStoreComponents.JobState,
                                                fullInstanceData);

            }

            return true;
        }
Exemple #2
0
        private bool LoadWorkflow(InstancePersistenceContext context, LoadWorkflowCommand command)
        {
            if (command.AcceptUninitializedInstance)
            {
                return false;
            }

            if (context.InstanceVersion == -1)
            {
                context.BindAcquiredLock(0);
            }

            Guid instanceId = context.InstanceView.InstanceId;
            Guid instanceOwnerId = context.InstanceView.InstanceOwner.InstanceOwnerId;

            IDictionary<XName, InstanceValue> instanceData = null;
            IDictionary<XName, InstanceValue> instanceMetadata = null;

            Dictionary<string, object> fullInstanceData = _stores.LoadWorkflowContext();
            
            instanceData = this.DeserializePropertyBag((Dictionary<XName, object>)fullInstanceData["instanceData"]);
            instanceMetadata = this.DeserializePropertyBag((Dictionary<XName, object>)fullInstanceData["instanceMetadata"]);

            context.LoadedInstance(InstanceState.Initialized, instanceData, instanceMetadata, null, null);

            return true;
        }