internal SharedAccessSignatureTokenProvider(string keyName, string sharedAccessKey, TimeSpan tokenTimeToLive)
        {
            if (string.IsNullOrEmpty(keyName))
            {
                throw new ArgumentNullException("keyName");
            }

            if (keyName.Length > MaxKeyNameLength)
            {
                throw new ArgumentOutOfRangeException(
                          "keyName",
                          SRCore.ArgumentStringTooBig("keyName", MaxKeyNameLength));
            }

            if (string.IsNullOrEmpty(sharedAccessKey))
            {
                throw new ArgumentNullException("sharedAccessKey");
            }

            if (sharedAccessKey.Length > MaxKeyLength)
            {
                throw new ArgumentOutOfRangeException(
                          "sharedAccessKey",
                          SRCore.ArgumentStringTooBig("sharedAccessKey", MaxKeyLength));
            }

            this._encodedSharedAccessKey = Encoding.UTF8.GetBytes(sharedAccessKey);
            this._keyName         = keyName;
            this._tokenTimeToLive = tokenTimeToLive;
        }
 private void ThrowIfSbmpClient(string operationName)
 {
     if (this.cachedSettings.Value.TransportType == TransportType.NetMessaging)
     {
         throw new NotSupportedException(SRCore.UnsupportedTransport(operationName, TransportType.NetMessaging.ToString()));
     }
 }
Exemple #3
0
            internal WaitForEventsAsyncResult(InstanceHandle handle, TimeSpan timeout, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.handle  = handle;
                this.timeout = timeout;

                if (this.timeout != TimeSpan.Zero && this.timeout != TimeSpan.MaxValue)
                {
                    this.timer = new IOThreadTimer(WaitForEventsAsyncResult.timeoutCallback, this, false);
                }

                List <InstancePersistenceEvent> existingReadyEvents = this.handle.StartWaiting(this, this.timer, this.timeout);

                if (existingReadyEvents == null)
                {
                    if (this.timeout == TimeSpan.Zero)
                    {
                        this.handle.CancelWaiting(this);
                        throw Fx.Exception.AsError(new TimeoutException(SRCore.WaitForEventsTimedOut(TimeSpan.Zero)));
                    }
                }
                else
                {
                    this.readyEvents = existingReadyEvents;
                    Complete(true);
                }
            }
Exemple #4
0
 private static string ToMessage(XName commandName)
 {
     if (commandName != null)
     {
         return(SRCore.GenericInstanceCommand(commandName));
     }
     return(SRCore.GenericInstanceCommandNull);
 }
 static string ToMessage(Guid instanceOwnerId)
 {
     if (instanceOwnerId == Guid.Empty)
     {
         return(SRCore.InstanceOwnerDefault);
     }
     return(SRCore.InstanceOwnerSpecific(instanceOwnerId));
 }
        //[Fx.Tag.SecurityNote(Critical = "Overrides critical inherited method")]
        //[SecurityCritical]
        ////[SuppressMessage(FxCop.Category.Security, FxCop.Rule.SecureGetObjectDataOverrides,
        //    //Justification = "Method is SecurityCritical")]
        //public override void GetObjectData(SerializationInfo info, StreamingContext context)
        //{
        //    base.GetObjectData(info, context);
        //    info.AddValue(InstanceKeyName, (InstanceKey != null && InstanceKey.IsValid) ? InstanceKey.Value : Guid.Empty, typeof(Guid));
        //}

        private static string ToMessage(InstanceKey instanceKey)
        {
            if (instanceKey != null && instanceKey.IsValid)
            {
                return(SRCore.KeyNotReadySpecific(instanceKey.Value));
            }
            return(SRCore.KeyNotReadyDefault);
        }
 static string ToMessage(Guid instanceId)
 {
     if (instanceId != Guid.Empty)
     {
         return(SRCore.InstanceNotReadySpecific(instanceId));
     }
     return(SRCore.InstanceNotReadyDefault);
 }
Exemple #8
0
 private static string ToMessage(Guid instanceId)
 {
     if (instanceId != Guid.Empty)
     {
         return(SRCore.InstanceCompleteSpecific(instanceId));
     }
     return(SRCore.InstanceCompleteDefault);
 }
