public async static void StartBuyProduct(string product) { try { SessionLog.RecordTrace("Buying " + product); try { #if WINDOWS_PHONE string receipt = await CurrentApp.RequestProductPurchaseAsync(product, false); #endif } catch (Exception ex) { LittleWatson.ReportException(ex); SessionLog.RecordTraceValue("Buy " + product, "Failed"); // temporarilly suppress ads //MessageBox.Show(AppResources.StoreException); //AppStats.Current.TemporarySuppressAds(); } AppStats.Current.CheckPurchases(); //#if !DEBUG // if (!AppStats.Current.ShouldShowAds) // Views.Advertisement.HideAll(); //#endif } catch (Exception ex) { LittleWatson.ReportException(ex); } Navigate.BackFromFeedback(); }
public static bool InitSession() { bool IsExpired = false; try { if (AppStats.Current.Version.CompareTo(AppStats.Current.ExpiredVersion) != 1) { if (DateTime.Now > AppStats.Current.LastUpgrade.AddMonths(AppStats.Current.ExpiredMonths)) { IsExpired = true; } } } catch (Exception ex) { LittleWatson.ReportException(ex); if (DateTime.Now > AppStats.Current.LastUpgrade.AddMonths(3)) { IsExpired = true; } } if (IsExpired) { SessionLog.RecordTrace("App Expired"); if (MessageBox.Show(AppResources.ExpiredMessage, AppResources.ExpiredCaption, MessageBoxButton.OKCancel) == MessageBoxResult.OK) { (new Microsoft.Phone.Tasks.MarketplaceDetailTask()).Show(); } SessionLog.RecordTrace("Terminating"); Application.Current.Terminate(); } //UserSettings.SelectedProperties = new List<Property>() { StandardProperty.Calories, StandardProperty.TotalFat, StandardProperty.Carbs, StandardProperty.Protein }; // processes live tile and other settings: var x = UserSettings.Current; if (AppStats.Current.SessionId == 1) { MessageQueue.Push(AppStats.Current); } else { MessageQueue.StartPump(); } return(true); }
// Code to execute when the application is closing (eg, user hit Back) // This code will not execute when the application is deactivated private void Application_Closing(object sender, ClosingEventArgs e) { SessionLog.RecordTrace("Application_Closing"); SessionLog.Push(); }
// Code to execute when the application is deactivated (sent to background) // This code will not execute when the application is closing private void Application_Deactivated(object sender, DeactivatedEventArgs e) { SessionLog.RecordTrace("Application_Deactivated"); SessionLog.Push(); }
public static bool InitSession(Context ApplicationContext) #endif { LastInitCalled = DateTime.Now; if (IsSessionInitialized) { return(false); } //FoodJournal.Model.Data.FoodJournalBackup.Log("InitSession", null, null); IsSessionInitialized = true; // if we're still getting too many session logs, we could consider only proceeding here if FinalizeSession succeeded longer than 1 hour ago or something AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => { LittleWatson.ReportException(e.ExceptionObject as Exception, "unhandledexception"); if (e.IsTerminating) { FinalizeSession(); } }; AppDomain.CurrentDomain.ProcessExit += (object sender, EventArgs e) => { SessionLog.Push(); }; #if WINDOWS_PHONE if (DateTime.Now > AppStats.Current.LastUpgrade.AddMonths(3)) { #else FoodJournal.Android15.AlarmService.ResetNotifications(); InitializeLanguage(); if (DateTime.Now > AppStats.Current.LastUpgrade.AddMonths(48)) { #endif SessionLog.RecordTrace("App Expired"); #if WINDOWS_PHONE if (MessageBox.Show(AppResources.ExpiredMessage, AppResources.ExpiredCaption, MessageBoxButton.OKCancel) == MessageBoxResult.OK) { (new Microsoft.Phone.Tasks.MarketplaceDetailTask()).Show(); } SessionLog.RecordTrace("Terminating"); Application.Current.Terminate(); #else new AlertDialog.Builder(ApplicationContext) .SetPositiveButton("Ok", (sender, args) => { //Navigate.navigationContext = ApplicationContext; Navigate.StartReviewTask(); }) .SetNegativeButton("Cancel", (sender, args) => { SessionLog.RecordTrace("Terminating"); throw new Exception(); }) .SetMessage(AppResources.ExpiredMessage) .SetTitle(AppResources.ExpiredCaption) .Create() .Show(); return(false); #endif } // UserSettings.Current.SelectedProperties = new List<Property> () { // StandardProperty.Calories, // StandardProperty.TotalFat, // StandardProperty.Carbs, // StandardProperty.Protein // }; try { // processes live tile and other settings: var x = UserSettings.Current; } catch (Exception ex) { LittleWatson.ReportException(ex); } // 9/6/15: I thikn this is not needed to be done this quickly anymore, and its a pretty heavy operation (loading SQL dependencies, etc) // commenting out for now // 9/19/15: this is messing with purchase stats, so bringing it back, but asynch for now BackgroundTask.Start(4000, () => { if (AppStats.Current.SessionId == 1) { MessageQueue.Push(AppStats.Current); } else { MessageQueue.StartPump(); } }); SyncQueue.StartLoad(); return(true); }
private static void Pump(Platform.NetworkConnectionType connectionType) { //#if DEBUG //if (FoodJournal.ViewModels.ScreenshotVM.InScreenshot) // return; //#endif try { if (connectionType == Platform.NetworkConnectionType.None) { return; } if (InHere) { PumpAgain = true; SessionLog.RecordTrace("Attempting to sync while already syncing"); return; } InHere = true; PumpAgain = false; var messages = new List <Package> (); var working = new List <PendingPost> (); List <PendingPost> PostQueue = null; try { ThreadSync.WaitOne(); // Wait till we have a sync signal, and clear the signal PostQueue = state.PostQueue.Where(x => x.State == PendingPost.SyncState.pending || x.State == PendingPost.SyncState.retry).ToList(); } catch (Exception ex) { LittleWatson.ReportException(ex); } finally { ThreadSync.Set(); // Set the signal for the next thread to go if it comes to it } int totallength = 0; foreach (var item in PostQueue) { var pkg = item.ToPackage(); if (messages.Count > 0 && totallength + pkg.Contents.Length > TotalMessageSizeLimit) { PumpAgain = true; break; } else { messages.Add(pkg); working.Add(item); totallength += pkg.Contents.Length; System.Diagnostics.Debug.WriteLine(string.Format("Posting {0} {1} {2}", pkg.Type, pkg.Key, pkg.ClientTime)); } } if (messages.Count > 0) { try { SyncService.Post(messages); } catch (Exception ex) { ReportQueueException(ex); foreach (var i in working.ToArray()) { if (i.Retry >= MAXRETRY) { //i.State = PendingPost.SyncState.abandoned; state.PostQueue.Remove(i); } else { i.State = PendingPost.SyncState.retry; i.Retry++; working.Remove(i); } } } try { ThreadSync.WaitOne(); // Wait till we have a sync signal, and clear the signal foreach (var i in working) { state.PostQueue.Remove(i); } } catch (Exception ex) { LittleWatson.ReportException(ex); } finally { ThreadSync.Set(); // Set the signal for the next thread to go if it comes to it } SaveState(); } } catch (Exception ex) { ReportQueueException(ex); } InHere = false; if (PumpAgain) { StartPump(); } return; }
private static void Pump(Platform.NetworkConnectionType connectionType) { try { if (connectionType == Platform.NetworkConnectionType.None) { return; } if (InHere) { PumpAgain = true; SessionLog.RecordTrace("Attempting to pump while already pumping"); return; } InHere = true; PumpAgain = false; var messages = new List <Message> (); var infomessages = new List <String> (); int totallength = 0; foreach (var item in MessageQueueDB.SelectWhere(m => m.Processed == null)) { var msg = new Message() { Key = item.Id.ToString(), MessageType = item.MessageType, Body = item.Message }; if (totallength + msg.Body.Length > TotalMessageSizeLimit) { if (messages.Count == 0) { messages.Add(msg); infomessages.Add("Msg " + msg.Key + " truncated from " + msg.Body.Length.ToString()); msg.Body = msg.Body.Substring(0, TotalMessageSizeLimit); } PumpAgain = true; break; } else { messages.Add(msg); totallength += msg.Body.Length; #if ANDROID try { // 3/25/15: no more retry for large messages // trying this for Android first, if successfull we may as well apply to WinPhone if (msg.Body.Length > LargeMessage) { item.Processed = DateTime.Now; MessageQueueDB.Update(item); } } catch (Exception ex) { ReportQueueException(ex); } #endif } } if (messages.Count > 0) { foreach (var info in infomessages) { messages.Add(new Message() { Key = "0", MessageType = "Info", Body = info }); } var svc = Services.NewServiceClient(); svc.PushCompleted += (x, y) => { InHere = false; // mark committed messages as processed in the database if (y.Error != null) { ReportQueueException(y.Error); } else { if (y.Result != null) { try { foreach (var result in y.Result) { int i; if (result.Key.Length > 8) { ParseLongResult(result.Key); } else if (int.TryParse(result.Key, out i) && i > 0) { foreach (var m in MessageQueueDB.SelectWhere(m => m.Id == i)) { m.Processed = DateTime.Now; MessageQueueDB.Update(m); } } } } catch (Exception ex) { LittleWatson.ReportException(ex); } } } InHere = false; if (PumpAgain) { StartPump(); } else { SessionLog.EndPerformance("Push"); } }; var upd = AppStats.Current.CultureSettingsLastUpdated.ToString("yyyy/MM/dd"); svc.PushAsync(AppStats.Current.AppInstance, AppStats.Current.Culture, AppStats.Current.Version + "?" + upd, messages); return; } } catch (Exception ex) { ReportQueueException(ex); } InHere = false; return; }