Exemplo n.º 1
0
        public static string Serialize(VCard vcard)
        {
            if (vcard.Photo == null)
            {
                return(string.Empty);
            }

            var extension = vcard.Photo.Extension.Coalesce("jpg");
            var mimeType  = ImageMimeHelper.GetMimeType(extension);

            return(Base64StringProcessor.SerializeBase64String(vcard.Photo.Contents, "PHOTO", mimeType, vcard.Version));
        }
Exemplo n.º 2
0
        public void Insert(IContact contact)
        {
            var vcard = new VCard
            {
                Version          = VCardVersion.V4,
                UniqueIdentifier = contact.Id,
                FormattedName    = contact.FullName,
                FirstName        = contact.FirstName,
                LastName         = contact.LastName,
                Organization     = contact.Company,
                Title            = contact.JobTitle,
                Telephones       = new List <MixERP.Net.VCards.Models.Telephone>()
                {
                    new MixERP.Net.VCards.Models.Telephone()
                    {
                        Number     = contact.MobilePhone,
                        Type       = TelephoneType.Cell,
                        Preference = 0
                    }
                },
                BirthDay = contact.Birthday,
                Emails   = new List <MixERP.Net.VCards.Models.Email>()
                {
                    new MixERP.Net.VCards.Models.Email()
                    {
                        EmailAddress = contact.Email
                    }
                },
                Addresses = new List <MixERP.Net.VCards.Models.Address>()
                {
                    new MixERP.Net.VCards.Models.Address()
                    {
                        Street = contact.Address
                    }
                },
                Note = contact.Notes
            };

            var  contactPath = "\\Contacts";
            var  otherPath   = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).ToString() + contactPath;
            bool exists      = Directory.Exists(otherPath);

            if (!exists)
            {
                Directory.CreateDirectory(otherPath);
            }

            string Serialized = vcard.Serialize();
            string path       = Path.Combine(otherPath, $"{contact.Id}.vcf");

            File.WriteAllText(path, Serialized);
        }
Exemplo n.º 3
0
        public static string GetMobileNumbers(this VCard vcard)
        {
            if (vcard?.Telephones == null)
            {
                return(string.Empty);
            }

            var cellPhones =
                (from cell in vcard.Telephones where cell != null && (cell.Type == TelephoneType.Cell || cell.Number.StartsWith("MOBILE:")) select cell.Number.Replace("MOBILE:", string.Empty).Trim())
                .ToList();

            return(string.Join(",", cellPhones));
        }
Exemplo n.º 4
0
        public static string GetTelephones(this VCard vcard)
        {
            if (vcard?.Telephones == null)
            {
                return(string.Empty);
            }

            var telephones =
                (from phone in vcard.Telephones where phone != null && phone.Type != TelephoneType.Cell && phone.Type != TelephoneType.Fax && !phone.Number.StartsWith("MOBILE:") select phone.Number)
                .ToList();

            return(string.Join(",", telephones));
        }
Exemplo n.º 5
0
        public static string Serialize(VCard vcard)
        {
            var builder = new StringBuilder();

            builder.Append(CategoriesProcessor.Serialize(vcard));
            builder.Append(NickNameProcessor.Serialize(vcard));
            builder.Append(SortStringProcessor.Serialize(vcard));
            builder.Append(SoundProcessor.Serialize(vcard));
            builder.Append(KeyProcessor.Serialize(vcard));
            builder.Append(ClassificationProcessor.Serialize(vcard));

            return(builder.ToString());
        }
Exemplo n.º 6
0
        public static void Parse(Token token, ref VCard vcard)
        {
            string value = token.Values[0];

            if (string.IsNullOrWhiteSpace(value))
            {
                return;
            }

            var date = DateTimeProcessor.Parse(value);

            vcard.Anniversary = date;
        }
