示例#1
0
        private static string GetExceptionReason(ExceptionReason reason)
        {
            string reasonString = null;

            switch (reason)
            {
            case ExceptionReason.String_Empty:
                reasonString = "String must not be empty.";
                break;

            case ExceptionReason.SmallCapacity:
                reasonString = "Capacity was less than the current size.";
                break;

            case ExceptionReason.InvalidOffsetLength:
                reasonString = "Offset and length must refer to a position in the string.";
                break;

            case ExceptionReason.DuplicateKey:
                reasonString = "The given key is already present in the dictionary.";
                break;

            case ExceptionReason.ContainerEmpty:
                reasonString = "Container is empty.";
                break;

            case ExceptionReason.MaximumCapacityReached:
                reasonString = "Maximum capacity has been reached.";
                break;
            }

            Debug.Assert(reasonString != null, "The enum value is not defined, please check the ExceptionReason Enum.");

            return(reasonString);
        }
示例#2
0
 /// <summary>
 /// Supports the serialization infrastructure.
 /// </summary>
 /// <param name="info">Serialization information.</param>
 /// <param name="context">Streaming context.</param>
 protected MockException(
     System.Runtime.Serialization.SerializationInfo info,
     System.Runtime.Serialization.StreamingContext context)
     : base(info, context)
 {
     this.reason = (ExceptionReason)info.GetValue("reason", typeof(ExceptionReason));
 }
示例#3
0
 /// <summary>
 /// Constructs a new instance of a symbol exception.
 /// </summary>
 /// <param name="symbolName">The symbol's name.</param>
 /// <param name="position">The position in the symbol in the original source.</param>
 /// <param name="reason">The exception reason.</param>
 public SymbolException(StringView symbolName, int position, ExceptionReason reason)
     : base(string.Format(s_reasonMessages[reason], symbolName))
 {
     Position    = position;
     SymbolToken = null;
     SymbolName  = symbolName;
     Reason      = reason;
 }
示例#4
0
 /// <summary>
 /// Constructs a new instance of a symbol exception.
 /// </summary>
 /// <param name="token">The symbol as a parsed token.</param>
 /// <param name="reason">The exception reason.</param>
 public SymbolException(Token token, ExceptionReason reason)
     : base(string.Format(s_reasonMessages[reason], token.Name))
 {
     SymbolToken = token;
     Position    = token.Position;
     SymbolName  = token.Name;
     Reason      = reason;
 }
