zoukankan      html  css  js  c++  java
  • 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
        }
    }
  • 相关阅读:
    【Linux软件安装】
    Java IO(七)ByteArrayInputStream 和 ByteArrayOutputStream
    Java IO(六) ObjectInputStream 和 ObjectOutputStream
    Java IO(四) InputStream 和 OutputStream
    Java IO(五)字节流 FileInputStream 和 FileOutputStream
    Java IO(三)FileDescriptor
    Java IO(二)File
    Java IO(一)概述
    Java中的集合(十五) Iterator 和 ListIterator、Enumeration
    Java中的自动装箱拆箱
  • 原文地址:https://www.cnblogs.com/imeiba/p/5697977.html
Copyright © 2011-2022 走看看