public void RemoveRosterItem(string userName, string jid)
        {
            if (IsASCRosterItem(userName, jid))
            {
                throw new JabberForbiddenException();
            }

            try
            {
                lock (syncRoot)
                {
                    if (RosterItems.ContainsKey(userName) && RosterItems[userName].ContainsKey(jid))
                    {
                        ExecuteNonQuery(
                            "delete from Roster where UserName = @userName and Jid = @jid",
                            new[] { "userName", "jid" },
                            new object[] { userName, jid }
                            );
                        RosterItems[userName].Remove(jid);
                    }
                }
            }
            catch (Exception e)
            {
                throw new JabberServiceUnavailableException("Could not remove roster item.", e);
            }
        }
        private void _rosterStore_RosterItemRemoved(ChatUser rosterItem)
        {
            var found = RosterItems.FirstOrDefault(c => c.Id == rosterItem.Id);

            if (found != null)
            {
                RosterItems.Remove(found);
            }
        }
 public List <UserRosterItem> GetRosterItems(string userName)
 {
     try
     {
         lock (syncRoot)
         {
             var items = GetASCRosterItems(userName);
             if (RosterItems.ContainsKey(userName))
             {
                 items.AddRange(RosterItems[userName].Values);
             }
             return(items);
         }
     }
     catch (Exception e)
     {
         throw new JabberServiceUnavailableException("Could not get roster items.", e);
     }
 }
        public UserRosterItem SaveOrUpdateRosterItem(string userName, UserRosterItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (IsASCRosterItem(userName, item.Jid))
            {
                throw new JabberForbiddenException();
            }

            try
            {
                lock (syncRoot)
                {
                    if (string.IsNullOrEmpty(item.Name))
                    {
                        item.Name = item.Jid;
                    }

                    ExecuteNonQuery(
                        "insert or replace into Roster(UserName, Jid, Name, Subscription, Ask, Groups) values (@userName, @jid, @name, @subscription, @ask, @groups)",
                        new[] { "userName", "jid", "name", "subscription", "ask", "groups" },
                        new object[] { userName, item.Jid, item.Name, (Int32)item.Subscribtion, (Int32)item.Ask, item.Groups != null ? item.Groups.ToArray() : null }
                        );
                    if (!RosterItems.ContainsKey(userName))
                    {
                        RosterItems[userName] = new UserRosterItemDic();
                    }
                    RosterItems[userName][item.Jid] = item;

                    return(item);
                }
            }
            catch (Exception e)
            {
                throw new JabberServiceUnavailableException("Could not save or update roster item.", e);
            }
        }
示例#5
0
 public RosterItem FindRosterItemHandle(string strHandle)
 {
     return(RosterItems.FindRosterItemHandle(strHandle));
 }
示例#6
0
 public RosterItem FindRosterItem(JID jid)
 {
     return(RosterItems.FindRosterItem(jid));
 }
 private void _rosterStore_RosterItemAdded(ChatUser rosterItem)
 {
     RosterItems.Add(rosterItem);
 }