Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Page:  1  2  next
Avatar
acdelemos #1
Member since Feb 2006 · 21 posts · Location: Brazil
Group memberships: Members
Show profile · Link to this post
Subject: How to save vcard data
Hi.

I need save vcard data, how to.

Thanxs.
Avatar
Alex #2
Member since Feb 2003 · 4447 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Here is a small smaple how to set your vcard with only a Nickname:

  1. VcardIq viq = new VcardIq(IqType.set, new Jid(XmppCon.Server));
  2. viq.Vcard.Nickname = "Alex";
  3. XmppCon.Send(viq);

normally you should request your own vcard first, edit it and send it back to the server.

Alex
Avatar
yeawsing #3
Member since Jul 2006 · 33 posts · Location: South Korea
Group memberships: Members
Show profile · Link to this post
Hi, I have did something on Publish VCard to server and store all data into XML file.  When we load the form it will check wheather it's the same JID or not.  If not the same it will retrive new data from the server.  So we don't need to retrieve over again if we didn't change it.
I have created two clases which is UserSettings.cs for handling XML and IOUtils.cs for handling IO.  I also have created a new form call frmPublishVCard.

What is missing in my Publish VCard are the Birthday and Picture.  Hopefully someone can help me out with this.  Here is my frmPublishVCard.cs code.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Drawing.Imaging;
  9.  
  10. using MiniClient.DataAccess;
  11. using agsXMPP;
  12. using agsXMPP.protocol;
  13. using agsXMPP.protocol.client;
  14. using agsXMPP.protocol.iq.vcard;
  15.  
  16. namespace MiniClient
  17. {
  18.     public partial class frmPublishVCard : Form
  19.     {
  20.         private XmppClientConnection _connection;
  21.         private bool hasChanged;
  22.         string packetId;
  23.  
  24.         public bool HasChanged
  25.         {
  26.             get { return hasChanged; }
  27.             set { hasChanged = value; }
  28.         }
  29.  
  30.         public frmPublishVCard(XmppClientConnection con)
  31.         {
  32.             InitializeComponent();
  33.             _connection = con;
  34.         }
  35.  
  36.         private void btnPrefOk_Click(object sender, EventArgs e)
  37.         {
  38.             this.Apply();
  39.             this.Close();
  40.         }
  41.  
  42.         private void btnPrefCancel_Click(object sender, EventArgs e)
  43.         {
  44.             this.Close();
  45.         }
  46.  
  47.         private void btnPrefApply_Click(object sender, EventArgs e)
  48.         {
  49.             this.Apply();
  50.             this.btnPrefApply.Enabled = false;
  51.         }
  52.  
  53.         private void Apply()
  54.         {
  55.             BeginInvoke(new ObjectHandler(PublishVcard), new object[] { this });
  56.             this.DialogResult = DialogResult.OK;
  57.         }
  58.  
  59.         private void frmPublishVCard_Shown(object sender, EventArgs e)
  60.         {
  61.             this.hasChanged = false;
  62.         }
  63.  
  64.         private void frmPublishVCard_KeyDown(object sender, KeyEventArgs e)
  65.         {
  66.             if (e.KeyCode == Keys.Escape)
  67.             {
  68.                 this.Close();
  69.             }
  70.             else
  71.                 if (e.KeyCode == Keys.Enter)
  72.                 {
  73.                     this.Apply();
  74.                     this.Close();
  75.                 }
  76.         }
  77.  
  78.         private void frmPublishVCard_FormClosing(object sender, FormClosingEventArgs e)
  79.         {
  80.             //Owner.RemoveOwnedForm(this);
  81.         }
  82.  
  83.         # region Personal Apply Has Changed Property
  84.  
  85.         private void personalTextBox_NickName_TextChanged(object sender, EventArgs e)
  86.         {
  87.             this.btnPrefApply.Enabled = true;
  88.             this.hasChanged = true;
  89.         }
  90.  
  91.         private void personalTextBoxFullName_TextChanged(object sender, EventArgs e)
  92.         {
  93.             this.btnPrefApply.Enabled = true;
  94.             this.hasChanged = true;
  95.         }
  96.  
  97.         private void personalTextBoxBirthYYYY_TextChanged(object sender, EventArgs e)
  98.         {
  99.             this.btnPrefApply.Enabled = true;
  100.             this.hasChanged = true;
  101.         }
  102.  
  103.         private void personalTextBoxBirthMM_TextChanged(object sender, EventArgs e)
  104.         {
  105.             this.btnPrefApply.Enabled = true;
  106.             this.hasChanged = true;
  107.         }
  108.  
  109.         private void personalTextBoxBirthDD_TextChanged(object sender, EventArgs e)
  110.         {
  111.             this.btnPrefApply.Enabled = true;
  112.             this.hasChanged = true;
  113.         }
  114.  
  115.         private void personalTextBoxFamilyName_TextChanged(object sender, EventArgs e)
  116.         {
  117.             this.btnPrefApply.Enabled = true;
  118.             this.hasChanged = true;
  119.         }
  120.  
  121.         private void personalTextBoxGivenName_TextChanged(object sender, EventArgs e)
  122.         {
  123.             this.btnPrefApply.Enabled = true;
  124.             this.hasChanged = true;
  125.         }
  126.  
  127.         private void personalTextBoxMiddleName_TextChanged(object sender, EventArgs e)
  128.         {
  129.             this.btnPrefApply.Enabled = true;
  130.             this.hasChanged = true;
  131.         }
  132.  
  133.         private void personalBtnBrowsePic_Click(object sender, EventArgs e)
  134.         {
  135.             this.btnPrefApply.Enabled = true;
  136.             this.hasChanged = true;
  137.         }
  138.  
  139.         private void personalBtnRemovePic_Click(object sender, EventArgs e)
  140.         {
  141.             this.btnPrefApply.Enabled = true;
  142.             this.hasChanged = true;
  143.         }
  144.  
  145.         private void personalTextBoxAddr1_TextChanged(object sender, EventArgs e)
  146.         {
  147.             this.btnPrefApply.Enabled = true;
  148.             this.hasChanged = true;
  149.         }
  150.  
  151.         private void personalTextBoxAddr2_TextChanged(object sender, EventArgs e)
  152.         {
  153.             this.btnPrefApply.Enabled = true;
  154.             this.hasChanged = true;
  155.         }
  156.  
  157.         private void personalTextBoxCity_TextChanged(object sender, EventArgs e)
  158.         {
  159.             this.btnPrefApply.Enabled = true;
  160.             this.hasChanged = true;
  161.         }
  162.  
  163.         private void personalTextBoxState_TextChanged(object sender, EventArgs e)
  164.         {
  165.             this.btnPrefApply.Enabled = true;
  166.             this.hasChanged = true;
  167.         }
  168.  
  169.         private void personalTextBoxZip_TextChanged(object sender, EventArgs e)
  170.         {
  171.             this.btnPrefApply.Enabled = true;
  172.             this.hasChanged = true;
  173.         }
  174.  
  175.         private void personalTextBoxCountry_TextChanged(object sender, EventArgs e)
  176.         {
  177.             this.btnPrefApply.Enabled = true;
  178.             this.hasChanged = true;
  179.         }
  180.  
  181.         private void personalTextBoxHomePage_TextChanged(object sender, EventArgs e)
  182.         {
  183.             this.btnPrefApply.Enabled = true;
  184.             this.hasChanged = true;
  185.         }
  186.  
  187.         private void personalTextBoxEmail_TextChanged(object sender, EventArgs e)
  188.         {
  189.             this.btnPrefApply.Enabled = true;
  190.             this.hasChanged = true;
  191.         }
  192.  
  193.         private void personalTextBoxVoiceTel_TextChanged(object sender, EventArgs e)
  194.         {
  195.             this.btnPrefApply.Enabled = true;
  196.             this.hasChanged = true;
  197.         }
  198.  
  199.         private void personalTextBoxFaxTel_TextChanged(object sender, EventArgs e)
  200.         {
  201.             this.btnPrefApply.Enabled = true;
  202.             this.hasChanged = true;
  203.         }
  204.  
  205.         private void personalTextBoxMobileTel_TextChanged(object sender, EventArgs e)
  206.         {
  207.             this.btnPrefApply.Enabled = true;
  208.             this.hasChanged = true;
  209.         }
  210.  
  211.         # endregion
  212.  
  213.         # region Work Apply Has Changed Property
  214.  
  215.         private void workTextBoxCompanyName_TextChanged(object sender, EventArgs e)
  216.         {
  217.             this.btnPrefApply.Enabled = true;
  218.             this.hasChanged = true;
  219.         }
  220.  
  221.         private void workTextBoxOrgUnit_TextChanged(object sender, EventArgs e)
  222.         {
  223.             this.btnPrefApply.Enabled = true;
  224.             this.hasChanged = true;
  225.         }
  226.  
  227.         private void workTextBoxTitle_TextChanged(object sender, EventArgs e)
  228.         {
  229.             this.btnPrefApply.Enabled = true;
  230.             this.hasChanged = true;
  231.         }
  232.  
  233.         private void workTextBoxVoiceTel_TextChanged(object sender, EventArgs e)
  234.         {
  235.             this.btnPrefApply.Enabled = true;
  236.             this.hasChanged = true;
  237.         }
  238.  
  239.         private void workTextBoxFaxTel_TextChanged(object sender, EventArgs e)
  240.         {
  241.             this.btnPrefApply.Enabled = true;
  242.             this.hasChanged = true;
  243.         }
  244.  
  245.         private void workTextBoxMobileTel_TextChanged(object sender, EventArgs e)
  246.         {
  247.             this.btnPrefApply.Enabled = true;
  248.             this.hasChanged = true;
  249.         }
  250.  
  251.         private void workTextBoxAddr1_TextChanged(object sender, EventArgs e)
  252.         {
  253.             this.btnPrefApply.Enabled = true;
  254.             this.hasChanged = true;
  255.         }
  256.  
  257.         private void workTextBoxAddr2_TextChanged(object sender, EventArgs e)
  258.         {
  259.             this.btnPrefApply.Enabled = true;
  260.             this.hasChanged = true;
  261.         }
  262.  
  263.         private void workTextBoxCity_TextChanged(object sender, EventArgs e)
  264.         {
  265.             this.btnPrefApply.Enabled = true;
  266.             this.hasChanged = true;
  267.         }
  268.  
  269.         private void workTextBoxState_TextChanged(object sender, EventArgs e)
  270.         {
  271.             this.btnPrefApply.Enabled = true;
  272.             this.hasChanged = true;
  273.         }
  274.  
  275.         private void workTextBoxZip_TextChanged(object sender, EventArgs e)
  276.         {
  277.             this.btnPrefApply.Enabled = true;
  278.             this.hasChanged = true;
  279.         }
  280.  
  281.         private void workTextBoxCountry_TextChanged(object sender, EventArgs e)
  282.         {
  283.             this.btnPrefApply.Enabled = true;
  284.             this.hasChanged = true;
  285.         }
  286.  
  287.         private void personalTextBoxAbout_TextChanged(object sender, EventArgs e)
  288.         {
  289.             this.btnPrefApply.Enabled = true;
  290.             this.hasChanged = true;
  291.         }
  292.  
  293.         #endregion

continue ...
I am still learning..., hope I can contribute back.
YS
Avatar
yeawsing #4
Member since Jul 2006 · 33 posts · Location: South Korea
Group memberships: Members
Show profile · Link to this post
  1.         private void frmPublishVCard_Load(object sender, EventArgs e)
  2.         {
  3.             String isVCard = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.HAS_VCARD);
  4.             String vcardID = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.VCARD_ID);
  5.             if (isVCard.Equals("True") && vcardID.Equals(_connection.MyJID.ToString()))
  6.             {
  7.                 PSNickName = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALNICKNAME);
  8.                 PSFullName = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALFULLNAME);
  9.                 PSBirthDay = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALBIRTHDAY);
  10.                 PSFamilyName = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALFAMILYNAME);
  11.                 PSGivenName = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALGIVENNAME);
  12.                 PSMiddleName = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALMIDDLENAME);
  13.                 PSAddr1 = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALADDR1);
  14.                 PSAddr2 = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALADDR2);
  15.                 PSCity = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALCITY);
  16.                 PSState = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALSTATE);
  17.                 PSZip = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALZIP);
  18.                 PSCountry = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALCOUNTRY);
  19.                 PSHomePage = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALHOMEPAGE);
  20.                 PSEmail = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALEMAIL);
  21.                 PSVoiceTel = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALVOICETEL);
  22.                 PSFaxTel = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALFAXTEL);
  23.                 PSMobileTel = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALMOBILETEL);
  24.  
  25.                 WKCompanyName = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKCOMPANYNAME);
  26.                 WKOrgUnit = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKORGUNIT);
  27.                 WKTitle = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKTITLE);
  28.                 WKVoiceTel = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKVOICETEL);
  29.                 WKFaxTel = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKFAXTEL);
  30.                 WKMobileTel = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKMOBILETEL);
  31.                 WKAddr1 = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKADDR1);
  32.                 WKAddr2 = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKADDR2);
  33.                 WKCity = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKCITY);
  34.                 WKState = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKSTATE);
  35.                 WKZip = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKZIP);
  36.                 WKCountry = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKCOUNTRY);
  37.  
  38.                 PSAbout = UserSettings.getAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALABOUT);
  39.             }
  40.             else // Get VCard info from Server
  41.             {
  42.                 VcardIq viq = new VcardIq(IqType.get);
  43.                 packetId = viq.Id;
  44.                 viq.From = _connection.MyJID;
  45.                 _connection.IqGrabber.SendIq(viq, new IqCB(VcardResult), null);
  46.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.HAS_VCARD, "True");
  47.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.VCARD_ID, viq.From.ToString());
  48.             }
  49.         }

