Exemplo n.º 1
0
        public static void StartShareTask()
        {
            try
            {
                SessionLog.RecordMilestone("Share", AppStats.Current.SessionId.ToString());
#if WINDOWS_PHONE
                var task = new ShareLinkTask();
                task.LinkUri = new Uri("http://www.windowsphone.com/s?appid=2f44a06e-3d7c-4e11-b74d-9135949a1889", UriKind.Absolute);
                task.Title   = AppResources.ShareTitle;
                task.Message = AppResources.ShareMessage;
                task.Show();
#else
                Intent sharingIntent = new Intent(Intent.ActionSend);
                sharingIntent.AddFlags(ActivityFlags.NewTask);
                sharingIntent.SetType("text/plain");
                sharingIntent.PutExtra(Intent.ExtraSubject, AppResources.ShareTitle);
                //sharingIntent.PutExtra(Intent.ExtraText, AppResources.ShareMessage);
                //sharingIntent.PutExtra(Intent.ExtraEmail, "*****@*****.**");
                navigationContext.StartActivity(Intent.CreateChooser(sharingIntent, AppResources.Feedback_Share));
#endif
            }
            catch (Exception ex)
            {
                LittleWatson.ReportException(ex);
            }
            Navigate.BackFromFeedback();
        }
Exemplo n.º 2
0
        public static void StartReviewTask()
        {
            try
            {
                SessionLog.RecordMilestone("Rate and Review", AppStats.Current.SessionId.ToString());
                UserSettings.Current.SuppressAskForReviewCount += 1; //SuppressAskForReview = true;
#if WINDOWS_PHONE
                Microsoft.Phone.Tasks.MarketplaceReviewTask detailTask = new Microsoft.Phone.Tasks.MarketplaceReviewTask();
                detailTask.Show();
#else
                Android.Net.Uri uri        = Android.Net.Uri.Parse("market://details?id=" + navigationContext.ApplicationContext.PackageName);
                Intent          goToMarket = new Intent(Intent.ActionView, uri);
                //goToMarket.AddFlags(ActivityFlags.NewTask);
                try
                {
                    navigationContext.StartActivity(goToMarket);
                }
                catch (ActivityNotFoundException)
                {
                    navigationContext.StartActivity(new Intent(Intent.ActionView, Android.Net.Uri.Parse("http://play.google.com/store/apps/details?id=" + navigationContext.ApplicationContext.PackageName)));
                }
#endif
            }
            catch (Exception ex)
            {
                LittleWatson.ReportException(ex);
            }
            Navigate.BackFromFeedback();
        }
Exemplo n.º 3
0
        public void CheckPurchases()
        {
                        #if WINDOWS_PHONE
            try
            {
                //                if (InstalledProductKind == ProductKind.unknown) return;

                        #if !DEBUG
                if (InstalledProductKind == ProductKind.Trial)
                {
                    var licenseInfo = new Microsoft.Phone.Marketplace.LicenseInformation();
                    if (!licenseInfo.IsTrial())
                    {
                        SessionLog.RecordMilestone("Converted from Trial to Paid", SessionId.ToString());
                        InstalledProductKind = ProductKind.Paid;
                        Save();
                    }
                }
                        #endif

                if (InstalledProductKind == ProductKind.Free && AdShows)
                {
                    var productLicenses = CurrentApp.LicenseInformation.ProductLicenses;
                    foreach (var license in productLicenses.Values)
                    {
                        if (license.IsActive && license.ProductId == RemoveAdsProduct)
                        {
                            SessionLog.RecordMilestone("RemoveAdsProduct Purchased", AppStats.Current.SessionId.ToString());
                            InstalledProductKind = ProductKind.Paid;
                            AdShows = false;
                            Save();
                        }

                        if (license.IsActive && license.ProductId.StartsWith(PremiumProduct))
                        {
                            SessionLog.RecordMilestone(license.ProductId + " Purchased", AppStats.Current.SessionId.ToString());
                            InstalledProductKind = ProductKind.Paid;
                            AdShows         = false;
                            MultiMealHidden = false;
                            Save();
                        }
                    }
                }
            }
            catch (Exception ex) { LittleWatson.ReportException(ex); }
                        #endif
        }
Exemplo n.º 4
0
        private void PinToStart_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            try
            {
                SessionLog.RecordMilestone("Pin To Start", AppStats.Current.SessionId.ToString());

                string tileId = new Random().Next().ToString();
                Uri    mp     = new Uri(@"/Views/Splash.xaml?" + "tileid=" + tileId, UriKind.Relative);

                IconicTileData tileData = new IconicTileData();
                tileData.Title          = "@AppResLib.dll,-200";
                tileData.IconImage      = new Uri(@"/Resources/IconTransparent.png", UriKind.Relative);
                tileData.SmallIconImage = new Uri(@"/Resources/IconTransparent.png", UriKind.Relative);
                ShellTile.Create(mp, tileData, false);

                (sender as Button).Visibility = System.Windows.Visibility.Collapsed;
            }
            catch (Exception ex) { LittleWatson.ReportException(ex); }
        }
