첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.01MB

▶ MainApplication.xaml

<Application x:Class="TestProject.MainApplication"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="MainWindow.xaml"
    Startup="Application_Startup"
    Exit="Application_Exit">
</Application>

 

▶ MainApplication.xaml.cs

using System.IO;
using System.IO.IsolatedStorage;
using System.Windows;

namespace TestProject
{
    /// <summary>
    /// 메인 애플리케이션
    /// </summary>
    public partial class MainApplication : Application
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 파일명
        /// </summary>
        private string fileName = "MainApplication.setting";

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainApplication()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainApplication()
        {
            Properties["COUNT"] = 100;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 애플리케이션 시작시 처리하기 - Application_Startup(sender, e)

        /// <summary>
        /// 애플리케이션 시작시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // C:\Users\계정명\AppData\Local\IsolatedStorage
            IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForDomain();

            try
            {
                using(IsolatedStorageFileStream stream = new IsolatedStorageFileStream(this.fileName, FileMode.Open, storageFile))
                {
                    using(StreamReader reader = new StreamReader(stream))
                    {
                        while(!reader.EndOfStream)
                        {
                            string[] keyValueArray = reader.ReadLine().Split(new char[] { ',' });

                            Properties[keyValueArray[0]] = keyValueArray[1];
                        }
                    }
                }
            }
            catch(FileNotFoundException)
            {
            }
        }

        #endregion
        #region 애플리케이션 종료시 처리하기 - Application_Exit(sender, e)

        /// <summary>
        /// 애플리케이션 종료시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Application_Exit(object sender, ExitEventArgs e)
        {
            IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForDomain();

            using(IsolatedStorageFileStream stream = new IsolatedStorageFileStream(this.fileName, FileMode.Create, storageFile))
            {
                using(StreamWriter writer = new StreamWriter(stream))
                {
                    foreach(string key in this.Properties.Keys)
                    {
                        writer.WriteLine("{0},{1}", key, Properties[key]);
                    }
                }
            }
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요