Example #1
0
        public void Start()
        {
            var log = LogManager.GetCurrentClassLogger();

            VerifyConfiguration(log);

            taskTokenSource = new CancellationTokenSource();
            var taskToken = taskTokenSource.Token;
            var downloader = new DownloaderService(LogManager.GetLogger("Downloader"), new HmaCliService(new FreeGeoIpService(log), Settings.ExcludedIps, Settings.HMAInstallFullPath, log));
            var parser = new ParsingService(LogManager.GetLogger("Parser"));

            downlaodTask = new Task(() =>
            {
                if (Program.TestAccount == null)
                {
                    while (!taskToken.IsCancellationRequested)
                    {
                        try
                        {
                            downloader.Download(taskToken);
                        }
                        catch (Exception ex)
                        {
                            log.Error("Uncaught exception in Downloader", ex);
                        }
                        if (!taskToken.IsCancellationRequested) Thread.Sleep(Settings.DownloaderBatchWaitTime);
                    }
                }
                else
                {
                    downloader.Download(taskToken, Program.TestAccount);
                    log.Info("Single account download complete");
                }

            }, taskTokenSource.Token);

            if (Program.RunDownloader)
            {
                downlaodTask.Start();
            }

            parseTask = new Task(() =>
            {
                while (!taskToken.IsCancellationRequested)
                {
                    try
                    {
                        parser.ParseEmlFiles(taskToken);
                    }
                    catch (Exception ex)
                    {
                        log.Error("Uncaught exception in Parser", ex);
                    }
                    if (!taskToken.IsCancellationRequested) Thread.Sleep(Settings.ParserBatchWaitTime);
                }
            }, taskTokenSource.Token);

            parseTask.Start();

        }
Example #2
0
 /// <summary>
 /// This method is called when the BroadcastReceiver is receiving an Intent
 /// broadcast.
 /// </summary>
 /// <param name="context">
 /// The Context in which the receiver is running.
 /// </param>
 /// <param name="intent">
 /// The Intent being received.
 /// </param>
 public override void OnReceive(Context context, Intent intent)
 {
     try
     {
         DownloaderService.StartDownloadServiceIfRequired(
             context, intent, typeof(SampleDownloaderService));
     }
     catch (PackageManager.NameNotFoundException e)
     {
         e.PrintStackTrace();
     }
 }
Example #3
0
 public ModerationModule(ModerationServices mod,
                         LevelTesting levelTesting,
                         DataServices dataServices,
                         TimerService timer,
                         DownloaderService dlSvc)
 {
     _timer        = timer;
     _dataServices = dataServices;
     _levelTesting = levelTesting;
     _mod          = mod;
     downloaderSvc = dlSvc;
 }
        public DownloadWindow(LicenceManager licenceManager, DownloaderService downloaderService)
        {
            InitializeComponent();

            var cancellationToken = new CancellationToken();

            this.licenceManager = licenceManager;
            downloader          = downloaderService;

            Task.Factory.StartNew(() => StartListeningToDownloadChannel(downloader.GetChannelReader(), cancellationToken));

            DisplayInstalledProducts();
        }
Example #5
0
        public void ValidateEmptyLinks()
        {
            var downloadRequest = new DownloadRequest()
            {
                Threads = 2,
                Links   = null
            };
            var downloadService = new DownloaderService(new FileDonwladStatus()
                                                        , NSubstitute.Substitute.For <Microsoft.Extensions.Configuration.IConfiguration>()
                                                        , NSubstitute.Substitute.For <Microsoft.Extensions.Logging.ILogger <DownloaderService> >());
            var duplicated = downloadService.GetDuplicatedFiles(downloadRequest);

            Assert.Empty(duplicated);
        }
