Пример #1
0
        /// <summary>
        /// Saves the screentshot report to the application's screenshot archive.
        /// </summary>
        private async void SaveScreenshotReport()
        {
            var pd = new ProgressDialog(this);

            pd.SetTitle(GetString(Resource.String.saving));
            pd.SetMessage(GetString(Resource.String.please_wait));
            pd.Indeterminate = true;
            pd.Show();

            var task = Task.Factory.StartNew(() => {
                var report = new ScreenshotReport();

                report.screenshot = screenshot;
                report.title      = GetString(Resource.String.app_name) + " " + GetString(Resource.String.report_screenshot);
                report.subtitle   = nameView.Text;
//        report.created = createdDate;
                report.notes = notesView.Text;

                report.tableData = new string[, ] {
                    { GetString(Resource.String.date), createdDate.ToShortDateString() + " " + createdDate.ToShortTimeString() },
                    { GetString(Resource.String.app_version), ion.version },
                    { GetString(Resource.String.location_address_1), addressView1.Text },
                    { GetString(Resource.String.location_address_2), addressView2.Text },
                    { GetString(Resource.String.location_city), cityView.Text },
                    { GetString(Resource.String.location_state_province_region), stateView.Text },
                    { GetString(Resource.String.location_country), countryView.Text },
                    { GetString(Resource.String.zip), zipView.Text },
                };

                try {
                    // TODO [email protected]: throw error if already exists
                    var dir  = ion.screenshotReportFolder;
                    var file = dir.GetFile(report.subtitle + ".pdf", EFileAccessResponse.CreateIfMissing);
                    using (var stream = file.OpenForWriting()) {
                        ScreenshotReportPdfExporter.Export(report, stream);
                    }

                    return(new Result());
                } catch (Exception e) {
                    Log.E(this, "Failed to create screenshot pdf report", e);
                    return(new Result(GetString(Resource.String.report_screenshot_error_export_failed)));
                }
            });

            var result = await task;

            pd.Dismiss();

            if (result.success)
            {
                Alert(Resource.String.report_screenshot_saved);
            }
            else
            {
                var err = new IONAlertDialog(this, "ERROR");
                err.SetMessage(result.errorReason);
                err.SetNegativeButton(Resource.String.cancel, (obj, args) => {
                    var d = obj as Dialog;
                    if (d != null)
                    {
                        d.Dismiss();
                    }
                });
                err.Show();
            }

            Finish();
        }
        private Result SaveScreenshot()
        {
            var report = new ScreenshotReport();

            ///save date in original format for localization later
            //report.created = date;
            report.title = Strings.Report.SCREENSHOT_TITLE;
            //report.subtitle = reportTitle.value;
            report.subtitle = subtitle;
            //report.notes = notes.value;
            report.notes      = notes.value;
            report.screenshot = image.AsPNG().ToArray();

            //if (report.subtitle == null || report.subtitle.Equals("")) {
            //	return new Result(Strings.Errors.SCREENSHOT_MISSING_TITLE);
            //}
            if (string.IsNullOrEmpty(subtitle))
            {
                return(new Result(Strings.Errors.SCREENSHOT_MISSING_TITLE));
            }
            /// adding an extra spot to manually add the localized date
            /// return here for possible raw data storage for different
            /// exporting formats
            //var data = new string[items.Count + 1, 2];
            var data = new string[7, 2];

            data[0, 0] = Strings.DATE;
            data[0, 1] = date.ToLocalTime().ToShortDateString();

            //for (int i = 1; i <= items.Count; i++) {
            //	var item = items[i - 1];
            //	data[i, 0] = item.header;
            //	data[i, 1] = item.value;
            //}
            data[1, 0] = "App Version";
            data[1, 1] = appversion;
            data[2, 0] = "Address Line 1";
            data[2, 1] = address1;
            data[3, 0] = "Address Line 2";
            data[3, 1] = address2;
            data[4, 0] = "City";
            data[4, 1] = city;
            data[5, 0] = "State/Province/Region";
            data[5, 1] = state;
            data[6, 0] = "ZIP/Postal Code";
            data[6, 1] = zipcode;

            report.tableData = data;

            try {
                var dir  = AppState.context.screenshotReportFolder;
                var file = dir.GetFile(report.subtitle + ".pdf", EFileAccessResponse.CreateIfMissing);
                using (var stream = file.OpenForWriting()) {
                    ScreenshotReportPdfExporter.Export(report, stream);
                }
            } catch (Exception e) {
                // TODO [email protected]: this needs a user-friendly dialog that will post on catch
                Log.E(this, "Failed to export pdf", e);
            }

            return(new Result());
        }