Exemple #9
0
 private static string ToMessage(Guid instanceId)
 {
     if (instanceId != Guid.Empty)
     {
         return(SRCore.InstanceHandleConflictSpecific(instanceId));
     }
     return(SRCore.InstanceHandleConflictDefault);
 }
Exemple #10
0
 private static void OnTimeout(object state)
 {
     InstanceHandle.WaitForEventsAsyncResult result = (InstanceHandle.WaitForEventsAsyncResult)state;
     if (result.handle.CancelWaiting(result))
     {
         result.Complete(false, new TimeoutException(SRCore.WaitForEventsTimedOut(result.timeout)));
     }
 }
Exemple #11
0
 private void ThrowIfSenderNull(string operationName)
 {
     this.EnsureCreateInternalSender();
     if (this.InternalSender == null)
     {
         throw FxTrace.Exception.AsError(new InvalidOperationException(SRCore.UnsupportedOperation(operationName)), null);
     }
 }
 static string ToMessage(Guid instanceId)
 {
     if (instanceId != Guid.Empty)
     {
         return(SRCore.InstanceLockLostSpecific(instanceId));
     }
     return(SRCore.InstanceLockLostDefault);
 }
Exemple #13
0
 static string ToMessage(InstanceKey instanceKey)
 {
     if (instanceKey != null && instanceKey.IsValid)
     {
         return(SRCore.KeyCompleteSpecific(instanceKey.Value));
     }
     return(SRCore.KeyCompleteDefault);
 }
 static string ToMessage(Guid instanceId)
 {
     if (instanceId == Guid.Empty)
     {
         return(SRCore.CannotAcquireLockDefault);
     }
     return(SRCore.CannotAcquireLockSpecific(instanceId));
 }
Exemple #15
0
 private static string ToMessage(System.Runtime.DurableInstancing.InstanceKey instanceKey)
 {
     if ((instanceKey != null) && instanceKey.IsValid)
     {
         return(SRCore.KeyCompleteSpecific(instanceKey.Value));
     }
     return(SRCore.KeyCompleteDefault);
 }
Exemple #16
0
 static string ToMessage(Guid instanceId)
 {
     if (instanceId != Guid.Empty)
     {
         return(SRCore.InstanceCollisionSpecific(instanceId));
     }
     return(SRCore.InstanceCollisionDefault);
 }
Exemple #17
0
            static void OnTimeout(object state)
            {
                WaitForEventsAsyncResult thisPtr = (WaitForEventsAsyncResult)state;

                if (thisPtr.handle.CancelWaiting(thisPtr))
                {
                    thisPtr.Complete(false, new TimeoutException(SRCore.WaitForEventsTimedOut(thisPtr.timeout)));
                }
            }
        internal static object ConvertFromHelper(ITypeDescriptorContext context, object value)
        {
            if (value == null)
            {
                return(null);
            }

            String stringValue = value as String;

            if (stringValue == null)
            {
                return(null);
            }

            stringValue = stringValue.Trim();
            if (stringValue == String.Empty)
            {
                return(null);
            }

            IXamlNamespaceResolver resolver =
                context.GetService(typeof(IXamlNamespaceResolver)) as IXamlNamespaceResolver;

            if (resolver == null)
            {
                return(null);
            }

            if (stringValue[0] == '{')
            {
                return(XName.Get(stringValue));
            }

            int    indexOfColon = stringValue.IndexOf(':');
            string prefix, localName;

            if (indexOfColon >= 0)
            {
                prefix    = stringValue.Substring(0, indexOfColon);
                localName = stringValue.Substring(indexOfColon + 1);
            }
            else
            {
                prefix    = string.Empty;
                localName = stringValue;
            }

            string ns = resolver.GetNamespace(prefix);

            if (ns == null)
            {
                throw FxTrace.Exception.AsError(new FormatException(SRCore.CouldNotResolveNamespacePrefix(prefix)));
            }

            return(XName.Get(localName, ns));
        }
