Exemplo n.º 1
0
 public static IByteDevice Wrap(IByteInDevice inDevice, IByteOutDevice outDevice)
 {
     return(inDevice.NotNull() || outDevice.NotNull() ? new ByteDeviceCombiner(inDevice, outDevice)
     {
         Wrapped = true
     } : null);
 }
Exemplo n.º 2
0
		public virtual bool Close()
		{
			bool result;
			if (result = this.backend.NotNull())
			{
				this.backend.Close();
				this.backend = null;
			}
			return result;
		}
Exemplo n.º 3
0
        public virtual async Tasks.Task <bool> Close()
        {
            bool result;

            if (result = this.inDevice.NotNull() && !this.Wrapped)
            {
                result = await this.inDevice.Close();

                this.inDevice = null;
            }
            if (this.outDevice.NotNull() && !this.Wrapped)
            {
                result = await this.outDevice.Close();

                this.outDevice = null;
            }
            return(result);
        }
Exemplo n.º 4
0
		byte? Next()
		{
			byte? result;
			if (this.nextPosition < this.matchingLength)
				result = this.endMark[this.nextPosition++];
			else if (this.backend.IsNull())
				result = null;
			else
			{
				byte? next = result = this.backend.Read();
				if (next.HasValue && next.Value == this.endMark[0])
				{
					this.nextPosition = 1;
					this.matchingLength = 1;
					while (true)
					{
						if (this.matchingLength < this.endMark.Length)
						{
							while (!(next = this.backend.Peek()).HasValue)
								;
							if (next.Value != this.endMark[this.matchingLength])
								break;
							this.matchingLength++;
							next = this.backend.Read();
						}
						else
						{
							this.matchingLength = 0;
							this.backend = null;
							result = null;
							break;
						}
					}
				}
			}
			return result;
		}
Exemplo n.º 5
0
 public static IByteDevice Open(IByteInDevice inDevice, IByteOutDevice outDevice)
 {
     return(inDevice.NotNull() || outDevice.NotNull() ? new ByteDeviceCombiner(inDevice, outDevice) : null);
 }
Exemplo n.º 6
0
		public virtual bool Close()
		{
			bool result;
			if (result = this.inDevice.NotNull() && !this.Wrapped)
			{
				this.inDevice.Close();
				this.inDevice = null;
			}
			if (this.outDevice.NotNull() && !this.Wrapped)
			{
				result |= this.outDevice.NotNull();
				this.outDevice.Close();
				this.outDevice = null;
			}
			return result;
		}
Exemplo n.º 7
0
		protected ByteDeviceCombiner(IByteInDevice inDevice) :
			this(inDevice, null)
		{
		}
Exemplo n.º 8
0
		public static IByteDevice Wrap(IByteInDevice inDevice)
		{
			return ByteDeviceCombiner.Wrap(inDevice, null);
		}
Exemplo n.º 9
0
		public static IByteDevice Open(IByteInDevice inDevice)
		{
			return ByteDeviceCombiner.Open(inDevice, null);
		}
Exemplo n.º 10
0
		public static Request Parse(IByteInDevice device)
		{
			Request result = new Request();
			string[] firstLine = Request.ReadLine(device).Decode().Join().Split(' ');
			if (firstLine.Length == 3)
			{
				result.Method = firstLine[0].Parse<Method>();
				result.Path = firstLine[1];
				result.Protocol = firstLine[2];
				string line;
				while ((line = Request.ReadLine(device).Decode().Join()).NotEmpty())
				{
					string[] parts = line.Split(new char[] { ':' }, 2);
					result[parts[0].Trim()] = parts[1].Trim();
				}
			}
			return result;
		}
Exemplo n.º 11
0
		protected FixedLengthByteInDevice(IByteInDevice backend, int length)
		{
			this.backend = backend;
			this.length = length;
		}
Exemplo n.º 12
0
 protected ByteDeviceCombiner(IByteInDevice inDevice, IByteOutDevice outDevice)
 {
     this.inDevice  = inDevice;
     this.outDevice = outDevice;
 }
Exemplo n.º 13
0
 protected ByteDeviceCombiner(IByteInDevice inDevice) :
     this(inDevice, null)
 {
 }
Exemplo n.º 14
0
 public static IByteDevice Wrap(IByteInDevice inDevice)
 {
     return(ByteDeviceCombiner.Wrap(inDevice, null));
 }
Exemplo n.º 15
0
		public static bool Write (this IByteOutDevice me, IByteInDevice device)
		{
			return me.Write(device.AsEnumerable());
		}
Exemplo n.º 16
0
		public static IByteInDevice Open(IByteInDevice device, int length)
		{
			return (device.NotNull() && length > 0) ? new FixedLengthByteInDevice(device, length) : null;
		}
Exemplo n.º 17
0
		static Generic.IEnumerable<byte> ReadLine(IByteInDevice device)
		{
			foreach (byte b in device.Read(13, 10))
				if (b != 13 && b != 10)
					yield return b;
		}
Exemplo n.º 18
0
		public Decoder(IByteInDevice backend, System.Text.Encoding encoding)
		{
			this.backend = backend;
			this.encoding = encoding;
			this.queue = this.backend.AsEnumerable().Decode(this.encoding).Cast(c => (char?)c).GetEnumerator();
		}
Exemplo n.º 19
0
 public static Generic.IEnumerator <Tasks.Task <byte?> > GetEnumerator(this IByteInDevice device)
 {
     yield return(device.Read());
 }
Exemplo n.º 20
0
		public bool Close()
		{
			bool result;
			if (result = this.backend.NotNull() && this.backend.Close())
			{
				this.backend = null;
				this.queue = null;
			}
			return result;
		}
Exemplo n.º 21
0
		public static IByteDevice Open(IByteInDevice inDevice, IByteOutDevice outDevice)
		{
			return inDevice.NotNull() || outDevice.NotNull() ? new ByteDeviceCombiner(inDevice, outDevice) : null;
		}
Exemplo n.º 22
0
		public bool Close()
		{
			bool result;
			this.backend = null;
			if (result = this.Closed.NotNull())
			{
				this.Closed();
				this.Closed = null;
			}
			return result;
		}
Exemplo n.º 23
0
		public static IByteDevice Wrap(IByteInDevice inDevice, IByteOutDevice outDevice)
		{
			return inDevice.NotNull() || outDevice.NotNull() ? new ByteDeviceCombiner(inDevice, outDevice) { Wrapped = true } : null;
		}
Exemplo n.º 24
0
		public static IByteInDevice Open(IByteInDevice backend, byte[] endMark)
		{
			return backend.NotNull() ? endMark.NotEmpty() ? new PartialByteInDevice(backend, endMark) : backend : null;
		}
Exemplo n.º 25
0
		protected ByteDeviceCombiner(IByteInDevice inDevice, IByteOutDevice outDevice)
		{
			this.inDevice = inDevice;
			this.outDevice = outDevice;
		}
Exemplo n.º 26
0
		PartialByteInDevice(IByteInDevice backend, byte[] endMark)
		{
			this.backend = backend;
			this.endMark = endMark;
		}
Exemplo n.º 27
0
		public static ByteStream Open(IByteInDevice device)
		{
			return ByteStream.Open(ByteDeviceCombiner.Open(device));
		}
Exemplo n.º 28
0
 public static IByteDevice Open(IByteInDevice inDevice)
 {
     return(ByteDeviceCombiner.Open(inDevice, null));
 }