public _SocketState(Stream strm,long lengthToRead,long maxLength,object tag,SocketCallBack callBack) { m_pStream = strm; m_LenthToRead = lengthToRead; m_MaxLength = maxLength; m_Tag = tag; m_pCallback = callBack; m_RecvType = ReadType.Length; }
private void GarminUSBReader_Progress(ReadType readType, int step, int maxSteps, double partCompleted) { if (InvokeRequired) { BeginInvoke(new ProgressDelegate(GarminUSBReader_Progress), readType, step, maxSteps, partCompleted); return; } status.Text = string.Format(Strings.Status, step, maxSteps, GetReadTypeString(readType)); progressBar.Value = (int)(100 * partCompleted); }
public _SocketState(Stream strm,long maxLength,string terminator,string removeFromEnd,object tag,SocketCallBack callBack) { m_pStream = strm; m_MaxLength = maxLength; m_RemFromEnd = removeFromEnd; m_Tag = tag; m_pCallback = callBack; m_pStack = new _FixedStack(terminator); m_RecvType = ReadType.Terminator; }
private static string GetReadTypeString(ReadType readType) { switch (readType) { case ReadType.ProductData: return Strings.ProductData; case ReadType.Runs: return Strings.Runs; case ReadType.Laps: return Strings.Laps; case ReadType.Tracks: return Strings.Tracks; } return ""; }
internal JsonContract(Type underlyingType) { ValidationUtils.ArgumentNotNull((object) underlyingType, "underlyingType"); this.UnderlyingType = underlyingType; this.IsNullable = ReflectionUtils.IsNullable(underlyingType); this.NonNullableUnderlyingType = !this.IsNullable || !ReflectionUtils.IsNullableType(underlyingType) ? underlyingType : Nullable.GetUnderlyingType(underlyingType); this.CreatedType = this.NonNullableUnderlyingType; this.IsConvertable = ConvertUtils.IsConvertible(this.NonNullableUnderlyingType); if (this.NonNullableUnderlyingType == typeof (byte[])) this.InternalReadType = ReadType.ReadAsBytes; else if (this.NonNullableUnderlyingType == typeof (int)) this.InternalReadType = ReadType.ReadAsInt32; else if (this.NonNullableUnderlyingType == typeof (Decimal)) this.InternalReadType = ReadType.ReadAsDecimal; else if (this.NonNullableUnderlyingType == typeof (string)) this.InternalReadType = ReadType.ReadAsString; else if (this.NonNullableUnderlyingType == typeof (DateTime)) this.InternalReadType = ReadType.ReadAsDateTime; else this.InternalReadType = ReadType.Read; }
// Token: 0x060002A5 RID: 677 // RVA: 0x0002EEF0 File Offset: 0x0002D0F0 internal JsonContract(Type underlyingType) { ValidationUtils.ArgumentNotNull(underlyingType, "underlyingType"); this.UnderlyingType = underlyingType; this.IsNullable = ReflectionUtils.IsNullable(underlyingType); this.NonNullableUnderlyingType = ((!this.IsNullable || !ReflectionUtils.IsNullableType(underlyingType)) ? underlyingType : Nullable.GetUnderlyingType(underlyingType)); this.CreatedType = this.NonNullableUnderlyingType; this.IsConvertable = ConvertUtils.IsConvertible(this.NonNullableUnderlyingType); this.IsEnum = TypeExtensions.IsEnum(this.NonNullableUnderlyingType); if (this.NonNullableUnderlyingType == typeof(byte[])) { this.InternalReadType = ReadType.ReadAsBytes; return; } if (this.NonNullableUnderlyingType == typeof(int)) { this.InternalReadType = ReadType.ReadAsInt32; return; } if (this.NonNullableUnderlyingType == typeof(decimal)) { this.InternalReadType = ReadType.ReadAsDecimal; return; } if (this.NonNullableUnderlyingType == typeof(string)) { this.InternalReadType = ReadType.ReadAsString; return; } if (this.NonNullableUnderlyingType == typeof(DateTime)) { this.InternalReadType = ReadType.ReadAsDateTime; return; } this.InternalReadType = ReadType.Read; }
internal byte[] ReadAsBytesInternal() { _readType = ReadType.ReadAsBytes; JsonToken t; do { if (!ReadInternal()) { SetToken(JsonToken.None); return null; } else { t = TokenType; } } while (t == JsonToken.Comment); if (IsWrappedInTypeObject()) { byte[] data = ReadAsBytes(); ReadInternal(); SetToken(JsonToken.Bytes, data, false); return data; } // attempt to convert possible base 64 string to bytes if (t == JsonToken.String) { string s = (string)Value; byte[] data; Guid g; if (s.Length == 0) { data = new byte[0]; } else if (ConvertUtils.TryConvertGuid(s, out g)) { data = g.ToByteArray(); } else { data = Convert.FromBase64String(s); } SetToken(JsonToken.Bytes, data, false); return data; } if (t == JsonToken.Null) return null; if (t == JsonToken.Bytes) { if (ValueType == typeof(Guid)) { byte[] data = ((Guid)Value).ToByteArray(); SetToken(JsonToken.Bytes, data, false); return data; } return (byte[])Value; } if (t == JsonToken.StartArray) { List<byte> data = new List<byte>(); while (ReadInternal()) { t = TokenType; switch (t) { case JsonToken.Integer: data.Add(Convert.ToByte(Value, CultureInfo.InvariantCulture)); break; case JsonToken.EndArray: byte[] d = data.ToArray(); SetToken(JsonToken.Bytes, d, false); return d; case JsonToken.Comment: // skip break; default: throw JsonReaderException.Create(this, "Unexpected token when reading bytes: {0}.".FormatWith(CultureInfo.InvariantCulture, t)); } } throw JsonReaderException.Create(this, "Unexpected end when reading bytes."); } if (t == JsonToken.EndArray) return null; throw JsonReaderException.Create(this, "Error reading bytes. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, t)); }
internal byte[] ReadAsBytesInternal() { _readType = ReadType.ReadAsBytes; do { if (!ReadInternal()) { SetToken(JsonToken.None); return null; } } while (TokenType == JsonToken.Comment); if (IsWrappedInTypeObject()) { byte[] data = ReadAsBytes(); ReadInternal(); SetToken(JsonToken.Bytes, data); return data; } // attempt to convert possible base 64 string to bytes if (TokenType == JsonToken.String) { string s = (string)Value; byte[] data = (s.Length == 0) ? new byte[0] : Convert.FromBase64String(s); SetToken(JsonToken.Bytes, data); } if (TokenType == JsonToken.Null) return null; if (TokenType == JsonToken.Bytes) return (byte[])Value; if (TokenType == JsonToken.StartArray) { List<byte> data = new List<byte>(); while (ReadInternal()) { switch (TokenType) { case JsonToken.Integer: data.Add(Convert.ToByte(Value, CultureInfo.InvariantCulture)); break; case JsonToken.EndArray: byte[] d = data.ToArray(); SetToken(JsonToken.Bytes, d); return d; case JsonToken.Comment: // skip break; default: throw JsonReaderException.Create(this, "Unexpected token when reading bytes: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType)); } } throw JsonReaderException.Create(this, "Unexpected end when reading bytes."); } if (TokenType == JsonToken.EndArray) return null; throw JsonReaderException.Create(this, "Error reading bytes. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType)); }
private object ReadStringValue(ReadType readType) { EnsureBuffer(); switch (_currentState) { case State.Start: case State.Property: case State.Array: case State.ArrayStart: case State.Constructor: case State.ConstructorStart: case State.PostValue: while (true) { char currentChar = _chars[_charPos]; switch (currentChar) { case '\0': if (ReadNullChar()) { SetToken(JsonToken.None, null, false); return null; } break; case '"': case '\'': ParseString(currentChar, readType); switch (readType) { case ReadType.ReadAsBytes: return Value; case ReadType.ReadAsString: return Value; case ReadType.ReadAsDateTime: if (Value is DateTime) { return (DateTime)Value; } return ReadDateTimeString((string)Value); #if !NET20 case ReadType.ReadAsDateTimeOffset: if (Value is DateTimeOffset) { return (DateTimeOffset)Value; } return ReadDateTimeOffsetString((string)Value); #endif default: throw new ArgumentOutOfRangeException(nameof(readType)); } case '-': if (EnsureChars(1, true) && _chars[_charPos + 1] == 'I') { return ParseNumberNegativeInfinity(readType); } else { ParseNumber(readType); return Value; } case '.': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (readType != ReadType.ReadAsString) { _charPos++; throw CreateUnexpectedCharacterException(currentChar); } ParseNumber(ReadType.ReadAsString); return Value; case 't': case 'f': if (readType != ReadType.ReadAsString) { _charPos++; throw CreateUnexpectedCharacterException(currentChar); } string expected = currentChar == 't' ? JsonConvert.True : JsonConvert.False; if (!MatchValueWithTrailingSeparator(expected)) { throw CreateUnexpectedCharacterException(_chars[_charPos]); } SetToken(JsonToken.String, expected); return expected; case 'I': return ParseNumberPositiveInfinity(readType); case 'N': return ParseNumberNaN(readType); case 'n': HandleNull(); return null; case '/': ParseComment(false); break; case ',': ProcessValueComma(); break; case ']': _charPos++; if (_currentState == State.Array || _currentState == State.ArrayStart || _currentState == State.PostValue) { SetToken(JsonToken.EndArray); return null; } throw CreateUnexpectedCharacterException(currentChar); case StringUtils.CarriageReturn: ProcessCarriageReturn(false); break; case StringUtils.LineFeed: ProcessLineFeed(); break; case ' ': case StringUtils.Tab: // eat _charPos++; break; default: _charPos++; if (!char.IsWhiteSpace(currentChar)) { throw CreateUnexpectedCharacterException(currentChar); } // eat break; } } case State.Finished: ReadFinished(); return null; default: throw JsonReaderException.Create(this, "Unexpected state: {0}.".FormatWith(CultureInfo.InvariantCulture, CurrentState)); } }
private void ParseNumber(ReadType readType) { ShiftBufferIfNeeded(); char firstChar = _chars[_charPos]; int initialPosition = _charPos; ReadNumberIntoBuffer(); // set state to PostValue now so that if there is an error parsing the number then the reader can continue SetPostValueState(true); _stringReference = new StringReference(_chars, initialPosition, _charPos - initialPosition); object numberValue; JsonToken numberType; bool singleDigit = (char.IsDigit(firstChar) && _stringReference.Length == 1); bool nonBase10 = (firstChar == '0' && _stringReference.Length > 1 && _stringReference.Chars[_stringReference.StartIndex + 1] != '.' && _stringReference.Chars[_stringReference.StartIndex + 1] != 'e' && _stringReference.Chars[_stringReference.StartIndex + 1] != 'E'); if (readType == ReadType.ReadAsString) { string number = _stringReference.ToString(); // validate that the string is a valid number if (nonBase10) { try { if (number.StartsWith("0x", StringComparison.OrdinalIgnoreCase)) { Convert.ToInt64(number, 16); } else { Convert.ToInt64(number, 8); } } catch (Exception ex) { throw JsonReaderException.Create(this, "Input string '{0}' is not a valid number.".FormatWith(CultureInfo.InvariantCulture, number), ex); } } else { double value; if (!double.TryParse(number, NumberStyles.Float, CultureInfo.InvariantCulture, out value)) { throw JsonReaderException.Create(this, "Input string '{0}' is not a valid number.".FormatWith(CultureInfo.InvariantCulture, _stringReference.ToString())); } } numberType = JsonToken.String; numberValue = number; } else if (readType == ReadType.ReadAsInt32) { if (singleDigit) { // digit char values start at 48 numberValue = firstChar - 48; } else if (nonBase10) { string number = _stringReference.ToString(); try { int integer = number.StartsWith("0x", StringComparison.OrdinalIgnoreCase) ? Convert.ToInt32(number, 16) : Convert.ToInt32(number, 8); numberValue = integer; } catch (Exception ex) { throw JsonReaderException.Create(this, "Input string '{0}' is not a valid integer.".FormatWith(CultureInfo.InvariantCulture, number), ex); } } else { int value; ParseResult parseResult = ConvertUtils.Int32TryParse(_stringReference.Chars, _stringReference.StartIndex, _stringReference.Length, out value); if (parseResult == ParseResult.Success) { numberValue = value; } else if (parseResult == ParseResult.Overflow) { throw JsonReaderException.Create(this, "JSON integer {0} is too large or small for an Int32.".FormatWith(CultureInfo.InvariantCulture, _stringReference.ToString())); } else { throw JsonReaderException.Create(this, "Input string '{0}' is not a valid integer.".FormatWith(CultureInfo.InvariantCulture, _stringReference.ToString())); } } numberType = JsonToken.Integer; } else if (readType == ReadType.ReadAsDecimal) { if (singleDigit) { // digit char values start at 48 numberValue = (decimal)firstChar - 48; } else if (nonBase10) { string number = _stringReference.ToString(); try { // decimal.Parse doesn't support parsing hexadecimal values long integer = number.StartsWith("0x", StringComparison.OrdinalIgnoreCase) ? Convert.ToInt64(number, 16) : Convert.ToInt64(number, 8); numberValue = Convert.ToDecimal(integer); } catch (Exception ex) { throw JsonReaderException.Create(this, "Input string '{0}' is not a valid decimal.".FormatWith(CultureInfo.InvariantCulture, number), ex); } } else { string number = _stringReference.ToString(); decimal value; if (decimal.TryParse(number, NumberStyles.Number | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out value)) { numberValue = value; } else { throw JsonReaderException.Create(this, "Input string '{0}' is not a valid decimal.".FormatWith(CultureInfo.InvariantCulture, _stringReference.ToString())); } } numberType = JsonToken.Float; } else if (readType == ReadType.ReadAsDouble) { if (singleDigit) { // digit char values start at 48 numberValue = (double)firstChar - 48; } else if (nonBase10) { string number = _stringReference.ToString(); try { // double.Parse doesn't support parsing hexadecimal values long integer = number.StartsWith("0x", StringComparison.OrdinalIgnoreCase) ? Convert.ToInt64(number, 16) : Convert.ToInt64(number, 8); numberValue = Convert.ToDouble(integer); } catch (Exception ex) { throw JsonReaderException.Create(this, "Input string '{0}' is not a valid double.".FormatWith(CultureInfo.InvariantCulture, number), ex); } } else { string number = _stringReference.ToString(); double value; if (double.TryParse(number, NumberStyles.Float, CultureInfo.InvariantCulture, out value)) { numberValue = value; } else { throw JsonReaderException.Create(this, "Input string '{0}' is not a valid double.".FormatWith(CultureInfo.InvariantCulture, _stringReference.ToString())); } } numberType = JsonToken.Float; } else { if (singleDigit) { // digit char values start at 48 numberValue = (long)firstChar - 48; numberType = JsonToken.Integer; } else if (nonBase10) { string number = _stringReference.ToString(); try { numberValue = number.StartsWith("0x", StringComparison.OrdinalIgnoreCase) ? Convert.ToInt64(number, 16) : Convert.ToInt64(number, 8); } catch (Exception ex) { throw JsonReaderException.Create(this, "Input string '{0}' is not a valid number.".FormatWith(CultureInfo.InvariantCulture, number), ex); } numberType = JsonToken.Integer; } else { long value; ParseResult parseResult = ConvertUtils.Int64TryParse(_stringReference.Chars, _stringReference.StartIndex, _stringReference.Length, out value); if (parseResult == ParseResult.Success) { numberValue = value; numberType = JsonToken.Integer; } else if (parseResult == ParseResult.Overflow) { #if !(NET20 || NET35 || PORTABLE40 || PORTABLE) string number = _stringReference.ToString(); if (number.Length > MaximumJavascriptIntegerCharacterLength) { throw JsonReaderException.Create(this, "JSON integer {0} is too large to parse.".FormatWith(CultureInfo.InvariantCulture, _stringReference.ToString())); } numberValue = BigIntegerParse(number, CultureInfo.InvariantCulture); numberType = JsonToken.Integer; #else throw JsonReaderException.Create(this, "JSON integer {0} is too large or small for an Int64.".FormatWith(CultureInfo.InvariantCulture, _stringReference.ToString())); #endif } else { string number = _stringReference.ToString(); if (_floatParseHandling == FloatParseHandling.Decimal) { decimal d; if (decimal.TryParse(number, NumberStyles.Number | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out d)) { numberValue = d; } else { throw JsonReaderException.Create(this, "Input string '{0}' is not a valid decimal.".FormatWith(CultureInfo.InvariantCulture, number)); } } else { double d; if (double.TryParse(number, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out d)) { numberValue = d; } else { throw JsonReaderException.Create(this, "Input string '{0}' is not a valid number.".FormatWith(CultureInfo.InvariantCulture, number)); } } numberType = JsonToken.Float; } } } ClearRecentString(); // index has already been updated SetToken(numberType, numberValue, false); }
/// <summary> /// Parses the specified fill item action. /// </summary> /// <param name="fillItemAction">The optional fill item action.</param> public virtual IEnumerable <IList <string> > Parse(Action <IList <string> > fillItemAction = null) { Line = 0; // this value contains current string value of item StringBuilder currentItem = new StringBuilder(); // this value contains current row values List <string> items = new List <string>(); // set initial state of reader automat ReadType readType = ReadType.CurrentLine; // set initial state of previous char char previousChar = char.MinValue; if (CsvReader.BaseStream.CanSeek) { CsvReader.BaseStream.Seek(0, SeekOrigin.Begin); } // read while not end of stream while (!CsvReader.EndOfStream) { // read single char int chValue = CsvReader.Read(); char ch = (char)chValue; // if char is // new line type if (ch == (char)10 || ch == (char)13) { // if current line is in quoted text, add this character to text if (readType == ReadType.QuoteText) { currentItem.Append(ch); } // else set reader automat to new line state else { // if reader not in new line status if (readType != ReadType.NewLine) { // add what we have as new item to items list items.Add(currentItem.ToString()); // call fill item function Line++; if (fillItemAction != null) { fillItemAction(items); } yield return(items); // reset items and current item text items.Clear(); currentItem.Length = 0; } readType = ReadType.NewLine; } } else if (this.cEnclosure != null && ch == this.cEnclosure.Value) { // if new line then change back to current line reader state if (readType == ReadType.NewLine) { readType = ReadType.CurrentLine; } // if reader automat is not in quote text, then set state to quote text if (readType != ReadType.QuoteText && previousChar == this.cDelimiter) { // workaround to allow add quotes to quote text with ex. "" are normal quote if (previousChar == this.cEnclosure) { currentItem.Append(ch); } readType = ReadType.QuoteText; } // turn off quote text state of reader automat else { readType = ReadType.CurrentLine; } } else if (ch == this.cDelimiter) { // if new line then change back to current line reader state if (readType == ReadType.NewLine) { readType = ReadType.CurrentLine; } // if in quotes allow add delimiter to text if (readType == ReadType.QuoteText) { currentItem.Append(ch); } // if normal delimiter, then add current item to items list and reset current item text else { items.Add(currentItem.ToString()); currentItem.Length = 0; } } else { // if new line then change back to current line reader state if (readType == ReadType.NewLine) { readType = ReadType.CurrentLine; } // add char to current item currentItem.Append(ch); } // set previous char previousChar = ch; } // workaround for those files not ending with new line if ((items.Count > 0) || (currentItem.Length > 0)) { Line++; items.Add(currentItem.ToString()); if (fillItemAction != null) { fillItemAction(items); } yield return(items); } }
private async Task<bool> IsWrappedInTypeObject() { _readType = ReadType.Read; if (TokenType == JsonToken.StartObject) { if (!await ReadInternal().ConfigureAwait(false)) throw JsonReaderException.Create(this, Path, "Unexpected end when reading bytes.", null); if (Value.ToString() == "$type") { await ReadInternal().ConfigureAwait(false); if (Value != null && Value.ToString().StartsWith("System.Byte[]")) { await ReadInternal().ConfigureAwait(false); if (Value.ToString() == "$value") { return true; } } } throw JsonReaderException.Create(this, Path, "Error reading bytes. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, JsonToken.StartObject), null); } return false; }
public HandScore(string name, string value, string conditioncode, CompNameAttribute compName, string dimension, int sequence, ReadType type, string userID, string userLastName, string userFirstName) { this.name = name; this.value = value; this.conditioncode = conditioncode; this.compName = compName; this.dimension = dimension; this.sequence = sequence; this.type = type; this.userID = userID; this.userLastName = userLastName; this.userFirstName = userFirstName; }
public AsyncTextureReader(RenderTexture texture) { Status = AsyncTextureReaderStatus.Idle; Texture = texture; // WARNING - if you change this, you'll need to update code below Debug.Assert( texture.format == RenderTextureFormat.ARGBFloat || texture.format == RenderTextureFormat.RGFloat || texture.format == RenderTextureFormat.RFloat || texture.format == RenderTextureFormat.ARGB32); Debug.Assert(texture.dimension == TextureDimension.Tex2D); var sync = System.Environment.GetEnvironmentVariable("FORCE_SYNC_GPU_READBACK"); if (sync == null) { if (SystemInfo.supportsAsyncGPUReadback) { Type = ReadType.Native; if (texture.format == RenderTextureFormat.ARGBFloat) { BytesPerPixel = 16; NativeReadFormat = TextureFormat.RGBAFloat; ElementCount = Texture.width * Texture.height; SizeInBytes = ElementCount * BytesPerPixel; } else if (texture.format == RenderTextureFormat.RGFloat) { BytesPerPixel = 8; NativeReadFormat = TextureFormat.RGFloat; ElementCount = Texture.width * Texture.height; SizeInBytes = ElementCount * BytesPerPixel; } else if (texture.format == RenderTextureFormat.RFloat) { BytesPerPixel = 4; NativeReadFormat = TextureFormat.RFloat; ElementCount = Texture.width * Texture.height; SizeInBytes = ElementCount * BytesPerPixel; } else // if (texture.format == RenderTextureFormat.ARGB32) { BytesPerPixel = 3; NativeReadFormat = TextureFormat.RGB24; ElementCount = Texture.width * Texture.height * BytesPerPixel; SizeInBytes = ElementCount; } Data = new NativeArray <T>(ElementCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); return; } if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLCore && SystemInfo.operatingSystemFamily == OperatingSystemFamily.Linux) { var version = SystemInfo.graphicsDeviceVersion; version = version.Split(new char[] { ' ' }, 3)[1]; var parts = version.Split(new char[] { '.' }); int major = int.Parse(parts[0]); int minor = int.Parse(parts[1]); //Debug.Log($"OpenGL version = {major}.{minor}"); // OpenGL extensions required: // ARB_buffer_storage (from 4.4) // ARB_shader_image_load_store (from 4.2) // ARB_sync (from 3.2) if (major > 4 || major == 4 && minor >= 4) { debug = new DebugDelegate(DebugCallback); AsyncTextureReaderImports.AsyncTextureReaderSetDebug(Marshal.GetFunctionPointerForDelegate(debug)); if (texture.format == RenderTextureFormat.ARGBFloat) { BytesPerPixel = 16; ElementCount = Texture.width * Texture.height; SizeInBytes = ElementCount * BytesPerPixel; } else if (texture.format == RenderTextureFormat.RGFloat) { BytesPerPixel = 8; ElementCount = Texture.width * Texture.height; SizeInBytes = ElementCount * BytesPerPixel; } else if (texture.format == RenderTextureFormat.RFloat) { BytesPerPixel = 4; ElementCount = Texture.width * Texture.height; SizeInBytes = ElementCount * BytesPerPixel; } else // if (texture.format == RenderTextureFormat.ARGB32) { BytesPerPixel = 4; ElementCount = Texture.width * Texture.height * BytesPerPixel; SizeInBytes = ElementCount; } Data = new NativeArray <T>(ElementCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); texture.Create(); LinuxId = AsyncTextureReaderImports.AsyncTextureReaderCreate(texture.GetNativeTexturePtr(), SizeInBytes); if (LinuxId >= 0) { LinuxUpdate = AsyncTextureReaderImports.AsyncTextureReaderGetUpdate(); GL.IssuePluginEvent(LinuxUpdate, LinuxId); Type = ReadType.LinuxOpenGL; } else { Debug.Log("ERROR: failed to create native AsyncTextureReader"); } return; } } } if (texture.format != RenderTextureFormat.ARGB32) { Debug.Log("ERROR: fallback AsyncTextureReader supports only ARGB32 texture format"); Type = ReadType.None; return; } Type = ReadType.Sync; BytesPerPixel = 3; ElementCount = Texture.width * Texture.height * BytesPerPixel; SizeInBytes = ElementCount; Data = new NativeArray <T>(ElementCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); ReadTexture = new Texture2D(texture.width, texture.height, TextureFormat.RGB24, false); }
private void ReadTypeCB_SelectedIndexChanged(object sender, EventArgs e) { try { ReadType readType = (ReadType)ReadTypeCB.SelectedItem; switch (readType) { case ReadType.Subscribe: { SamplingIntervalLB.Visible = true; SamplingIntervalNP.Visible = true; SamplingIntervalUnitsLB.Visible = true; StartTimeLB.Visible = true; StartTimeDP.Visible = true; StartTimeCK.Visible = true; StartTimeCK.Enabled = false; StartTimeCK.Checked = true; EndTimeLB.Visible = false; EndTimeDP.Visible = false; EndTimeCK.Visible = false; MaxReturnValuesLB.Visible = false; MaxReturnValuesNP.Visible = false; MaxReturnValuesCK.Visible = false; ReturnBoundsLB.Visible = false; ReturnBoundsCK.Visible = false; AggregateLB.Visible = true; AggregateCB.Visible = true; ResampleIntervalLB.Visible = true; ResampleIntervalNP.Visible = true; ResampleIntervalUnitsLB.Visible = true; TimeStepLB.Visible = false; TimeStepNP.Visible = false; TimeStepUnitsLB.Visible = false; break; } case ReadType.Raw: { SamplingIntervalLB.Visible = false; SamplingIntervalNP.Visible = false; SamplingIntervalUnitsLB.Visible = false; StartTimeLB.Visible = true; StartTimeDP.Visible = true; StartTimeCK.Visible = true; StartTimeCK.Enabled = true; EndTimeLB.Visible = true; EndTimeDP.Visible = true; EndTimeCK.Visible = true; EndTimeCK.Enabled = true; MaxReturnValuesLB.Visible = true; MaxReturnValuesNP.Visible = true; MaxReturnValuesCK.Visible = true; MaxReturnValuesCK.Enabled = true; ReturnBoundsLB.Visible = true; ReturnBoundsCK.Visible = true; AggregateLB.Visible = false; AggregateCB.Visible = false; ResampleIntervalLB.Visible = false; ResampleIntervalNP.Visible = false; ResampleIntervalUnitsLB.Visible = false; TimeStepLB.Visible = false; TimeStepNP.Visible = false; TimeStepUnitsLB.Visible = false; break; } case ReadType.Modified: { SamplingIntervalLB.Visible = false; SamplingIntervalNP.Visible = false; SamplingIntervalUnitsLB.Visible = false; StartTimeLB.Visible = true; StartTimeDP.Visible = true; StartTimeCK.Visible = true; StartTimeCK.Enabled = true; EndTimeLB.Visible = true; EndTimeDP.Visible = true; EndTimeCK.Visible = true; EndTimeCK.Enabled = true; MaxReturnValuesLB.Visible = true; MaxReturnValuesNP.Visible = true; MaxReturnValuesCK.Visible = true; MaxReturnValuesCK.Enabled = true; ReturnBoundsLB.Visible = false; ReturnBoundsCK.Visible = false; AggregateLB.Visible = false; AggregateCB.Visible = false; ResampleIntervalLB.Visible = false; ResampleIntervalNP.Visible = false; ResampleIntervalUnitsLB.Visible = false; TimeStepLB.Visible = false; TimeStepNP.Visible = false; TimeStepUnitsLB.Visible = false; break; } case ReadType.Processed: { SamplingIntervalLB.Visible = false; SamplingIntervalNP.Visible = false; SamplingIntervalUnitsLB.Visible = false; StartTimeLB.Visible = true; StartTimeDP.Visible = true; StartTimeCK.Visible = true; StartTimeCK.Enabled = false; StartTimeCK.Checked = true; EndTimeLB.Visible = true; EndTimeDP.Visible = true; EndTimeCK.Visible = true; EndTimeCK.Enabled = false; EndTimeCK.Checked = true; MaxReturnValuesLB.Visible = false; MaxReturnValuesNP.Visible = false; MaxReturnValuesCK.Visible = false; ReturnBoundsLB.Visible = false; ReturnBoundsCK.Visible = false; AggregateLB.Visible = true; AggregateCB.Visible = true; ResampleIntervalLB.Visible = true; ResampleIntervalNP.Visible = true; ResampleIntervalUnitsLB.Visible = true; TimeStepLB.Visible = false; TimeStepNP.Visible = false; TimeStepUnitsLB.Visible = false; break; } case ReadType.AtTime: { SamplingIntervalLB.Visible = false; SamplingIntervalNP.Visible = false; SamplingIntervalUnitsLB.Visible = false; StartTimeLB.Visible = true; StartTimeDP.Visible = true; StartTimeCK.Visible = true; StartTimeCK.Enabled = false; StartTimeCK.Checked = true; EndTimeLB.Visible = false; EndTimeDP.Visible = false; EndTimeCK.Visible = false; MaxReturnValuesLB.Visible = true; MaxReturnValuesNP.Visible = true; MaxReturnValuesCK.Visible = true; MaxReturnValuesCK.Enabled = false; MaxReturnValuesCK.Checked = true; ReturnBoundsLB.Visible = false; ReturnBoundsCK.Visible = false; AggregateLB.Visible = false; AggregateCB.Visible = false; ResampleIntervalLB.Visible = false; ResampleIntervalNP.Visible = false; ResampleIntervalUnitsLB.Visible = false; TimeStepLB.Visible = true; TimeStepNP.Visible = true; TimeStepUnitsLB.Visible = true; break; } } } catch (Exception exception) { MessageBox.Show(exception.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 读取文件内容 /// </summary> /// <param name="folderPath">文件夹路径</param> /// <param name="fileName">文件名</param> /// <param name="encode">编码</param> /// <param name="readType">读取类型(0:精准,1:前缀模糊)</param> /// <returns></returns> public static string ReadLog(string folderPath, string fileName, Encoding encode, ReadType readType = ReadType.Accurate) { string s = ""; try { LogWriteLock.EnterReadLock(); // 根据文件名读取当前文件内容 if (readType == ReadType.Accurate) { var filePath = Path.Combine(folderPath, fileName); if (!File.Exists(filePath)) { s = null; } else { StreamReader f2 = new StreamReader(filePath, encode); s = f2.ReadToEnd(); f2.Close(); f2.Dispose(); } } // 根据前缀读取所有文件内容 if (readType == ReadType.Prefix) { var allFiles = new DirectoryInfo(folderPath); var selectFiles = allFiles.GetFiles().Where(fi => fi.Name.ToLower().Contains(fileName.ToLower())).ToList(); foreach (var item in selectFiles) { if (File.Exists(item.FullName)) { StreamReader f2 = new StreamReader(item.FullName, encode); s += f2.ReadToEnd(); f2.Close(); f2.Dispose(); } } } // 根据前缀读取 最新文件 时间倒叙 if (readType == ReadType.PrefixLatest) { var allFiles = new DirectoryInfo(folderPath); var selectLastestFile = allFiles.GetFiles().Where(fi => fi.Name.ToLower().Contains(fileName.ToLower())).OrderByDescending(d => d.Name).FirstOrDefault(); if (selectLastestFile != null && File.Exists(selectLastestFile.FullName)) { StreamReader f2 = new StreamReader(selectLastestFile.FullName, encode); s = f2.ReadToEnd(); f2.Close(); f2.Dispose(); } } } catch (Exception) { FailedCount++; } finally { LogWriteLock.ExitReadLock(); } return(s); }
public override bool Read() { _readType = ReadType.Read; return(ReadInternal()); }
private void SetReadType(ReadType Type) { this.LastReadType = Type; this.LastReadTypeOffset = this.Offset; }
internal byte[] ReadAsBytesInternal() { _readType = ReadType.ReadAsBytes; do { if (!ReadInternal()) { SetToken(JsonToken.None); return(null); } } while (TokenType == JsonToken.Comment); if (IsWrappedInTypeObject()) { byte[] data = ReadAsBytes(); ReadInternal(); SetToken(JsonToken.Bytes, data); return(data); } // attempt to convert possible base 64 string to bytes if (TokenType == JsonToken.String) { string s = (string)Value; byte[] data = (s.Length == 0) ? new byte[0] : Convert.FromBase64String(s); SetToken(JsonToken.Bytes, data); } if (TokenType == JsonToken.Null) { return(null); } if (TokenType == JsonToken.Bytes) { return((byte[])Value); } if (TokenType == JsonToken.StartArray) { List <byte> data = new List <byte>(); while (ReadInternal()) { switch (TokenType) { case JsonToken.Integer: data.Add(Convert.ToByte(Value, CultureInfo.InvariantCulture)); break; case JsonToken.EndArray: byte[] d = data.ToArray(); SetToken(JsonToken.Bytes, d); return(d); case JsonToken.Comment: // skip break; default: throw CreateReaderException(this, "Unexpected token when reading bytes: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType)); } } throw CreateReaderException(this, "Unexpected end when reading bytes."); } if (TokenType == JsonToken.EndArray) { return(null); } throw CreateReaderException(this, "Error reading bytes. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType)); }
internal int? ReadAsInt32Internal() { _readType = ReadType.ReadAsInt32; JsonToken t; do { if (!ReadInternal()) { SetToken(JsonToken.None); return null; } else { t = TokenType; } } while (t == JsonToken.Comment); if (t == JsonToken.Integer || t == JsonToken.Float) { if (!(Value is int)) SetToken(JsonToken.Integer, Convert.ToInt32(Value, CultureInfo.InvariantCulture), false); return (int)Value; } if (t == JsonToken.Null) return null; int i; if (t == JsonToken.String) { string s = (string)Value; if (string.IsNullOrEmpty(s)) { SetToken(JsonToken.Null); return null; } if (int.TryParse(s, NumberStyles.Integer, Culture, out i)) { SetToken(JsonToken.Integer, i, false); return i; } else { throw JsonReaderException.Create(this, "Could not convert string to integer: {0}.".FormatWith(CultureInfo.InvariantCulture, Value)); } } if (t == JsonToken.EndArray) return null; throw JsonReaderException.Create(this, "Error reading integer. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType)); }
internal byte[] ReadAsBytesInternal() { _readType = ReadType.ReadAsBytes; JsonToken t; do { if (!ReadInternal()) { SetToken(JsonToken.None); return(null); } else { t = TokenType; } } while (t == JsonToken.Comment); if (IsWrappedInTypeObject()) { byte[] data = ReadAsBytes(); ReadInternal(); SetToken(JsonToken.Bytes, data, false); return(data); } // attempt to convert possible base 64 string to bytes if (t == JsonToken.String) { string s = (string)Value; byte[] data; Guid g; if (s.Length == 0) { data = new byte[0]; } else if (ConvertUtils.TryConvertGuid(s, out g)) { data = g.ToByteArray(); } else { data = Convert.FromBase64String(s); } SetToken(JsonToken.Bytes, data, false); return(data); } if (t == JsonToken.Null) { return(null); } if (t == JsonToken.Bytes) { if (ValueType == typeof(Guid)) { byte[] data = ((Guid)Value).ToByteArray(); SetToken(JsonToken.Bytes, data, false); return(data); } return((byte[])Value); } if (t == JsonToken.StartArray) { List <byte> data = new List <byte>(); while (ReadInternal()) { t = TokenType; switch (t) { case JsonToken.Integer: data.Add(Convert.ToByte(Value, CultureInfo.InvariantCulture)); break; case JsonToken.EndArray: byte[] d = data.ToArray(); SetToken(JsonToken.Bytes, d, false); return(d); case JsonToken.Comment: // skip break; default: throw JsonReaderException.Create(this, "Unexpected token when reading bytes: {0}.".FormatWith(CultureInfo.InvariantCulture, t)); } } throw JsonReaderException.Create(this, "Unexpected end when reading bytes."); } if (t == JsonToken.EndArray) { return(null); } throw JsonReaderException.Create(this, "Error reading bytes. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, t)); }
public void Call(Client client, ReadType read) { Method.Invoke(Obj, new object[] { client, read }); }
internal decimal?ReadAsDecimalInternal() { _readType = ReadType.ReadAsDecimal; JsonToken t; do { if (!ReadInternal()) { SetToken(JsonToken.None); return(null); } else { t = TokenType; } } while (t == JsonToken.Comment); if (t == JsonToken.Integer || t == JsonToken.Float) { if (!(Value is decimal)) { SetToken(JsonToken.Float, Convert.ToDecimal(Value, CultureInfo.InvariantCulture), false); } return((decimal)Value); } if (t == JsonToken.Null) { return(null); } if (t == JsonToken.String) { string s = (string)Value; if (string.IsNullOrEmpty(s)) { SetToken(JsonToken.Null); return(null); } decimal d; if (decimal.TryParse(s, NumberStyles.Number, Culture, out d)) { SetToken(JsonToken.Float, d, false); return(d); } else { throw JsonReaderException.Create(this, "Could not convert string to decimal: {0}.".FormatWith(CultureInfo.InvariantCulture, Value)); } } if (t == JsonToken.EndArray) { return(null); } throw JsonReaderException.Create(this, "Error reading decimal. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, t)); }
internal async Task<DateTime?> ReadAsDateTimeInternal() { _readType = ReadType.ReadAsDateTime; do { if (!await ReadInternal().ConfigureAwait(false)) { SetToken(JsonToken.None); return null; } } while (TokenType == JsonToken.Comment); if (TokenType == JsonToken.Date) return (DateTime)Value; if (TokenType == JsonToken.Null) return null; DateTime dt; if (TokenType == JsonToken.String) { string s = (string)Value; if (string.IsNullOrEmpty(s)) { SetToken(JsonToken.Null); return null; } if (DateTime.TryParse(s, Culture, DateTimeStyles.RoundtripKind, out dt)) { dt = DateTimeUtils.EnsureDateTime(dt, DateTimeZoneHandling); SetToken(JsonToken.Date, dt); return dt; } else { throw JsonReaderException.Create(this, Path, "Could not convert string to DateTime: {0}.".FormatWith(CultureInfo.InvariantCulture, Value), null); } } if (TokenType == JsonToken.EndArray) return null; throw JsonReaderException.Create(this, Path, "Error reading date. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType), null); }
internal int?ReadAsInt32Internal() { _readType = ReadType.ReadAsInt32; JsonToken t; do { if (!ReadInternal()) { SetToken(JsonToken.None); return(null); } else { t = TokenType; } } while (t == JsonToken.Comment); if (t == JsonToken.Integer || t == JsonToken.Float) { if (!(Value is int)) { SetToken(JsonToken.Integer, Convert.ToInt32(Value, CultureInfo.InvariantCulture), false); } return((int)Value); } if (t == JsonToken.Null) { return(null); } int i; if (t == JsonToken.String) { string s = (string)Value; if (string.IsNullOrEmpty(s)) { SetToken(JsonToken.Null); return(null); } if (int.TryParse(s, NumberStyles.Integer, Culture, out i)) { SetToken(JsonToken.Integer, i, false); return(i); } else { throw JsonReaderException.Create(this, "Could not convert string to integer: {0}.".FormatWith(CultureInfo.InvariantCulture, Value)); } } if (t == JsonToken.EndArray) { return(null); } throw JsonReaderException.Create(this, "Error reading integer. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType)); }
public void SetReadType(ReadType t) { readType = t; }
internal DateTimeOffset?ReadAsDateTimeOffsetInternal() { _readType = ReadType.ReadAsDateTimeOffset; JsonToken t; do { if (!ReadInternal()) { SetToken(JsonToken.None); return(null); } else { t = TokenType; } } while (t == JsonToken.Comment); if (t == JsonToken.Date) { if (Value is DateTime) { SetToken(JsonToken.Date, new DateTimeOffset((DateTime)Value), false); } return((DateTimeOffset)Value); } if (t == JsonToken.Null) { return(null); } DateTimeOffset dt; if (t == JsonToken.String) { string s = (string)Value; if (string.IsNullOrEmpty(s)) { SetToken(JsonToken.Null); return(null); } object temp; if (DateTimeUtils.TryParseDateTime(s, DateParseHandling.DateTimeOffset, DateTimeZoneHandling, out temp)) { dt = (DateTimeOffset)temp; SetToken(JsonToken.Date, dt, false); return(dt); } if (DateTimeOffset.TryParse(s, Culture, DateTimeStyles.RoundtripKind, out dt)) { SetToken(JsonToken.Date, dt, false); return(dt); } throw JsonReaderException.Create(this, "Could not convert string to DateTimeOffset: {0}.".FormatWith(CultureInfo.InvariantCulture, Value)); } if (t == JsonToken.EndArray) { return(null); } throw JsonReaderException.Create(this, "Error reading date. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, t)); }
private void ParseString(char quote, ReadType readType) { _charPos++; ShiftBufferIfNeeded(); ReadStringIntoBuffer(quote); SetPostValueState(true); switch (readType) { case ReadType.ReadAsBytes: Guid g; byte[] data; if (_stringReference.Length == 0) { data = new byte[0]; } else if (_stringReference.Length == 36 && ConvertUtils.TryConvertGuid(_stringReference.ToString(), out g)) { data = g.ToByteArray(); } else { data = Convert.FromBase64CharArray(_stringReference.Chars, _stringReference.StartIndex, _stringReference.Length); } SetToken(JsonToken.Bytes, data, false); break; case ReadType.ReadAsString: string text = _stringReference.ToString(); SetToken(JsonToken.String, text, false); _quoteChar = quote; break; case ReadType.ReadAsInt32: case ReadType.ReadAsDecimal: case ReadType.ReadAsBoolean: // caller will convert result break; default: if (_dateParseHandling != DateParseHandling.None) { DateParseHandling dateParseHandling; if (readType == ReadType.ReadAsDateTime) { dateParseHandling = DateParseHandling.DateTime; } #if !NET20 else if (readType == ReadType.ReadAsDateTimeOffset) { dateParseHandling = DateParseHandling.DateTimeOffset; } #endif else { dateParseHandling = _dateParseHandling; } if (dateParseHandling == DateParseHandling.DateTime) { DateTime dt; if (DateTimeUtils.TryParseDateTime(_stringReference, DateTimeZoneHandling, DateFormatString, Culture, out dt)) { SetToken(JsonToken.Date, dt, false); return; } } #if !NET20 else { DateTimeOffset dt; if (DateTimeUtils.TryParseDateTimeOffset(_stringReference, DateFormatString, Culture, out dt)) { SetToken(JsonToken.Date, dt, false); return; } } #endif } SetToken(JsonToken.String, _stringReference.ToString(), false); _quoteChar = quote; break; } }
internal byte[] ReadAsBytesInternal() { this._readType = ReadType.ReadAsBytes; while (this.ReadInternal()) { if (this.TokenType != JsonToken.Comment) { if (this.IsWrappedInTypeObject()) { byte[] numArray = this.ReadAsBytes(); this.ReadInternal(); this.SetToken(JsonToken.Bytes, (object)numArray); return(numArray); } else { if (this.TokenType == JsonToken.String) { string s = (string)this.Value; this.SetToken(JsonToken.Bytes, s.Length == 0 ? (object)new byte[0] : (object)Convert.FromBase64String(s)); } if (this.TokenType == JsonToken.Null) { return((byte[])null); } if (this.TokenType == JsonToken.Bytes) { return((byte[])this.Value); } if (this.TokenType == JsonToken.StartArray) { List <byte> list = new List <byte>(); while (this.ReadInternal()) { switch (this.TokenType) { case JsonToken.Comment: continue; case JsonToken.Integer: list.Add(Convert.ToByte(this.Value, (IFormatProvider)CultureInfo.InvariantCulture)); continue; case JsonToken.EndArray: byte[] numArray = list.ToArray(); this.SetToken(JsonToken.Bytes, (object)numArray); return(numArray); default: throw JsonReaderException.Create(this, StringUtils.FormatWith("Unexpected token when reading bytes: {0}.", (IFormatProvider)CultureInfo.InvariantCulture, (object)this.TokenType)); } } throw JsonReaderException.Create(this, "Unexpected end when reading bytes."); } else if (this.TokenType == JsonToken.EndArray) { return((byte[])null); } else { throw JsonReaderException.Create(this, StringUtils.FormatWith("Error reading bytes. Unexpected token: {0}.", (IFormatProvider)CultureInfo.InvariantCulture, (object)this.TokenType)); } } } } this.SetToken(JsonToken.None); return((byte[])null); }
private object ParseNumberNaN(ReadType readType) { if (MatchValueWithTrailingSeparator(JsonConvert.NaN)) { switch (readType) { case ReadType.Read: case ReadType.ReadAsDouble: if (_floatParseHandling == FloatParseHandling.Double) { SetToken(JsonToken.Float, double.NaN); return double.NaN; } break; case ReadType.ReadAsString: SetToken(JsonToken.String, JsonConvert.NaN); return JsonConvert.NaN; } throw JsonReaderException.Create(this, "Cannot read NaN value."); } throw JsonReaderException.Create(this, "Error parsing NaN value."); }
internal DateTime? ReadAsDateTimeInternal() { _readType = ReadType.ReadAsDateTime; do { if (!ReadInternal()) { SetToken(JsonToken.None); return null; } } while (TokenType == JsonToken.Comment); if (TokenType == JsonToken.Date) return (DateTime)Value; if (TokenType == JsonToken.Null) return null; if (TokenType == JsonToken.String) { string s = (string)Value; if (string.IsNullOrEmpty(s)) { SetToken(JsonToken.Null); return null; } DateTime dt; object temp; if (DateTimeUtils.TryParseDateTime(s, DateParseHandling.DateTime, DateTimeZoneHandling, _dateFormatString, Culture, out temp)) { dt = (DateTime)temp; dt = DateTimeUtils.EnsureDateTime(dt, DateTimeZoneHandling); SetToken(JsonToken.Date, dt, false); return dt; } if (DateTime.TryParse(s, Culture, DateTimeStyles.RoundtripKind, out dt)) { dt = DateTimeUtils.EnsureDateTime(dt, DateTimeZoneHandling); SetToken(JsonToken.Date, dt, false); return dt; } throw JsonReaderException.Create(this, "Could not convert string to DateTime: {0}.".FormatWith(CultureInfo.InvariantCulture, Value)); } if (TokenType == JsonToken.EndArray) return null; throw JsonReaderException.Create(this, "Error reading date. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType)); }
private object ReadNumberValue(ReadType readType) { EnsureBuffer(); switch (_currentState) { case State.Start: case State.Property: case State.Array: case State.ArrayStart: case State.Constructor: case State.ConstructorStart: case State.PostValue: while (true) { char currentChar = _chars[_charPos]; switch (currentChar) { case '\0': if (ReadNullChar()) { SetToken(JsonToken.None, null, false); return null; } break; case '"': case '\'': ParseString(currentChar, readType); switch (readType) { case ReadType.ReadAsInt32: return ReadInt32String(_stringReference.ToString()); case ReadType.ReadAsDecimal: return ReadDecimalString(_stringReference.ToString()); case ReadType.ReadAsDouble: return ReadDoubleString(_stringReference.ToString()); default: throw new ArgumentOutOfRangeException(nameof(readType)); } case 'n': HandleNull(); return null; case 'N': return ParseNumberNaN(readType); case 'I': return ParseNumberPositiveInfinity(readType); case '-': if (EnsureChars(1, true) && _chars[_charPos + 1] == 'I') { return ParseNumberNegativeInfinity(readType); } else { ParseNumber(readType); return Value; } case '.': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': ParseNumber(readType); return Value; case '/': ParseComment(false); break; case ',': ProcessValueComma(); break; case ']': _charPos++; if (_currentState == State.Array || _currentState == State.ArrayStart || _currentState == State.PostValue) { SetToken(JsonToken.EndArray); return null; } throw CreateUnexpectedCharacterException(currentChar); case StringUtils.CarriageReturn: ProcessCarriageReturn(false); break; case StringUtils.LineFeed: ProcessLineFeed(); break; case ' ': case StringUtils.Tab: // eat _charPos++; break; default: _charPos++; if (!char.IsWhiteSpace(currentChar)) { throw CreateUnexpectedCharacterException(currentChar); } // eat break; } } case State.Finished: ReadFinished(); return null; default: throw JsonReaderException.Create(this, "Unexpected state: {0}.".FormatWith(CultureInfo.InvariantCulture, CurrentState)); } }
internal JsonContract(Type underlyingType) { ValidationUtils.ArgumentNotNull(underlyingType, nameof(underlyingType)); UnderlyingType = underlyingType; IsNullable = ReflectionUtils.IsNullable(underlyingType); NonNullableUnderlyingType = (IsNullable && ReflectionUtils.IsNullableType(underlyingType)) ? Nullable.GetUnderlyingType(underlyingType) : underlyingType; CreatedType = NonNullableUnderlyingType; IsConvertable = ConvertUtils.IsConvertible(NonNullableUnderlyingType); IsEnum = NonNullableUnderlyingType.IsEnum(); InternalReadType = ReadType.Read; }
internal DateTimeOffset? ReadAsDateTimeOffsetInternal() { _readType = ReadType.ReadAsDateTimeOffset; JsonToken t; do { if (!ReadInternal()) { SetToken(JsonToken.None); return null; } else { t = TokenType; } } while (t == JsonToken.Comment); if (t == JsonToken.Date) { if (Value is DateTime) SetToken(JsonToken.Date, new DateTimeOffset((DateTime)Value), false); return (DateTimeOffset)Value; } if (t == JsonToken.Null) return null; if (t == JsonToken.String) { string s = (string)Value; if (string.IsNullOrEmpty(s)) { SetToken(JsonToken.Null); return null; } DateTimeOffset dt; if (DateTimeUtils.TryParseDateTimeOffset(s, _dateFormatString, Culture, out dt)) { SetToken(JsonToken.Date, dt, false); return dt; } if (DateTimeOffset.TryParse(s, Culture, DateTimeStyles.RoundtripKind, out dt)) { SetToken(JsonToken.Date, dt, false); return dt; } throw JsonReaderException.Create(this, "Could not convert string to DateTimeOffset: {0}.".FormatWith(CultureInfo.InvariantCulture, Value)); } if (t == JsonToken.EndArray) return null; throw JsonReaderException.Create(this, "Error reading date. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, t)); }
/// <summary> /// Reads the next JSON token from the stream. /// </summary> /// <returns> /// true if the next token was read successfully; false if there are no more tokens to read. /// </returns> public override bool Read() { _readType = ReadType.Read; return ReadInternal(); }
internal decimal? ReadAsDecimalInternal() { _readType = ReadType.ReadAsDecimal; JsonToken t; do { if (!ReadInternal()) { SetToken(JsonToken.None); return null; } else { t = TokenType; } } while (t == JsonToken.Comment); if (t == JsonToken.Integer || t == JsonToken.Float) { if (!(Value is decimal)) SetToken(JsonToken.Float, Convert.ToDecimal(Value, CultureInfo.InvariantCulture), false); return (decimal)Value; } if (t == JsonToken.Null) return null; if (t == JsonToken.String) { string s = (string)Value; if (string.IsNullOrEmpty(s)) { SetToken(JsonToken.Null); return null; } decimal d; if (decimal.TryParse(s, NumberStyles.Number, Culture, out d)) { SetToken(JsonToken.Float, d, false); return d; } else { throw JsonReaderException.Create(this, "Could not convert string to decimal: {0}.".FormatWith(CultureInfo.InvariantCulture, Value)); } } if (t == JsonToken.EndArray) return null; throw JsonReaderException.Create(this, "Error reading decimal. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, t)); }
/// <summary> /// Reads the next JSON token from the stream as a <see cref="Nullable{Decimal}"/>. /// </summary> /// <returns>A <see cref="Nullable{Decimal}"/>.</returns> public override decimal? ReadAsDecimal() { _readType = ReadType.ReadAsDecimal; if (!ReadInternal()) throw CreateJsonReaderException("Unexpected end when reading decimal: Line {0}, position {1}.", _currentLineNumber, _currentLinePosition); if (TokenType == JsonToken.Null) return null; if (TokenType == JsonToken.Float) return (decimal?)Value; throw CreateJsonReaderException("Unexpected token when reading decimal: {0}. Line {1}, position {2}.", TokenType, _currentLineNumber, _currentLinePosition); }
internal string ReadAsStringInternal() { _readType = ReadType.ReadAsString; JsonToken t; do { if (!ReadInternal()) { SetToken(JsonToken.None); return null; } else { t = TokenType; } } while (t == JsonToken.Comment); if (t == JsonToken.String) return (string)Value; if (t == JsonToken.Null) return null; if (JsonTokenUtils.IsPrimitiveToken(t)) { if (Value != null) { string s; if (Value is IFormattable) s = ((IFormattable)Value).ToString(null, Culture); else s = Value.ToString(); SetToken(JsonToken.String, s, false); return s; } } if (t == JsonToken.EndArray) return null; throw JsonReaderException.Create(this, "Error reading string. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, t)); }
public void Call(Server server, ReadType read, UserT userinfo) { Method.Invoke(Obj, new object[] { server, read, userinfo }); }
private bool IsWrappedInTypeObject() { _readType = ReadType.Read; if (TokenType == JsonToken.StartObject) { if (!ReadInternal()) throw JsonReaderException.Create(this, "Unexpected end when reading bytes."); if (Value.ToString() == JsonTypeReflector.TypePropertyName) { ReadInternal(); if (Value != null && Value.ToString().StartsWith("System.Byte[]", StringComparison.Ordinal)) { ReadInternal(); if (Value.ToString() == JsonTypeReflector.ValuePropertyName) { return true; } } } throw JsonReaderException.Create(this, "Error reading bytes. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, JsonToken.StartObject)); } return false; }
internal string ReadAsStringInternal() { _readType = ReadType.ReadAsString; do { if (!ReadInternal()) { SetToken(JsonToken.None); return null; } } while (TokenType == JsonToken.Comment); if (TokenType == JsonToken.String) return (string)Value; if (TokenType == JsonToken.Null) return null; if (IsPrimitiveToken(TokenType)) { if (Value != null) { string s; if (ConvertUtils.IsConvertible(Value)) s = ConvertUtils.ToConvertible(Value).ToString(Culture); else if (Value is IFormattable) s = ((IFormattable)Value).ToString(null, Culture); else s = Value.ToString(); SetToken(JsonToken.String, s); return s; } } if (TokenType == JsonToken.EndArray) return null; throw CreateReaderException(this, "Error reading string. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType)); }
internal JsonContract(Type underlyingType) { ValidationUtils.ArgumentNotNull(underlyingType, "underlyingType"); UnderlyingType = underlyingType; IsNullable = ReflectionUtils.IsNullable(underlyingType); NonNullableUnderlyingType = (IsNullable && ReflectionUtils.IsNullableType(underlyingType)) ? Nullable.GetUnderlyingType(underlyingType) : underlyingType; CreatedType = NonNullableUnderlyingType; IsConvertable = ConvertUtils.IsConvertible(NonNullableUnderlyingType); IsEnum = NonNullableUnderlyingType.IsEnum(); if (NonNullableUnderlyingType == typeof(byte[])) { InternalReadType = ReadType.ReadAsBytes; } else if (NonNullableUnderlyingType == typeof(int)) { InternalReadType = ReadType.ReadAsInt32; } else if (NonNullableUnderlyingType == typeof(decimal)) { InternalReadType = ReadType.ReadAsDecimal; } else if (NonNullableUnderlyingType == typeof(string)) { InternalReadType = ReadType.ReadAsString; } else if (NonNullableUnderlyingType == typeof(DateTime)) { InternalReadType = ReadType.ReadAsDateTime; } #if !NET20 else if (NonNullableUnderlyingType == typeof(DateTimeOffset)) { InternalReadType = ReadType.ReadAsDateTimeOffset; } #endif else { InternalReadType = ReadType.Read; } }
private bool IsWrappedInTypeObject() { _readType = ReadType.Read; if (TokenType == JsonToken.StartObject) { if (!ReadInternal()) throw CreateReaderException(this, "Unexpected end when reading bytes."); if (Value.ToString() == "$type") { ReadInternal(); if (Value != null && Value.ToString().StartsWith("System.Byte[]")) { ReadInternal(); if (Value.ToString() == "$value") { return true; } } } throw CreateReaderException(this, "Error reading bytes. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, JsonToken.StartObject)); } return false; }
/// <summary> /// Reads the next JSON token from the stream as a <see cref="T:Byte[]"/>. /// </summary> /// <returns> /// A <see cref="T:Byte[]"/> or a null reference if the next JSON token is null. /// </returns> public override byte[] ReadAsBytes() { _readType = ReadType.ReadAsBytes; if (!ReadInternal()) throw CreateJsonReaderException("Unexpected end when reading bytes: Line {0}, position {1}.", _currentLineNumber, _currentLinePosition); if (TokenType == JsonToken.Null) return null; if (TokenType == JsonToken.Bytes) return (byte[]) Value; throw CreateJsonReaderException("Unexpected token when reading bytes: {0}. Line {1}, position {2}.", TokenType, _currentLineNumber, _currentLinePosition); }
internal async Task<string> ReadAsStringInternal() { _readType = ReadType.ReadAsString; do { if (!await ReadInternal().ConfigureAwait(false)) { SetToken(JsonToken.None); return null; } } while (TokenType == JsonToken.Comment); if (TokenType == JsonToken.String) return (string)Value; if (TokenType == JsonToken.Null) return null; if (IsPrimitiveToken(TokenType)) { if (Value != null) { string s; if (Value is IFormattable) s = ((IFormattable)Value).ToString(null, Culture); else s = Value.ToString(); SetToken(JsonToken.String, s); return s; } } if (TokenType == JsonToken.EndArray) return null; throw JsonReaderException.Create(this, Path, "Error reading string. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType), null); }
/// <summary> /// Reads the next JSON token from the stream as a <see cref="Nullable{DateTimeOffset}"/>. /// </summary> /// <returns>A <see cref="DateTimeOffset"/>.</returns> public override DateTimeOffset? ReadAsDateTimeOffset() { _readType = ReadType.ReadAsDateTimeOffset; if (!ReadInternal()) throw CreateJsonReaderException("Unexpected end when reading date: Line {0}, position {1}.", _currentLineNumber, _currentLinePosition); if (TokenType == JsonToken.Null) return null; if (TokenType == JsonToken.Date) return (DateTimeOffset)Value; throw CreateJsonReaderException("Unexpected token when reading date: {0}. Line {1}, position {2}.", TokenType, _currentLineNumber, _currentLinePosition); }
public void InitializeHandScore(string name, string value, string conditioncode, string compName, string dimension, int sequence, string type, string userID, string userLastName, string userFirstName) { this.name = name; this.value = value; this.conditioncode = conditioncode; switch (compName.ToLower()) { case "score points": this.compName = CompNameAttribute.ScorePoints; break; case "scorepoints": this.compName = CompNameAttribute.ScorePoints; break; case "overall": this.compName = CompNameAttribute.ScorePoints; break; case "condition codes": this.compName = CompNameAttribute.ConditionCodes; break; case "conditioncodes": this.compName = CompNameAttribute.ConditionCodes; break; case "dimension": this.compName = CompNameAttribute.Dimension; break; default: this.compName = CompNameAttribute.Dimension; break; } this.dimension = dimension; this.sequence = sequence; switch (type.ToLower()) { case "initial": this.type = ReadType.Initial; break; case "reliability": this.type = ReadType.Reliability; break; case "additional": this.type = ReadType.Reliability; break; case "backread": this.type = ReadType.Backread; break; case "resolution": this.type = ReadType.Resolution; break; case "manager read": this.type = ReadType.ManageOverride; break; case "manageoverride": this.type = ReadType.ManageOverride; break; case "manageroverride": this.type = ReadType.ManageOverride; break; case "machineinitial": this.type = ReadType.Initial; break; case "machine initial read": this.type = ReadType.Initial; break; case "targeted backread": this.type = ReadType.TargetedBackread; break; case "targetedbackread": this.type = ReadType.TargetedBackread; break; case "rescore": this.type = ReadType.Rescore; break; case "dimension rater": this.type = ReadType.Analytic; break; case "analytic": this.type = ReadType.Analytic; break; case "dimension rescore": this.type = ReadType.Analytic; break; case "final": this.type = ReadType.Final; break; default: throw new Exception("Unknown ReadType: " + type); break; } this.userID = userID; this.userLastName = userLastName; this.userFirstName = userFirstName; }