Пример #1
0
        /// <summary>
        /// Method to export contacts to local machine. Creates
        /// the file the contacts will be saved to and calls methods
        /// that generate the xml formatting for the exported contacts.
        /// </summary>
        /// <returns>void</returns>
        private void ExecuteLocalExport()
        {
            var saveDlg = new SaveFileDialog()
            {
                CheckPathExists = true,
                OverwritePrompt = true,
                FileName        = "ace_contacts",
                Filter          = "VCF files (*.vcf) | *.vcf| xCard files (*.xml) | *.xml",
                FilterIndex     = 0,
            };

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

            if (ServiceManager.Instance.LinphoneService.VCardSupported)
            {
                //  Added 2/21/207 fjr, save as XML
                if (saveDlg.FileName.EndsWith(".xml"))
                {
                    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.WriteCardsAsXML(saveDlg.FileName, vCards);
                }
                else
                {
                    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);
            }
        }