public static object Load_sSystem(string hostURL, bool load) { string url = hostURL + "jsonDataExchange.asmx/ReceiveFromServer"; if (load) { try { var request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); request.ContentType = "application/json"; request.Method = "POST"; request.Expect = "application/json"; using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write("{'GHin':'" + "ask" + "'}"); streamWriter.Close(); } var httpResponse = (System.Net.HttpWebResponse)request.GetResponse(); StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream()); string resp = streamReader.ReadToEnd(); sJsonReceiver jj = Newtonsoft.Json.JsonConvert.DeserializeObject <sJsonReceiver>(resp); string jsonSys = jj.d; return(new Dictionary <string, object> { { "sghSystem", SystemBase.Objectify(jsonSys) } }); } catch (System.Net.WebException e) { string pageContent = new StreamReader(e.Response.GetResponseStream()).ReadToEnd().ToString(); return(new Dictionary <string, object> { { "sghSystem", pageContent } }); } } else { return(new Dictionary <string, object> { { "sghSystem", "" } }); } }
protected override void SolveInstance(IGH_DataAccess DA) { string hostURL = ""; bool load = false; bool reset = false; if (!DA.GetData(0, ref hostURL)) { return; } if (!DA.GetData(1, ref load)) { return; } DA.GetData(2, ref reset); string url = hostURL + "sWebSystemServer.asmx/ReceiveFromServer"; if (load) { result = ""; try { var request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); request.ContentType = "application/json"; request.Method = "POST"; request.Expect = "application/json"; using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write("{'ClientMess':'" + "ask" + "'}"); streamWriter.Close(); } var httpResponse = (System.Net.HttpWebResponse)request.GetResponse(); StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream()); string resp = streamReader.ReadToEnd(); sJsonReceiver jj = Newtonsoft.Json.JsonConvert.DeserializeObject <sJsonReceiver>(resp); result = jj.d; } catch (System.Net.WebException e) { this.Message = "Couldn't Find The Server"; string pageContent = new StreamReader(e.Response.GetResponseStream()).ReadToEnd().ToString(); } } if (reset) { result = ""; } ISystem sysLoaded = null; if (result.Length > 0) { string jsonSys = result; sysLoaded = SystemBase.Objectify(jsonSys); this.Message = "System : " + sysLoaded.systemSettings.systemName + "\nis loaded" + "\nLoadCase: " + sysLoaded.systemSettings.currentCase; } else { this.Message = "System NULL"; } DA.SetData(0, sysLoaded); }