Пример #1
0
 public InitializeTask(IAppParser appParser, IAppIndexer indexer, 
     RepositoryEmitter repository, ProgramSettings settings)
     : base(settings) {
     this.appParser = appParser;
     this.indexer = indexer;
     this.repository = repository;
 }
        public void AddOption_DuplicateNamesCollection()
        {
            var ps = new ProgramSettings("command");

            Assert.Throws <ArgumentException>(delegate
            {
                ps.AddOption(new string[] { "a", "a" }, false);
            });
        }
        public void AddOption_DuplicateNames()
        {
            var ps = new ProgramSettings("command");

            Assert.Throws <ArgumentException>(delegate
            {
                ps.AddOption('a', "a", false);
            });
        }
        public void AddOption_NoNameCollection()
        {
            var ps = new ProgramSettings("command");

            Assert.Throws <ArgumentException>(delegate
            {
                ps.AddOption(null, false);
            });
        }
        public void PrintHelp_NullWriter()
        {
            var ps = new ProgramSettings("command");

            Assert.Throws <ArgumentException>(delegate
            {
                ps.PrintHelp(null);
            });
        }
        public void AddPlainArgument_EmptyName()
        {
            var ps = new ProgramSettings("command");

            Assert.Throws <ArgumentException>(delegate
            {
                ps.AddPlainArgument(0, "");
            });
        }
Пример #7
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // set theme
            Uri uri = new Uri($"Themes/{ProgramSettings.GetInstance().Theme}.xaml", UriKind.Relative);
            ResourceDictionary resource = (ResourceDictionary)LoadComponent(uri);

            Current.Resources.MergedDictionaries.Clear();
            Current.Resources.MergedDictionaries.Add(resource);
        }
Пример #8
0
        public RescueTask(IAppParser appParser, IAppIndexer indexer,
            RepositoryEmitter repository, ProgramSettings settings)
            : base(settings) {
            this.appParser = appParser;
            this.indexer = indexer;
            this.repository = repository;

            limit = settings.BatchSize / 200 * 200; // 因为Search API是200一批,找个最接近的200的倍数,以免浪费
        }
        public void AddOptionConflict_Synonyms()
        {
            var ps = new ProgramSettings("command");

            ps.AddOption('o', "option", false);
            Assert.Throws <ConstraintException>(delegate
            {
                ps.AddOptionConflict("o", "option");
            });
        }
        public void AddOptionDependency_OptionNotDefined()
        {
            var ps = new ProgramSettings("command");

            ps.AddOption('o', "option", false);
            Assert.Throws <ConstraintException>(delegate
            {
                ps.AddOptionDependency("o", "x");
            });
        }
Пример #11
0
        /// <summary>
        /// Создает новый путь к файлу.
        /// </summary>
        /// <param name="filePath">Путь к файлу.</param>
        /// <returns>Строку с новым путем файла. Имя файла - результат хеш-функции SHA-384.</returns>
        private static string MakeNewFilePath(string filePath)
        {
            string fileExtension = Path.GetExtension(filePath);
            string fileName      = Path.GetFileNameWithoutExtension(filePath);
            string newFilePath   = ProgramSettings.GetInstance().ReplacePath + @"\";
            string newFileName   = StringHash(fileName).Replace('\\', '_');

            newFileName = newFileName.Replace('/', '_');
            return(newFilePath + newFileName + fileExtension);
        }
Пример #12
0
        /// <summary>
        /// Empty constructor for Controller
        /// </summary>
        public Controller(ProgramSettings settings)
        {
            //LocatedBridges = new List<BridgeInfo>();
            m_AppKeyManager = new AppKeyManager(true); //BSON deserialisieren

            GlobalSettings = settings;

            //Hack Newtonsoft.Json
            JsonSerializer serializer = new JsonSerializer();
        }
Пример #13
0
        public void Parse_MandatoryOptionMissing()
        {
            ProgramSettings ps = new ProgramSettings("command");

            ps.AddOption(new string[] { "mandatoryOption" }, true);
            Assert.Throws <ParseException>(delegate
            {
                Parser.Parse("", ps);
            });
        }
Пример #14
0
        public void ParameterWithCommasJoint()
        {
            var settings = new ProgramSettings("program");

            settings.AddOption('h', "hh", true, new StringParameter("par", true));
            var result = Parser.Parse(new[] { "-h=1,2,3", "--", "abraka", "dabra" }, settings);

            Assert.IsTrue(result.WasParsed("hh"));
            Assert.AreEqual((string)result.GetParameterValue("h"), "1,2,3");
        }
