public string GetExtensionDataForExtension(string extensionId)
        {
            ExtensionData ex = getExtensionDataForExtensions(extensionId);

            if (ex != null)
            {
                return(ex.ConfigData);
            }
            return(null);
        }
        public string ToXml()
        {
            XDocument xDoc     = new XDocument();
            XElement  rootElem = new XElement("Controls");

            xDoc.Add(rootElem);
            if (ExtensionsData != null)
            {
                foreach (KeyValuePair <string, ExtensionData> data in ExtensionsData)
                {
                    if (string.IsNullOrEmpty(data.Key))
                    {
                        continue;
                    }

                    XElement controlElement = new XElement("Control");
                    controlElement.SetAttributeValue("Name", data.Key);
                    rootElem.Add(controlElement);

                    ExtensionData dataValue = data.Value;
                    if (dataValue == null)
                    {
                        continue;
                    }

                    string configData = dataValue.ConfigData;
                    if (configData == null)
                    {
                        continue;
                    }
                    configData = configData.Trim();
                    XElement configDataElement = new XElement("Control.ConfigData");
                    if (configData.StartsWith("<", StringComparison.Ordinal) && configData.EndsWith(">", StringComparison.Ordinal))
                    {
                        try
                        {
                            XDocument xDoc2 = XDocument.Parse(configData);
                            configDataElement.Add(xDoc2.Root);
                        }
                        catch
                        {
                            configDataElement.Value = configData;
                        }
                    }
                    else
                    {
                        configDataElement.Value = configData;
                    }
                    controlElement.Add(configDataElement);
                }
            }
            return(xDoc.ToString(
                       SaveOptions.OmitDuplicateNamespaces
                       ));
        }
 public void SetExtensionDataForExtension(string extensionId, string data)
 {
     ExtensionData ex = getExtensionDataForExtensions(extensionId);
     if (ex == null)
     {
         ex = new ExtensionData();
         if (ExtensionsConfigData == null)
             ExtensionsConfigData = new ExtensionsConfigData() { ExtensionsData = new System.Collections.Generic.Dictionary<string, ExtensionData>() };
         ExtensionsConfigData.ExtensionsData.Add(extensionId, ex);
     }
     ex.ConfigData = data;
 }
        public void SetExtensionDataForExtension(string extensionId, string data)
        {
            ExtensionData ex = getExtensionDataForExtensions(extensionId);

            if (ex == null)
            {
                ex = new ExtensionData();
                if (ExtensionsConfigData == null)
                {
                    ExtensionsConfigData = new ExtensionsConfigData()
                    {
                        ExtensionsData = new System.Collections.Generic.Dictionary <string, ExtensionData>()
                    }
                }
                ;
                ExtensionsConfigData.ExtensionsData.Add(extensionId, ex);
            }
            ex.ConfigData = data;
        }
Beispiel #5
0
        public void SaveExtensionsConfigData()
        {
            if (ExtensionsDataManager == null)
                return;

            if (ExtensionBehaviors != null)
            {
                foreach (ExtensionBehavior extensionBehavior in ExtensionBehaviors)
                {
                    if (extensionBehavior == null)
                        continue;
                    ISupportsConfiguration behavior = extensionBehavior.MapBehavior as ISupportsConfiguration;
                    if (behavior != null)
                    {
                        try
                        {
                            string savedData = behavior.SaveConfiguration();
                            ExtensionsDataManager.SetExtensionDataForExtension(extensionBehavior.BehaviorId, savedData);
                        }
                        catch (Exception ex)
                        {
                            NotificationPanel.Instance.AddNotification(ESRI.ArcGIS.Mapping.Controls.Resources.Strings.BehaviorSaveFailed, ESRI.ArcGIS.Mapping.Controls.Resources.Strings.BehaviorSaveFailedMessage, string.Format(ESRI.ArcGIS.Mapping.Controls.Resources.Strings.ErrorSaveConfigurationOfExtension, behavior.GetType().FullName) + Environment.NewLine + ex.Message, MessageType.Warning);
                            Logger.Instance.LogError(ex);
                        }
                    }
                }
            }

            IApplicationAdmin appAdmin = MapApplication.Current as IApplicationAdmin;
            if (appAdmin != null && appAdmin.ConfigurableControls != null)
            {
                ExtensionsDataManager = ExtensionsDataManager ?? new ExtensionsDataManager();
                ExtensionsDataManager.ExtensionsConfigData = ExtensionsDataManager.ExtensionsConfigData ?? new ExtensionsConfigData();
                ExtensionsDataManager.ExtensionsConfigData.ExtensionsData = ExtensionsDataManager.ExtensionsConfigData.ExtensionsData ?? new Dictionary<string, ExtensionData>();

                foreach (FrameworkElement elem in appAdmin.ConfigurableControls)
                {
                    if (string.IsNullOrWhiteSpace(elem.Name))
                        continue;

                    ExtensionData extensionData = null;
                    if (!ExtensionsDataManager.ExtensionsConfigData.ExtensionsData.TryGetValue(elem.Name, out extensionData))
                    {
                        extensionData = new ExtensionData();
                        ExtensionsDataManager.ExtensionsConfigData.ExtensionsData.Add(elem.Name, extensionData);
                    }

                    ISupportsConfiguration supportsConfig = elem as ISupportsConfiguration;
                    if (supportsConfig != null)
                    {
                        try
                        {
                            extensionData.ConfigData = supportsConfig.SaveConfiguration();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxDialog.Show(string.Format(ESRI.ArcGIS.Mapping.Controls.Resources.Strings.ErrorSaveConfigurationOfExtension, elem.GetType().FullName) + Environment.NewLine + ex.Message);
                            Logger.Instance.LogError(ex);
                        }
                    }
                }
            }
        }