Ejemplo n.º 1
0
        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();
                }
            }
        }
Ejemplo n.º 2
0
        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();
                }
            }
        }