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

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

        #region Field

        /// <summary>
        /// 파일 경로
        /// </summary>
        private string filePath = "Application.txt";

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Protected

        #region 시작시 처리하기 - OnStartup(e)

        /// <summary>
        /// 시작시 처리하기
        /// </summary>
        /// <param name="e">이벤트 인자</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForDomain();

            try
            {
                using(IsolatedStorageFileStream isolatedStorageFileStream = new IsolatedStorageFileStream(this.filePath, FileMode.Open, isolatedStorageFile))
                {
                    using(StreamReader streamReader = new StreamReader(isolatedStorageFileStream))
                    {
                        while(!streamReader.EndOfStream)
                        {
                            string[] keyValueArray = streamReader.ReadLine().Split(new char[] {','});
                            
                            Properties[keyValueArray[0]] = keyValueArray[1];
                        }
                    }
                }
            }
            catch(FileNotFoundException fileNotFoundException)
            {
                MessageBox.Show(fileNotFoundException.Message);
            }
        }

        #endregion

        #region 종료시 처리하기 - OnExit(e)

        /// <summary>
        /// 종료시 처리하기
        /// </summary>
        /// <param name="e">이벤트 인자</param>
        protected override void OnExit(ExitEventArgs e)
        {
            IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForDomain();

            using(IsolatedStorageFileStream isolatedStorageFileStream = new IsolatedStorageFileStream(this.filePath, FileMode.Create, isolatedStorageFile))
            {
                using(StreamWriter streamWriter = new StreamWriter(isolatedStorageFileStream))
                {
                    foreach(string key in this.Properties.Keys)
                    {
                        streamWriter.WriteLine("{0},{1}", key, Properties[key]);
                    }
                }
            }
        }

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

댓글을 달아 주세요