public static bool AddTemplate(this CommandsTemplates commandsTemplates, string commandName, string templateDescription, string commandLine, bool overwrite) { Dictionary <string, string> templates; if (commandsTemplates.Templates.TryGetValue(commandName, out templates))//command templates exists { if (templates.ContainsKey(templateDescription)) { if (overwrite) { templates[templateDescription] = commandLine; } else { return(false); } } else { templates[templateDescription] = commandLine; } } else { templates = new Dictionary <string, string>(); commandsTemplates.Templates[commandName] = templates; templates[templateDescription] = commandLine; } commandsTemplates.MarkDirty(); return(true); }
public static void DeleteTemplate(this CommandsTemplates commandsTemplates, string commandName, string templateDescription) { Dictionary <string, string> commandDic; if (commandsTemplates.Templates.TryGetValue(commandName, out commandDic)) { if (commandDic.Remove(templateDescription)) { commandsTemplates.MarkDirty(); } } }
public static IEnumerable <string> GetTemplatesNames(this CommandsTemplates commandsTemplates, string commandName) { Dictionary <string, string> commandDic; if (commandsTemplates.Templates.TryGetValue(commandName, out commandDic)) { return(commandDic.Keys); } else { return(null); } }
public static void Save(CommandsTemplates commandsTemplates) { if (!commandsTemplates.Modified) { return; } string filePath = GetDefaultExeConfigPath(ConfigurationUserLevel.PerUserRoamingAndLocal); using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write)) { var serializer = new DataContractSerializer(typeof(CommandsTemplatesDictionary)); serializer.WriteObject(fs, commandsTemplates.Templates); } }