1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Windows;
  7.  
  8. using ESRI.ArcGIS.esriSystem;
  9. using System.Xml.Serialization;
  10. using System.IO;
  11. using SWGW.Properties;
  12. using System.Diagnostics;
  13. namespace SWGW
  14. {
  15. /// <summary>
  16. /// App.xaml 的交互逻辑
  17. /// </summary>
  18. public partial class App : Application
  19. {
  20.  
  21. #region License
  22. protected override void OnStartup(StartupEventArgs e)
  23. {
  24. SettingsManager.OnStartup();
  25. base.OnStartup(e);
  26.  
  27. if (!LicenseManager.InitializeLicense.InitializeEngineLicense())
  28. {
  29. MessageBox.Show("无法初始化ArcGIS Engine的授权或地球扩展。截止...");
  30. }
  31.  
  32. }
  33. #endregion
  34.  
  35. #region 私有类
  36. static class SettingsManager
  37. {
  38. #region Class Members
  39. static Settings settings = new Settings();
  40. const string applicationDirectory = "SWGW";
  41. //配置文件名称
  42. const string settingsFileName = "XXXX.xml";
  43. #endregion Class Members
  44.  
  45. #region Constructor
  46.  
  47. static SettingsManager()
  48. {
  49. EnsureDirectoryExists();
  50. }
  51.  
  52. #endregion Constructor
  53.  
  54. #region Properties
  55.  
  56. public static Settings ApplicationSettings
  57. {
  58. get { return settings; }
  59. }
  60.  
  61. #endregion Properties
  62.  
  63. #region Startup, Exit
  64.  
  65. public static void OnStartup()
  66. {
  67. LoadSettings();
  68. }
  69.  
  70. public static void OnExit()
  71. {
  72. SaveSettings();
  73. }
  74.  
  75. #endregion Overrides
  76.  
  77. #region Other Functions
  78.  
  79. static string SettingsFileName
  80. {
  81. get
  82. {
  83. return Path.Combine(
  84. Path.Combine(
  85. Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
  86. applicationDirectory),
  87. settingsFileName);
  88. }
  89. }
  90.  
  91. static void LoadSettings()
  92. {
  93. Settings tmp;
  94.  
  95. try
  96. {
  97. XmlSerializer xml = new XmlSerializer(typeof(Settings));
  98.  
  99. using (Stream stream = new System.IO.FileStream(SettingsFileName,
  100. FileMode.Open, FileAccess.Read, FileShare.Read))
  101. {
  102. tmp = (Settings)xml.Deserialize(stream);
  103. }
  104. }
  105. catch (Exception e)
  106. {
  107. Trace.WriteLine(e.Message);
  108. return;
  109. }
  110.  
  111. settings = tmp;
  112. }
  113.  
  114. static void SaveSettings()
  115. {
  116. try
  117. {
  118. XmlSerializer xml = new XmlSerializer(typeof(Settings));
  119.  
  120. using (Stream stream = new System.IO.FileStream(SettingsFileName,
  121. FileMode.Create, FileAccess.Write, FileShare.None))
  122. {
  123. xml.Serialize(stream, settings);
  124. }
  125. }
  126. catch (Exception e)
  127. {
  128. Trace.WriteLine(e.Message);
  129. }
  130. }
  131.  
  132. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
  133. static void EnsureDirectoryExists()
  134. {
  135. try
  136. {
  137. DirectoryInfo info = new DirectoryInfo(
  138. Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
  139. applicationDirectory));
  140.  
  141. if (!info.Exists)
  142. {
  143. info.Create();
  144. }
  145. }
  146. catch (Exception ex)
  147. {
  148. Trace.WriteLine(ex.Message);
  149. }
  150. }
  151.  
  152. #endregion Other Functions
  153. }
  154.  
  155. #endregion
  156. }
  157. }

