private void ApplySettingsInternal(IEnumerable <IStorableSettings> settings) { IonicZipFileAdapter globalsZipAdapter = null; IonicZipFileAdapter projectZipAdapter = null; try { globalsZipAdapter = new IonicZipFileAdapter(GlobalsSettingsPathFileName); projectZipAdapter = new IonicZipFileAdapter(ProjectSettingsPathFileName); foreach (var item in settings) { string typeFullName = item.GetType().FullName; StorableSettings tmpSettings = new StorableSettings(); FillSettings(globalsZipAdapter, typeFullName, tmpSettings, s => s.GlobalSettings); FillSettings(projectZipAdapter, typeFullName, tmpSettings, s => tmpSettings.ProjectSettings); item.ApplySettings(tmpSettings); } } catch (Exception ex) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); } finally { if (globalsZipAdapter != null) { globalsZipAdapter.Dispose(); } if (projectZipAdapter != null) { projectZipAdapter.Dispose(); } } }
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); } } }
public static bool IsZipFile(string fileName) { return(IonicZipFileAdapter.IsZipFile(fileName)); }
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(); } } }