Exemplo n.º 1
0
 private PrintDirectoryDateStorage GetPrintDirectoryDateStorage()
 {
     if (_directoryDateStorage == null)
     {
         _directoryDateStorage = PrintDirectoryManager.GetDirectoryDateStorage(_destinationDirectory);
     }
     return(_directoryDateStorage);
 }
Exemplo n.º 2
0
        public static PrintDirectoryDateStorage GetDirectoryDateStorage(string directory)
        {
            PrintDirectoryDateStorage directoryDateStorage = new PrintDirectoryDateStorage
            {
                DirectoryLevel1 = new PrintDirectoryDateStorageLevel {
                    Type = PrintDirectoryDateStorageType.NoSubDirectory
                },
                DirectoryLevel2 = new PrintDirectoryDateStorageLevel {
                    Type = PrintDirectoryDateStorageType.NoSubDirectory
                }
            };

            foreach (EnumDirectoryInfo directoryInfo in zdir.EnumerateDirectoriesInfo(directory, minLevel: 1, maxLevel: 1))
            {
                // priority DaySubDirectory, MonthSubDirectory, YearSubDirectory
                PrintDirectoryDateStorageLevel directoryDateStorageLevel = GetDirectoryDateStorageLevel(directoryInfo.SubDirectory);
                if (directoryDateStorageLevel.Type > directoryDateStorage.DirectoryLevel1.Type)
                {
                    directoryDateStorage.DirectoryLevel1 = directoryDateStorageLevel;
                    directoryDateStorage.DirectoryLevel2 = new PrintDirectoryDateStorageLevel {
                        Type = PrintDirectoryDateStorageType.NoSubDirectory
                    };
                }
                if (directoryDateStorageLevel.Type == directoryDateStorage.DirectoryLevel1.Type && directoryDateStorageLevel.Type != PrintDirectoryDateStorageType.NoSubDirectory)
                {
                    foreach (EnumDirectoryInfo directoryInfo2 in zdir.EnumerateDirectoriesInfo(directoryInfo.Directory, minLevel: 1, maxLevel: 1))
                    {
                        directoryDateStorageLevel = GetDirectoryDateStorageLevel(directoryInfo2.SubDirectory);
                        if (directoryDateStorageLevel.Type > directoryDateStorage.DirectoryLevel2.Type)
                        {
                            directoryDateStorage.DirectoryLevel2 = directoryDateStorageLevel;
                        }
                    }
                }
            }
            //printDirectoryInfo.SubDirectory1Type = printSubDirectory1Info;
            //printDirectoryInfo.SubDirectory2Type = printSubDirectory2Info;
            return(directoryDateStorage);
        }
Exemplo n.º 3
0
 public static PrintDirectoryDateStorage GetDirectoryDateStorage(string directory)
 {
     PrintDirectoryDateStorage directoryDateStorage = new PrintDirectoryDateStorage
         {
             DirectoryLevel1 = new PrintDirectoryDateStorageLevel { Type = PrintDirectoryDateStorageType.NoSubDirectory },
             DirectoryLevel2 = new PrintDirectoryDateStorageLevel { Type = PrintDirectoryDateStorageType.NoSubDirectory }
         };
     foreach (EnumDirectoryInfo directoryInfo in zdir.EnumerateDirectoriesInfo(directory, minLevel: 1, maxLevel: 1))
     {
         // priority DaySubDirectory, MonthSubDirectory, YearSubDirectory
         PrintDirectoryDateStorageLevel directoryDateStorageLevel = GetDirectoryDateStorageLevel(directoryInfo.SubDirectory);
         if (directoryDateStorageLevel.Type > directoryDateStorage.DirectoryLevel1.Type)
         {
             directoryDateStorage.DirectoryLevel1 = directoryDateStorageLevel;
             directoryDateStorage.DirectoryLevel2 = new PrintDirectoryDateStorageLevel { Type = PrintDirectoryDateStorageType.NoSubDirectory };
         }
         if (directoryDateStorageLevel.Type == directoryDateStorage.DirectoryLevel1.Type && directoryDateStorageLevel.Type != PrintDirectoryDateStorageType.NoSubDirectory)
         {
             foreach (EnumDirectoryInfo directoryInfo2 in zdir.EnumerateDirectoriesInfo(directoryInfo.Directory, minLevel: 1, maxLevel: 1))
             {
                 directoryDateStorageLevel = GetDirectoryDateStorageLevel(directoryInfo2.SubDirectory);
                 if (directoryDateStorageLevel.Type > directoryDateStorage.DirectoryLevel2.Type)
                     directoryDateStorage.DirectoryLevel2 = directoryDateStorageLevel;
             }
         }
     }
     //printDirectoryInfo.SubDirectory1Type = printSubDirectory1Info;
     //printDirectoryInfo.SubDirectory2Type = printSubDirectory2Info;
     return directoryDateStorage;
 }
Exemplo n.º 4
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);
                }
            }
        }
Exemplo n.º 5
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);
                }
            }
        }
Exemplo n.º 6
0
 private PrintDirectoryDateStorage GetPrintDirectoryDateStorage()
 {
     if (_directoryDateStorage == null)
         _directoryDateStorage = PrintDirectoryManager.GetDirectoryDateStorage(_destinationDirectory);
     return _directoryDateStorage;
 }