public int Add(MessagePatternModel link, int id)
        {
            Trace.Call(link, id);

            if (link == null) {
                throw new ArgumentNullException("link");
            }

            string[] keys = PatternIDs;
            if (keys == null) {
                keys = new string[] {};
            }
            int highestKey = 0;
            int newKey = id;
            if (id == -1) {
                foreach (string key in keys) {
                    int parsedKey = Int32.Parse(key);
                    if (parsedKey > highestKey) {
                        highestKey = parsedKey;
                    }
                }
                newKey = ++highestKey;
            }

            link.ID = newKey;
            link.Save(UserConfig);

            var keyList = new List<string>(keys);
            keyList.Add(link.ID.ToString());
            PatternIDs = keyList.ToArray();
            return newKey;
        }
Example #2
0
        static MessageBuilderSettings()
        {
            // OPT: this emoji regex is really long, around 27k characters
            var emojiRegexBuilder = new StringBuilder(32 * 1024);

            emojiRegexBuilder.Append(":(");
            foreach (var emojiShortname in Emojione.ShortnameToUnicodeMap.Keys)
            {
                emojiRegexBuilder.AppendFormat("{0}|", Regex.Escape(emojiShortname));
            }
            // remove trailing |
            emojiRegexBuilder.Length--;
            emojiRegexBuilder.Append("):");

            var emojiRegex = new Regex(emojiRegexBuilder.ToString(), RegexOptions.Compiled);

            EmojiMessagePattern = new MessagePatternModel(emojiRegex)
            {
                MessagePartType = typeof(ImageMessagePartModel),
                LinkFormat      = "smuxi-emoji://{1}"
            };

            BuiltinPatterns = new List <MessagePatternModel>();
            InitBuiltinSmartLinks();
        }
        public void Set(MessagePatternModel link)
        {
            Trace.Call(link);

            if (link == null)
            {
                throw new ArgumentNullException("link");
            }

            link.Save(UserConfig);
        }
        public MessagePatternModel Get(int id)
        {
            Trace.Call(id);

            string prefix = "MessagePatterns/" + id + "/";

            if (UserConfig[prefix + "MessagePartPattern"] == null)
            {
                // link does not exist
                return(null);
            }
            var link = new MessagePatternModel(id);

            link.Load(UserConfig);
            return(link);
        }
        public int Add(MessagePatternModel link, int id)
        {
            Trace.Call(link, id);

            if (link == null)
            {
                throw new ArgumentNullException("link");
            }

            string[] keys = PatternIDs;
            if (keys == null)
            {
                keys = new string[] {};
            }
            int highestKey = 0;
            int newKey     = id;

            if (id == -1)
            {
                foreach (string key in keys)
                {
                    int parsedKey = Int32.Parse(key);
                    if (parsedKey > highestKey)
                    {
                        highestKey = parsedKey;
                    }
                }
                newKey = ++highestKey;
            }

            link.ID = newKey;
            link.Save(UserConfig);

            var keyList = new List <string>(keys);

            keyList.Add(link.ID.ToString());
            PatternIDs = keyList.ToArray();
            return(newKey);
        }
 public int Add(MessagePatternModel link)
 {
     return Add(link, -1);
 }
        public void Set(MessagePatternModel link)
        {
            Trace.Call(link);

            if (link == null) {
                throw new ArgumentNullException("link");
            }

            link.Save(UserConfig);
        }
        public MessagePatternModel Get(int id)
        {
            Trace.Call(id);

            string prefix = "MessagePatterns/" + id + "/";
            if (UserConfig[prefix + "MessagePartPattern"] == null) {
                // link does not exist
                return null;
            }
            var link = new MessagePatternModel(id);
            link.Load(UserConfig);
            return link;
        }
 public int Add(MessagePatternModel link)
 {
     return(Add(link, -1));
 }