Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        internal override void RunQueryI(string Query, List <SearchResultVM> results, bool IsAsync)
        {
            if (!IsAsync)
            {
                return;
            }

            if (ShouldAbort)
            {
                return;
            }
            System.Threading.Thread.Sleep(500);

            if (ShouldAbort)
            {
                return;
            }
            if (!ServiceCallNeeded)
            {
                return;
            }

            SessionLog.RecordTraceValue("Service Query", this.ToString(), Query);
            RunQueryS(Query, results);
        }
Exemplo n.º 4
0
 public void SetGoal(Property property, Single value)
 {
     if (goals == null)
     {
         goals = new PropertyDictionary(string.Empty);
     }
     goals[property] = value;
     SessionLog.RecordTraceValue(property.ToString() + " goal", value.ToString());
     Save();
 }
Exemplo n.º 5
0
 public static void Truncate()
 {
     try {
         var ExpiredRows = DateTime.Now.Date.AddDays(-1 * RetentionMaxDays);
         var DeleteCount = MessageQueueDB.DeleteWhere(m => m.Created < ExpiredRows && m.Processed != null);
         if (DeleteCount > 0)
         {
             SessionLog.RecordTraceValue("Truncating Message Queue Rows", DeleteCount.ToString());
         }
     } catch (Exception ex) {
         ReportQueueException(ex);
     }
 }
Exemplo n.º 6
0
        private void UpdateStats()
        {
            if (AppInstance == null)
            {
                // new install
                                #if DEBUG
                //AppInstance = "DEBUGINSTANCE";
                AppInstance = (new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3)).ToString();
                                #else
                AppInstance = Guid.NewGuid().ToString();
                                #endif
                Culture = Thread.CurrentThread.CurrentUICulture.Name;
                InstalledProductKind = ProductKind.unknown;
                InstallDate          = DateTime.Now.Date;
                PreviousSessionDate  = InstallDate;
                UserId            = GetWindowsLiveAnonymousID();
                DeviceInfo        = GetDeviceInfo();
                DaysInStreak      = 1;
                LastTrialReminder = DateTime.MinValue;                 //DateTime.Now.Date;
                AdShows           = true;
                DeDupeDone        = true;

                Version = new AssemblyName(Assembly.GetExecutingAssembly().FullName).Version.ToString();
                SessionLog.RecordMilestone("New Install", Version);
            }

            // new or existing install

            if (Culture != Thread.CurrentThread.CurrentUICulture.Name)
            {
                SessionLog.RecordTraceValue("Culture changed", string.Format("From {0} to {1}", Culture, Thread.CurrentThread.CurrentUICulture.Name));
                Culture = Thread.CurrentThread.CurrentUICulture.Name;
            }

            SessionId = SessionId + 1;

            if (SessionId > 1)
            {
                DeviceInfo = "";
            }

            if (PreviousSessionDate < DateTime.Now.Date)
            {
                if (PreviousSessionDate == DateTime.Now.Date.AddDays(-1))
                {
                    DaysInStreak += 1;
                }
                else
                {
                    DaysInStreak = 1;
                }
                PreviousSessionDate = DateTime.Now.Date;
            }

            DaysSinceInstall = DateTime.Now.Date.Subtract(InstallDate).Days;

            if (InstalledProductKind == ProductKind.unknown)
            {
                GetInstalledProductKind();
            }

            CalculateTrialDays();

            CheckPurchases();

            if (LastUpgrade == DateTime.MinValue)
            {
                LastUpgrade = DateTime.Now;
            }

            var version = new AssemblyName(Assembly.GetExecutingAssembly().FullName).Version.ToString();
            if (Version != version)
            {
                SessionLog.RecordMilestone("Upgraded", string.Format("from {0} to {1}", Version, version));
                Version     = version;
                LastUpgrade = DateTime.Now;

                if (string.IsNullOrEmpty(UserId))
                {
                    UserId = GetWindowsLiveAnonymousID();
                    if (!string.IsNullOrEmpty(UserId))
                    {
                        SessionLog.RecordMilestone("UID", UserId);
                    }
                }
            }

            RecordPerf = ((new System.Random()).Next(10) == 0);
        }
