Exemple #1
0
        public void ElementsTest()
        {
            var e1 = new Message()
            {
                From    = new Jid("from@s/R"),
                To      = new Jid("to@s/R"),
                Type    = MessageType.headline,
                Body    = "body",
                Subject = "subject",
            };
            var e2 = new Message()
            {
                From    = new Jid("from@s/R"),
                To      = new Jid("to@s/R"),
                Type    = MessageType.headline,
                Body    = "body",
                Subject = "subject",
            };
            var key = "key";

            storage.SaveElement(e1.To, key + "|1", e1);
            storage.SaveElement(e2.To, key + "|2", e2);

            var fromdb = storage.GetElements(Jid.Empty, key);

            CollectionAssert.IsEmpty(fromdb);

            fromdb = storage.GetElements(e1.To, key + "%");
            Assert.AreEqual(2, fromdb.Count());
            Assert.AreEqual(e1.ToString(), fromdb.ElementAt(0).ToString());
            Assert.AreEqual(e2.ToString(), fromdb.ElementAt(1).ToString());

            var frome = storage.GetElement(e1.To, key + "|1");

            Assert.AreEqual(e1.ToString(), frome.ToString());
            frome = storage.GetElement(e2.To, key + "|2");
            Assert.AreEqual(e2.ToString(), frome.ToString());

            fromdb = storage.GetElements(e1.To, key + "|1");
            Assert.AreEqual(1, fromdb.Count());
            Assert.AreEqual(e1.ToString(), fromdb.ElementAt(0).ToString());

            storage.RemoveElements(e1.To, key + "|1");

            fromdb = storage.GetElements(e1.To, key + "|1");
            CollectionAssert.IsEmpty(fromdb);

            fromdb = storage.GetElements(e1.To, "%");
            Assert.AreEqual(1, fromdb.Count());
            Assert.AreEqual(e2.ToString(), fromdb.ElementAt(0).ToString());

            storage.RemoveElements(e1.To, "%");

            fromdb = storage.GetElements(e1.To, key);
            CollectionAssert.IsEmpty(fromdb);
        }
Exemple #2
0
 public void SetVCard(string username, Vcard vcard)
 {
     CheckUsername(username);
     if (vcard == null)
     {
         elements.RemoveElements(new Jid(username), "vcard");
     }
     else
     {
         elements.SaveElement(new Jid(username), "vcard", vcard);
     }
 }
Exemple #3
0
        public static void SaveOffline(this IXmppElementStorage storage, Jid jid, Element element)
        {
            var id = element.GetAttribute("id");

            if (string.IsNullOrEmpty(id))
            {
                id = Guid.NewGuid().ToString("N");
            }

            var message = element as Message;

            if (message != null)
            {
                message.XDelay = new Delay {
                    Stamp = DateTime.UtcNow,
                };
            }

            storage.SaveElement(jid, "offline|" + id, element);
        }