Exemplo n.º 1
0
        public async Task <Maybe <string> > ExportAs(
            IScreen context,
            QueryResult queryResult,
            string name = "")
        {
            if (queryResult == null)
            {
                return(null);
            }

            var exportOptions = new CollectionExportOptions(false, null);
            var result        = await ShowHostDialog(context).For(exportOptions);

            if (result.Action is "cancel")
            {
                return(null);
            }

            Maybe <string> maybePath = null;

            switch (result.Model.GetSelectedExportFormat())
            {
            case 0:
                maybePath = await ExportToJson(queryResult, name);

                break;

            case 1:
                maybePath = await ExportToExcel(queryResult.DataTable, name);

                break;

            case 2:
                maybePath = await ExportToCsv(queryResult.DataTable, name);

                break;
            }

            if (maybePath.HasValue)
            {
                var builder = NotificationInteraction.Default()
                              .HasMessage($"{result.Model.ExportFormat} saved in:\n{maybePath.Value.ShrinkPath(128)}");

                if (Path.HasExtension(maybePath.Value))
                {
                    builder.Dismiss().WithButton("Open",
                                                 async button =>
                    {
                        await _applicationInteraction.OpenFileWithAssociatedApplication(maybePath.Value);
                    });
                }

                builder.WithButton("Reveal in Explorer",
                                   async button => { await _applicationInteraction.RevealInExplorer(maybePath.Value); })
                .Dismiss().WithButton("Close", button => { });

                builder.Queue();
            }

            return(maybePath);
        }
Exemplo n.º 2
0
        public async Task <Maybe <string> > ExportAs(
            IScreen context,
            CollectionReference collectionReference,
            IList <DocumentReference> selectedDocuments = null)
        {
            if (collectionReference == null)
            {
                return(null);
            }

            var exportOptions = new CollectionExportOptions(collectionReference.IsFilesOrChunks, selectedDocuments?.Count);
            var result        = await ShowHostDialog(context).For(exportOptions);

            if (result.Action is "cancel")
            {
                return(null);
            }

            var itemsToExport = result.Model.GetSelectedRecordsFilter() == 0
                ? collectionReference.Items
                : selectedDocuments;
            var referenceName = collectionReference.Name;

            Maybe <string> maybePath = null;

            switch (result.Model.GetSelectedExportFormat())
            {
            case 0:
                maybePath = await ExportToJson(itemsToExport, referenceName);

                break;

            case 1:
                maybePath = await ExportToExcel(itemsToExport, referenceName);

                break;

            case 2:
                maybePath = await ExportToCsv(itemsToExport, referenceName);

                break;

            case 3:
                maybePath = await ExportStoredFiles(itemsToExport);

                break;
            }

            if (maybePath.HasValue)
            {
                var builder = NotificationInteraction.Default()
                              .HasMessage($"{result.Model.ExportFormat} saved in:\n{maybePath.Value.ShrinkPath(128)}");

                if (Path.HasExtension(maybePath.Value))
                {
                    builder.Dismiss().WithButton("Open",
                                                 async button =>
                    {
                        await _applicationInteraction.OpenFileWithAssociatedApplication(maybePath.Value);
                    });
                }

                builder.WithButton("Reveal in Explorer",
                                   async button => { await _applicationInteraction.RevealInExplorer(maybePath.Value); })
                .Dismiss().WithButton("Close", button => { });

                builder.Queue();
            }

            return(maybePath);
        }