Beispiel #1
0
        //private string GetFile(PrintTitleInfo titleInfo)
        //{
        //    //string file = "";
        //    //file = _printDirectory + "\\";
        //    //return file + PrintIssue.GetStandardFilename(titleInfo.formatedTitle, titleInfo.special, titleInfo.date, titleInfo.dateType, titleInfo.number, titleInfo.specialText);
        //    string file = PrintIssue.GetStandardFilename(titleInfo.formatedTitle, titleInfo.special, titleInfo.date, titleInfo.dateType, titleInfo.number, titleInfo.specialText);
        //    file = zfile.ReplaceBadFilenameChars(file, "_");
        //    return _printDirectory + "\\" + file;
        //}

        //private string GetFile(PrintTitleRequest titleRequest)
        //{
        //    //string file = "";
        //    //file = _printDirectory + "\\";
        //    //return file + PrintIssue.GetStandardFilename(titleRequest.formatedTitle, titleRequest.special, titleRequest.date, titleRequest.dateType, titleRequest.number, titleRequest.specialText);
        //    string file = PrintIssue.GetStandardFilename(titleRequest.FormatedTitle, titleRequest.Special, titleRequest.Date, titleRequest.DateType, titleRequest.Number, titleRequest.SpecialText);
        //    file = zfile.ReplaceBadFilenameChars(file, "_");
        //    return _printDirectory + "\\" + file;
        //}

        //public static string GetFile(PrintTitleRequest titleRequest)
        public static string GetFile(PrintTitleInfo titleInfo)
        {
            string file = PrintIssue.GetStandardFilename(titleInfo.FormatedTitle, titleInfo.Special, titleInfo.Date, titleInfo.DateType, titleInfo.Number, titleInfo.SpecialText);

            file = zfile.ReplaceBadFilenameChars(file, "_");
            return(file);
        }
Beispiel #2
0
        public string GetPath(FileGroup_v2 file)
        {
            string pathFile = _destinationDirectory;
            string filename = zPath.GetFileNameWithoutExtension(file.BaseFilename);

            if (!file.BadFile)
            {
                PrintInfo printInfo = PrintIssue.GetPrintInfo(filename);
                //Trace.WriteLine("_MoveFiles() filename \"{0}\" date \"{1}\"", filename, printInfo != null ? printInfo.Date.ToString() : "null");
                if (printInfo != null && printInfo.Date != null)
                {
                    string subDirectory = GetPrintDirectoryDateStorage().GetDirectory((Date)printInfo.Date);
                    if (subDirectory != null)
                    {
                        pathFile = zPath.Combine(pathFile, subDirectory);
                    }
                }
                else if (!file.DestinationDirectoryFile)
                {
                    if (file.SubDirectory != null)
                    {
                        pathFile = zPath.Combine(pathFile, file.SubDirectory);
                    }
                }
                //else if (file.File.StartsWith(destinationDirectory))
                //else // if (file.DestinationDirectoryFile)
                //{
                //    // dont move unknow file of destination directory
                //    if (n <= file.Number)
                //        n = file.Number + 1;
                //    continue;
                //    // pas de continue sinon n n'est pas incrémenté
                //    // keep directory file
                //    //file = fileGroup.DirectoryInfo.Directory;
                //}
            }
            else
            {
                pathFile = zPath.Combine(pathFile, _badFileDirectory);
            }
            pathFile = zPath.Combine(pathFile, filename);
            if (file.Number > 0)
            {
                pathFile += string.Format("[{0}]", file.Number);
            }
            pathFile += zPath.GetExtension(file.BaseFilename);
            return(pathFile);
        }
Beispiel #3
0
        private string GetFile(string directory)
        {
            string titleFileName = GetTitleFileName();

            directory = GetDirectory(directory, titleFileName);

            if (_printType == PrintType.Print && _date == null && _number == null)
            {
                if (__traceWarning)
                {
                    Trace.WriteLine("warning can't find date nor number in \"{0}\"", _sourceTitle);
                }
            }

            string label = null;

            if (_specialText != null)
            {
                label = zfile.ReplaceBadFilenameChars(_specialText, "_");
            }
            string file = PrintIssue.GetStandardFilename(titleFileName, _special, _date, _dateType, _number, label);

            return(directory + file);
        }
