コード例 #1
0
        private void HandleParsedLineReceived(ParsedLineEventArgs parsedLine)
        {
            this.OnParsedLineReceived(parsedLine);
            if (parsedLine.PreventProcessing)
            {
                return;
            }
            var eventArgs = new ParameterEventReceivedEventArgs(parsedLine.Parameter, parsedLine.Id);

            this.Events[parsedLine.Command].OnEvent(eventArgs);
            if (eventArgs.PreventProcessing)
            {
                return;
            }

            if (parsedLine.Command == "_")
            {
                this.OnAnswerReceived(parsedLine);
                if (parsedLine.PreventProcessing)
                {
                    return;
                }
                List <Action <ParsedLineEventArgs> > onAnswerList;
                if (this.onAnswerDelegates.TryGetValue(parsedLine.Id, out onAnswerList))
                {
                    foreach (var action in onAnswerList)
                    {
                        action.BeginInvoke(parsedLine, null, null);
                    }
                }
            }
        }
コード例 #2
0
 public SendPacket(byte[] bytesToSend, ParsedLineEventArgs eventArgs, Stream rawData, MessageServerClient client, bool disposeStream, long toSend)
 {
     this.BytesToSend   = bytesToSend;
     this.EventArgs     = eventArgs;
     this.RawData       = rawData;
     this.Client        = client;
     this.DisposeStream = disposeStream;
     this.ToSend        = toSend;
 }
コード例 #3
0
        private void OnParsedLineReceived(ParsedLineEventArgs e)
        {
            EventHandler <ParsedLineEventArgs> handler = this.ParsedLineReceived;

            if (handler != null)
            {
                handler(this, e);
            }
        }
コード例 #4
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();
                }
            }
        }
コード例 #5
0
        private void HandleRawLine(RawLineReceivedEventArgs lineEvent)
        {
            try
            {
                string line      = lineEvent.RawLine.Line;
                var    rawLineId = lineEvent.RawLine.Id;
                Logger.WriteLine("Received: {0}, with {1}", TraceEventType.Information, line, rawLineId);

                this.OnRawLineReceived(lineEvent);
                if (lineEvent.PreventProcessing)
                {
                    return;
                }
                ParsedLineEventArgs parsedLine;
                string afterId      = line;
                int    secoundSpace = this.FindFirstSeparatingSpace(afterId);
                if (secoundSpace == -1)
                {
                    throw new RawLineFormatException("The Raw line doesn't contain a secound separation space");
                }
                string command   = afterId.Substring(0, secoundSpace);
                string parameter = afterId.Substring(secoundSpace + 1);
                command   = UnEscapeString(command);
                parameter = UnEscapeString(parameter);

                parsedLine = new ParsedLineEventArgs(
                    rawLineId, command, new StringParameter(parameter), lineEvent.RawLine.RawData);

                this.HandleParsedLineReceived(parsedLine);
            }
            catch (RawLineFormatException e)
            {
                Logger.WriteLine("Received Invalid Line... Disconnecting: {0}", TraceEventType.Error, e);
                this.HandleDisconnect();
            }
            catch (Exception e)
            {
                this.HandleUnknownException(e);
            }
        }
コード例 #6
0
 public SendPacket(byte[] bytesToSend, ParsedLineEventArgs eventArgs, Stream rawData, MessageServerClient client, bool disposeStream, long toSend)
 {
     this.BytesToSend = bytesToSend;
     this.EventArgs = eventArgs;
     this.RawData = rawData;
     this.Client = client;
     this.DisposeStream = disposeStream;
     this.ToSend = toSend;
 }
コード例 #7
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();
                }
            }
        }
コード例 #8
0
 private void OnParsedLineSend(ParsedLineEventArgs e)
 {
     EventHandler<ParsedLineEventArgs> handler = this.ParsedLineSend;
     if (handler != null)
     {
         handler(this, e);
     }
 }
コード例 #9
0
 private void OnAnswerReceived(ParsedLineEventArgs e)
 {
     EventHandler<ParsedLineEventArgs> handler = this.AnswerReceived;
     if (handler != null)
     {
         handler(this, e);
     }
 }
コード例 #10
0
        private void HandleRawLine(RawLineReceivedEventArgs lineEvent)
        {
            try
            {
                string line = lineEvent.RawLine.Line;
                var rawLineId = lineEvent.RawLine.Id;
                Logger.WriteLine("Received: {0}, with {1}", TraceEventType.Information, line, rawLineId);

                this.OnRawLineReceived(lineEvent);
                if (lineEvent.PreventProcessing)
                {
                    return;
                }
                ParsedLineEventArgs parsedLine;
                string afterId = line;
                int secoundSpace = this.FindFirstSeparatingSpace(afterId);
                if (secoundSpace == -1)
                {
                    throw new RawLineFormatException("The Raw line doesn't contain a secound separation space");
                }
                string command = afterId.Substring(0, secoundSpace);
                string parameter = afterId.Substring(secoundSpace + 1);
                command = UnEscapeString(command);
                parameter = UnEscapeString(parameter);

                parsedLine = new ParsedLineEventArgs(
                    rawLineId, command, new StringParameter(parameter), lineEvent.RawLine.RawData);

                this.HandleParsedLineReceived(parsedLine);
            }
            catch (RawLineFormatException e)
            {
                Logger.WriteLine("Received Invalid Line... Disconnecting: {0}", TraceEventType.Error, e);
                this.HandleDisconnect();
            }
            catch (Exception e)
            {
                this.HandleUnknownException(e);
            }
        }
コード例 #11
0
        private void HandleParsedLineReceived(ParsedLineEventArgs parsedLine)
        {
            this.OnParsedLineReceived(parsedLine);
            if (parsedLine.PreventProcessing)
            {
                return;
            }
            var eventArgs = new ParameterEventReceivedEventArgs(parsedLine.Parameter, parsedLine.Id);
            this.Events[parsedLine.Command].OnEvent(eventArgs);
            if (eventArgs.PreventProcessing)
            {
                return;
            }

            if (parsedLine.Command == "_")
            {
                this.OnAnswerReceived(parsedLine);
                if (parsedLine.PreventProcessing)
                {
                    return;
                }
                List<Action<ParsedLineEventArgs>> onAnswerList;
                if (this.onAnswerDelegates.TryGetValue(parsedLine.Id, out onAnswerList))
                {
                    foreach (var action in onAnswerList)
                    {
                        action.BeginInvoke(parsedLine, null, null);
                    }
                }
            }
        }