Example #1
0
        /// <summary>
        /// Gets a specified chunk of the levels on the server by a given author
        /// </summary>
        /// <param name="username">User to get levels from</param>
        /// <param name="chunk">chunk of levels to get</param>
        /// <returns>The chunk requested</returns>
        public static List <QuizInfo> GetQuizzesByAuthorChunked(string username = "******", int chunk = 1)
        {
            List <string[]> quizDatas = ServerOperations.GetQuizzesByAuthorName(username, chunk);

            return(ListOfDataToQuizInfo(quizDatas));
        }
Example #2
0
        /// <summary>
        /// Gets a specified chunk of the levels on the server with a given string in their name
        /// </summary>
        /// <param name="quizName">search string for level names</param>
        /// <param name="chunk">chunk of levels to get</param>
        /// <returns>The chunk requested</returns>
        public static List <QuizInfo> GetQuizzesByQuizNameChunked(string quizName, int chunk = 1)
        {
            List <string[]> quizData = ServerOperations.GetQuizzesByQuizName(quizName, chunk);

            return(ListOfDataToQuizInfo(quizData));
        }
 /// <summary>
 /// Delete the user's account in a background task.
 /// </summary>
 /// <param name="password">the current password of the account.</param>
 /// <returns></returns>
 private OperationReturnMessage DeleteAccount(string password)
 {
     Device.BeginInvokeOnMainThread(() => this.LabelDeleteAccountMessage.Text = "Waiting...");
     return(ServerOperations.DeleteAccount(CredentialManager.Username, password.Trim()));
 }
 /// <summary>
 /// Confirm the email associated with the account in a background task.
 /// </summary>
 /// <param name="token">The confirmation token sent to the user's email.</param>
 /// <returns></returns>
 private OperationReturnMessage ConfirmEmail(string token)
 {
     Device.BeginInvokeOnMainThread(() => this.LabelConfirmEmailMessage.Text = "Waiting...");
     return(ServerOperations.ConfirmEmail(CredentialManager.Username, token.Trim()));
 }
 /// <summary>
 /// Change the user's email in a background task.
 /// </summary>
 /// <param name="password">The current password of the account.</param>
 /// <param name="newEmail">The new email.</param>
 /// <returns></returns>
 private OperationReturnMessage ChangeEmail(string password, string newEmail)
 {
     Device.BeginInvokeOnMainThread(() => this.LabelChangeEmailMessage.Text = "Waiting...");
     return(ServerOperations.ChangeEmail(CredentialManager.Username, password.Trim(), newEmail.Trim()));
 }
