Example #1
0
        public static ResultDescriptor Find(Result result)
        {
            ResultDescriptor resultDescriptor;

            lock (LockDescriptor)
            {
                if (RegisteredDescriptorProvider.Count > 0)
                {
                    foreach (Type type in RegisteredDescriptorProvider)
                    {
                        AddDescriptorsFromType(type);
                    }
                    RegisteredDescriptorProvider.Clear();
                }

                if (!Descriptors.TryGetValue(result, out resultDescriptor))
                {
                    resultDescriptor = new ResultDescriptor(result, "Unknown", "Unknown", "Unknown", (string)null);
                }
                if (resultDescriptor.Description == null)
                {
                    string descriptionFromResultCode = GetDescriptionFromResultCode(result.Code);
                    resultDescriptor.Description = descriptionFromResultCode ?? "Unknown";
                }
            }

            return(resultDescriptor);
        }
Example #2
0
 private static void AddDescriptorsFromType(Type type)
 {
     foreach (FieldInfo declaredField in type.GetTypeInfo().DeclaredFields)
     {
         if (declaredField.FieldType == typeof(ResultDescriptor) && declaredField.IsPublic &&
             declaredField.IsStatic)
         {
             ResultDescriptor resultDescriptor = (ResultDescriptor)declaredField.GetValue((object)null);
             if (!Descriptors.ContainsKey(resultDescriptor.Result))
             {
                 Descriptors.Add(resultDescriptor.Result, resultDescriptor);
             }
         }
     }
 }
Example #3
0
 public static ResultDescriptor Find(Result result)
 {
     ResultDescriptor resultDescriptor;
       lock (ResultDescriptor.LockDescriptor)
       {
     if (ResultDescriptor.RegisteredDescriptorProvider.Count > 0)
     {
       foreach (Type item_0 in ResultDescriptor.RegisteredDescriptorProvider)
     ResultDescriptor.AddDescriptorsFromType(item_0);
       ResultDescriptor.RegisteredDescriptorProvider.Clear();
     }
     if (!ResultDescriptor.Descriptors.TryGetValue(result, out resultDescriptor))
       resultDescriptor = new ResultDescriptor(result, "Unknown", "Unknown", "Unknown", (string) null);
     if (resultDescriptor.Description == null)
     {
       string local_2 = ResultDescriptor.GetDescriptionFromResultCode(result.Code);
       resultDescriptor.Description = local_2 ?? "Unknown";
     }
       }
       return resultDescriptor;
 }
Example #4
0
 public bool Equals(ResultDescriptor other)
 {
     if (object.ReferenceEquals((object) null, (object) other))
     return false;
       if (object.ReferenceEquals((object) this, (object) other))
     return true;
       else
     return other.Result.Equals(this.Result);
 }
Example #5
0
 /// <summary>
 /// Determines whether the specified <see cref="ResultDescriptor"/> is equal to this instance.
 /// </summary>
 /// <param name="other">The <see cref="ResultDescriptor"/> to compare with this instance.</param>
 /// <returns>
 ///   <c>true</c> if the specified <see cref="ResultDescriptor"/> is equal to this instance; otherwise, <c>false</c>.
 /// </returns>
 public bool Equals(ResultDescriptor other)
 {
     if (ReferenceEquals(null, other))
         return false;
     if (ReferenceEquals(this, other))
         return true;
     return other.Result.Equals(this.Result);
 }
Example #6
0
        /// <summary>
        /// Finds the specified result descriptor.
        /// </summary>
        /// <param name="result">The result code.</param>
        /// <returns>A descriptor for the specified result</returns>
        public static ResultDescriptor Find(Result result)
        {
            ResultDescriptor descriptor;

            // Check also SharpDX registered result descriptors
            lock (LockDescriptor)
            {
                if (RegisteredDescriptorProvider.Count > 0)
                {
                    foreach (var type in RegisteredDescriptorProvider)
                    {
                        AddDescriptorsFromType(type);
                    }
                    RegisteredDescriptorProvider.Clear();
                }
                if (!Descriptors.TryGetValue(result, out descriptor))
                {
                    descriptor = new ResultDescriptor(result, UnknownText, UnknownText, UnknownText);
                }

                // If description is null, than we try to add description from Win32 GetDescriptionFromResultCode
                // Or we use unknown description
                if (descriptor.Description == null)
                {
                    // Check if a Win32 description exist
                    var description = GetDescriptionFromResultCode(result.Code);
                    descriptor.Description = description ?? UnknownText;
                }
            }

            return descriptor;
        }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:SharpDX.SharpDXException"/> class.
 /// </summary>
 /// <param name="result">The error result code.</param>
 /// <param name="message">The message describing the exception.</param>
 /// <param name="args">formatting arguments</param>
 public SharpDXException(Result result, string message, params object[] args)
     : base(string.Format(CultureInfo.InvariantCulture, message, args))
 {
     this.descriptor = ResultDescriptor.Find(result);
     HResult = (int)result;
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:SharpDX.SharpDXException"/> class.
 /// </summary>
 /// <param name="result">The error result code.</param>
 /// <param name="message">The message describing the exception.</param>
 public SharpDXException(Result result, string message)
     : base(message)
 {
     this.descriptor = ResultDescriptor.Find(result);
     HResult = (int)result;
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:SharpDX.SharpDXException"/> class.
 /// </summary>
 /// <param name="descriptor">The result descriptor.</param>
 public SharpDXException(ResultDescriptor descriptor)
     : base(descriptor.ToString())
 {
     this.descriptor = descriptor;
     HResult = (int)descriptor.Result;
 }
Example #10
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "T:SharpDX.SharpDXException" /> class.
 /// </summary>
 public SharpDXException() : base("A SharpDX exception occurred.")
 {
     this.descriptor = ResultDescriptor.Find(Result.Fail);
     HResult = (int)Result.Fail;
 }
Example #11
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "T:SharpDX.SharpDXException" /> class.
 /// </summary>
 /// <param name = "message">The message describing the exception.</param>
 /// <param name = "innerException">The exception that caused this exception.</param>
 /// <param name="args">formatting arguments</param>
 public SharpDXException(string message, Exception innerException, params object[] args)
     : base(string.Format(CultureInfo.InvariantCulture, message, args), innerException)
 {
     this.descriptor = ResultDescriptor.Find(Result.Fail);
     HResult = (int)Result.Fail;
 }