continue...
I am still learning..., hope I can contribute back.
YS
Avatar
yeawsing #5
Member since Jul 2006 · 33 posts · Location: South Korea
Group memberships: Members
Show profile · Link to this post
This is the part I am getting the VCard Data

  1.         private void VcardResult(object sender, IQ iq, object data)
  2.         {
  3.             if (InvokeRequired)
  4.             {
  5.                 // Windows Forms are not Thread Safe, we need to invoke this :(
  6.                 // We're not in the UI thread, so we need to call BeginInvoke              
  7.                 BeginInvoke(new IqCB(VcardResult), new object[] { sender, iq, data });
  8.                 return;
  9.             }
  10.  
  11.             if (iq.Type == IqType.result)
  12.             {
  13.                 Vcard vcard = iq.Vcard;
  14.                 if (vcard != null)
  15.                 {
  16.                     PSNickName = vcard.Nickname;
  17.                     PSFullName = vcard.Fullname;
  18.                     if (vcard.Birthday != DateTime.MinValue)
  19.                     {
  20.                         PSBirthDay = vcard.Birthday.ToShortDateString();
  21.                     }
  22.  
  23.                     Name name = vcard.Name;
  24.                     if (name != null)
  25.                     {
  26.                         PSFamilyName = name.Family;
  27.                         PSGivenName = name.Given;
  28.                         PSMiddleName = name.Middle;
  29.                     }
  30.  
  31.                     Address personalAddress = vcard.GetAddress(AddressLocation.HOME);
  32.                     if (personalAddress == null)
  33.                     {
  34.                         personalAddress = vcard.GetAddress(AddressLocation.NONE);
  35.                     }
  36.                     if (personalAddress != null)
  37.                     {
  38.                         PSAddr1 = personalAddress.Street;
  39.                         PSAddr2 = personalAddress.ExtraAddress;
  40.                         PSCity = personalAddress.Locality;
  41.                         PSState = personalAddress.Region;
  42.                         PSZip = personalAddress.PostalCode;
  43.                         PSCountry = personalAddress.Country;
  44.                     }
  45.  
  46.                     personalTextBoxHomePage.Text = vcard.Url;
  47.  
  48.                     Email mail = vcard.GetEmailAddress(EmailType.HOME);
  49.                     if (mail == null)
  50.                     {
  51.                         mail = vcard.GetEmailAddress(EmailType.NONE);
  52.                     }
  53.                     if (mail != null)
  54.                     {
  55.                         PSEmail = mail.UserId;
  56.                     }
  57.  
  58.                     Telephone personalTelephoneVoice = vcard.GetTelephoneNumber(TelephoneType.VOICE, TelephoneLocation.HOME);
  59.                     if (personalTelephoneVoice == null)
  60.                         personalTelephoneVoice = vcard.GetTelephoneNumber(TelephoneType.VOICE, TelephoneLocation.NONE);
  61.                     if (personalTelephoneVoice != null)
  62.                         PSVoiceTel = vcard.GetTelephoneNumber(TelephoneType.VOICE, TelephoneLocation.HOME).Number;
  63.  
  64.                     Telephone personalTelephoneFax = vcard.GetTelephoneNumber(TelephoneType.FAX, TelephoneLocation.HOME);
  65.                     if (personalTelephoneFax == null)
  66.                         personalTelephoneFax = vcard.GetTelephoneNumber(TelephoneType.FAX, TelephoneLocation.NONE);
  67.                     if (personalTelephoneFax != null)
  68.                         PSFaxTel = vcard.GetTelephoneNumber(TelephoneType.FAX, TelephoneLocation.HOME).Number;
  69.  
  70.                     Telephone personalTelephoneCell = vcard.GetTelephoneNumber(TelephoneType.CELL, TelephoneLocation.HOME);
  71.                     if (personalTelephoneCell == null)
  72.                         personalTelephoneCell = vcard.GetTelephoneNumber(TelephoneType.CELL, TelephoneLocation.NONE);
  73.                     if (personalTelephoneCell != null)
  74.                         PSMobileTel = vcard.GetTelephoneNumber(TelephoneType.CELL, TelephoneLocation.HOME).Number;
  75.  
  76.                     Organization workOrganization = vcard.Organization;
  77.                     if (workOrganization != null)
  78.                     {
  79.                         WKCompanyName = workOrganization.Name;
  80.                         WKOrgUnit = workOrganization.Unit;
  81.                     }
  82.  
  83.                     workTextBoxTitle.Text = vcard.Title;
  84.  
  85.                     Telephone workTelephoneVoice = vcard.GetTelephoneNumber(TelephoneType.VOICE, TelephoneLocation.WORK);
  86.                     if (workTelephoneVoice == null)
  87.                         workTelephoneVoice = vcard.GetTelephoneNumber(TelephoneType.VOICE, TelephoneLocation.NONE);
  88.                     if (workTelephoneVoice != null)
  89.                         WKVoiceTel = vcard.GetTelephoneNumber(TelephoneType.VOICE, TelephoneLocation.WORK).Number;
  90.  
  91.                     Telephone workTelephoneFax = vcard.GetTelephoneNumber(TelephoneType.FAX, TelephoneLocation.WORK);
  92.                     if (workTelephoneFax == null)
  93.                         workTelephoneFax = vcard.GetTelephoneNumber(TelephoneType.FAX, TelephoneLocation.NONE);
  94.                     if (workTelephoneFax != null)
  95.                         WKFaxTel = vcard.GetTelephoneNumber(TelephoneType.FAX, TelephoneLocation.WORK).Number;
  96.  
  97.                     Telephone workTelephoneCell = vcard.GetTelephoneNumber(TelephoneType.CELL, TelephoneLocation.WORK);
  98.                     if (workTelephoneCell == null)
  99.                         workTelephoneCell = vcard.GetTelephoneNumber(TelephoneType.CELL, TelephoneLocation.NONE);
  100.                     if (workTelephoneCell != null)
  101.                         WKMobileTel = vcard.GetTelephoneNumber(TelephoneType.CELL, TelephoneLocation.WORK).Number;
  102.  
  103.                     Address workAddress = vcard.GetAddress(AddressLocation.WORK);
  104.                     if (workAddress != null)
  105.                     {
  106.                         WKAddr1 = workAddress.Street;
  107.                         WKAddr2 = workAddress.ExtraAddress;
  108.                         WKCity = workAddress.Locality;
  109.                         WKState = workAddress.Region;
  110.                         WKZip = workAddress.PostalCode;
  111.                         WKCountry = workAddress.Country;
  112.                     }
  113.  
  114.                     PSAbout = vcard.Description;
  115.  
  116.                     Photo photo = vcard.Photo;
  117.                     if (photo != null)
  118.                     {
  119.                         personalPic.Image = vcard.Photo.Image;
  120.                     }
  121.                 }
  122.             }
  123.         }
