Ejemplo n.º 1
0
        void IStringSettingConvertible.Convert(string settingValue)
        {
            Logger.Instance.LogFormat(LogType.Debug, this, Resources.AddressBook_StartScanMessage);

            XDocument doc = XDocument.Parse(settingValue);

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

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

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

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

                    EntryDataItem eo = new EntryDataItem();
                    eo.IsEnabled  = IsEnabled(customElementE);
                    eo.Identifier = providerType;
                    eo.Data       = customObject;
                    entry.Data.Add(eo);
                }

                Entries.Add(entry);
            }

            Logger.Instance.LogFormat(LogType.Debug, this, Resources.AddressBook_FinishScanMessage, Entries.Count);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EntryDataItemViewModel"/> class.
        /// </summary>
        /// <param name="parent">The parent VM.</param>
        internal EntryDataItemViewModel(EntryViewModel parent)
        {
            Parent = parent;

            IsEnabled = true;
            Source = new EntryDataItem();
        }
Ejemplo n.º 3
0
        void IStringSettingConvertible.Convert(string settingValue)
        {
            Logger.Instance.LogFormat(LogType.Debug, this, Resources.AddressBook_StartScanMessage);

            XDocument doc = XDocument.Parse(settingValue);

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

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

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

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

                    EntryDataItem eo = new EntryDataItem();
                    eo.IsEnabled = IsEnabled(customElementE);
                    eo.Identifier = providerType;
                    eo.Data = customObject;
                    entry.Data.Add(eo);
                }

                Entries.Add(entry);
            }

            Logger.Instance.LogFormat(LogType.Debug, this, Resources.AddressBook_FinishScanMessage, Entries.Count);
        }
Ejemplo n.º 4
0
        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;
        }