示例#5
0
        internal MockException(ExceptionReason reason, IError error)
            : base(error.Message)
        {
            Debug.Assert(error != null);

            this.error  = error;
            this.reason = reason;
        }
        internal static void ValidateRootInputs(Activity rootActivity, IDictionary <string, object> inputs)
        {
            IList <ValidationError> validationErrors = null;

            ValidationHelper.ValidateArguments(rootActivity, rootActivity.EquivalenceInfo, rootActivity.OverloadGroups, rootActivity.RequiredArgumentsNotInOverloadGroups, inputs, ref validationErrors);
            if (inputs != null)
            {
                List <string> c = null;
                IEnumerable <RuntimeArgument> enumerable = from a in rootActivity.RuntimeArguments
                                                           where ArgumentDirectionHelper.IsIn(a.Direction)
                                                           select a;
                foreach (string str in inputs.Keys)
                {
                    bool flag = false;
                    foreach (RuntimeArgument argument in enumerable)
                    {
                        if (argument.Name == str)
                        {
                            flag = true;
                            object obj2 = null;
                            if (inputs.TryGetValue(str, out obj2) && !TypeHelper.AreTypesCompatible(obj2, argument.Type))
                            {
                                ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.InputParametersTypeMismatch(argument.Type, argument.Name), rootActivity));
                            }
                            break;
                        }
                    }
                    if (!flag)
                    {
                        if (c == null)
                        {
                            c = new List <string>();
                        }
                        c.Add(str);
                    }
                }
                if (c != null)
                {
                    ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.UnusedInputArguments(c.AsCommaSeparatedValues()), rootActivity));
                }
            }
            if ((validationErrors != null) && (validationErrors.Count > 0))
            {
                string          paramName            = "rootArgumentValues";
                ExceptionReason invalidNonNullInputs = ExceptionReason.InvalidNonNullInputs;
                if (inputs == null)
                {
                    paramName            = "program";
                    invalidNonNullInputs = ExceptionReason.InvalidNullInputs;
                }
                string message = GenerateExceptionString(validationErrors, invalidNonNullInputs);
                if (message != null)
                {
                    throw FxTrace.Exception.Argument(paramName, message);
                }
            }
        }
        private static string GenerateExceptionString(IList<ValidationError> validationErrors, ExceptionReason reason)
        {
            StringBuilder builder = null;
            for (int i = 0; i < validationErrors.Count; i++)
            {
                ValidationError error = validationErrors[i];
                if (!error.IsWarning)
                {
                    if (builder == null)
                    {
                        builder = new StringBuilder();
                        switch (reason)
                        {
                            case ExceptionReason.InvalidTree:
                                builder.Append(System.Activities.SR.ErrorsEncounteredWhileProcessingTree);
                                break;

                            case ExceptionReason.InvalidNullInputs:
                                builder.Append(System.Activities.SR.RootArgumentViolationsFoundNoInputs);
                                break;

                            case ExceptionReason.InvalidNonNullInputs:
                                builder.Append(System.Activities.SR.RootArgumentViolationsFound);
                                break;
                        }
                    }
                    string displayName = null;
                    if (error.Source != null)
                    {
                        displayName = error.Source.DisplayName;
                    }
                    else
                    {
                        displayName = "<UnknownActivity>";
                    }
                    builder.AppendLine();
                    builder.Append(string.Format(System.Activities.SR.Culture, "'{0}': {1}", new object[] { displayName, error.Message }));
                    if (builder.Length > 0x1000)
                    {
                        break;
                    }
                }
            }
            string str2 = null;
            if (builder != null)
            {
                str2 = builder.ToString();
                if (str2.Length > 0x1000)
                {
                    string tooManyViolationsForExceptionMessage = System.Activities.SR.TooManyViolationsForExceptionMessage;
                    str2 = str2.Substring(0, 0x1000 - tooManyViolationsForExceptionMessage.Length) + tooManyViolationsForExceptionMessage;
                }
            }
            return str2;
        }
        private static string MessageFromExceptionReason(ExceptionReason exceptionReason)
        {
            // Get the name of the enum value.
            string exceptionReasonName = Enum.GetName(typeof(ExceptionReason), exceptionReason);

            // Try to find a string resource with this name.
            string message = Resources.ResourceManager.GetString(exceptionReasonName);

            // If we failed to find a string resource or the string is empty,
            // then use the name of the enum value instead.
            if (String.IsNullOrEmpty(message)) {
                message = exceptionReasonName;
            }

            return message;
        }
示例#9
0
        private static string GetExceptionReason(ExceptionReason reason)
        {
            switch (reason)
            {
            case ExceptionReason.String_Empty:
                return("String must not be empty.");

            case ExceptionReason.SmallCapacity:
                return("Capacity was less than the current size.");

            case ExceptionReason.InvalidOffsetLength:
                return("Offset and length must refer to a position in the string.");

            case ExceptionReason.DuplicateKey:
                return("The given key is already present in the dictionary.");

            default:
                Debug.Assert(false, "The enum value is not defined, please check the ExceptionReason Enum.");
                return("");
            }
        }
示例#10
0
 public static void ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionReason reason)
 {
     throw new ArgumentOutOfRangeException(argument.ToString(), GetExceptionReason(reason));
 }
		internal MockException(ExceptionReason reason, string exceptionMessage)
			: base(exceptionMessage)
		{
			this.reason = reason;
		}
