Ejemplo n.º 1
0
        private void ParseDisplayConfigAndAdd(XDocument doc, SettingsDisplayConfiguration config)
        {
            if (!doc.IsXmlValid(Properties.Resources.SettingsInfoSchema))
            {
                return;
            }

            foreach (XElement identifierE in doc.Root.Elements("Identifier"))
            {
                IdentifierInfo identifier = new IdentifierInfo();
                identifier.Name = identifierE.Attribute("Name").Value;

                identifier.DisplayText = identifierE.TryGetAttributeValue("DisplayText", identifier.Name);
                identifier.Description = identifierE.TryGetAttributeValue("Description", null);
                identifier.Order = identifierE.TryGetAttributeValue("Order", 0);
                identifier.Parent = identifierE.TryGetAttributeValue("Parent", null);

                foreach (XElement settingE in identifierE.Elements("Setting"))
                {
                    SettingInfo setting = new SettingInfo();
                    setting.Identifier = identifier.Name;
                    setting.Name = settingE.Attribute("Name").Value;

                    setting.Category = settingE.TryGetAttributeValue("Category", null);
                    setting.DisplayText = settingE.TryGetAttributeValue("DisplayText", setting.Name);
                    setting.Description = settingE.TryGetAttributeValue("Description", null);
                    setting.Order = settingE.TryGetAttributeValue("Order", 0);
                    setting.Editor = settingE.TryGetAttributeValue("Editor", null);
                    setting.EditorParameter = settingE.TryGetAttributeValue("EditorParameter", null);
                    setting.IsDynamic = settingE.TryGetAttributeValue("IsDynamic", false);

                    identifier.Settings.Add(setting);
                }

                config.Identifiers.Add(identifier);
            }
        }
Ejemplo n.º 2
0
        private void InitializeSettings()
        {
            try
            {
                using (var service = ServiceFactory.GetCallbackServiceWrapper<ISettingsService>(new SettingsServiceCallback()))
                {
                    _displayConfiguration = service.Instance.GetDisplayConfiguration();
                    BuildSectionsTree(service.Instance);

                    IsConnected = true;
                }
            }
            catch (EndpointNotFoundException ex)
            {
                Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.EndpointNotFoundOnStart);
                Logger.Instance.LogException(this, ex);

                UIUtilities.ShowWarning(Properties.Resources.EndpointNotFoundOnStart);

            }
            catch (Exception ex)
            {
                Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.SettingsInitializationError);
                Logger.Instance.LogException(this, ex);

                UIUtilities.ShowWarning(Properties.Resources.SettingsInitializationError);
            }
        }
Ejemplo n.º 3
0
        // TODO: Do this in LoadSettings()!
        private void LoadSettingsDisplayConfiguration(IList<string> assemblyFiles)
        {
            SettingsDisplayConfiguration config = new SettingsDisplayConfiguration();

            foreach (string assemblyFile in assemblyFiles)
            {
                string assemblyLocation = null;
                try
                {
                    Assembly assembly = Assembly.LoadFile(assemblyFile);
                    assemblyLocation = assembly.Location;

                    // Try to locate and load the embedded resource file
                    string embResText = assembly.GetEmbeddedResourceText(EmbeddedResourceFileName);
                    // If the assembly has no such settings configuration, skip further processing.
                    if (string.IsNullOrWhiteSpace(embResText))
                    {
                        continue;
                    }

                    XDocument doc = XDocument.Parse(embResText);
                    ParseDisplayConfigAndAdd(doc, config);

                    Logger.Instance.LogFormat(LogType.Debug, this, Properties.Resources.SettingsDisplayConfigurationEmbResLoaded, assemblyLocation);
                }
                catch (XmlException ex)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, Properties.Resources.SettingsDisplayConfigurationEmbResLoaded, assemblyLocation, ex.Message);
                }
                catch (BadImageFormatException)
                {
                    // We can ignore this exception because it may occur with unmanaged dlls.
                }
                catch (Exception)
                {
                    // Ignore parsing this file.
                    Logger.Instance.LogFormat(LogType.Warning, null, "Could not parse settings-info file '{0}'. It either is no settings-info-file or it is in an invalid format.", assemblyLocation);
                }
            }

            // Done loading!
            _displayConfiguration = config;
        }