private static void ReplaceXmlIfExists(XElement globalsSettingXml, SettingAdapter adapter, XElement newElement) { if (newElement != null) { XElement oldElement = globalsSettingXml.Descendants("State").FirstOrDefault(x => x.Attribute("Name").Value.Equals(adapter.GetCoreType().FullName, StringComparison.Ordinal)); if (oldElement == null) { globalsSettingXml.Add(newElement); } else { oldElement.ReplaceWith(newElement); } } }
private void FillSettings(IonicZipFileAdapter zipAdapter, string typeFullName, StorableSettings settings, Func <StorableSettings, Dictionary <string, string> > getSettingDictionary) { string entryName = typeFullName + ".xml"; XElement xml = null; Stream xmlStream = zipAdapter.GetEntryStreamByName(entryName); if (xmlStream != null) { xml = XElement.Load(xmlStream); } if (xml != null) { var currentSettingStateXml = xml; Dictionary <string, string> sourceStateDictionary = SettingAdapter.FromXml(currentSettingStateXml); Dictionary <string, string> targetStateDictionary = getSettingDictionary(settings); foreach (var stateItem in sourceStateDictionary) { targetStateDictionary.Add(stateItem.Key, stateItem.Value); } } }
protected virtual void SaveSettingsCore(IEnumerable <IStorableSettings> storableSettings) { //if (File.Exists(GlobalsSettingsPathFileName)) File.Delete(GlobalsSettingsPathFileName); //if (File.Exists(ProjectSettingsPathFileName)) File.Delete(ProjectSettingsPathFileName); IonicZipFileAdapter globalsZipFileAdapter = null; IonicZipFileAdapter projectZipFileAdapter = null; bool needSaveGlobalsSettings = false; bool needSaveProjectSettings = false; try { globalsZipFileAdapter = new IonicZipFileAdapter(GlobalsSettingsPathFileName); projectZipFileAdapter = new IonicZipFileAdapter(ProjectSettingsPathFileName); foreach (var setting in storableSettings) { var settings = setting.GetSettings(); if (settings.GlobalSettings.Count > 0) { needSaveGlobalsSettings = true; } if (settings.ProjectSettings.Count > 0 && GisEditor.ProjectManager.IsLoaded) { needSaveProjectSettings = true; } try { if (needSaveGlobalsSettings) { SettingAdapter globalsAdapter = new InfrastructureSettingAdapter(setting); XElement globalsXmlElement = SettingAdapter.ToXml(settings.GlobalSettings, globalsAdapter.GetCoreType()); SaveSingleSettings(globalsZipFileAdapter, setting, globalsXmlElement); } if (needSaveProjectSettings) { SettingAdapter projectAdapter = new ProjectSettingAdapter(setting); XElement projectXmlElement = SettingAdapter.ToXml(settings.ProjectSettings, projectAdapter.GetCoreType()); SaveSingleSettings(projectZipFileAdapter, setting, projectXmlElement); } } catch (Exception ex) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); } } if (needSaveGlobalsSettings) { globalsZipFileAdapter.Save(GlobalsSettingsPathFileName); } if (needSaveProjectSettings) { projectZipFileAdapter.Save(ProjectSettingsPathFileName); } } catch (Exception ex) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); } finally { if (globalsZipFileAdapter != null) { globalsZipFileAdapter.Dispose(); } if (projectZipFileAdapter != null) { projectZipFileAdapter.Dispose(); } } }