Example #6
0
        /// <summary>
        /// The get expansion files.
        /// </summary>
        /// <returns>
        /// The get expansion files.
        /// </returns>
        private bool GetExpansionFiles()
        {
            bool result = false;

            try
            {
                // Build the intent that launches this activity.
                Intent launchIntent = Intent;
                var    intent       = new Intent(this, typeof(ExpansionDownloaderActivity));
                intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop);
                intent.SetAction(launchIntent.Action);

                if (launchIntent.Categories != null)
                {
                    foreach (string category in launchIntent.Categories)
                    {
                        intent.AddCategory(category);
                    }
                }

                // Build PendingIntent used to open this activity when user
                // taps the notification.
                Android.App.PendingIntent pendingIntent = Android.App.PendingIntent.GetActivity(
                    this, 0, intent, Android.App.PendingIntentFlags.UpdateCurrent);

                // Always force download of LVL
                DownloadsDB.GetDB(this).UpdateMetadata(0, 0);
                // Request to start the download
                DownloaderServiceRequirement startResult = DownloaderService.StartDownloadServiceIfRequired(
                    this, pendingIntent, typeof(ExpansionDownloaderService));

                // The DownloaderService has started downloading the files,
                // show progress otherwise, the download is not needed so  we
                // fall through to starting the actual app.
                if (startResult != DownloaderServiceRequirement.NoDownloadRequired)
                {
                    InitializeDownloadUi();
                    result = true;
                }
            }
            catch (PackageManager.NameNotFoundException e)
            {
#if DEBUG
                Android.Util.Log.Debug(Tag, "Cannot find own package!");
#endif
                e.PrintStackTrace();
            }

            return(result);
        }
Example #7
0
        public async Task EmptyLinksDontStartDownload()
        {
            var downloadRequest = new DownloadRequest()
            {
                Threads = 2,
                Links   = null
            };
            var fileDownloadStatus = new FileDonwladStatus();
            var downloadService    = new DownloaderService(fileDownloadStatus
                                                           , NSubstitute.Substitute.For <Microsoft.Extensions.Configuration.IConfiguration>()
                                                           , NSubstitute.Substitute.For <Microsoft.Extensions.Logging.ILogger <DownloaderService> >());
            await downloadService.Download(downloadRequest);

            Assert.Empty(fileDownloadStatus.Definitions);
        }
Example #8
0
 private void UpdateWCFService()
 {
     if (DownloaderService.IsServiceStarted())
     {
         serviceToolStripMenuItem.Text = "Stop service";
         toolService.Checked           = true;
         toolService.Text = "Stop service";
     }
     else
     {
         serviceToolStripMenuItem.Text = "Start service";
         toolService.Checked           = false;
         toolService.Text = "Start service";
     }
 }
        private DownloadsViewModel()
        {
            Service = DownloaderService.GetService;
            Service.CurrentDownloadFileChanged += Service_CurrentDownloadFileChanged;
            Service.DownloadProgressChanged    += Service_DownloadProgressChanged;
            Service.DownloadQueueComplete      += Service_DownloadQueueComplete;
            Service.DownloadComplete           += Service_DownloadComplete;

            if (Service.CurrentDownloadTrack != null)
            {
                CurrentDownloadFile = Service.CurrentDownloadTrack;
                Changed("CurrentDownloadFile");
                MaximumValue            = Service.Maximum;
                VisibilityNoNowDownload = Visibility.Collapsed;
                VisibilityNowDownload   = Visibility.Visible;
                Changed("VisibilityNoNowDownload");
                Changed("VisibilityNowDownload");
                Changed("TitleString");
                Changed("MaximumValue");
                Changed("ArtistString");
                Changed("AlbumString");
                Changed("YearAlbumString");
            }
            else
            {
                VisibilityNoNowDownload = Visibility.Visible;
                VisibilityNowDownload   = Visibility.Collapsed;
                Changed("VisibilityNoNowDownload");
                Changed("VisibilityNowDownload");
            }

            playlistCurrent = new PlaylistFile()
            {
                Artist  = "",
                Cover   = "ms-appx:///Assets/Images/playlist-placeholder.png",
                Id      = 778,
                IsLocal = true,
                Year    = "2019",
                IsAlbum = false,
                Genre   = "без жанра",
                Name    = "Загруженное"
            };

            ShowQueueCommand = new RelayCommand(async() =>
            {
                await ContentDialogService.Show(new QueueDownloadContentDialog(Service.QueueTracks));
            });
        }
        public SamplesImporterController(ISamplesImporterView view)
        {
            _view = view;

            _sampleImporterService = new SampleImporterService();
            _downloaderService     = new DownloaderService();
            _settingsService       = new SettingsService();
            _networkStatusService  = new NetworkStatusService();

            Samples       = new List <Sample>();
            _projectsPath = string.Empty;

            Init();

            view.SetController(this);
        }
