Esempio n. 1
0
        private void cmdLogin_Click(object sender, EventArgs e)
        {
            WHC = new System.Net.WebHeaderCollection();
            WHC.Add("Referer", "http://gendou.com/");

            WebReq wr = new WebReq();
            wr.Request("http://gendou.com/forum/login.php", WHC,
                "name=" + txtUser.Text + "&pass="******"&back=%2F",
                "", true);
            long ltStart = Tick();
            while (!wr.isReady)
            {
                if (ltStart + 10000 < Tick())
                {
                    lbSessID.Text = "Connection timeout";
                    return;
                }
                Application.DoEvents(); System.Threading.Thread.Sleep(10);
            }

            for (int a = 0; a < wr.Headers.Count; a++)
                if (wr.Headers.GetKey(a) == "Set-Cookie")
                {
                    string[] sVals = wr.Headers.GetValues(a);
                    for (int b = 0; b < sVals.Length; b++)
                        if (sVals[b].StartsWith("sid="))
                            SessID = sVals[b]
                                .Substring(4)
                                .Split(';')[0];
                }

            WHC.Add("Cookie", "sid=" + SessID);
            lbSessID.Text = "Session: " + SessID;
        }
Esempio n. 2
0
 internal static void S()
 {
     System.Net.WebHeaderCollection h = new System.Net.WebHeaderCollection();
     h.Add("Accept: application/json");
     h.Add("Client: MyClient");
     foreach (var x in h.GetHeaders())
     {
         Console.WriteLine(x.Key + " = " + x.Value);
     }
 }
Esempio n. 3
0
        public lifecycle(string serverLocation, string sessionId, Request.lifecycle request, bool isBulk = false)
        {
            // Set the URL
            string url = (isBulk ? String.Empty : serverLocation) + "/data/lifecycle";

            if (isBulk)
            {
                this.BulkRequest = new request(url, requestMethod.Post, request, null);
                return;
            }

            // Set the header for the authenticated user
            System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
            headers.Add(System.Net.HttpRequestHeader.Authorization, String.Format("Session {0}", sessionId));

            // Call the API
            Ekin.Rest.Client restClient = new Ekin.Rest.Client(url, headers);
            restClient.ErrorType = typeof(error);
            Ekin.Rest.Response response = restClient.Post(request);

            // Return result
            if (response.Status == System.Net.HttpStatusCode.OK)
            {
                this.IsCalledSuccessfully = true;
            }
            else if (response.InternalError != null)
            {
                this.IsCalledSuccessfully = false;
                this.Error = response.InternalError.GetFormattedErrorMessage();
            }
            else
            {
                this.IsCalledSuccessfully = false;
            }
        }
Esempio n. 4
0
 public getSessionInfo(string serverLocation, string sessionId)
 {
     System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
     headers.Add(System.Net.HttpRequestHeader.Authorization, String.Format("Session {0}", sessionId));
     Ekin.Rest.Client restClient = new Ekin.Rest.Client(serverLocation + "/authentication/getSessionInfo", headers);
     restClient.ErrorType = typeof(error);
     Ekin.Rest.Response response = restClient.Get();
     if (response.Status == System.Net.HttpStatusCode.OK)
     {
         try
         {
             this.Data = JsonConvert.DeserializeObject <Result.getSessionInfo>(response.Content);
             this.IsCalledSuccessfully = true;
         }
         catch (Exception ex)
         {
             this.IsCalledSuccessfully = false;
             this.Error = ex.Message;
         }
     }
     else
     {
         this.IsCalledSuccessfully = false;
         this.Error = response.InternalError.GetFormattedErrorMessage();
     }
 }
Esempio n. 5
0
 public logout(string serverLocation, string sessionId)
 {
     System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
     headers.Add(System.Net.HttpRequestHeader.Authorization, String.Format("Session {0}", sessionId));
     Ekin.Rest.Client   restClient = new Ekin.Rest.Client(serverLocation + "/authentication/logout", headers);
     Ekin.Rest.Response response   = restClient.Get();
     this.IsCalledSuccessfully = (response.Status == System.Net.HttpStatusCode.OK);
 }
Esempio n. 6
0
        public override void AddHeaders(System.Net.WebHeaderCollection headers)
        {
            headers.Add("LANG", LanguageFilter.Current.ToJson().CompressStr());
            headers.Add("IDSISTEMA", AppProperties.SYSID.ToJson().CompressStr());
            headers.Add("SEGURIDADACTIVA", AppProperties.SECURITY.ToJson().CompressStr());

            var tempUser = SeguridadDelegate.UsuarioTemporal;

            if (tempUser != null)
            {
                if (headers["INFO"] == null)
                {
                    headers.Add("INFO", tempUser
                                .ToJson().CompressStr());
                }
            }
        }
        public override void Add(string name, string value)
        {
#if NETFX_CORE
            _actual[name] = value;
#else
            _actual.Add(name, value);
#endif
        }