Exemplo n.º 7
0
        public static void Migrate()
        {
            try
            {
                Database db = new Database();
                if (!db.DatabaseExists())
                {
                    return;
                }

                if (db.AllItems.Count() == 0 && db.AllSelections.Count() == 0)
                {
                    Logging.SessionLog.RecordMilestone("Deleting Legacy DB", "");
                    db.DeleteDatabase();
                    return;
                }

                DateTime start                = DateTime.Now;
                int      ExceptionCount       = 0;
                Dictionary <int, int> itemmap = new Dictionary <int, int>();

                Logging.SessionLog.RecordTraceValue("Database migration - item count", db.AllItems.Count().ToString());
                Logging.SessionLog.RecordTraceValue("Database migration - selection count", db.AllSelections.Count().ToString());

                var AllItems      = db.AllItems.ToList();
                var AllSelections = db.AllSelections.ToList();

                List <FoodItem> ToDeleteItems      = new List <FoodItem>();
                List <Entry>    ToDeleteSelections = new List <Entry>();

                foreach (FoodItem Item in AllItems)
                {
                    try
                    {
                        if (FoodJournal.Model.Data.FoodJournalDB.GetItemIDFromOldItemID(Item.Id) == -1)
                        {
                            var NewItem = new FoodJournal.Model.Data.FoodItemDO();

                            NewItem.Culture        = Item.Culture;
                            NewItem.DescriptionDB  = Item.Description;
                            NewItem.LastAmountDB   = Item.LastAmount.ToStorageString();
                            NewItem.NutritionDB    = Item.PropertyValues;
                            NewItem.OldDBID        = Item.Id;
                            NewItem.ServingSizesDB = Item.ServingSizesData;
                            NewItem.SourceID       = Item.SourceID;
                            NewItem.TextDB         = Item.Text;

                            FoodJournal.Model.Data.FoodJournalDB.SaveFoodItemDO(NewItem);

                            itemmap.Add(Item.Id, NewItem.Id);
                        }

                        ToDeleteItems.Add(Item);
                    }
                    catch (Exception ex) { ExceptionCount++; LittleWatson.ReportException(ex); }
                }

                foreach (Entry Selection in AllSelections)
                {
                    try
                    {
                        var NewSelection = new FoodJournal.Model.Data.EntryDO();
                        NewSelection.AmountScaleDB    = Selection.AmountScale;
                        NewSelection.AmountSelectedDB = Selection.AmountSelected.ToStorageString();
                        NewSelection.Date             = Selection.Date;
                        NewSelection.FoodItemType     = FoodJournal.Model.Data.FoodItemType.Food;
                        NewSelection.Period           = Selection.Period;

                        if (!itemmap.ContainsKey(Selection.ItemId))
                        {
                            itemmap.Add(Selection.ItemId, FoodJournal.Model.Data.FoodJournalDB.GetItemIDFromOldItemID(Selection.ItemId));
                        }

                        NewSelection.FoodItemId = itemmap[Selection.ItemId];

                        if (NewSelection.FoodItemId > 0)
                        {
                            FoodJournal.Model.Data.FoodJournalDB.SaveEntryDO(NewSelection);
                        }
                        else
                        {
                            SessionLog.RecordTraceValue("Missing FoodItem converting ItemSelection", Selection.ItemId.ToString());
                        }

                        ToDeleteSelections.Add(Selection);
                    }
                    catch (Exception ex) { ExceptionCount++; LittleWatson.ReportException(ex); }
                }


                foreach (Entry Selection in ToDeleteSelections)
                {
                    try
                    {
                        db.AllSelections.DeleteOnSubmit(Selection);
                        db.SubmitChanges();
                    }
                    catch (Exception ex) { db = new Database(); ExceptionCount++; LittleWatson.ReportException(ex); }
                }

                foreach (FoodItem Item in ToDeleteItems)
                {
                    try
                    {
                        db.AllItems.DeleteOnSubmit(Item);
                        db.SubmitChanges();
                    }
                    catch (Exception ex) { db = new Database(); ExceptionCount++; LittleWatson.ReportException(ex); }
                }

                Logging.SessionLog.RecordTraceValue("Database migration - exception count", ExceptionCount.ToString());
                Logging.SessionLog.RecordMilestone("Database migration - duration", string.Format("{0} s", DateTime.Now.Subtract(start).TotalSeconds));
            }
            catch (Exception ex) { LittleWatson.ReportException(ex); }
        }
