Exemple #1
0
        public FindPrintManager Create()
        {
            if (_version < 3 || _version > 6)
                throw new PBException("bad version {0}", _version);

            XmlConfig config = XmlConfig.CurrentConfig;
            _printConfig = config.GetConfig("PrintConfig");
            _printList1Config = config.GetConfig("PrintList1Config");
            _printList2Config = config.GetConfig("PrintList2Config");

            //_printTitleManager = CreatePrintTitleManager.Create(_version, _gapDayBefore, _gapDayAfter);
            PrintTitleManagerCreator createPrintTitleManager = new PrintTitleManagerCreator();
            createPrintTitleManager.Init(_xeConfig);
            createPrintTitleManager.SetParameters(_parameters);
            createPrintTitleManager.Version = _version;
            createPrintTitleManager.GapDayBefore = _gapDayBefore;
            createPrintTitleManager.GapDayAfter = _gapDayAfter;
            _printTitleManager = createPrintTitleManager.Create();

            _findDayManager = CreateFindDayManager();
            _printManager = CreatePrintManager();
            _postTypeDirectories = CreatePostTypeDirectories();
            _findPrintManager = _CreateFindPrintManager();

            return _findPrintManager;
        }
Exemple #2
0
        // int gapDayBefore = 0, int gapDayAfter = 0, int? traceLevel = null
        //public static DownloadAutomateManager_v2 Create(int version = 3, bool dailyPrintManager = false, bool useTestManager = false, bool test = false)
        //{
        //    CreateDownloadAutomateManager create = new CreateDownloadAutomateManager();
        //    create._version = version;
        //    create._dailyPrintManager = dailyPrintManager;
        //    //create._gapDayBefore = gapDayBefore;
        //    //create._gapDayAfter = gapDayAfter;
        //    create._useTestManager = useTestManager;
        //    //create._traceLevel = traceLevel;
        //    create._test = test;
        //    return create._Create();
        //}

        public DownloadAutomateManager Create()
        {
            // from DownloadAutomate_f.CreateDownloadAutomate_v2()

            // le 01/11/2014 désactive version 1 et version 2
            // version 1 : utilise l'ancien FindPrintManager, l'ancienne liste de print dans print_list1.xml, l'ancien pattern de date FindPrints/Dates/Date avec l'ancien FindDateManager
            // version 2 : version 1 + le nouveau FindPrintManager_new avec le nouveau PrintTitleManager, la nouvelle liste de print dans print_list2.xml,
            // version 3 : version 2 + le nouveau pattern de date FindPrints/Dates/DateNew avec le nouveau FindDateManager_new
            // version 4 (not used) : version 3 + découpe le titre avec "du" ou "-" (PrintTitleManager)
            // version 5 : version 3 +  new find date
            // version 6 : version 5 +  printTitleManager version 2 + findPrintManager version 2

            if (_version < 3 || _version > 6)
            {
                throw new PBException("bad version {0}", _version);
            }

            Trace.WriteLine("create download automate : version {0} useTestManager {1} traceLevel {2}", _version, _useTestManager, _traceLevel.zToStringOrNull());

            //if (!_test)
            //    _xeConfig = XmlConfig.CurrentConfig.GetElement("DownloadAutomateManager");
            //else
            //    _xeConfig = XmlConfig.CurrentConfig.GetElement("DownloadAutomateManager_Test");

            _mongoDownloadAutomateManager = CreateMongoDownloadAutomateManager();

            //_findPrintManager = CreateFindPrintManager();
            _findPrintManager = FindPrintManagerCreator.Create(_xeConfig, _parameters, _version);

            _downloadManager = CreateDownloadManager();
            _mailSender      = CreateMailSender();
            _mailMessage     = CreateMailMessage();

            _downloadAutomateManager = _CreateDownloadAutomateManager();

            //InitServers();
            //CreateServerManagers();

            _downloadAutomateManager.Init(_xeConfig);
            _downloadAutomateManager.SetParameters(_parameters);

            TraceResult();

            //if (!ControlDownloadManagerClient())
            //    throw new PBException("error DownloadManagerClient is not working");

            if (_traceLevel != null)
            {
                //Trace.CurrentTrace.TraceLevel = (int)_traceLevel;
                pb.TraceLevel.Level = (int)_traceLevel;
            }

            //_downloadAutomateManager.Start();

            return(_downloadAutomateManager);
        }