Example #11
0
        /// <summary>
        /// The get expansion files.
        /// </summary>
        /// <returns>
        /// The get expansion files.
        /// </returns>
        private bool GetExpansionFiles()
        {
            bool result = false;

            try
            {
                // Build the intent that launches this activity.
                Intent launchIntent = this.Intent;
                var    intent       = new Intent(this, typeof(SampleDownloaderActivity));
                intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop);
                intent.SetAction(launchIntent.Action);

                if (launchIntent.Categories != null)
                {
                    foreach (string category in launchIntent.Categories)
                    {
                        intent.AddCategory(category);
                    }
                }

                // Build PendingIntent used to open this activity when user
                // taps the notification.
                PendingIntent pendingIntent = PendingIntent.GetActivity(
                    this, 0, intent, PendingIntentFlags.UpdateCurrent);

                // Request to start the download
                DownloadServiceRequirement startResult = DownloaderService.StartDownloadServiceIfRequired(
                    this, pendingIntent, typeof(SampleDownloaderService));

                // The DownloaderService has started downloading the files,
                // show progress otherwise, the download is not needed so  we
                // fall through to starting the actual app.
                if (startResult != DownloadServiceRequirement.NoDownloadRequired)
                {
                    this.InitializeDownloadUi();
                    result = true;
                }
            }
            catch (PackageManager.NameNotFoundException e)
            {
                Debug.WriteLine("Cannot find own package! MAYDAY!");
                e.PrintStackTrace();
            }

            return(result);
        }
        internal static async Task Main(string[] args)
        {
            const string localhost = "127.0.0.1";

            var loggerFactory = new LoggerFactory();

            loggerFactory.AddNLog();
            LogManager.LoadConfiguration("nlog.config");

            var store      = new RocksDbKeyValueStore();
            var memberList = new string[0];
            Func <IEnumerable <string> > memberListProvider = () => memberList;

            var d1 = CreateDownloader(loggerFactory, @"R:\d1", store, memberListProvider);
            var d2 = CreateDownloader(NullLoggerFactory.Instance, @"R:\d2", store, memberListProvider);

            var s1 = new Server
            {
                Ports    = { new ServerPort(localhost, ServerPort.PickUnused, ServerCredentials.Insecure) },
                Services = { DownloaderService.BindService(d1.DownloaderService) }
            };
            var s2 = new Server
            {
                Ports    = { new ServerPort(localhost, ServerPort.PickUnused, ServerCredentials.Insecure) },
                Services = { DownloaderService.BindService(d2.DownloaderService) }
            };

            s1.Start();
            s2.Start();

            memberList = s1.Ports.Concat(s2.Ports).Select(p => $"{localhost}:{p.BoundPort}").ToArray();

            var t1 = d1.InvokeAsync();
            var t2 = d2.InvokeAsync();

            await Task.WhenAll(t1, t2);

            await s1.ShutdownAsync();

            await s2.ShutdownAsync();

            Console.WriteLine("Finished");
        }
