Esempio n. 1
0
 public static void ProcessRosterIQSet(string username, IQ iq)
 {
     if (iq.Query.HasChildElements)
     {
         BLL.Users api = new BLL.Users();
         foreach (Node r in iq.Query.ChildNodes)
         {
             Element el = r as Element;
             if (el != null)
             {
                 RosterItem ri = el as RosterItem;
                 if (el.HasAttribute("subscription"))
                 {
                     if (ri.Subscription == SubscriptionType.remove)
                     {
                         api.DeleteFriend(username, ri.Jid.User);
                     }
                 }
                 if (el.HasChildElements)
                 {
                     NodeList    li        = el.ChildNodes;
                     ElementList eli       = ri.GetGroups();
                     string      groupName = null;
                     if (eli.Count > 0)
                     {
                         groupName = eli.Item(0).Value;
                     }
                     if (li.Count > 0)
                     {
                         api.ChangeFriendStatus(username, ri.Jid.User, groupName, null, true);
                     }
                 }
             }
         }
         iq.Type = IqType.get;
         ProcessRosterIQGet(username, iq);
     }
 }
Esempio n. 2
0
        private void onCommandResult(IQ iq)
        {
            Element commandResult = iq.SelectSingleElement("command");

            if (iq.Type == IqType.result && commandResult != null)
            {
                Element note = commandResult.SelectSingleElement("note");
                if (note != null)
                {
                    MessageBox.Show(note.Value, "Command result", MessageBoxButtons.OK,
                                    note.GetAttribute("type") == "error" ? MessageBoxIcon.Exclamation : MessageBoxIcon.Information);
                }
                Element result = commandResult.SelectSingleElement("x", "jabber:x:data");
                if (result != null)
                {
                    clearButtons();
                    clearForm();

                    Element actions = commandResult.SelectSingleElement("actions");
                    if (actions != null)
                    {
                        sessionId = commandResult.GetAttribute("sessionid");
                        string execute = actions.GetAttribute("execute");
                        foreach (Node node in actions.ChildNodes)
                        {
                            if (node.NodeType == NodeType.Element)
                            {
                                addButton(((Element)node).TagName, execute == ((Element)node).TagName);
                            }
                        }
                    }

                    //    addFormInfoLabel(iq.InnerXml, 8);
                    //    addFormInfoLabel("-----------------------------------------------", 8);

                    ListView lv = null;
                    foreach (Node child in result.ChildNodes)
                    {
                        if (child.NodeType != NodeType.Element)
                        {
                            continue;
                        }
                        Element ch = (Element)child;
                        switch (ch.TagName.ToUpper())
                        {
                        case "REPORTED":
                            //clearForm();
                            formY = 500;
                            lv    = new ListView();
                            pnlForm.Controls.Add(lv);
                            lv.Dock = DockStyle.Fill; lv.View = View.Details; lv.FullRowSelect = true;
                            foreach (Element field in ch.SelectElements("field"))
                            {
                                lv.Columns.Add(field.GetAttribute("var"), field.GetAttribute("label"));
                            }
                            break;

                        case "ITEM":
                            if (lv == null)
                            {
                                continue;
                            }
                            var item = new ListViewItem("undefined");
                            foreach (Element field in ch.SelectElements("field"))
                            {
                                if (item.Text == "undefined")
                                {
                                    item.Text = field.GetTag("value");
                                }
                                else
                                {
                                    item.SubItems.Add(field.GetTag("value"));
                                }
                            }
                            lv.Items.Add(item);
                            break;

                        case "TITLE":
                            addFormInfoLabel(ch.Value, FONT_TITLE);
                            break;

                        case "INSTRUCTIONS":
                            addFormInfoLabel(ch.Value, FONT_INSTRUCTIONS);
                            break;

                        case "FIELD":
                            switch (ch.GetAttribute("type"))
                            {
                            case "list-single":
                                ElementList optionList = ch.SelectElements("option");
                                ListItem[]  options    = new ListItem[optionList.Count];
                                for (int i = 0; i < options.Length; i++)
                                {
                                    options[i] = new ListItem(optionList.Item(i).GetAttribute("label"), optionList.Item(i).GetTag("value"));
                                }
                                addFormListSingle(ch.GetAttribute("var"), ch.GetAttribute("label"), options, ch.GetTag("value"));
                                break;

                            case "boolean":
                                addFormBoolean(ch.GetAttribute("var"), ch.GetAttribute("label"), ch.GetTag("value"));
                                break;

                            case "fixed":
                                addFormInfoLabel(ch.GetTag("value"), FONT_INSTRUCTIONS);
                                break;

                            case "text-multi":
                                string text = "";
                                foreach (Element value in ch.SelectElements("value"))
                                {
                                    if (text != "")
                                    {
                                        text += "\r\n";
                                    }
                                    text += value.Value;
                                }
                                addFormText(ch.GetAttribute("var"), ch.GetAttribute("label"), "text-multi", text);
                                break;

                            default:
                                addFormText(ch.GetAttribute("var"), ch.GetAttribute("label"), ch.GetAttribute("type"), ch.GetTag("value"));
                                break;
                            }
                            break;
                        }
                    }
                    if (lv != null)
                    {
                        lv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                    }
                    this.Height = Math.Min(Screen.PrimaryScreen.WorkingArea.Height - 60, formY + 100);
                }
                focusFirstElement();
            }
        }