Exemplo n.º 1
0
        public static void UnregisterWithAws(string id)
        {
            string jsonRequest = new JavaScriptSerializer().Serialize(new
            {
                Key = new
                {
                    id = new { S = id }
                },
                TableName = "flingrMap"
            });

            AwsRequest.RequestPut("/FlingrRegistration", "", jsonRequest);
        }
Exemplo n.º 2
0
        private const string secretKey     = "sorry, private";                                      // (Can we store this somewhere safer? XD)

        public static string RegisterWithAws(string remoteIp, string remotePort, string localIp, string localPort)
        {
            string jsonRequest = new JavaScriptSerializer().Serialize(new
            {
                Item = new
                {
                    ipAddr  = new { S = remoteIp },
                    wanPort = new { S = remotePort },
                    lanAddr = new { S = localIp },
                    lanPort = new { S = localPort }
                },
                TableName = "flingrMap"
            });

            WebRequest request = AwsRequest.RequestPut("/FlingrRegistration", "", jsonRequest);

            string responseJson = null;

            try
            {
                using (WebResponse response = request.GetResponse())
                {
                    StreamReader responseReader = new StreamReader(response.GetResponseStream());
                    responseJson = responseReader.ReadToEnd();
                }
            }
            catch (WebException error)
            {
                Console.WriteLine(error.Message);
                StreamReader responseReader = new StreamReader(error.Response.GetResponseStream());
                responseJson = responseReader.ReadToEnd();
            }

            AwsJsonObject jsonObj = JsonConvert.DeserializeObject <AwsJsonObject>(responseJson);

            if (jsonObj != null && jsonObj.Item != null && jsonObj.Item.id != null && jsonObj.Item.id.S != null)
            {
                return(jsonObj.Item.id.S);
            }

            return(null);
        }
Exemplo n.º 3
0
        /*
         * This ONLY goes inside of a thread.
         */
        private void RegisterWithAws()
        {
            while (true)
            {
                string keyword = AwsRequest.RegisterWithAws(
                    controller.GetRemoteIp(),
                    controller.GetRemotePort().ToString(),
                    controller.GetLocalIp(),
                    controller.GetLocalPort().ToString());

                if (!string.IsNullOrEmpty(keyword))
                {
                    // Present the ID to the user in the GUI
                    Dispatcher.Invoke(new Action(() => {
                        currentId = keyword;
                        ConnectionStatusLabel.Content = keyword;
                    }));
                }

                Thread.Sleep(180100);
            }
        }