Пример #15
0
        public UpdateTask(IAppParser appParser, IAppIndexer indexer, IUpdateNotifier notifier,
            IKernel kernel, ProgramSettings settings)
            : base(settings) {
            this.appParser = appParser;
            this.indexer = indexer;
            this.notifier = notifier;
            this.kernel = kernel;

            limit = settings.BatchSize / 200 * 200; // 因为Search API是200一批,找个最接近的200的倍数,以免浪费
        }
Пример #16
0
        public void Parse_WrongNumberOfOptionParameters()
        {
            ProgramSettings ps = new ProgramSettings("command");

            ps.AddOption(new string[] { "intOption" }, true, new IntParameter("name", true, 0, 10));
            Assert.Throws <ParseException>(delegate
            {
                Parser.Parse("command -intOption", ps);
            });
        }
        public void SaveConfig()
        {
            //	Create the directories that hold the config files if they don't exist.
            Directory.CreateDirectory(ConfigFolderPath);

            //	Ask our children to save themselves.  The children are expected to back up old files on their own if applicable.
            ProgramSettings.SaveConfig();
            FileAliasSettings.SaveConfig();
            CharacterAliasSettings.SaveConfig();
        }
Пример #18
0
        private static void runTimeCommandExample()
        {
            ProgramSettings s = new ProgramSettings("time");

            s.AddOption('f', "format", false, new StringParameter("FORMAT", true),
                        "Specify output format, possibly overriding the format specified in the environment variable TIME.");
            s.AddOption('p', "portability", false, null,
                        "Use the portable output format.");
            s.AddOption('o', "output", false, new StringParameter("FILE", true),
                        "Do not send the results to stderr, but overwrite the specified file.");
            s.AddOption('a', "append", false, null,
                        "(Used together with -o.) Do not overwrite but append.");
            s.AddOption('v', "verbose", false, null,
                        "Give very verbose output about all the program knows about.");
            s.AddOption('V', "version", false, null,
                        "Print version information on standard output, then exit successfully.");
            s.AddOption(null, "help", false, null,
                        "Print a usage message on standard output and exit successfully.");

            s.AddOptionDependency("a", "o"); // both of these options must be present if first option is present

            string      cmd    = "time -o output_file -a --verbose -- first_file second_file";
            ParseResult result = Parser.Parse(cmd, s);

            // get parameter value for specific option (cast needed)
            string output = (string)result.GetParameterValue("o");

            output = (string)result.GetParameterValue("output");

            // find out whether this option was present (good for non-parametric /Boolean/ options)
            result.WasParsed("v"); // true
            result.WasParsed("p"); // false

            // enumerate all parsed options
            foreach (var item in result.ParsedOptions)
            {
                if (item.Names.Contains("v"))
                {
                    // ...
                }
                else if (item.Names.Contains("o"))
                {
                    string outFile = (string)item.Value;
                    // printOutput(outFile);
                }
                // ...
            }

            // get all the plain arguments in the order they appeared in the command
            List <string> plainArgs = result.PlainArguments;

            // print help using specified TextWriter
            s.PrintHelp(Console.Out);
            //s.PrintHelp(new System.IO.StreamWriter("myfile.txt"));
        }
Пример #19
0
 public virtual void SetUp()
 {
     _wordListReaderFactory        = A.Fake <IWordListReaderFactory>();
     _wordCombinationFinderFactory = A.Fake <IWordCombinationFinderFactory>();
     _outputWriter = A.Fake <IWordCombinationsOutputWriter>();
     _settings     = new ProgramSettings {
         DesiredWordLength = 8,
         WordListFile      = new FileInfo("C:\\Windows\\WordList.ini")
     };
     _sut = new WordListProgram(_wordListReaderFactory, _wordCombinationFinderFactory, _outputWriter, _settings);
 }
        public SerializeObject ProcessFirstUnprocessedData()
        {
            _properietes = ProgramSettingsHelper.GetProperietes();
            var unprocessedData = _externalDataService.GetFirstUnprocessedExternalData();

            unprocessedData.PhotoPath = FindPhotoPathByTriggerDateTime(unprocessedData.Vehicles.First().DateTime);
            unprocessedData           = _anprService.GetInfoFromPhoto(unprocessedData);
            _externalDataService.DeleteProcessedExternalData(unprocessedData.Id);

            return(unprocessedData);
        }
