Ejemplo n.º 1
0
        private async void UploadIssue_Clicked(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(stream) || string.IsNullOrEmpty(area_issue.Text) || string.IsNullOrEmpty(area_issue.Text) || string.IsNullOrEmpty(Comments.Text))
            {
                await DisplayAlert("Empty Field", "Please Fill The Fields", "Ok");

                return;
            }
            insertIssues.adder = LoggedInUser.userID;
            insertIssues.additional_comments = Comments.Text;
            insertIssues.address             = area_issue.Text;
            insertIssues.event_id            = "NONE";
            insertIssues.photo             = stream;
            insertIssues.rating            = rating.SelectedItem.ToString();
            insertIssues.status            = "OPEN";
            insertIssues.status_changed_by = "NONE";

            MyActivityIndicator.IsVisible = true;
            try
            {
                newRecordResponse = await aPIService.InsertNewIssue(Constants.mongoDBBName, Constants.mongoDBCollectionIssues, Constants.mongoDBKey, insertIssues);

                MyActivityIndicator.IsVisible = false;

                if (!string.IsNullOrEmpty(newRecordResponse._id.oid))
                {
                    await DisplayAlert("Success", "Successsfully Inserted The Record.", "ok");

                    await this.Navigation.PopAsync();
                }
                else
                {
                    await DisplayAlert("Failure", "Failed To Insert The Record.", "ok");
                }
            }
            catch (ApiException apiException)
            {
                this.newRecordResponse = null;
                MongoCache.WriteOfflineIssue(insertIssues);
                await DisplayAlert("Failure", "Failed To Insert The Record. Will Try again when the internet is back.", "ok");

                await this.Navigation.PopAsync();
            }
        }
Ejemplo n.º 2
0
        protected override async void OnStart()
        {
            // Handle when your app starts
            issuesToBeUploaded = MongoCache.ReadOfflineIssue();
            eventsToBeUploaded = MongoCache.ReadOfflineEvent();

            if (issuesToBeUploaded != null)
            {
                newRecordResponse = new NewRecordResponse();
                aPIService        = RestService.For <IAPIService>(Constants.mongoDBBaseUrl);
                int currentIssue = 0;

                if (issuesToBeUploaded.Count > 0)
                {
                    try
                    {
                        foreach (var issue in issuesToBeUploaded)
                        {
                            newRecordResponse = await aPIService.InsertNewIssue(Constants.mongoDBBName, Constants.mongoDBCollectionIssues, Constants.mongoDBKey, issue);

                            if (!string.IsNullOrEmpty(newRecordResponse._id.oid))
                            {
                                // This is Success.

                                /*
                                 * First, we get the issue list from application settings and then we iterate over each and every saved instance.
                                 * Now, when we have success, we remove that item, so that it doesn't appear again in the list.
                                 * Now, we need to increment the issue count.
                                 */
                                issuesToBeUploaded.RemoveAt(currentIssue);
                                currentIssue++;
                            }
                            else
                            {
                                // This is Failure.
                                Console.WriteLine("Failure Occurred. Moving To Next One.");
                            }
                        }
                        foreach (var item in issuesToBeUploaded)
                        {
                            MongoCache.WriteOfflineIssue(item);
                        }
                    }
                    catch (Exception ex)
                    {
                        // Move On.
                        Console.WriteLine("Error While Uploading Issue Backlog : " + ex.Message);
                    }
                }
            } // Issue Uploaded

            if (eventsToBeUploaded != null)
            {
                newEventResponse = new Event();
                aPIService       = RestService.For <IAPIService>(Constants.mongoDBBaseUrl);
                int currentEvent = 0;

                if (eventsToBeUploaded.Count > 0)
                {
                    try
                    {
                        foreach (var eventVal in eventsToBeUploaded)
                        {
                            newEventResponse = await aPIService.InsertNewEvent(Constants.mongoDBBName, Constants.mongoDBCollectionEvents, Constants.mongoDBKey, eventVal);

                            if (!string.IsNullOrEmpty(newEventResponse._id.oid))
                            {
                                // This is Success.

                                /*
                                 * First, we get the event list from application settings and then we iterate over each and every saved instance.
                                 * Now, when we have success, we remove that item, so that it doesn't appear again in the list.
                                 * Now, we need to increment the issue count.
                                 */
                                eventsToBeUploaded.RemoveAt(currentEvent);
                                currentEvent++;
                            }
                            else
                            {
                                // This is Failure.
                                Console.WriteLine("Failure Occurred. Moving To Next One.");
                            }
                        }

                        foreach (var item in eventsToBeUploaded)
                        {
                            MongoCache.WriteOfflineEvent(item);
                        }
                    }
                    catch (Exception ex)
                    {
                        // Move On.
                        Console.WriteLine("Error While Uploading Event Backlog : " + ex.Message);
                    }
                }
            } // Event Uploaded
        }