I am still learning..., hope I can contribute back.
YS
Avatar
yeawsing #6
Member since Jul 2006 · 33 posts · Location: South Korea
Group memberships: Members
Show profile · Link to this post
This the part I am publishing the VCard Data and also storing it into XML file

  1.         private void PublishVcard(object sender)
  2.         {
  3.             bool isVCardChange = false;
  4.  
  5.             VcardIq viq = new VcardIq(IqType.set);
  6.             packetId = viq.Id;
  7.             viq.From = _connection.MyJID;
  8.  
  9. # region Check isVCardChange
  10.  
  11.             if (PSNickName != personalTextBox_NickName.Text)
  12.                 isVCardChange = true;
  13.  
  14.             if (PSFullName != personalTextBoxFullName.Text)
  15.                 isVCardChange = true;
  16.  
  17.             if (PSBirthDay != personalTextBoxBirthYYYY.Text)
  18.                 isVCardChange = true;
  19.             //viq.Vcard.Birthday = personalTextBoxBirthYYYY.Text;
  20.  
  21.             if (PSFamilyName != personalTextBoxFamilyName.Text)
  22.                 isVCardChange = true;
  23.  
  24.             if (PSGivenName != personalTextBoxGivenName.Text)
  25.                 isVCardChange = true;
  26.  
  27.             if (PSMiddleName != personalTextBoxMiddleName.Text)
  28.                 isVCardChange = true;
  29.  
  30.             if (PSAddr1 != personalTextBoxAddr1.Text || PSAddr2 != personalTextBoxAddr2.Text || PSCity != personalTextBoxCity.Text ||
  31.                 PSState != personalTextBoxState.Text || PSZip != personalTextBoxZip.Text || PSCountry != personalTextBoxCountry.Text)
  32.                 isVCardChange = true;
  33.  
  34.             if (PSHomePage != personalTextBoxHomePage.Text)
  35.                 isVCardChange = true;
  36.  
  37.             if (PSEmail != personalTextBoxEmail.Text)
  38.                 isVCardChange = true;
  39.  
  40.             if (PSVoiceTel != personalTextBoxVoiceTel.Text)
  41.                 isVCardChange = true;
  42.  
  43.             if (PSFaxTel != personalTextBoxFaxTel.Text)
  44.                 isVCardChange = true;
  45.  
  46.             if (PSMobileTel != personalTextBoxMobileTel.Text)
  47.                 isVCardChange = true;
  48.  
  49.             if (WKCompanyName != workTextBoxCompanyName.Text)
  50.                 isVCardChange = true;
  51.  
  52.             if (WKOrgUnit != workTextBoxOrgUnit.Text)
  53.                 isVCardChange = true;
  54.  
  55.             if (WKTitle != workTextBoxTitle.Text)
  56.                 isVCardChange = true;
  57.  
  58.             if (WKVoiceTel != workTextBoxVoiceTel.Text)
  59.                 isVCardChange = true;
  60.  
  61.             if (WKFaxTel != workTextBoxFaxTel.Text)
  62.                 isVCardChange = true;
  63.  
  64.             if (WKMobileTel != workTextBoxMobileTel.Text)
  65.                 isVCardChange = true;
  66.  
  67.             if (WKAddr1 != workTextBoxAddr1.Text || WKAddr2 != workTextBoxAddr2.Text || WKCity != workTextBoxCity.Text
  68.                 || WKState != workTextBoxState.Text || WKZip != workTextBoxZip.Text || WKCountry != workTextBoxCountry.Text)
  69.                 isVCardChange = true;
  70.  
  71.             if (PSAbout != personalTextBoxAbout.Text)
  72.                 isVCardChange = true;
  73.  
  74. # endregion
  75.  
  76.             if (isVCardChange)
  77.             {
  78.                 viq.Vcard.Nickname = personalTextBox_NickName.Text;
  79.                 viq.Vcard.Fullname = personalTextBoxFullName.Text;
  80.  
  81.                 Name name = new Name(personalTextBoxFamilyName.Text, personalTextBoxGivenName.Text, personalTextBoxMiddleName.Text);
  82.                 viq.Vcard.Name = name;
  83.  
  84.                 Address psaddr = new Address(AddressLocation.HOME, personalTextBoxAddr1.Text, personalTextBoxAddr2.Text,
  85.                                            personalTextBoxCity.Text, personalTextBoxState.Text, personalTextBoxZip.Text,
  86.                                            personalTextBoxCountry.Text, false);
  87.                 viq.Vcard.AddAddress(psaddr);
  88.  
  89.                 viq.Vcard.Url = personalTextBoxHomePage.Text;
  90.  
  91.                 Email email = new Email(EmailType.HOME, personalTextBoxEmail.Text, false);
  92.                 viq.Vcard.AddEmailAddress(email);
  93.  
  94.                 Telephone pstelvoice = new Telephone(TelephoneLocation.HOME, TelephoneType.VOICE, personalTextBoxVoiceTel.Text);
  95.                 viq.Vcard.AddTelephoneNumber(pstelvoice);
  96.  
  97.                 Telephone pstelfax = new Telephone(TelephoneLocation.HOME, TelephoneType.FAX, personalTextBoxFaxTel.Text);
  98.                 viq.Vcard.AddTelephoneNumber(pstelfax);
  99.  
  100.                 Telephone pstelcell = new Telephone(TelephoneLocation.HOME, TelephoneType.CELL, personalTextBoxMobileTel.Text);
  101.                 viq.Vcard.AddTelephoneNumber(pstelcell);
  102.  
  103.                 Organization myOrg = new Organization(workTextBoxCompanyName.Text, workTextBoxOrgUnit.Text);
  104.                 viq.Vcard.Organization = myOrg;
  105.  
  106.                 viq.Vcard.Title = workTextBoxTitle.Text;
  107.  
  108.                 Telephone wktelvoice = new Telephone(TelephoneLocation.WORK, TelephoneType.VOICE, workTextBoxVoiceTel.Text);
  109.                 viq.Vcard.AddTelephoneNumber(wktelvoice);
  110.  
  111.                 Telephone wktelfax = new Telephone(TelephoneLocation.WORK, TelephoneType.FAX, workTextBoxFaxTel.Text);
  112.                 viq.Vcard.AddTelephoneNumber(wktelfax);
  113.  
  114.                 Telephone wktelcell = new Telephone(TelephoneLocation.WORK, TelephoneType.CELL, workTextBoxMobileTel.Text);
  115.                 viq.Vcard.AddTelephoneNumber(wktelcell);
  116.  
  117.                 Address wkaddr = new Address(AddressLocation.WORK, workTextBoxAddr1.Text, workTextBoxAddr2.Text, workTextBoxCity.Text,
  118.                                            workTextBoxState.Text, workTextBoxZip.Text, workTextBoxCountry.Text, false);
  119.                 viq.Vcard.AddAddress(wkaddr);
  120.  
  121.                 viq.Vcard.Description = personalTextBoxAbout.Text;
  122.  
  123.                 _connection.Send(viq);
  124.  
  125. # region Writing VCard Info into XML file
  126.  
  127.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALNICKNAME, personalTextBox_NickName.Text);
  128.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALFULLNAME, personalTextBoxFullName.Text);
  129.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALFAMILYNAME, personalTextBoxFamilyName.Text);
  130.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALGIVENNAME, personalTextBoxGivenName.Text);
  131.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALMIDDLENAME, personalTextBoxMiddleName.Text);
  132.  
  133.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALADDR1, personalTextBoxAddr1.Text);
  134.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALADDR2, personalTextBoxAddr2.Text);
  135.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALCITY, personalTextBoxCity.Text);
  136.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALSTATE, personalTextBoxState.Text);
  137.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALZIP, personalTextBoxZip.Text);
  138.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALCOUNTRY, personalTextBoxCountry.Text);
  139.  
  140.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALHOMEPAGE, personalTextBoxHomePage.Text);
  141.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALEMAIL, personalTextBoxEmail.Text);
  142.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALVOICETEL, personalTextBoxVoiceTel.Text);
  143.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALFAXTEL, personalTextBoxFaxTel.Text);
  144.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALMOBILETEL, personalTextBoxMobileTel.Text);
  145.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKCOMPANYNAME, workTextBoxCompanyName.Text);
  146.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKORGUNIT, workTextBoxOrgUnit.Text);
  147.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKTITLE, workTextBoxTitle.Text);
  148.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKVOICETEL, workTextBoxVoiceTel.Text);
  149.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKFAXTEL, workTextBoxFaxTel.Text);
  150.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKMOBILETEL, workTextBoxMobileTel.Text);
  151.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKADDR1, workTextBoxAddr1.Text);
  152.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKADDR2, workTextBoxAddr2.Text);
  153.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKCITY, workTextBoxCity.Text);
  154.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKSTATE, workTextBoxState.Text);
  155.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKZIP, workTextBoxZip.Text);
  156.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.WORKCOUNTRY, workTextBoxCountry.Text);
  157.                 UserSettings.setAttributes(UserSettings.VCARD_SECTION, UserSettings.PERSONALABOUT, personalTextBoxAbout.Text);
  158.  
  159. #endregion
  160.             }
  161.         }
