예제 #1
0
        public static void MakeRequest(string requestUrl, string data,
                ReplyDelegate action)
        {
            ServicePointManagerTimeoutSupport.ResetHosts();
            WebRequest request = WebRequest.Create(requestUrl);

            request.Method = "POST";

            request.ContentType = "application/x-www-form-urlencoded";

            byte[] buffer = Encoding.ASCII.GetBytes(data);
            int length = (int) buffer.Length;
            request.ContentLength = length;

            request.BeginGetRequestStream(delegate(IAsyncResult res)
            {
                Stream requestStream = request.EndGetRequestStream(res);

                requestStream.Write(buffer, 0, length);

                request.BeginGetResponse(delegate(IAsyncResult ar)
                {
                    string reply = String.Empty;

                    using (WebResponse response = request.EndGetResponse(ar))
                    {
                        try
                        {
                            using (Stream s = response.GetResponseStream())
                                using (StreamReader r = new StreamReader(s))
                                    reply = r.ReadToEnd();

                        }
                        catch (System.InvalidOperationException)
                        {
                        }
                    }

                    action(requestUrl, data, reply);
                }, null);
            }, null);
        }
예제 #2
0
        public static void MakeRequest(string requestUrl, string data,
                ReplyDelegate action)
        {
            WebRequest request = WebRequest.Create(requestUrl);
            WebResponse response = null;

            request.Method = "POST";

            request.ContentType = "application/x-www-form-urlencoded";

            byte[] buffer = new System.Text.ASCIIEncoding().GetBytes(data);
            int length = (int) buffer.Length;
            request.ContentLength = length;

            request.BeginGetRequestStream(delegate(IAsyncResult res)
            {
                Stream requestStream = request.EndGetRequestStream(res);

                requestStream.Write(buffer, 0, length);

                request.BeginGetResponse(delegate(IAsyncResult ar)
                {
                    string reply = String.Empty;

                    response = request.EndGetResponse(ar);

                    try
                    {
                        StreamReader r = new StreamReader(response.GetResponseStream());
                        reply = r.ReadToEnd();

                    }
                    catch (System.InvalidOperationException)
                    {
                    }

                    action(requestUrl, data, reply);
                }, null);
            }, null);
        }
예제 #3
0
 public FormPoster(string base_url, string rel_url, Dictionary<string, string> parameters)
 {
   this.BaseUrl = base_url;
   this.Parameters = parameters;
   this.Reply = new ReplyDelegate((rep) => { });
   this.RelUrl = rel_url;
   this.PostForm();
 }
예제 #4
0
 /// <summary>
 /// Posts a counter increment to stathat over HTTP using ez API - the stat and/or you don't have to be pre-registered
 /// </summary>
 /// <param name="ezkey">your ezkey (defaults to email address).  If you already have a stathat account, use the one associated with it.</param>
 /// <param name="stat">the name for your stat</param>
 /// <param name="count">the number</param>
 /// <param name="replyDelegate">the function you'd like called with the reply from stathat's server</param>
 public static void EzValue(string ezkey, string stat, int value, ReplyDelegate replyDelegate)
 {
   Post.EzValue(ezkey, stat, (float)value, replyDelegate);
 }
예제 #5
0
 /// <summary>
 /// Posts a counter increment to stathat over HTTP using ez API - the stat and/or you don't have to be pre-registered
 /// </summary>
 /// <param name="ezkey">your ezkey (defaults to email address).  If you already have a stathat account, use the one associated with it.</param>
 /// <param name="stat">the name for your stat</param>
 /// <param name="count">the number</param>
 /// <param name="replyDelegate">the function you'd like called with the reply from stathat's server</param>
 public static void EzValue(string ezkey, string stat, float value, ReplyDelegate replyDelegate)
 {
   Dictionary<string, string> p = new Dictionary<string, string>();
   p.Add("ezkey", ezkey);
   p.Add("stat", stat);
   p.Add("value", value.ToString());
   new FormPoster(Post.BaseUrl, "/ez", p, replyDelegate);
 }