Exemple #19
0
        protected override object GetElementKey(ConfigurationElement element)
        {
            TokenProviderElement tokenProviderElement = (TokenProviderElement)element;

            if (tokenProviderElement == null || string.IsNullOrEmpty(tokenProviderElement.Name))
            {
                throw new ConfigurationErrorsException(SRCore.NullOrEmptyConfigurationAttribute("name", "tokenProvider"));
            }
            return(tokenProviderElement.Name);
        }
            Message System.ServiceModel.Channels.IInputChannel.EndReceive(IAsyncResult result)
            {
                AmqpChannelListener.AmqpInputSessionChannel.TryReceiveAsyncResult tryReceiveAsyncResult = AsyncResult <AmqpChannelListener.AmqpInputSessionChannel.TryReceiveAsyncResult> .End(result);

                if (!tryReceiveAsyncResult.Outcome)
                {
                    throw new TimeoutException(SRCore.TimeoutOnOperation(tryReceiveAsyncResult.OriginalTimeout));
                }
                return(tryReceiveAsyncResult.Message);
            }
 public Message Receive(TimeSpan timeout)
 {
     AmqpChannelListener.AmqpInputSessionChannel.TryReceiveAsyncResult tryReceiveAsyncResult = new AmqpChannelListener.AmqpInputSessionChannel.TryReceiveAsyncResult(this, timeout, null, null);
     tryReceiveAsyncResult.RunSynchronously();
     if (!tryReceiveAsyncResult.Outcome)
     {
         throw new TimeoutException(SRCore.TimeoutOnOperation(timeout));
     }
     return(tryReceiveAsyncResult.Message);
 }
        private void EtwRegister()
        {
            this.etwCallback = new System.Runtime.Interop.UnsafeNativeMethods.EtwEnableCallback(this.EtwEnableCallBack);
            uint num = System.Runtime.Interop.UnsafeNativeMethods.EventRegister(ref this.providerId, this.etwCallback, null, ref this.traceRegistrationHandle);

            if (num != 0)
            {
                throw new InvalidOperationException(SRCore.EtwRegistrationFailed(num.ToString("x", CultureInfo.CurrentCulture)));
            }
        }
        unsafe void EtwRegister()
        {
            this.etwCallback = new UnsafeNativeMethods.EtwEnableCallback(EtwEnableCallBack);
            uint etwRegistrationStatus = UnsafeNativeMethods.EventRegister(ref this.providerId, this.etwCallback, null, ref this.traceRegistrationHandle);

            if (etwRegistrationStatus != 0)
            {
                throw new InvalidOperationException(SRCore.EtwRegistrationFailed(etwRegistrationStatus.ToString("x", CultureInfo.CurrentCulture)));
            }
        }
Exemple #24
0
 private static string ToMessage(Guid instanceId, Guid instanceOwnerId)
 {
     if (instanceId == Guid.Empty)
     {
         return(SRCore.CannotAcquireLockDefault);
     }
     if (instanceOwnerId == Guid.Empty)
     {
         return(SRCore.CannotAcquireLockSpecific(instanceId));
     }
     return(SRCore.CannotAcquireLockSpecificWithOwner(instanceId, instanceOwnerId));
 }
 static string ToMessage(Guid instanceId, InstanceKey instanceKey, Guid conflictingInstanceId)
 {
     if (instanceKey != null && instanceKey.IsValid)
     {
         if (instanceId != Guid.Empty && conflictingInstanceId != Guid.Empty)
         {
             return(SRCore.KeyCollisionSpecific(instanceId, instanceKey.Value, conflictingInstanceId));
         }
         return(SRCore.KeyCollisionSpecificKeyOnly(instanceKey.Value));
     }
     return(SRCore.KeyCollisionDefault);
 }
 private static string ToMessage(Guid instanceId, System.Runtime.DurableInstancing.InstanceKey instanceKey, Guid conflictingInstanceId)
 {
     if ((instanceKey == null) || !instanceKey.IsValid)
     {
         return(SRCore.KeyCollisionDefault);
     }
     if ((instanceId != Guid.Empty) && (conflictingInstanceId != Guid.Empty))
     {
         return(SRCore.KeyCollisionSpecific(instanceId, instanceKey.Value, conflictingInstanceId));
     }
     return(SRCore.KeyCollisionSpecificKeyOnly(instanceKey.Value));
 }
 public static void ValidateProperty(this KeyValuePair <XName, InstanceValue> property, bool allowDelete)
 {
     if (property.Key == null)
     {
         throw Fx.Exception.AsError(new InvalidOperationException(SRCore.MetadataCannotContainNullKey));
     }
     if (property.Value == null)
     {
         throw Fx.Exception.AsError(new InvalidOperationException(SRCore.MetadataCannotContainNullValue(property.Key)));
     }
     if (!allowDelete && property.Value.IsDeletedValue)
     {
         throw Fx.Exception.AsError(new InvalidOperationException(SRCore.InitialMetadataCannotBeDeleted(property.Key)));
     }
 }
 public void Abort()
 {
     foreach (IPersistencePipelineModule module in _modules)
     {
         try
         {
             module.Abort();
         }
         catch (Exception exception)
         {
             if (Fx.IsFatal(exception))
             {
                 throw;
             }
             throw Fx.Exception.AsError(new CallbackException(SRCore.PersistencePipelineAbortThrew(module.GetType().Name), exception));
         }
     }
 }