Example #6
0
        /// <summary>
        /// Updates the local database by syncing with the server
        /// </summary>
        /// <returns>an awaitable task for the completion of syncing</returns>
        public static async Task UpdateLocalDatabaseAsync()
        {
            if (App.Path != null && App.UserPath.Length > 2)
            {
                RealmConfiguration threadConfig = App.realmConfiguration(RosterPath);
                Realm threadInstance            = Realm.GetInstance(threadConfig);

                List <QuizInfo> QuizInfos = new List <QuizInfo>(threadInstance.All <QuizInfo>());
                if (CrossConnectivity.Current.IsConnected)
                {
                    for (int i = 0; i < QuizInfos.Count(); i++)
                    {
                        if (CredentialManager.IsLoggedIn)
                        {
                            if (QuizInfos[i].IsDeletedLocally)
                            {
                                if (await ServerOperations.DeleteQuiz(QuizInfos[i].DBId) == OperationReturnMessage.True)
                                {
                                    string toDeleteDBId = QuizInfos[i].DBId;
                                    QuizInfos.Remove(QuizInfos[i]);
                                    DeleteQuizInfo(toDeleteDBId);
                                }
                            }
                            else if (QuizInfos[i].SyncStatus != (int)SyncStatusEnum.NotDownloadedAndNeedDownload)
                            {
                                string lastModifiedDate = ServerOperations.GetLastModifiedDate(QuizInfos[i].DBId);
                                if (lastModifiedDate == "") // returns empty string could not reach server
                                {
                                    QuizInfo copy = new QuizInfo(QuizInfos[i])
                                    {
                                        SyncStatus = (int)SyncStatusEnum.Offline // 3 represents offline
                                    };
                                    EditQuizInfo(copy, threadInstance);
                                }
                                else
                                {
                                    // Server returns "false" if quiz is not already on the server
                                    if (lastModifiedDate == "false" || lastModifiedDate == null)
                                    {
                                        QuizInfo copy = new QuizInfo(QuizInfos[i])
                                        {
                                            SyncStatus = (int)SyncStatusEnum.NeedUpload // 1 represents need upload
                                        };
                                        EditQuizInfo(copy, threadInstance);
                                    }
                                    else
                                    {
                                        DateTime localModifiedDateTime  = Convert.ToDateTime(QuizInfos[i].LastModifiedDate);
                                        DateTime serverModifiedDateTime = Convert.ToDateTime(lastModifiedDate);
                                        if (localModifiedDateTime > serverModifiedDateTime)
                                        {
                                            QuizInfo copy = new QuizInfo(QuizInfos[i])
                                            {
                                                SyncStatus = (int)SyncStatusEnum.NeedUpload // 1 represents need upload
                                            };
                                            EditQuizInfo(copy, threadInstance);
                                        }
                                        else if (localModifiedDateTime < serverModifiedDateTime)
                                        {
                                            QuizInfo copy = new QuizInfo(QuizInfos[i])
                                            {
                                                SyncStatus = (int)SyncStatusEnum.NeedDownload // 0 represents needs download
                                            };
                                            EditQuizInfo(copy, threadInstance);
                                        }
                                        else if (localModifiedDateTime == serverModifiedDateTime)
                                        {
                                            QuizInfo copy = new QuizInfo(QuizInfos[i])
                                            {
                                                SyncStatus = (int)SyncStatusEnum.Synced // 2 represents in sync
                                            };
                                            EditQuizInfo(copy, threadInstance);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            QuizInfo copy = new QuizInfo(QuizInfos[i])
                            {
                                SyncStatus = (int)SyncStatusEnum.Synced // 2 represents in sync
                            };
                            EditQuizInfo(copy, threadInstance);
                        }
                    }

                    string[] dbIds = new string[QuizInfos.Count];
                    for (int i = 0; i < dbIds.Length; i++)
                    {
                        dbIds[i] = QuizInfos[i].DBId;
                    }

                    List <string[]> missingQuizs = ServerOperations.GetMissingQuizzesByAuthorName(CredentialManager.Username, dbIds);
                    foreach (string[] missingQuiz in missingQuizs)
                    {
                        QuizInfo info = new QuizInfo
                        {
                            DBId             = missingQuiz[0],
                            AuthorName       = missingQuiz[1],
                            QuizName         = missingQuiz[2],
                            Category         = missingQuiz[3],
                            LastModifiedDate = missingQuiz[4],
                            SubscriberCount  = int.Parse(missingQuiz[5]),
                            SyncStatus       = (int)SyncStatusEnum.NotDownloadedAndNeedDownload
                        };
                        threadInstance.Write(() =>
                        {
                            threadInstance.Add(info);
                        });
                    }
                }
                else
                {
                    for (int i = 0; i < QuizInfos.Count; i++)
                    {
                        QuizInfo copy = new QuizInfo(QuizInfos[i])
                        {
                            SyncStatus = (int)SyncStatusEnum.Offline // 3 represents offline
                        };
                        EditQuizInfo(copy, threadInstance);
                    }
                }
            }
        }
Example #7
0
        /// <summary>
        /// Loads the profile content if the user is logged in.
        /// </summary>
        /// <returns> </returns>
        private async Task UpdateProfileContentAsync(string category)
        {
            if (!this.IsContentLoading)
            {
                this.IsContentLoading         = true;
                this.QuizNumber.IsVisible     = true;
                this.PickerCategory.IsVisible = false;
                this.PickerCategory.IsEnabled = false;
                this.StackLayoutQuizStack.Children.Clear();
                this.StackLayoutQuizStack.IsEnabled = false;
                this.ActivityIndicator.IsVisible    = true;
                this.ActivityIndicator.IsRunning    = true;

                await Task.Run(async() =>
                {
                    await this.SetupQuizzes(category);
                    int createdCountFromServer = ServerOperations.GetNumberOfQuizzesByAuthorName(CredentialManager.Username);
                    string frameMessage        = "";
                    if (createdCountFromServer >= 0) // Returns -1 if can't connect to server
                    {
                        if (createdCountFromServer == 0 &&
                            !QuizRosterDatabase.GetRoster()
                            .Any(quizInfo => quizInfo.AuthorName == CredentialManager.Username))
                        {
                            frameMessage = "You haven't made any quizzes yet!";
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                this.PickerCategory.IsVisible = false;
                                this.QuizNumber.IsVisible     = false;
                            });
                        }
                        else
                        {
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                this.QuizNumber.Text          = "You have published a total of " + createdCountFromServer + " quizzes!";
                                this.PickerCategory.IsVisible = true;
                                this.PickerCategory.IsEnabled = true;
                            });
                        }
                    }
                    else
                    {
                        frameMessage = "Could not connect to BizQuiz servers. Please try again later.";
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            this.PickerCategory.IsVisible = true;
                            this.PickerCategory.IsEnabled = true;
                        });
                    }

                    if (frameMessage != "")
                    {
                        Frame frame = new Frame()
                        {
                            CornerRadius      = 10,
                            HorizontalOptions = LayoutOptions.CenterAndExpand,
                            Content           = new Label
                            {
                                Text = frameMessage,
                                HorizontalTextAlignment = TextAlignment.Center,
                                FontSize = 38
                            }
                        };

                        Device.BeginInvokeOnMainThread(() =>
                                                       this.StackLayoutQuizStack.Children.Add(frame));
                    }
                });

                if (this.ToolbarItems.Count <= 0)
                {
                    ToolbarItem accountSettingsButton = new ToolbarItem();
                    accountSettingsButton.Clicked += this.ToolbarItemAccountSettings_Clicked;
                    accountSettingsButton.Icon     = ImageSource.FromFile("ic_settings_white_48dp.png") as FileImageSource;
                    this.ToolbarItems.Add(accountSettingsButton);
                }

                this.IsOnLoginPage = false;
                this.ActivityIndicator.IsRunning    = false;
                this.ActivityIndicator.IsVisible    = false;
                this.StackLayoutQuizStack.IsEnabled = true;
                this.IsContentLoading = false;
            }
        }