Пример #1
0
        public int AddFilter(FilterModel filter)
        {
            Trace.Call(filter);

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

            string[] filterKeys = (string[]) f_UserConfig["Filters/Filters"];
            if (filterKeys == null) {
                filterKeys = new string[] {};
            }
            int highestKey = 0;
            foreach (string filterKey in filterKeys) {
                int key = Int32.Parse(filterKey);
                if (key > highestKey) {
                    highestKey = key;
                }
            }
            int newKey = ++highestKey;

            string prefix = "Filters/" + newKey + "/";
            f_UserConfig[prefix + "Protocol"] = filter.Protocol;
            f_UserConfig[prefix + "NetworkID"] = filter.NetworkID;
            if (filter.ChatType == null) {
                f_UserConfig[prefix + "ChatType"] = String.Empty;
            } else {
                f_UserConfig[prefix + "ChatType"] = filter.ChatType.ToString();
            }
            f_UserConfig[prefix + "ChatID"] = filter.ChatID;
            if (filter.MessageType == null) {
                f_UserConfig[prefix + "MessageType"] = String.Empty;
            } else {
                f_UserConfig[prefix + "MessageType"] = filter.MessageType.ToString();
            }
            f_UserConfig[prefix + "MessagePattern"] = filter.MessagePattern;

            List<string> filterKeyList = new List<string>(filterKeys);
            filterKeyList.Add(newKey.ToString());
            f_UserConfig["Filters/Filters"] = filterKeyList.ToArray();
            return newKey;
        }
Пример #2
0
        protected virtual void OnAddButtonClicked(object sender, System.EventArgs e)
        {
            Trace.Call(sender, e);

            try {
                var filter = new FilterModel();
                filter.Protocol       = String.Empty;
                filter.ChatID         = String.Empty;
                filter.MessagePattern = String.Empty;
                Gtk.TreeIter iter = f_ListStore.AppendValues(filter, -1);
                f_TreeView.Selection.SelectIter(iter);

                OnChanged(EventArgs.Empty);
            } catch (Exception ex) {
                Frontend.ShowException(ex);
            }
        }
Пример #3
0
        public void SetFilter(int key, FilterModel filter)
        {
            Trace.Call(key, filter);

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

            string prefix = "Filters/" + key + "/";
            f_UserConfig[prefix + "Protocol"] = filter.Protocol;
            f_UserConfig[prefix + "NetworkID"] = filter.NetworkID;
            if (filter.ChatType == null) {
                f_UserConfig[prefix + "ChatType"] = String.Empty;
            } else {
                f_UserConfig[prefix + "ChatType"] = filter.ChatType.ToString();
            }
            f_UserConfig[prefix + "ChatID"] = filter.ChatID;
            if (filter.MessageType == null) {
                f_UserConfig[prefix + "MessageType"] = String.Empty;
            } else {
                f_UserConfig[prefix + "MessageType"] = filter.MessageType.ToString();
            }
            f_UserConfig[prefix + "MessagePattern"] = filter.MessagePattern;
        }
Пример #4
0
        public FilterModel GetFilter(int key)
        {
            Trace.Call(key);

            string prefix = "Filters/" + key + "/";
            if (f_UserConfig[prefix + "MessagePattern"] == null) {
                // filter does not exist
                return null;
            }
            FilterModel filter = new FilterModel();
            filter.Protocol = (string) f_UserConfig[prefix + "Protocol"];
            filter.NetworkID = (string) f_UserConfig[prefix + "NetworkID"];
            var chatType = (string) f_UserConfig[prefix + "ChatType"];
            if (!String.IsNullOrEmpty(chatType)) {
                filter.ChatType = (ChatType) Enum.Parse(
                    typeof(ChatType),
                    chatType
                );
            }
            filter.ChatID = (string) f_UserConfig[prefix + "ChatID"];
            var msgType = (string) f_UserConfig[prefix + "MessageType"];
            if (!String.IsNullOrEmpty(msgType)) {
                filter.MessageType = (MessageType) Enum.Parse(
                    typeof(MessageType),
                    msgType
                );
            }
            filter.MessagePattern = (string) f_UserConfig[prefix + "MessagePattern"];
            return filter;
        }