Exemplo n.º 1
0
 /// <summary> Владелец ларька с шаурмой </summary>
 public ShaurmaTruckOwner(ICleaner cleaner, ICooker cooker, IDriver driver, ICashier cashier)
 {
     _cleaner = cleaner;
     _cooker  = cooker;
     _driver  = driver;
     _cashier = cashier;
 }
Exemplo n.º 2
0
        public void ShouldCallParsingForEachPageFromPreviousIteration()
        {
            // Arrange
            string              baseUrl           = "https://en.wikipedia.org";
            string              path1             = "Resources/test.html";
            string              path2             = "Resources/Red_fox.html";
            string              initialUrl        = "https://en.wikipedia.org/test.html";
            string              innerUrl          = "https://en.wikipedia.org/wiki/Red_fox";
            string              expectedString    = "IterationCall() done!";
            string              notExpectedString = "Something went wrong in IterationCall().";
            ISaver              saver             = Substitute.For <ISaver>();
            IDownloader         downloader        = Substitute.For <IDownloader>();
            ICleaner            cleaner           = Substitute.For <ICleaner>();
            UrlCollectorService iterationService  = new UrlCollectorService(saver, downloader, cleaner);

            downloader.Download(Arg.Is <string>(innerUrl))
            .Returns("someDownloadedHtmlText");
            downloader.Download(Arg.Is <string>(initialUrl))
            .Returns("initialtext");
            downloader.SaveIntoFile(Arg.Is <string>("initialtext"))
            .Returns(path1);
            downloader.SaveIntoFile(Arg.Is <string>("someDownloadedHtmlText"))
            .Returns(path2);

            // Act
            var result = iterationService.Solothread(initialUrl, baseUrl);

            // Assert
            Assert.IsTrue(result.Result.Contains(expectedString), "IterationCall works wrong!");
            Assert.IsFalse(result.Result.Contains(notExpectedString), "IterationCall works wrong!");
        }
Exemplo n.º 3
0
 public Column(String name, String property, String prefix, ICleaner cleaner)
 {
     _name     = name;
     _property = property;
     _prefix   = prefix;
     _cleaner  = cleaner;
 }
Exemplo n.º 4
0
        public void SetUp()
        {
            target             = new TestRunnerImpl();
            args               = Stub <ITestRunnerArgs>();
            parser             = Stub <IParser>();
            cleaner            = Stub <ICleaner>();
            runDataBuilder     = Stub <IRunDataBuilder>();
            runDataListBuilder = Stub <IRunDataListBuilder>();
            executorLauncher   = Stub <IExecutorLauncher>();
            trxWriter          = Stub <ITrxWriter>();
            breaker            = Stub <IBreaker>();
            enumerator         = Stub <IRunDataEnumerator>();
            windowsFileHelper  = Stub <IWindowsFileHelper>();
            collector          = Stub <ICollector>();

            target.Args               = args;
            target.Parser             = parser;
            target.Cleaner            = cleaner;
            target.RunDataBuilder     = runDataBuilder;
            target.RunDataListBuilder = runDataListBuilder;
            target.ExecutorLauncher   = executorLauncher;
            target.TrxWriter          = trxWriter;
            target.Breaker            = breaker;
            target.Collector          = collector;
            target.WindowsFileHelper  = windowsFileHelper;
        }
Exemplo n.º 5
0
 public Column(String name, String property, String prefix, ICleaner cleaner)
 {
     _name = name;
     _property = property;
     _prefix = prefix;
     _cleaner = cleaner;
 }
