Esempio n. 1
0
        private void _SearchPostToDownload(DateTime lastRunDateTime)
        {
            //Trace.WriteLine("{0:dd-MM-yyyy HH:mm:ss} - Search download from {1:dd-MM-yyyy HH:mm:ss}", DateTime.Now, lastRunDateTime);
            bool download = false;

            lastRunDateTime = lastRunDateTime.AddDays(-1);
            //foreach (ServerManager server in _servers.Values)
            foreach (IServerManager server in _servers.Values)
            {
                if (server.EnableSearchDocumentToDownload)
                {
                    Trace.WriteLine("{0:dd-MM-yyyy HH:mm:ss} - Search download on {1} from {2:dd-MM-yyyy HH:mm:ss}", DateTime.Now, server.Name, lastRunDateTime);
                    int nb = 0;
                    foreach (IPostToDownload post in server.FindFromDateTime(lastRunDateTime))
                    {
                        if (RunSourceCommand.IsExecutionAborted())
                        {
                            break;
                        }

                        if (TryDownloadPost(post, server.DownloadDirectory))
                        {
                            download = true;
                            if (_postDownloadServerLimit != 0 && ++nb == _postDownloadServerLimit)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            if (!download)
            {
                Trace.WriteLine("{0:dd-MM-yyyy HH:mm:ss} - Nothing to download", DateTime.Now);
            }
        }
Esempio n. 2
0
        // bool loadNewPost = true, bool searchPostToDownload = true, bool uncompressFile = true, bool sendMail = false
        public void Run()
        {
            DateTime nextRunDateTime = _mongoDownloadAutomateManager.GetNextRunDateTime();
            bool     messageNextRun  = true;

            while (true)
            {
                if (RunSourceCommand.IsExecutionAborted())
                {
                    break;
                }
                if ((_runNow || DateTime.Now >= nextRunDateTime) && (_loadNewPost || _searchPostToDownload))
                {
                    _runNow = false;

                    if (_loadNewPost)
                    {
                        _LoadNewPost();
                    }

                    if (_searchPostToDownload)
                    {
                        DateTime?lastRunDateTime = _mongoDownloadAutomateManager.GetLastRunDateTime();
                        if (lastRunDateTime == null)
                        {
                            lastRunDateTime = DateTime.Now.AddDays(-3);
                        }

                        _SearchPostToDownload((DateTime)lastRunDateTime);

                        _mongoDownloadAutomateManager.SetLastRunDateTime(DateTime.Now);
                        nextRunDateTime = _mongoDownloadAutomateManager.GetNextRunDateTime();
                    }
                    else // calculate nextRunDateTime if !_searchPostToDownload
                    {
                        nextRunDateTime = DateTime.Now + _mongoDownloadAutomateManager.GetTimeBetweenRun();
                    }

                    messageNextRun = true;
                }
                else
                {
                    Try(() => _SendMail(_sendMail));
                }
                if (!_stayRunning && !_searchPostToDownload && !ActiveDownload() && TaskManager.CurrentTaskManager.Count == 0)
                {
                    break;
                }

                if (!ActiveDownload() && TaskManager.CurrentTaskManager.Count == 0 && messageNextRun)
                {
                    if (_loadNewPost || _searchPostToDownload)
                    {
                        Trace.WriteLine("{0:dd-MM-yyyy HH:mm:ss} - next run {1:dd-MM-yyyy HH:mm:ss}", DateTime.Now, nextRunDateTime);
                    }
                    else
                    {
                        Trace.WriteLine("{0:dd-MM-yyyy HH:mm:ss} - nothing to run", DateTime.Now);
                    }
                    messageNextRun = false;
                }

                Thread.Sleep(_waitTimeBetweenOperation);
            }
        }