Esempio n. 8
0
        public objects_get(string serverLocation, string sessionId, Request.objects_get request, bool isBulk = false, bool returnRawResponse = false)
        {
            if (request == null || String.IsNullOrEmpty(request.id))
            {
                IsCalledSuccessfully = false;
                this.Error           = "Object id must be provided";
                return;
            }

            // Set the URL
            string url = (isBulk ? String.Empty : serverLocation) + "/data/objects" +
                         (request.id.Substring(0, 1) != "/" ? "/" : "") + request.id +
                         //(request.fields != null ? "?" + request.fields.ToQueryString() : String.Empty);
                         (request.fields != null ? "?fields=" + GetFieldList(request.fields) : String.Empty);

            if (isBulk)
            {
                this.BulkRequest = new request(url, requestMethod.Get);
                return;
            }

            // Set the header for the authenticated user
            System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
            headers.Add(System.Net.HttpRequestHeader.Authorization, String.Format("Session {0}", sessionId));

            // Call the API
            Ekin.Rest.Client restClient = new Ekin.Rest.Client(url, headers);
            restClient.ErrorType = typeof(error);
            Ekin.Rest.Response response = restClient.Get();

            // Parse Data
            if (response.Status == System.Net.HttpStatusCode.OK)
            {
                try
                {
                    if (returnRawResponse)
                    {
                        this.Data = response.Content;
                    }
                    else
                    {
                        this.Data = JsonConvert.DeserializeObject(response.Content);
                    }
                    this.IsCalledSuccessfully = true;
                }
                catch (Exception ex)
                {
                    this.IsCalledSuccessfully = false;
                    this.Error = ex.Message;
                }
            }
            else
            {
                this.IsCalledSuccessfully = false;
                this.Error = response.InternalError.GetFormattedErrorMessage();
            }
        }
Esempio n. 9
0
        private NetworkFileStreamPersister NewNetworkFilePersister()
        {
            var headers = new System.Net.WebHeaderCollection();

            headers.Add("User-Agent", downloadLicense.UserAgent);

            NetworkFileStream networkFileStream = new NetworkFileStream(tempFile, new Uri(downloadLicense.DownloadUrl), 0, headers);

            return(new NetworkFileStreamPersister(networkFileStream, jsonDownloadState));
        }
        public async Task <IList <ProductoDTO> > BuscarProductos(ProveedorDTO fabricanteEntity)
        {
            IList <ProductoDTO> objetoLocal = null;

            if (fabricanteEntity.TipoApi == "REST")
            {
                RestClient restClient = new RestClient();

                string respuestaJSON = await restClient.MakeRequest
                                           (requestUrlApi : fabricanteEntity.UrlServicio,
                                           JSONRequest : fabricanteEntity.Body,
                                           JSONmethod : fabricanteEntity.MetodoApi,
                                           JSONContentType : "application/json",
                                           msTimeOut : -1);

                var routes_list = JsonConvert.DeserializeObject <Dictionary <string, object> >(respuestaJSON);

                objetoLocal = await _convertJsonToDto.ConvertToProductList(routes_list, fabricanteEntity.TransformacionProductos);
            }
            else if (fabricanteEntity.TipoApi == "SOAP")
            {
                string body = fabricanteEntity.Body;

                System.Net.WebHeaderCollection collection = new System.Net.WebHeaderCollection();
                collection.Add("SOAPAction", fabricanteEntity.SOAPAction);
                collection.Add("Content-Type", "text/xml");

                RestClient soapClient = new RestClient();

                string respuestaXML = await soapClient.MakeRequest
                                          (requestUrlApi : fabricanteEntity.UrlServicio,
                                          JSONRequest : fabricanteEntity.Body,
                                          JSONmethod : fabricanteEntity.MetodoApi,
                                          JSONContentType : "text/xml",
                                          msTimeOut : -1,
                                          headers : collection);

                objetoLocal = await _convertXmlToDto.ConvertToProductList(respuestaXML, fabricanteEntity.TransformacionProductos);
            }

            return(objetoLocal);
        }