Exemplo n.º 5
0
        public void RegisterPurchase(string productid)
        {
            try {
                SessionLog.RecordMilestone(productid + " Purchased", AppStats.Current.SessionId.ToString());
                InstalledProductKind = ProductKind.Paid;
                AdShows         = false;
                MultiMealHidden = false;
                Save();

                //foreach (var a in FoodJournal.Android15.Adapters.PeriodListAdapter.AllAds)
                //    try {
                //        a.Visibility = Android.Views.ViewStates.Gone;
                //    } catch (Exception ex) {
                //        LittleWatson.ReportException (ex);
                //    }
            } catch (Exception ex) {
                LittleWatson.ReportException(ex);
            }
        }
Exemplo n.º 6
0
        private void BuyProduct(string product)
        {
            try
            {
                SessionLog.RecordMilestone("Buying " + product, AppStats.Current.SessionId.ToString());
                if (_serviceConnection != null)
                {
#if DEBUG
                    _serviceConnection.BillingHandler.BuyProduct("android.test.purchased", "inapp", "");
#else
                    _serviceConnection.BillingHandler.BuyProduct(product, "inapp", "");
#endif
                }
            }
            catch (Exception ex)
            {
                LittleWatson.ReportException(ex);
            }
        }
Exemplo n.º 7
0
        public static void StartEmailTask()
        {
            try
            {
                SessionLog.RecordMilestone("Email", AppStats.Current.SessionId.ToString());
                var to      = AppStats.email;
                var subject = AppResources.FeedbackSubject;

                #if AMAZON
                try { subject += " (z" + AppStats.Current.AppInstance.ToString().Substring(0, 6) + ")"; }
                #else
                #if V16
                try { subject += " (v" + AppStats.Current.AppInstance.ToString().Substring(0, 6) + ")"; }
                #else
                try { subject += " (" + AppStats.Current.AppInstance.ToString().Substring(0, 6) + ")"; }
                #endif
                #endif
                catch (Exception ex) { LittleWatson.ReportException(ex); }

#if WINDOWS_PHONE
                var task = new EmailComposeTask();
                task.To      = to;
                task.Subject = subject;
                task.Show();
#else
                //Intent emailIntent = new Intent(Intent.ActionSendto, Android.Net.Uri.FromParts("mailto",to, null));
                Intent emailIntent = new Intent(Intent.ActionSendto);
                emailIntent.AddFlags(ActivityFlags.NewTask);
                Android.Net.Uri Uri = Android.Net.Uri.Parse("mailto:" + to + "?subject=" + subject);
                emailIntent.SetData(Uri);
                //emailIntent.SetType("text/plain");
                //emailIntent.PutExtra(Intent.ExtraEmail, new string[]{to});
                //emailIntent.PutExtra(Intent.ExtraSubject, subject);
                //emailIntent.PutExtra(Intent.ExtraText, AppResources.Feedback_EmailText);
                navigationContext.StartActivity(Intent.CreateChooser(emailIntent, AppResources.Feedback_Email));
#endif
            }
            catch (Exception ex)
            {
                LittleWatson.ReportException(ex);
            }
            Navigate.BackFromFeedback();
        }
Exemplo n.º 8
0
        protected void PinToStart(object sender, EventArgs args)
        {
            try
            {
                SessionLog.RecordMilestone("Pin To Start", AppStats.Current.SessionId.ToString());

                var shortcutIntent = new Intent(this, typeof(Splash));
                shortcutIntent.SetAction(Intent.ActionMain);

                var iconResource = Intent.ShortcutIconResource.FromContext(
                    this, Resource.Drawable.ic_launcher);

                var intent = new Intent();
                intent.PutExtra(Intent.ExtraShortcutIntent, shortcutIntent);
                intent.PutExtra(Intent.ExtraShortcutName, AppResources.AppTitle);
                intent.PutExtra(Intent.ExtraShortcutIconResource, iconResource);
                intent.PutExtra("duplicate", false);
                intent.SetAction("com.android.launcher.action.INSTALL_SHORTCUT");
                SendBroadcast(intent);

                (sender as Button).Visibility = ViewStates.Gone;
            }
            catch (Exception ex) { LittleWatson.ReportException(ex); }
        }
