Beispiel #1
0
        public override void RunSub(ICloneable _threadParameter)
        {
            this.JudgeTaskCancelFlag();
            CheckFileParameter param = (CheckFileParameter)_threadParameter;

            MatchFile.CheckDirectoryIsExists(param.OriginalDirectory, true);
            MatchFile.CheckDirectoryIsExists(param.OutputDirectory, true);

            DirectoryInfo originalFold    = new DirectoryInfo(param.OriginalDirectory);
            DirectoryInfo destinationFold = new DirectoryInfo(param.OutputDirectory);


            var originalfiles    = originalFold.GetFiles();
            var destinationfiles = destinationFold.GetFiles();
            List <CheckResult> listCheckResult    = new List <CheckResult>();
            List <PairFile>    convertingFileList = MatchFile.GetPairFileList(param);

            // Check Original First
            foreach (FileInfo file in originalfiles)
            {
                this.JudgeTaskCancelFlag();
                CheckResult checkresult = this.AnalyzeandReturnCheckResult(file, convertingFileList, destinationfiles);
                listCheckResult.Add(checkresult);
            }
            //check destination
            foreach (FileInfo file in destinationfiles)
            {
                this.JudgeTaskCancelFlag();
                CheckResult checkresult;
                try
                {
                    checkresult = listCheckResult.First(f =>
                    {
                        return((f.DestinationFileNameWithExtension == Path.GetFileNameWithoutExtension(file.Name)) && (f.DestinationExtension == Path.GetExtension(file.Name)));
                    });
                    if (checkresult == null)
                    {
                        // Destination is more than original
                        listCheckResult.Add(GetDestinationCheckResult(file));
                    }
                }
                catch (InvalidOperationException ex)
                {
                    // no equal item
                    listCheckResult.Add(GetDestinationCheckResult(file));
                }
                catch (Exception ex)
                {
                }
            }
            LogCheckResult(listCheckResult);
            foreach (DirectoryInfo dir in originalFold.GetDirectories())
            {
                CheckFileParameter paramSub = (CheckFileParameter)param.Clone();
                paramSub.OriginalDirectory = dir.FullName;
                paramSub.OutputDirectory  += "\\" + dir.Name;
                RunSub(paramSub);
            }
        }
Beispiel #2
0
        public override void RunSub(ICloneable _threadParameter)
        {
            this.JudgeTaskCancelFlag();
            CheckFileParameter param = (CheckFileParameter)_threadParameter;

            MatchFile.CheckDirectoryIsExists(param.OriginalDirectory, true);
            MatchFile.CheckDirectoryIsExists(param.OutputDirectory, true);

            DirectoryInfo originalFold    = new DirectoryInfo(param.OriginalDirectory);
            DirectoryInfo destinationFold = new DirectoryInfo(param.OutputDirectory);


            var originalfiles    = originalFold.GetFiles();
            var destinationfiles = destinationFold.GetFiles();
            List <CheckResult> listCheckResult    = new List <CheckResult>();
            List <PairFile>    convertingFileList = MatchFile.GetPairFileList(param);

            // Check Original First
            foreach (FileInfo file in originalfiles)
            {
                this.JudgeTaskCancelFlag();
                CheckResult checkresult = this.AnalyzeandReturnCheckResult(file, convertingFileList, destinationfiles);
                if ((checkresult.OriginalFileNameWithExtension == checkresult.DestinationFileNameWithExtension) &&
                    (checkresult.OriginalExtension == checkresult.DestinationExtension) &&
                    (checkresult.OriginalFileSize == checkresult.DestinationFileSize))
                {
                    listCheckResult.Add(checkresult);
                }
            }
            //check destination

            LogCheckResult(listCheckResult);
            foreach (DirectoryInfo dir in originalFold.GetDirectories())
            {
                CheckFileParameter paramSub = (CheckFileParameter)param.Clone();
                paramSub.OriginalDirectory = dir.FullName;
                paramSub.OutputDirectory  += "\\" + dir.Name;
                RunSub(paramSub);
            }
        }
