public static NetworkConnectionType GetConnectionTypeEx() { if (!Thread.CurrentThread.IsBackground) { throw new Exception("Can't get Connection Type on UI Thread (this can take up to 30 seconds)"); } try { #if WINDOWSPHONE if (!NetworkInterface.GetIsNetworkAvailable()) { return(NetworkConnectionType.None); } using (SessionLog.NewScope("Getting Network Type", null)) { var type = NetworkInterface.NetworkInterfaceType; NetworkConnectionTypeName = type.ToString(); SessionLog.RecordTraceValue("NetworkType", type.ToString()); switch (type) { case (NetworkInterfaceType.Wireless80211): return(NetworkConnectionType.Fast); case (NetworkInterfaceType.None): return(NetworkConnectionType.None); } } #endif } catch (Exception ex) { LittleWatson.ReportException(ex); } return(NetworkConnectionType.Slow); }
private void Requery(string syncID, bool loadCaches) { using (var log = SessionLog.NewScope("Requerying" + (loadCaches ? " 2" : ""), period.ToString())) { // Breakfast <- static list of entries // Breakfast Items // All Items // New Item // USDA List? // - simple // - nutrition items // - generic items List <FoodItem> shown = new List <FoodItem>(); List <Entry> list = Cache.GetEntryCache(date)[(int)period]; foreach (Entry e in list) { if (e.Item != null) { if (!shown.Contains(e.Item, FoodItemComparer.instance)) { shown.Add(e.Item); } } } var results = new ObservableCollection <SearchResultVM>(); //results.Clear(); int cnt = results.Count; foreach (var item in Cache.GetRecentCache(period)) { if (!shown.Contains(item.FlatItem, FoodItemComparer.instance)) { shown.Add(item.FlatItem); results.Add(new SearchResultRecentVM(item)); } } #if LegacyDB var enumerator = new Cache.PeriodEntryEnumerator(period); if (loadCaches) { enumerator.LoadAllDays(); } enumerator.ShouldLoadDay = () => { if (!loadCaches) { return(false); } if (ShouldStopQuery(syncID)) { log.SetState("Aborted"); return(false); } else { return(true); } }; while (enumerator.MoveNext()) { FoodItem item = enumerator.Current.Item; if (item != null) { if (!shown.Contains(item, FoodItemComparer.instance)) { shown.Add(item); results.Add(new SearchResultFoodItemVM(item)); } } } #endif //" + period.ToString().ToLower() + " if (results.Count != cnt) { results.Insert(cnt, new SearchResultHeaderVM(Strings.FromEnum("MyRecentItems", period.ToString()), 0)); } cnt = results.Count; int i = 0; var enumerator2 = new ResourceRecord2Enumerator(period); int MaxCommonItems = AppStats.Current.IncludePremiumItems ? MAXCOMMONITEMSPAID : MAXCOMMONITEMSFREE; while (i < MaxCommonItems && enumerator2.MoveNext()) { FoodItem item = enumerator2.Current; if (!shown.Contains(item, FoodItemComparer.instance)) { shown.Add(item); results.Add(new SearchResultFoodItemVM(item)); i++; } } if (results.Count != cnt) { results.Insert(cnt, new SearchResultHeaderVM(Strings.FromEnum("CommonItems", period.ToString()), 0)); } cnt = results.Count; if (loadCaches || Cache.AllItemsLoaded) { if (!Cache.AllItemsLoaded) { if (ShouldStopQuery(syncID)) { log.SetState("Aborted"); return; } } if (!Cache.AllItemsLoaded) { FoodJournalNoSQL.LoadItems(false, null); } } if (loadCaches) { //if (HasQuery) System.Threading.Thread.Sleep(500); if (ShouldStopQuery(syncID)) { log.SetState("Aborted"); return; } } else { while (results.Count > 12) { results.RemoveAt(12); } } foreach (var r in results) { r.Listener = this; } // todo: sync instead (how to deal with the removeat 12 though? this.ItemList = results; NotifyPropertyChanged("ItemList"); } }