示例#1
0
        public void SendToken(string host, string connectCode)
        {
            var st = new StartToken {
                ConnectCode = connectCode, Host = host
            };

            OnToken?.Invoke(this, st);
        }
示例#2
0
 private bool ProcessComment(CharReader charReader)
 {
     if (!charReader.PeekLine().StartsWith("%"))
     {
         return(false);
     }
     FlushTokenBuffer();
     OnToken?.Invoke(TokenType.Comment, charReader.ReadLine().Substring(1));
     return(true);
 }
示例#3
0
 public void RegisterMinion()
 {
     var rpcMinion = new RpcBuffer(appName, (msgId, payload) =>
     {
         var serverResponse = "Carbon has a huge pp also this is debug messages.";
         var gotData        = Encoding.UTF8.GetString(payload, 0, payload.Length);
         Console.WriteLine($"RPCMinion: Got data: {gotData}");
         OnToken?.Invoke(this, StartToken.FromString(gotData)); //Invoke method and return.
         return(Encoding.UTF8.GetBytes(serverResponse));
     });
 }
示例#4
0
 private bool ProcessProcedure(CharReader charReader)
 {
     if (charReader.PeekChar() == '{')
     {
         FlushTokenBuffer();
         charReader.ReadChar();
         OnToken?.Invoke(TokenType.BeginProcedure, "");
         return(true);
     }
     if (charReader.PeekChar() == '}')
     {
         FlushTokenBuffer();
         charReader.ReadChar();
         OnToken?.Invoke(TokenType.EndProcedure, "");
         return(true);
     }
     return(false);
 }
示例#5
0
 private bool ProcessArray(CharReader charReader)
 {
     if (charReader.PeekChar() == '[')
     {
         FlushTokenBuffer();
         charReader.ReadChar();
         OnToken?.Invoke(TokenType.BeginArray, "");
         return(true);
     }
     if (charReader.PeekChar() == ']')
     {
         FlushTokenBuffer();
         charReader.ReadChar();
         OnToken?.Invoke(TokenType.EndArray, "");
         return(true);
     }
     return(false);
 }
示例#6
0
 private bool ProcessDictionary(CharReader charReader)
 {
     if (charReader.PeekString(2) == "<<")
     {
         FlushTokenBuffer();
         charReader.ReadString(2);
         OnToken?.Invoke(TokenType.BeginDictionary, "");
         return(true);
     }
     if (charReader.PeekString(2) == ">>")
     {
         FlushTokenBuffer();
         charReader.ReadString(2);
         OnToken?.Invoke(TokenType.EndDictionary, "");
         return(true);
     }
     return(false);
 }
示例#7
0
 private void FlushTokenBuffer()
 {
     if (_stringBuilder.Length > 0)
     {
         var value = _stringBuilder.ToString();
         if (long.TryParse(value, out _))
         {
             OnToken?.Invoke(TokenType.Integer, value);
         }
         else if (float.TryParse(value, out _))
         {
             OnToken?.Invoke(TokenType.Real, value);
         }
         else
         {
             OnToken?.Invoke(TokenType.Name, value);
         }
         _stringBuilder.Clear();
     }
 }
示例#8
0
        private Token RequestToken(string url)
        {
            using (WebClient client = new WebClient())
            {
                try
                {
                    var json      = client.DownloadString(url);
                    var aResponse = JsonConvert.DeserializeObject <AbstractResponse>(json);

                    if (aResponse is Response response)
                    {
                        var message = $"Error {response.Status}: {response.Message}";
                        OnError?.Invoke(this, new TokenErrorArgs {
                            Message = message
                        });
                        return(null);
                    }
                    else
                    {
                        var token = aResponse as Token;
                        OnToken?.Invoke(this, new TokenArgs {
                            Token = token
                        });
                        return(token);
                    }
                }
                catch (WebException e)
                {
                    HttpWebResponse response = (HttpWebResponse)e.Response;

                    OnError?.Invoke(this, new TokenErrorArgs {
                        Message = response.StatusCode.ToString()
                    });
                    return(null);
                }
            }
        }
示例#9
0
        private bool ProcessXPacket(CharReader charReader)
        {
            if (!charReader.PeekLine().Equals("<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>"))
            {
                return(false);
            }
            FlushTokenBuffer();
            charReader.ReadLine();
            var textBuilder = new StringBuilder();

            while (true)
            {
                var line = charReader.ReadLine();
                if (line.Equals("<?xpacket end=\"w\"?>"))
                {
                    OnToken?.Invoke(TokenType.XPacket, textBuilder.ToString());
                    return(true);
                }
                else if (!string.IsNullOrEmpty(line))
                {
                    textBuilder.AppendLine(line);
                }
            }
        }
