Ejemplo n.º 1
0
        private void FileParser()
        {
            var extension    = InputFile.FileName.Split('.')[1];
            var uploadFolder = Path.Combine(webHostEnvironment.WebRootPath,
                                            "UploadedFiles");
            var filePath = Path.Combine(uploadFolder, "input." + extension);

            using (var fs = new FileStream(filePath, FileMode.Create))
            {
                InputFile.CopyTo(fs);
            }
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            if (extension == "txt")
            {
                Input = System.IO.File.ReadAllText(filePath);
                if (Input.Contains('�'))
                {
                    Input = System.IO.File.ReadAllText(filePath, Encoding.GetEncoding(1251));
                }
            }
            else
            {
                try
                {
                    using (var document = WordprocessingDocument.Open(filePath, false))
                    {
                        Input = document.MainDocumentPart.Document.Body.InnerText;
                    }
                } catch
                {
                    _logger.LogError("Ошибка ввода docx");
                }
            }
        }
Ejemplo n.º 2
0
        bool ProcessNonMediaFile()
        {
            if (!NoCopyUnalteredFiles)
            {
                if (!OutputFile.Directory.Exists)
                {
                    OutputFile.Directory.Create();
                }

                bool RetVal = false;

                Console.Write(InputFile.FullName + " is not a media file. ");

                if (!OutputFile.Exists)
                {
                    if (!DeleteOriginal)
                    {
                        Console.WriteLine("Copying...");
                        InputFile.CopyTo(OutputFile.FullName);
                        RetVal = true;
                    }
                    else
                    {
                        Console.WriteLine("Moving...");
                        InputFile.MoveTo(OutputFile.FullName);
                        RetVal = true;
                    }
                }

                return(RetVal);
            }
            else
            {
                Console.WriteLine("Skipping non-media file " + InputFile.FullName);
                return(true);
            }
        }