//--------------------------------------------------------------------- private T ReadValue <T>() { ReadMethod <T> method = InputValues.GetReadMethod <T>(); int index; return(method(currentLine, out index)); }
/// <summary> /// Handles reading pending project packets. /// </summary> public override void HandleRead() { var magicNumber = ReadByte(); ReadMethod?.Invoke(magicNumber); }
/// <summary> /// Handles reading caliber packets. /// </summary> public override void HandleRead() { var caliberRequest = ReadBoolean(); ReadMethod?.Invoke(caliberRequest); }
/// <summary> /// Handles an error message packets. /// </summary> public override void HandleRead() { var errorCode = ReadByte(); ReadMethod?.Invoke(errorCode); }
/// <summary>Begins an asynchronous read operation.</summary> /// <returns>An <see cref="T:System.IAsyncResult" /> object that represents the asynchronous read, which could still be pending.</returns> /// <param name="array">The byte array to read the data into.</param> /// <param name="offset">The byte offset in <paramref name="array" /> at which to begin writing data read from the stream.</param> /// <param name="count">The maximum number of bytes to read.</param> /// <param name="asyncCallback">An optional asynchronous callback, to be called when the read is complete.</param> /// <param name="asyncState">A user-provided object that distinguishes this particular asynchronous read request from other requests.</param> /// <exception cref="T:System.IO.IOException">An asynchronous read past the end of the stream was attempted, or a disk error occurred.</exception> /// <exception cref="T:System.ArgumentException">One or more of the arguments is invalid.</exception> /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.</exception> /// <exception cref="T:System.NotSupportedException">The current <see cref="T:System.IO.Compression.DeflateStream" /> implementation does not support the read operation.</exception> /// <exception cref="T:System.InvalidOperationException">This call cannot be completed. </exception> public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback cback, object state) { if (disposed) { throw new ObjectDisposedException(GetType().FullName); } if (!CanRead) { throw new NotSupportedException("This stream does not support reading"); } if (buffer == null) { throw new ArgumentNullException("buffer"); } if (count < 0) { throw new ArgumentOutOfRangeException("count", "Must be >= 0"); } if (offset < 0) { throw new ArgumentOutOfRangeException("offset", "Must be >= 0"); } if (count + offset > buffer.Length) { throw new ArgumentException("Buffer too small. count/offset wrong."); } ReadMethod readMethod = ReadInternal; return(readMethod.BeginInvoke(buffer, offset, count, cback, state)); }
public void Invoke(byte[] datas) { if (ParameterType != null) { var po = Activator.CreateInstance(ParameterType); if (readParamList == null) { readParamList = new object[3]; readParamList[1] = 4; } readParamList[0] = datas; readParamList[2] = datas.Length - 4; ReadMethod.Invoke(po, readParamList); readParamList[0] = ""; if (paramList == null) { paramList = new object[1]; } paramList[0] = po; Debug.Log("TryInvoke " + Method.Name + " " + po.ToString()); Method.Invoke(null, paramList); } else { Debug.Log("TryInvoke " + Method.Name); Method.Invoke(null, null); } }
//--------------------------------------------------------------------- /// <summary> /// Reads an integer input value for an effective seed-dispersal /// distance. /// </summary> /// <param name="reader"> /// The string reader from which the input value is read. /// </param> /// <param name="index"> /// The starting index in the reader's input stream where the input /// value was located. /// </param> /// <remarks> /// This method uses the registered ReadMethod for integer values. /// The input value "uni" is treated specially, and yield an integer /// input value equal to the Universal constant. /// </remarks> public static InputValue <int> ReadMethod(StringReader reader, out int index) { ReadMethod <int> intRead = InputValues.GetReadMethod <int>(); try { return(intRead(reader, out index)); } catch (InputValueException exc) { if (exc.Value == UniversalAsString) { index = reader.Index - exc.Value.Length; return(new InputValue <int>(Universal, exc.Value)); } else if (exc.Message.Contains("outside the range")) { // Overflow exception with integer value throw; } else { string message = string.Format("\"{0}\" is not a valid integer or \"{1}\"", exc.Value, UniversalAsString); throw new InputValueException(exc.Value, message); } } }
/// <summary> /// Handles reading caliber packets. /// </summary> public override void HandleRead() { var caliberCount = ReadInt32(); ReadMethod?.Invoke(caliberCount); }
/// <summary> /// Handles reading project packets. /// </summary> public override void HandleRead() { var shouldStart = ReadBoolean(); ReadMethod?.Invoke(shouldStart); }
private static void TakeFileFromFolder(ReadMethod readMethod, string filter = null) { Stream stream = null; OpenFileDialog openFileDialog = new OpenFileDialog(); if (filter != null) { openFileDialog.Filter = filter; } if (openFileDialog.ShowDialog() == DialogResult.OK) { try { if ((stream = openFileDialog.OpenFile()) != null) { readMethod(stream); } } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } }
/// <summary> /// Handles reading heartbeats. /// </summary> public override void HandleRead() { var heartBeat = ReadByte(); ReadMethod?.Invoke(heartBeat); manager.WritePacket(OpCodes.HeartbeatTransmit); }
//--------------------------------------------------------------------- /// <summary> /// Initializes a new instance. /// </summary> public InputVar(string name, ReadMethod <T> readMethod) : base(name) { myValue = null; Require.ArgumentNotNull(readMethod); this.readMethod = readMethod; index = -1; }
/// <summary> /// Handles reading version over network. /// </summary> public override void HandleRead() { var x = ReadByte(); var y = ReadByte(); var z = ReadByte(); OtherVersion = new Version(x, y, z); ReadMethod?.Invoke(OtherVersion); }
public void GetReadMethod_UnregisteredType() { try { ReadMethod <UnregisteredClass> readMethod = InputValues.GetReadMethod <UnregisteredClass>(); } catch (Exception exc) { Data.Output.WriteLine(exc.Message); throw; } }
public override int GetHashCode() { unchecked { var hashCode = (PropertyName != null ? PropertyName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ PropertyType.GetHashCode(); hashCode = (hashCode * 397) ^ (ReadMethod != null ? ReadMethod.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (AccessorField != null ? AccessorField.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (AccessorProp != null ? AccessorProp.GetHashCode() : 0); return hashCode; } }
private static TDataType[] ReadArray <TDataType>(uint numberOfComponents, ReadMethod <TDataType> read) { var result = new TDataType[numberOfComponents]; for (int i = 0; i < numberOfComponents; i++) { result.SetValue(read(), i); } return(result); }
public void Init() { Flel.Util.Type.SetDescription <RegisteredClass>("Registered Class"); InputValues.Register <RegisteredClass>(RegisteredClass.Parse); byteReadMethod = InputValues.GetReadMethod <byte>(); values = new byte[] { 78, 0, 255 }; string[] valsAsStrs = Array.ConvertAll(values, new Converter <byte, string>(Convert.ToString)); valuesAsStr = string.Join(" ", valsAsStrs); }
public void GetReadMethod_Float_LessThanMin() { try { StringReader reader = new StringReader(double.MinValue.ToString()); ReadMethod <float> readMethod = InputValues.GetReadMethod <float>(); int index; InputValue <float> result = readMethod(reader, out index); } catch (InputValueException exc) { Data.Output.WriteLine(exc.Message); throw exc; } }
public void GetReadMethod_Int_MoreThanMax() { try { StringReader reader = new StringReader(long.MaxValue.ToString()); ReadMethod <int> readMethod = InputValues.GetReadMethod <int>(); int index; InputValue <int> result = readMethod(reader, out index); } catch (InputValueException exc) { Data.Output.WriteLine(exc.Message); throw exc; } }
public void GetReadMethod_RegisteredType() { ReadMethod <RegisteredClass> readMethod = InputValues.GetReadMethod <RegisteredClass>(); string[] words = new string[] { "aardvark", "LKR555", "<-o->" }; string separator = " \t "; StringReader reader = new StringReader(string.Join(separator, words)); foreach (string word in words) { int index; InputValue <RegisteredClass> result = readMethod(reader, out index); Assert.AreEqual(word, result.Actual.Str); Assert.AreEqual(word, result.String); Assert.AreEqual(index + word.Length, reader.Index); } }
/// <summary> /// Reads a plug-in name from a text reader and returns the /// information for the plug-in. /// </summary> public static InputValue <Edu.Wisc.Forest.Flel.Util.PlugIns.Info> Read(StringReader reader, out int index) { ReadMethod <string> strReadMethod = InputValues.GetReadMethod <string>(); InputValue <string> name = strReadMethod(reader, out index); if (name.Actual.Trim(null) == "") { throw new InputValueException(name.Actual, name.String + " is not a valid plug-in name."); } Edu.Wisc.Forest.Flel.Util.PlugIns.Info info = (Edu.Wisc.Forest.Flel.Util.PlugIns.Info)PlugIns.Manager.GetInfo(name.Actual); if (info == null) { throw new InputValueException(name.Actual, "No plug-in with the name \"{0}\".", name.Actual); } return(new InputValue <Edu.Wisc.Forest.Flel.Util.PlugIns.Info>(info, name.Actual)); }
/// <summary>Waits for the pending asynchronous read to complete.</summary> /// <returns>The number of bytes read from the stream, between zero (0) and the number of bytes you requested. <see cref="T:System.IO.Compression.DeflateStream" /> returns zero (0) only at the end of the stream; otherwise, it blocks until at least one byte is available.</returns> /// <param name="asyncResult">The reference to the pending asynchronous request to finish.</param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="asyncResult" /> is null.</exception> /// <exception cref="T:System.ArgumentException"> /// <paramref name="asyncResult" /> did not originate from a <see cref="M:System.IO.Compression.DeflateStream.BeginRead(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)" /> method on the current stream.</exception> /// <exception cref="T:System.SystemException">An exception was thrown during a call to <see cref="M:System.Threading.WaitHandle.WaitOne" />.</exception> /// <exception cref="T:System.InvalidOperationException">The end call is invalid because asynchronous read operations for this stream are not yet complete.</exception> /// <exception cref="T:System.InvalidOperationException">The stream is null.</exception> public override int EndRead(IAsyncResult async_result) { if (async_result == null) { throw new ArgumentNullException("async_result"); } AsyncResult asyncResult = async_result as AsyncResult; if (asyncResult == null) { throw new ArgumentException("Invalid IAsyncResult", "async_result"); } ReadMethod readMethod = asyncResult.AsyncDelegate as ReadMethod; if (readMethod == null) { throw new ArgumentException("Invalid IAsyncResult", "async_result"); } return(readMethod.EndInvoke(async_result)); }
//--------------------------------------------------------------------- /// <summary> /// Reads a plug-in name from a text reader and returns the /// information for the plug-in. /// </summary> public static InputValue <PlugIns.PlugInInfo> Read(StringReader reader, out int index) { ReadMethod <string> strReadMethod = InputValues.GetReadMethod <string>(); InputValue <string> name = strReadMethod(reader, out index); if (name.Actual.Trim(null) == "") { throw new InputValueException(name.Actual, name.String + " is not a valid plug-in name."); } PlugIns.PlugInInfo info = installedPlugIns[name.Actual]; if (info == null) { throw new InputValueException(name.Actual, "No plug-in with the name \"{0}\".", name.Actual); } return(new InputValue <PlugIns.PlugInInfo>(info, name.Actual)); }
public override IAsyncResult BeginRead(byte [] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) { if (disposed) { throw new ObjectDisposedException(GetType().FullName); } if (!CanRead) { throw new NotSupportedException("This stream does not support reading"); } if (array == null) { throw new ArgumentNullException("array"); } if (count < 0) { throw new ArgumentOutOfRangeException("count", "Must be >= 0"); } if (offset < 0) { throw new ArgumentOutOfRangeException("offset", "Must be >= 0"); } if (count + offset > array.Length) { throw new ArgumentException("Buffer too small. count/offset wrong."); } ReadMethod r = new ReadMethod(ReadInternal); return(r.BeginInvoke(array, offset, count, asyncCallback, asyncState)); }
public void Init() { Flel.Util.Type.SetDescription<RegisteredClass>("Registered Class"); InputValues.Register<RegisteredClass>(RegisteredClass.Parse); byteReadMethod = InputValues.GetReadMethod<byte>(); values = new byte[] { 78, 0, 255 }; string[] valsAsStrs = Array.ConvertAll(values, new Converter<byte, string>(Convert.ToString)); valuesAsStr = string.Join(" ", valsAsStrs); }
public override IAsyncResult BeginRead (byte [] buffer, int offset, int count, AsyncCallback cback, object state) { if (disposed) throw new ObjectDisposedException (GetType ().FullName); if (!CanRead) throw new NotSupportedException ("This stream does not support reading"); if (buffer == null) throw new ArgumentNullException ("buffer"); if (count < 0) throw new ArgumentOutOfRangeException ("count", "Must be >= 0"); if (offset < 0) throw new ArgumentOutOfRangeException ("offset", "Must be >= 0"); if (count + offset > buffer.Length) throw new ArgumentException ("Buffer too small. count/offset wrong."); ReadMethod r = new ReadMethod (ReadInternal); return r.BeginInvoke (buffer, offset, count, cback, state); }
private static TDataType[] ToArray <TDataType>(ExifDataType dataType, uint length, ReadMethod <TDataType> read) { int dataTypeSize = (int)ExifValue.GetSize(dataType); int arrayLength = (int)length / dataTypeSize; TDataType[] result = new TDataType[arrayLength]; for (int i = 0; i < arrayLength; i++) { result.SetValue(read(), i); } return(result); }
/// <summary> /// Handles reading heartbeats. /// </summary> public override void HandleRead() { var heartBeat = ReadByte(); ReadMethod?.Invoke(heartBeat); }
/// <summary> /// Handles reading version over network. /// </summary> public override void HandleRead() { var trig = ReadInt32(); ReadMethod?.Invoke(trig); }
//--------------------------------------------------------------------- /// <summary> /// Registers a method to read a value of a specific type from a text /// text reader. /// </summary> public static void Register <T>(ReadMethod <T> method) { string typeFullName = typeof(T).FullName; readMethods[typeFullName] = method; }