Exemplo n.º 1
0
        protected override void GenerateSqlCommand(SqlCommand command)
        {
            LoadWorkflowByInstanceKeyCommand keyLoadCommand = base.InstancePersistenceCommand as LoadWorkflowByInstanceKeyCommand;
            LoadType loadType = keyLoadCommand.AcceptUninitializedInstance ? LoadType.LoadOrCreateByKey : LoadType.LoadByKey;
            Guid     key      = keyLoadCommand.LookupInstanceKey;
            List <CorrelationKey> keysToAssociate = CorrelationKey.BuildKeyList(keyLoadCommand.InstanceKeysToAssociate, base.Store.InstanceEncodingOption);
            Guid instanceId = keyLoadCommand.AssociateInstanceKeyToInstanceId;

            GenerateLoadSqlCommand(command, loadType, key, instanceId, keysToAssociate);
        }
Exemplo n.º 2
0
        protected override Exception ProcessSqlResult(SqlDataReader reader)
        {
            Exception nextResultSet = StoreUtilities.GetNextResultSet(base.InstancePersistenceCommand.Name, reader);

            if (nextResultSet == null)
            {
                Guid instanceId = reader.GetGuid(1);
                reader.GetInt64(2);
                byte[] primitiveDataProperties                = reader.IsDBNull(3) ? null : ((byte[])reader.GetValue(3));
                byte[] complexDataProperties                  = reader.IsDBNull(4) ? null : ((byte[])reader.GetValue(4));
                byte[] serializedMetadataProperties           = reader.IsDBNull(5) ? null : ((byte[])reader.GetValue(5));
                InstanceEncodingOption @byte                  = (InstanceEncodingOption)reader.GetByte(6);
                InstanceEncodingOption instanceEncodingOption = (InstanceEncodingOption)reader.GetByte(7);
                long instanceVersion = reader.GetInt64(8);
                bool boolean         = reader.GetBoolean(9);
                bool flag2           = reader.GetBoolean(10);
                InstancePersistenceCommand       instancePersistenceCommand = base.InstancePersistenceCommand;
                LoadWorkflowByInstanceKeyCommand command = 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)base.InstancePersistenceContext.UserContext).TrackStoreLock(instanceId, instanceVersion, base.DependentTransaction);
                    base.InstancePersistenceContext.BindAcquiredLock(instanceVersion);
                }
                this.instanceData     = SerializationUtilities.DeserializePropertyBag(primitiveDataProperties, complexDataProperties, @byte);
                this.instanceMetadata = SerializationUtilities.DeserializeMetadataPropertyBag(serializedMetadataProperties, instanceEncodingOption);
                if (!flag2)
                {
                    this.ReadInstanceMetadataChanges(reader, this.instanceMetadata);
                    this.ReadKeyData(reader, this.associatedInstanceKeys, this.completedInstanceKeys);
                }
                else if (command != null)
                {
                    foreach (KeyValuePair <Guid, IDictionary <XName, InstanceValue> > pair in command.InstanceKeysToAssociate)
                    {
                        this.associatedInstanceKeys.Add(pair.Key, pair.Value);
                    }
                    if (!this.associatedInstanceKeys.ContainsKey(command.LookupInstanceKey))
                    {
                        base.InstancePersistenceContext.AssociatedInstanceKey(command.LookupInstanceKey);
                        this.associatedInstanceKeys.Add(command.LookupInstanceKey, new Dictionary <XName, InstanceValue>());
                    }
                }
                if (command != null)
                {
                    foreach (KeyValuePair <Guid, IDictionary <XName, InstanceValue> > pair2 in command.InstanceKeysToAssociate)
                    {
                        base.InstancePersistenceContext.AssociatedInstanceKey(pair2.Key);
                        if (pair2.Value != null)
                        {
                            foreach (KeyValuePair <XName, InstanceValue> pair3 in pair2.Value)
                            {
                                base.InstancePersistenceContext.WroteInstanceKeyMetadataValue(pair2.Key, pair3.Key, pair3.Value);
                            }
                        }
                    }
                }
                base.InstancePersistenceContext.LoadedInstance(boolean ? InstanceState.Initialized : InstanceState.Uninitialized, this.instanceData, this.instanceMetadata, this.associatedInstanceKeys, this.completedInstanceKeys);
                return(nextResultSet);
            }
            if (nextResultSet is InstanceLockLostException)
            {
                base.InstancePersistenceContext.InstanceHandle.Free();
            }
            return(nextResultSet);
        }
        InstancePersistenceCommand CreateLoadCommandHelper(InstanceKey key, out InstanceHandle handle, bool canCreateInstance, Guid suggestedIdOrId, ICollection<InstanceKey> associatedKeys, bool loadAny)
        {
            if (loadAny)
            {
                handle = this.store.CreateInstanceHandle(this.owner);
                return new TryLoadRunnableWorkflowCommand();
            }
            else if (key != null)
            {
                LoadWorkflowByInstanceKeyCommand loadByKeyCommand;
                handle = this.store.CreateInstanceHandle(this.owner);
                if (canCreateInstance)
                {
                    loadByKeyCommand = new LoadWorkflowByInstanceKeyCommand()
                    {
                        LookupInstanceKey = key.Value,
                        AssociateInstanceKeyToInstanceId = suggestedIdOrId == Guid.Empty ? Guid.NewGuid() : suggestedIdOrId,
                        AcceptUninitializedInstance = true,
                    };
                }
                else
                {
                    loadByKeyCommand = new LoadWorkflowByInstanceKeyCommand()
                    {
                        LookupInstanceKey = key.Value,
                    };
                }
                InstanceKey lookupKeyToAdd = (canCreateInstance && key.Metadata != null && key.Metadata.Count > 0) ? key : null;
                if (associatedKeys != null)
                {
                    foreach (InstanceKey keyToAssociate in associatedKeys)
                    {
                        if (keyToAssociate == key)
                        {
                            if (!canCreateInstance)
                            {
                                continue;
                            }
                            lookupKeyToAdd = null;
                        }
                        TryAddKeyToInstanceKeysCollection(loadByKeyCommand.InstanceKeysToAssociate, keyToAssociate);
                    }
                }
                if (lookupKeyToAdd != null)
                {
                    TryAddKeyToInstanceKeysCollection(loadByKeyCommand.InstanceKeysToAssociate, lookupKeyToAdd);
                }
                return loadByKeyCommand;
            }
            else
            {
                if (associatedKeys != null)
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(SR.NoAdditionalKeysOnInstanceIdLoad));
                }

                handle = this.store.CreateInstanceHandle(this.owner, suggestedIdOrId == Guid.Empty ? Guid.NewGuid() : suggestedIdOrId);
                return new LoadWorkflowCommand()
                {
                    AcceptUninitializedInstance = canCreateInstance,
                };
            }
        }
 private InstancePersistenceCommand CreateLoadCommandHelper(InstanceKey key, out InstanceHandle handle, bool canCreateInstance, Guid suggestedIdOrId, ICollection<InstanceKey> associatedKeys, bool loadAny)
 {
     if (loadAny)
     {
         handle = this.store.CreateInstanceHandle(this.owner);
         return new TryLoadRunnableWorkflowCommand();
     }
     if (key != null)
     {
         LoadWorkflowByInstanceKeyCommand command;
         handle = this.store.CreateInstanceHandle(this.owner);
         if (canCreateInstance)
         {
             command = new LoadWorkflowByInstanceKeyCommand {
                 LookupInstanceKey = key.Value,
                 AssociateInstanceKeyToInstanceId = (suggestedIdOrId == Guid.Empty) ? Guid.NewGuid() : suggestedIdOrId,
                 AcceptUninitializedInstance = true
             };
         }
         else
         {
             command = new LoadWorkflowByInstanceKeyCommand {
                 LookupInstanceKey = key.Value
             };
         }
         InstanceKey keyToAdd = ((canCreateInstance && (key.Metadata != null)) && (key.Metadata.Count > 0)) ? key : null;
         if (associatedKeys != null)
         {
             foreach (InstanceKey key3 in associatedKeys)
             {
                 if (key3 == key)
                 {
                     if (!canCreateInstance)
                     {
                         continue;
                     }
                     keyToAdd = null;
                 }
                 TryAddKeyToInstanceKeysCollection(command.InstanceKeysToAssociate, key3);
             }
         }
         if (keyToAdd != null)
         {
             TryAddKeyToInstanceKeysCollection(command.InstanceKeysToAssociate, keyToAdd);
         }
         return command;
     }
     if (associatedKeys != null)
     {
         throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activities.SR.NoAdditionalKeysOnInstanceIdLoad));
     }
     handle = this.store.CreateInstanceHandle(this.owner, (suggestedIdOrId == Guid.Empty) ? Guid.NewGuid() : suggestedIdOrId);
     return new LoadWorkflowCommand { AcceptUninitializedInstance = canCreateInstance };
 }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        private Exception ProcessLoadWorkflowByInstanceKey(
            InstancePersistenceContext context,
            LoadWorkflowByInstanceKeyCommand command)
        {

            try
            {
                Guid instanceId = _dataStore.GetInstanceAssociation(
                    command.LookupInstanceKey);
                if(instanceId == Guid.Empty)
                {
                    throw new InstanceKeyNotReadyException(
                        String.Format("Unable to load instance for key: {0}",
                            command.LookupInstanceKey));
                }

                SharedLoadWorkflow(context, instanceId);
                return null;
            }
            catch(InstancePersistenceException exception)
            {
                Console.WriteLine(
                    // ReSharper disable LocalizableElement
                    "ProcessLoadWorkflowByInstanceKey exception: {0}",
                    // ReSharper restore LocalizableElement
                    exception.Message);
                return exception;
            }

        }