Exemple #3
0
        public static FindPrintInfo Find(FindPrintManager findPrintManager, string title, PrintType printType = PrintType.Unknow, bool forceSelect = false, Date?expectedDate = null)
        {
            FindPrint findPrint = new FindPrint();

            findPrint._findPrintManager = findPrintManager;
            findPrint._sourceTitle      = title;
            findPrint._printType        = printType;
            findPrint._forceSelect      = forceSelect;
            findPrint._expectedDate     = expectedDate;
            findPrint._Find();
            return(findPrint.GetFindPrintInfo());
        }
Exemple #4
0
        public static void RenameDailyPrintFiles(string sourceDirectory, string destinationDirectory, string logFile, bool simulate = true, string parameters = null)
        {
            // parameters : (FindPrintManager) int version, bool dailyPrintManager, int gapDayBefore, int gapDayAfter
            //NamedValues<ZValue> parameters2 = NamedValues.ParseValues(parameters);
            NamedValues <ZValue> parameters2 = ParseParameters(parameters);
            XElement             xe          = GetDownloadAutomateManagerConfig(GetTestValue(parameters2));
            int version = xe.zXPathValue("Version").zTryParseAs(6);
            FindPrintManager findPrintManager = FindPrintManagerCreator.Create(xe, parameters2, version);
            //PrintFileManager_v2.GetDailyPrintFiles(sourceDirectory).zRenameDailyPrintFiles(findPrintManager, destinationDirectory, simulate: simulate).zSave(logFile);

            string lastDirectory = null;

            PrintFileManager_v2.GetDailyPrintFiles(sourceDirectory).zGetRenameDailyPrintFilesInfos(findPrintManager)
            .Select(renamePrintFile =>
            {
                if (!simulate)
                {
                    string directory = zPath.GetDirectoryName(renamePrintFile.SourceFile);
                    if (directory != lastDirectory)
                    {
                        // remove empty directories
                        if (lastDirectory != null)
                        {
                            //zdir.DeleteEmptyDirectory(lastDirectory, deleteOnlySubdirectory: false);
                            zdir.DeleteEmptyDirectory(lastDirectory, recurse: true);
                        }
                        lastDirectory = directory;
                    }
                    if (renamePrintFile.RenameFile)
                    {
                        renamePrintFile.DestinationFile = PrintFileManager_v2.RenamePrintFile(renamePrintFile.SourceFile, zPath.Combine(destinationDirectory, renamePrintFile.File));
                    }
                }
                return(renamePrintFile);
            }).zSave(logFile);
            // remove empty directories
            if (!simulate && lastDirectory != null)
            {
                //zdir.DeleteEmptyDirectory(lastDirectory, deleteOnlySubdirectory: false);
                zdir.DeleteEmptyDirectory(lastDirectory, recurse: true);
            }
        }
Exemple #5
0
        private FindPrintManager _CreateFindPrintManager()
        {
            FindPrintManager findPrintManager = new FindPrintManager();
            findPrintManager.TrySplitTitle = _trySplitTitle;
            findPrintManager.PrintTitleManager = _printTitleManager;
            findPrintManager.FindPrintList = new RegexValuesList(_printList2Config.GetElements("FindPrints/Prints/Print"), compileRegex: true);
            if (_dailyPrintManager)
            {
                findPrintManager.FindPrintList.Add(_printList2Config.GetElements("FindPrints/Prints/ShortPrint"), compileRegex: true);
                findPrintManager.FindDayManager = _findDayManager;
                findPrintManager.UseFindDay = true;
                findPrintManager.SetGapDayBefore(_gapDayBefore);
                findPrintManager.SetGapDayAfter(_gapDayAfter);
            }
            findPrintManager.PrintManager = _printManager;
            findPrintManager.PostTypeDirectories = _postTypeDirectories;
            findPrintManager.DefaultPrintDirectory = _printList1Config.Get("FindPrints/DefaultPrintDirectory");
            findPrintManager.UnknowPrintDirectory = _printList1Config.Get("FindPrints/UnknowPrintDirectory");

            //if (_version >= 6)
            //    findPrintManager.Version = 2;

            return findPrintManager;
        }
