Esempio n. 1
0
        protected override void ProcessFtp(ISourceFactory factory)
        {
            using (var hostManager = AutoDiscover == true ?
                                     new DynamicHostManager(Config, new NetworkScanner(TaskPoolScheduler.Default), TaskPoolScheduler.Default)
                                         : (IHostManager) new StaticHostManager(Config.Known))
            {
                CancellationToken token = CancellationToken.None;
                if (Config.TimeOut.HasValue)
                {
                    CancellationTokenSource tokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(Config.TimeOut.Value));
                    token = tokenSource.Token;
                }

                var downloaders = factory.GetSources(hostManager);
                var tasks       = downloaders.Select(ftpDownloader => ftpDownloader.Download(token));

                var archiving = new DeleteArchiving();
                if (Archive.HasValue)
                {
                    log.Info("Archiving...");
                    archiving.Archive(Out, TimeSpan.FromDays(Archive.Value));
                }

                Task.WhenAll(tasks).Wait(token);
            }
        }
Esempio n. 2
0
        private async Task <bool> Download()
        {
            log.Info("Checking Ftp....");
            try
            {
                var         sources = downloaderFactory.GetSources(hostManager).ToArray();
                List <Task> tasks   = new List <Task>();
                log.Info("Downloading from {0} cameras", sources.Length);
                CancellationTokenSource token = new CancellationTokenSource();

                foreach (var item in sources)
                {
                    tasks.Add(item.Download(token.Token));
                }

                if (configuration.TimeOut.HasValue)
                {
                    var time = TimeSpan.FromSeconds(configuration.TimeOut.Value);
                    token.CancelAfter(time);
                    var timeoutTask = Task.Delay(time, token.Token);
                    await Task.WhenAny(Task.WhenAll(tasks), timeoutTask).ConfigureAwait(false);

                    if (timeoutTask.IsCompleted)
                    {
                        log.Error("FTP processing Timout!");
                        return(false);
                    }
                }
                else
                {
                    await Task.WhenAll(tasks).ConfigureAwait(false);
                }

                log.Info("Done!");
                return(true);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }

            return(false);
        }