Ejemplo n.º 1
0
        private void Write(ref StringBuilder output, vCard card)
        {
            if (card == null)
                return;

            output.Append("BEGIN:VCARD" + Environment.NewLine + "VERSION:3.0" + Environment.NewLine);
            output.Append("N:" + card.Surname + ";" + card.GivenName + ";" + card.MiddleName + ";" +
                card.Prefix + ";" + card.Suffix + Environment.NewLine);
            output.Append("FN:" + card.FormattedName + Environment.NewLine);
            if (card.Title.NotBlank())
                output.Append("TITLE:" + card.Title + Environment.NewLine);
            output.Append("END:VCARD" + Environment.NewLine);
        }
        private void ExecuteExportCommand(object obj)
        {
            var saveDlg = new SaveFileDialog()
            {
                CheckPathExists = true,
                OverwritePrompt = true,
                FileName = "ace_contacts",
                Filter = "VCF files (*.vcf) | *.vcf",
                FilterIndex = 0,
            };

            if (saveDlg.ShowDialog() != true)
                return;

            if (ServiceManager.Instance.LinphoneService.VCardSupported)
            {
               ServiceManager.Instance.ContactService.ExportVCards(saveDlg.FileName);
            }
            else
            {
                var cardWriter = new vCardWriter();
                var vCards = new List<vCard>();

                foreach (var contactVM in this.Contacts)
                {
                    var card = new vCard()
                    {
                        GivenName = contactVM.Contact.Fullname,
                        FormattedName = contactVM.Contact.Fullname,
                        Title = contactVM.Contact.RegistrationName
                    };
                    vCards.Add(card);
                }
                cardWriter.WriteCards(saveDlg.FileName, vCards);
            }
        }
Ejemplo n.º 3
0
        private void Parse(string lines)
        {
            vCard card = new vCard();
            RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.Multiline |
                                   RegexOptions.IgnorePatternWhitespace;

            Regex regex;
            Match m;
            MatchCollection mc;

            regex = new Regex(@"(?<strElement>(FN))   (:(?<strFN>[^\n\r]*))", options);
            m = regex.Match(lines);
            if (m.Success)
                card.FormattedName = m.Groups["strFN"].Value;

            // N
            regex =
                new Regex(
                    @"(\n(?<strElement>(N)))   (:(?<strSurname>([^;]*))) (;(?<strGivenName>([^;]*)))  (;(?<strMidName>([^;]*))) (;(?<strPrefix>([^;]*))) (;(?<strSuffix>[^\n\r]*))",
                    options);
            m = regex.Match(lines);
            if (m.Success)
            {
                card.Surname = m.Groups["strSurname"].Value;
                card.GivenName = m.Groups["strGivenName"].Value;
                card.MiddleName = m.Groups["strMidName"].Value;
                card.Prefix = m.Groups["strPrefix"].Value;
                card.Suffix = m.Groups["strSuffix"].Value;
            }

            // TITLE
            regex = new Regex(@"(?<strElement>(TITLE))   (:(?<strTITLE>[^\n\r]*))", options);
            m = regex.Match(lines);
            if (m.Success)
                card.Title = m.Groups["strTITLE"].Value;

            // PRODID
            regex = new Regex(@"(?<strElement>(PRODID))   (:(?<strPRODID>[^\n\r]*))", options);
            m = regex.Match(lines);
            if (m.Success)
                card.ProdId = m.Groups["strPRODID"].Value;

            // REV
            regex = new Regex(@"(?<strElement>(REV))   (:(?<strREV>[^\n\r]*))", options);
            m = regex.Match(lines);
            if (m.Success)
            {
                string[] expectedFormats = { "yyyyMMddHHmmss", "yyyy-MM-ddTHHmmssZ", "yyyyMMddTHHmmssZ" };
                card.Rev = DateTime.ParseExact(m.Groups["strREV"].Value, expectedFormats, null, System.Globalization.DateTimeStyles.AllowWhiteSpaces);
            }

            if (card.Title.NotBlank() && card.FormattedName.NotBlank())
                vCards.Add(card);
        }
Ejemplo n.º 4
0
        private void Parse(string lines)
        {
            vCard        card    = new vCard();
            RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.Multiline |
                                   RegexOptions.IgnorePatternWhitespace;

            Regex           regex;
            Match           m;
            MatchCollection mc;

            regex = new Regex(@"(?<strElement>(FN))   (:(?<strFN>[^\n\r]*))", options);
            m     = regex.Match(lines);
            if (m.Success)
            {
                card.FormattedName = m.Groups["strFN"].Value;
            }

            // N
            regex =
                new Regex(
                    @"(\n(?<strElement>(N)))   (:(?<strSurname>([^;]*))) (;(?<strGivenName>([^;]*)))  (;(?<strMidName>([^;]*))) (;(?<strPrefix>([^;]*))) (;(?<strSuffix>[^\n\r]*))",
                    options);
            m = regex.Match(lines);
            if (m.Success)
            {
                card.Surname    = m.Groups["strSurname"].Value;
                card.GivenName  = m.Groups["strGivenName"].Value;
                card.MiddleName = m.Groups["strMidName"].Value;
                card.Prefix     = m.Groups["strPrefix"].Value;
                card.Suffix     = m.Groups["strSuffix"].Value;
            }

            // TITLE
            regex = new Regex(@"(?<strElement>(TITLE))   (:(?<strTITLE>[^\n\r]*))", options);
            m     = regex.Match(lines);
            if (m.Success)
            {
                card.Title = m.Groups["strTITLE"].Value;
            }

            // PRODID
            regex = new Regex(@"(?<strElement>(PRODID))   (:(?<strPRODID>[^\n\r]*))", options);
            m     = regex.Match(lines);
            if (m.Success)
            {
                card.ProdId = m.Groups["strPRODID"].Value;
            }

            // REV
            regex = new Regex(@"(?<strElement>(REV))   (:(?<strREV>[^\n\r]*))", options);
            m     = regex.Match(lines);
            if (m.Success)
            {
                string[] expectedFormats = { "yyyyMMddHHmmss", "yyyy-MM-ddTHHmmssZ", "yyyyMMddTHHmmssZ" };
                card.Rev = DateTime.ParseExact(m.Groups["strREV"].Value, expectedFormats, null, System.Globalization.DateTimeStyles.AllowWhiteSpaces);
            }

            if (card.Title.NotBlank() && card.FormattedName.NotBlank())
            {
                vCards.Add(card);
            }
        }