Exemple #6
0
 public static FindPrintInfo Find(FindPrintManager findPrintManager, string title, PrintType printType = PrintType.Unknow, bool forceSelect = false, Date? expectedDate = null)
 {
     FindPrint findPrint = new FindPrint();
     findPrint._findPrintManager = findPrintManager;
     findPrint._sourceTitle = title;
     findPrint._printType = printType;
     findPrint._forceSelect = forceSelect;
     findPrint._expectedDate = expectedDate;
     findPrint._Find();
     return findPrint.GetFindPrintInfo();
 }
Exemple #7
0
        //private static RenamePrintFile RenamePrintFile(FindPrintManager findPrintManager, string file, Date date, string destinationDirectory, bool simulate)
        private static RenamePrintFile GetRenamePrintFileInfo(FindPrintManager findPrintManager, string file, Date date)
        {
            RenamePrintFile renamePrintFile = new RenamePrintFile();

            //try
            //{
            renamePrintFile.SourceFile   = file;
            renamePrintFile.Title        = zPath.GetFileNameWithoutExtension(file);
            renamePrintFile.ExpectedDate = date;
            FindPrintInfo findPrint = findPrintManager.Find(renamePrintFile.Title, PrintType.Print, expectedDate: date);

            if (findPrint.DayTitle != null)
            {
                renamePrintFile.FormatedTitle = findPrint.DayTitle;
            }
            else
            {
                renamePrintFile.FormatedTitle = findPrint.titleInfo.FormatedTitle;
            }
            renamePrintFile.Name        = findPrint.name;
            renamePrintFile.Date        = findPrint.date;
            renamePrintFile.DateType    = findPrint.dateType;
            renamePrintFile.Number      = findPrint.number;
            renamePrintFile.Special     = findPrint.special;
            renamePrintFile.SpecialText = findPrint.specialText;
            renamePrintFile.Label       = findPrint.label;
            renamePrintFile.RemainText  = findPrint.remainText;
            if (findPrint.print != null)
            {
                renamePrintFile.PrintName = findPrint.print.Name;
            }

            if (!findPrint.found)
            {
                renamePrintFile.Error = string.Format("unknow print \"{0}\" date {1} formated title \"{2}\"", zPath.GetFileName(file), findPrint.date, findPrint.titleInfo.FormatedTitle);
            }
            else if (findPrint.date == null)
            {
                renamePrintFile.Error = string.Format("date not found \"{0}\"", zPath.GetFileName(file));
            }

            if (findPrint.found && findPrint.date != null)
            {
                int dateGap = findPrint.date.Value.Subtract(date).Days;
                if (dateGap < -findPrintManager.GapDayBefore || dateGap > findPrintManager.GapDayAfter)
                {
                    renamePrintFile.Error = string.Format("wrong date found {0} - \"{1}\"", findPrint.date, renamePrintFile.Title);
                }
                else
                {
                    renamePrintFile.RenameFile = true;
                    renamePrintFile.File       = findPrint.file + zPath.GetExtension(file);
                    //string newfile = zPath.Combine(destinationDirectory, findPrint.file) + zPath.GetExtension(file);
                    //newfile = zfile.GetNewFilename(newfile);
                    //if (!simulate)
                    //{
                    //    zfile.CreateFileDirectory(newfile);
                    //    zFile.Move(file, newfile);
                    //}
                }
            }
            //}
            //catch (Exception ex)
            //{
            //    Trace.WriteLine("  error print \"{0}\"", zPath.GetFileName(file));
            //    Trace.WriteLine(Error.GetErrorMessage(ex, true, false));
            //    Trace.WriteLine();
            //}
            return(renamePrintFile);
        }
