Beispiel #1
0
        public async Task <bool> ProcessFromUrl(string url, string sourceFilename)
        {
            var extension = new FileInfo(sourceFilename).Extension;

            using (var wc = new System.Net.WebClient()) {
                string fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + $".{extension}";
                await wc.DownloadFileTaskAsync(new Uri(url), fileName);

                if (System.IO.File.Exists(fileName))
                {
                    if (extension.Equals(".doc"))
                    {
                        fileName = await DocHelpers.ConvertToDocx(fileName);
                    }

                    if (System.IO.File.Exists(fileName))
                    {
                        var id = DateTime.Now.GetNextWeekday(DayOfWeek.Monday).ToString("ddMMyy");
                        await _createHtmlFile(id, fileName);

                        var week = await _processFile(id, fileName);

                        if (week != null)
                        {
                            Console.WriteLine("Sending to cosmos");
                            await _service.Create(week);

                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Beispiel #2
0
        private async Task <bool> _createHtmlFile(string id, string fileName)
        {
            var outputFile = id + ".html";
            var tempFile   = Path.Combine(Path.GetTempPath(), outputFile);
            var htmlFile   = await DocHelpers.ConvertToHtml(fileName, tempFile);

            if (File.Exists(htmlFile))
            {
                await _fileUploader.UploadFile(htmlFile, "html", outputFile, "text/html");

                return(true);
            }
            return(false);
        }