Beispiel #4
0
        private void GetPrintInfo()
        {
            //if (_findPrint == null || !_findPrint.found)
            if (!_findPrint.Success)
            {
                return;
            }

            _found = true;
            //MatchValues matchValues = _findPrint.matchValues;
            //MatchValuesInfos matchValues = _findPrint.MatchValues;
            //_name = matchValues.Name;
            _name = _findPrint.Name;

            _print = _findPrintManager.PrintManager[_name];

            if (_print == null)
            {
                _findPrintType = FindPrintType.PrintType1;
                //if (matchValues.Attributes.ContainsKey("title"))
                //    _title = matchValues.Attributes["title"];
                if (_findPrint.Attributes.ContainsKey("title"))
                {
                    _title = _findPrint.Attributes["title"];
                }
                //if (matchValues.Attributes.ContainsKey("directory"))
                //    _directory = matchValues.Attributes["directory"];
                if (_findPrint.Attributes.ContainsKey("directory"))
                {
                    _directory = _findPrint.Attributes["directory"];
                }
                string directory;
                if (_directory != null)
                {
                    directory = _directory;
                }
                else
                {
                    directory = _findPrintManager.DefaultPrintDirectory;
                }
                _print = new Print(_name, _title, GetDirectory(directory));
            }
            else
            {
                _findPrintType = FindPrintType.PrintType2;
            }

            PrintIssue printIssue = _print.NewPrintIssue();

            if (_date != null)
            {
                printIssue.Date        = _date;
                printIssue.DateType    = _dateType;
                printIssue.Special     = _special;
                printIssue.SpecialText = _specialText;

                if (_number != null)
                {
                    if (printIssue.CanCalculatePrintNumber())
                    {
                        int calculatedPrintNumber = printIssue.Print.GetPrintNumber((Date)printIssue.Date);
                        if (calculatedPrintNumber != (int)_number)
                        {
                            if (__traceWarning)
                            {
                                Trace.WriteLine("warning number in title {0} is different than calculated number {1}", (int)_number, calculatedPrintNumber);
                            }
                        }
                    }
                    // utilise de préférence le no du titre plutot que celui calculé
                    // sauf pour le monde ex : "Le Monde week-end + Magazine + 3 suppléments du samedi 30 aout 2014" le 3 n'est pas le bon numéro
                    printIssue.PrintNumber = (int)_number;
                }
            }
            else if (_number != null)
            {
                printIssue.PrintNumber = (int)_number;
                printIssue.Special     = _special;
            }

            //printIssue.TrySetValues(_findPrint.matchValues.GetAllValues());
            printIssue.TrySetValues(_findPrint.GetAllValues());
            _label = printIssue.Label;

            _file = zPath.Combine(_print.Directory, zPath.GetFileNameWithoutExtension(printIssue.GetFilename()));
        }
