public void DownloadBlueprint(string path, string ruimteid, string setnr) { var holder = (from h in bluePrints where h.filepath == path && h.ruimteId == ruimteid && h.ruimteSetNr == setnr select h).FirstOrDefault(); if (holder == null) { holder = new BluePrintHolder() { filepath = path, ruimteId = ruimteid, ruimteSetNr = setnr != null ? setnr : "Basis", statusInfo = BluePrintStatus.Downloading }; bluePrints.Add(holder); } if (HuidigeRuimteSetNrs.ContainsKey(ruimteid)) { HuidigeRuimteSetNrs[ruimteid] = setnr != null ? setnr : "Basis"; } else { HuidigeRuimteSetNrs.Add(ruimteid, setnr != null ? setnr : "Basis"); } string apath = "http://mybouwapp.nl/Images/Blueprints/" + path; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apath); request.UseDefaultCredentials = true; Acumulator.Instance().updateDownActive(ruimteid, true); request.BeginGetResponse(RequestReady, request); }
public void GetAllBlueprints() { //Acumulator.Instance().Blueprints.Clear(); bluePrints.Clear(); foreach (Ruimte r in Acumulator.Instance().OTracker.offerteRuimte_.Children) { string path = Acumulator.Instance().GetPathGespiegeld(r.RuimteID); BluePrintHolder holder = new BluePrintHolder() { filepath = path, ruimteId = r.RuimteID, ruimteSetNr = "Basis", statusInfo = BluePrintStatus.Downloading }; if (HuidigeRuimteSetNrs.ContainsKey(r.RuimteID)) { HuidigeRuimteSetNrs[r.RuimteID] = "Basis"; } else { HuidigeRuimteSetNrs.Add(r.RuimteID, "Basis"); } bluePrints.Add(holder); if (path != null && path != "") { string apath = "http://mybouwapp.nl/Images/Blueprints/" + path; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apath); request.UseDefaultCredentials = true; Acumulator.Instance().updateDownActive(r.RuimteID, true); request.BeginGetResponse(RequestReady, request); } } }
private void RequestReady(IAsyncResult asyncResult) { var req = asyncResult.AsyncState as HttpWebRequest; BluePrintHolder holder = null; try { using (WebResponse wrs = req.EndGetResponse(asyncResult)) { var path = wrs.ResponseUri.ToString().Replace("http://mybouwapp.nl/Images/Blueprints/", ""); var foo = wrs.GetResponseStream(); var bar = foo.CloneToMemoryStream(); var foobar = bar.ToArray(); holder = (from h in bluePrints where (h.statusInfo == BluePrintStatus.Downloading || h.statusInfo == BluePrintStatus.Retrying) && h.filepath == path select h).FirstOrDefault(); holder.pixelData = foobar; holder.statusInfo = BluePrintStatus.Complete; while (lockacumu) { } lockacumu = true; // Acumulator.Instance().BlueprintRequestReady(path, foobar, null); lockacumu = false; UIThread.Invoke(() => Acumulator.Instance().BB.ReloadImage()); } } catch (Exception e) { var path = req.RequestUri.ToString().Replace("http://mybouwapp.nl/Images/Blueprints/", ""); holder = (from h in bluePrints where (h.statusInfo == BluePrintStatus.Downloading || h.statusInfo == BluePrintStatus.Retrying) && h.filepath == path select h).FirstOrDefault(); if (holder != null) { holder.statusInfo = BluePrintStatus.Retrying; if (holder.numRetry < 3) { holder.numRetry++; DownloadBlueprint(holder.filepath, holder.ruimteId, holder.ruimteSetNr); } else { holder.statusInfo = BluePrintStatus.Failed; UIThread.Invoke(() => LogHelper.SendLog("download failed after retry: " + e.Message, LogType.error)); } } } }