示例#12
0
 public ModbusException(ExceptionReason reason)
     : base()
 {
     Reason = reason;
 }
示例#13
0
 internal MockException(ExceptionReason reason, MockBehavior behavior, Invocation invocation)
     : this(reason, behavior, invocation, Resources.ResourceManager.GetString(reason.ToString()))
 {
 }
 public ChessBoardException(ExceptionReason exceptionReason, ExceptionReasonDetail exceptionReasonDetail)
     : this(exceptionReason, exceptionReasonDetail, null)
 {
 }
 public ChessBoardException(ExceptionReason exceptionReason, ExceptionReasonDetail exceptionReasonDetail, Exception innerException)
     : base(MessageFromExceptionReason(exceptionReason), innerException)
 {
     this.ExceptionReason = exceptionReason;
     this.ExceptionReasonDetail = exceptionReasonDetail;
 }
示例#16
0
 internal MockException(ExceptionReason reason, MockBehavior behavior,
                        ICallContext invocation, string message)
     : base(GetMessage(behavior, invocation, message))
 {
     this.reason = reason;
 }
		internal MockException(ExceptionReason reason, MockBehavior behavior,
			ICallContext invocation, string message)
			: base(GetMessage(behavior, invocation, message))
		{
			this.reason = reason;
		}
示例#18
0
 public OmnicommException(ExceptionReason reason) :
     base()
 {
     Reason = reason;
 }
示例#19
0
 public static void InvalidOperationException(ExceptionReason reason)
 {
     throw new InvalidOperationException(GetExceptionReason(reason));
 }
示例#20
0
 public TreeZeroException(object node, ExceptionReason reason, string message = null) : base(message ?? reason.ToString())
 {
     Node   = node;
     Reason = reason;
 }
 public AddonsLoadingException(ExceptionReason reason)
 {
     Reason = reason;
 }
示例#22
0
文件: Cpu.cs 项目: szpght/moha
 private void Exception(ExceptionReason reason)
 {
     ExceptionReason = reason;
     throw new NotImplementedException();
 }
		/// <summary>
		/// Supports the serialization infrastructure.
		/// </summary>
		/// <param name="info">Serialization information.</param>
		/// <param name="context">Streaming context.</param>
		protected MockException(
		  System.Runtime.Serialization.SerializationInfo info,
		  System.Runtime.Serialization.StreamingContext context)
			: base(info, context)
		{
			this.reason = (ExceptionReason)info.GetValue("reason", typeof(ExceptionReason));
		}
 public TranslateException(ExceptionReason reason, string message, Exception innerException)
     : base(message, innerException)
 {
     Reason = reason;
 }
		internal MockException(ExceptionReason reason, MockBehavior behavior,
			ICallContext invocation)
			: this(reason, behavior, invocation,
				Properties.Resources.ResourceManager.GetString(reason.ToString()))
		{
		}
示例#26
0
 public static void ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionReason reason)
 {
     throw new ArgumentOutOfRangeException(GetArgumentName(argument), GetExceptionReason(reason));
 }
 public ChessBoardException(ExceptionReason exceptionReason)
     : this(exceptionReason, ExceptionReasonDetail.None, null)
 {
 }
示例#28
0
 /// <summary>
 /// 初始化 <see cref="InvalidNewNameException"/> 的新实例。
 /// </summary>
 /// <param name="newName">无效的新文件名。</param>
 /// <param name="reason">新文件名无效的原因。</param>
 public InvalidNewNameException(string newName, ExceptionReason reason)
 {
     this.NewName = newName;
     this.Reason  = reason;
 }
 public ChessBoardException(ExceptionReason exceptionReason, Exception innerException)
     : this(exceptionReason, ExceptionReasonDetail.None, innerException)
 {
 }
