protected override void GenerateSqlCommand(SqlCommand command) { LoadWorkflowCommand instancePersistenceCommand = base.InstancePersistenceCommand as LoadWorkflowCommand; LoadType loadType = instancePersistenceCommand.AcceptUninitializedInstance ? LoadType.LoadOrCreateByInstance : LoadType.LoadByInstance; Guid instanceId = base.InstancePersistenceContext.InstanceView.InstanceId; this.GenerateLoadSqlCommand(command, loadType, Guid.Empty, instanceId, null); }
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; }
protected override Exception ProcessSqlResult(SqlDataReader reader) { Exception exception = StoreUtilities.GetNextResultSet(base.InstancePersistenceCommand.Name, reader); if (exception == null) { Guid instanceId = reader.GetGuid(1); long surrogateInstanceId = reader.GetInt64(2); byte[] primitiveProperties = reader.IsDBNull(3) ? null : (byte[])(reader.GetValue(3)); byte[] complexProperties = reader.IsDBNull(4) ? null : (byte[])(reader.GetValue(4)); byte[] metadataProperties = reader.IsDBNull(5) ? null : (byte[])(reader.GetValue(5)); InstanceEncodingOption dataEncodingOption = (InstanceEncodingOption)(reader.GetByte(6)); InstanceEncodingOption metadataEncodingOption = (InstanceEncodingOption)(reader.GetByte(7)); long version = reader.GetInt64(8); bool isInitialized = reader.GetBoolean(9); bool createdInstance = reader.GetBoolean(10); LoadWorkflowCommand loadWorkflowCommand = base.InstancePersistenceCommand as LoadWorkflowCommand; LoadWorkflowByInstanceKeyCommand loadByKeycommand = base.InstancePersistenceCommand as LoadWorkflowByInstanceKeyCommand; if (!base.InstancePersistenceContext.InstanceView.IsBoundToInstance) { base.InstancePersistenceContext.BindInstance(instanceId); } if (!base.InstancePersistenceContext.InstanceView.IsBoundToInstanceOwner) { base.InstancePersistenceContext.BindInstanceOwner(base.StoreLock.LockOwnerId, base.StoreLock.LockOwnerId); } if (!base.InstancePersistenceContext.InstanceView.IsBoundToLock) { InstanceLockTracking instanceLockTracking = (InstanceLockTracking)(base.InstancePersistenceContext.UserContext); instanceLockTracking.TrackStoreLock(instanceId, version, this.DependentTransaction); base.InstancePersistenceContext.BindAcquiredLock(version); } this.instanceData = SerializationUtilities.DeserializePropertyBag(primitiveProperties, complexProperties, dataEncodingOption); this.instanceMetadata = SerializationUtilities.DeserializeMetadataPropertyBag(metadataProperties, metadataEncodingOption); if (!createdInstance) { ReadInstanceMetadataChanges(reader, this.instanceMetadata); ReadKeyData(reader, this.associatedInstanceKeys, this.completedInstanceKeys); } else if (loadByKeycommand != null) { foreach (KeyValuePair <Guid, IDictionary <XName, InstanceValue> > keyEntry in loadByKeycommand.InstanceKeysToAssociate) { this.associatedInstanceKeys.Add(keyEntry.Key, keyEntry.Value); } if (!this.associatedInstanceKeys.ContainsKey(loadByKeycommand.LookupInstanceKey)) { base.InstancePersistenceContext.AssociatedInstanceKey(loadByKeycommand.LookupInstanceKey); this.associatedInstanceKeys.Add(loadByKeycommand.LookupInstanceKey, new Dictionary <XName, InstanceValue>()); } } if (loadByKeycommand != null) { foreach (KeyValuePair <Guid, IDictionary <XName, InstanceValue> > keyEntry in loadByKeycommand.InstanceKeysToAssociate) { base.InstancePersistenceContext.AssociatedInstanceKey(keyEntry.Key); if (keyEntry.Value != null) { foreach (KeyValuePair <XName, InstanceValue> property in keyEntry.Value) { base.InstancePersistenceContext.WroteInstanceKeyMetadataValue(keyEntry.Key, property.Key, property.Value); } } } } base.InstancePersistenceContext.LoadedInstance ( isInitialized ? InstanceState.Initialized : InstanceState.Uninitialized, this.instanceData, this.instanceMetadata, this.associatedInstanceKeys, this.completedInstanceKeys ); } else if (exception is InstanceLockLostException) { base.InstancePersistenceContext.InstanceHandle.Free(); } return(exception); }
private Exception ProcessLoadWorkflow( InstancePersistenceContext context, LoadWorkflowCommand command) { try { if(command.AcceptUninitializedInstance) { context.LoadedInstance(InstanceState.Uninitialized, null, null, null, null); } else { SharedLoadWorkflow(context, context.InstanceView.InstanceId); } return null; } catch(InstancePersistenceException exception) { Console.WriteLine( // ReSharper disable LocalizableElement "ProcessLoadWorkflow exception: {0}", // ReSharper restore LocalizableElement exception.Message); return exception; } }