示例#1
0
        public void Run()
        {
            var collector = new ConsoleInputCollector(string.Format(
                                                          "Select an option:{0}" +
                                                          "0: Exit                      4: Load data from xml files{0}" +
                                                          "1: View and edit settings    5: Generate .arff file{0}" +
                                                          "2: Download data .zip files  6: RUN 2 THROUGH 5{0}" +
                                                          "3: Extract zip files{0}"
                                                          , Environment.NewLine), new LongRangeValidator(0, 6));

            var          input = -1;
            IList <Bill> bills = null;

            while (input.Equals(0) == false)
            {
                input = int.Parse(collector.GetInput());

                switch (input)
                {
                case 1:
                    _settings.ManageSettings();
                    break;

                case 2:
                    RunDownload();
                    break;

                case 3:
                    RunExtract();
                    break;

                case 4:
                    bills = LoadBillData();
                    break;

                case 5:
                    WriteArffFile(bills);
                    break;

                case 6:
                    RunDownload();
                    RunExtract();
                    bills = LoadBillData();
                    WriteArffFile(bills);
                    break;

                default:
                    break;
                }
            }
        }
示例#2
0
        public void ManageSettings()
        {
            var menuInput = new ConsoleInputCollector(string.Format(
                                                          "Select an option:{0}"
                                                          + "0: Back to main menu         3: Output file location{0}"
                                                          + "1: Download directory        4: Overwrite downloaded files{0}"
                                                          + "2: Data extract directory    5: Overwrite extracted files{0}"
                                                          , Environment.NewLine), new LongRangeValidator(0, 5));

            var input = -1;

            while (input.Equals(0) == false)
            {
                var newSetting = string.Empty;
                ConsoleInputCollector settingCollector = null;

                input = int.Parse(menuInput.GetInput());

                switch (input)
                {
                case 1:
                    settingCollector = new ConsoleInputCollector(
                        string.Format(
                            "Where would you like to store downloaded data? (Leave blank to cancel){0}" +
                            "Current: {1}",
                            Environment.NewLine, this.DownloadDirectoryPath),
                        new DirectoryValidator()
                        );
                    settingCollector.CancelCommands = new[] { string.Empty };
                    newSetting = settingCollector.GetInput();
                    if (newSetting != null)
                    {
                        this.DownloadDirectoryPath = newSetting;
                    }
                    break;


                case 2:
                    settingCollector = new ConsoleInputCollector(
                        string.Format(
                            "Where would you like to store extracted data? (Leave blank to cancel){0}" +
                            "Current: {1}",
                            Environment.NewLine, this.ExtractDirectoryPath),
                        new DirectoryValidator()
                        );
                    settingCollector.CancelCommands = new[] { string.Empty };
                    newSetting = settingCollector.GetInput();
                    if (newSetting != null)
                    {
                        this.ExtractDirectoryPath = newSetting;
                    }
                    break;


                case 3:
                    settingCollector = new ConsoleInputCollector(
                        string.Format(
                            "Where would you like to save the output.arff file? (Leave blank to cancel){0}" +
                            "Current: {1}",
                            Environment.NewLine, this.OutputArffFilePath),
                        new FileValidator()
                        );
                    settingCollector.CancelCommands = new[] { string.Empty };
                    newSetting = settingCollector.GetInput();
                    if (newSetting != null)
                    {
                        this.OutputArffFilePath = newSetting;
                    }
                    break;


                case 4:
                    settingCollector = new ConsoleInputCollector(
                        string.Format(
                            "Overwrite pre-existing zip files? (Leave blank to cancel){0}" +
                            "Current: {1}",
                            Environment.NewLine, this.OverwriteDownloadedZipFiles),
                        new BoolValidator()
                        );
                    settingCollector.CancelCommands = new[] { string.Empty };
                    newSetting = settingCollector.GetInput();
                    if (newSetting != null)
                    {
                        this.OverwriteDownloadedZipFiles = bool.Parse(newSetting);
                    }
                    break;


                case 5:
                    settingCollector = new ConsoleInputCollector(
                        string.Format(
                            "Overwrite pre-existing xml data files? (Leave blank to cancel){0}" +
                            "Current: {1}",
                            Environment.NewLine, this.OverwriteExtractedXmlFiles),
                        new BoolValidator()
                        );
                    settingCollector.CancelCommands = new[] { string.Empty };
                    newSetting = settingCollector.GetInput();
                    if (newSetting != null)
                    {
                        this.OverwriteExtractedXmlFiles = bool.Parse(newSetting);
                    }
                    break;


                default:
                    break;
                }
            }
            _settings.Save();
        }