public async Task LoadingAsync() { try { if (HIOStaticValues.CheckSyncingData()) { SyncronizingState = SyncronizingStateEnum.Syncronizing; Trace.WriteLine("SyncronizingState in dashboard:" + SyncronizingState); Trace.WriteLine("percent in dashboard:" + ProgressPercent); DispatcherTimer dt = new DispatcherTimer(); dt.Interval = TimeSpan.FromSeconds(1); dt.Tick += Dt_Tick; dt.Start(); return; } App.Current.Dispatcher.Invoke(new Action(() => { SourceItems.Clear(); })); Converts conv = new Converts(); DataBase db = new DataBase(); // HIOStaticValues.commandQ.Add(()=> QBatteryandSignalCheckAsync()); Commands ic = new Commands(); HIOStaticValues.commandQ.Add(() => { BatteryValue = ic.GetBatteryStatus(); }); HIOStaticValues.commandQ.Add(() => { Commands cmd = new Backend.Commands(); cmd.GetRssi(); App.Current.Dispatcher.Invoke(new Action(() => { SignalValue = cmd.GetSignalStatus(HIOStaticValues.blea.rssi); })); }); HIOStaticValues.commandQ.Add(() => { App.Current.Dispatcher.Invoke(new Action(async() => { SyncronizingState = ic.AmISync(); if (SyncronizingState == SyncronizingStateEnum.NotSynced) { await Syncronize(); } })); }); App.Current.Dispatcher.Invoke(new Action(async() => { //READ DATA lp = await Task.Run(() => { return(db.ReadData()); }); if (lp != null) { ItemCounter = (lp.Count > 1) ? lp.Count + " Items" : lp.Count + " Item"; } //Note : lp may be null if (lp != null && lp.Any()) { #region Load Data List <TAccountItem> items = new List <TAccountItem>(); foreach (var item in lp) { DrawingImage tmpDraw = new DrawingImage(); if (item.imageData == null || item.imageData.Length == 0) { tmpDraw = HIOStaticValues.PutTextInImage(item.url.Substring(0, 1)); } else { tmpDraw = conv.BitmapImageToDrawingImage(conv.byteArrayToImage(item.imageData)); } items.Add(new TAccountItem(this) { UserID = item.rowid, Name = item.title, Username = item.userName, Url = item.url, ImageData = tmpDraw, AppID = item.appID, SubTitle1 = item.userName, SubTitle2 = conv.GetPrettyDate(item.last_used), Popularity = item.popularity, Date = item.last_used }); // items.Add(new User() { Title = listlp[i].title, Username = listlp[i].userName, rowid = listlp[i].rowid }); } #endregion #region Sort Data if (SortByField.IsNullOrEmpty() || "Name".Equals(SortByField, StringComparison.InvariantCultureIgnoreCase)) { items = items.OrderBy(t => t.Name).ToList(); } else if ("Date".Equals(SortByField, StringComparison.InvariantCultureIgnoreCase)) { items = items.OrderByDescending(t => t.Date).ToList(); } else if ("Popularity".Equals(SortByField, StringComparison.InvariantCultureIgnoreCase)) { items = items.OrderByDescending(t => t.Popularity).ToList(); } #endregion #region Add Data foreach (var item in items) { SourceItems.Add(item); } #endregion } OnPropertyChanged(nameof(Items)); })); } catch (Exception ex) { } finally { NotifyItemsChanged(); } }
public async Task LoadData() { try { App.Current.Dispatcher.Invoke(new Action(async() => { SourceItems.Clear(); DataBase db = new DataBase(); Converts conv = new Converts(); lp = await Task.Run(() => { return(db.ReadData()); }); if (lp != null) { ItemCounter = (lp.Count > 1) ? lp.Count + " Items" : lp.Count + " Item"; } //Note : lp may be null if (lp != null && lp.Any()) { #region Load Data List <TAccountItem> items = new List <TAccountItem>(); foreach (var item in lp) { DrawingImage tmpDraw = new DrawingImage(); if (item.imageData == null || item.imageData.Length == 0) { tmpDraw = HIOStaticValues.PutTextInImage(item.url.Substring(0, 1)); } else { tmpDraw = conv.BitmapImageToDrawingImage(conv.byteArrayToImage(item.imageData)); } items.Add(new TAccountItem(this) { UserID = item.rowid, Name = item.title, Username = item.userName, Url = item.url, ImageData = tmpDraw, AppID = item.appID, SubTitle1 = item.userName, SubTitle2 = conv.GetPrettyDate(item.last_used), Popularity = item.popularity, Date = item.last_used }); // items.Add(new User() { Title = listlp[i].title, Username = listlp[i].userName, rowid = listlp[i].rowid }); } #endregion #region Sort Data if (SortByField.IsNullOrEmpty() || "Name".Equals(SortByField, StringComparison.InvariantCultureIgnoreCase)) { items = items.OrderBy(t => t.Name).ToList(); } else if ("Date".Equals(SortByField, StringComparison.InvariantCultureIgnoreCase)) { items = items.OrderByDescending(t => t.Date).ToList(); } else if ("Popularity".Equals(SortByField, StringComparison.InvariantCultureIgnoreCase)) { items = items.OrderByDescending(t => t.Popularity).ToList(); } #endregion #region Add Data foreach (var item in items) { SourceItems.Add(item); } #endregion } OnPropertyChanged(nameof(Items)); })); } catch { } finally { // NotifyItemsChanged(); // SyncronizingState = SyncronizingStateEnum.Completed; } }