Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Usings
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using agsXMPP;
- using agsXMPP.protocol.Base;
- using agsXMPP.protocol.client;
- #endregion
- namespace WebtvImplementatie.BU.FrontEnd
- {
- public class GTalk
- {
- private readonly Chat _chat;
- private readonly Gebruiker _gebruiker;
- public bool EersteKeer = true;
- public GTalk()
- {
- _gebruiker = new Gebruiker();
- _chat = new Chat(_gebruiker);
- }
- public XmppClientConnection Xmpp
- {
- get { return _gebruiker.Xmpp; }
- }
- public List<Contact> Contacten
- {
- get { return _gebruiker.Contacten; }
- }
- public bool LogIn(string gebruiker, string wachtwoord)
- {
- return _gebruiker.LogIn(gebruiker, wachtwoord);
- }
- public void LogUit()
- {
- _gebruiker.LogUit();
- }
- public void VerstuurBericht(string chatContact, string bericht)
- {
- _chat.VerstuurBericht(chatContact, bericht);
- }
- public List<Bericht> HaalBerichtenOp(string chatContact)
- {
- return _gebruiker.HaalBerichtenOp(chatContact);
- }
- public List<Contact> HaalGebruikersOp()
- {
- return _gebruiker.HaalContactenOp();
- }
- public void VoegBerichtToe(string chatContact, string bericht)
- {
- _gebruiker.VoegBerichtToe(chatContact, bericht);
- }
- public void WijzigContactStatus(string chatContact, ShowType statusType)
- {
- _gebruiker.WijzigContactStatus(chatContact, statusType);
- }
- public void WijzigContactNaam(string nieuweNaam)
- {
- _chat.WijzigContactNaam(nieuweNaam);
- }
- #region Nested type: Bericht
- public class Bericht
- {
- public Bericht(string verstuurder, string bericht, DateTime tijd)
- {
- Verstuurder = verstuurder;
- BerichtInhoud = bericht;
- Tijd = tijd;
- }
- public string Verstuurder { get; private set; }
- public string BerichtInhoud { get; private set; }
- public DateTime Tijd { get; private set; }
- }
- #endregion
- #region Nested type: Chat
- private class Chat
- {
- private readonly Gebruiker _gebruiker;
- public Chat(Gebruiker gebruiker)
- {
- _gebruiker = gebruiker;
- }
- private string ContactNaam { get; set; }
- public void VerstuurBericht(string chatContact, string bericht)
- {
- _gebruiker.Xmpp.Send(new Message(chatContact, MessageType.chat, bericht));
- }
- public void WijzigContactNaam(string nieuweNaam)
- {
- ContactNaam = nieuweNaam;
- }
- }
- #endregion
- #region Nested type: Contact
- public class Contact
- {
- private readonly List<Bericht> _berichten;
- private readonly string _contactNaam;
- public Contact(string contactNaam)
- {
- _contactNaam = contactNaam;
- ContactStatus = " - Offline";
- _berichten = new List<Bericht>();
- }
- public string ContactNaam
- {
- get { return _contactNaam; }
- }
- public string ContactStatus { get; set; }
- public IEnumerable<Bericht> Berichten
- {
- get { return _berichten; }
- }
- public void VoegBerichtToeAanLijst(Bericht bericht)
- {
- _berichten.Add(bericht);
- }
- public void LijstLegen()
- {
- _berichten.Clear();
- }
- }
- #endregion
- #region Nested type: Gebruiker
- private class Gebruiker
- {
- private readonly List<Contact> _contacten;
- private readonly Presence _status;
- private readonly XmppClientConnection _xmpp;
- public Gebruiker()
- {
- _xmpp = new XmppClientConnection();
- _status = new Presence();
- _contacten = new List<Contact>();
- WijzigServer();
- BindAanEvents();
- }
- public XmppClientConnection Xmpp
- {
- get { return _xmpp; }
- }
- public List<Contact> Contacten
- {
- get { return _contacten; }
- }
- private void WijzigServer()
- {
- _xmpp.Server = "gmail.com";
- _xmpp.ConnectServer = "talk.google.com";
- }
- public bool LogIn(string gebruiker, string wachtwoord)
- {
- _xmpp.Username = gebruiker;
- _xmpp.Password = wachtwoord;
- _xmpp.Open();
- Thread.Sleep(2000);
- return _xmpp.Authenticated;
- }
- public void LogUit()
- {
- _xmpp.Close();
- }
- private void BindAanEvents()
- {
- _xmpp.OnRosterItem += xmpp_OnRosterItem;
- }
- private void VoegContactToeAanLijst(string chatContact)
- {
- _contacten.Add(new Contact(chatContact));
- }
- public List<Contact> HaalContactenOp()
- {
- return _contacten;
- }
- public void WijzigContactStatus(string chatContact, ShowType statusType)
- {
- foreach (Contact c in _contacten)
- {
- if (chatContact.ToLower() == c.ContactNaam.ToLower())
- {
- switch (statusType)
- {
- case ShowType.NONE:
- c.ContactStatus = _status.Type == PresenceType.available ? " - Online " : " - Offline";
- break;
- case ShowType.dnd:
- c.ContactStatus = " - Bezig ";
- break;
- case ShowType.away:
- c.ContactStatus = " - Afwezig ";
- break;
- case ShowType.xa:
- c.ContactStatus = " - Afwezig ";
- break;
- default:
- c.ContactStatus = " - Offline";
- break;
- }
- }
- }
- }
- public void VoegBerichtToe(string chatContact, string bericht)
- {
- foreach (Contact c in _contacten)
- {
- if (c.ContactNaam.ToLower() == chatContact.ToLower())
- {
- c.VoegBerichtToeAanLijst(new Bericht(chatContact, bericht, DateTime.Now));
- }
- }
- }
- public List<Bericht> HaalBerichtenOp(string chatContact)
- {
- var tempList = new List<Bericht>();
- foreach (Contact c in _contacten)
- {
- if (chatContact == c.ContactNaam)
- {
- tempList.AddRange(c.Berichten);
- c.LijstLegen();
- }
- }
- return tempList;
- }
- private void xmpp_OnRosterItem(object sender, RosterItem item)
- {
- VoegContactToeAanLijst(item.Jid.Bare);
- }
- }
- #endregion
- }
- }
Add Comment
Please, Sign In to add comment