Ejemplo n.º 1
0
        /// <summary>
        /// Loads necessary data and perfor initialisation checks
        /// </summary>
        private void InitialiseApp()
        {
            try
            {
                SetLicenseInfo();
                var isDbUpgraded = AppUtility.UpdateSchema();

                if (!isDbUpgraded)
                {
                    AppUtility.MigrateXmlDataToDatabase();
                    ReminderUtility.ClearAllRemindersOnUpgrade();
                    BirthdayUtility.SaveLocalCards();
                }

                UpdateLocalizedRes();

                CheckFriendBirthdayFile();
            }
            catch (Exception ex)
            {
                MessageBox.Show(AppResources.ErrAppInitialise, AppResources.ErrInitialiseTitle, MessageBoxButton.OK);
                AppLog.WriteToLog(DateTime.Now, "Error during initialisation. Error : " + ex.Message + ". Stack : " + ex.StackTrace, LogLevel.Error);
                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            }
        }
        private async Task SaveFriends()
        {
            try
            {
                var friendListTask = await DownloadFriends(App.AccessToken);

                friendListTask   = App.IsTrial ? friendListTask.Take(100).ToList() : friendListTask;
                _savedFriendList = BirthdayUtility.GetFriendList();

                if (!App.UserPreferences.ContactSync.FacebookSyncEnabled.HasValue || App.UserPreferences.ContactSync.FacebookSyncEnabled.Value)
                {
                    //display status message
                    StatusText.Text = AppResources.RetrievingFbFriend;
                    foreach (var user in friendListTask)
                    {
                        //check if the friend exists already
                        if (_savedFriendList != null && _savedFriendList.Count > 0 &&
                            _savedFriendList.Exists(f => !String.IsNullOrEmpty(f.FacebookId) &&
                                                    f.FacebookId.Equals(user.FacebookId, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            UpdateExistingFriendToList(user, _savedFriendList.Find(x => !String.IsNullOrEmpty(x.FacebookId) &&
                                                                                   x.FacebookId.Equals(user.FacebookId, StringComparison.InvariantCultureIgnoreCase)));
                        }
                        else
                        {
                            BirthdayUtility.AddNewFriend(user);
                        }
                    }
                }

                //Save friend list to file
                StatusText.Text = AppResources.SaveBdays;

                //update the reminder list
                StatusText.Text = AppResources.CreateBdayReminder;
                ReminderUtility.UpdateCalendarEntries();
                //BirthdayUtility.downloadProfileImages(isSync);

                //update last sync time in settings and app user preferences
                App.UserPreferences.ContactSync.LastSync = DateTime.Now;
                if (App.UserPreferences != null)
                {
                    SettingsUtility.UpdateUserSettings(App.UserPreferences);
                }

                await BirthdayUtility.SyncCards(App.UserPreferences.UserDetails.FacebookId);

                //update card sync status
                App.UserPreferences.ContactSync.CardsSynced = true;
                if (App.UserPreferences != null)
                {
                    SettingsUtility.UpdateUserSettings(App.UserPreferences);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, AppResources.ErrBuildBdayList, MessageBoxButton.OK);
                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Populate fb friends if not yet populated
        /// </summary>
        private void CheckFriendBirthdayFile()
        {
            int recordCount;

            using (var context = new BirthdayDataContext(Database.DbConnectionString))
            {
                recordCount = context.Friends.Count();
            }

            if (recordCount == 0)
            {
                var setupContactsMessageBox = new CustomMessageBox
                {
                    Height             = 300,
                    Caption            = AppResources.BdaySetupTitle,
                    Message            = AppResources.BdaySetupMessage,
                    LeftButtonContent  = AppResources.YesLabel,
                    RightButtonContent = AppResources.LaterLabel,
                    VerticalAlignment  = VerticalAlignment.Center
                };

                setupContactsMessageBox.Dismissed += CustomMessageBoxDismissed;
                setupContactsMessageBox.Show();
            }
            else
            {
                ReminderUtility.UpdateCalendarEntries();

                if (_isSourceToast)
                {
                    MessageBox.Show(AppResources.ReminderUpdateSuccess, AppResources.ReminderUpdatedTitle, MessageBoxButton.OK);
                }
                if (IsSyncRequired())
                {
                    var result = MessageBox.Show(AppResources.ContactNotUpdatedMessage, AppResources.SyncContactsLabel, MessageBoxButton.OKCancel);
                    NavigationService.Navigate(result.Equals(MessageBoxResult.OK)
                        ? new Uri("/FacebookLogin.xaml?" + UriParameter.IsSyncScneario + "=Yes", UriKind.Relative)
                        : new Uri("/MainPage.xaml", UriKind.Relative));
                }
                else
                {
                    NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
                }
            }
        }