Example #1
0
 public static void ThrowIfNonPositiveArgument(TimeSpan timeout, string argumentName)
 {
     if (timeout <= TimeSpan.Zero)
     {
         throw Fx.Exception.ArgumentOutOfRange(argumentName, timeout, SRCore.TimeoutMustBePositive(argumentName, timeout));
     }
 }
Example #2
0
 protected void Complete(bool completedSynchronously)
 {
     if (this.isCompleted)
     {
         throw Fx.Exception.AsError(new InvalidOperationException(SRCore.AsyncResultCompletedTwice(base.GetType())));
     }
     this.completedSynchronously = completedSynchronously;
     if (this.OnCompleting != null)
     {
         try
         {
             this.OnCompleting(this, this.exception);
         }
         catch (Exception exception)
         {
             if (Fx.IsFatal(exception))
             {
                 throw;
             }
             this.exception = exception;
         }
     }
     if (completedSynchronously)
     {
         this.isCompleted = true;
     }
     else
     {
         lock (this.ThisLock)
         {
             this.isCompleted = true;
             if (this.manualResetEvent != null)
             {
                 this.manualResetEvent.Set();
             }
         }
     }
     if (this.callback != null)
     {
         try
         {
             if (this.VirtualCallback != null)
             {
                 this.VirtualCallback(this.callback, this);
             }
             else
             {
                 this.callback(this);
             }
         }
         catch (Exception exception2)
         {
             if (Fx.IsFatal(exception2))
             {
                 throw;
             }
             throw Fx.Exception.AsError(new CallbackException(SRCore.AsyncCallbackThrewException, exception2));
         }
     }
 }
Example #3
0
        public T Dequeue(TimeSpan timeout)
        {
            T local;

            if (!this.Dequeue(timeout, out local))
            {
                throw Fx.Exception.AsError(new TimeoutException(SRCore.TimeoutInputQueueDequeue(timeout)));
            }
            return(local);
        }
 public static char[] AllocateCharArray(int size)
 {
     char[] chArray;
     try
     {
         chArray = new char[size];
     }
     catch (OutOfMemoryException exception)
     {
         throw Exception.AsError(new InsufficientMemoryException(SRCore.BufferAllocationFailed(size * 2), exception));
     }
     return(chArray);
 }
 public static byte[] AllocateByteArray(int size)
 {
     byte[] buffer;
     try
     {
         buffer = new byte[size];
     }
     catch (OutOfMemoryException exception)
     {
         throw Exception.AsError(new InsufficientMemoryException(SRCore.BufferAllocationFailed(size), exception));
     }
     return(buffer);
 }
        internal static object ConvertFromHelper(ITypeDescriptorContext context, object value)
        {
            string str2;
            string str3;

            if (value == null)
            {
                return(null);
            }
            string expandedName = value as string;

            if (expandedName == null)
            {
                return(null);
            }
            expandedName = expandedName.Trim();
            if (expandedName == string.Empty)
            {
                return(null);
            }
            IXamlNamespaceResolver service = context.GetService(typeof(IXamlNamespaceResolver)) as IXamlNamespaceResolver;

            if (service == null)
            {
                return(null);
            }
            if (expandedName[0] == '{')
            {
                return(XName.Get(expandedName));
            }
            int index = expandedName.IndexOf(':');

            if (index >= 0)
            {
                str2 = expandedName.Substring(0, index);
                str3 = expandedName.Substring(index + 1);
            }
            else
            {
                str2 = string.Empty;
                str3 = expandedName;
            }
            string namespaceName = service.GetNamespace(str2);

            if (namespaceName == null)
            {
                throw Fx.Exception.AsError(new FormatException(SRCore.CouldNotResolveNamespacePrefix(str2)));
            }
            return(XName.Get(str3, namespaceName));
        }
