Esempio n. 1
0
        private static void Main(string[] args)
        {
            var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());

            XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));

            var scheduler       = new TelegramScheduler(File.ReadAllText("telegram.token"));
            var pipelineBuilder = new DataPipelineBuilder();

            var fetcher   = new GeniusSongInfoFetcher(File.ReadAllText("genius.token"));
            var extractor = new SongInfoExtractor();

            pipelineBuilder.Append(new LambdaProcessor(source =>
            {
                var info = extractor.ExtractFromString(source.FileName);

                info.WriteToFile(source.FileInfo.FullName);
                info = fetcher.ExtractAsyncTask(info).GetAwaiter().GetResult();
                info.WriteToFile(source.FileInfo.FullName);

                return(source);
            }));
            scheduler.Add(pipelineBuilder);

            scheduler.Start();

            scheduler.Join();
        }
Esempio n. 2
0
        private static void CreatePipelineWithException(IExecutor executor)
        {
            var pipelineA = new DataPipelineBuilder();
            var pipelineB = new DataPipelineBuilder();

            pipelineA.Append(new LambdaProcessor(s => throw new Exception("This exception is expected.")));
            pipelineA.Append(new LambdaProcessor(s => { }));

            pipelineB.Append(new LambdaProcessor(s => throw new Exception("This exception is expected.")));

            executor.Initialize(new[] { pipelineA, pipelineB });
        }
Esempio n. 3
0
        public void TestBasicExecution()
        {
            var executor = new Executor(1);
            var pipeline = new DataPipelineBuilder();

            pipeline.Append(new LambdaProcessor(s => { }));

            executor.Initialize(new[] { pipeline });

            executor.ExecuteBlocking(new MockFileSource(), true);
            executor.ExecuteBlocking(new MockFileSource(), true);

            executor.Stop();
        }
Esempio n. 4
0
        private static void CreateAndExecuteSimplePipeline(IExecutor executor,
                                                           EventCollector <ExecutorLifeCycleEventArgs> collector, int count, int sleep = 125)
        {
            var pipeline = new DataPipelineBuilder();

            pipeline.Append(new LambdaProcessor(s => Thread.Sleep(sleep)));

            executor.Initialize(new[] { pipeline });

            executor.LifeCycleEvent += collector.Collect;

            for (int i = 0; i < count; i++)
            {
                executor.Execute(new MockFileSource());
            }

            executor.Stop();

            executor.LifeCycleEvent -= collector.Collect;
        }
Esempio n. 5
0
        private static void Main(string[] args)
        {
            var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());

            XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));

            var scheduler = new TelegramScheduler(new Executor(8, new ExternalSourceComparer()),
                                                  File.ReadAllText("telegram.token"));
            var pipelineBuilder = new DataPipelineBuilder();

            var extractor = new SongInfoExtractor(false);

            GeniusSongInfoFetcher genius = null;

            try {
                string apiKey = null;
                if (File.Exists("genius.token"))
                {
                    apiKey = File.ReadAllText("genius.token");
                }

                genius = new GeniusSongInfoFetcher(apiKey);
            }
            catch (ArgumentException) {}             // will be thrown if no token could be found

            if (genius == null)
            {
                Log.Warn("Neither a genius.token file nor the corresponding environmental variable has been set. -Skipping genius");
            }

            var merger = new SongInfoMerger();             // a class that can merge multiple SongInfo instances

            pipelineBuilder.Append(new LambdaProcessor(source =>
            {
                // load already stored ID3-tags (if any) from the specified file
                var originalInfo = SongInfo.ReadFromFile(source.FileInfo.FullName);

                // try to parse the filename and extract the title, and artist(s)
                var parsedInfo = extractor.ExtractFromString(source.FileName);
                // merge the metadata but ensure that they are (probably) identical
                // greedy ensures that null values are overridden
                originalInfo = merger.Merge(originalInfo, parsedInfo, greedy: true);

                if (genius != null)                   // if a genius client is available
                // search for the info on genius
                {
                    parsedInfo = genius.ExtractAsyncTask(originalInfo).GetAwaiter().GetResult();
                    // since the fetched result could be completely different, non-greedy merging is important
                    originalInfo = merger.Merge(originalInfo, parsedInfo, greedy: false);
                }

                originalInfo.WriteToFile(source.FileInfo.FullName);                 // write new metadata back
                return(source);
            }));

            // Move the finished files into the downloads folder
            pipelineBuilder.Append(new SourceMover("/downloads", keepName: true));

            scheduler.Add(pipelineBuilder);

            scheduler.Start();

            scheduler.Join();
        }