コード例 #1
0
        public override async Task Execute(string[] args)
        {
            if (args.Length < 2)
            {
                Controlo.ReportError("Usage: {0}", ShortHelp);
                return;
            }

            string settingName  = args[0];
            string settingValue = new ArraySegment <string>(args, 1, args.Length - 1).Aggregate((a, b) => a + " " + b);

            var p = typeof(FetchoConfiguration).GetProperty(settingName);

            if (p == null)
            {
                Controlo.ReportError("Setting doesn't exist {0}", settingName);
            }
            else
            {
                var converter = TypeDescriptor.GetConverter(p.PropertyType);
                try
                {
                    var obj = converter.ConvertFromString(null, CultureInfo.InvariantCulture, settingValue);
                    FetchoConfiguration.Current.SetConfigurationSetting(p.Name, obj);
                }
                catch (NotSupportedException)
                {
                    Controlo.ReportError("Not a valid {0}", p.PropertyType);
                }
            }
        }
コード例 #2
0
 public override async Task Execute(string[] args)
 {
     foreach (var command in Controlo.Commands.Values)
     {
         Controlo.ReportInfo("{0,10}\t{1}", command.CommandName, command.ShortHelp);
     }
 }
コード例 #3
0
        public override async Task Execute(string[] args)
        {
            var t = typeof(FetchoConfiguration);

            foreach (var p in t.GetProperties())
            {
                if (p.GetCustomAttributes(typeof(ConfigurationSettingAttribute), false).Any())
                {
                    Controlo.ReportInfo("\t{0,-50} {1,-16} = {2}", p.Name, p.PropertyType, FormatValue(p.GetValue(FetchoConfiguration.Current)));
                }
            }
        }
コード例 #4
0
 public override async Task Execute(string[] args)
 {
     Controlo.ReportInfo("Quitting");
     Controlo.Shutdown();
     //Environment.Exit(1);
 }
コード例 #5
0
        public override async Task Execute(string[] args)
        {
            if (args.Length < 1)
            {
                Controlo.ReportError("Usage: {0}", ShortHelp);
                return;
            }

            string subcommand = args[0];

            if (subcommand == "status")
            {
                if (Current == null)
                {
                    Controlo.ReportError("Fetching not in progress");
                    return;
                }

                Controlo.ReportInfo("Total: {0}, Complete: {1}", Current.Items.Count, Current.Complete);
            }
            else if (subcommand == "reddit")
            {
                if (Current != null)
                {
                    Controlo.ReportError("Fetching in progress");
                    return;
                }

                if (args.Length < 3)
                {
                    Controlo.ReportError("Usage: {0}", ShortHelp);
                    return;
                }

                if (!Guid.TryParse(args[2], out Guid destinationWorkspaceId))
                {
                    Controlo.ReportError("No destination workspace id specified or invalid GUID: {0}", args[2]);
                    return;
                }

                string subreddit = args[1];

                Controlo.ReportInfo("Getting the URLs from r/{0}", subreddit);
                var submissions = await RedditSubmissionFetcher.GetSubmissions(subreddit);

                Controlo.ReportInfo("{0} submissions extracted from r/{1}", submissions.Count(), subreddit);
                Current = new FetchingTask();
                await SetupWorkspaceDataWriter();
                await SendItemsForQueuing(submissions.Select(x => MakeQueueItem(x, destinationWorkspaceId)));

                Controlo.ReportInfo("Task created");
            }
            else if (subcommand == "hackernews")
            {
                if (Current != null)
                {
                    Controlo.ReportError("Fetching in progress");
                    return;
                }

                if (args.Length < 2)
                {
                    Controlo.ReportError("Usage: {0}", ShortHelp);
                    return;
                }

                if (!Guid.TryParse(args[1], out Guid destinationWorkspaceId))
                {
                    Controlo.ReportError("No destination workspace id specified or invalid GUID: {0}", args[2]);
                    return;
                }

                Controlo.ReportInfo("Getting the URLs from hackernews");
                Current = new FetchingTask();
                await SetupWorkspaceDataWriter();

                int      numberOfDaysToFetch = 100;
                DateTime start = DateTime.Now.AddDays(-numberOfDaysToFetch - 1);
                for (int i = 0; i < numberOfDaysToFetch; i++)
                {
                    var hnis = await HackerNewsFrontPageFetcher.GetLinks(start);

                    start = start.AddDays(1);
                    Controlo.ReportInfo("{0} submissions extracted from hackernews", hnis.Count());
                    await SendItemsForQueuing(hnis.Select(x => MakeQueueItem(x, destinationWorkspaceId)));
                }

                Controlo.ReportInfo("Task created");
            }
            else
            {
                Controlo.ReportError("Usage: {0}", ShortHelp);
            }
        }