Пример #1
0
        private static PresentationData Convert(string markdown)
        {
            var presentation = new GfmToPresentationConverter().Convert(markdown);

            if (presentation != null)
            {
                foreach (var slide in presentation.Slides)
                {
                    slide.Id.Should().NotBeNullOrWhiteSpace();
                    slide.Id = null;
                }
            }

            return(presentation);
        }
Пример #2
0
        public async Task <int> RunAsync(IReadOnlyList <string> args, CancellationToken cancellationToken)
        {
            try
            {
                var argsReader = new ArgsReader(args);
                if (argsReader.ReadFlag("help|h|?"))
                {
                    WriteUsage(Console.Out);
                    return(0);
                }

                string markdownPath = argsReader.ReadArgument();
                if (markdownPath == null)
                {
                    throw new ArgsReaderException("Missing Markdown file path.");
                }

                string presentationId    = argsReader.ReadOption("id");
                string presentationTitle = argsReader.ReadOption("title");
                if (presentationId != null && presentationTitle != null)
                {
                    throw new ArgsReaderException("--id and --title cannot be used together.");
                }

                bool eraseSlides = argsReader.ReadFlag("erase");

                argsReader.VerifyComplete();

                var markdown = await File.ReadAllTextAsync(markdownPath, Encoding.UTF8, cancellationToken).ConfigureAwait(false);

                var converter    = new GfmToPresentationConverter();
                var presentation = converter.Convert(markdown);

                if (!string.IsNullOrWhiteSpace(presentationId))
                {
                    presentation.Id = presentationId;
                }
                if (!string.IsNullOrWhiteSpace(presentationTitle))
                {
                    presentation.Title = presentationTitle;
                }
                presentation.EraseSlides = eraseSlides;

                var slidesService = await CreateSlidesServiceAsync(cancellationToken).ConfigureAwait(false);

                var presentationFactory = new GooglePresentationGenerator(slidesService);
                presentationId = await presentationFactory.GeneratePresentationAsync(presentation, cancellationToken).ConfigureAwait(false);

                Console.WriteLine("https://docs.google.com/presentation/d/{0}/edit", presentationId);

                return(0);
            }
            catch (Exception exception)
            {
                if (exception is ArgsReaderException)
                {
                    Console.Error.WriteLine(exception.Message);
                    Console.Error.WriteLine();
                    WriteUsage(Console.Error);
                    return(2);
                }
                else if (exception is ApplicationException || exception is InvalidOperationException ||
                         exception is IOException || exception is UnauthorizedAccessException)
                {
                    Console.Error.WriteLine(exception.Message);
                    return(3);
                }
                else
                {
                    Console.Error.WriteLine(exception.ToString());
                    return(3);
                }
            }
        }