示例#10
0
        private bool ProcessHexString(CharReader charReader)
        {
            if (charReader.PeekChar() != '<')
            {
                return(false);
            }
            FlushTokenBuffer();
            charReader.ReadChar();
            var textBuilder = new StringBuilder();

            while (true)
            {
                var character = charReader.ReadChar();
                if (character == '>')
                {
                    OnToken?.Invoke(TokenType.HexString, textBuilder.ToString());
                    return(true);
                }
                else if (character == '\0')
                {
                    throw new Exception("Unexpected end of data.");
                }
                else if (IsBaseX(character, 16))
                {
                    textBuilder.Append(character);
                }
                else if (IsWhitespace(character))
                {
                    // Skip new line
                }
                else
                {
                    throw new Exception("Invalid hex charcter.");
                }
            }
        }
示例#11
0
        public void RunLoop(string initialURI)
        {
            if (initialURI != null)
            {
                OnToken?.Invoke(this, StartToken.FromString(initialURI));
            }
            while (true)
            {
                PipeSecurity ps = new PipeSecurity();

                ps.AddAccessRule(new PipeAccessRule("Users", PipeAccessRights.FullControl, System.Security.AccessControl.AccessControlType.Allow));

                NamedPipeServerStream pipeServer = NamedPipeServerStreamConstructors.New("AmongUsCapturePipe", PipeDirection.InOut, 1, pipeSecurity: ps);

                pipeServer.WaitForConnection();
                Console.WriteLine("Client connected");
                try
                {
                    //Read the request from the client. Once the client has
                    // written to the pipe its security token will be available.
                    StreamString ss = new StreamString(pipeServer);

                    string     rawToken   = ss.ReadString();
                    StartToken startToken = StartToken.FromString(rawToken);
                    Console.WriteLine($@"Decoded message as {JsonConvert.SerializeObject(startToken, Formatting.Indented)}");
                    OnToken?.Invoke(this, startToken);
                }
                // Catch the IOException that is raised if the pipe is broken
                // or disconnected.
                catch (IOException e)
                {
                    Console.WriteLine(@"ERROR: {0}", e.Message);
                }
                pipeServer.Close();
            }
        }
示例#12
0
        private bool ProcessString(CharReader charReader)
        {
            if (charReader.PeekChar() != '(')
            {
                return(false);
            }
            int bracketCount = 1;

            FlushTokenBuffer();
            charReader.ReadChar();
            var textBuilder = new StringBuilder();

            while (true)
            {
                var character = charReader.ReadChar();
                if (character == '\\')
                {
                    var peekedChar = charReader.PeekChar();
                    if (IsBaseX(peekedChar, 8))
                    {
                        var octalString = GetOctalString(charReader);
                        textBuilder.Append(octalString);
                        continue;
                    }
                    if (peekedChar == '\\' || peekedChar == '(' || peekedChar == ')')
                    {
                        textBuilder.Append(charReader.ReadChar());
                        continue;
                    }
                    if (peekedChar == 'n')
                    {
                        charReader.ReadChar();
                        textBuilder.Append('\n');
                        continue;
                    }
                    if (peekedChar == 'r')
                    {
                        charReader.ReadChar();
                        textBuilder.Append('\r');
                        continue;
                    }
                    if (peekedChar == 't')
                    {
                        charReader.ReadChar();
                        textBuilder.Append('\t');
                        continue;
                    }
                    if (peekedChar == 'b')
                    {
                        charReader.ReadChar();
                        textBuilder.Append('\b');
                        continue;
                    }
                    if (peekedChar == 'f')
                    {
                        charReader.ReadChar();
                        textBuilder.Append('\f');
                        continue;
                    }
                    throw new Exception("Unexpected escape code.");
                }
                else if (character == '(')
                {
                    bracketCount++;
                }
                else if (character == ')' && bracketCount > 1)
                {
                    bracketCount--;
                }
                else if (character == ')' && bracketCount == 1)
                {
                    OnToken?.Invoke(TokenType.String, textBuilder.ToString());
                    return(true);
                }
                else if (character == '\0')
                {
                    throw new Exception("Unexpected end of data.");
                }
                textBuilder.Append(character);
            }
        }
示例#13
0
 protected virtual void OnTokenEvent(StartToken e)
 {
     // Safely raise the event for all subscribers
     OnToken?.Invoke(this, e);
 }
示例#14
0
 public void startWithToken(string uri)
 {
     OnToken?.Invoke(this, StartToken.FromString(uri));
 }