Example #13
0
 private void StartStopWCFService()
 {
     try
     {
         if (DownloaderService.IsServiceStarted())
         {
             DownloaderService.StopService();
         }
         else
         {
             DownloaderService.StartService();
         }
         UpdateWCFService();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #14
0
        private void StartExpansionDownload()
        {
            //("MainActivity.StartExpansionDownload");
            Intent intent  = this.Intent;
            Intent intent2 = new Intent(this, typeof(SMainActivity));

            intent2.SetFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask);
            intent2.SetAction(intent.Action);
            if (intent.Categories != null)
            {
                foreach (string category in intent.Categories)
                {
                    intent2.AddCategory(category);
                }
            }
            PendingIntent activity = PendingIntent.GetActivity(this, 0, intent2, PendingIntentFlags.UpdateCurrent);

            try
            {
                DownloaderServiceRequirement downloaderServiceRequirement = DownloaderService.StartDownloadServiceIfRequired(this, activity, typeof(ExpansionDownloaderService));
                if (downloaderServiceRequirement != 0)
                {
                    //("MainActivity.StartExpansionDownload A startResult:" + downloaderServiceRequirement);
                    this._downloaderServiceConnection = DownloaderClientMarshaller.CreateStub(this, typeof(ExpansionDownloaderService));
                    this._downloaderServiceConnection.Connect(this);
                    //("MainActivity.StartExpansionDownload B startResult:" + downloaderServiceRequirement);
                }
                else
                {
                    //("MainActivity.StartExpansionDownload - all files have finished downloading already");
                    this.OnExpansionDowloaded();
                }
            }
            catch (IllegalStateException ex)
            {
                //("MainActivity.StartExpansionDownload ERROR exception:" + ex);
                Crashes.TrackError(ex);
            }
        }
Example #15
0
        public async Task OnlyHttp()
        {
            var downloadRequest = new DownloadRequest()
            {
                Threads = 2,
                Links   = new System.Collections.Generic.List <LinkSave>
                {
                    new LinkSave {
                        Filename = "file1", Link = "http://someValidLink"
                    },
                    new LinkSave {
                        Filename = "file2", Link = "http://someValidLink"
                    }
                }
            };
            var fileDownloadStatus = new FileDonwladStatus();
            var downloadService    = new DownloaderService(fileDownloadStatus
                                                           , NSubstitute.Substitute.For <Microsoft.Extensions.Configuration.IConfiguration>()
                                                           , NSubstitute.Substitute.For <Microsoft.Extensions.Logging.ILogger <DownloaderService> >());

            Assert.True(downloadService.ValidateHttpLinks(downloadRequest));
        }
Example #16
0
        private bool GetExpansionFiles()
        {
            bool result = false;

            // Build the intent that launches this activity.
            Intent launchIntent = this.Intent;
            var    intent       = new Intent(this, typeof(SuperSimpleActivity));

            intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop);
            intent.SetAction(launchIntent.Action);

            if (launchIntent.Categories != null)
            {
                foreach (string category in launchIntent.Categories)
                {
                    intent.AddCategory(category);
                }
            }

            // Build PendingIntent used to open this activity when user
            // taps the notification.
            PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent);

            // Request to start the download
            DownloadServiceRequirement startResult = DownloaderService.StartDownloadServiceIfRequired(this, pendingIntent, typeof(SampleDownloaderService));

            // The DownloaderService has started downloading the files,
            // show progress otherwise, the download is not needed so  we
            // fall through to starting the actual app.
            if (startResult != DownloadServiceRequirement.NoDownloadRequired)
            {
                this.downloaderServiceConnection = ClientMarshaller.CreateStub(this, typeof(SampleDownloaderService));

                result = true;
            }

            return(result);
        }
        private bool GetExpansionFiles()
        {
            bool result = false;

            try
            {
                Intent launchIntent = Intent;
                var    intent       = new Intent(this, typeof(LibraryDownloaderActivity));
                intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop);
                intent.SetAction(launchIntent.Action);

                if (launchIntent.Categories != null)
                {
                    foreach (string category in launchIntent.Categories)
                    {
                        intent.AddCategory(category);
                    }
                }

                PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent);

                DownloadServiceRequirement startResult = DownloaderService.StartDownloadServiceIfRequired(this, pendingIntent, typeof(LibraryDownloaderService));

                if (startResult != DownloadServiceRequirement.NoDownloadRequired)
                {
                    InitializeDownloadUI();
                    result = true;
                }
            }
            catch (PackageManager.NameNotFoundException e)
            {
                Console.WriteLine("Cannot find own package! MAYDAY!");
                e.PrintStackTrace();
            }

            return(result);
        }
Example #18
0
 public DownloadController(DownloaderService downloaderService, MetaDataService metaDataService)
 {
     _downloaderService = downloaderService;
     _metaDataService   = metaDataService;
 }
Example #19
0
 public override void OnReceive(Context context, Intent intent)
 {
     DownloaderService.StartDownloadServiceIfRequired(context, intent, typeof(MyDownloaderService));
 }
Example #20
0
 public override void OnReceive(Android.Content.Context context, Intent intent)
 {
     DownloaderService.StartDownloadServiceIfRequired(context, intent, typeof(ExpansionDownloaderService));
 }
 public PokemonController(PokemonService pokemonService, DownloaderService downloaderService)
 {
     PokemonService    = pokemonService;
     DownloaderService = downloaderService;
 }
 public static bool IsSuccess(this DownloaderServiceStatus status)
 => DownloaderService.IsStatusSuccess((int)status);
Example #23
0
 public DownloadController(ILogger <DownloadController> logger, DownloaderService downloaderService, FileDonwladStatus status)
 {
     _logger              = logger;
     _downloaderService   = downloaderService;
     _downloadDefinitions = status.Definitions;
 }
 public static bool IsClientError(this DownloaderServiceStatus status)
 => DownloaderService.IsStatusClientError((int)status);
 private void OpenDownloadsFolder(object sender, RoutedEventArgs e)
 {
     Process.Start("explorer.exe", DownloaderService.GetUserDownloadsFolder());
 }
Example #26
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     Settings.Default.Save();
     DownloaderService.StopService();
 }
 public static bool IsInformational(this DownloaderServiceStatus status)
 => DownloaderService.IsStatusInformational((int)status);
 public static bool IsCompleted(this DownloaderServiceStatus status)
 => DownloaderService.IsStatusCompleted((int)status);