Exemplo n.º 7
0
        public void SaveVcfTest_vCard4_0()
        {
            List <VCard?> list = GenerateVCardList();

            string path = Path.Combine(TestContext !.TestRunResultsDirectory, "SaveVcfTest_v4.0.vcf");

            list.SaveVcf(path, VCdVersion.V4_0);

            IList <VCard> list2 = VCard.LoadVcf(path);

            Assert.AreEqual(2, list2.Count);
            Assert.IsInstanceOfType(list2.FirstOrDefault()?.Relations?.FirstOrDefault()?.Value, typeof(VCard));
        }
Exemplo n.º 8
0
        string FormatAddress(VCard.VAddress address)
        {
            if (address == null)
                return string.Empty;

            return String.Format("{0}<br/>{1}, {2} {3}<br/>{4} {5}",
                                 address.Street,
                                 address.Locality,
                                 address.Region,
                                 address.PostalCode,
                                 address.Country,
                                 address.Extra);
        }
Exemplo n.º 9
0
        private void ConvertVCardOrganization(VCard vcard, ContactEntity contact, Dictionary <int, OrganizationEntity> organizationsById, Dictionary <string, OrganizationEntity> organizationsByName)
        {
            OrganizationEntity organization = null;

            int organizationId = vcard.OrganizationId;

            if (organizationId < 0)
            {
                VCardOrganization organizationCard = VCardOrganization.List(vcard.VCardId);
                if (organizationCard != null)
                {
                    if (!string.IsNullOrEmpty(organizationCard.Unit))
                    {
                        SafelySetStringProperty(contact, "OrganizationUnit", organizationCard.Unit);
                    }

                    string organizationName = organizationCard.Name;
                    if (!string.IsNullOrEmpty(organizationName))
                    {
                        if (organizationName.Length > 255)
                        {
                            organizationName = organizationName.Substring(0, 255);
                        }

                        // Find or create organization
                        if (organizationsByName.ContainsKey(organizationName))
                        {
                            organization = organizationsByName[organizationName];
                        }
                        else
                        {
                            organization = BusinessManager.InitializeEntity <OrganizationEntity>(OrganizationEntity.GetAssignedMetaClassName());
                            SafelySetStringProperty(organization, "Name", organizationName);
                            organization.PrimaryKeyId = BusinessManager.Create(organization);
                        }
                    }
                }
            }
            else
            {
                if (organizationsById.ContainsKey(organizationId))
                {
                    organization = organizationsById[organizationId];
                }
            }

            if (organization != null)
            {
                contact.OrganizationId = organization.PrimaryKeyId;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Complex type members is to be de-serialized to object from json and clear the properties.
        /// </summary>
        public void DeSerializeAndClearObjectsFromJson()
        {
            if (!string.IsNullOrEmpty(this.AuxRegDisposition))
            {
                this.Disposition = JsonSerialization.DeserializeString <RegistrationDisposition>(this.AuxRegDisposition);
            }

            if (!string.IsNullOrEmpty(this.AuxRegistrant))
            {
                this.registrant = JsonSerialization.DeserializeString <VCard>(this.AuxRegistrant);
            }

            if (!string.IsNullOrEmpty(this.AuxContact))
            {
                this.contact = JsonSerialization.DeserializeString <VCard>(this.AuxContact);
            }

            if (this.AuxPointsArea != null)
            {
                this.pointsArea = JsonSerialization.DeserializeString <Position[]>(this.AuxPointsArea);
            }

            if (this.AuxQuadPoints != null)
            {
                this.QuadrilateralArea = JsonSerialization.DeserializeString <QuadrilateralArea[]>(this.AuxQuadPoints);
            }

            if (!string.IsNullOrEmpty(this.AuxTvSpectrum))
            {
                this.callSign = JsonSerialization.DeserializeString <TvSpectrum>(this.AuxTvSpectrum);
            }

            if (!string.IsNullOrEmpty(this.AuxEvent))
            {
                this.auxEvent = JsonSerialization.DeserializeString <Event>(this.AuxEvent);
            }

            if (this.callSign != null && this.callSign.Channel.HasValue)
            {
                this.Channel = this.callSign.Channel.Value;
            }

            this.AuxRegDisposition = string.Empty;
            this.AuxRegistrant     = string.Empty;
            this.AuxContact        = string.Empty;
            this.AuxPointsArea     = string.Empty;
            this.AuxQuadPoints     = string.Empty;
            this.AuxTvSpectrum     = string.Empty;
            this.AuxEvent          = string.Empty;
        }
Exemplo n.º 11
0
        public static VCard VCard(this IDivision division)
        {
            var vcard = new VCard();

            if (!string.IsNullOrWhiteSpace(division.Title))
            {
                vcard.OrganizationName = division.Title;
            }

            if (!string.IsNullOrWhiteSpace(division.Email))
            {
                vcard.Emails.Add(division.Email);
            }

            if (!string.IsNullOrWhiteSpace(division.SecondaryEmail))
            {
                vcard.Emails.Add(division.SecondaryEmail);
            }

            if (!string.IsNullOrWhiteSpace(division.Phone))
            {
                vcard.Phones.Add(new VCardPhone()
                {
                    Number = division.Phone, Type = VCardPhoneType.Work
                });
            }

            if (!string.IsNullOrWhiteSpace(division.Fax))
            {
                vcard.Phones.Add(new VCardPhone()
                {
                    Number = division.Fax, Type = VCardPhoneType.Fax
                });
            }

            if (!string.IsNullOrWhiteSpace(division.WebSite))
            {
                vcard.Url = division.WebSite;
            }

            if (!string.IsNullOrWhiteSpace(division.Location))
            {
                // TODO: Add organization address
                vcard.DeliveryAddress = division.Location;
            }

            vcard.LastRevision = division.LastModifiedOnDate;

            return(vcard);
        }
Exemplo n.º 12
0
        public async Task <IHttpActionResult> DeleteVCard(int id)
        {
            VCard vCard = await db.VCards.FindAsync(id);

            if (vCard == null)
            {
                return(NotFound());
            }

            db.VCards.Remove(vCard);
            await db.SaveChangesAsync();

            return(Ok(vCard));
        }
Exemplo n.º 13
0
    /// <summary>
    /// Liest eine vCard-Datei und gibt ihre Daten als <see cref="Contact"/>-Array zurück. (Eine vCard-Datei kann
    /// mehrere aneinandergehängte vCards enthalten.) Enthält die Datei keinen Text, wird ein leeres Array zurückgegeben.
    /// </summary>
    /// <param name="fileName">Der vollständige Pfad der vCard-Datei.</param>
    /// <returns>Die Daten der vCard als <see cref="Contact"/>-Array.</returns>
    /// <exception cref="ArgumentNullException"><paramref name="fileName"/> ist <c>null</c>.</exception>
    /// <exception cref="ArgumentException"><paramref name="fileName"/> ist kein gültiger Dateipfad.</exception>
    /// <exception cref="IOException">Die Datei konnte nicht geladen werden.</exception>
    internal static List <Contact> Read(string fileName)
    {
        IList <VCard> vcards = VCard.LoadVcf(fileName);


        var wabContacts = new List <Contact>(vcards.Count);

        for (int i = 0; i < vcards.Count; i++)
        {
            wabContacts.Add(ConvertToContact(vcards[i]));
        }

        return(wabContacts);
    }
Exemplo n.º 14
0
        private static void TestValue(VCard expected, VCard actual)
        {
            //v2.1
            AssertValue("FormattedName", expected.FormattedName, actual.FormattedName);
            AssertValue("FirstName", expected.FirstName, actual.FirstName);
            AssertValue("MiddleName", expected.MiddleName, actual.MiddleName);
            AssertValue("LastName", expected.LastName, actual.LastName);
            AssertValue("Prefix", expected.Prefix, actual.Prefix);
            AssertValue("Suffix", expected.Suffix, actual.Suffix);
            AssertValue("BirthDay", expected.BirthDay?.ToString("o"), actual.BirthDay?.ToString("o"));
            AssertValue("Addresses", JsonConvert.SerializeObject(expected.Addresses.Coalesce(new List <Address>()).OrderBy(x => x.Preference).ThenBy(x => x.Locality), Formatting.Indented), JsonConvert.SerializeObject(actual.Addresses.Coalesce(new List <Address>()).OrderBy(x => x.Preference).ThenBy(x => x.Locality), Formatting.Indented));
            AssertValue("DeliveryAddress", JsonConvert.SerializeObject(expected.DeliveryAddress.Coalesce(new DeliveryAddress()), Formatting.Indented), JsonConvert.SerializeObject(actual.DeliveryAddress.Coalesce(new DeliveryAddress()), Formatting.Indented));
            AssertValue("Telephones", JsonConvert.SerializeObject(expected.Telephones.Coalesce(new List <Telephone>()).OrderBy(x => x.Type).ThenBy(x => x.Number), Formatting.Indented), JsonConvert.SerializeObject(actual.Telephones.Coalesce(new List <Telephone>()).OrderBy(x => x.Type).ThenBy(x => x.Number), Formatting.Indented));
            AssertValue("Emails", JsonConvert.SerializeObject(expected.Emails, Formatting.Indented), JsonConvert.SerializeObject(actual.Emails, Formatting.Indented));
            AssertValue("Mailer ", expected.Mailer, actual.Mailer);
            AssertValue("Title", expected.Title, actual.Title);
            AssertValue("Role", expected.Role, actual.Role);
            AssertValue("TimeZone", expected.TimeZone?.ToString(), actual.TimeZone?.ToString());
            AssertValue("Logo", expected.Logo?.Contents, actual.Logo?.Contents);
            AssertValue("Photo", expected.Photo?.Contents, actual.Photo?.Contents);
            AssertValue("Note", expected.Note, actual.Note);
            AssertValue("LastRevision", expected.LastRevision?.ToString("o"), actual.LastRevision?.ToString("o"));
            AssertValue("Url", expected.Url?.ToString(), actual.Url?.ToString());
            AssertValue("UniqueIdentifier", expected.UniqueIdentifier, actual.UniqueIdentifier);
            AssertValue("Organization", expected.Organization, actual.Organization);
            AssertValue("OrganizationalUnit", expected.OrganizationalUnit, actual.OrganizationalUnit);
            AssertValue("Longitude", expected.Longitude.ToString(), actual.Longitude.ToString());
            AssertValue("Longitude", expected.Latitude.ToString(), actual.Latitude.ToString());

            //V3
            AssertValue("NickName", expected.NickName, actual.NickName);
            AssertValue("Categories", JsonConvert.SerializeObject(expected.Categories, Formatting.Indented), JsonConvert.SerializeObject(actual.Categories, Formatting.Indented));
            AssertValue("SortString", expected.SortString, actual.SortString);
            AssertValue("Sound", expected.Sound, actual.Sound);
            AssertValue("Key", expected.Key, actual.Key);
            AssertValue("Classification", Enum.GetName(typeof(ClassificationType), expected.Classification), Enum.GetName(typeof(ClassificationType), actual.Classification));

            //v4.0
            AssertValue("Source", expected.Source?.ToString(), actual.Source?.ToString());
            AssertValue("Kind", Enum.GetName(typeof(Kind), expected.Kind), Enum.GetName(typeof(Kind), actual.Kind));
            AssertValue("Anniversary", expected.Anniversary?.ToString("o"), actual.Anniversary?.ToString("o"));
            AssertValue("Gender", Enum.GetName(typeof(Gender), expected.Gender), Enum.GetName(typeof(Gender), actual.Gender));
            AssertValue("Impps", JsonConvert.SerializeObject(expected.Impps, Formatting.Indented), JsonConvert.SerializeObject(actual.Impps, Formatting.Indented));
            AssertValue("Languages", JsonConvert.SerializeObject(expected.Languages, Formatting.Indented), JsonConvert.SerializeObject(actual.Languages, Formatting.Indented));
            AssertValue("Relations", JsonConvert.SerializeObject(expected.Relations, Formatting.Indented), JsonConvert.SerializeObject(actual.Relations, Formatting.Indented));
            AssertValue("CalendarUserAddresses", JsonConvert.SerializeObject(expected.CalendarUserAddresses, Formatting.Indented), JsonConvert.SerializeObject(actual.CalendarUserAddresses, Formatting.Indented));
            AssertValue("CalendarAddresses", JsonConvert.SerializeObject(expected.CalendarAddresses, Formatting.Indented), JsonConvert.SerializeObject(actual.CalendarAddresses, Formatting.Indented));

            AssertValue(expected.CustomExtensions, actual.CustomExtensions);
        }
        public static ContactModel VCardToContact(VCard vcard, LeadRect bounds = default(LeadRect))
        {
            ContactModel contact = new ContactModel();

            contact.Name = new ContactField(String.Format("{0} {1}", vcard.FirstName, vcard.LastName), bounds);

            foreach (var phoneNumber in vcard.Telephones)
            {
                PhoneType type;

                switch (phoneNumber.Type)
                {
                case TelephoneType.Home:
                    type = PhoneType.Home;
                    break;

                case TelephoneType.Work:
                    type = PhoneType.Work;
                    break;

                case TelephoneType.Cell:
                    type = PhoneType.WorkMobile;
                    break;

                case TelephoneType.Fax:
                    type = PhoneType.WorkFax;
                    break;

                default:
                    type = PhoneType.Home;
                    break;
                }

                contact.PhoneNumbers.Add(new PhoneField(phoneNumber.Number, bounds, type));
            }

            contact.Companies.Add(new ContactField(vcard.Organization, bounds));

            contact.JobTitles.Add(new ContactField(vcard.Title, bounds));

            foreach (var email in vcard.Emails)
            {
                contact.Emails.Add(new EmailField(email.EmailAddress, bounds, Models.EmailType.Work));
            }

            contact.Websites.Add(new ContactField(vcard.Url.ToString(), bounds));

            return(contact);
        }
Exemplo n.º 16
0
        void HandleOnAuthenticate(object sender)
        {
            ConnectionState = AccountConnectionState.Connected;

            // FIXME: Don't send presence until we have our roster.

            if (m_PendingStatus != null)
            {
                Status = m_PendingStatus;
            }
            else
            {
                Status = new ClientStatus(ClientAvailability.Available, null);
            }

            m_ConnectedAt = DateTime.Now;

            // Request own vcard.
            RequestVCard(Jid, delegate(object o, IQ iq, object data) {
                VCard vcard = null;

                if (iq != null && iq.Type != IQType.error)
                {
                    vcard = iq["vCard"] as VCard;
                    if (vcard != null)
                    {
                        if (vcard.ChildNodes == null || vcard.ChildNodes.Count == 0)
                        {
                            vcard = null;
                        }
                    }
                }

                m_MyVCard = vcard;

                if (vcard == null)
                {
                    // FIXME: Raise an event telling user to fill out profile!
                    Console.WriteLine("No VCard!");
                }
                else
                {
                    if (MyVCardUpdated != null)
                    {
                        MyVCardUpdated(this, EventArgs.Empty);
                    }
                }
            }, null);
        }
Exemplo n.º 17
0
        public static string Serialize(VCard vcard)
        {
            if (string.IsNullOrWhiteSpace(vcard.NickName))
            {
                return(string.Empty);
            }

            //The property "NICKNAME" is valid only for VCardVersion 3.0 and above.
            if (vcard.Version == VCardVersion.V2_1)
            {
                return(string.Empty);
            }

            return(DefaultSerializer.GetVCardString("NICKNAME", vcard.NickName, false, vcard.Version));
        }
Exemplo n.º 18
0
        public static string Serialize(VCard vcard)
        {
            if (vcard.Anniversary == null)
            {
                return(string.Empty);
            }

            //Only vCard 4.0 supports ANNIVERSARY property
            if (vcard.Version != VCardVersion.V4)
            {
                return(string.Empty);
            }

            return(DateTimeProcessor.Serialize(vcard.Anniversary, "ANNIVERSARY", vcard.Version));
        }
Exemplo n.º 19
0
        public static string Serialize(VCard vcard)
        {
            if (string.IsNullOrWhiteSpace(vcard.Key))
            {
                return(string.Empty);
            }

            //The property "KEY" is valid only for VCardVersion 3.0 and above.
            if (vcard.Version == VCardVersion.V2_1)
            {
                return(string.Empty);
            }

            return(Base64StringProcessor.SerializeBase64String(vcard.Key, "KEY", string.Empty, vcard.Version));
        }
Exemplo n.º 20
0
        public static string Serialize(VCard vcard)
        {
            if (vcard.CalendarUserAddresses == null || vcard.CalendarUserAddresses.Count() == 0)
            {
                return(string.Empty);
            }

            //Only vCard 4.0 supports CALADRURI property
            if (vcard.Version != VCardVersion.V4)
            {
                return(string.Empty);
            }

            return(UrlProcessor.SerializeUris(vcard.CalendarUserAddresses, "CALADRURI", vcard.Version));
        }
Exemplo n.º 21
0
        public static string Serialize(VCard vcard)
        {
            if (string.IsNullOrWhiteSpace(vcard.Sound))
            {
                return(string.Empty);
            }

            //The property "SOUND" is valid only for VCardVersion 3.0 and above.
            if (vcard.Version == VCardVersion.V2_1)
            {
                return(string.Empty);
            }

            return(Base64StringProcessor.SerializeBase64String(vcard.Sound, "SOUND", "BASIC", vcard.Version));
        }
        public static void Parse(Token token, ref VCard vcard)
        {
            var deliveryAddress = new DeliveryAddress();

            if (vcard.Version == VCardVersion.V4)
            {
                string address = token.Values[0];
                string type    = token.AdditionalKeyMembers.FirstOrDefault(x => x.Key == "TYPE").Value;

                deliveryAddress.Address = address;
                deliveryAddress.Type    = AddressTypeLookup.Parse(type);
            }

            vcard.DeliveryAddress = deliveryAddress;
        }
Exemplo n.º 23
0
        public static string Serialize(VCard vcard)
        {
            //Please note that the property "SORT-STRING" only exists for VCardVersion 3.0
            //where VCardVersion 4.0 uses "SORT-AS" key in N property
            if (vcard.Version != VCardVersion.V3)
            {
                return(string.Empty);
            }

            if (string.IsNullOrWhiteSpace(vcard.SortString))
            {
                return(string.Empty);
            }

            return(DefaultSerializer.GetVCardString("SORT-STRING", vcard.SortString, true, vcard.Version));
        }
Exemplo n.º 24
0
    public void IEnumerableTest2()
    {
        var vc = new VCard
        {
            BirthPlaceViews = new TextProperty("Lummerland")
        };

        IEnumerable enumerable = vc.BirthPlaceViews;

        foreach (var item in enumerable)
        {
            Assert.IsNotNull(item);
        }

        Assert.IsNotNull(vc.BirthPlaceViews.FirstOrDefault());
    }
Exemplo n.º 25
0
        public static string Serialize(VCard vcard)
        {
            if (vcard.Addresses == null)
            {
                return(string.Empty);
            }

            var builder = new StringBuilder();

            foreach (var address in vcard.Addresses)
            {
                builder.Append(Serialize(address, vcard.Version));
            }

            return(builder.ToString());
        }
Exemplo n.º 26
0
        /// <summary>
        /// Add a vCard to the collection
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            using (VCardPropertiesDlg dlg = new VCardPropertiesDlg())
            {
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    VCard newVCard = new VCard();
                    dlg.GetValues(newVCard);

                    // Create a unique ID for the new vCard
                    newVCard.UniqueId.AssignNewId(true);

                    vCards.Add(newVCard);
                }
            }
        }
