FreeMoney.BitcoinNotificationService.CreateAgent C# (CSharp) Method

CreateAgent() private method

private CreateAgent ( string agent_name ) : bool
agent_name string
return bool
        private bool CreateAgent(string agent_name)
        {
            m_log.Info("[FreeMoney] Creating an agent with the notification service with the name "+agent_name);

            string data = "name="+agent_name
                + "&watch_type=2";

            //string useragent = "Bitcoin payment module for OpenSim - https://github.com/edmundedgar/Mod-Bitcoin";

            string url = m_config["bitcoin_ping_service_1_base_url"]+"/";
            Console.WriteLine(url);

            HttpWebRequest httpWebRequest=(HttpWebRequest)WebRequest.Create(url);
            httpWebRequest.Headers.Add("Authorization: "+ m_config["bitcoin_ping_service_1_accesskey"]);
            httpWebRequest.Method = "POST";

            ASCIIEncoding encoding = new ASCIIEncoding ();
            byte[] byte1 = encoding.GetBytes (data);

            //httpWebRequest.ContentType = "application/x-www-form-urlencoded";
            httpWebRequest.ContentLength = byte1.Length;

            Stream newStream = httpWebRequest.GetRequestStream ();
            newStream.Write (byte1, 0, byte1.Length);
            newStream.Close();

            HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse ();
            string response;
            using (StreamReader streamReader = new StreamReader (httpWebResponse.GetResponseStream ())) {
                response = streamReader.ReadToEnd ();
                streamReader.Close ();
            }
            Console.WriteLine(response);

            if (httpWebResponse.StatusCode != HttpStatusCode.OK) {
                m_log.Warn("[FreeMoney] Got a bad status code from the notification service when trying to set up a notification agent.");
                return false;
            }

            try {

                JArray agent = (JArray)JArray.Parse(response);
                if ( (string)agent["id"] != "" ) {
                    m_agent_id = agent["id"].ToString();
                    m_log.Info("[FreeMoney] Using the agent ID "+m_agent_id+". Set this in the config to make transactions faster.");
                    return true;
                }

            } catch (Exception e) {

                m_log.Warn("[FreeMoney] Could not parse response when trying to set up a notification agent.");
                //Console.WriteLine("Parsing of creation attempt failed.");
                //Console.WriteLine(e.ToString());
                //Console.WriteLine(response);

            }

            return false;
        }