Beispiel #5
0
        // book example :
        //   destinationDirectory : g:\pib\media\ebook\book\unsorted_verified\Les météores
        //                        : g:\pib\media\ebook\book\bonus
        private void _MoveFiles_v1(IEnumerable <FileGroup_v2> files, string destinationDirectory)
        {
            // directory : g:\\pib\\media\\ebook\\print
            //Trace.WriteLine("_MoveFiles() directory \"{0}\"", directory);
            int n = 0;
            //Dictionary<int, int> fileNumbers = GetDestinationFileNumbers(files);
            List <string>             moveFiles            = new List <string>();
            PrintDirectoryDateStorage directoryDateStorage = null;
            bool   first      = true;
            string directory2 = null;

            foreach (FileGroup_v2 file in files)
            {
                // file : (book)
                //   Directory                : "g:\pib\media\ebook\_dl\_dl_pib\book\10\book\Les fées cuisinent et les lutins dînent"
                //   SubDirectory             : "Les fées cuisinent et les lutins dînent"
                //   File                     : "g:\pib\media\ebook\_dl\_dl_pib\book\10\book\Les fées cuisinent et les lutins dînent\Les fées cuisinent et les lutins dînent\Fees-Lutins.pdf"
                //   BaseFilename             : "Fees-Lutins.pdf"
                //   Number                   : 0
                //   BadFile                  : false
                //   DestinationDirectoryFile : false
                //
                // file : (print)

                // fileGroup.DirectoryGroup.BaseDirectory
                // fileGroup.DirectoryInfo.Directory    : g:\\pib\\media\\ebook\\print\\.02_hebdo\\01 net
                //                                        g:\\pib\\media\\ebook\\_dl\\_dl_pib\\01\\print\\.02_hebdo\\01 net
                // fileGroup.DirectoryInfo.SubDirectory : .02_hebdo\\01 net
                // fileGroup.SubDirectory               : 2014
                // fileGroup.File                       : g:\\pib\\media\\ebook\\print\\.02_hebdo\\01 net\\2014\\01 net - 2014-10-16 - no 806(1).pdf
                // fileGroup.BaseFilename               : 01 net - 2014-10-16 - no 806.pdf
                // fileGroup.Number                     : 1

                if (first)
                {
                    first = false;
                    //Trace.WriteLine("_MoveFiles() SubDirectory \"{0}\"", fileGroup.DirectoryInfo.SubDirectory);
                    directory2 = destinationDirectory;
                    //if (file.SubDirectory != null && useSubdirectory)
                    //    directory2 = zPath.Combine(destinationDirectory, file.SubDirectory);
                    //Trace.WriteLine("_MoveFiles() directory \"{0}\"", directory2);
                    directoryDateStorage = PrintDirectoryManager.GetDirectoryDateStorage(directory2);
                }

                string pathFile = directory2;
                string filename = zPath.GetFileNameWithoutExtension(file.BaseFilename);
                if (!file.BadFile)
                {
                    PrintInfo printInfo = PrintIssue.GetPrintInfo(filename);
                    //Trace.WriteLine("_MoveFiles() filename \"{0}\" date \"{1}\"", filename, printInfo != null ? printInfo.Date.ToString() : "null");
                    if (printInfo != null && printInfo.Date != null)
                    {
                        string subDirectory = directoryDateStorage.GetDirectory((Date)printInfo.Date);
                        if (subDirectory != null)
                        {
                            pathFile = zPath.Combine(pathFile, subDirectory);
                        }
                    }
                    else if (!file.DestinationDirectoryFile)
                    {
                        if (file.SubDirectory != null)
                        {
                            pathFile = zPath.Combine(pathFile, file.SubDirectory);
                        }
                    }
                    //else if (file.File.StartsWith(destinationDirectory))
                    else // if (file.DestinationDirectoryFile)
                    {
                        // dont move unknow file of destination directory
                        if (n <= file.Number)
                        {
                            n = file.Number + 1;
                        }
                        continue;
                        // pas de continue sinon n n'est pas incrémenté
                        // keep directory file
                        //file = fileGroup.DirectoryInfo.Directory;
                    }
                }
                else
                {
                    pathFile = zPath.Combine(pathFile, __badFileDirectory);
                }
                pathFile = zPath.Combine(pathFile, filename);
                if (n > 0)
                {
                    pathFile += string.Format("[{0}]", n);
                }
                pathFile += zPath.GetExtension(file.BaseFilename);
                if (file.File != pathFile)
                {
                    moveFiles.Add(pathFile);
                    Trace.WriteLine("move file         \"{0}\"", file.File);
                    Trace.WriteLine("       to         \"{0}\"", pathFile + ".tmp");
                    if (!_simulate)
                    {
                        zfile.CreateFileDirectory(pathFile);
                        zFile.Move(file.File, pathFile + ".tmp");
                    }
                }
                //if (fileGroup.Number != n || fileGroup.DirectoryInfo.Directory != directory)
                //{
                //    string file = zPath.Combine(directory, fileGroup.DirectoryInfo.SubDirectory, zPath.GetFileNameWithoutExtension(fileGroup.BaseFilename));
                //    if (n > 0)
                //        file += string.Format("[{0}]", n);
                //    file += zPath.GetExtension(fileGroup.BaseFilename);
                //    files.Add(file);
                //    Trace.WriteLine("move file \"{0}\" to \"{1}\"", fileGroup.File, file + ".tmp");
                //    if (!_simulate)
                //    {
                //        zfile.CreateFileDirectory(file);
                //        File.Move(fileGroup.File, file + ".tmp");
                //    }
                //}
                n++;
            }

            foreach (string file in moveFiles)
            {
                Trace.WriteLine("rename tmp file   \"{0}\"", file + ".tmp");
                Trace.WriteLine("             to   \"{0}\"", file);
                if (!_simulate)
                {
                    zFile.Move(file + ".tmp", file);
                }
            }
        }
