Пример #1
0
        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);
        }
Пример #2
0
        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();
                }
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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);
            }
        }