Beispiel #1
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hayden v0.7.0");
            Console.WriteLine("By Bepis");

            if (args.Length != 1)
            {
                Console.WriteLine("Usage: hayden <config file location>");
                return;
            }

            var rawConfigFile = JObject.Parse(File.ReadAllText(args[0]));

            IThreadConsumer consumer;

            string backendType = rawConfigFile["backend"]["type"].Value <string>();

            var    yotsubaConfig    = rawConfigFile["source"].ToObject <YotsubaConfig>();
            string downloadLocation = null;

            switch (backendType)
            {
            case "Asagi":
                var asagiConfig = rawConfigFile["backend"].ToObject <AsagiConfig>();

                downloadLocation = asagiConfig.DownloadLocation;
                consumer         = new AsagiThreadConsumer(asagiConfig, yotsubaConfig.Boards);
                break;

            default:
                throw new ArgumentException($"Unknown backend type {backendType}");
            }

            ProxyProvider proxyProvider = null;

            if (rawConfigFile["proxies"] != null)
            {
                proxyProvider = new ConfigProxyProvider((JArray)rawConfigFile["proxies"]);
            }

            Log("Initialized.");
            Log("Press Q to stop archival.");

            var haydenDirectory = Path.Combine(downloadLocation, "hayden");

            Directory.CreateDirectory(haydenDirectory);

            var stateStore = new LiteDbStateStore(Path.Combine(haydenDirectory, "imagequeue.db"));

            var boardArchiver = new BoardArchiver(yotsubaConfig, consumer, stateStore, proxyProvider);

            var tokenSource = new CancellationTokenSource();

            var archivalTask = boardArchiver.Execute(tokenSource.Token)
                               .ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Log("!! FATAL EXCEPTION !!");
                    Log(task.Exception.ToString());
                }
            });

            var terminateTask = WaitForTerminateAsync();
            await Task.WhenAny(archivalTask, terminateTask);

            Log("Shutting down...");

            if (!tokenSource.IsCancellationRequested)
            {
                tokenSource.Cancel();
            }

            await archivalTask;
        }
Beispiel #2
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hayden v0.3.0");
            Console.WriteLine("By Bepis");

            if (args.Length != 1)
            {
                Console.WriteLine("Usage: hayden <config file location>");
                return;
            }

            var rawConfigFile = JObject.Parse(File.ReadAllText(args[0]));

            IThreadConsumer consumer;

            string backendType = rawConfigFile["backend"]["type"].Value <string>();

            var yotsubaConfig = rawConfigFile["source"].ToObject <YotsubaConfig>();

            switch (backendType)
            {
            case "Asagi":
                var asagiConfig = rawConfigFile["backend"].ToObject <AsagiConfig>();

                consumer = new AsagiThreadConsumer(asagiConfig, yotsubaConfig.Boards);
                break;

            default:
                throw new ArgumentException($"Unknown backend type {backendType}");
            }

            Log("Initialized.");

            //Log($"Downloading from board /{board}/ to directory {downloadDir}");
            Log("Press Q to stop archival.");

            var boardArchiver = new BoardArchiver(yotsubaConfig, consumer);

            var tokenSource = new CancellationTokenSource();

            var archivalTask = boardArchiver.Execute(tokenSource.Token);

            while (true)
            {
                try
                {
                    var readKey = await Utility.ReadKeyAsync(CancellationToken.None, true);

                    if (readKey.Key == ConsoleKey.Q)
                    {
                        break;
                    }
                }
                catch (TaskCanceledException)
                {
                    break;
                }
            }

            Log("Shutting down...");

            tokenSource.Cancel();

            await archivalTask;
        }