Example #7
0
 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cultureInfo, object value, Type type)
 {
     if (value == null)
     {
         throw Fx.Exception.ArgumentNull("value");
     }
     if (!(value is TimeSpan))
     {
         throw Fx.Exception.Argument("value", SRCore.IncompatibleArgumentType(typeof(TimeSpan), value.GetType()));
     }
     if (((TimeSpan)value) == TimeSpan.MaxValue)
     {
         return("Infinite");
     }
     return(base.ConvertTo(context, cultureInfo, value, type));
 }
Example #8
0
 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));
         }
     }
 }
Example #9
0
        public void Collect()
        {
            Fx.AssertAndThrow(this.expectedStage == Stage.Collect, "Collect called at the wrong time.");
            this.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
                        {
                            this.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
                        {
                            this.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));
                        }
                    }
                }
            }

            this.expectedStage = Stage.Map;
        }
Example #10
0
        public void Map()
        {
            Fx.AssertAndThrow(this.expectedStage == Stage.Map, "Map called at the wrong time.");
            this.expectedStage = Stage.None;

            List <Tuple <IPersistencePipelineModule, IDictionary <XName, object> > > pendingValues = null;

            foreach (IPersistencePipelineModule module in modules)
            {
                IDictionary <XName, object> mappedValues = module.MapValues(this.readWriteView, this.writeOnlyView);
                if (mappedValues != null)
                {
                    if (pendingValues == null)
                    {
                        pendingValues = new List <Tuple <IPersistencePipelineModule, IDictionary <XName, object> > >();
                    }
                    pendingValues.Add(new Tuple <IPersistencePipelineModule, IDictionary <XName, object> >(module, mappedValues));
                }
            }

            if (pendingValues != null)
            {
                foreach (Tuple <IPersistencePipelineModule, IDictionary <XName, object> > writeOnlyValues in pendingValues)
                {
                    foreach (KeyValuePair <XName, object> value in writeOnlyValues.Item2)
                    {
                        try
                        {
                            this.values.Add(value.Key, new InstanceValue(value.Value, InstanceValueOptions.Optional | InstanceValueOptions.WriteOnly));
                        }
                        catch (ArgumentException exception)
                        {
                            throw Fx.Exception.AsError(new InvalidOperationException(SRCore.NameCollisionOnMap(value.Key, writeOnlyValues.Item1.GetType().Name), exception));
                        }
                    }
                }

                this.writeOnlyView.ResetCaches();
            }

            this.expectedStage = Stage.Save;
        }
Example #11
0
        public static System.Exception AssertAndFailFast(string description)
        {
            string message = SRCore.FailFastMessage(description);

            try
            {
                try
                {
                    Exception.TraceFailFast(message);
                }
                finally
                {
                    Environment.FailFast(message);
                }
            }
            catch
            {
                throw;
            }
            return(null);
        }
 public void Collect()
 {
     Fx.AssertAndThrow(this.expectedStage == Stage.Collect, "Collect called at the wrong time.");
     this.expectedStage = Stage.None;
     foreach (IPersistencePipelineModule module in this.modules)
     {
         IDictionary <XName, object> dictionary;
         IDictionary <XName, object> dictionary2;
         module.CollectValues(out dictionary, out dictionary2);
         if (dictionary != null)
         {
             foreach (KeyValuePair <XName, object> pair in dictionary)
             {
                 try
                 {
                     this.values.Add(pair.Key, new InstanceValue(pair.Value));
                 }
                 catch (ArgumentException exception)
                 {
                     throw Fx.Exception.AsError(new InvalidOperationException(SRCore.NameCollisionOnCollect(pair.Key, module.GetType().Name), exception));
                 }
             }
         }
         if (dictionary2 != null)
         {
             foreach (KeyValuePair <XName, object> pair2 in dictionary2)
             {
                 try
                 {
                     this.values.Add(pair2.Key, new InstanceValue(pair2.Value, InstanceValueOptions.WriteOnly | InstanceValueOptions.Optional));
                 }
                 catch (ArgumentException exception2)
                 {
                     throw Fx.Exception.AsError(new InvalidOperationException(SRCore.NameCollisionOnCollect(pair2.Key, module.GetType().Name), exception2));
                 }
             }
         }
     }
     this.expectedStage = Stage.Map;
 }