Пример #21
0
 private void LoadProgramSettings(string settingsPath)
 {
     try
     {
         _programSettings = JsonConvert.DeserializeObject <ProgramSettings>(File.ReadAllText(settingsPath));
     }
     catch (Exception)
     {
         // Ignore it
     }
 }
        private void InitializeControls(ProgramSettings settings)
        {
            chbAutoStart.Checked       = settings.AutoStartProgram;
            chbListerMaximized.Checked = settings.ListerFormMaximized;
            txtListerWidth.Text        = settings.ListerFormWidth.ToString();
            txtListerHeight.Text       = settings.ListerFormHeight.ToString();
            txtHighVersion.Text        = settings.PluginHighVersion.ToString();
            txtLowVersion.Text         = settings.PluginLowVersion.ToString();
            txtIniFile.Text            = settings.PluginIniFile;
            if (settings.PluginIniFile.StartsWith(AssemblyUtils.AssemblyDirectory, StringComparison.InvariantCultureIgnoreCase))
            {
                txtIniFile.Text = settings.PluginIniFile.Substring(AssemblyUtils.AssemblyDirectory.Length).TrimStart('\\');
            }

            cmbListerFormKey1.DataSource      = Enum.GetValues(typeof(VirtualKeyModifier));
            cmbListerFormKey1.SelectedItem    = (VirtualKeyModifier)settings.ListerFormKey1;
            cmbListerFormKey2.DataSource      = Enum.GetValues(typeof(VirtualKeyModifier));
            cmbListerFormKey2.SelectedItem    = (VirtualKeyModifier)settings.ListerFormKey2;
            cmbListerFormKey3.ValueMember     = "Id";
            cmbListerFormKey3.DisplayMember   = "Text";
            cmbListerFormKey3.DataSource      = ((VirtualKey[])Enum.GetValues(typeof(VirtualKey))).Where(x => !string.IsNullOrEmpty(x.GetDescription())).Select(x => new { Id = (int)x, Text = x.GetDescription() }).ToList();
            cmbListerFormKey3.SelectedValue   = settings.ListerFormKey3;
            cmbSearchDialogKey1.DataSource    = Enum.GetValues(typeof(VirtualKeyModifier));
            cmbSearchDialogKey1.SelectedItem  = (VirtualKeyModifier)settings.SearchDialogKey1;
            cmbSearchDialogKey2.DataSource    = Enum.GetValues(typeof(VirtualKeyModifier));
            cmbSearchDialogKey2.SelectedItem  = (VirtualKeyModifier)settings.SearchDialogKey2;
            cmbSearchDialogKey3.ValueMember   = "Id";
            cmbSearchDialogKey3.DisplayMember = "Text";
            cmbSearchDialogKey3.DataSource    = ((VirtualKey[])Enum.GetValues(typeof(VirtualKey))).Where(x => !string.IsNullOrEmpty(x.GetDescription())).Select(x => new { Id = (int)x, Text = x.GetDescription() }).ToList();
            cmbSearchDialogKey3.SelectedValue = settings.SearchDialogKey3;
            cmbPrintDialogKey1.DataSource     = Enum.GetValues(typeof(VirtualKeyModifier));
            cmbPrintDialogKey1.SelectedItem   = (VirtualKeyModifier)settings.PrintDialogKey1;
            cmbPrintDialogKey2.DataSource     = Enum.GetValues(typeof(VirtualKeyModifier));
            cmbPrintDialogKey2.SelectedItem   = (VirtualKeyModifier)settings.PrintDialogKey2;
            cmbPrintDialogKey3.ValueMember    = "Id";
            cmbPrintDialogKey3.DisplayMember  = "Text";
            cmbPrintDialogKey3.DataSource     = ((VirtualKey[])Enum.GetValues(typeof(VirtualKey))).Where(x => !string.IsNullOrEmpty(x.GetDescription())).Select(x => new { Id = (int)x, Text = x.GetDescription() }).ToList();
            cmbPrintDialogKey3.SelectedValue  = settings.PrintDialogKey3;

            foreach (var plugin in settings.Plugins)
            {
                var fileName = plugin.Path;
                if (fileName.StartsWith(AssemblyUtils.AssemblyDirectory, StringComparison.InvariantCultureIgnoreCase))
                {
                    fileName = fileName.Substring(AssemblyUtils.AssemblyDirectory.Length).TrimStart('\\');
                }
                var index = gridViewPlugin.Rows.Add();
                var row   = gridViewPlugin.Rows[index];
                row.Cells[0].Value = fileName;
                row.Cells[1].Value = string.Join(";", plugin.Extensions.ToArray());
            }
            gridViewPlugin.Columns[0].Width = gridViewPlugin.ClientSize.Width - 100;
            gridViewPlugin.Columns[1].Width = 100;
        }