Exemplo n.º 8
0
        // Code to execute on Unhandled Exceptions
        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        {
            if (e.ExceptionObject != null && e.ExceptionObject.StackTrace != null)
            {
                if (e.ExceptionObject.StackTrace.Contains("WebBrowser.Fire")) // ScriptNotifyEvent or LoadCompleted"))
                {
                    if (e.ExceptionObject.Message == "Parameter count mismatch." || e.ExceptionObject.Message == "Object reference not set to an instance of an object.")
                    {
                        // ad contol cretaors thought it was a good idea to randomly crash someone else's app :o
                        // just eat this exception
                        SessionLog.RecordTraceValue("Eaten exception", e.ExceptionObject.Message);
                        e.Handled = true;
                        return;
                    }
                }
            }

            if (e.ExceptionObject != null && e.ExceptionObject.Message != null)
            {
                if (e.ExceptionObject.Message.StartsWith("FrameworkDispatcher.Update has not been called.") ||
                    e.ExceptionObject.Message.Contains("Cannot create instance of type 'Microsoft.Phone.Controls.WebBrowser'"))
                {
                    // ad contol cretaors thought it was a good idea to randomly crash someone else's app :o
                    // just eat this exception
                    SessionLog.RecordTraceValue("Eaten exception", e.ExceptionObject.Message);
                    e.Handled = true;
                    return;
                }
            }

            Exception exception = e.ExceptionObject;

            if ((exception is XmlException || exception is NullReferenceException) && exception.ToString().ToUpper().Contains("INNERACTIVE"))
            {
                SessionLog.RecordTraceValue("Handled Inneractive exception {0}", exception.Message);
                e.Handled = true;
                return;
            }
            else if (exception is NullReferenceException && exception.ToString().ToUpper().Contains("SOMA"))
            {
                SessionLog.RecordTraceValue("Handled Smaato null reference exception {0}", exception.Message);
                e.Handled = true;
                return;
            }
            else if ((exception is System.IO.IOException || exception is NullReferenceException) && exception.ToString().ToUpper().Contains("GOOGLE"))
            {
                SessionLog.RecordTraceValue("Handled Google exception {0}", exception.Message);
                e.Handled = true;
                return;
            }
            else if (exception is ObjectDisposedException && exception.ToString().ToUpper().Contains("MOBFOX"))
            {
                SessionLog.RecordTraceValue("Handled Mobfox exception {0}", exception.Message);
                e.Handled = true;
                return;
            }
            else if ((exception is NullReferenceException || exception is XamlParseException) && exception.ToString().ToUpper().Contains("MICROSOFT.ADVERTISING"))
            {
                SessionLog.RecordTraceValue("Handled Microsoft.Advertising exception {0}", exception.Message);
                e.Handled = true;
                return;
            }

            LittleWatson.ReportException(e.ExceptionObject);
            //if (e.ExceptionObject.StackTrace != null && e.ExceptionObject.StackTrace.Contains("AdDuplex"))
            //    e.Handled = true;
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // An unhandled exception has occurred; break into the debugger
                System.Diagnostics.Debugger.Break();
            }
            //e.Handled = true;
        }
Exemplo n.º 9
0
        public static void AskForReviewIfAppropriate()
        {
            try
            {
                if (checkedForReview.AddHours(2) > DateTime.Now)
                {
                    return;
                }
                checkedForReview = DateTime.Now;

                                #if WINDOWS_PHONE
                Sale sale = AppStats.Current.CurrentSale;
                if (sale != null)
                {
                    if (sale.NumberOfSessionsBetween == 0 || AppStats.Current.SessionId % sale.NumberOfSessionsBetween == 0)
                    {
                        if (MessageBox.Show(sale.SubTitle, sale.Title, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                        {
                            SessionLog.RecordMilestone("Sale Accepted " + sale.ID, AppStats.Current.SessionId.ToString());
                            Navigate.StartBuyProduct(sale.productId);
                        }
                        else
                        {
                            if (sale.ID != null && sale.ID.StartsWith("test"))
                            {
                                SessionLog.RecordMilestone("Sale Declined " + sale.ID, AppStats.Current.SessionId.ToString());
                            }
                            else
                            {
                                SessionLog.RecordTraceValue("Sale Declined " + sale.ID, AppStats.Current.SessionId.ToString());
                            }
                        }

                        return;
                    }
                }
                                #endif

                FeedbackSettings feedbackSettings = AppStats.Current.FeedbackSettings;

                if (AppStats.Current.DaysSinceInstall < feedbackSettings.DaysTillStart)
                {
                    return;
                }
                if (UserSettings.Current.SuppressAskForReviewCount > feedbackSettings.NumberOfReAttempts)
                {
                    return;
                }
#if SUPPORTTRIAL
                if (AppStats.Current.InstalledProductKind == AppStats.ProductKind.Trial)
                {
                    return;
                }
#endif

                if (AppStats.Current.SessionId % feedbackSettings.NumberOfSessionsBetween != 0)
                {
                    return;
                }
                if (AppStats.Current.ReviewRequests >= feedbackSettings.NumberOfRequests)
                {
                    return;
                }
                AppStats.Current.ReviewRequests += 1;

                                #if WINDOWS_PHONE
                if (MessageBox.Show(AppResources.ReviewBody, AppResources.ReviewTitle, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    SessionLog.RecordMilestone("Review Request Accepted" + feedbackSettings.ID, AppStats.Current.SessionId.ToString());
                    Navigate.StartReviewTask();
                }
                else
                {
                    SessionLog.RecordTraceValue("Review Request Declined" + feedbackSettings.ID, AppStats.Current.SessionId.ToString());
                }
                                #else
                new AlertDialog.Builder(Navigate.navigationContext)
                .SetPositiveButton("Ok", (sender, args) =>
                {
                    SessionLog.RecordMilestone("Review Request Accepted" + feedbackSettings.ID, AppStats.Current.ReviewRequests.ToString());
                    Navigate.StartReviewTask();
                })
                .SetNegativeButton("Cancel", (sender, args) =>
                {
                    SessionLog.RecordTraceValue("Review Request Declined" + feedbackSettings.ID, AppStats.Current.ReviewRequests.ToString());
                })
                .SetMessage(AppResources.ReviewBody)
                .SetTitle(AppResources.ReviewTitle)
                .Create()
                .Show();
#endif
            }
            catch (Exception ex) {
                LittleWatson.ReportException(ex);
            }
        }