예제 #6
0
 /// <summary>
 /// Posts a counter increment to stathat over HTTP using ez API - the stat and/or you don't have to be pre-registered
 /// </summary>
 /// <param name="ezkey">your ezkey (defaults to email address).  If you already have a stathat account, use the one associated with it.</param>
 /// <param name="stat">the name for your stat</param>
 /// <param name="count">the number to increment</param>
 /// <param name="replyDelegate">the function you'd like called with the reply from stathat's server</param>
 public static void EzCounter(string ezkey, string stat, int count, ReplyDelegate replyDelegate)
 {
   Post.EzCounter(ezkey, stat, (float)count, replyDelegate);
 }
예제 #7
0
 /// <summary>
 /// Posts a counter increment to stathat over HTTP using ez API - the stat and/or you don't have to be pre-registered
 /// </summary>
 /// <param name="ezkey">your ezkey (defaults to email address).  If you already have a stathat account, use the one associated with it.</param>
 /// <param name="stat">the name for your stat</param>
 /// <param name="count">the number to increment</param>
 /// <param name="replyDelegate">the function you'd like called with the reply from stathat's server</param>
 public static void EzCounter(string ezkey, string stat, float count, ReplyDelegate replyDelegate)
 {
   Dictionary<string, string> p = new Dictionary<string, string>();
   p.Add("ezkey", ezkey);
   p.Add("stat", stat);
   p.Add("count", count.ToString());
   new FormPoster(Post.BaseUrl, "/ez", p, replyDelegate);
 }
예제 #8
0
 /// <summary>
 /// Posts a value to stathat over HTTP
 /// </summary>
 /// <param name="key">the stat's posting key</param>
 /// <param name="ukey">your user key</param>
 /// <param name="value">the number</param>
 /// <param name="replyDelegate">the function you'd like called with the reply from stathat's server</param>
 public static void Value(string key, string ukey, int value, ReplyDelegate replyDelegate)
 {
   Post.Value(key, ukey, (float)value, replyDelegate);
 }
예제 #9
0
 /// <summary>
 /// Posts a value to stathat over HTTP
 /// </summary>
 /// <param name="key">the stat's posting key</param>
 /// <param name="ukey">your user key</param>
 /// <param name="value">the number</param>
 /// <param name="replyDelegate">the function you'd like called with the reply from stathat's server</param>
 public static void Value(string key, string ukey, float value, ReplyDelegate replyDelegate)
 {
   Dictionary<string, string> p = new Dictionary<string, string>();
   p.Add("key", key);
   p.Add("ukey", ukey);
   p.Add("value", value.ToString());
   new FormPoster(Post.BaseUrl, "/v", p, replyDelegate);
 }
예제 #10
0
    /// <summary>
    /// Posts a counter increment to stathat over HTTP
    /// </summary>
    /// <param name="key">the stat's posting key</param>
    /// <param name="ukey">your user key</param>
    /// <param name="count">the number to increment</param>
    /// <param name="replyDelegate">the function you'd like called with the reply from stathat's server</param>
    public static void Counter(string key, string ukey, int count, ReplyDelegate replyDelegate)
    {
      Post.Counter(key, ukey, (float)count, replyDelegate);

    }
예제 #11
0
 /// <summary>
 /// Posts a counter increment to stathat over HTTP
 /// </summary>
 /// <param name="key">the stat's posting key</param>
 /// <param name="ukey">your user key</param>
 /// <param name="count">the number to increment</param>
 /// <param name="replyDelegate">the function you'd like called with the reply from stathat's server</param>
 public static void Counter(string key, string ukey, float count, ReplyDelegate replyDelegate)
 {
   Dictionary<string, string> p = new Dictionary<string, string>();
   p.Add("key", key);
   p.Add("ukey", ukey);
   p.Add("count", count.ToString());
   new FormPoster(Post.BaseUrl, "/c", p, replyDelegate);
 }
예제 #12
0
        public NXTCommand(byte[] c, byte[] r, ReplyDelegate del = null)
        {
            command = c;// new byte[c.Length];
            reply = r;// new byte[r.Length];

            commandType = command[0];
            commandCode = command[1];

            replyDelegate = del;
            ///Array.Copy(c, this.command, c.Length);
            //Array.Copy(r, this.reply, r.Length);
        }