/// <summary> /// Get the prefix for a server. /// Will reset the prefix to default if it is corrupted. /// </summary> /// <param name="serverId">The id of the server.</param> /// <returns>The prefix used for the server.</returns> /// <exception cref="UnknownServerException">Thrown if the main server data could not be found.</exception> public async Task <string> GetPrefix(ulong serverId) { var result = await _dbSetting.Get(serverId); if (result == null) { result = new CommandSetting { ServerId = serverId }; try { await _dbSetting.Add(result); } catch (Exception e) { throw new UnknownServerException("The database is most likely missing the main server data.", e); } } if (string.IsNullOrWhiteSpace(result?.Prefix)) { result.Prefix = "/"; await _dbSetting.Update(result); } return(result.Prefix); }
public Server() { Id = "Servers/"; LanguageSetting = new LanguageSetting(); CommandSetting = new CommandSetting(); WelcomeMessage = new WelcomeMessage(); }
private void SaveCommandField() { string text = cboCommandLine.Text; if (text.Trim().Length == 0) { return; } string template = TranslateToTokens(text); if (!Administrator.ProfileManager.CommandSettings.Keys.Contains(text)) { CommandSetting commandSetting = new CommandSetting { Key = text, Line = text, Template = template }; Administrator.ProfileManager.CommandSettings.Persist(commandSetting); InitialiseCommandField(); } else { Administrator.ProfileManager.CommandSettings.Select(text); //Administrator.ProfileManager.CommandSettings.SelectedItem.Line = text; //Administrator.ProfileManager.CommandSettings.Save(); } //setCboCommandLineText(Administrator.ProfileManager.CommandSettings.SelectedKey); }
public void Initialize(string buttonText, CommandSetting command) { SetButtonText(buttonText); myCommand = command; button.OnClickAsObservable().Subscribe(_ => { commandTriggerController.Send(command); }).AddTo(this); }
/// <summary> /// Set the prefix of a server. /// </summary> /// <param name="serverId">The id of the server.</param> /// <param name="prefix">the new prefix.</param> public async Task SetPrefix(ulong serverId, string prefix) { var setting = new CommandSetting { ServerId = serverId, Prefix = prefix }; await _dbSetting.Update(setting); }
private CommandDefinition GetCommandDefinition( CommandSetting setting, object parameters = null, IDbTransaction transaction = null, CancellationToken cancellationToken = default(CancellationToken)) => new CommandDefinition( commandText: setting.CommandText, parameters: parameters, transaction: transaction, commandTimeout: setting.CommandTimeout, commandType: setting.CommandType, flags: setting.Flags, cancellationToken: cancellationToken);
public async Task Update(CommandSetting value) { //try //{ // var entry = Context.Attach(value); // entry.State = EntityState.Modified; //} //catch //{ // //ignore //} Context.CommandSettings.Update(value); await Context.SaveChangesAsync(); }
private void Form1_Load(object sender, EventArgs e) { Server.OnConnect += OnConnect; Server.OnDisconnect += OnDisconnect; Server.Start(); //加载自定义命令 var commands = CommandSetting.Load(@"CommandSettings.xml"); foreach (var command in commands) { var item = toolStripMenuItemCMDs.DropDownItems.Add(command.Name); item.Tag = command; item.Click += toolStripMenuItemCMDs_Click; } }
/// <summary> /// Creates a database connection. /// </summary> /// <param name="type"></param> /// <param name="commandSetting"></param> /// <returns></returns> public IDbConnection CreateDbConnection(Type type, CommandSetting commandSetting) { Require <ArgumentNullException>(type != null, ErrorMessages.NullTypeError); Require <ArgumentNullException>(commandSetting != null, $"The command setting passed was null. Check configuration for type '{type.FullName}'."); var connectionString = commandSetting.ConnectionString; if (connectionString == null) { return(CreateDbConnection(type)); } Require <ArgumentNullException>(!string.IsNullOrWhiteSpace(connectionString.ProviderName), "The providerName from the command setting cannot be null."); Require <ArgumentNullException>(!string.IsNullOrWhiteSpace(connectionString.ConnectionString), "The connectionString from the command setting cannot be null."); return(CreateDbConnection(connectionString.ProviderName, connectionString.ConnectionString)); }
/// <summary> /// 快捷命令行。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripMenuItemCMDs_Click(object sender, EventArgs e) { CommandSetting setting = (sender as ToolStripMenuItem).Tag as CommandSetting; foreach (ListViewItem lvi in listView1.SelectedItems) { try { CmdForm form = new CmdForm(lvi.Tag as ClientData); form.Show(setting.Commands); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
/// <summary> /// Gets the command setting /// </summary> /// <param name="type">The type.</param> /// <param name="key">The key.</param> public CommandSetting GetCommand(Type type, string key) { Require <ArgumentNullException>(type != null, ErrorMessages.NullTypePassed); Require <ArgumentNullException>(!string.IsNullOrWhiteSpace(key), ErrorMessages.NullKeyPassed); var section = DrapperConfigurationSection.GetConfiguration(); Require <ArgumentNullException>(section != null, ErrorMessages.NoSectionDefinition); var @namespace = GetNamespaceSettingElement(section, type); Require <ArgumentNullException>(@namespace != null, ErrorMessages.NoNamespaceEntry, type.Namespace); var typeSetting = GetTypeSettingElement(@namespace, type); Require <ArgumentNullException>(typeSetting != null, ErrorMessages.UnknownType, type); var entry = GetCommandSetting(typeSetting, key); Require <ArgumentNullException>(entry != null, ErrorMessages.NoCommandSetting, type, key); var result = new CommandSetting { CommandText = entry.CommandText, CommandTimeout = entry.CommandTimeout, CommandType = entry.CommandType, Flags = entry.Flags, Split = entry.Split, IsolationLevel = entry.IsolationLevel }; Validate(result); return(result); }
void StartCompile(CompileMode mode) { // a compile is running already if (IsCompiling()) { //TODO: should halt compiling really return; //CurrentThread.Stop(); } if (mode.bIntercepted) { Options options = OptionsManager.GetGlobalOptions().GetGlobalConfiguration().Options; bool bExtendCommands = options.ExtendCommands.Value; if (!bExtendCommands) { return; } } if (IsVSCompiling()) { //cancel it App().ExecuteCommand("Build.Cancel", ""); } // activate the output pane... GetOutputPane().Clear(); ActivateOutputPane(); // ok, lets attempt to start compiling now. CurrentThread = null; PostEvent = ""; // no solution loaded DTE2 app = App(); Solution solution = app.Solution; if (solution == null) { return; } // first save all the open files - this is a global setting SaveOpenFiles(); List <Project> Projects; // find the selections we need (projects) if (mode.Selection == SelectionTypes.Solution) { Projects = ProjectUtility.GetSolutionProjects(); } else if (mode.Selection == SelectionTypes.Project) { Projects = ProjectUtility.GetActiveProjects(); } else // if (mode.Selection == SelectionTypes.ProjectOnly) { Projects = ProjectUtility.GetActiveProjectOnly(); } // // Mode Arguments // // clean : send it -clean // rebuild : send it -force // build : none... string ModeArguments = ""; if (mode.Action == CompileTypes.Rebuild) { ModeArguments += "-force"; } else if (mode.Action == CompileTypes.Clean) { ModeArguments += "-clean"; } //else if Debug || NoDebug || Build ... no additional needed //TODO: need the global options path string GlobalArguments = "-dependencies \"" + Paths.GetGlobalOptionsFilename() + "\""; //no projects to compile if (Projects.Count == 0) { return; } List <CommandSetting> CommandSettings = new List <CommandSetting>(); int numprojects = Projects.Count; for (int ip = 0; ip < numprojects; ip++) { Project project = Projects[ip]; string ActiveConfiguration = ProjectUtility.ProjectActiveConfiguration(project); List <VCFile> ohfiles = ProjectUtility.GetOhFiles(project); // does it contain active oh files? if not skip it. ProjectUtility.FilterActiveFiles(ref ohfiles, ActiveConfiguration); if (ohfiles.Count == 0) { continue; } // are the project settings set to enable opcpp? bool bProjectEnabled = true; if (!bProjectEnabled) { continue; } //3. do we have .doh files in the project? List <VCFile> dohfiles = ProjectUtility.GetDohFiles(project); ProjectUtility.FilterActiveFiles(ref dohfiles, ActiveConfiguration); // if (dohfiles.Count == 0) // continue; //fetch the project doh files from the global/project doh settings List <string> ProjectDohFiles = new List <string>(); // if(ProjectDohFiles.Count + dohfiles.Count == 0) // { // //print a message "Project has oh files but no dialect was found or specified" // continue; // } //now build the settings CommandSetting setting = new CommandSetting(); setting.Project = project; setting.WorkingDir = StringUtility.RLeft(project.FileName, "\\"); //build the oh files list from the arguments //build the doh files list from the arguments string ohfilestring = ""; for (int i = 0; i < ohfiles.Count; i++) { VCFile file = ohfiles[i]; ohfilestring += '"'; ohfilestring += file.FullPath; ohfilestring += '"'; if (i + 1 < ohfiles.Count) { ohfilestring += ','; } } string dohfilestring = ""; for (int i = 0; i < dohfiles.Count; i++) { VCFile file = dohfiles[i]; dohfilestring += '"'; dohfilestring += file.FullPath; dohfilestring += '"'; if (i + 1 < dohfiles.Count) { dohfilestring += ','; } } for (int i = 0; i < ProjectDohFiles.Count; i++) { dohfilestring += '"'; dohfilestring += ProjectDohFiles[i]; dohfilestring += '"'; if (i + 1 < ProjectDohFiles.Count) { dohfilestring += ','; } } string FileArguments = ""; if (ohfilestring.Length > 0) { FileArguments += " -oh " + ohfilestring; } if (dohfilestring.Length > 0) { FileArguments += " -doh " + dohfilestring; } // fetch the global + overloaded project arguments CommandLineInfo info = OptionsManager.GetCommandLineInfo(project); setting.ExePath = info.ExecutablePath; FileArguments += " -dependencies \"" + Paths.GetProjectOptionsFilename(project) + "\""; if (setting.ExePath == "") { LogCompile("Error: opCpp exe path is undefined, please define in global and/or project settings"); return; } string ProjectArguments = info.Arguments; string MacroArguments = FileArguments + " " + ProjectArguments + " " + ModeArguments + " " + GlobalArguments; if (opBeta.IsBeta) { MacroArguments += " -beta"; } setting.Arguments = Paths.ResolveVisualStudioMacros(project, MacroArguments); //verify the macros worked... Regex findmacros = new Regex("$\\(*.\\)"); Match result = findmacros.Match(setting.Arguments); if (result.Success) { string foundstring = setting.Arguments.Substring(result.Index, result.Length); LogCompile("Error: bad macro found in settings - " + foundstring); return; } CommandSettings.Add(setting); } //no commands to execute if (CommandSettings.Count == 0) { // CurrentMode = null; // FinishedCompile(false); return; } //execute commands CurrentMode = mode; CurrentThread = new opCppThread(CommandSettings); CurrentThread.OnReadLine = LogCompile; CurrentThread.OnEnd = FinishedCompile; CurrentThread.Start(); }
public void CommandFlagsReturnsNoneByDefault() { var setting = new CommandSetting(); Equal(CommandFlags.None, setting.Flags); }
public async Task Add(CommandSetting value) { Context.CommandSettings.Add(value); await Context.SaveChangesAsync(); }
public void Send(CommandSetting command) { commandTriggerUseCase.SendCommand(command.CommandName); }
public async Task Remove(CommandSetting value) { Context.CommandSettings.Remove(value); await Context.SaveChangesAsync(); }
public void CommandTextReturnsNullByDefault() { var setting = new CommandSetting(); Equal(null, setting.CommandText); }
public void CommandTimeoutReturnsThirtyByDefault() { var setting = new CommandSetting(); Equal(30, setting.CommandTimeout); }
public void CommandTypeReturnsTextByDefault() { var setting = new CommandSetting(); Equal(CommandType.Text, setting.CommandType); }
public void IsolationLevelDefaultsToSerializable() { var setting = new CommandSetting(); Equal(IsolationLevel.Serializable, setting.IsolationLevel); }