Пример #23
0
        public void Parse_OptionDependencyErrorSecond()
        {
            ProgramSettings ps = new ProgramSettings("command");

            ps.AddOption(new string[] { "a" }, true);
            ps.AddOption(new string[] { "b" }, true);
            ps.AddOptionDependency("a", "b");
            Assert.Throws <ParseException>(delegate
            {
                Parser.Parse("command -b", ps);
            });
        }
Пример #24
0
        public PluginForm(ProgramSettings settings, PluginManager pluginMgr)
        {
            InitializeComponent();

            pluginManager = pluginMgr;
            SetupButtons();

            PrevPagePluginBtn.BackgroundImage = Image.FromFile("./Data/Image/PrevPlugin.png");
            NextPagePluginBtn.BackgroundImage = Image.FromFile("./Data/Image/NextPlugin.png");

            SizeChanged += new EventHandler(PluginForm_SizeChanged);
        }
Пример #25
0
        public void Parse_ConflictingOptions()
        {
            ProgramSettings ps = new ProgramSettings("command");

            ps.AddOption(new string[] { "a" }, true);
            ps.AddOption(new string[] { "b" }, true);
            ps.AddOptionConflict("a", "b");
            Assert.Throws <ParseException>(delegate
            {
                Parser.Parse("command -a -b", ps);
            });
        }
        public void AddOptionConflict_ConflictingOptionDependency()
        {
            var ps = new ProgramSettings("command");

            ps.AddOption('a', "aOption", false);
            ps.AddOption('b', "bOption", false);
            ps.AddOptionDependency("a", "b");
            Assert.Throws <ConstraintException>(delegate
            {
                ps.AddOptionConflict("a", "b");
            });
        }
Пример #27
0
        static void Main(string[] args)
        {
            m_settings = Properties.ProgramSettings.Default;

            PrintVersionAndSettings();

            CheckScreenResolutions();

            var engine = AdNotifierEngine.Create(m_settings.PollPeriodMilliseconds);

            engine.Result.LoopForever();
        }
Пример #28
0
        /// <summary>
        /// Loads the type.
        /// </summary>
        /// <param name="component">The type.</param>
        public void LoadComponent(Configuration.GlobalPlugin component)
        {
            _type = component;

            var globalSettings = ProgramSettings.GetGlobalSettings();

            Image icon = Resources.add_on;

            if (component.Icon != null)
            {
                icon = component.Icon;

                if (string.IsNullOrWhiteSpace(component.IconPath))
                {
                    component.IconPath = PluginsManager.SaveIconOnCache(component.Icon, globalSettings);
                }
            }
            else if (!string.IsNullOrWhiteSpace(component.IconPath))
            {
                string iconLocation = Path.Combine(globalSettings.DirectoriesSettings.CacheDirectory, component.IconPath);
                if (File.Exists(iconLocation))
                {
                    component.Icon = Image.FromFile(iconLocation);
                    icon           = component.Icon;
                }
                else if (component.PluginInstance != null)
                {
                    component.Icon     = component.PluginInstance.Icon;
                    component.IconPath = PluginsManager.SaveIconOnCache(component.Icon, globalSettings);
                    icon = component.Icon;
                }
                else
                {
                    component.IconPath = null;
                }
            }

            pictureTypeIcon.Image = icon;

            lblCreatedBy.Text = component.CreatedBy;
            lblVersion.Text   = component.Version;

            Uri uriReleaseInfo;

            lnkReleasaeInfo.Visible = !string.IsNullOrWhiteSpace(component.ReleaseNotesUrl) && Uri.TryCreate(component.ReleaseNotesUrl, UriKind.Absolute, out uriReleaseInfo) && uriReleaseInfo.Scheme == Uri.UriSchemeHttp;

            Uri uriAuthorWebsite;

            lnkAuthorWebsite.Visible = !string.IsNullOrWhiteSpace(component.AuthorWebsiteUrl) && Uri.TryCreate(component.AuthorWebsiteUrl, UriKind.Absolute, out uriAuthorWebsite) && uriAuthorWebsite.Scheme == Uri.UriSchemeHttp;

            txtPluginDescription.Text = component.Description;
        }
