示例#1
0
 public static ExceptionResource CreateExceptionResource(int exceptionAppointmentID, int exceptionAppointmentResourcesID)
 {
     ExceptionResource exceptionResource = new ExceptionResource();
     exceptionResource.ExceptionAppointmentID = exceptionAppointmentID;
     exceptionResource.ExceptionAppointmentResourcesID = exceptionAppointmentResourcesID;
     return exceptionResource;
 }
示例#2
0
        public static JsonReaderException GetJsonReaderException(ref Utf8JsonReader json, ExceptionResource resource, byte nextByte, ReadOnlySpan <byte> bytes)
        {
            string message = GetResourceString(ref json, resource, nextByte, Encoding.UTF8.GetString(bytes.ToArray(), 0, bytes.Length));

            long lineNumber         = json.CurrentState._lineNumber;
            long bytePositionInLine = json.CurrentState._bytePositionInLine;

            message += $" LineNumber: {lineNumber} | BytePositionInLine: {bytePositionInLine}.";
            return(new JsonReaderException(message, lineNumber, bytePositionInLine));
        }
示例#3
0
 public static void ThrowInvalidOperationException(ExceptionResource resource, int currentDepth, byte token, JsonTokenType tokenType)
 {
     throw GetInvalidOperationException(resource, currentDepth, token, tokenType);
 }
示例#4
0
 internal static void ThrowNotSupportedException(ExceptionResource resource)
 {
     throw new NotSupportedException(GetResourceString(resource));
 }
示例#5
0
 private static ArgumentOutOfRangeException GetArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
 {
     return(new ArgumentOutOfRangeException(GetArgumentName(argument), GetResourceString(resource)));
 }
示例#6
0
    public static void ThrowArgumentOutOfRangeException(ExceptionArgument expArgument, ExceptionResource expResource)
    {
        string paramName = enumType.GetEnumName(expArgument);

        switch (expResource)
        {
        case ExceptionResource.Arg_ArrayPlusOffTooSmall:
        case ExceptionResource.Arg_NonZeroLowerBound:
        case ExceptionResource.Arg_RankMultiDimNotSupported:
        case ExceptionResource.Argument_InvalidArrayType:
        case ExceptionResource.Argument_InvalidOffLen:
        case ExceptionResource.ArgumentOutOfRange_BiggerThanCollection:
        case ExceptionResource.ArgumentOutOfRange_Count:
        case ExceptionResource.ArgumentOutOfRange_Index:
        case ExceptionResource.ArgumentOutOfRange_ListInsert:
        case ExceptionResource.ArgumentOutOfRange_NeedNonNegNum:
        case ExceptionResource.ArgumentOutOfRange_SmallCapacity:
        case ExceptionResource.InvalidOperation_EnumFailedVersion:
        case ExceptionResource.InvalidOperation_EnumOpCantHappen:
        case ExceptionResource.NotSupported_ReadOnlyCollection:
        default:
            throw new ArgumentOutOfRangeException(paramName);
        }
        throw new NotImplementedException();
    }
示例#7
0
 internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
 {
     throw GetArgumentOutOfRangeException(argument, resource);
 }
