Beispiel #1
0
        // ========================================
        // constructor
        // ========================================
        public MemopadAppContext()
        {
            try {
                PathUtil.EnsureDirectoryExists(MemopadConsts.EmbeddedRoot);
                PathUtil.EnsureDirectoryExists(MemopadConsts.EmbeddedFileRoot);
                PathUtil.EnsureDirectoryExists(MemopadConsts.EmbeddedImageRoot);

                PathUtil.EnsureDirectoryExists(MemopadConsts.AutoFileImportDirPath);
                PathUtil.EnsureDirectoryExists(MemopadConsts.MyDocumentsRootPath);
            } catch (Exception ex) {
                MessageBox.Show(
                    "MochaNoteが使用するフォルダを作成できません。" + Environment.NewLine +
                    ex.Message,
                    "起動エラー",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );

                return;
            }

            FileImageDescription.RootPath = MemopadConsts.EmbeddedImageRoot;

            InitConnections();
            var store = ContainerFactory.CreateXmlSqlServerStore(_memoConnection, _exDataConnection);

            ContainerFactory.CreateContainer(
                store,
                MemopadConsts.ProxyAssemblyName,
                MemopadConsts.ProxyAssemblyFilePath
                );

            _facade = MemopadApplication.Instance;
            _facade.Init(this);
            if (_facade.IllegalSettings)
            {
                throw new ArgumentException("Illegal settings");
            }
            if (_facade.NeedRecoverMemoInfos)
            {
                /// Application.Restart()される
                _facade.RecoverMemoInfos();
            }

            //Application.ApplicationExit += HandleApplicationExit;

            _facade.LoadFusenForms();
            var isMin = _facade.WindowSettings.MinimizeToTaskTray && _facade.WindowSettings.MinimizeOnStartUp;

            if (isMin)
            {
                using (var proc = Process.GetCurrentProcess()) {
                    PsapiPI.EmptyWorkingSet(proc.Handle);
                }
            }
            else
            {
                _facade.ShowMainForm();
            }

#if !DEBUG
            _server = new MemopadServer();
            _server.Listen();
#endif
        }