Exemplo n.º 27
0
    public void WriteEmptyVCard()
    {
        var    vcard = new VCard();
        string s     = vcard.ToVcfString(VCdVersion.V4_0);

        IList <VCard>?cards = VCard.ParseVcf(s);

        Assert.AreEqual(cards.Count, 1);

        vcard = cards[0];

        Assert.AreEqual(VCdVersion.V4_0, vcard.Version);
        Assert.IsNotNull(vcard.DisplayNames);
        Assert.AreEqual(vcard.DisplayNames !.Count(), 1);
        Assert.IsNotNull(vcard.DisplayNames !.First());
    }
Exemplo n.º 28
0
        public static void Parse(Token token, ref VCard vcard)
        {
            string value = token.Values[0];

            if (string.IsNullOrWhiteSpace(value))
            {
                return;
            }

            var uri = new Uri(value, UriKind.RelativeOrAbsolute);

            var urls = (List <Uri>)vcard.CalendarUserAddresses ?? new List <Uri>();

            urls.Add(uri);
            vcard.CalendarUserAddresses = urls;
        }
Exemplo n.º 29
0
        internal VCard ToVCard()
        {
            var card = new VCard();

            if (!string.IsNullOrWhiteSpace(this.FirstName))
            {
                card.FirstName = this.FirstName;
            }
            card.LastName = this.LastName;
            var phone = new Telephone();

            phone.Number    = this.PhoneNumber;
            phone.Type      = TelephoneType.Cell;
            card.Telephones = new Telephone[] { phone };
            return(card);
        }