I am still learning..., hope I can contribute back.
YS
Avatar
yeawsing #7
Member since Jul 2006 · 33 posts · Location: South Korea
Group memberships: Members
Show profile · Link to this post
At the begining I thought, when one of the field has change I just need to update that VCard field and publish it.  But somehow it was wrong.  So whenever I need to update one field or more, I need to send the whole lot again to the server :(

I haven't post the UserSetting.cs and IOUtils.cs.  If anyone need it, I will post it here too.

Also please correct me, if I did something wrong here.  I am still learning...

YS
I am still learning..., hope I can contribute back.
YS
Avatar
Jabberer #8
Member since Feb 2006 · 249 posts
Group memberships: Members
Show profile · Link to this post
Hello,

yes you have to send always the complete VCard to the server. I would not save the vCard in the user settings. You can request it from the server when you display it. If your user is also using other xmpp clients which update the vcard then it can be different from your user settings.

birthday and photo:

  1. vcard.Birthday = dtBirthday.Value; // dtBirtday is a dateTime picker here
  2. vcard.Photo = new Photo(picPhoto.Image, imageFormat);

the code we use to Load the picture and get the ImageFormat:
  1. private void SetPicture(string filename)
  2. {
  3.     try
  4.     {
  5.         Image img = Image.FromFile(filename);
  6.        
  7.         picPhoto.Load(filename);
  8.         hasPhoto = true;
  9.         string ext = Path.GetExtension(filename);
  10.         switch (ext.ToLower())
  11.         {
  12.             case ".png":
  13.                 imageFormat = ImageFormat.Png;
  14.                 break;
  15.             case ".jpg":
  16.             case ".jpeg":
  17.                 imageFormat = ImageFormat.Jpeg;
  18.                 break;                      
  19.             case ".gif":
  20.                 imageFormat = ImageFormat.Gif;
  21.                 break;
  22.  
  23.         }
  24.     }
  25.     catch (Exception ex)
  26.     {
  27.         MessageBox.Show("Unable to load photo");
  28.         hasPhoto = false;
  29.     }
  30. }
Software Developer
AG-Software
Avatar
yeawsing #9
Member since Jul 2006 · 33 posts · Location: South Korea
Group memberships: Members
Show profile · Link to this post
Thanks Jabberer.  You guys response are amazing fast.

Thanks again.  Your forum support are the best and able to solve problem within 1 or 2 day.

YS.
I am still learning..., hope I can contribute back.
YS
Avatar
pisey #10
Member since Sep 2012 · 13 posts
Group memberships: Members
Show profile · Link to this post
Subject: if i use WPF, How Can I select photo
if i use WPF, How Can I select photo
But I use code like this but Error:
 Photo photo = vcard.Photo;
     if (photo.Image!= null)
        {
        
         bitmap.UriSource = new System.Uri(ChangeAvatar.Source.ToString());
         ChangeAvatar.Source = vcard.Photo.Image;
                           
        }
Avatar
Alex #11
Member since Feb 2003 · 4447 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
you have to get the phote as bytes and load a WPF image from the bytes.
You can get the bytes of the photo with the following code:

  1. byte[] pic = Convert.FromBase64String(vcard.Photo.GetTag("BINVAL"));

Alex
Avatar
pisey #12
Member since Sep 2012 · 13 posts
Group memberships: Members
Show profile · Link to this post
Subject: How to Insert Avatar Image use WPF
Thanks you so much for Select Avatar Picture.
But I want to ask you again about How to save Avatar Picture.
In window form i use this code:
if(photo.Image != null)
{
vcard.Photo = new Photo(photo.Image, System.Drawing.Imaging.ImageFormat.Bmp);
}

But In WPF, how can I?
This post was edited on 2012-09-27, 08:03 by pisey.
Avatar
Alex #13
Member since Feb 2003 · 4447 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Instead of GetTag use SetTag, the rest is the same.

Alex
Avatar
pisey #14
Member since Sep 2012 · 13 posts
Group memberships: Members
Show profile · Link to this post
thanks, but I use this code , Error because I can't use


  1. byte[] pic = Convert.FromBase64String(vcard.Photo.SetTag("BINVAL"));
  2. objPhoto = vcard.Photo;
  3. if (ChangeAvatar_vcard.Source != null)
  4. {
  5.     ChangeAvatar_vcard.Source = LoadImage(pic);  
  6. }
  7.  
  8. private static BitmapImage LoadImage(byte[] pic)
  9. {
  10.     if (pic == null || pic.Length == 0) return null;
  11.     var image = new BitmapImage();
  12.     using (var mem = new MemoryStream(pic))
  13.     {
  14.         mem.Position = 0;
  15.         image.BeginInit();
  16.         image.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
  17.         image.CacheOption = BitmapCacheOption.OnLoad;
  18.         image.UriSource = null;
  19.         image.StreamSource = mem;
  20.         image.EndInit();
  21.     }
  22.     image.Freeze();
  23.     return image;
  24. }
This post was edited 3 times, last on 2013-04-16, 17:26 by Alex.
Avatar
Alex #15
Member since Feb 2003 · 4447 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
you have to check first if vcard.Photo is not null. If it is null then you must create a new photo, then you can use it.

  1. if (vcard.Photo == null)
  2.    vcard.Photo = new Photo();

Alex
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Page:  1  2  next
Forum: agsXMPP RSS