Exemplo n.º 1
0
        protected void FeedConvertingFileQueue()
        {
            TimerCallback callback = (state) =>
            {
                using (var database = new Database("converting-files"))
                {
                    var submitedFiles = database.Fetch <SubmitedFile>("SELECT TOP 100 * FROM SubmitedFile ORDER BY ID").ToArray();

                    if (submitedFiles != null && submitedFiles.Length > 0)
                    {
                        foreach (var file in submitedFiles)
                        {
                            if (file.Path.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase))
                            {
                                FileConvertDirector <HtmlConverter> .AddConvertingFile(new SubmittedConvertingFile(file.Path, file.ResourceId));
                            }
                            else
                            {
                                FileConvertDirector <PdfConverter> .AddConvertingFile(new SubmittedConvertingFile(file.Path, file.ResourceId));
                            }
                        }

                        int maxId = submitedFiles[submitedFiles.Length - 1].Id;
                        database.Execute("DELETE FROM SubmitedFile WHERE ID <= @0", maxId);
                    }
                }
            };

            var timer = new Timer(callback);

            timer.Change(3000, 10000);
        }
Exemplo n.º 2
0
        public void TestAddFile()
        {
            FileConvertDirector <PdfConverter> .AddConvertingFile(new ConvertingFile(_basePath + "46164C79-5EB9-468A-9C1F-83490C47E21E.txt"));

            // 无异常即通过
            Assert.AreEqual(1, 1);
        }
Exemplo n.º 3
0
        public void TestRunAndOnConvertFinished()
        {
            ConvertingFile[] convertingFiles =
            {
                new ConvertingFile(_basePath + "6A962133-5C21-4B26-9183-82C72481C330.pdf"),
                new ConvertingFile(_basePath + "0979BF52-E3D7-4199-AEC4-3E538C8A64A3.docx")
            };

            var successCount = 0;

            FileConvertDirector <HtmlConverter> .OutputPath = "E:/Temp";
            FileConvertDirector <HtmlConverter> .AddConvertingFiles(convertingFiles);

            FileConvertDirector <HtmlConverter> .OnConvertFinished += (sender, args) =>
            {
                var convertedFile = sender as ConvertingFile;
                Assert.IsTrue(convertingFiles.Any(f => f.FilePath == convertedFile.FilePath));
                Assert.IsTrue(File.Exists(convertedFile.OutputPath) || Directory.Exists(convertedFile.OutputPath));

                successCount++;
            };

            FileConvertDirector <HtmlConverter> .Run();

            while (successCount != convertingFiles.Length - 1)
            {
                Thread.Sleep(200);
            }

            Assert.AreEqual(1, 1);
        }
Exemplo n.º 4
0
        public void TestAddFile()
        {
            FileConvertDirector <HtmlConverter> .AddConvertingFile(new ConvertingFile(_basePath + "F5E1D185-A97D-40E6-8CAF-4873714B241E.pdf"));

            // 无异常即通过
            Assert.AreEqual(1, 1);
        }
Exemplo n.º 5
0
        public void TestAddFiles()
        {
            ConvertingFile[] convertingFiles =
            {
                new ConvertingFile(_basePath + "6A962133-5C21-4B26-9183-82C72481C330.pdf")
            };

            FileConvertDirector <HtmlConverter> .AddConvertingFiles(convertingFiles);

            Assert.AreEqual(1, 1);
        }
Exemplo n.º 6
0
        public void Start()
        {
            FileConvertDirector <PdfConverter> .OutputPath = ConfigurationManager.AppSettings["converter-pdf-output-path"];
            FileConvertDirector <PdfConverter> .Run();

            FileConvertDirector <PdfConverter> .OnConvertFinished += OnConvertPdfFinished;

            FileConvertDirector <HtmlConverter> .OutputPath = ConfigurationManager.AppSettings["converter-html-output-path"];
            FileConvertDirector <HtmlConverter> .Run();

            FileConvertDirector <HtmlConverter> .OnConvertFinished += OnConvertHtmlFinished;

            FeedConvertingFileQueue();
        }
Exemplo n.º 7
0
        public void TestAddFiles()
        {
            ConvertingFile[] convertingFiles =
            {
                new ConvertingFile(_basePath + "46164C79-5EB9-468A-9C1F-83490C47E21E.txt"),
                new ConvertingFile(_basePath + "F5E1D185-A97D-40E6-8CAF-4873714B241E.ppt"),
                new ConvertingFile(_basePath + "F5E1D185-A97D-40E6-8CAF-4873714B241E.pptx"),
                new ConvertingFile(_basePath + "208A3214-3BA6-4CEC-8A0A-F707FBF8E58F.xls"),
                new ConvertingFile(_basePath + "208A3214-3BA6-4CEC-8A0A-F707FBF8E58F.xlsx"),
                new ConvertingFile(_basePath + "6A962133-5C21-4B26-9183-82C72481C330.pdf"),
                new ConvertingFile(_basePath + "0979BF52-E3D7-4199-AEC4-3E538C8A64A3.doc"),
                new ConvertingFile(_basePath + "0979BF52-E3D7-4199-AEC4-3E538C8A64A3.docx")
            };

            FileConvertDirector <PdfConverter> .AddConvertingFiles(convertingFiles);

            Assert.AreEqual(1, 1);
        }
Exemplo n.º 8
0
        public void TestRunAndOnConvertFinished()
        {
            ConvertingFile[] convertingFiles =
            {
                new ConvertingFile(_basePath + "46164C79-5EB9-468A-9C1F-83490C47E21E.txt"),
                new ConvertingFile(_basePath + "F5E1D185-A97D-40E6-8CAF-4873714B241E.ppt"),
                new ConvertingFile(_basePath + "F5E1D185-A97D-40E6-8CAF-4873714B241E.pptx"),
                new ConvertingFile(_basePath + "208A3214-3BA6-4CEC-8A0A-F707FBF8E58F.xls"),
                new ConvertingFile(_basePath + "208A3214-3BA6-4CEC-8A0A-F707FBF8E58F.xlsx"),
                new ConvertingFile(_basePath + "6A962133-5C21-4B26-9183-82C72481C330.pdf"),
                new ConvertingFile(_basePath + "0979BF52-E3D7-4199-AEC4-3E538C8A64A3.doc"),
                new ConvertingFile(_basePath + "0979BF52-E3D7-4199-AEC4-3E538C8A64A3.docx")
            };

            var successCount = 0;

            FileConvertDirector <PdfConverter> .AddConvertingFiles(convertingFiles);

            FileConvertDirector <PdfConverter> .OnConvertFinished += (sender, args) =>
            {
                var convertedFile = sender as ConvertingFile;
                Assert.IsTrue(convertingFiles.Any(f => f.FilePath == convertedFile.FilePath));
                Assert.IsTrue(File.Exists(convertedFile.OutputPath) || Directory.Exists(convertedFile.OutputPath));

                successCount++;
            };

            FileConvertDirector <PdfConverter> .Run();

            while (successCount != convertingFiles.Length - 1)
            {
                Thread.Sleep(200);
            }

            Assert.AreEqual(1, 1);
        }
Exemplo n.º 9
0
        protected void OnConvertPdfFinished(object sender, EventArgs args)
        {
            var convertedFile = sender as ConvertingFile;

            FileConvertDirector <HtmlConverter> .AddConvertingFile(new ConvertingFile(convertedFile.OutputPath));
        }