Ejemplo n.º 1
0
        public void HandleFileDoesNotExistDoNothing()
        {
            var handler        = new DeleteSuccessfulFileHandlingStrategy();
            var processingFile = new ProcessingFile(Path.Combine(testDirectory, "somenonexistant.file.inprogress"), "somenonexistant.file", "nonexistantpath\\nonexistant.file");

            handler.Handle(processingFile);

            Assert.IsTrue(true);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CreateProcessingFile([FromBody] ProcessingFile item)
        {
            if (item == null)
            {
                return(this.BadRequest());
            }

            await this.unitOfWork.ProcessingFilesRepository.AddAsync(item);

            await this.unitOfWork.SaveAsync();

            return(this.CreatedAtRoute("GetProcessingFile", new { id = item.Id }, item));
        }
Ejemplo n.º 3
0
        public void HandleFileExistsDeleteFile()
        {
            var file           = new FileInfo(Path.Combine(testDirectory, "test.file"));
            var processingFile = new ProcessingFile(file.FullName, "original.name", "originalpath\\original.name");

            using (var sr = file.Create())
            {
            }
            var handler = new DeleteSuccessfulFileHandlingStrategy();

            handler.Handle(processingFile);

            Assert.IsFalse(file.Exists);
        }
Ejemplo n.º 4
0
        private static void processFile(String InputFile)
        {
            // copy processing file
            ProcessingFile procFile = new ProcessingFile(InputFile);

            //make output file name
            if (ChoosenOutputFile == null)
            {
                if (InputFile.Contains("."))
                {
                    ChoosenOutputFile = InputFile.Remove(InputFile.LastIndexOf(".")) + ".pptx";
                }
                else
                {
                    ChoosenOutputFile = InputFile + ".pptx";
                }
            }

            //open the reader
            using (StructuredStorageReader reader = new StructuredStorageReader(procFile.File.FullName))
            {
                // parse the ppt document
                PowerpointDocument ppt = new PowerpointDocument(reader);

                // detect document type and name
                OpenXmlPackage.DocumentType outType = Converter.DetectOutputType(ppt);
                string conformOutputFile            = Converter.GetConformFilename(ChoosenOutputFile, outType);

                // create the pptx document
                PresentationDocument pptx = PresentationDocument.Create(conformOutputFile, outType);

                //start time
                DateTime start = DateTime.Now;
                TraceLogger.Info("Converting file {0} into {1}", InputFile, conformOutputFile);

                // convert
                Converter.Convert(ppt, pptx);

                // stop time
                DateTime end  = DateTime.Now;
                TimeSpan diff = end.Subtract(start);
                TraceLogger.Info("Conversion of file {0} finished in {1} seconds", InputFile, diff.TotalSeconds.ToString(CultureInfo.InvariantCulture));
            }
        }
Ejemplo n.º 5
0
 internal new void Normalize()
 {
     if (Type == Types.SceneryMain || Type == Types.SceneryPart)
     {
         if (ProcessingFile != null)
         {
             ProcessingFile.Invoke(this, EventArgs.Empty);
         }
         Application.DoEvents();
         Editor.BeginAutoUndo();
         Editor.Text = base.Normalize();
         Editor.OnSyntaxHighlight(new TextChangedEventArgs(Editor.VisibleRange));
         if (ProcessingFileDone != null)
         {
             ProcessingFileDone.Invoke(this, EventArgs.Empty);
         }
         Application.DoEvents();
     }
 }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            TraceLogger.LogLevel = TraceLogger.LoggingLevel.DebugInternal;

            const string outputDir = "dumps";

            if (Directory.Exists(outputDir))
            {
                Directory.Delete(outputDir, true);
            }

            Directory.CreateDirectory(outputDir);

            string         inputFile = args[0];
            ProcessingFile procFile  = new ProcessingFile(inputFile);

            StructuredStorageReader file   = new StructuredStorageReader(procFile.File.FullName);
            PowerpointDocument      pptDoc = new PowerpointDocument(file);

            // Dump unknown records
            foreach (Record record in pptDoc)
            {
                if (record is UnknownRecord)
                {
                    string filename = String.Format(@"{0}\{1}.record", outputDir, record.GetIdentifier());

                    using (FileStream fs = new FileStream(filename, FileMode.Create))
                    {
                        record.DumpToStream(fs);
                    }
                }
            }

            // Output record tree
            Console.WriteLine(pptDoc);
            Console.WriteLine();

            // Let's make development as easy as pie.
            System.Diagnostics.Debugger.Break();
        }
        public ActionResult Put(IFormFile file, string input)
        {
            const string customCopyHeader = "X-Copy-From";
            var          pathCopyFrom     = Request.Headers.FirstOrDefault
                                                (h => h.Key == customCopyHeader).Value;


            if (string.IsNullOrEmpty(pathCopyFrom))
            {
                var statusCode = ProcessingFile.InsertFile(file, input);

                return(_codeResults[statusCode]);
            }

            if (file == null)
            {
                var statusCode = ProcessingFile.CopyFile(input, pathCopyFrom);

                return(_codeResults[statusCode]);
            }

            return(BadRequest());
        }
        public ActionResult Get(string input)
        {
            var path = ProcessingFile.RootDirectory + @"\" + input;

            if (Directory.Exists(path))
            {
                if (Directory.GetFiles(path).Length == 0 &&
                    Directory.GetDirectories(path).Length == 0)
                {
                    return(NoContent());
                }

                try
                {
                    return(new JsonResult(ProcessingFile.GetAllFiles(path)));
                }
                catch
                {
                    return(StatusCode(500));
                }
            }

            if (System.IO.File.Exists(path))
            {
                try
                {
                    var fileStream = new FileStream(path, FileMode.Open);
                    return(File(fileStream, "application/unknown", input));
                }
                catch
                {
                    return(StatusCode(500));
                }
            }

            return(NotFound());
        }
        public ActionResult Head(string filename)
        {
            try
            {
                var fullFileName = ProcessingFile.RootDirectory + @"\" + filename;
                var fileInfo     = new FileInfo(fullFileName);

                if (!fileInfo.Exists)
                {
                    return(NotFound());
                }

                Response.Headers.Add("Filename", fileInfo.Name);
                Response.Headers.Add("Created-at", fileInfo.CreationTime.ToString(CultureInfo.InvariantCulture));
                Response.Headers.Add("Modified-at", fileInfo.LastWriteTime.ToString(CultureInfo.InvariantCulture));
                Response.Headers.Add("Size", ProcessingFile.SizeSuffix(fileInfo.Length));

                return(Ok());
            }
            catch
            {
                return(StatusCode(500));
            }
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> EditProcessingFile([FromBody] ProcessingFile item, int id)
        {
            if (item == null)
            {
                return(this.BadRequest());
            }

            var processingFile = await this.unitOfWork.ProcessingFilesRepository.GetSingleAsync(id);

            if (processingFile == null)
            {
                return(this.NotFound());
            }

            processingFile.Name   = item.Name;
            processingFile.Path   = item.Path;
            processingFile.Format = item.Format;
            processingFile.Type   = item.Type;

            this.unitOfWork.ProcessingFilesRepository.Edit(processingFile);
            await this.unitOfWork.SaveAsync();

            return(new NoContentResult());
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            ParseArgs(args, ToolName);

            InitializeLogger();

            PrintWelcome(ToolName, RevisionResource);

            try
            {
                //copy processing file
                var procFile = new ProcessingFile(InputFile);

                //make output file name
                if (ChoosenOutputFile == null)
                {
                    if (InputFile.Contains("."))
                    {
                        ChoosenOutputFile = InputFile.Remove(InputFile.LastIndexOf(".")) + ".xlsx";
                    }
                    else
                    {
                        ChoosenOutputFile = InputFile + ".xlsx";
                    }
                }

                //parse the document
                using (var reader = new StructuredStorageReader(procFile.File.FullName))
                {
                    var xlsDoc = new XlsDocument(reader);

                    var    outType           = Converter.DetectOutputType(xlsDoc);
                    string conformOutputFile = Converter.GetConformFilename(ChoosenOutputFile, outType);
                    using (var spreadx = SpreadsheetDocument.Create(conformOutputFile, outType))
                    {
                        //start time
                        var start = DateTime.Now;
                        TraceLogger.Info("Converting file {0} into {1}", InputFile, conformOutputFile);

                        Converter.Convert(xlsDoc, spreadx);

                        var end  = DateTime.Now;
                        var diff = end.Subtract(start);
                        TraceLogger.Info("Conversion of file {0} finished in {1} seconds", InputFile, diff.TotalSeconds.ToString(CultureInfo.InvariantCulture));
                    }
                }
            }
            catch (ParseException ex)
            {
                TraceLogger.Error("Could not convert {0} because it was created by an unsupported application (Excel 95 or older).", InputFile);
                TraceLogger.Debug(ex.ToString());
            }
            catch (DirectoryNotFoundException ex)
            {
                TraceLogger.Error(ex.Message);
                TraceLogger.Debug(ex.ToString());
            }
            catch (FileNotFoundException ex)
            {
                TraceLogger.Error(ex.Message);
                TraceLogger.Debug(ex.ToString());
            }
            catch (Exception ex)
            {
                TraceLogger.Error("Conversion of file {0} failed.", InputFile);
                TraceLogger.Debug(ex.ToString());
            }
        }
Ejemplo n.º 12
0
        public static void Main(string[] args)
        {
            ParseArgs(args, ToolName);

            InitializeLogger();

            PrintWelcome(ToolName, RevisionResource);

            // convert
            try
            {
                //copy processing file
                var procFile = new ProcessingFile(InputFile);

                //make output file name
                if (ChoosenOutputFile == null)
                {
                    if (InputFile.Contains("."))
                    {
                        ChoosenOutputFile = InputFile.Remove(InputFile.LastIndexOf(".")) + ".docx";
                    }
                    else
                    {
                        ChoosenOutputFile = InputFile + ".docx";
                    }
                }

                //open the reader
                using (var reader = new StructuredStorageReader(procFile.File.FullName))
                {
                    //parse the input document
                    var doc = new WordDocument(reader);

                    //prepare the output document
                    var    outType           = Converter.DetectOutputType(doc);
                    string conformOutputFile = Converter.GetConformFilename(ChoosenOutputFile, outType);
                    var    docx = WordprocessingDocument.Create(conformOutputFile, outType);

                    //start time
                    var start = DateTime.Now;
                    TraceLogger.Info("Converting file {0} into {1}", InputFile, conformOutputFile);

                    //convert the document
                    Converter.Convert(doc, docx);

                    var end  = DateTime.Now;
                    var diff = end.Subtract(start);
                    TraceLogger.Info("Conversion of file {0} finished in {1} seconds", InputFile, diff.TotalSeconds.ToString(CultureInfo.InvariantCulture));
                }
            }
            catch (DirectoryNotFoundException ex)
            {
                TraceLogger.Error(ex.Message);
                TraceLogger.Debug(ex.ToString());
            }
            catch (FileNotFoundException ex)
            {
                TraceLogger.Error(ex.Message);
                TraceLogger.Debug(ex.ToString());
            }
            catch (ReadBytesAmountMismatchException ex)
            {
                TraceLogger.Error("Input file {0} is not a valid Microsoft Word 97-2003 file.", InputFile);
                TraceLogger.Debug(ex.ToString());
            }
            catch (MagicNumberException ex)
            {
                TraceLogger.Error("Input file {0} is not a valid Microsoft Word 97-2003 file.", InputFile);
                TraceLogger.Debug(ex.ToString());
            }
            catch (UnspportedFileVersionException ex)
            {
                TraceLogger.Error("File {0} has been created with a Word version older than Word 97.", InputFile);
                TraceLogger.Debug(ex.ToString());
            }
            catch (ByteParseException ex)
            {
                TraceLogger.Error("Input file {0} is not a valid Microsoft Word 97-2003 file.", InputFile);
                TraceLogger.Debug(ex.ToString());
            }
            catch (MappingException ex)
            {
                TraceLogger.Error("There was an error while converting file {0}: {1}", InputFile, ex.Message);
                TraceLogger.Debug(ex.ToString());
            }
            catch (Exception ex)
            {
                TraceLogger.Error("Conversion of file {0} failed.", InputFile);
                TraceLogger.Debug(ex.ToString());
            }
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            ParseArgs(args, ToolName);

            InitializeLogger();

            PrintWelcome(ToolName, RevisionResource);

            if (CreateContextMenuEntry)
            {
                // create context menu entry
                try
                {
                    TraceLogger.Info("Creating context menu entry for xls2x ...");
                    RegisterForContextMenu(GetContextMenuKey(ContextMenuInputExtension, ContextMenuText));
                    TraceLogger.Info("Succeeded.");
                }
                catch (Exception)
                {
                    TraceLogger.Info("Failed. Sorry :(");
                }
            }
            else
            {
                try
                {
                    //copy processing file
                    ProcessingFile procFile = new ProcessingFile(InputFile);

                    //make output file name
                    if (ChoosenOutputFile == null)
                    {
                        if (InputFile.Contains("."))
                        {
                            ChoosenOutputFile = InputFile.Remove(InputFile.LastIndexOf(".")) + ".xlsx";
                        }
                        else
                        {
                            ChoosenOutputFile = InputFile + ".xlsx";
                        }
                    }

                    //parse the document
                    using (StructuredStorageReader reader = new StructuredStorageReader(procFile.File.FullName))
                    {
                        XlsDocument xlsDoc = new XlsDocument(reader);

                        OpenXmlPackage.DocumentType outType = Converter.DetectOutputType(xlsDoc);
                        string conformOutputFile            = Converter.GetConformFilename(ChoosenOutputFile, outType);
                        using (SpreadsheetDocument spreadx = SpreadsheetDocument.Create(conformOutputFile, outType))
                        {
                            //start time
                            DateTime start = DateTime.Now;
                            TraceLogger.Info("Converting file {0} into {1}", InputFile, conformOutputFile);

                            Converter.Convert(xlsDoc, spreadx);

                            DateTime end  = DateTime.Now;
                            TimeSpan diff = end.Subtract(start);
                            TraceLogger.Info("Conversion of file {0} finished in {1} seconds", InputFile, diff.TotalSeconds.ToString(CultureInfo.InvariantCulture));
                        }
                    }
                }
                catch (ParseException ex)
                {
                    TraceLogger.Error("Could not convert {0} because it was created by an unsupported application (Excel 95 or older).", InputFile);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (DirectoryNotFoundException ex)
                {
                    TraceLogger.Error(ex.Message);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (FileNotFoundException ex)
                {
                    TraceLogger.Error(ex.Message);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (ZipCreationException ex)
                {
                    TraceLogger.Error("Could not create output file {0}.", ChoosenOutputFile);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (Exception ex)
                {
                    TraceLogger.Error("Conversion of file {0} failed.", InputFile);
                    TraceLogger.Debug(ex.ToString());
                }
            }
        }
Ejemplo n.º 14
0
        public static void Main(string[] args)
        {
            ParseArgs(args, ToolName);

            InitializeLogger();

            PrintWelcome(ToolName);

            if (CreateContextMenuEntry)
            {
                // create context menu entry
                try
                {
                    TraceLogger.Info("Creating context menu entry for doc2x ...");
                    RegisterForContextMenu(GetContextMenuKey(ContextMenuInputExtension, ContextMenuText));
                    TraceLogger.Info("Succeeded.");
                }
                catch (Exception)
                {
                    TraceLogger.Info("Failed. Sorry :(");
                }
            }
            else
            {
                // convert
                try
                {
                    //copy processing file
                    ProcessingFile procFile = new ProcessingFile(InputFile);

                    //make output file name
                    if (ChoosenOutputFile == null)
                    {
                        if (InputFile.Contains("."))
                        {
                            ChoosenOutputFile = InputFile.Remove(InputFile.LastIndexOf(".")) + ".docx";
                        }
                        else
                        {
                            ChoosenOutputFile = InputFile + ".docx";
                        }
                    }

                    //open the reader
                    using (StructuredStorageReader reader = new StructuredStorageReader(procFile.File.FullName))
                    {
                        //parse the input document
                        WordDocument doc = new WordDocument(reader);

                        //prepare the output document
                        OpenXmlPackage.DocumentType outType = Converter.DetectOutputType(doc);
                        string conformOutputFile            = Converter.GetConformFilename(ChoosenOutputFile, outType);
                        WordprocessingDocument docx         = WordprocessingDocument.Create(conformOutputFile, outType);

                        //start time
                        DateTime start = DateTime.Now;
                        TraceLogger.Info("Converting file {0} into {1}", InputFile, conformOutputFile);

                        //convert the document
                        Converter.Convert(doc, docx);

                        DateTime end  = DateTime.Now;
                        TimeSpan diff = end.Subtract(start);
                        TraceLogger.Info("Conversion of file {0} finished in {1} seconds", InputFile, diff.TotalSeconds.ToString(CultureInfo.InvariantCulture));
                    }
                }
                catch (DirectoryNotFoundException ex)
                {
                    TraceLogger.Error(ex.Message);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (FileNotFoundException ex)
                {
                    TraceLogger.Error(ex.Message);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (ReadBytesAmountMismatchException ex)
                {
                    TraceLogger.Error("Input file {0} is not a valid Microsoft Word 97-2003 file.", InputFile);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (MagicNumberException ex)
                {
                    TraceLogger.Error("Input file {0} is not a valid Microsoft Word 97-2003 file.", InputFile);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (UnspportedFileVersionException ex)
                {
                    TraceLogger.Error("File {0} has been created with a Word version older than Word 97.", InputFile);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (ByteParseException ex)
                {
                    TraceLogger.Error("Input file {0} is not a valid Microsoft Word 97-2003 file.", InputFile);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (MappingException ex)
                {
                    TraceLogger.Error("There was an error while converting file {0}: {1}", InputFile, ex.Message);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (ZipCreationException ex)
                {
                    TraceLogger.Error("Could not create output file {0}.", ChoosenOutputFile);
                    //TraceLogger.Error("Perhaps the specified outputfile was a directory or contained invalid characters.");
                    TraceLogger.Debug(ex.ToString());
                }
                catch (Exception ex)
                {
                    TraceLogger.Error("Conversion of file {0} failed.", InputFile);
                    TraceLogger.Debug(ex.ToString());
                }
            }
        }