async Task <IEnumerable <Item> > IDataStore <Item> .GetItemsAsync(bool forceRefresh) { var items = new List <Item>(); var topCities = await HTTPClientService.GetAccuWeatherTopCitiesDataAsync(); foreach (var city in topCities) { items.Add(new Item() { Id = city.Key, City = city.EnglishName, Country = city.Country.EnglishName, Population = city.Details.Population }); } return(items); }
public void onStartingDownload(HTTPClientService http, EndPoint server, int imgCount, UIElement ui) { App.WriteLog(server.ToString()+" start downloading. total imgs: " + imgCount, Log.MsgType.Information); this.Dispatcher.Invoke(new Action(delegate { string trans_status = String.Format(Properties.Resources.CLEANSPACE_TRANSFER_STATUS2, imgCount); this.text_TransState1.Text = trans_status; trans_status = String.Format(Properties.Resources.CLEANSPACE_TRANSFER_STATUS, 1); this.text_TransState.Text = trans_status; this.RecieveStatus.Text = Properties.Resources.CS_PC_RECEIVING; })); }
public void onHttpFinishloadingOne(HTTPClientService http, EndPoint server, RemotePhotoInfo rpi, string path, int status, UIElement ui) { lock (locker) { if (status == GlobalDef.Status.S_DownloadedSuccessful) { string tempurl = rpi.fileUrl.Replace(":" + GlobalDef.REMOTEHTTPSERVER_PORT + "/download", ":" + GlobalDef.REMOTEHTTPSERVER_PORT + "/downloadcomplete"); App.WriteLog(server.ToString() + " download img: " + rpi.fileUrl + " success", Log.MsgType.Information); this.Dispatcher.Invoke(new Action(delegate { string trans_status = String.Format(Properties.Resources.CLEANSPACE_TRANSFER_STATUS2, http.getTotalImgCount()); this.text_TransState1.Text = trans_status; trans_status = String.Format(Properties.Resources.CLEANSPACE_TRANSFER_STATUS, http.getDownloadedImgCount() >= http.getTotalImgCount() ? http.getDownloadedImgCount() : http.getDownloadedImgCount() + 1); this.text_TransState.Text = trans_status; Image thumbnail = ui as Image; if (File.Exists(path) && (Utils.IsPicture(path) || Utils.IsVideo(path))) { thumbmgr.addNewImg(path); if (thumbnail != null) { try { //BinaryReader binReader = new BinaryReader(File.Open(path, FileMode.Open)); //FileInfo fileInfo = new FileInfo(path); //byte[] bytes = binReader.ReadBytes((int)fileInfo.Length); //binReader.Close(); //BitmapImage bitmap = new BitmapImage(); //bitmap.BeginInit(); //bitmap.StreamSource = new MemoryStream(bytes); //bitmap.EndInit(); thumbnail.Source = Utils.GetThumbnail(path, 48, 48); } catch { } } } })); //new thread to post delete command for the damn server may timeout int result = DownloadCompleteRequest(tempurl); DateTime now = DateTime.UtcNow; while (result == -1) { TimeSpan ts = DateTime.UtcNow - now; if (ts.TotalSeconds >= 175 || isClosing || !http.isStarted) { StopAllSessions(); break; } result = DownloadCompleteRequest(tempurl); } //Thread t = new Thread(() => { }); //t.Start(); //t.Join(); } else { App.WriteLog(server.ToString() + " download img: " + rpi.fileUrl + " fail. retry....", Log.MsgType.Information); } } }
public void onHttpClientSelfDestroy(HTTPClientService http, EndPoint server, int status, UIElement ui) { lock (locker1) { if (status != GlobalDef.Status.S_HTTPDownladerInitSuccess) uploadMassData(GlobalDef.MassDataItems.Mass_Transmit_fail_times, "1"); this.m_httpServsDit.Remove(server); softap_conn = false; scanSoftAp.Disconnect(); mDeviceId = string.Empty; mGroupTime = string.Empty; ReleaseMobileSoftapHolder(); try { this.Dispatcher.Invoke(new Action(delegate { if (tipwnd != null && tipwnd.IsLoaded) tipwnd.Hide(); string alldone_status = String.Format(Properties.Resources.CS_TRANS_COMPLETE_RESULT, http.getDownloadedImgCount()); this.text_TransState1.Text = alldone_status; this.RecieveStatus.Text = Properties.Resources.CS_PC_READY; this.TransferCompletedIndicator.Visibility = Visibility.Visible; this.ProgressIndicator.Visibility = Visibility.Collapsed; // this.ThumbnailCanvas.Visibility = Visibility.Hidden; })); } catch { //UI destroyed. ignore.. } App.WriteLog(server.ToString() + " done. success: "+ http.getDownloadedImgCount() + " failed: " + http.getDownloadFailedImgCount(), Log.MsgType.Information); } }
public void onHttpClientPreTransVideo(HTTPClientService http, EndPoint server, UIElement ui) { this.Dispatcher.Invoke(new Action(delegate { Image thumbnail = ui as Image; if (thumbnail != null) { thumbnail.Source = new BitmapImage(new Uri(@"./images/video.png", UriKind.Relative)); } })); }