private static void Main(string[] args)
        {
            var settingsProvider = new SettingsProvider();
            var msmqFactory      = new MessageQueueFactory();
            var downloadFactory  = new DownloadClientFactory(settingsProvider);
            var logger           = LogManager.GetLogger(nameof(FileControlService));
            var commandParser    = new CommandParser();
            var commandSender    = new CommandSender(msmqFactory, commandParser, settingsProvider, LogManager.GetLogger(nameof(CommandSender)));

            var messageHandlers = new IMessageHandler[]
            {
                new FileInfoMessageHandler(downloadFactory, LogManager.GetLogger(nameof(FileInfoMessageHandler))),
                new ServiceInfoMessageHandler(settingsProvider, LogManager.GetLogger(nameof(ServiceInfoMessageHandler)))
            };

            HostFactory.Run(x =>
            {
                x.Service(() => new FileControlService(msmqFactory, settingsProvider, logger, commandSender, messageHandlers));
                x.SetServiceName("MSMQ.StreamScanning.CentralService");
                x.SetDisplayName("MSMQ StreamScanning Central Service");
                x.StartAutomaticallyDelayed();
                x.RunAsLocalService();
                x.EnableServiceRecovery(y => y.RestartService(1).RestartService(1));
            });
        }
        public void GetDownloadClient_SupportedType_ReturnsIDownload(string url, string downloadLocation)
        {
            var fi     = new FileConnInfo(url, downloadLocation);
            var client = DownloadClientFactory.GetDownloadClient(fi);

            Assert.IsInstanceOf <IDownloader>(client);
        }
        public void GetDownloadClient_NullFieConnInfo_Throws()
        {
            ActualValueDelegate <object> testDelegate =
                () =>
            {
                FileConnInfo fi     = null;
                var          client = DownloadClientFactory.GetDownloadClient(fi);
                return(client);
            };

            Assert.That(testDelegate, Throws.TypeOf <ArgumentNullException>());
        }
        public void GetDownloadClient_NotSupportedType_Throws(string url, string downloadLocation)
        {
            ActualValueDelegate <object> testDelegate =
                () =>
            {
                var fi     = new FileConnInfo(url, downloadLocation);
                var client = DownloadClientFactory.GetDownloadClient(fi);
                return(client);
            };

            Assert.That(testDelegate, Throws.TypeOf <NotSupportedException>());
        }
Exemple #5
0
        public virtual void ProcessSource(string downloadLocation, string src)
        {
            Log.Info($"Download Start: {src}");

            if (downloadLocation == null)
            {
                throw new ArgumentNullException("Download Location can't be null");
            }
            if (src == null)
            {
                throw new ArgumentNullException("Source can't be null. Nothing to process.");
            }

            FileConnInfo fInfo = null;

            try
            {
                //Get New File Info object
                fInfo = new FileConnInfo(src, downloadLocation);

                //Get New Downloader Client
                IDownloader downloader = DownloadClientFactory.GetDownloadClient(fInfo);

                //Process Download
                if (downloader != null)
                {
                    downloader.CreateRequest();
                    downloader.GetResponse();
                }

                Log.Info($"Download Done: {src} ");
            }
            catch (Exception ex)
            {
                //Delete Partially Downloaded File
                if (fInfo != null)
                {
                    Helper.TryToDeleteFile(fInfo.LocalFilePath);
                }

                Log.Error($"Download Error: {src}", ex);
            }
        }