예제 #1
0
        //---------------------------------------------------------------------

        private T ReadValue <T>()
        {
            ReadMethod <T> method = InputValues.GetReadMethod <T>();
            int            index;

            return(method(currentLine, out index));
        }
예제 #2
0
        /// <summary>
        /// Handles reading pending project packets.
        /// </summary>
        public override void HandleRead()
        {
            var magicNumber = ReadByte();


            ReadMethod?.Invoke(magicNumber);
        }
예제 #3
0
        /// <summary>
        /// Handles reading caliber packets.
        /// </summary>
        public override void HandleRead()
        {
            var caliberRequest = ReadBoolean();


            ReadMethod?.Invoke(caliberRequest);
        }
예제 #4
0
        /// <summary>
        /// Handles an error message packets.
        /// </summary>
        public override void HandleRead()
        {
            var errorCode = ReadByte();


            ReadMethod?.Invoke(errorCode);
        }
예제 #5
0
        /// <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));
        }
예제 #6
0
 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);
     }
 }
예제 #7
0
        //---------------------------------------------------------------------

        ///    <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);
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Handles reading caliber packets.
        /// </summary>
        public override void HandleRead()
        {
            var caliberCount = ReadInt32();


            ReadMethod?.Invoke(caliberCount);
        }
예제 #9
0
        /// <summary>
        /// Handles reading project packets.
        /// </summary>
        public override void HandleRead()
        {
            var shouldStart = ReadBoolean();


            ReadMethod?.Invoke(shouldStart);
        }
예제 #10
0
        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);
                }
            }
        }
예제 #11
0
        /// <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;
        }
예제 #13
0
        /// <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);
        }
예제 #14
0
 public void GetReadMethod_UnregisteredType()
 {
     try {
         ReadMethod <UnregisteredClass> readMethod =
             InputValues.GetReadMethod <UnregisteredClass>();
     }
     catch (Exception exc) {
         Data.Output.WriteLine(exc.Message);
         throw;
     }
 }
예제 #15
0
 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;
     }
 }
예제 #16
0
        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);
            }
        }
예제 #21
0
        /// <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));
        }
예제 #22
0
        /// <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));
        }
예제 #23
0
        //---------------------------------------------------------------------

        /// <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));
        }
예제 #24
0
        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);
        }
예제 #26
0
		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);
		}
예제 #27
0
        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);
        }
예제 #28
0
        /// <summary>
        /// Handles reading heartbeats.
        /// </summary>
        public override void HandleRead()
        {
            var heartBeat = ReadByte();

            ReadMethod?.Invoke(heartBeat);
        }
예제 #29
0
        /// <summary>
        /// Handles reading version over network.
        /// </summary>
        public override void HandleRead()
        {
            var trig = ReadInt32();

            ReadMethod?.Invoke(trig);
        }
예제 #30
0
        //---------------------------------------------------------------------

        /// <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;
        }