Exemplo n.º 30
0
        public static VCard ToVCard(this Contact contact, string tenant, HttpRequestBase request)
        {
            if (contact == null)
            {
                return(new VCard());
            }

            var vcard = new VCard
            {
                Version       = VCardVersion.V4,
                FirstName     = contact.FirstName,
                MiddleName    = contact.MiddleName,
                LastName      = contact.LastName,
                Prefix        = contact.Prefix,
                Suffix        = contact.Suffix,
                FormattedName = contact.FormattedName,
                Url           = string.IsNullOrWhiteSpace(contact.Url) ? null : new Uri(contact.Url, UriKind.RelativeOrAbsolute),
                Kind          = contact.Kind,
                Gender        = contact.Gender,
                Languages     = string.IsNullOrWhiteSpace(contact.TimeZone)
                    ? new List <Language>()
                    : new List <Language>
                {
                    new Language
                    {
                        Type       = LanguageType.Unknown,
                        Preference = 1,
                        Name       = contact.Language
                    }
                },
                TimeZone           = string.IsNullOrWhiteSpace(contact.TimeZone) ? null : TimeZoneInfo.FindSystemTimeZoneById(contact.TimeZone),
                Organization       = contact.Organization,
                OrganizationalUnit = contact.OrganizationalUnit,
                Title      = contact.Title,
                Emails     = contact.ParseEmails(),
                Telephones = contact.ParseTelephones(),
                Addresses  = contact.ParseAddresses(),
                Photo      = contact.GetPhoto(tenant, request),
                BirthDay   = contact.BirthDay,
                NickName   = contact.NickName,
                Role       = contact.Role,
                Note       = contact.Note,
                Categories = contact.Tags.Or("").Split(',')
            };

            return(vcard);
        }
