Пример #1
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);
        }
Пример #2
0
        public static PrintInfo GetPrintInfo(string filename)
        {
            Match match = __rgPrintInfo.Match(filename);

            if (match.Success)
            {
                PrintInfo printInfo = new PrintInfo();
                if (match.Groups[1].Value != "")
                {
                    printInfo.Title = match.Groups[1].Value;
                }
                if (match.Groups[2].Value != "")
                {
                    printInfo.Special = true;
                }
                if (match.Groups[5].Value != "")
                {
                    printInfo.Date     = (Date)DateTime.ParseExact(match.Groups[5].Value, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                    printInfo.DateType = DateType.Day;
                }
                if (match.Groups[6].Value != "")
                {
                    printInfo.Date     = (Date)DateTime.ParseExact(match.Groups[6].Value, "yyyy-MM", CultureInfo.InvariantCulture);
                    printInfo.DateType = DateType.Month;
                }
                if (match.Groups[7].Value != "")
                {
                    printInfo.Date     = (Date)DateTime.ParseExact(match.Groups[7].Value, "yyyy", CultureInfo.InvariantCulture);
                    printInfo.DateType = DateType.Year;
                }
                if (match.Groups[9].Value != "")
                {
                    printInfo.Number = int.Parse(match.Groups[9].Value);
                }
                if (match.Groups[11].Value != "")
                {
                    printInfo.Label = match.Groups[11].Value;
                }
                return(printInfo);
            }
            else
            {
                return(null);
            }
        }
Пример #3
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);
                }
            }
        }
Пример #4
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);
                }
            }
        }
Пример #5
0
 public static PrintInfo GetPrintInfo(string filename)
 {
     Match match = __rgPrintInfo.Match(filename);
     if (match.Success)
     {
         PrintInfo printInfo = new PrintInfo();
         if (match.Groups[1].Value != "")
             printInfo.Title = match.Groups[1].Value;
         if (match.Groups[2].Value != "")
             printInfo.Special = true;
         if (match.Groups[5].Value != "")
         {
             printInfo.Date = (Date)DateTime.ParseExact(match.Groups[5].Value, "yyyy-MM-dd", CultureInfo.InvariantCulture);
             printInfo.DateType = DateType.Day;
         }
         if (match.Groups[6].Value != "")
         {
             printInfo.Date = (Date)DateTime.ParseExact(match.Groups[6].Value, "yyyy-MM", CultureInfo.InvariantCulture);
             printInfo.DateType = DateType.Month;
         }
         if (match.Groups[7].Value != "")
         {
             printInfo.Date = (Date)DateTime.ParseExact(match.Groups[7].Value, "yyyy", CultureInfo.InvariantCulture);
             printInfo.DateType = DateType.Year;
         }
         if (match.Groups[9].Value != "")
             printInfo.Number = int.Parse(match.Groups[9].Value);
         if (match.Groups[11].Value != "")
             printInfo.Label = match.Groups[11].Value;
         return printInfo;
     }
     else
         return null;
 }