Esempio n. 1
0
        public override bool Handle(MessageContext context,
                                    string commandName,
                                    string parameters)
        {
            string originalErrorText = parameters.Trim();

            if (originalErrorText.Equals(String.Empty))
            {
                return(false);
            }

            string errorText = originalErrorText;

            NumberParser np = new NumberParser();

            if (!np.Parse(errorText))
            {
                return(false);
            }

            // Error is out of bounds
            if ((ulong)np.Decimal > uint.MaxValue)
            {
                // Do nothing
            }
            // Error is outside of the range [0, 65535]: it cannot be a plain Win32 error code
            else if ((ulong)np.Decimal > ushort.MaxValue)
            {
                // Customer bit is set: custom error code
                if (IsCustomer(np.Decimal))
                {
                    string description = String.Format("[custom, severity {0}, facility {1}, code {2}]",
                                                       FormatSeverity(np.Decimal),
                                                       FormatFacility(np.Decimal),
                                                       FormatCode(np.Decimal));
                    AddMessage(MessageType.Custom,
                               np.Decimal,
                               np.Hex,
                               description,
                               null);
                }
                // Reserved bit is set: HRESULT_FROM_NT(ntstatus)
                else if (IsReserved(np.Decimal))
                {
                    int status = (int)(np.Decimal & 0xCFFFFFFF);

                    string description;// = ntStatus.GetNtstatusDescription(status);

                    //if (description == null)
                    description = status.ToString("X");

                    description = String.Format("HRESULT_FROM_NT({0})", description);

                    AddMessage(MessageType.Custom,
                               np.Decimal,
                               np.Hex,
                               description,
                               null);
                }
                // Win32 facility: HRESULT_FROM_WIN32(winerror)
                else if (GetFacility(np.Decimal) == 7)
                {
                    // Must be an error code
                    if (GetSeverity(np.Decimal) == 2)
                    {
                        short  err = GetCode(np.Decimal);
                        string description;// = winerror.GetWinerrorDescription(err);

                        //if (description == null)
                        description = err.ToString("D");

                        description = String.Format("HRESULT_FROM_WIN32({0})", description);

                        AddMessage(MessageType.Custom,
                                   np.Decimal,
                                   np.Hex,
                                   description,
                                   null);
                    }
                }
            }

            return(true);
        }