Beispiel #6
0
        private void _MoveFiles(IEnumerable <FileGroup> fileGroups, string directory, bool useSubdirectory = true)
        {
            // directory : g:\\pib\\media\\ebook\\print
            //Trace.WriteLine("_MoveFiles() directory \"{0}\"", directory);
            int                       n     = 0;
            List <string>             files = new List <string>();
            PrintDirectoryDateStorage directoryDateStorage = null;
            bool                      first      = true;
            string                    directory2 = null;

            foreach (FileGroup fileGroup in fileGroups)
            {
                // fileGroup.DirectoryGroup.BaseDirectory
                // fileGroup.DirectoryInfo.Directory    : g:\\pib\\media\\ebook\\print\\.02_hebdo\\01 net
                //                                        g:\\pib\\media\\ebook\\_dl\\_dl_pib\\01\\print\\.02_hebdo\\01 net
                // fileGroup.DirectoryInfo.SubDirectory : .02_hebdo\\01 net
                // fileGroup.SubDirectory               : 2014
                // fileGroup.File                       : g:\\pib\\media\\ebook\\print\\.02_hebdo\\01 net\\2014\\01 net - 2014-10-16 - no 806(1).pdf
                // fileGroup.BaseFilename               : 01 net - 2014-10-16 - no 806.pdf
                // fileGroup.Number                     : 1

                if (first)
                {
                    first = false;
                    //Trace.WriteLine("_MoveFiles() SubDirectory \"{0}\"", fileGroup.DirectoryInfo.SubDirectory);
                    directory2 = directory;
                    if (fileGroup.DirectoryInfo.SubDirectory != null && useSubdirectory)
                    {
                        directory2 = zPath.Combine(directory, fileGroup.DirectoryInfo.SubDirectory);
                    }
                    //Trace.WriteLine("_MoveFiles() directory \"{0}\"", directory2);
                    directoryDateStorage = PrintDirectoryManager.GetDirectoryDateStorage(directory2);
                }

                string file     = directory2;
                string filename = zPath.GetFileNameWithoutExtension(fileGroup.BaseFilename);
                if (!fileGroup.BadFile)
                {
                    PrintInfo printInfo = PrintIssue.GetPrintInfo(filename);
                    //Trace.WriteLine("_MoveFiles() filename \"{0}\" date \"{1}\"", filename, printInfo != null ? printInfo.Date.ToString() : "null");
                    if (printInfo != null && printInfo.Date != null)
                    {
                        string subDirectory = directoryDateStorage.GetDirectory((Date)printInfo.Date);
                        if (subDirectory != null)
                        {
                            file = zPath.Combine(file, subDirectory);
                        }
                    }
                    else if (fileGroup.File.StartsWith(directory))
                    {
                        // dont move unknow file of destination directory
                        if (n <= fileGroup.Number)
                        {
                            n = fileGroup.Number + 1;
                        }
                        continue;
                        // pas de continue sinon n n'est pas incrémenté
                        // keep directory file
                        //file = fileGroup.DirectoryInfo.Directory;
                    }
                }
                else
                {
                    file = zPath.Combine(file, __badFileDirectory);
                }
                file = zPath.Combine(file, filename);
                if (n > 0)
                {
                    file += string.Format("[{0}]", n);
                }
                file += zPath.GetExtension(fileGroup.BaseFilename);
                if (fileGroup.File != file)
                {
                    files.Add(file);
                    Trace.WriteLine("move file         \"{0}\"", fileGroup.File);
                    Trace.WriteLine("       to         \"{0}\"", file + ".tmp");
                    if (!_simulate)
                    {
                        zfile.CreateFileDirectory(file);
                        zFile.Move(fileGroup.File, file + ".tmp");
                    }
                }
                //if (fileGroup.Number != n || fileGroup.DirectoryInfo.Directory != directory)
                //{
                //    string file = zPath.Combine(directory, fileGroup.DirectoryInfo.SubDirectory, zPath.GetFileNameWithoutExtension(fileGroup.BaseFilename));
                //    if (n > 0)
                //        file += string.Format("[{0}]", n);
                //    file += zPath.GetExtension(fileGroup.BaseFilename);
                //    files.Add(file);
                //    Trace.WriteLine("move file \"{0}\" to \"{1}\"", fileGroup.File, file + ".tmp");
                //    if (!_simulate)
                //    {
                //        zfile.CreateFileDirectory(file);
                //        File.Move(fileGroup.File, file + ".tmp");
                //    }
                //}
                n++;
            }

            foreach (string file in files)
            {
                Trace.WriteLine("rename tmp file   \"{0}\"", file + ".tmp");
                Trace.WriteLine("             to   \"{0}\"", file);
                if (!_simulate)
                {
                    zFile.Move(file + ".tmp", file);
                }
            }
        }