Example #13
0
 void Abort()
 {
     for (int j = 0; j < this.pendingModules.Length; j++)
     {
         IPersistencePipelineModule module = this.pendingModules[j];
         if (module != null)
         {
             try
             {
                 module.Abort();
             }
             catch (Exception exception)
             {
                 if (Fx.IsFatal(exception))
                 {
                     throw;
                 }
                 throw Fx.Exception.AsError(new CallbackException(SRCore.PersistencePipelineAbortThrew(module.GetType().Name), exception));
             }
         }
     }
 }
Example #14
0
        public static T Convert <T>(object source)
        {
            T local;

            if (source is T)
            {
                return((T)source);
            }
            if (source == null)
            {
                if (typeof(T).IsValueType && !IsNullableType(typeof(T)))
                {
                    throw Fx.Exception.AsError(new InvalidCastException(SRCore.CannotConvertObject(source, typeof(T))));
                }
                return(default(T));
            }
            if (!TryNumericConversion <T>(source, out local))
            {
                throw Fx.Exception.AsError(new InvalidCastException(SRCore.CannotConvertObject(source, typeof(T))));
            }
            return(local);
        }
        public void Map()
        {
            Fx.AssertAndThrow(this.expectedStage == Stage.Map, "Map called at the wrong time.");
            this.expectedStage = Stage.None;
            List <Tuple <IPersistencePipelineModule, IDictionary <XName, object> > > list = null;

            foreach (IPersistencePipelineModule module in this.modules)
            {
                IDictionary <XName, object> dictionary = module.MapValues(this.readWriteView, this.writeOnlyView);
                if (dictionary != null)
                {
                    if (list == null)
                    {
                        list = new List <Tuple <IPersistencePipelineModule, IDictionary <XName, object> > >();
                    }
                    list.Add(new Tuple <IPersistencePipelineModule, IDictionary <XName, object> >(module, dictionary));
                }
            }
            if (list != null)
            {
                foreach (Tuple <IPersistencePipelineModule, IDictionary <XName, object> > tuple in list)
                {
                    foreach (KeyValuePair <XName, object> pair in tuple.Item2)
                    {
                        try
                        {
                            this.values.Add(pair.Key, new InstanceValue(pair.Value, InstanceValueOptions.WriteOnly | InstanceValueOptions.Optional));
                        }
                        catch (ArgumentException exception)
                        {
                            throw Fx.Exception.AsError(new InvalidOperationException(SRCore.NameCollisionOnMap(pair.Key, tuple.Item1.GetType().Name), exception));
                        }
                    }
                }
                this.writeOnlyView.ResetCaches();
            }
            this.expectedStage = Stage.Save;
        }
Example #16
0
 public ArgumentException ArgumentNullOrEmpty(string paramName)
 {
     return(this.Argument(paramName, SRCore.ArgumentNullOrEmpty(paramName)));
 }
Example #17
0
 public InternalException(string description) : base(SRCore.ShipAssertExceptionMessage(description))
 {
 }
 internal static TimeoutException CreateEnterTimedOutException(TimeSpan timeout)
 {
     return(new TimeoutException(SRCore.LockTimeoutExceptionMessage(timeout)));
 }
Example #19
0
 private static void ThrowInvalidAsyncResult(IAsyncResult result)
 {
     throw Fx.Exception.AsError(new InvalidOperationException(SRCore.InvalidAsyncResultImplementation(result.GetType())));
 }
 protected override void Invoke()
 {
     this.callback(this.state, this.TimedOut ? new TimeoutException(SRCore.TimeoutOnOperation(this.originalTimeout)) : null);
 }
 protected virtual Exception CreateQuotaExceededException(int maxSizeQuota)
 {
     return(new InvalidOperationException(SRCore.BufferedOutputStreamQuotaExceeded(maxSizeQuota)));
 }