Exemplo n.º 6
0
        private static void ExtractTracks(ICleaner clean, HtmlNodeCollection songNodes, List <Track> tracklist)
        {
            for (int i = 0; i < songNodes.Count; i++)
            {
                HtmlNode artistNode = songNodes[i].SelectSingleNode(".//div[@class='artist']");
                HtmlNode titleNode  = songNodes[i].SelectSingleNode(".//div[@class='song']");

                if (artistNode == null)
                {
                    throw new NodeNotFoundException($"Couldn't find song's author node with the given XPath at index: {i}!");
                }

                if (titleNode == null)
                {
                    throw new NodeNotFoundException($"Couldn't find song's title node with the given XPath at index: {i}!");
                }

                if (clean.IsNotArtist(artistNode.InnerText))
                {
                    continue;
                }

                string artistName = clean.ArtistName(artistNode.InnerText);

                tracklist.Add(new Track(artistName, titleNode.InnerText));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Extract <see cref="Track"/>s from the JSON.
        /// </summary>
        /// <param name="json">Non null string.</param>
        /// <param name="clean"></param>
        /// <returns>Non null <see cref="Track"/> collection.</returns>
        /// <exception cref="NodeNotFoundException"></exception>
        internal static List <Track> Process(string json, ICleaner clean)
        {
            if (json.StartsWith("{\"count\":0,"))
            {
                return(new List <Track>());
            }

            // If this not here, HtmlAgilityPack can't work
            json = UnicodeCharactersToASCII(json).Replace(@"\/", "/");

            HtmlDocument htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(json);

            var songNodes = htmlDoc.DocumentNode.SelectNodes("//div[@class='now-playing-small clearfix' or @class='now-playing-big clearfix']");

            if (songNodes == null)
            {
                throw new NodeNotFoundException("Couldn't find songs with the given XPath!");
            }

            List <Track> tracklist = new List <Track>();

            ExtractTracks(clean, songNodes, tracklist);

            return(tracklist);
        }
 public StreamWordListGenerator(
     Stream stream,
     ICleaner cleaner)
 {
     _stream  = stream;
     _cleaner = cleaner;
 }
Exemplo n.º 9
0
        private static IStorage CreateStorage()
        {
            ICleaner   cleaner   = Substitute.For <ICleaner>();
            IScheduler scheduler = Substitute.For <IScheduler>();
            IStorage   storage   = new InMemoryStorage(cleaner, scheduler);

            return(storage);
        }
Exemplo n.º 10
0
        public Transformer(IFileCompression compression, ICleaner cleaner, IBinner binner, IEtlForexConfig config)
            : this()
        {
            TempLocation = new DirectoryInfo(Path.Combine(config.RootTempFolder, "Transformer"));

            Compression = compression;
            Cleaner     = cleaner;
            Binner      = binner;
        }
Exemplo n.º 11
0
 public UrlCollectorService(ISaver saver, IDownloader downloader, ICleaner cleaner)
 {
     this.saveIntoDatabaseService = new SaveIntoDatabaseService(saver);
     this.deleteFileService       = new DeleteFileService(cleaner);
     this.parsePageService        = new ParsePageService(this.saveIntoDatabaseService, this.deleteFileService);
     this.downloadPageService     = new DownloadPageService(downloader);
     this.multyIterationID        = 0;
     this.iterationID             = 0;
 }
Exemplo n.º 12
0
        public Transformer(ISourceSpecification source, IFileCompression compression, ICleaner cleaner, IBinner binner, IEtlForexConfig config)
        {
            TempLocation = new DirectoryInfo(Path.Combine(config.RootTempFolder, "Transformer"));

            Source      = source;
            Compression = compression;
            Cleaner     = cleaner;
            Binner      = binner;
        }
Exemplo n.º 13
0
 protected UiMarshalingViewModel(
     IRegionManager regionManager,
     IModuleManager moduleManager,
     IDialogService dialogService,
     ICleaner cleaner,
     IViewProvider viewProvider
     ) : base(regionManager, moduleManager, dialogService, cleaner, viewProvider)
 {
     _application = Application.Current;
 }
 public Scheduler(ICleaner cleaner, SearchEngineSettings settings)
 {
     _cleaner = cleaner;
     _timer   = new Timer
     {
         Enabled  = false,
         Interval = settings.CleaUpIntervalMs
     };
     _timer.Elapsed += OnElapsed;
 }
Exemplo n.º 15
0
 public UnitExample(IAdmin adminContext, ICleaner cleanerContext, IDriver driverContext, IEngineer engineerContext, IFleetManager fleetManagerContext, ITram tramContext, IUser userContext)
 {
     this.adminContext        = adminContext;
     this.cleanerContext      = cleanerContext;
     this.driverContext       = driverContext;
     this.engineerContext     = engineerContext;
     this.fleetManagerContext = fleetManagerContext;
     this.tramContext         = tramContext;
     this.userContext         = userContext;
 }
Exemplo n.º 16
0
        public ShellViewModel(ICleaner cleaner, IReporter reporter)
        {
            _cleaner  = cleaner;
            _reporter = reporter;

            Title          = $"Solution Cleaner {Assembly.GetExecutingAssembly().GetName().Version.ToString(3)}";
            Directory      = AppDomain.CurrentDomain.BaseDirectory;
            FileExtensions = ".csproj.user; ";
            DirectoryNames = "bin; obj; ";
            CleanCommand   = new DelegateCommand <object>(CleanFiles);
        }
Exemplo n.º 17
0
        public MainForm(ICalculator calculator, IInputsValidator validator, ICleaner cleaner, IMemoryMeasurer measurer, BackgroundWorker worker)
        {
            _calculator       = calculator;
            _validator        = validator;
            _cleaner          = cleaner;
            _measurer         = measurer;
            _worker           = worker;
            _bgWorkersThreads = new List <Thread>();

            InitializeComponent();
            PrepareWorker();
        }
Exemplo n.º 18
0
        public async Task Contains_CallsCleaner()
        {
            // Arrange
            ICleaner cleaner = Substitute.For <ICleaner>();
            IStorage storage = await CreateStorageWithSchedulerAndWait(cleaner);

            // Act
            storage.Contains("");

            // Assert
            cleaner.Received(1).Clear(Arg.Any <PriorityQueue <ExpiringKey> >(), Arg.Any <Dictionary <Key, Element> >());
        }
        public MainWindowViewModel(
            IRegionManager regionManager,
            IModuleManager moduleManager,
            IDialogService dialogService,
            ICleaner cleaner,
            IViewProvider viewProvider
            ) : base(regionManager, moduleManager, dialogService, cleaner, viewProvider)
        {
            _fileBrowserPresenter = new FileBrowserPresenter(_moduleManager, _regionManager);

            SwitchFileBrowserCommand = new DelegateCommand(this.SwitchFileBrowserCommandExecute);
        }
Exemplo n.º 20
0
        private static async Task <IStorage> CreateStorageWithSchedulerAndWait(ICleaner cleaner)
        {
            const int       timePeriod = 10;
            IScheduler      scheduler  = new Scheduler();
            InMemoryStorage storage    = new InMemoryStorage(cleaner, scheduler);

            do
            {
                await Task.Delay(timePeriod);
            } while (!storage.CleanupRequested);

            return(storage);
        }
Exemplo n.º 21
0
 public Renamer()
 {
     this.logger = new Logger();
     this.settings = new Settings(logger);
     this.fileSearcher = new FileSearcher(settings, logger);
     this.movieFileBot = new FileBot(settings, logger, true);
     this.seriesFileBot = new FileBot(settings, logger, false);
     this.cleaner = new Cleaner(settings, fileSearcher, logger);
     this.pathGenerator = new PathGenerator();
     this.fileMover = new FileMover(logger);
     this.cleaner = new Cleaner(settings, fileSearcher, logger);
     this.archiver = new Archiver(settings, fileMover);
 }
 public ServiceProviderViewModel(
     IRegionManager regionManager,
     IModuleManager moduleManager,
     IDialogService dialogService,
     ICleaner cleaner,
     IViewProvider viewProvider)
 {
     _regionManager = regionManager;
     _moduleManager = moduleManager;
     _dialogService = dialogService;
     _cleaner       = cleaner;
     _viewProvider  = viewProvider;
 }
Exemplo n.º 23
0
        /// <summary>
        /// Extract the <see cref="Track"/>s from the HTML.
        /// </summary>
        /// <param name="sourceCode">Non null string.</param>
        /// <param name="clean">Non null custom cleaning object.</param>
        /// <returns>Non null <see cref="Track"/> collection.</returns>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        internal static List <Music> Process(string sourceCode, ICleaner clean)
        {
            // TODO: HtmlAgilityPack
            string substrint_string = "TRACKLISTA";

            sourceCode = sourceCode.Substring(sourceCode.IndexOf(substrint_string));
            sourceCode = sourceCode.Substring(0, sourceCode.IndexOf("</div></div></div>  </div>"));

            // [FIX] <a href="google.hu">Click here</a> to Click here
            sourceCode = Regex.Replace(sourceCode, @"<a\s*[^>]*><u>(.*)</u><\/a>", "$1");
            sourceCode = Regex.Replace(sourceCode, @"<a\s*[^>]*>(.*)<\/a>", "$1");
            sourceCode = Regex.Replace(sourceCode, @"<[^>]*>", "\n");
            sourceCode = Regex.Replace(sourceCode, @"[\r\n]+", "\n");

            string[] lines = sourceCode.Split(new string[] { "\n" }, StringSplitOptions.None);

            List <Music> tracklist = new List <Music>();

            for (int i = 0; i < lines.Length; i++)
            {
                string musicName = lines[i];

                if (musicName.Length < 3 ||
                    clean.IsNotArtist(musicName))
                {
                    continue;
                }

                // [FIX] Multiple spaces replace single space
                musicName = Regex.Replace(musicName, @"\s+", " ").Trim();

                musicName = musicName.Replace("MK DJ", "")
                            .Replace("() ", "")
                            .Replace("( ", "(")
                            .Replace(" )", ")");

                musicName = clean.MusicPrefixes(musicName);
                musicName = clean.MusicPostfixes(musicName);

                musicName = HtmlEntity.DeEntitize(musicName);

                if (musicName.Length < 3)
                {
                    continue;
                }

                tracklist.Add(new Music(musicName));
            }

            return(tracklist);
        }
Exemplo n.º 24
0
        public void Manage(Backup backup, ICleaner cleaner,
                           IStorage storage, ICreationPoint pointCreation)
        {
            var filesCopyInfo = storage.Save(backup.FilesPath);

            if (pointCreation is IncRestoreCreationPoint && backup.RestorePoints.Count == 0)
            {
                throw new UnavaliableIncPointCreation("No parent point");
            }
            var restorePoint = pointCreation.Create(filesCopyInfo);

            backup.AddRestorePoint(restorePoint);
            cleaner.Clear(backup);
        }
Exemplo n.º 25
0
        public Backup(ICleaner cleaner, params string[] files)
        {
            if (_files.Count == 0)
            {
                throw new Exception("The files count mustn't be 0");
            }

            foreach (var file in files)
            {
                _files.Add(file);
            }

            _cleaner = cleaner;
        }
Exemplo n.º 26
0
 public Main(string initialDirectory)
 {
     InitializeComponent();
     pathValidator = new PathValidator();
     cleaner       = new Cleaner
     {
         Context = SynchronizationContext.Current
     };
     cleaner.CleaningDone += CleaningDone;
     path.Text             = (initialDirectory ?? "");
     path.SelectionStart   = 0;
     base.ActiveControl    = ((path.Text == "") ? ((Control)path) : ((Control)start));
     Running = false;
 }
Exemplo n.º 27
0
 public Application(
     ILogger <Application> logger,
     ICleaner cleaner,
     IDetectPackage detectPackage,
     ITriggerRestart triggerRestart,
     ZipDeployOptions options,
     IUnzipper unzipper)
 {
     _logger         = logger;
     _cleaner        = cleaner;
     _detectPackage  = detectPackage;
     _triggerRestart = triggerRestart;
     _options        = options;
     _unzipper       = unzipper;
 }
Exemplo n.º 28
0
        public Engine(IMenu menu, IReader reader, IWriter writer, ICleaner cleaner)
        {
            this.menu    = menu;
            this.reader  = reader;
            this.writer  = writer;
            this.cleaner = cleaner;

            assembly = Assembly.GetExecutingAssembly();
            types    = assembly.GetExportedTypes()
                       .Where(x => x.Name.EndsWith(CommandSuffix) &&
                              typeof(ICommand).IsAssignableFrom(x) &&
                              !x.IsInterface &&
                              !x.IsAbstract)
                       .ToArray();
        }
Exemplo n.º 29
0
        /// <summary>
        /// Creates a new <see cref="MainForm"/>.
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            pathValidator = new PathValidator();

            cleaner = new Cleaner
            {
                Context = SynchronizationContext.Current,
            };
            cleaner.CleaningDone += CleaningDone;

            ActiveControl = path;

            Running = false;
        }
Exemplo n.º 30
0
        public EmptyResult Clean()
        {
            long languageId = WebSettingsConfig.Instance.GetLanguageFromId();
            var  cleaners   = new ICleaner[] {
                new LoggerQuery(),
                new RatingByIpsQuery(languageId),
                new UsersQuery(),
                new SentencesQuery(),
                new ShuffleWordsQuery(WordType.Default, ShuffleType.Usual),
            };
            var maxDateToRemove = DateTime.Today.AddMonths(-2);

            foreach (var cleaner in cleaners)
            {
                cleaner.Clean(maxDateToRemove);
            }
            return(new EmptyResult());
        }
Exemplo n.º 31
0
        public void ShouldExtractHtmlTags()
        {
            // Arrange
            string   baseUrl                         = "https://en.wikipedia.org";
            string   path                            = "Resources/test.html";
            string   expectedString                  = "https://en.wikipedia.org/wiki/Red_fox";
            string   notExpectedString               = "https://vk.com/gingerfoxday";
            int      iterationId                     = 5;
            ISaver   saver                           = Substitute.For <ISaver>();
            ICleaner cleaner                         = Substitute.For <ICleaner>();
            SaveIntoDatabaseService saveService      = new SaveIntoDatabaseService(saver);
            DeleteFileService       deleteService    = new DeleteFileService(cleaner);
            ParsePageService        parsePageService = new ParsePageService(saveService, deleteService);

            // Act
            var result = parsePageService.Parse(path, baseUrl, iterationId);

            // Assert
            Assert.IsTrue(result.Contains(expectedString), "File has been parsed wrong!");
            Assert.IsFalse(result.Contains(notExpectedString), "File has been parsed wrong!");
        }
Exemplo n.º 32
0
        /// <summary>
        /// Extract the <see cref="Track"/>s from the HTML.
        /// </summary>
        /// <param name="sourceCode">Non null string.</param>
        /// <param name="clean">Non null custom cleaning object.</param>
        /// <returns>Non null <see cref="Track"/> collection.</returns>
        /// <exception cref="NodeNotFoundException"></exception>
        public static List <Track> Process(string sourceCode, ICleaner clean)
        {
            HtmlDocument htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(sourceCode);

            var songNodes = htmlDoc.DocumentNode.SelectNodes("//div[@class='content']/div[@class='chart-wrapper']/div[@class='chart-content-wrapper']/div[@class='chart-content-block-sub']");

            if (songNodes == null)
            {
                throw new NodeNotFoundException("Couldn't find songs with the given XPath!");
            }

            var tracks = new List <Track>();

            for (int i = 0; i < songNodes.Count; i++)
            {
                HtmlNode artistNode = songNodes[i].SelectSingleNode("./div[@class='chart-content-metadata-sub']/div[@class='chart-content-author-sub']/a"),
                         titleNode  = songNodes[i].SelectSingleNode("./div[@class='chart-content-metadata-sub']/div[@class='chart-content-title-sub']/a");

                if (artistNode == null)
                {
                    throw new NodeNotFoundException($"Couldn't find song's author node with the given XPath at index: {i}!");
                }

                if (titleNode == null)
                {
                    throw new NodeNotFoundException($"Couldn't find song's title node with the given XPath at index: {i}!");
                }

                string artistName = clean.ArtistName(artistNode.InnerText);

                tracks.Add(new Track(artistName, titleNode.InnerText));
            }

            return(tracks);
        }
Exemplo n.º 33
0
        public void SetUp()
        {
            target = new TestRunnerImpl();
            args = Stub<ITestRunnerArgs>();
            parser = Stub<IParser>();
            cleaner = Stub<ICleaner>();
            runDataBuilder = Stub<IRunDataBuilder>();
            runDataListBuilder = Stub<IRunDataListBuilder>();
            executorLauncher = Stub<IExecutorLauncher>();
            trxWriter = Stub<ITrxWriter>();
            breaker = Stub<IBreaker>();
            enumerator = Stub<IRunDataEnumerator>();
            windowsFileHelper = Stub<IWindowsFileHelper>();
            collector = Stub<ICollector>();

            target.Args = args;
            target.Parser = parser;
            target.Cleaner = cleaner;
            target.RunDataBuilder = runDataBuilder;
            target.RunDataListBuilder = runDataListBuilder;
            target.ExecutorLauncher = executorLauncher;
            target.TrxWriter = trxWriter;
            target.Breaker = breaker;
            target.Collector = collector;
            target.WindowsFileHelper = windowsFileHelper;
        }
Exemplo n.º 34
0
 public void SetSubCleaner(ICleaner sub)
 {
     _sub = sub;
 }