Exemple #8
0
        //public static IEnumerable<RenamePrintFile> RenameDailyPrintFiles(IEnumerable<DailyPrintFile> files, FindPrintManager findPrintManager, string destinationDirectory, bool simulate = true)
        public static IEnumerable <RenamePrintFile> GetRenameDailyPrintFilesInfos(IEnumerable <DailyPrintFile> files, FindPrintManager findPrintManager)
        {
            //string lastDirectory = null;
            foreach (DailyPrintFile file in files)
            {
                //if (file.Directory != lastDirectory)
                //{
                //    // remove empty directories
                //    if (!simulate && lastDirectory != null)
                //        zdir.DeleteEmptyDirectory(lastDirectory, deleteOnlySubdirectory: false);
                //    lastDirectory = file.Directory;
                //}
                //yield return RenamePrintFileI(findPrintManager, file.File, file.Date, destinationDirectory, simulate);
                yield return(GetRenamePrintFileInfo(findPrintManager, file.File, file.Date));
            }

            // remove empty directories
            //if (!simulate && lastDirectory != null)
            //    zdir.DeleteEmptyDirectory(lastDirectory, deleteOnlySubdirectory: false);
        }
Exemple #9
0
 // string destinationDirectory, bool simulate = true
 public static IEnumerable <RenamePrintFile> zGetRenameDailyPrintFilesInfos(this IEnumerable <DailyPrintFile> files, FindPrintManager findPrintManager)
 {
     return(PrintFileManager_v2.GetRenameDailyPrintFilesInfos(files, findPrintManager));
 }
        // int gapDayBefore = 0, int gapDayAfter = 0, int? traceLevel = null
        //public static DownloadAutomateManager_v2 Create(int version = 3, bool dailyPrintManager = false, bool useTestManager = false, bool test = false)
        //{
        //    CreateDownloadAutomateManager create = new CreateDownloadAutomateManager();
        //    create._version = version;
        //    create._dailyPrintManager = dailyPrintManager;
        //    //create._gapDayBefore = gapDayBefore;
        //    //create._gapDayAfter = gapDayAfter;
        //    create._useTestManager = useTestManager;
        //    //create._traceLevel = traceLevel;
        //    create._test = test;
        //    return create._Create();
        //}

        public DownloadAutomateManager Create()
        {
            // from DownloadAutomate_f.CreateDownloadAutomate_v2()

            // le 01/11/2014 désactive version 1 et version 2
            // version 1 : utilise l'ancien FindPrintManager, l'ancienne liste de print dans print_list1.xml, l'ancien pattern de date FindPrints/Dates/Date avec l'ancien FindDateManager
            // version 2 : version 1 + le nouveau FindPrintManager_new avec le nouveau PrintTitleManager, la nouvelle liste de print dans print_list2.xml,
            // version 3 : version 2 + le nouveau pattern de date FindPrints/Dates/DateNew avec le nouveau FindDateManager_new
            // version 4 (not used) : version 3 + découpe le titre avec "du" ou "-" (PrintTitleManager)
            // version 5 : version 3 +  new find date
            // version 6 : version 5 +  printTitleManager version 2 + findPrintManager version 2

            if (_version < 3 || _version > 6)
                throw new PBException("bad version {0}", _version);

            Trace.WriteLine("create download automate : version {0} useTestManager {1} traceLevel {2}", _version, _useTestManager, _traceLevel.zToStringOrNull());

            //if (!_test)
            //    _xeConfig = XmlConfig.CurrentConfig.GetElement("DownloadAutomateManager");
            //else
            //    _xeConfig = XmlConfig.CurrentConfig.GetElement("DownloadAutomateManager_Test");

            _mongoDownloadAutomateManager = CreateMongoDownloadAutomateManager();

            //_findPrintManager = CreateFindPrintManager();
            _findPrintManager = FindPrintManagerCreator.Create(_xeConfig, _parameters, _version);

            _downloadManager = CreateDownloadManager();
            _mailSender = CreateMailSender();
            _mailMessage = CreateMailMessage();

            _downloadAutomateManager = _CreateDownloadAutomateManager();

            //InitServers();
            //CreateServerManagers();

            _downloadAutomateManager.Init(_xeConfig);
            _downloadAutomateManager.SetParameters(_parameters);

            TraceResult();

            //if (!ControlDownloadManagerClient())
            //    throw new PBException("error DownloadManagerClient is not working");

            if (_traceLevel != null)
                Trace.CurrentTrace.TraceLevel = (int)_traceLevel;

            //_downloadAutomateManager.Start();

            return _downloadAutomateManager;
        }