public static IEnumerator getUpdates(updateCallback callback) { // The async http request code here is a mess cobbled together from various posts // on the internet. Non-async requests would freeze up the client. var webRequest = (HttpWebRequest)WebRequest.Create(updateCheckURL); webRequest.UserAgent = "Corecii-Spectrum-ServerMod"; webRequest.Method = "GET"; webRequest.Accept = "application/vnd.github.v3+json"; // NOTE: THIS IS NOT SECURE. IT DOES NOT CHECK THE SSL CERTIFICATE // I was getting SSL errors making the web request. After looking it up, it appeared // that the cause was an old version of whatever provides the network stuff. I // would assume that can't be updated unless Distance is updated, but I don't know. // Anyways, this is not too bad just for one request. If it's MitM'd, the worst case // scenario is that the player checks github for an update and finds nothing new. // After making the request, the original certificate checker is put back in place. HttpWebResponse response = null; Action wrapperAction = () => { var previousCallback = ServicePointManager.ServerCertificateValidationCallback; ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); }; webRequest.BeginGetResponse(new AsyncCallback((iar) => { response = (HttpWebResponse)((HttpWebRequest)iar.AsyncState).EndGetResponse(iar); ServicePointManager.ServerCertificateValidationCallback = previousCallback; }), webRequest); }; IAsyncResult asyncResult = wrapperAction.BeginInvoke(new AsyncCallback((iar) => { var action = (Action)iar.AsyncState; action.EndInvoke(iar); }), wrapperAction); while (!asyncResult.IsCompleted || response == null) { yield return(null); } /// if (response.StatusCode != HttpStatusCode.OK) { Console.WriteLine("There was an error checking for a newer version of ServerMod"); yield break; } var stream = response.GetResponseStream(); var reader = new StreamReader(stream); var result = reader.ReadToEnd(); response.Close(); var jsonReader = new JsonFx.Json.JsonReader(); var releases = jsonReader.Read <List <Dictionary <string, object> > >(result); callback(releases); /// yield break; }
/** * Update the DataGridView based on the given CollateralReport, thread-safe */ public void update(QuickFix44.CollateralReport report) { if (grdAccounts.InvokeRequired) { updateCallback d = new updateCallback(update); this.Invoke(d, new object[] { report }); } else { QuickFix.Account account = report.getAccount(); double balance = 0D, used = 0D; // try to set the balance and used margin values from the report, if they exist try { balance = report.getEndCash().getValue(); used = report.getDouble(9038); // FXCMUsedMargin } catch (Exception e) {} // if the account is already in the DataGridView if (map.ContainsKey(account)) { // update the cells with the values that changed DataGridViewRow row = grdAccounts.Rows[map[account]]; row.Cells["Balance"].Value = balance; row.Cells["UsedMargin"].Value = used; } else // otherwise add it to the DataGridView { map.Add(account, map.Count); grdAccounts.Rows.Add( account.getValue(), balance, used ); } // force the interface to refresh Application.DoEvents(); } }
public void update(QuickFix44.MarketDataSnapshotFullRefresh snapshot) { if (grdRates.InvokeRequired) { updateCallback d = new updateCallback(update); this.Invoke(d, new object[] { snapshot }); } else { QuickFix.Symbol instrument = snapshot.getSymbol(); double minQty = 0D; // if the currency is already in the DataGridView if (map.ContainsKey(instrument)) { // update only the cells of the row that have changed DataGridViewRow row = grdRates.Rows[map[instrument]]; row.Cells["Updated"].Value = getClose(snapshot); row.Cells["Bid"].Value = getPrice(snapshot, "0", Convert.ToDouble(row.Cells["Bid"].Value)); row.Cells["Ask"].Value = getPrice(snapshot, "1", Convert.ToDouble(row.Cells["Ask"].Value)); row.Cells["MinQuantity"].Value = minQty; } else // otherwise add it to the DataGridView { map.Add(instrument, map.Count); grdRates.Rows.Add( instrument, getClose(snapshot), getPrice(snapshot, "0", 0D), getPrice(snapshot, "1", 0D), minQty ); } // force the interface to refresh //Application.DoEvents(); } }
private void UpdateNetworkLabel(string txt) { if (lblNetwork.Dispatcher.CheckAccess() == false) { updateCallback uCallBack = new updateCallback(UpdateNetworkLabel); this.Dispatcher.Invoke(uCallBack, txt); } else { lblNetwork.Content = txt; } }