示例#30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:DotNetAsm.SymbolCollectionException"/> class.
 /// </summary>
 /// <param name="symbolName">The symbol name in the operation that raised the exception.</param>
 /// <param name="reason">The exception reason.</param>
 public SymbolCollectionException(string symbolName, ExceptionReason reason)
     : base(symbolName)
 {
     Reason = reason;
 }
示例#31
0
        internal static void ValidateRootInputs(Activity rootActivity, IDictionary <string, object> inputs)
        {
            IList <ValidationError> validationErrors = null;

            ValidationHelper.ValidateArguments(rootActivity, rootActivity.EquivalenceInfo, rootActivity.OverloadGroups, rootActivity.RequiredArgumentsNotInOverloadGroups, inputs, ref validationErrors);

            // Validate if there are any extra arguments passed in the input dictionary
            if (inputs != null)
            {
                List <string> unusedArguments           = null;
                IEnumerable <RuntimeArgument> arguments = rootActivity.RuntimeArguments.Where((a) => ArgumentDirectionHelper.IsIn(a.Direction));

                foreach (string key in inputs.Keys)
                {
                    bool found = false;
                    foreach (RuntimeArgument argument in arguments)
                    {
                        if (argument.Name == key)
                        {
                            found = true;

                            // Validate if the input argument type matches the expected argument type.
                            if (inputs.TryGetValue(key, out object inputArgumentValue))
                            {
                                if (!TypeHelper.AreTypesCompatible(inputArgumentValue, argument.Type))
                                {
                                    ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.InputParametersTypeMismatch(argument.Type, argument.Name), rootActivity));
                                }
                            }
                            // The ValidateArguments will validate Required in-args and hence not duplicating that validation if the key is not found.

                            break;
                        }
                    }

                    if (!found)
                    {
                        if (unusedArguments == null)
                        {
                            unusedArguments = new List <string>();
                        }
                        unusedArguments.Add(key);
                    }
                }
                if (unusedArguments != null)
                {
                    ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.UnusedInputArguments(unusedArguments.AsCommaSeparatedValues()), rootActivity));
                }
            }

            if (validationErrors != null && validationErrors.Count > 0)
            {
                string          parameterName = "rootArgumentValues";
                ExceptionReason reason        = ExceptionReason.InvalidNonNullInputs;

                if (inputs == null)
                {
                    parameterName = "program";
                    reason        = ExceptionReason.InvalidNullInputs;
                }

                string exceptionString = GenerateExceptionString(validationErrors, reason);

                if (exceptionString != null)
                {
                    throw FxTrace.Exception.Argument(parameterName, exceptionString);
                }
            }
        }
        private static string GenerateExceptionString(IList <ValidationError> validationErrors, ExceptionReason reason)
        {
            StringBuilder builder = null;

            for (int i = 0; i < validationErrors.Count; i++)
            {
                ValidationError error = validationErrors[i];
                if (!error.IsWarning)
                {
                    if (builder == null)
                    {
                        builder = new StringBuilder();
                        switch (reason)
                        {
                        case ExceptionReason.InvalidTree:
                            builder.Append(System.Activities.SR.ErrorsEncounteredWhileProcessingTree);
                            break;

                        case ExceptionReason.InvalidNullInputs:
                            builder.Append(System.Activities.SR.RootArgumentViolationsFoundNoInputs);
                            break;

                        case ExceptionReason.InvalidNonNullInputs:
                            builder.Append(System.Activities.SR.RootArgumentViolationsFound);
                            break;
                        }
                    }
                    string displayName = null;
                    if (error.Source != null)
                    {
                        displayName = error.Source.DisplayName;
                    }
                    else
                    {
                        displayName = "<UnknownActivity>";
                    }
                    builder.AppendLine();
                    builder.Append(string.Format(System.Activities.SR.Culture, "'{0}': {1}", new object[] { displayName, error.Message }));
                    if (builder.Length > 0x1000)
                    {
                        break;
                    }
                }
            }
            string str2 = null;

            if (builder != null)
            {
                str2 = builder.ToString();
                if (str2.Length > 0x1000)
                {
                    string tooManyViolationsForExceptionMessage = System.Activities.SR.TooManyViolationsForExceptionMessage;
                    str2 = str2.Substring(0, 0x1000 - tooManyViolationsForExceptionMessage.Length) + tooManyViolationsForExceptionMessage;
                }
            }
            return(str2);
        }
