Beispiel #1
0
        internal static IAddressBook Parse(string xmlContent)
        {
            Logger.Instance.LogFormat(LogType.Debug, null, Properties.Resources.AddressBook_StartScanMessage);

            AddressBook addressBook = new AddressBook();

            // Parse document
            XDocument doc = XDocument.Parse(xmlContent);

            foreach (XElement entryE in doc.Root.Elements("Entry"))
            {
                AddressBookEntry entry = new AddressBookEntry();
                entry.Name = entryE.TryGetAttributeValue("Name", null);

                // Find all other custom attributes
                foreach (XElement customElementE in entryE.Elements())
                {
                    string providerType = customElementE.Name.LocalName;

                    IAddressProvider provider = addressBook.GetAddressProvider(providerType);
                    if (provider == null)
                    {
                        continue;
                    }

                    if (!IsEnabled(customElementE))
                    {
                        continue;
                    }

                    object customObject = provider.ParseXElement(customElementE);
                    if (customObject == null)
                    {
                        continue;
                    }

                    entry.CustomData[providerType] = customObject;
                }

                addressBook._entries.Add(entry);
            }

            Logger.Instance.LogFormat(LogType.Debug, null, Properties.Resources.AddressBook_FinishScanMessage, addressBook._entries.Count);

            return(addressBook);
        }
        private AddressBook CompileAddressBookFromViewModel()
        {
            AddressBook addressBook = new AddressBook();

            foreach (EntryViewModel evm in this.Entries)
            {
                AddressBookEntry abe = new AddressBookEntry();
                abe.FirstName = evm.FirstName;
                abe.LastName = evm.LastName;

                foreach (EntryDataItemViewModel edivm in evm.DataItems)
                {
                    EntryDataItem edi = new EntryDataItem();
                    // Decide which value to use
                    if (edivm.Editor != null)
                    {
                        edi.IsEnabled = edivm.IsEnabled;
                        edi.Identifier = CustomDataEditors.CustomDataEditorCache.GetTypeEditorIdentifier(edivm.Editor.GetType());
                        edi.Data = edivm.Editor.Value;

                        // If there is no data available, skip this entry.
                        if (edi.Data == null)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (edivm.Source != null)
                        {
                            edi = edivm.Source;
                        }

                        // TODO: What happens if there is no editor, AND no value?
                        continue;
                    }

                    abe.Data.Add(edi);
                }

                addressBook.Entries.Add(abe);
            }

            return addressBook;
        }