Ejemplo n.º 1
0
 void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
 {
     if (e.Error == null)
     {
         RESTJsonFetched(sender, new RestEventArgs(e.Result, _callbackKey));
     }
     else
     {
         RestError re = new RestError("Error fetching " + _callbackKey, e.Error.Message.ToString());
         re.ReturnKey = _callbackKey;
         RestErrorEventArgs evg = new RestErrorEventArgs(re);
         RESTJsonError(sender, evg);
     }
 }
Ejemplo n.º 2
0
 private void Client_UploadDataCompleted(object sender, UploadDataCompletedEventArgs e)
 {
     if (e.Error == null)
     {
         string json = System.Text.Encoding.Default.GetString(e.Result);
         RESTJsonFetched(sender, new RestEventArgs(json, _callbackKey));
     }
     else
     {
         RestError re = new RestError("Error fetching " + _callbackKey, e.Error.Message.ToString());
         re.ReturnKey = _callbackKey;
         RestErrorEventArgs evg = new RestErrorEventArgs(re);
         RESTJsonError(sender, evg);
     }
 }
Ejemplo n.º 3
0
        protected virtual void ExecuteRestGetAsynch(string completeUrl)
        {
            //needed for SSL
            System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
            System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, cert, chain, errors) => cert.Subject.ToUpper().Contains(_certificateSubject));
            ServicePointManager.ServerCertificateValidationCallback           += new RemoteCertificateValidationCallback(ValidateRemoteCertificate);


            if (CanPingServices() == false)
            {
                RestError re = new RestError("Connection Error", "A connection could not be established to our servers!  Please check that your device is connected to the internet before continuing.");
                re.ReturnKey = "CONNECT";
                RestErrorEventArgs evg = new RestErrorEventArgs(re);
                RESTJsonError(this, evg);
                return;
            }

            WebClient client = createWebClientObject();

            client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
            client.DownloadStringAsync(new Uri(completeUrl));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// A method for posting serialized data
        /// to the server.
        /// </summary>
        /// <param name="completeUrl">The complete url to post to</param>
        /// <param name="json">The json payload to post</param>
        protected virtual void ExecuteRestPost(string completeUrl, string json)
        {
            //needed for SSL
            System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
            System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, cert, chain, errors) => cert.Subject.ToUpper().Contains(_certificateSubject));
            ServicePointManager.ServerCertificateValidationCallback           += new RemoteCertificateValidationCallback(ValidateRemoteCertificate);

            if (CanPingServices() == false)
            {
                RestError re = new RestError("Connection Error", "A connection could not be established to our servers!  Please check that your device is connected to the internet before continuing.");
                re.ReturnKey = "CONNECT";
                RestErrorEventArgs evg = new RestErrorEventArgs(re);
                RESTJsonError(this, evg);
                return;
            }

            WebClient client = createWebClientObject();

            client.UploadDataCompleted += Client_UploadDataCompleted;
            byte[] payload = System.Text.Encoding.ASCII.GetBytes(json);

            client.UploadDataAsync(new Uri(completeUrl), "POST", payload);
        }
Ejemplo n.º 5
0
 protected virtual void RaiseRestError(RestErrorEventArgs re)
 {
     RESTJsonError(this, re);
 }