Ejemplo n.º 1
0
        public static Exception GetError(XName commandName, CommandResult result, SqlDataReader reader)
        {
            Exception returnValue = null;

            if (result != CommandResult.Success)
            {
                switch (result)
                {
                    case CommandResult.InstanceAlreadyExists:
                        returnValue = new InstanceCollisionException(commandName, reader.GetGuid(1));
                        break;
                    case CommandResult.InstanceLockNotAcquired:
                        returnValue = new InstanceLockedException(commandName, reader.GetGuid(1), reader.GetGuid(2), ReadLockOwnerMetadata(reader));
                        break;
                    case CommandResult.InstanceNotFound:
                        returnValue = new InstanceNotReadyException(commandName, reader.GetGuid(1));
                        break;
                    case CommandResult.KeyAlreadyExists:
                        returnValue = new InstanceKeyCollisionException(commandName, Guid.Empty,
                            new InstanceKey(reader.GetGuid(1)), Guid.Empty);
                        break;
                    case CommandResult.KeyNotFound:
                        returnValue = new InstanceKeyNotReadyException(commandName, new InstanceKey(reader.GetGuid(1)));
                        break;
                    case CommandResult.InstanceLockLost:
                        returnValue = new InstanceLockLostException(commandName, reader.GetGuid(1));
                        break;
                    case CommandResult.InstanceCompleted:
                        returnValue = new InstanceCompleteException(commandName, reader.GetGuid(1));
                        break;
                    case CommandResult.KeyDisassociated:
                        returnValue = new InstanceKeyCompleteException(commandName, new InstanceKey(reader.GetGuid(1)));
                        break;
                    case CommandResult.StaleInstanceVersion:
                        returnValue = new InstanceLockLostException(commandName, reader.GetGuid(1));
                        break;
                    case CommandResult.HostLockExpired:
                        returnValue = new InstancePersistenceException(SR.HostLockExpired);
                        break;
                    case CommandResult.HostLockNotFound:
                        returnValue = new InstancePersistenceException(SR.HostLockNotFound);
                        break;
                    case CommandResult.CleanupInProgress:
                        returnValue = new InstancePersistenceCommandException(SR.CleanupInProgress);
                        break;
                    case CommandResult.InstanceAlreadyLockedToOwner:
                        returnValue = new InstanceAlreadyLockedToOwnerException(commandName, reader.GetGuid(1), reader.GetInt64(2));
                        break;
                    default:
                        returnValue = new InstancePersistenceCommandException(SR.UnknownSprocResult(result));
                        break;
                }
            }

            return returnValue;
        }
            bool TryCreateRedirectionException(InstanceLockedException exception, out RedirectionException redirectionException)
            {
                Uri redirectVia = null;

                object redirectViaObject;
                string endpointName = this.invoker.endpoint != null ? this.invoker.endpoint.Name : null;
                XName endpointXName = endpointName == null ? null : WorkflowServiceNamespace.EndpointsPath.GetName(endpointName);
                if (endpointXName != null && exception.SerializableInstanceOwnerMetadata != null &&
                    exception.SerializableInstanceOwnerMetadata.TryGetValue(endpointXName, out redirectViaObject))
                {
                    redirectVia = redirectViaObject as Uri;
                }

                if (redirectVia == null)
                {
                    redirectionException = null;
                    return false;
                }

                redirectionException = new RedirectionException(RedirectionType.Resource, RedirectionDuration.Permanent,
                    RedirectionScope.Session, new RedirectionLocation(redirectVia));
                return true;
            }
 private bool TryCreateRedirectionException(InstanceLockedException exception, out RedirectionException redirectionException)
 {
     Uri address = null;
     object obj2;
     string localName = (this.invoker.endpoint != null) ? this.invoker.endpoint.Name : null;
     XName key = (localName == null) ? null : WorkflowServiceNamespace.EndpointsPath.GetName(localName);
     if (((key != null) && (exception.SerializableInstanceOwnerMetadata != null)) && exception.SerializableInstanceOwnerMetadata.TryGetValue(key, out obj2))
     {
         address = obj2 as Uri;
     }
     if (address == null)
     {
         redirectionException = null;
         return false;
     }
     redirectionException = new RedirectionException(RedirectionType.Resource, RedirectionDuration.Permanent, RedirectionScope.Session, new RedirectionLocation[] { new RedirectionLocation(address) });
     return true;
 }