Ejemplo n.º 1
0
        /// <summary>
        /// Handles the clicked async.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        async void Handle_ClickedAsync(object sender, System.EventArgs e)
        {
            bool allCompleted = true;

            foreach (var view in feedbackStackLayout.Children)
            {
                var mView = view as RatingStars;

                if (mView != null)
                {
                    if (mView.SelectedRating == -1)
                    {
                        allCompleted = false;
                    }
                }
            }

            if (allCompleted)
            {
                string returnString = ViewTools.CommaSeparatedValue("Question,Rating",
                                                                    feedbackStackLayout, startTime,
                                                                    DateTime.Now.Subtract(startTime));

                int result = await App.Database.SaveItemAsync(new SleepFeedbackModel()
                {
                    CSV = returnString
                });


                if (CrossConnectivity.Current.IsConnected)
                {
                    CancellationTokenSource cancelSrc = new CancellationTokenSource();
                    ProgressDialogConfig    config    = new ProgressDialogConfig()
                                                        .SetTitle("Uploading to Server")
                                                        .SetIsDeterministic(false)
                                                        .SetMaskType(MaskType.Black)
                                                        .SetCancel(onCancel: cancelSrc.Cancel);

                    using (IProgressDialog progress = UserDialogs.Instance.Progress(config))
                    {
                        await DropboxServer.UploadFeedback(new System.IO.MemoryStream(Encoding.UTF8.GetBytes(returnString)), App.Database.GetLargestFeedbackID());

                        await Task.Delay(100);
                    }
                }

                App.RefreshServer = true;

                await Navigation.PopModalAsync();
            }
            else
            {
                await UserDialogs.Instance.AlertAsync("Please answer all questions", Title = "Error", okText : "Okay");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Send message to cloud
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ToolbarItem_Clicked_2(object sender, EventArgs e)
        {
            if (CrossConnectivity.Current.IsConnected)
            {
                PromptResult userMessage = await UserDialogs.Instance.PromptAsync(new PromptConfig()
                                                                                  .SetMessage("Enter your message")
                                                                                  .SetText(""));

                if (userMessage.Ok && userMessage.Text.Trim().Length > 0)
                {
                    try
                    {
                        CancellationTokenSource cancelSrc = new CancellationTokenSource();
                        ProgressDialogConfig    config    = new ProgressDialogConfig()
                                                            .SetTitle("Uploading to Server")
                                                            .SetIsDeterministic(false)
                                                            .SetMaskType(MaskType.Black)
                                                            .SetCancel(onCancel: cancelSrc.Cancel);

                        using (IProgressDialog progress = UserDialogs.Instance.Progress(config))
                        {
                            await DropboxServer.UploadMessage(userMessage.Text);

                            await Task.Delay(500);
                        }

                        UserDialogs.Instance.Toast(new ToastConfig("Successfully Sent")
                                                   .SetDuration(TimeSpan.FromSeconds(3))
                                                   .SetPosition(ToastPosition.Bottom));
                    }
                    catch
                    {
                        UserDialogs.Instance.Toast(new ToastConfig("Error")
                                                   .SetDuration(TimeSpan.FromSeconds(3))
                                                   .SetPosition(ToastPosition.Bottom));
                    }
                }
            }
            else
            {
                UserDialogs.Instance.Toast(new ToastConfig("No Internet Connected")
                                           .SetDuration(TimeSpan.FromSeconds(3))
                                           .SetPosition(ToastPosition.Bottom));
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void bedtimeResistanceButtonBottom_Clicked(object sender, EventArgs e)
        {
            if ((sender as Button) != null)
            {
                (sender as Button).IsEnabled = false;
            }

            string returnString = ViewTools.CommaSeparatedValue("Data,Value", "Intervention,Bedtime Resistance",
                                                                bedtimeResistanceStackContent, taskModels,
                                                                startTime, DateTime.Now.Subtract(startTime));

            Debug.WriteLineIf(App.Debugging, returnString);

            int result = await App.Database.SaveItemAsync(new StorageModel()
            {
                CSV          = returnString,
                Intervention = "Bedtime Resistance"
            });

            if (CrossConnectivity.Current.IsConnected)
            {
                CancellationTokenSource cancelSrc = new CancellationTokenSource();
                ProgressDialogConfig    config    = new ProgressDialogConfig()
                                                    .SetTitle("Uploading to Server")
                                                    .SetIsDeterministic(false)
                                                    .SetMaskType(MaskType.Black)
                                                    .SetCancel(onCancel: cancelSrc.Cancel);

                using (IProgressDialog progress = UserDialogs.Instance.Progress(config))
                {
                    await DropboxServer.UploadFile(new System.IO.MemoryStream(Encoding.UTF8.GetBytes(returnString)), App.Database.GetLargestID());

                    await Task.Delay(100);
                }
            }

            App.RefreshServer = true;

            await Navigation.PopAsync();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Force re-sync of data
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ToolbarItem_Clicked(object sender, EventArgs e)
        {
            Debug.WriteLineIf(App.Debugging, "Update_Clicked()");

            if (!CrossConnectivity.Current.IsConnected)
            {
                return;
            }

            //int count = 0;

            CancellationTokenSource cancelSrc = new CancellationTokenSource();
            ProgressDialogConfig    config    = new ProgressDialogConfig()
                                                .SetTitle("Syncing with server")
                                                .SetIsDeterministic(false)
                                                .SetMaskType(MaskType.Black)
                                                .SetCancel(onCancel: cancelSrc.Cancel);

            using (IProgressDialog progress = UserDialogs.Instance.Progress(config))
            {
                try
                {
                    ListFolderResult serverFiles = await DropboxServer.CountIndividualFiles();

                    List <StorageModel> currentData = await App.Database.GetDataAsync();

                    if (serverFiles == null || currentData == null || cancelSrc.IsCancellationRequested)
                    {
                        // Nothing.. just move on
                    }
                    else if (currentData.Count == serverFiles.Entries.Count)
                    {
                        // Same.. no worries
                    }
                    else if (currentData.Count > serverFiles.Entries.Count)
                    {
                        List <int> localIds = currentData.Select(l => l.ID).ToList();

                        List <string> remoteIdsStr = serverFiles.Entries.Select(r => r.Name).ToList();
                        remoteIdsStr = remoteIdsStr.Select(r => r.Split('_')[1]).ToList();
                        remoteIdsStr = remoteIdsStr.Select(r => r.Split('.')[0]).ToList();

                        List <int> remoteIds = remoteIdsStr.Select(r => int.Parse(r)).ToList();

                        var missing = localIds.Except(remoteIds);

                        for (int count = 0; count < missing.Count() && !cancelSrc.IsCancellationRequested; count++)
                        {
                            if (cancelSrc.IsCancellationRequested)
                            {
                                continue;
                            }
                            else
                            {
                                await Task.Delay(App.DropboxDeltaTimeout);
                            }

                            progress.Title = "Uploading File " + (count + 1) + " of " + missing.Count().ToString();

                            var mStorageModel = currentData.Single(m => m.ID == missing.ElementAt(count));

                            await DropboxServer.UploadFile(new System.IO.MemoryStream(Encoding.UTF8.GetBytes(mStorageModel.CSV)), mStorageModel.ID);
                        }
                    }
                }
                catch (Exception exc)
                {
                    Debug.WriteLineIf(App.Debugging, exc.ToString());
                }

                try
                {
                    ListFolderResult serverFiles = await DropboxServer.CountFeedback();

                    List <SleepFeedbackModel> currentData = await App.Database.GetFeedbackAsync();

                    if (serverFiles == null || currentData == null || cancelSrc.IsCancellationRequested)
                    {
                        // Nothing.. just move on
                    }
                    else if (currentData.Count == serverFiles.Entries.Count)
                    {
                        // Same.. no worries
                    }
                    else if (currentData.Count > serverFiles.Entries.Count)
                    {
                        List <int> localIds = currentData.Select(l => l.ID).ToList();

                        List <string> remoteIdsStr = serverFiles.Entries.Select(r => r.Name).ToList();
                        remoteIdsStr = remoteIdsStr.Select(r => r.Split('_')[1]).ToList();
                        remoteIdsStr = remoteIdsStr.Select(r => r.Split('.')[0]).ToList();

                        List <int> remoteIds = remoteIdsStr.Select(r => int.Parse(r)).ToList();

                        var missing = localIds.Except(remoteIds);

                        for (int count = 0; count < missing.Count() && !cancelSrc.IsCancellationRequested; count++)
                        {
                            if (cancelSrc.IsCancellationRequested)
                            {
                                continue;
                            }
                            else
                            {
                                await Task.Delay(App.DropboxDeltaTimeout);
                            }

                            progress.Title = "Uploading Feedback " + (count + 1) + " of " + missing.Count().ToString();

                            var mStorageModel = currentData.Single(m => m.ID == missing.ElementAt(count));

                            await DropboxServer.UploadFeedback(new System.IO.MemoryStream(Encoding.UTF8.GetBytes(mStorageModel.CSV)), mStorageModel.ID);
                        }
                    }
                }
                catch (Exception exc)
                {
                    Debug.WriteLineIf(App.Debugging, exc.ToString());
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Load Stuff
        /// </summary>
        public async void LoadAssets()
        {
            // Skip loading if no internet
            if (!CrossConnectivity.Current.IsConnected)
            {
                App.Current.MainPage = new NavigationPage(new TaskPageStart());
            }

            Debug.WriteLineIf(App.Debugging, "LoadAssets()");

            CancellationTokenSource cancelSrc = new CancellationTokenSource();
            ProgressDialogConfig    config    = new ProgressDialogConfig()
                                                .SetTitle("Contacting Server")
                                                .SetIsDeterministic(false)
                                                .SetMaskType(MaskType.Black)
                                                .SetCancel(onCancel: cancelSrc.Cancel);

            using (IProgressDialog progress = UserDialogs.Instance.Progress(config))
            {
                try
                {
                    if (App.UpdatingAttempts)
                    {
                        progress.Title = "Downloading manifest";

                        var mManifest = await App.Database.GetManifestAsync();

                        if (mManifest != null && mManifest.Count == 1)
                        {
                            App.MainManifest = JsonConvert.DeserializeObject <Manifest>(mManifest.First().JSON);
                        }
                        else
                        {
                            App.MainManifest = null;
                        }

                        progress.Title = "Parsing Manifest";

                        await DropboxServer.DownloadManifest(App.MainManifest);
                    }

                    progress.Title = "Polling local database";

                    List <StorageModel> currentItems = null;

                    try
                    {
                        currentItems = await App.Database.GetDataAsync();
                    }
                    catch (Exception e)
                    {
                        currentItems = null;

                        Debug.WriteLineIf(App.Debugging, e.ToString());
                    }

                    progress.Title = "Polling remote database";

                    ListFolderResult serverFiles = await DropboxServer.CountIndividualFiles();

                    int count = 0;

                    if (serverFiles == null || currentItems == null || cancelSrc.IsCancellationRequested)
                    {
                        // Nothing.. just move on
                    }
                    else if (currentItems.Count == serverFiles.Entries.Count)
                    {
                        // Same.. no worries
                    }
                    else if (currentItems.Count > serverFiles.Entries.Count)
                    {
                        List <int> localIds = currentItems.Select(l => l.ID).ToList();

                        List <string> remoteIdsStr = serverFiles.Entries.Select(r => r.Name).ToList();
                        remoteIdsStr = remoteIdsStr.Select(r => r.Split('_')[1]).ToList();
                        remoteIdsStr = remoteIdsStr.Select(r => r.Split('.')[0]).ToList();

                        List <int> remoteIds = remoteIdsStr.Select(r => int.Parse(r)).ToList();

                        var missing = localIds.Except(remoteIds);

                        foreach (int index in missing)
                        {
                            if (cancelSrc.IsCancellationRequested)
                            {
                                continue;
                            }

                            progress.Title = "Uploading File " + (count + 1) + " of " + missing.Count().ToString();

                            var mStorageModel = currentItems.Single(m => m.ID == index);

                            await DropboxServer.UploadFile(new System.IO.MemoryStream(Encoding.UTF8.GetBytes(mStorageModel.CSV)), mStorageModel.ID);

                            await Task.Delay(App.DropboxDeltaTimeout);

                            count++;
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLineIf(App.Debugging, e.ToString());
                }

                App.Current.MainPage = new NavigationPage(new TaskPageStart());
            }
        }