Esempio n. 11
0
        public execute(string serverLocation, string sessionId, Request.execute request)
        {
            // Set the URL
            string url = serverLocation + "/bulk/execute";

            // Set the header for the authenticated user
            System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
            headers.Add(System.Net.HttpRequestHeader.Authorization, String.Format("Session {0}", sessionId));

            // Set the CallOptions header
            if (request.batch != null)
            {
                headers.Add("CallOptions", string.Format("Batch={0}", ((bool)request.batch) ? "true" : "false"));
            }

            // Call the API
            Ekin.Rest.Client restClient = new Ekin.Rest.Client(url, headers);
            restClient.ErrorType = typeof(error);
            Ekin.Rest.Response response = restClient.Post(request);

            // Parse Data
            if (response.Status == System.Net.HttpStatusCode.OK)
            {
                try
                {
                    this.Data = JsonConvert.DeserializeObject <Result.execute>(response.Content);
                    this.IsCalledSuccessfully = true;
                }
                catch (Exception ex)
                {
                    this.IsCalledSuccessfully = false;
                    this.Error = ex.Message;
                }
            }
            else
            {
                this.IsCalledSuccessfully = false;
                this.Error = response.InternalError.GetFormattedErrorMessage();
            }
        }
 static RestDefaultHeaders()
 {
     _defaultHeaders = new System.Net.WebHeaderCollection();
     _defaultHeaders.Add(System.Net.HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36");
     _defaultHeaders.Add(System.Net.HttpRequestHeader.ContentType, "application/json;");
     _defaultHeaders.Add(System.Net.HttpRequestHeader.Accept, "application/json, text/plain, */*");
     _defaultHeaders.Add(System.Net.HttpRequestHeader.AcceptEncoding, "gzip, deflate");
     _defaultHeaders.Add(System.Net.HttpRequestHeader.AcceptLanguage, "en-US,en;q=0.8");
     _defaultHeaders.Add(System.Net.HttpRequestHeader.Connection, "keep-alive");
     _defaultHeaders.Add(System.Net.HttpRequestHeader.CacheControl, "no-cache");
 }
        public getCalendarExceptions(string serverLocation, string sessionId, Request.getCalendarExceptions request, bool isBulk = false)
        {
            if (request == null || request.fromDate == DateTime.MinValue || request.toDate == DateTime.MinValue)
            {
                IsCalledSuccessfully = false;
                this.Error           = "FromDate and toDate must be provided";
                return;
            }

            // Set the URL
            string url = string.Format("{0}?{1}fromDate={2:yyyy-MM-dd}&toDate={3:yyyy-MM-dd}",
                                       (isBulk ? String.Empty : serverLocation) + "/data/getCalendarExceptions?",
                                       string.IsNullOrWhiteSpace(request.entityId) ? "" : "entityId=" + request.entityId + "&",
                                       request.fromDate,
                                       request.toDate);

            if (isBulk)
            {
                this.BulkRequest = new request(url, requestMethod.Get, typeof(Result.getCalendarExceptions));
                return;
            }

            // Set the header for the authenticated user
            System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
            headers.Add(System.Net.HttpRequestHeader.Authorization, String.Format("Session {0}", sessionId));

            // Call the API
            Ekin.Rest.Client restClient = new Ekin.Rest.Client(url, headers);
            restClient.ErrorType = typeof(error);
            Ekin.Rest.Response response = restClient.Get();

            // Parse Data
            if (response.Status == System.Net.HttpStatusCode.OK)
            {
                try
                {
                    this.Data = JsonConvert.DeserializeObject <Result.getCalendarExceptions>(response.Content);
                    this.IsCalledSuccessfully = true;
                }
                catch (Exception ex)
                {
                    this.IsCalledSuccessfully = false;
                    this.Error = ex.Message;
                }
            }
            else
            {
                this.IsCalledSuccessfully = false;
                this.Error = response.InternalError.GetFormattedErrorMessage();
            }
        }
Esempio n. 14
0
        public search(string serverLocation, string sessionId, Request.search request, bool isBulk = false)
        {
            if (request == null || String.IsNullOrWhiteSpace(request.q))
            {
                IsCalledSuccessfully = false;
                this.Error           = "Search query must be provided";
                return;
            }

            // Set the URL
            string url = (isBulk ? String.Empty : serverLocation) + "/data/search?q=" + request.q +
                         (request.fields != null ? "&" + request.fields.ToQueryString() : String.Empty) +
                         (!String.IsNullOrWhiteSpace(request.typeName) ? "&" + request.typeName.ToQueryString() : String.Empty) +
                         (request.paging != null ? "&" + request.paging.ToQueryString() : String.Empty);

            if (isBulk)
            {
                this.BulkRequest = new request(url, requestMethod.Get);
                return;
            }

            // Set the header for the authenticated user
            System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
            headers.Add(System.Net.HttpRequestHeader.Authorization, String.Format("Session {0}", sessionId));

            // Call the API
            Ekin.Rest.Client restClient = new Ekin.Rest.Client(url, headers);
            restClient.ErrorType = typeof(error);
            Ekin.Rest.Response response = restClient.Get();

            // Parse Data
            if (response.Status == System.Net.HttpStatusCode.OK)
            {
                try
                {
                    this.Data = JsonConvert.DeserializeObject <Result.search>(response.Content);
                    this.IsCalledSuccessfully = true;
                }
                catch (Exception ex)
                {
                    this.IsCalledSuccessfully = false;
                    this.Error = ex.Message;
                }
            }
            else
            {
                this.IsCalledSuccessfully = false;
                this.Error = response.InternalError.GetFormattedErrorMessage();
            }
        }
Esempio n. 15
0
        public download(string serverLocation, string sessionId, Request.download request, bool isBulk = false)
        {
            if (request == null || String.IsNullOrEmpty(request.documentId))
            {
                IsCalledSuccessfully = false;
                this.Error           = "Document id must be provided";
                return;
            }

            // Set the URL
            string url = (isBulk ? String.Empty : serverLocation) + "/files/download?documentId=" +
                         (request.documentId.Substring(0, 1) != "/" ? "/" : "") + request.documentId +
                         (request.redirect ? "&" + request.redirect.ToQueryString() : String.Empty);

            if (isBulk)
            {
                this.BulkRequest = new request(url, requestMethod.Get);
                return;
            }

            // Set the header for the authenticated user
            System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
            headers.Add(System.Net.HttpRequestHeader.Authorization, String.Format("Session {0}", sessionId));

            // Call the API
            Ekin.Rest.Client restClient = new Ekin.Rest.Client(url, headers);
            restClient.ErrorType = typeof(error);
            Ekin.Rest.Response response = restClient.Get();

            // Parse Data
            if (response.Status == System.Net.HttpStatusCode.OK)
            {
                try
                {
                    this.Data = JsonConvert.DeserializeObject <Result.download>(response.Content);
                    this.IsCalledSuccessfully = true;
                }
                catch (Exception ex)
                {
                    this.IsCalledSuccessfully = false;
                    this.Error = ex.Message;
                }
            }
            else
            {
                this.IsCalledSuccessfully = false;
                this.Error = response.InternalError.GetFormattedErrorMessage();
            }
        }
Esempio n. 16
0
        public entityQuery(string serverLocation, string sessionId, Queries.entityQuery request, bool isBulk = false)
        {
            // Set the URL
            string url = (isBulk ? String.Empty : serverLocation) + "/data/entityQuery";

            if (isBulk)
            {
                this.BulkRequest = new request(url, requestMethod.Post, request, typeof(Result.entityQuery));
                return;
            }

            // Set the header for the authenticated user
            System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
            headers.Add(System.Net.HttpRequestHeader.Authorization, String.Format("Session {0}", sessionId));

            // Call the API
            Ekin.Rest.Client restClient = new Ekin.Rest.Client(url, headers);
            restClient.ErrorType = typeof(error);
            Ekin.Rest.Response response = restClient.Post(request);

            // Return result
            if (response.Status == System.Net.HttpStatusCode.OK)
            {
                try
                {
                    this.Data = JsonConvert.DeserializeObject <Result.entityQuery>(response.Content, new JsonSerializerSettings()
                    {
                        Error = HandleDeserializationError
                    });

                    this.IsCalledSuccessfully = true;
                }
                catch (Exception ex)
                {
                    this.IsCalledSuccessfully = false;
                    this.Error = ex.Message;
                }
            }
            else if (response.InternalError != null)
            {
                this.IsCalledSuccessfully = false;
                this.Error = response.InternalError.GetFormattedErrorMessage();
            }
            else
            {
                this.IsCalledSuccessfully = false;
            }
        }
Esempio n. 17
0
        public getCalendarInfo(string serverLocation, string sessionId, Request.getCalendarInfo request, bool isBulk = false)
        {
            if (request == null || String.IsNullOrEmpty(request.id))
            {
                IsCalledSuccessfully = false;
                this.Error           = "Entity id must be provided";
                return;
            }

            // Set the URL
            string url = (isBulk ? String.Empty : serverLocation) + "/data/getCalendarInfo?userId=" + request.id;

            if (isBulk)
            {
                this.BulkRequest = new request(url, requestMethod.Get, typeof(Result.getCalendarInfo));
                return;
            }

            // Set the header for the authenticated user
            System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
            headers.Add(System.Net.HttpRequestHeader.Authorization, String.Format("Session {0}", sessionId));

            // Call the API
            Ekin.Rest.Client restClient = new Ekin.Rest.Client(url, headers);
            restClient.ErrorType = typeof(error);
            Ekin.Rest.Response response = restClient.Get();

            // Parse Data
            if (response.Status == System.Net.HttpStatusCode.OK)
            {
                try
                {
                    this.Data = JsonConvert.DeserializeObject <Result.getCalendarInfo>(response.Content);
                    this.IsCalledSuccessfully = true;
                }
                catch (Exception ex)
                {
                    this.IsCalledSuccessfully = false;
                    this.Error = ex.Message;
                }
            }
            else
            {
                this.IsCalledSuccessfully = false;
                this.Error = response.InternalError.GetFormattedErrorMessage();
            }
        }
Esempio n. 18
0
        public objects_delete(string serverLocation, string sessionId, Request.objects_delete request, bool isBulk = false)
        {
            if (request == null || String.IsNullOrEmpty(request.id))
            {
                IsCalledSuccessfully = false;
                this.Error           = "Entity id must be provided";
                return;
            }

            // Set the URL
            string url = (isBulk ? String.Empty : serverLocation) + "/metadata/objects" +
                         (request.id.Substring(0, 1) != "/" ? "/" : "") + request.id;

            if (isBulk)
            {
                this.BulkRequest = new request(url, requestMethod.Delete);
                return;
            }

            // Set the header for the authenticated user
            System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
            headers.Add(System.Net.HttpRequestHeader.Authorization, String.Format("Session {0}", sessionId));

            // Call the API
            Ekin.Rest.Client restClient = new Ekin.Rest.Client(url, headers);
            restClient.ErrorType = typeof(error);
            Ekin.Rest.Response response = restClient.Delete();

            // Return result
            if (response.Status == System.Net.HttpStatusCode.OK)
            {
                this.IsCalledSuccessfully = true;
            }
            else if (response.InternalError != null)
            {
                this.IsCalledSuccessfully = false;
                this.Error = response.InternalError.GetFormattedErrorMessage();
            }
            else
            {
                this.IsCalledSuccessfully = false;
            }
        }
Esempio n. 19
0
        public objects_put(string serverLocation, string sessionId, string id, object obj, bool isBulk = false)
        {
            // Set the URL
            string url = (isBulk ? String.Empty : serverLocation) + "/data/objects" +
                         (id.Substring(0, 1) != "/" ? "/" : "") + id;

            if (isBulk)
            {
                this.BulkRequest = new request(url, requestMethod.Put, obj, typeof(Result.objects_put));
                return;
            }

            // Set the header for the authenticated user
            System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
            headers.Add(System.Net.HttpRequestHeader.Authorization, String.Format("Session {0}", sessionId));

            // Call the API
            Ekin.Rest.Client restClient = new Ekin.Rest.Client(url, headers);
            restClient.ErrorType = typeof(error);
            Ekin.Rest.Response response = restClient.Put(obj);

            // Parse Data
            if (response.Status == System.Net.HttpStatusCode.OK)
            {
                try
                {
                    this.Data = JsonConvert.DeserializeObject <Result.objects_put>(response.Content);
                    this.IsCalledSuccessfully = true;
                }
                catch (Exception ex)
                {
                    this.IsCalledSuccessfully = false;
                    this.Error = ex.Message;
                }
            }
            else
            {
                this.IsCalledSuccessfully = false;
                this.Error = response.InternalError.GetFormattedErrorMessage();
            }
        }
        public getSystemSettingsValues(string serverLocation, string sessionId, Request.getSystemSettingsValues request, bool isBulk = false)
        {
            // Set the URL
            string url = (isBulk ? String.Empty : serverLocation) + "/metadata/getSystemSettingsValues?" + request.ToQueryString();

            if (isBulk)
            {
                this.BulkRequest = new request(url, requestMethod.Get, typeof(Result.describeMetadata));
                return;
            }

            // Set the header for the authenticated user
            System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
            headers.Add(System.Net.HttpRequestHeader.Authorization, String.Format("Session {0}", sessionId));

            // Call the API
            Ekin.Rest.Client restClient = new Ekin.Rest.Client(url, headers);
            restClient.ErrorType = typeof(error);
            Ekin.Rest.Response response = restClient.Get();

            // Parse Data
            if (response.Status == System.Net.HttpStatusCode.OK)
            {
                try
                {
                    this.Data = JsonConvert.DeserializeObject <Result.getSystemSettingsValues>(response.Content);
                    this.IsCalledSuccessfully = true;
                }
                catch (Exception ex)
                {
                    this.IsCalledSuccessfully = false;
                    this.Error = ex.Message;
                }
            }
            else
            {
                this.IsCalledSuccessfully = false;
                this.Error = response.InternalError.GetFormattedErrorMessage();
            }
        }
Esempio n. 21
0
 public void cargarJson(string url, System.Collections.ArrayList headers, string post = null, string content_type = "application/x-www-form-urlencoded")
 {
     try {
         System.Net.HttpWebRequest      solicitud = (System.Net.HttpWebRequest)System.Net.WebRequest.CreateDefault(new Uri(url));
         System.Net.WebHeaderCollection cabeceras = new System.Net.WebHeaderCollection();
         foreach (string cabecera in headers)
         {
             if (cabecera.IndexOf("Accept") == 0)
             {
                 string[] partes = cabecera.Split(new char[] { ':' }, 2);
                 solicitud.Accept = partes[1].Trim();
             }
             else
             {
                 cabeceras.Add(cabecera);
             }
         }
         solicitud.Headers = cabeceras;
         if (post != null)
         {
             solicitud.Method      = "POST";
             solicitud.ContentType = content_type;
             byte[] buffer = new byte[post.Length];
             //post.
             for (int i = 0; i < post.Length; i++)
             {
                 buffer[i] = (byte)(post[i]);
             }
             System.IO.Stream datos = solicitud.GetRequestStream();
             datos.Write(buffer, 0, post.Length);
         }
         System.Net.HttpWebResponse respuesta = (System.Net.HttpWebResponse)solicitud.GetResponse();
         string json_texto = leerStream(respuesta.GetResponseStream());
         parse(json_texto);
     }catch (Exception ex) {
         System.Diagnostics.Trace.WriteLine("ERROR AL CARGAR JSON. \r\n" + ex.Message);
     }
 }
Esempio n. 22
0
        //拆单
        private void Btn_Enter_Click(object sender, EventArgs e)
        {
            if (SelectIDList != null)
            {
                if (SelectIDList.Count == 0)
                {
                    MessageBox.Show("您未选择任何桌子!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }

                Desk d;
                d = (Desk)this.Owner;

                getconsumptionsid();                                                                    //接受json数据
                var jserConsumption    = new JavaScriptSerializer();
                var personsConsumption = jserConsumption.Deserialize <Consumption>(Str_consumptionsid); //解析json数据
                if (personsConsumption.merge.branches.Count() > 1)
                {
                    Merge mg = new Merge();
                    List <Consumption> branches = new List <Consumption>();
                    Consumption        merge    = new Consumption();
                    merge.id = this.Txt_Master.Text;
                    Consumption master = new Consumption();
                    master.id = personsConsumption.merge.master.id;
                    for (int j = 0; j < personsConsumption.merge.branches.Count(); j++)
                    {
                        Consumption branch = new Consumption();

                        branch.id = personsConsumption.merge.branches[j].id;
                        branches.Add(branch);
                    }
                    for (int i = 0; i < SelectIDList.Count(); i++)
                    {
                        Consumption target = branches.Where(r => r.id == SelectIDList[i]).FirstOrDefault();
                        branches.Remove(target);

                        //根据消费ID 移除桌子
                        foreach (Control ct in this.panelTables.Controls)
                        {
                            if (ct is DeskControl.DeskControl)
                            {
                                DeskControl.DeskControl dc = (DeskControl.DeskControl)ct;
                                if (SelectIDList[i] == dc.lbConsumption.Text)
                                {
                                    d.CurrentChooseDesk.Remove(dc.lbTableID.Text);
                                }
                            }
                        }
                    }
                    mg.merge    = merge;
                    mg.master   = master;
                    mg.branches = branches.ToArray();
                    System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
                    headers.Add("Authorization", PassValue.token);
                    Post.PostHttp(headers, "consumptions/merge", mg);
                }
                else if (personsConsumption.merge.branches.Count() == 1)
                {
                    Merge mg = new Merge();
                    List <Consumption> branches = new List <Consumption>();
                    Consumption        merge    = new Consumption();
                    merge.id    = this.Txt_Master.Text;
                    mg.merge    = merge;
                    mg.master   = null;
                    mg.branches = null;

                    for (int i = 0; i < SelectIDList.Count(); i++)
                    {
                        //根据消费ID 移除桌子
                        foreach (Control ct in this.panelTables.Controls)
                        {
                            if (ct is DeskControl.DeskControl)
                            {
                                DeskControl.DeskControl dc = (DeskControl.DeskControl)ct;
                                if (SelectIDList[i] == dc.lbConsumption.Text)
                                {
                                    d.CurrentChooseDesk.Remove(dc.lbTableID.Text);
                                }
                            }
                        }
                    }


                    System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
                    headers.Add("Authorization", PassValue.token);
                    Post.PostHttp(headers, "consumptions/merge", mg);
                }
                MessageBox.Show("拆单成功!");

                d.Refresh_Method();
                this.Close();
            }
        }
Esempio n. 23
0
        private string Upload(string sPath)
        {
            try
            {
                System.IO.FileStream fs = new System.IO.FileStream(
                    sPath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                byte[] bImg = new byte[fs.Length]; fs.Read(bImg, 0, bImg.Length);
                fs.Close(); fs.Dispose(); string fname = MakeFName();

                string sPostTo = "http://www.imagehost.org/";
                string sRefer  = "http://www.imagehost.org/";

                WebReq WReq     = new WebReq();
                string sMPBound = "----------" + WReq.RandomChars(22);
                string sPD1     = "--" + sMPBound + "\r\n" +
                                  "Content-Disposition: form-data; name=\"a\"" + "\r\n" +
                                  "\r\n" + "upload" + "\r\n" + "--" + sMPBound + "\r\n" +
                                  "Content-Disposition: form-data; name=\"file[]\"; " +
                                  "filename=\"" + fname + ".png\r\n" +
                                  "Content-Type: image/png" + "\r\n" +
                                  "\r\n";
                string sPD2 = "\r\n" + "--" + sMPBound + "\r\n" +
                              "Content-Disposition: form-data; name=\"file[]\"; filename=\"\"" + "\r\n" +
                              "\r\n" + "\r\n" + "--" + sMPBound + "\r\n" +
                              "Content-Disposition: form-data; name=\"file[]\"; filename=\"\"" + "\r\n" +
                              "\r\n" + "\r\n" + "--" + sMPBound + "\r\n" +
                              "Content-Disposition: form-data; name=\"file[]\"; filename=\"\"" + "\r\n" +
                              "\r\n" + "\r\n" + "--" + sMPBound + "\r\n" +
                              "Content-Disposition: form-data; name=\"file[]\"; filename=\"\"" + "\r\n" +
                              "\r\n" + "\r\n" + "--" + sMPBound + "\r\n" +
                              "Content-Disposition: form-data; name=\"file[]\"; filename=\"\"" + "\r\n" +
                              "\r\n" + "\r\n" + "--" + sMPBound + "\r\n" +
                              "Content-Disposition: form-data; name=\"file[]\"; filename=\"\"" + "\r\n" +
                              "\r\n" + "\r\n" + "--" + sMPBound + "\r\n" +
                              "Content-Disposition: form-data; name=\"file[]\"; filename=\"\"" + "\r\n" +
                              "\r\n" + "\r\n" + "--" + sMPBound + "--" + "\r\n";
                byte[] bPD1 = new byte[sPD1.Length];
                byte[] bPD2 = new byte[sPD2.Length];
                for (int a = 0; a < sPD1.Length; a++)
                {
                    bPD1[a] = (byte)sPD1[a];
                }
                for (int a = 0; a < sPD2.Length; a++)
                {
                    bPD2[a] = (byte)sPD2[a];
                }
                byte[] bPD = new byte[bPD1.Length + bImg.Length + bPD2.Length];
                bPD1.CopyTo(bPD, 0);
                bImg.CopyTo(bPD, 0 + bPD1.Length);
                bPD2.CopyTo(bPD, 0 + bPD1.Length + bImg.Length);
                System.Net.WebHeaderCollection whc = new System.Net.WebHeaderCollection();
                //whc.Add("Expect: 100-continue");
                whc.Add("Referer: " + sRefer);

                WReq.Request(sPostTo, whc, bPD, sMPBound, 3, "", true);
                while (!WReq.isReady)
                {
                    Application.DoEvents();
                    System.Threading.Thread.Sleep(1);
                }
                if (WReq.sResponse.Contains(fname))
                {
                    if (WReq.sResponse.Contains("nowrap\">Hotlink</td>"))
                    {
                        return(Split(Split(Split(WReq.sResponse,
                                                 "nowrap\">Hotlink</td>")[1],
                                           " size=\"50\" value=\"")[1],
                                     "\" />")[0]);
                    }
                    else
                    {
                        return(Split(Split(Split(WReq.sResponse,
                                                 "nowrap\">Text Link</td>")[1],
                                           " size=\"50\" value=\"")[1],
                                     "\" />")[0]);
                    }
                }
                else
                {
                    return("");
                }
            }
            catch { return(""); }
        }
        /// <summary>
        /// Applies the transform to the request.
        /// </summary>
        /// <param name="request"> The web request.</param>
        /// <param name="response"> The web response.</param>
        public override void ApplyTransform(WebRequest request, WebResponse response)
        {
            base.ApplyTransform (request, response);

            try
            {
                System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
                WebHeader.FillWebHeaderCollection(headers,request.RequestHttpSettings.AdditionalHeaders);

                foreach ( TransformAction transformAction in _actions )
                {
                    // Add Header
                    if ( transformAction is AddTransformAction )
                    {
                        AddTransformAction add = (AddTransformAction)transformAction;

                        object result = add.Value.GetValue(response);

                        if ( headers[add.Name] == null )
                        {
                            headers.Add(add.Name, Convert.ToString(result));
                        }
                    }

                    // Update Header
                    if ( transformAction is UpdateTransformAction )
                    {
                        UpdateTransformAction update = (UpdateTransformAction)transformAction;

                        object result = update.Value.GetValue(response);
                        SetHeaderValue(request, update.Name, Convert.ToString(result), headers);
                    }

                    // Remove Header
                    if ( transformAction is RemoveTransformAction )
                    {
                        RemoveTransformAction remove = (RemoveTransformAction)transformAction;

                        if ( headers[remove.Name] != null )
                        {
                            headers.Remove(remove.Name);
                        }
                    }
                }

                // update request
                request.RequestHttpSettings.AdditionalHeaders = WebHeader.ToArray(headers);
            }
            catch ( Exception ex )
            {
                ExceptionManager.Publish(ex);
            }
        }
Esempio n. 25
0
        //拆单
        private void Btn_Enter_Click(object sender, EventArgs e)
        {
            if (SelectIDList != null)
            {
                if (SelectIDList.Count == 0)
                {
                    MessageBox.Show("您未选择任何桌子!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }

                Desk d;
                d = (Desk)this.Owner;

                getconsumptionsid();//接受json数据
                var jserConsumption = new JavaScriptSerializer();
                var personsConsumption = jserConsumption.Deserialize<Consumption>(Str_consumptionsid);//解析json数据
                if (personsConsumption.merge.branches.Count() > 1)
                {
                    Merge mg = new Merge();
                    List<Consumption> branches = new List<Consumption>();
                    Consumption merge = new Consumption();
                    merge.id = this.Txt_Master.Text;
                    Consumption master = new Consumption();
                    master.id = personsConsumption.merge.master.id;
                    for (int j = 0; j < personsConsumption.merge.branches.Count(); j++)
                    {
                        Consumption branch = new Consumption();

                        branch.id = personsConsumption.merge.branches[j].id;
                        branches.Add(branch);
                    }
                    for (int i = 0; i < SelectIDList.Count(); i++)
                    {
                        Consumption target = branches.Where(r => r.id == SelectIDList[i]).FirstOrDefault();
                        branches.Remove(target);

                        //根据消费ID 移除桌子
                        foreach (Control ct in this.panelTables.Controls)
                        {
                            if (ct is DeskControl.DeskControl)
                            {
                                DeskControl.DeskControl dc = (DeskControl.DeskControl)ct;
                                if (SelectIDList[i] == dc.lbConsumption.Text)
                                {
                                    d.CurrentChooseDesk.Remove(dc.lbTableID.Text);
                                }
                            }
                        }
                    }
                    mg.merge = merge;
                    mg.master = master;
                    mg.branches = branches.ToArray();
                    System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
                    headers.Add("Authorization", PassValue.token);
                    Post.PostHttp(headers, "consumptions/merge", mg);
                }
                else if (personsConsumption.merge.branches.Count() == 1)
                {
                    Merge mg = new Merge();
                    List<Consumption> branches = new List<Consumption>();
                    Consumption merge = new Consumption();
                    merge.id = this.Txt_Master.Text;
                    mg.merge = merge;
                    mg.master = null;
                    mg.branches = null;

                    for (int i = 0; i < SelectIDList.Count(); i++)
                    {
                        //根据消费ID 移除桌子
                        foreach (Control ct in this.panelTables.Controls)
                        {
                            if (ct is DeskControl.DeskControl)
                            {
                                DeskControl.DeskControl dc = (DeskControl.DeskControl)ct;
                                if (SelectIDList[i] == dc.lbConsumption.Text)
                                {
                                    d.CurrentChooseDesk.Remove(dc.lbTableID.Text);
                                }
                            }
                        }
                    }

                    System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
                    headers.Add("Authorization", PassValue.token);
                    Post.PostHttp(headers, "consumptions/merge", mg);
                }
                MessageBox.Show("拆单成功!");

                d.Refresh_Method();
                this.Close();
            }
        }