Example #1
0
        //public DownloadManager_v2 CreateDownloadManager_v2(bool useTestManager = false)
        public DownloadManager CreateDownloadManager()
        {
            MongoCollectionManager <DownloadedFile> mongoDownloadedFileManager = MongoCollectionManager <DownloadedFile> .Create(_xeConfig.zXPathElement("MongoDownloadedFile"));

            mongoDownloadedFileManager.IdGenerator = new MongoIdGeneratorInt(mongoDownloadedFileManager.GetCollection());
            mongoDownloadedFileManager.KeyName     = "Key"; // Key is the name of key field in DownloadedFile_v2

            //MongoCollectionManager<QueueDownloadFile> mongoQueueDownloadFileManager = MongoCollectionManager<QueueDownloadFile>.Create(_xeConfig.zXPathElement("MongoQueueDownloadFile_new"));
            //mongoQueueDownloadFileManager.IdGenerator = new MongoIdGeneratorInt(mongoQueueDownloadFileManager.GetCollection());
            //mongoDownloadedFileManager.KeyName = "Key";     // Key is the name of key field in QueueDownloadFile_v2
            MongoCollectionManager <QueueDownloadFile> mongoQueueDownloadFileManager = CreateMongoQueueDownloadFileManager(_xeConfig);

            MongoCollectionManager <DownloadLinkRef> mongoCurrentDownloadFileManager = MongoCollectionManager <DownloadLinkRef> .Create(_xeConfig.zXPathElement("MongoCurrentDownloadFile"));

            mongoCurrentDownloadFileManager.IdGenerator = new MongoIdGeneratorInt(mongoCurrentDownloadFileManager.GetCollection());

            ProtectLink protectLink = null;

            //Debrider debrider = null;
            //if (!_useTestManager)
            //    debrider = CreateDebrider();
            //else
            //    debrider = new DebriderAlldebridTest();
            Debrider debrider = CreateDebrider();
            DownloadManagerClientBase downloadManagerClient = CreateDownloadManagerClient();
            UncompressQueueManager    uncompressManager     = CreateUncompressManager();

            DownloadManager downloadManager = new DownloadManager();

            downloadManager.DownloadManagerClient           = downloadManagerClient;
            downloadManager.MongoDownloadedFileManager      = mongoDownloadedFileManager;
            downloadManager.MongoQueueDownloadFileManager   = mongoQueueDownloadFileManager;
            downloadManager.MongoCurrentDownloadFileManager = mongoCurrentDownloadFileManager;
            downloadManager.ProtectLink       = protectLink;
            downloadManager.Debrider          = debrider;
            downloadManager.UncompressManager = uncompressManager;
            return(downloadManager);
        }
        //public DownloadManager_v2 CreateDownloadManager_v2(bool useTestManager = false)
        public DownloadManager CreateDownloadManager()
        {
            MongoCollectionManager<DownloadedFile> mongoDownloadedFileManager = MongoCollectionManager<DownloadedFile>.Create(_xeConfig.zXPathElement("MongoDownloadedFile"));
            mongoDownloadedFileManager.IdGenerator = new MongoIdGeneratorInt(mongoDownloadedFileManager.GetCollection());
            mongoDownloadedFileManager.KeyName = "Key";     // Key is the name of key field in DownloadedFile_v2

            //MongoCollectionManager<QueueDownloadFile> mongoQueueDownloadFileManager = MongoCollectionManager<QueueDownloadFile>.Create(_xeConfig.zXPathElement("MongoQueueDownloadFile_new"));
            //mongoQueueDownloadFileManager.IdGenerator = new MongoIdGeneratorInt(mongoQueueDownloadFileManager.GetCollection());
            //mongoDownloadedFileManager.KeyName = "Key";     // Key is the name of key field in QueueDownloadFile_v2
            MongoCollectionManager<QueueDownloadFile> mongoQueueDownloadFileManager = CreateMongoQueueDownloadFileManager(_xeConfig);

            MongoCollectionManager<DownloadLinkRef> mongoCurrentDownloadFileManager = MongoCollectionManager<DownloadLinkRef>.Create(_xeConfig.zXPathElement("MongoCurrentDownloadFile"));
            mongoCurrentDownloadFileManager.IdGenerator = new MongoIdGeneratorInt(mongoCurrentDownloadFileManager.GetCollection());

            ProtectLink protectLink = null;

            //Debrider debrider = null;
            //if (!_useTestManager)
            //    debrider = CreateDebrider();
            //else
            //    debrider = new DebriderAlldebridTest();
            Debrider debrider = CreateDebrider();
            DownloadManagerClientBase downloadManagerClient = CreateDownloadManagerClient();
            UncompressQueueManager uncompressManager = CreateUncompressManager();

            DownloadManager downloadManager = new DownloadManager();
            downloadManager.DownloadManagerClient = downloadManagerClient;
            downloadManager.MongoDownloadedFileManager = mongoDownloadedFileManager;
            downloadManager.MongoQueueDownloadFileManager = mongoQueueDownloadFileManager;
            downloadManager.MongoCurrentDownloadFileManager = mongoCurrentDownloadFileManager;
            downloadManager.ProtectLink = protectLink;
            downloadManager.Debrider = debrider;
            downloadManager.UncompressManager = uncompressManager;
            return downloadManager;
        }
        // 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;
        }