Exemplo n.º 9
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.º 10
0
        public static void Migrate()
        {
            try
            {
                                #if WINDOWS_PHONE
                FoodJournalDB db = new FoodJournalDB(false);
                                #else
                FoodJournalDB db = new FoodJournalDB(true);
                                #endif

                if (!db.DatabaseExists())
                {
                    return;
                }

                if (db.Table <FoodItemDO>().Count() == 0 && db.Table <EntryDO>().Count() == 0)
                {
#if !WINDOWS_PHONE
                    db.Close();
#endif
                    Logging.SessionLog.RecordMilestone("Deleting Legacy FoodItem DB", "");
                    db.DeleteDatabase();
                    return;
                }

                                #if !WINDOWS_PHONE
                if (System.IO.File.Exists(DatabaseFilePath))
                {
                    db.Close();
                    System.IO.File.Copy(DatabaseFilePath, DatabaseFilePath.Replace(".db3", ".bak"));
                    db = new FoodJournalDB(true);
                }
                                #endif

                DateTime start = DateTime.Now;

                int ExceptionCount            = 0;
                Dictionary <int, int> itemmap = new Dictionary <int, int>();

                Logging.SessionLog.RecordTraceValue("Database migration - item count", db.Table <FoodItemDO>().Count().ToString());
                Logging.SessionLog.RecordTraceValue("Database migration - selection count", db.Table <EntryDO>().Count().ToString());

                var AllItems      = db.Table <FoodItemDO>().ToList();
                var AllSelections = db.Table <EntryDO>().ToList();

                List <FoodItemDO> ToDeleteItems      = new List <FoodItemDO>();
                List <EntryDO>    ToDeleteSelections = new List <EntryDO>();

                Dictionary <int, String> items     = new Dictionary <int, string>();
                List <DateTime>          savedates = new List <DateTime>();

                foreach (FoodItemDO item in AllItems)
                {
                    try
                    {
                        items.Add(item.Id, item.TextDB);

                        var NewItem = new FoodJournal.Model.FoodItem(item.TextDB, false);

                        NewItem.Culture        = item.Culture;
                        NewItem.DescriptionDB  = item.DescriptionDB;
                        NewItem.LastAmountDB   = item.LastAmountDB;
                        NewItem.NutritionDB    = item.NutritionDB;
                        NewItem.ServingSizesDB = item.ServingSizesDB;
                        NewItem.SourceID       = item.SourceID;

                        Cache.MergeItem(NewItem);

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

                foreach (EntryDO entry in AllSelections)
                {
                    try
                    {
                        var entryDate = DateTime.Parse(entry.Date);

                        var NewSelection = new FoodJournal.Model.Entry(entryDate, entry.Period, items[entry.FoodItemId]);
                        NewSelection.AmountScaleDB    = entry.AmountScaleDB;
                        NewSelection.AmountSelectedDB = entry.AmountSelectedDB;

                        Cache.AddEntry(NewSelection);

                        ToDeleteSelections.Add(entry);

                        if (!savedates.Contains(entryDate))
                        {
                            savedates.Add(entryDate);
                        }
                    }
                    catch (Exception ex) { ExceptionCount++; LittleWatson.ReportException(ex); }
                }

                foreach (Period period in PeriodList.All)
                {
                    foreach (DateTime date in savedates)
                    {
                        FoodJournalNoSQL.StartSaveDay(date, period);
                    }
                }

                int i = 120;
                while (i-- > 0 && FoodJournalNoSQL.IsSaving())
                {
                    System.Threading.Thread.Sleep(500);
                }

                if (i == 0)
                {
                    SessionLog.RecordMilestone("Upgrade failed in 1 minute", AllSelections.Count.ToString());
                    throw new Exception("Upgrade failed in 1 minute");
                }

                foreach (EntryDO Selection in ToDeleteSelections)
                {
                    try
                    {
                                                #if WINDOWS_PHONE
                        db.Table <EntryDO>().DeleteOnSubmit(Selection);
                        db.SubmitChanges();
                                                #else
                        db.Delete <EntryDO>(Selection.Id);
                                                #endif
                    }
                    catch (Exception ex) { db = new FoodJournalDB(false); ExceptionCount++; LittleWatson.ReportException(ex); }
                }

                foreach (FoodItemDO Item in ToDeleteItems)
                {
                    try
                    {
                                                #if WINDOWS_PHONE
                        db.Table <FoodItemDO>().DeleteOnSubmit(Item);
                        db.SubmitChanges();
                                                #else
                        db.Delete <FoodItemDO>(Item.Id);
                                                #endif
                    }
                    catch (Exception ex) { db = new FoodJournalDB(false); ExceptionCount++; LittleWatson.ReportException(ex); }
                }

                Logging.SessionLog.RecordMilestone("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.º 11
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);
            }
        }