示例#33
0
 internal MockException(ExceptionReason reason, string exceptionMessage)
     : base(exceptionMessage)
 {
     this.reason = reason;
 }
示例#34
0
        private static string GenerateExceptionString(IList <ValidationError> validationErrors, ExceptionReason reason)
        {
            // 4096 is an arbitrary constant.  Currently clipped by character count (not bytes).
            const int maxExceptionStringSize = 4096;

            StringBuilder exceptionMessageBuilder = null;

            for (int i = 0; i < validationErrors.Count; i++)
            {
                ValidationError validationError = validationErrors[i];

                if (!validationError.IsWarning)
                {
                    // create the common exception string
                    if (exceptionMessageBuilder == null)
                    {
                        exceptionMessageBuilder = new StringBuilder();

                        switch (reason)
                        {
                        case ExceptionReason.InvalidTree:
                            exceptionMessageBuilder.Append(SR.ErrorsEncounteredWhileProcessingTree);
                            break;

                        case ExceptionReason.InvalidNonNullInputs:
                            exceptionMessageBuilder.Append(SR.RootArgumentViolationsFound);
                            break;

                        case ExceptionReason.InvalidNullInputs:
                            exceptionMessageBuilder.Append(SR.RootArgumentViolationsFoundNoInputs);
                            break;
                        }
                    }

                    string activityName = null;

                    if (validationError.Source != null)
                    {
                        activityName = validationError.Source.DisplayName;
                    }
                    else
                    {
                        activityName = "<UnknownActivity>";
                    }

                    exceptionMessageBuilder.AppendLine();
                    exceptionMessageBuilder.Append(string.Format("'{0}': {1}", activityName, validationError.Message));

                    if (exceptionMessageBuilder.Length > maxExceptionStringSize)
                    {
                        break;
                    }
                }
            }

            string exceptionString = null;

            if (exceptionMessageBuilder != null)
            {
                exceptionString = exceptionMessageBuilder.ToString();

                if (exceptionString.Length > maxExceptionStringSize)
                {
                    string snipNotification = SR.TooManyViolationsForExceptionMessage;

                    exceptionString  = exceptionString.Substring(0, maxExceptionStringSize - snipNotification.Length);
                    exceptionString += snipNotification;
                }
            }

            return(exceptionString);
        }
示例#35
0
 internal MockException(ExceptionReason reason, MockBehavior behavior,
                        ICallContext invocation)
     : this(reason, behavior, invocation,
            Properties.Resources.ResourceManager.GetString(reason.ToString()))
 {
 }
示例#36
0
        internal static void ThrowIfViolationsExist(IList <ValidationError> validationErrors, ExceptionReason reason = ExceptionReason.InvalidTree)
        {
            Exception exception = CreateExceptionFromValidationErrors(validationErrors, reason);

            if (exception != null)
            {
                throw FxTrace.Exception.AsError(exception);
            }
        }
示例#37
0
        private static Exception CreateExceptionFromValidationErrors(IList <ValidationError> validationErrors, ExceptionReason reason)
        {
            if (validationErrors != null && validationErrors.Count > 0)
            {
                string exceptionString = GenerateExceptionString(validationErrors, reason);

                if (exceptionString != null)
                {
                    return(new InvalidWorkflowException(exceptionString));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
示例#38
0
 public VpkException(ExceptionReason reason) : base()
 {
     Reason = reason;
 }