WPF使用ARCGIS App文件配置Cs后台文件的更多相关文章

  1. webpack4 单入口文件配置 多入口文件配置 以及常用的配置

    单入口文件配置 webpack.config.js const path = require('path'); const HtmlWebpackPlugin = require('html-webp ...

  2. 虚拟主机ip配置,nginx.conf文件配置及日志文件切割

    今天粗略整理了一下虚拟主机配置,nginx.conf文件的配置,及日志文件的切割,记录如下: nginx虚拟主机配置:1.IP地址配置,2.绑定ip地址和虚拟主机详情:1.ip地址的配置:ifconf ...

  3. maven中pom文件配置解决资源文件的编码问题

    <build> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId& ...

  4. Vue插件配置和 后台交互

    Vue插件配置和 后台交互 一.全局配置静态文件(csss, js..) 1.1 全局配置css文件 创建css文件 在main.js配置css文件 // 配置全局css样式 // 方式一 impor ...

  5. mybatis 自动生成文件配置

    maven 依赖配置: <!-- sql server --><dependency> <groupId>com.microsoft.sqlserver</g ...

  6. Django-03-静态文件配置

    一.django静态文件配置原理 静态文件配置就是为了让用户请求时django服务器能找到静态文件返回. 首先要理解几个概念: 媒体文件:用户上传的文件 静态文件:css,js,image等 开发环境 ...

  7. informatica 参数文件配置

    Informatica 中 parameter file 参数文件配置规则: 参数文件的头部内容 [Global] All Integration Services, Integration Serv ...

  8. Django学习——静态文件配置、request对象方法、pycharm如何链接数据库、Django如何指定数据库、Django orm操作

    静态文件配置 # 1.静态文件 网站所使用的已经提前写好的文件 css文件 js文件 img文件 第三方文件 我们在存储静态文件资源的时候一般默认都是放在static文件夹下 # 2.Django静态 ...

  9. c#Winform程序调用app.config文件配置数据库连接字符串 SQL Server文章目录 浅谈SQL Server中统计对于查询的影响 有关索引的DMV SQL Server中的执行引擎入门 【译】表变量和临时表的比较 对于表列数据类型选择的一点思考 SQL Server复制入门(一)----复制简介 操作系统中的进程与线程

    c#Winform程序调用app.config文件配置数据库连接字符串 你新建winform项目的时候,会有一个app.config的配置文件,写在里面的<connectionStrings n ...

随机推荐

  1. AC日记——矩阵取数游戏 洛谷 P1005

    矩阵取数游戏 思路: dp+高精: 代码: #include <bits/stdc++.h> using namespace std; #define ll long long struc ...

  2. Vue结合原生js实现自定义组件自动生成

    就目前三大前端主流数据驱动框架(vue,ng,react)而言,均具有创建自定义组件的api,但都是必须先做到事先写好挂载点,这个挂载点可以是原有静态元素标签也可以是自定义模板:对于多种组件通过同一数 ...

  3. IllegalStateException: Unable to find a @SpringBootConfiguration

    此处需要改掉包名和类名

  4. 在centos 6.9安装wordpress,浏览器不能访问问题

    在centos 6.9安装wordpress浏览器访问先出现403错误,然后提示access denied nginx错误打印FastCGI sent in stderr: "Unable ...

  5. Optional int parameter 'id' is present but cannot be translated into a null value due to being decla

    这个错误可以将参数由int改为Integer

  6. python学习第一天_环境的搭建

    Python linux环境的安装: 1.https://www.python.org/ftp/python/ 大家可以在这里下载自己所需的linux下的版本 ,这里我下载的2.6.6版本: 2.在C ...

  7. VMware Workstation虚拟机进入BIOS

    1.<F2>键 2.

  8. Flask实战第57天:UEditor编辑器集成以及配置上传文件到七牛

    相关链接 UEditor:http://ueditor.baidu.com/website/​ 下载地址:http://ueditor.baidu.com/website/download.html# ...

  9. Python开发基础-Day21多态与多态性、绑定方法和非绑定方法

    多态与多态性 多态 多态并不是一个新的知识 多态是指一类事物有多种形态,在类里就是指一个抽象类有多个子类,因而多态的概念依赖于继承 举个栗子:动物有多种形态,人.狗.猫.猪等,python的序列数据类 ...

  10. 【枚举】【最小表示法】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem F. Matrix Game

    给你一个n*m的字符矩阵,将横向(或纵向)全部裂开,然后以任意顺序首尾相接,然后再从中间任意位置切开,问你能构成的字典序最大的字符串. 以横向切开为例,纵向类似. 将所有横排从大到小排序,枚举最后切开 ...