Exemplo n.º 31
0
        private void ConvertContacts(string companyLocale, Dictionary <int, OrganizationEntity> organizationsById, Dictionary <int, ContactEntity> contactsById)
        {
            Dictionary <string, OrganizationEntity> organizationsByName = new Dictionary <string, OrganizationEntity>();

            if (organizationsById != null && organizationsByName != null)
            {
                foreach (OrganizationEntity organization in organizationsById.Values)
                {
                    organizationsByName.Add(organization.Name, organization);
                }
            }

            Regex urlValidator = new Regex("^[\\w-_./:\\?&=]+");

            foreach (VCard vcard in VCard.List())
            {
                int vcardId = vcard.VCardId;

                ContactEntity contact = BusinessManager.InitializeEntity <ContactEntity>(ContactEntity.GetAssignedMetaClassName());

                SafelySetStringProperty(contact, "FullName", vcard.FullName);
                SafelySetStringProperty(contact, "NickName", vcard.NickName);
                if (!string.IsNullOrEmpty(vcard.Url) && urlValidator.IsMatch(vcard.Url))
                {
                    SafelySetStringProperty(contact, "WebSiteUrl", vcard.Url);
                }
                if (vcard.Birthday != DateTime.MinValue)
                {
                    contact.BirthDate = vcard.Birthday;
                }
                SafelySetStringProperty(contact, "JobTitle", vcard.Title);
                SafelySetStringProperty(contact, "Role", vcard.Role);
                SafelySetStringProperty(contact, "Description", vcard.Description);
                contact.Gender = ConvertGender(vcard.Gender);

                ConvertVCardName(vcardId, contact);
                ConvertVCardAddress(vcardId, contact, companyLocale);
                ConvertVCardPhones(vcardId, contact);
                ConvertVCardEmails(vcardId, contact);
                ConvertVCardOrganization(vcard, contact, organizationsById, organizationsByName);

                // Save contact
                contact.PrimaryKeyId = BusinessManager.Create(contact);

                contactsById.Add(vcardId, contact);
            }
        }