Exemple #29
0
        /// <summary>
        /// Checks the validity of the authorization rule.
        /// </summary>
        protected override void OnValidate()
        {
            if (string.IsNullOrEmpty(this.InternalKeyName) || !string.Equals(this.InternalKeyName, Auth.SharedAccessSignatureBuilder.UrlEncode(this.InternalKeyName)))
            {
                throw new InvalidDataContractException(SRCore.SharedAccessAuthorizationRuleKeyContainsInvalidCharacters);
            }

            if (this.InternalKeyName.Length > 256)
            {
                throw new InvalidDataContractException(SRCore.SharedAccessAuthorizationRuleKeyNameTooBig((object)256));
            }
            if (string.IsNullOrEmpty(this.InternalPrimaryKey))
            {
                throw new InvalidDataContractException(SRCore.SharedAccessAuthorizationRuleRequiresPrimaryKey);
            }

            if (Encoding.ASCII.GetByteCount(this.InternalPrimaryKey) != 44)
            {
                throw new InvalidDataContractException(SRCore.SharedAccessRuleAllowsFixedLengthKeys((object)44));
            }

            if (!SharedAccessAuthorizationRule.CheckBase64(this.InternalPrimaryKey))
            {
                throw new InvalidDataContractException(SRCore.SharedAccessKeyShouldbeBase64);
            }

            if (!string.IsNullOrEmpty(this.InternalSecondaryKey))
            {
                if (Encoding.ASCII.GetByteCount(this.InternalSecondaryKey) != 44)
                {
                    throw new InvalidDataContractException(SRCore.SharedAccessRuleAllowsFixedLengthKeys((object)44));
                }
                if (!SharedAccessAuthorizationRule.CheckBase64(this.InternalSecondaryKey))
                {
                    throw new InvalidDataContractException(SRCore.SharedAccessKeyShouldbeBase64);
                }
            }

            if (!SharedAccessAuthorizationRule.IsValidCombinationOfRights(this.Rights))
            {
                throw new InvalidDataContractException(SRClient.InvalidCombinationOfManageRight);
            }
        }
        public void Collect()
        {
            Fx.AssertAndThrow(_expectedStage == Stage.Collect, "Collect called at the wrong time.");
            _expectedStage = Stage.None;

            foreach (IPersistencePipelineModule module in _modules)
            {
                IDictionary <XName, object> readWriteValues;
                IDictionary <XName, object> writeOnlyValues;

                module.CollectValues(out readWriteValues, out writeOnlyValues);
                if (readWriteValues != null)
                {
                    foreach (KeyValuePair <XName, object> value in readWriteValues)
                    {
                        try
                        {
                            _values.Add(value.Key, new InstanceValue(value.Value));
                        }
                        catch (ArgumentException exception)
                        {
                            throw Fx.Exception.AsError(new InvalidOperationException(SRCore.NameCollisionOnCollect(value.Key, module.GetType().Name), exception));
                        }
                    }
                }
                if (writeOnlyValues != null)
                {
                    foreach (KeyValuePair <XName, object> value in writeOnlyValues)
                    {
                        try
                        {
                            _values.Add(value.Key, new InstanceValue(value.Value, InstanceValueOptions.Optional | InstanceValueOptions.WriteOnly));
                        }
                        catch (ArgumentException exception)
                        {
                            throw Fx.Exception.AsError(new InvalidOperationException(SRCore.NameCollisionOnCollect(value.Key, module.GetType().Name), exception));
                        }
                    }
                }
            }

            _expectedStage = Stage.Map;
        }