示例#8
0
 private static string GetResourceString(ExceptionResource resource, int errorCode, int pin) => resource switch
 {
示例#9
0
 [DoesNotReturn] public static void ThrowArgument(ExceptionResource resource) => throw new ArgumentException(GetResourceText(resource));
示例#10
0
 public static PlatformNotSupportedException GetPlatformNotSupportedException(ExceptionResource resource)
 {
     return(new PlatformNotSupportedException(GetResourceString(resource, -1, -1)));
 }
示例#11
0
 public static ArgumentException GetArgumentException(ExceptionResource resource)
 {
     return(new ArgumentException(GetResourceString(resource, -1, -1)));
 }
示例#12
0
 public static InvalidOperationException GetInvalidOperationException(ExceptionResource resource, int pin = -1)
 {
     return(new InvalidOperationException(GetResourceString(resource, -1, pin)));
 }
示例#13
0
 public static IOException GetIOException(ExceptionResource resource, int errorCode = -1, int pin = -1)
 {
     return(new IOException(GetResourceString(resource, errorCode, pin)));
 }
示例#14
0
        private static string GetResourceString(ExceptionResource resource, int errorCode, int pin)
        {
            string message = string.Empty;

            switch (resource)
            {
            case ExceptionResource.NoChipIteratorFound:
                message = $"Unable to find a chip iterator, error code: {errorCode}";
                break;

            case ExceptionResource.NoChipFound:
                message = $"Unable to find a chip, error code: {errorCode}";
                break;

            case ExceptionResource.PinModeReadError:
                message = $"Error while reading pin mode for pin: {pin}";
                break;

            case ExceptionResource.OpenPinError:
                message = $"Pin {pin} not available, error: {errorCode}";
                break;

            case ExceptionResource.ReadPinError:
                message = $"Error while reading value from pin: {pin}, error: {errorCode}";
                break;

            case ExceptionResource.PinNotOpenedError:
                message = $"Can not access pin {pin} that is not open.";
                break;

            case ExceptionResource.SetPinModeError:
                message = $"Error setting pin mode, for pin: {pin}, error: {errorCode}";
                break;

            case ExceptionResource.ConvertPinNumberingSchemaError:
                message = $"This driver is generic so it cannot perform conversions between pin numbering schemes.";
                break;

            case ExceptionResource.RequestEventError:
                message = $"Error while requesting event listener for pin {pin}, error code: {errorCode}";
                break;

            case ExceptionResource.InvalidEventType:
                message = $"Invalid or not supported event type requested";
                break;

            case ExceptionResource.EventWaitError:
                message = $"Error while waiting for event, error code {errorCode}, pin: {pin}";
                break;

            case ExceptionResource.EventReadError:
                message = $"Error while reading pin event result, error code {errorCode}";
                break;

            case ExceptionResource.NotListeningForEventError:
                message = $"Attempted to remove a callback for a pin that is not listening for events.";
                break;

            case ExceptionResource.LibGpiodNotInstalled:
                message = $"Libgpiod driver not installed. More information on: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/about/";
                break;

            default:
                Debug.Fail($"The ExceptionResource enum value: {resource} is not part of the switch. Add the appropriate case and exception message.");
                break;
            }

            return(message);
        }
示例#15
0
 private static string GetResourceText(ExceptionResource resource)
 {
     return(SR.GetResourceString(GetResourceName(resource)));
 }
示例#16
0
 [DoesNotReturn] public static void ThrowInvalidOperation(ExceptionResource resource) => throw new InvalidOperationException(GetResourceText(resource));
示例#17
0
 public static InvalidOperationException GetInvalidOperationException(ExceptionResource resource, string location = null)
 {
     return(new InvalidOperationException(GetResourceString(resource, location)));
 }
示例#18
0
 internal static void ThrowArgumentException(ExceptionResource resource)
 {
     throw new ArgumentException(GetResourceText(resource));
 }
示例#19
0
 internal static void ThrowArgumentException(ExceptionResource resource)
 {
     throw GetArgumentException(resource);
 }
示例#20
0
 internal static void ThrowInvalidOperationException(ExceptionResource resource)
 {
     throw new InvalidOperationException(GetResourceText(resource));
 }
示例#21
0
 internal static void ThrowInvalidOperationException(ExceptionResource resource, Exception e)
 {
     throw new InvalidOperationException(GetResourceString(resource), e);
 }
示例#22
0
        internal static void ThrowInvalidOperationException(ExceptionResource resource, params object[] args)
        {
            var message = string.Format(GetResourceText(resource), args);

            throw new InvalidOperationException(message);
        }
示例#23
0
 private static ArgumentException GetArgumentException(ExceptionResource resource)
 {
     return(new ArgumentException(GetResourceString(resource)));
 }
示例#24
0
 internal static ArgumentException GetArgumentException(ExceptionResource resource)
 {
     return(new ArgumentException(GetResourceText(resource)));
 }
示例#25
0
 public static void ThrowJsonReaderException(ref Utf8JsonReader json, ExceptionResource resource, byte nextByte = default, ReadOnlySpan <byte> bytes = default)
 {
     throw GetJsonReaderException(ref json, resource, nextByte, bytes);
 }
示例#26
0
 private static string GetResourceText(ExceptionResource resource)
 {
     return(Resources.ResourceManager.GetString(GetResourceName(resource), Resources.Culture));
 }
示例#27
0
        private static string GetResourceString(ref Utf8JsonReader json, ExceptionResource resource, byte nextByte, string characters)
        {
            string character = IsPrintable(nextByte) ? ((char)nextByte).ToString() : $"0x{nextByte:X2}";

            string message = "";

            switch (resource)
            {
            case ExceptionResource.ArrayDepthTooLarge:
                message = SR.Format(SR.ArrayDepthTooLarge, json.CurrentState.Options.MaxDepth);
                break;

            case ExceptionResource.MismatchedObjectArray:
                message = SR.Format(SR.MismatchedObjectArray, character);
                break;

            case ExceptionResource.EndOfStringNotFound:
                message = SR.EndOfStringNotFound;
                break;

            case ExceptionResource.RequiredDigitNotFoundAfterSign:
                message = SR.Format(SR.RequiredDigitNotFoundAfterSign, character);
                break;

            case ExceptionResource.RequiredDigitNotFoundAfterDecimal:
                message = SR.Format(SR.RequiredDigitNotFoundAfterDecimal, character);
                break;

            case ExceptionResource.RequiredDigitNotFoundEndOfData:
                message = SR.RequiredDigitNotFoundEndOfData;
                break;

            case ExceptionResource.ExpectedEndAfterSingleJson:
                message = SR.Format(SR.ExpectedEndAfterSingleJson, character);
                break;

            case ExceptionResource.ExpectedEndOfDigitNotFound:
                message = SR.Format(SR.ExpectedEndOfDigitNotFound, character);
                break;

            case ExceptionResource.ExpectedNextDigitEValueNotFound:
                message = SR.Format(SR.ExpectedNextDigitEValueNotFound, character);
                break;

            case ExceptionResource.ExpectedSeparatorAfterPropertyNameNotFound:
                message = SR.Format(SR.ExpectedSeparatorAfterPropertyNameNotFound, character);
                break;

            case ExceptionResource.ExpectedStartOfPropertyNotFound:
                message = SR.Format(SR.ExpectedStartOfPropertyNotFound, character);
                break;

            case ExceptionResource.ExpectedStartOfPropertyOrValueNotFound:
                message = SR.ExpectedStartOfPropertyOrValueNotFound;
                break;

            case ExceptionResource.ExpectedStartOfValueNotFound:
                message = SR.Format(SR.ExpectedStartOfValueNotFound, character);
                break;

            case ExceptionResource.ExpectedValueAfterPropertyNameNotFound:
                message = SR.ExpectedValueAfterPropertyNameNotFound;
                break;

            case ExceptionResource.FoundInvalidCharacter:
                message = SR.Format(SR.FoundInvalidCharacter, character);
                break;

            case ExceptionResource.InvalidEndOfJsonNonPrimitive:
                message = SR.Format(SR.InvalidEndOfJsonNonPrimitive, json.TokenType);
                break;

            case ExceptionResource.ObjectDepthTooLarge:
                message = SR.Format(SR.ObjectDepthTooLarge, json.CurrentState.Options.MaxDepth);
                break;

            case ExceptionResource.ExpectedFalse:
                message = SR.Format(SR.ExpectedFalse, characters);
                break;

            case ExceptionResource.ExpectedNull:
                message = SR.Format(SR.ExpectedNull, characters);
                break;

            case ExceptionResource.ExpectedTrue:
                message = SR.Format(SR.ExpectedTrue, characters);
                break;

            case ExceptionResource.InvalidCharacterWithinString:
                message = SR.Format(SR.InvalidCharacterWithinString, character);
                break;

            case ExceptionResource.InvalidCharacterAfterEscapeWithinString:
                message = SR.Format(SR.InvalidCharacterAfterEscapeWithinString, character);
                break;

            case ExceptionResource.InvalidHexCharacterWithinString:
                message = SR.Format(SR.InvalidHexCharacterWithinString, character);
                break;

            case ExceptionResource.EndOfCommentNotFound:
                message = SR.EndOfCommentNotFound;
                break;

            case ExceptionResource.ZeroDepthAtEnd:
                message = SR.Format(SR.ZeroDepthAtEnd);
                break;

            case ExceptionResource.ExpectedJsonTokens:
                message = SR.ExpectedJsonTokens;
                break;

            default:
                Debug.Fail($"The ExceptionResource enum value: {resource} is not part of the switch. Add the appropriate case and exception message.");
                break;
            }

            return(message);
        }
示例#28
0
        private static string GetResourceString(ExceptionResource argument, string location = null)
        {
            Debug.Assert(Enum.IsDefined(typeof(ExceptionResource), argument),
                         "The enum value is not defined, please check the ExceptionResource Enum.");

            // Should be look up with environment resources
            string resourceString = null;

            switch (argument)
            {
            case ExceptionResource.AlreadyWriting:
                resourceString = "Already writing.";
                break;

            case ExceptionResource.NotWritingNoAlloc:
                resourceString = "No writing operation. Make sure Alloc() was called.";
                break;

            case ExceptionResource.NoWriteToComplete:
                resourceString = "No writing operation to complete.";
                break;

            case ExceptionResource.AlreadyReading:
                resourceString = "Already reading.";
                break;

            case ExceptionResource.NoReadToComplete:
                resourceString = "No reading operation to complete.";
                break;

            case ExceptionResource.NoConcurrentOperation:
                resourceString = "Concurrent reads or writes are not supported.";
                break;

            case ExceptionResource.GetResultNotCompleted:
                resourceString = "Can't GetResult unless completed";
                break;

            case ExceptionResource.NoWritingAllowed:
                resourceString = "Writing is not allowed after writer was completed";
                break;

            case ExceptionResource.NoReadingAllowed:
                resourceString = "Reading is not allowed after reader was completed";
                break;

            case ExceptionResource.CompleteWriterActiveWriter:
                resourceString = "Can't complete writer while writing.";
                break;

            case ExceptionResource.CompleteReaderActiveReader:
                resourceString = "Can't complete reader while reading.";
                break;

            case ExceptionResource.AdvancingPastBufferSize:
                resourceString = "Can't advance past buffer size";
                break;

            case ExceptionResource.AdvancingWithNoBuffer:
                resourceString = "Can't advance without buffer allocated";
                break;

            case ExceptionResource.BackpressureDeadlock:
                resourceString = "Advancing examined to the end would cause pipe to deadlock because FlushAsync is waiting";
                break;

            case ExceptionResource.AdvanceToInvalidCursor:
                resourceString = "Pipe is already advanced past provided cursor";
                break;
            }

            resourceString = resourceString ?? $"Error ResourceKey not defined {argument}.";

            if (location != null)
            {
                resourceString += Environment.NewLine;
                resourceString += "From: " + location.Replace("at ", ">> ");
            }

            return(resourceString);
        }
示例#29
0
        public static InvalidOperationException GetInvalidOperationException(ExceptionResource resource, int currentDepth, byte token, JsonTokenType tokenType)
        {
            string message = GetResourceString(resource, currentDepth, token, tokenType);

            return(new InvalidOperationException(message));
        }
示例#30
0
 public static void ThrowInvalidOperationException(ExceptionResource resource, string location = null)
 {
     throw GetInvalidOperationException(resource, location);
 }
示例#31
0
 public void AddToExceptionResources(ExceptionResource exceptionResource)
 {
     base.AddObject("ExceptionResources", exceptionResource);
 }
示例#32
0
        private static string GetResourceString(ExceptionResource argument, string location = null)
        {
            Debug.Assert(Enum.IsDefined(typeof(ExceptionResource), argument),
                         "The enum value is not defined, please check the ExceptionResource Enum.");

            // Should be look up with enviorment resources
            string resourceString = null;

            switch (argument)
            {
            case ExceptionResource.AlreadyProducing:
                resourceString = "Already producing.";
                break;

            case ExceptionResource.NotProducingNoAlloc:
                resourceString = "No ongoing producing operation. Make sure Alloc() was called.";
                break;

            case ExceptionResource.NotProducingToComplete:
                resourceString = "No ongoing producing operation to complete.";
                break;

            case ExceptionResource.AlreadyConsuming:
                resourceString = "Already consuming.";
                break;

            case ExceptionResource.NotConsumingToComplete:
                resourceString = "No ongoing consuming operation to complete.";
                break;

            case ExceptionResource.NoConcurrentReads:
                resourceString = "Concurrent reads are not supported.";
                break;

            case ExceptionResource.GetResultNotCompleted:
                resourceString = "Can't GetResult unless completed";
                break;

            case ExceptionResource.NoWritingAllowed:
                resourceString = "Writing is not allowed after writing was completed";
                break;

            case ExceptionResource.NoReadingAllowed:
                resourceString = "Writing is not allowed after writing was completed";
                break;

            case ExceptionResource.CompleteWriterActiveProducer:
                resourceString = "Can't complete writer while producer operation is ongoing.";
                break;

            case ExceptionResource.CompleteReaderActiveConsumer:
                resourceString = "Can't complete reader while consuming operation is ongoing.";
                break;
            }

            resourceString = resourceString ?? $"Error ResourceKey not defined {argument}.";

            if (location != null)
            {
                resourceString += Environment.NewLine;
                resourceString += "From: " + location.Replace("at ", ">> ");
            }

            return(resourceString);
        }