public WebHookEngine(RoomieEngine roomieController, string computerName, string communicationUrl, string accessKey, string encryptionKey) { this.roomieController = roomieController; this.computerName = computerName; this.communicationUrl = communicationUrl; this.accessKey = accessKey; this.encryptionKey = encryptionKey; //TODO: reintroduce multiple webhook engines? string threadPoolName = "Web Hook (to " + communicationUrl + ")"; //int engineCount = Common.GetWebHookEngines(this.roomieController).Count; //if (engineCount > 0) // threadPoolName += "(" + engineCount + ")"; this.threadPool = roomieController.CreateThreadPool(threadPoolName); this.running = false; communicator = new WebCommunicator.CommunicatorClient(communicationUrl, accessKey, encryptionKey); bool serverFound = false; while (!serverFound) { try { print("pinging Webhook server at " + communicationUrl + "..."); Message pingResponse = communicator.PingServer(); //TODO: should we look at the result? print("Webhook server found!"); serverFound = true; } catch (CommunicationException exception) { print("Error contacting server: " + exception.Message); System.Threading.Thread.Sleep(new TimeSpan(0, 0, 10)); } } ////initialize connection //Dictionary<string, string> sendValues = new Dictionary<string, string>(1); //sendValues.Add("action", "start session"); //sendValues.Add("ComputerName", computerName); //SecureHttpCommunication.RecievedPackage package = SendMessage(sendValues, null); //if (package.HasErrorMessage) // throw new ScriptException("Error starting webhook session"); //foreach (SecureHttpCommunication.Message message in package) //{ // if (message.ContainsParameter("NewSessionToken")) // sessionToken = message.GetValue("NewSessionToken"); // break; //} //if (String.IsNullOrEmpty(sessionToken)) // throw new ScriptException("Did not recieve a new SessionID"); //print("Webhook Session Token: " + sessionToken); events = new Queue<OutputEvent>(); //TODO: make this work! //this.roomieController.ScriptMessageSent += new Scope scopeScriptMessageEventHandler(roomieController_ScriptMessageSent); }
static void TestDreamingnestPing() { var client = new CommunicatorClient("http://" + host + "/communicator/", "4241084ebc474b35", "916fa93f32134cf2"); var response = client.PingServer(); Console.WriteLine(response); }
static void TestMessage(Message message, string address, string accessKey, string encryptionKey = null) { WriteDivider(); Console.WriteLine(message); WriteDivider(); var client = new CommunicatorClient ( url: address, accessKey: accessKey, encryptionKey: encryptionKey ); Console.WriteLine("Sending message..."); var response = client.SendMessage(message, encryptionKey != null, 1); Console.WriteLine(response.ToString()); WriteDivider(); }
static void Main(string[] args) { byte[] lul = Encoding.UTF8.GetBytes("<"); Console.WriteLine("I am the client!"); WebCommunicator.StreamUtilities.RunCryptoSanityCheck(); Console.WriteLine("\tpassed crypto sanity check."); byte[] key = StreamUtilities.StringToByteArray("0123456789abcdef"); client = new CommunicatorClient("http://localhost:1337", "user_1_key", key); Message message1 = new Message(); message1.Values.Add("Action", "Time?"); send(message1); Message message2 = new Message(); message2.Values.Add("Action", "Write"); message2.Values.Add("Text", "Hello from over the network!"); send(message2); Console.ReadKey(); }