Beispiel #3
0
        public override void RunSub(ICloneable _threadParameter)
        {
            JudgeTaskCancelFlag();
            LibreOfficeParameter librparam = (LibreOfficeParameter)_threadParameter;

            MatchFile.CheckDirectoryIsExists(librparam.OriginalDirectory, true);
            MatchFile.CheckDirectoryIsExists(librparam.OutputDirectory, true);
            DirectoryInfo originalFold    = new DirectoryInfo(librparam.OriginalDirectory);
            DirectoryInfo destinationFold = new DirectoryInfo(librparam.OutputDirectory);

            if (!originalFold.Exists)
            {
                return;
            }
            if (!destinationFold.Exists)
            {
                return;
            }

            //Get pairfile
            List <PairFile> convertingFileList = MatchFile.GetPairFileList(librparam);

            //Convert file
            foreach (PairFile file in convertingFileList)
            {
                try
                {
                    JudgeTaskCancelFlag();
                    string temp = GetCommand(librparam, file);
                    commandList.Add(temp);
                    DateTime dtStart       = System.DateTime.Now;
                    bool     isNeedConvert = true;
                    bool     Printlog      = false;

                    if (!librparam.Isoverwrite)
                    {
                        if (System.IO.File.Exists(librparam.OutputDirectory + "\\" + file.outputFileName))
                        {
                            isNeedConvert = false;
                        }
                    }

                    if (librparam.IsOnlyLogNeedtoConvert)
                    {
                        if (isNeedConvert)
                        {
                            Printlog = true;
                        }
                    }
                    else
                    {
                        // always print log
                        Printlog = true;
                    }
                    if (Printlog)
                    {
                        log.Log("Convert file [" + file.originalFile.FullName + "][" + CustomizedLog.GetByteDescription(file.originalFile.Length) + "]");
                        log.LogContinue();
                    }
                    //if (token.IsCancellationRequested)
                    //{
                    //    // Clean up here, then...
                    //    log.DeleteLog(3);
                    //    log.LogTaskCancel("Converting");
                    //    // this.BeginInvoke(new SetbuttonStatus(SetLibreOfficeButtonStatus), new object[] { true });
                    //    token.ThrowIfCancellationRequested();
                    //}
                    if (file.IsRename)
                    {
                        file.CreateSerialNumberFile();
                    }


                    if (isNeedConvert)
                    {
                        Process pr = new Process();//声明一个进程类对象
                        pr.StartInfo.FileName  = "\"" + librparam.Path + "\"";
                        pr.StartInfo.Arguments = " " + librparam.Command + " " + librparam.OutputFileExtension + " " + "\"" + file.GetRightOriginalName() + "\" " + " --outdir \"" + librparam.OutputDirectory + "\"";
                        pr.Start();
                        pr.WaitForExit();

                        //DateTime dtConvertStart = System.DateTime.Now;
                        //// Console.WriteLine("LibreOffice Process is finished");
                        //while (!System.IO.File.Exists(librparam.OutputDirectory + "\\" + file.outputFileName)) {
                        //    // Console.WriteLine(librparam.OutputFileExtension + " is not created");
                        //    Thread.Sleep(100);
                        //}
                        //DateTime dtConvertEnd = System.DateTime.Now;
                        // Console.WriteLine("wait for the pdf file time: " + (dtConvertEnd - dtConvertStart).TotalSeconds.ToString("F0") + "s");
                    }

                    // delete serialNumber file
                    if (file.IsRename)
                    {
                        file.DeleteSerialNumberFile();
                    }
                    DateTime dtEnd = System.DateTime.Now;

                    if (Printlog)
                    {
                        log.DeleteLog(3);
                        log.Log((dtEnd - dtStart).TotalSeconds.ToString("F0") + "s" + (isNeedConvert ? "" : "(N)") + "\t\t" + file.originalFile.FullName);
                    }
                }
                catch (System.OperationCanceledException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    log.Log("error:" + ex.Message);
                }
            }
            if (librparam.IsincludSubfolder)
            {
                foreach (DirectoryInfo dir in originalFold.GetDirectories())
                {
                    LibreOfficeParameter libreparamSub = (LibreOfficeParameter)librparam.Clone();
                    libreparamSub.OriginalDirectory = dir.FullName;
                    libreparamSub.OutputDirectory  += "\\" + dir.Name;
                    RunSub(libreparamSub);
                }
            }
        }