Пример #29
0
        /// <summary>
        /// Loads the local variables.
        /// </summary>
        public void LoadLocalVariables()
        {
            _settings = ProgramSettings.GetGlobalSettings();

            txtDefaultProjectsDirectory.Text = _settings.DirectoriesSettings.DefaultProjectsDirectory;
            txtPluginsDirectory.Text         = _settings.DirectoriesSettings.PluginsDirectory;
            txtCacheDirectory.Text           = _settings.DirectoriesSettings.CacheDirectory;
            txtTempDirectory.Text            = _settings.DirectoriesSettings.TempDirectory;
            txtLogDirectory.Text             = _settings.DirectoriesSettings.LogDirectory;

            LogLevel.AllLevels.ToList().ForEach(l => cmbLogLevel.Items.Add(l));
            cmbLogLevel.SelectedItem = LogLevel.AllLevels.FirstOrDefault(l => l.Name.Equals(_settings.LogSettings.Level, StringComparison.InvariantCultureIgnoreCase));
        }
Пример #30
0
        public void Settings_Always_SavesValue(int manageIntervalMilliseconds)
        {
            var uut = new ProgramSettingsProvider();

            var settings = new ProgramSettings()
            {
                ManageInterval = TimeSpan.FromMilliseconds(manageIntervalMilliseconds)
            };

            uut.Settings = settings;

            uut.Settings.ShouldBe(settings);
        }
        public WebSocketThread(ProgramSettings programSettings,
                               SerialThread serialThread,
                               AlarmThread alarmThread,
                               IApiService apiService,
                               ILoggerFactory loggerFactory)
        {
            this.uri          = $"ws://{programSettings.WebServerHost}:{programSettings.WebServerPort}";
            this.serialThread = serialThread;
            this.alarmThread  = alarmThread;
            this.apiService   = apiService;

            this.logger = loggerFactory.CreateLogger <WebSocketThread>();
        }
Пример #32
0
        public StartWindow()
        {
            InitializeComponent();

            Title = App.Name;

            ProgramSettings settings = ProgramSettings.GetInstance();

            if (string.IsNullOrEmpty(settings.LastOpenCollection))
            {
                button_LastOpenCollection.IsEnabled = false;
            }
        }
Пример #33
0
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        private bool SaveSettings()
        {
            ProgramSettings.ScannerProductName    = TwainLib.GetSelectedSource();
            ProgramSettings.UseInsertion          = InsertionCheckBox.Checked;
            ProgramSettings.UseDoubleSided        = DoubleSidedCheckBox.Checked;
            ProgramSettings.UseGrey               = GreyCheckBox.Checked;
            ProgramSettings.CheckIfEmpty          = CheckIfEmptyCheckBox.Checked;
            ProgramSettings.UseEdgeDetection      = EdgeDetectionCheckBox.Checked;
            ProgramSettings.UseRotationCorrection = RotationCorrectionCheckBox.Checked;
            ProgramSettings.UseVendorTool         = VendorToolCheckBox.Checked;
            ProgramSettings.Save();
            return(true);
        }
Пример #34
0
        public AppParser(IWebDownload download, JsonSerializerSettings serializerSettings,
            int truncateLimit, MatchOptions segmentMatchOptions, ProgramSettings settings) {
            this.download = download;
            this.serializerSettings = serializerSettings;
            this.truncateLimit = truncateLimit;
            this.segmentMatchOptions = segmentMatchOptions;
            this.settings = settings;

            // Debug下为了Fiddler的Auto Responder能稳定拦截请求,需要对id进行排序
            if (settings.Debug) {
                this.output = new SortedSet<int>();
            }
            else {
                this.output = new HashSet<int>();
            }
        }
Пример #35
0
 public UpdateNotifier(RepositoryEmitter repository, SmtpClient smtp, ProgramSettings settings) {
     this.repository = repository;
     this.smtp = smtp;
     this.settings = settings;
 }
Пример #36
0
        public LuceneIndexer(bool rebuild, ProgramSettings settings) {
            this.settings = settings;

            writer = CreateIndexWriter(rebuild);
        }
Пример #37
0
 public WebDownload(ProgramSettings settings) {
     if (!String.IsNullOrEmpty(settings.ProxyAddress)) {
         proxy = new WebProxy(settings.ProxyAddress);
     }
 }
Пример #38
0
        static void LoadSettings()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(ProgramSettings));

            string path = Path.Combine(System.Environment.SpecialFolder.ApplicationData.ToString(), APP_SETTINGS_DIRECTORY);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
                return;
            }

            path = Path.Combine(path, APP_SETTINGS_FILENAME);

            if (File.Exists(path))
            {
                using (XmlReader reader = XmlReader.Create(path))
                {
                    Program.Settings = (ProgramSettings)serializer.Deserialize(reader);
                }
            }
        }
Пример #39
0
 public TestTask(IKernel kernel, ProgramSettings settings)
     : base(settings) {
     this.kernel = kernel;
 }
Пример #40
0
 protected TaskBase(ProgramSettings settings) {
     this.settings = settings;
 }