Exemplo n.º 1
0
 public ParsedLineEventArgs(RawLineId id, string command, StringParameter parameter, Stream rawData)
 {
     this.Id = id;
     this.Command = command;
     this.Parameter = parameter;
     this.RawData = rawData;
 }
 public ParameterEventReceivedEventArgs(StringParameter parameter, RawLineId id)
 {
     this.Parameter = parameter;
     this.Id = id;
 }
Exemplo n.º 3
0
        private void SendCommandAsyncPrivate(RawLineId id, string command, StringParameter messageParameter = null, Stream rawData = null, Action<ParsedLineEventArgs> onAnswer = null, bool disposeStream = false, long bytesToSend = -1)
        {
            var eventArgs = new ParsedLineEventArgs(id, command, messageParameter, rawData);
            if (onAnswer != null)
            {
                List<Action<ParsedLineEventArgs>> delList;
                if (!this.onAnswerDelegates.TryGetValue(id, out delList))
                {
                    delList = new List<Action<ParsedLineEventArgs>>();
                    this.onAnswerDelegates.Add(id, delList);
                }
                delList.Add(onAnswer);
            }

            command = EscapeString(command);
            var parameterString = EscapeString(messageParameter == null ? "" : messageParameter.Parameter);
            if (rawData != null && bytesToSend == -1)
            {
                bytesToSend = rawData.Length - rawData.Position;
            }

            string rawDataString = rawData == null ? string.Empty : string.Format(" RAWDATA {0}", bytesToSend);
            string commandLine = string.Format("{0} {1}{2}", command, parameterString, rawDataString);
            Logger.WriteLine("Sending: {0}, with {1}", TraceEventType.Information, commandLine, id);
            byte[] commandBytes = this.encoding.GetBytes(commandLine + "\0");
            byte[] idBytes = id.GetIdBytes();

            var completeCommandBytes = new byte[commandBytes.Length + idBytes.Length + 1];
            Array.Copy(idBytes, 0, completeCommandBytes, 0, idBytes.Length);
            completeCommandBytes[idBytes.Length] = 0x20; // Code for Space
            Array.Copy(commandBytes, 0, completeCommandBytes, idBytes.Length + 1, commandBytes.Length);

            this.EnqueuePacket(
                new SendPacket(completeCommandBytes, eventArgs, rawData, this, disposeStream, bytesToSend));
            lock (this.sendSync)
            {
                if (this.currentPacket == null)
                {
                    this.SendNextPacket();
                }
            }
        }
Exemplo n.º 4
0
        public void SendCommandAsync(
            string command, 
            StringParameter parameter, 
            Stream rawData = null, 
            Action<ParsedLineEventArgs> onAnswer = null,
            bool disposeStream = false, long dataLengthToSend = -1)
        {
            RawLineId id;
            lock (this.idLock)
            {
                id = this.sendCounter;
                this.sendCounter = this.sendCounter.Inc();
            }

            this.SendCommandAsyncPrivate(id, command, parameter, rawData, onAnswer, disposeStream, dataLengthToSend);
        }
Exemplo n.º 5
0
 public void SendAnswer(
     RawLineId id, StringParameter parameter, Stream rawData = null, Action<ParsedLineEventArgs> onAnswer = null, bool disposeStream = false, long dataLengthToSend = -1)
 {
     this.SendCommandAsyncPrivate(id, "_", parameter, rawData, onAnswer, disposeStream, dataLengthToSend);
 }