protected override Exception ProcessSqlResult(SqlDataReader reader)
        {
            Exception exception = StoreUtilities.GetNextResultSet(base.InstancePersistenceCommand.Name, reader);

            if (exception == null)
            {
                SaveWorkflowCommand  saveWorkflowCommand  = base.InstancePersistenceCommand as SaveWorkflowCommand;
                InstanceLockTracking instanceLockTracking = (InstanceLockTracking)(base.InstancePersistenceContext.UserContext);
                if ((this.serviceDeploymentHash != Guid.Empty) && (this.serviceDeploymentId == 0))
                {
                    this.serviceDeploymentId = reader.GetInt64(1);
                    PutServiceDeploymentId();
                    exception = StoreUtilities.GetNextResultSet(base.InstancePersistenceCommand.Name, reader);
                }

                if (exception == null)
                {
                    if (!base.InstancePersistenceContext.InstanceView.IsBoundToLock)
                    {
                        long instanceVersion = reader.GetInt64(1);
                        instanceLockTracking.TrackStoreLock(base.InstancePersistenceContext.InstanceView.InstanceId, instanceVersion, this.DependentTransaction);
                        base.InstancePersistenceContext.BindAcquiredLock(instanceVersion);
                    }

                    if (saveWorkflowCommand.InstanceData.Count > 0)
                    {
                        base.InstancePersistenceContext.PersistedInstance(saveWorkflowCommand.InstanceData);
                    }

                    SaveWorkflowAsyncResult.UpdateKeyData(base.InstancePersistenceContext, saveWorkflowCommand);

                    foreach (KeyValuePair <XName, InstanceValue> property in saveWorkflowCommand.InstanceMetadataChanges)
                    {
                        base.InstancePersistenceContext.WroteInstanceMetadataValue(property.Key, property.Value);
                    }

                    if (saveWorkflowCommand.CompleteInstance)
                    {
                        base.InstancePersistenceContext.CompletedInstance();
                    }

                    if (saveWorkflowCommand.UnlockInstance || saveWorkflowCommand.CompleteInstance)
                    {
                        instanceLockTracking.TrackStoreUnlock(this.DependentTransaction);
                        base.InstancePersistenceContext.InstanceHandle.Free();
                    }
                }
                else if (exception is InstanceLockLostException)
                {
                    base.InstancePersistenceContext.InstanceHandle.Free();
                }
            }

            return(exception);
        }
Ejemplo n.º 2
0
        internal void GenerateUnlockCommand(InstanceLockTracking instanceLockTracking)
        {
            UnlockInstanceCommand command = new UnlockInstanceCommand {
                SurrogateOwnerId = this.storeLock.SurrogateLockOwnerId,
                InstanceId       = instanceLockTracking.InstanceId,
                InstanceVersion  = instanceLockTracking.InstanceVersion
            };

            using (new TransactionScope(TransactionScopeOption.Suppress))
            {
                this.BeginTryCommandInternal(null, command, TimeSpan.MaxValue, this.unlockInstanceCallback, command);
            }
        }
Ejemplo n.º 3
0
        protected override Exception ProcessSqlResult(SqlDataReader reader)
        {
            Exception nextResultSet = StoreUtilities.GetNextResultSet(base.InstancePersistenceCommand.Name, reader);

            if (nextResultSet == null)
            {
                SaveWorkflowCommand  instancePersistenceCommand = base.InstancePersistenceCommand as SaveWorkflowCommand;
                InstanceLockTracking userContext = (InstanceLockTracking)base.InstancePersistenceContext.UserContext;
                if ((this.serviceDeploymentHash != Guid.Empty) && (this.serviceDeploymentId == 0L))
                {
                    this.serviceDeploymentId = reader.GetInt64(1);
                    this.PutServiceDeploymentId();
                    nextResultSet = StoreUtilities.GetNextResultSet(base.InstancePersistenceCommand.Name, reader);
                }
                if (nextResultSet == null)
                {
                    if (!base.InstancePersistenceContext.InstanceView.IsBoundToLock)
                    {
                        long instanceVersion = reader.GetInt64(1);
                        userContext.TrackStoreLock(base.InstancePersistenceContext.InstanceView.InstanceId, instanceVersion, base.DependentTransaction);
                        base.InstancePersistenceContext.BindAcquiredLock(instanceVersion);
                    }
                    if (instancePersistenceCommand.InstanceData.Count > 0)
                    {
                        base.InstancePersistenceContext.PersistedInstance(instancePersistenceCommand.InstanceData);
                    }
                    UpdateKeyData(base.InstancePersistenceContext, instancePersistenceCommand);
                    foreach (KeyValuePair <XName, InstanceValue> pair in instancePersistenceCommand.InstanceMetadataChanges)
                    {
                        base.InstancePersistenceContext.WroteInstanceMetadataValue(pair.Key, pair.Value);
                    }
                    if (instancePersistenceCommand.CompleteInstance)
                    {
                        base.InstancePersistenceContext.CompletedInstance();
                    }
                    if (instancePersistenceCommand.UnlockInstance || instancePersistenceCommand.CompleteInstance)
                    {
                        userContext.TrackStoreUnlock(base.DependentTransaction);
                        base.InstancePersistenceContext.InstanceHandle.Free();
                    }
                    return(nextResultSet);
                }
                if (nextResultSet is InstanceLockLostException)
                {
                    base.InstancePersistenceContext.InstanceHandle.Free();
                }
            }
            return(nextResultSet);
        }
        static bool OnBindReclaimed(IAsyncResult result)
        {
            SqlWorkflowInstanceStoreAsyncResult thisPtr = (SqlWorkflowInstanceStoreAsyncResult)result.AsyncState;

            thisPtr.InstancePersistenceContext.EndBindReclaimedLock(result);
            Guid instanceId  = thisPtr.InstancePersistenceContext.InstanceView.InstanceId;
            long lockVersion = thisPtr.InstancePersistenceContext.InstanceVersion;

            InstanceLockTracking instanceLockTracking = (InstanceLockTracking)(thisPtr.InstancePersistenceContext.UserContext);

            instanceLockTracking.TrackStoreLock(instanceId, lockVersion, null);
            thisPtr.InstancePersistenceContext.InstanceHandle.Free();

            throw FxTrace.Exception.AsError(new InstanceLockLostException(thisPtr.InstancePersistenceCommand.Name, instanceId));
        }
 internal void GenerateUnlockCommand(InstanceLockTracking instanceLockTracking)
 {
     UnlockInstanceCommand command = new UnlockInstanceCommand {
         SurrogateOwnerId = this.storeLock.SurrogateLockOwnerId,
         InstanceId = instanceLockTracking.InstanceId,
         InstanceVersion = instanceLockTracking.InstanceVersion
     };
     using (new TransactionScope(TransactionScopeOption.Suppress))
     {
         this.BeginTryCommandInternal(null, command, TimeSpan.MaxValue, this.unlockInstanceCallback, command);
     }
 }
Ejemplo n.º 6
0
        protected override void OnFreeInstanceHandle(InstanceHandle instanceHandle, object userContext)
        {
            InstanceLockTracking instanceLockTracking = (InstanceLockTracking)(userContext);

            instanceLockTracking.HandleFreed();
        }
Ejemplo n.º 7
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);
        }