• WPF使用ARCGIS App文件配置Cs后台文件


    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Windows;
    
    using ESRI.ArcGIS.esriSystem;
    using System.Xml.Serialization;
    using System.IO;
    using SWGW.Properties;
    using System.Diagnostics;
    namespace SWGW
    {
        /// <summary>
        /// App.xaml 的交互逻辑
        /// </summary>
        public partial class App : Application
        {
    
            #region License
            protected override void OnStartup(StartupEventArgs e)
            {
                SettingsManager.OnStartup();
                base.OnStartup(e);
    
                if (!LicenseManager.InitializeLicense.InitializeEngineLicense())
                {
                    MessageBox.Show("无法初始化ArcGIS Engine的授权或地球扩展。截止...");
                }
               
            }
            #endregion
    
            #region 私有类
            static class SettingsManager
            {
                #region Class Members
                static Settings settings = new Settings();
                const string applicationDirectory = "SWGW";
                //配置文件名称
                const string settingsFileName = "XXXX.xml";
                #endregion Class Members
    
                #region Constructor
    
                static SettingsManager()
                {
                    EnsureDirectoryExists();
                }
    
                #endregion Constructor
    
                #region Properties
    
                public static Settings ApplicationSettings
                {
                    get { return settings; }
                }
    
                #endregion Properties
    
                #region Startup, Exit
    
                public static void OnStartup()
                {
                    LoadSettings();
                }
    
                public static void OnExit()
                {
                    SaveSettings();
                }
    
                #endregion Overrides
    
                #region Other Functions
    
                static string SettingsFileName
                {
                    get
                    {
                        return Path.Combine(
                            Path.Combine(
                            Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                            applicationDirectory),
                            settingsFileName);
                    }
                }
    
                static void LoadSettings()
                {
                    Settings tmp;
    
                    try
                    {
                        XmlSerializer xml = new XmlSerializer(typeof(Settings));
    
                        using (Stream stream = new System.IO.FileStream(SettingsFileName,
                            FileMode.Open, FileAccess.Read, FileShare.Read))
                        {
                            tmp = (Settings)xml.Deserialize(stream);
                        }
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLine(e.Message);
                        return;
                    }
    
                    settings = tmp;
                }
    
                static void SaveSettings()
                {
                    try
                    {
                        XmlSerializer xml = new XmlSerializer(typeof(Settings));
    
                        using (Stream stream = new System.IO.FileStream(SettingsFileName,
                               FileMode.Create, FileAccess.Write, FileShare.None))
                        {
                            xml.Serialize(stream, settings);
                        }
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLine(e.Message);
                    }
                }
    
                [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
                static void EnsureDirectoryExists()
                {
                    try
                    {
                        DirectoryInfo info = new DirectoryInfo(
                            Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                            applicationDirectory));
    
                        if (!info.Exists)
                        {
                            info.Create();
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex.Message);
                    }
                }
    
                #endregion Other Functions
            }
    
    
            #endregion
        }
    }
  • 相关阅读:
    团队如何限制合适的在制品(WIP)数量
    cssui库,自适应ui库
    npm i 报错 nodegyp 在此解决方案中一次生成一个项目。若要启用并行生成,请添加“/m”开关。
    20192413宗俊豪 202120222 《网络与系统攻防技术》实验五实验报告
    数据结构笔记——查找
    数据结构笔记——图
    js Object 复习
    js String
    软件工程相关术语缩写
    Angular 依赖注入的错误 NullInjectorError, No provider for XXX
  • 原文地址:https://www.cnblogs.com/imeiba/p/5697977.html
Copyright © 2020-2023  润新知