Exemplo n.º 32
0
        void Populate(VCard vcard)
        {
            string template = null;

            if (vcard == null) {
                template = "Unable to view profile.";
            } else {
                template = Util.ReadResource("profile.html");

                // FIXME: This is just a quick hack. Really need to do all the replacement at once.
                template = template.Replace("@@NAME@@", vcard.FullName);
                template = template.Replace("@@JID@@", vcard.JabberId);
                template = template.Replace("@@NICKNAME@@", vcard.Nickname);

                try {
                    template = template.Replace("@@BIRTHDAY@@", vcard.Birthday.ToString());
                } catch {
                    template = template.Replace("@@BIRTHDAY@@", String.Empty);
                }

                var email = vcard.GetEmail(EmailType.home);
                if (email != null)
                    template = template.Replace("@@EMAIL@@", email.UserId);
                else
                    template = template.Replace("@@EMAIL@@", String.Empty);

                if (vcard.Url != null)
                    template = template.Replace("@@WEBSITE@@", vcard.Url.ToString());
                else
                    template = template.Replace("@@WEBSITE@@", String.Empty);

                template = template.Replace("@@ADDRESS@@", FormatAddress(vcard.GetAddress(AddressLocation.home)));

                var phone = vcard.GetTelephone(TelephoneType.voice, TelephoneLocation.home);
                if (phone != null)
                    template = template.Replace("@@PHONE@@", phone.Number);
                else
                    template = template.Replace("@@PHONE@@", String.Empty);

                template = template.Replace("@@ABOUT@@", vcard.Description);

                var org = vcard.Organization;
                if (org != null) {
                    template = template.Replace("@@COMPANY@@", org.OrgName);
                    template = template.Replace("@@DEPARTMENT@@", vcard.Organization.Unit);
                } else {
                    template = template.Replace("@@COMPANY@@", String.Empty);
                    template = template.Replace("@@DEPARTMENT@@", String.Empty);
                }

                template = template.Replace("@@POSITION@@", vcard.Title);
                template = template.Replace("@@ROLE@@", vcard.Role);

                email = vcard.GetEmail(EmailType.work);
                if (email != null)
                    template = template.Replace("@@WORK_EMAIL@@", email.UserId);
                else
                    template = template.Replace("@@WORK_EMAIL@@", String.Empty);

                template = template.Replace("@@WORK_ADDRESS@@", FormatAddress(vcard.GetAddress(AddressLocation.work)));

                phone = vcard.GetTelephone(TelephoneType.voice, TelephoneLocation.work);
                if (phone != null)
                    template = template.Replace("@@WORK_PHONE@@", phone.Number);
                else
                    template = template.Replace("@@WORK_PHONE@@", String.Empty);
            }
            QApplication.Invoke(delegate {
                webView.SetHtml(template);
            });
        }