//-------------------------------------------------------------------

        /// @copybrief DSFMonitor::OnErrorOccured
        private void DSFMonitor_OnErrorOccured(object sender, DSFErrorOccuredEventArgs e)
        {
            if (!Utilities.IsProcessAlive(e.ProcessID))
            {
                return;
            }

            // Event: DSFErrorOccured
            {
                var message = string.Format("SCFF DirectShow Filter({0}) has encountered a problem.",
                                            e.ProcessID);
                var args    = new ErrorOccuredEventArgs(message, false);
                var handler = this.OnDSFErrorOccured;
                if (handler != null)
                {
                    handler(this, args);
                }
            }
        }
        //===================================================================
        // 外部インタフェース
        //===================================================================

        /// アプリケーションの起動処理
        /// - Argsで指定されたPathのProfileを読み込む or
        /// - LastProfileからProfileを読み込む or
        /// - Profileを新規作成
        /// @param[in] path Argsで指定されたPath
        public void Startup(string path)
        {
            // SCFF DirectShow Filterがインストールされているか
            string message;
            var    result = EnvironmentChecker.CheckSCFFDSFInstalled(out message);

            if (!result)
            {
                // Event: StartupErrorOccured
                {
                    var args    = new ErrorOccuredEventArgs(message, false);
                    var handler = this.OnStartupErrorOccured;
                    if (handler != null)
                    {
                        handler(this, args);
                    }
                }
            }

            /// @todo(me) WPFではカラーチェックを簡単にやる方法が見つからなかったので要調査

            // Options
            var optionsFile     = new OptionsFile(this.Options);
            var optionsFilePath = Utilities.ApplicationDirectory + Constants.OptionsFileName;

            optionsFile.ReadFile(optionsFilePath);

            // RuntimeOptions
            this.RuntimeOptions.RefreshDirectory(this.Interprocess);

            // 起動時にAeroがOnだったかを記録
            this.RuntimeOptions.SaveStartupAeroState();

            // Profile
            this.InitProfileInternal(path);
        }
        //-------------------------------------------------------------------
        /// @copybrief DSFMonitor::OnErrorOccured
        private void DSFMonitor_OnErrorOccured(object sender, DSFErrorOccuredEventArgs e)
        {
            if (!Utilities.IsProcessAlive(e.ProcessID)) return;

            // Event: DSFErrorOccured
            {
              var message = string.Format("SCFF DirectShow Filter({0}) has encountered a problem.",
                                  e.ProcessID);
              var args = new ErrorOccuredEventArgs(message, false);
              var handler = this.OnDSFErrorOccured;
              if (handler != null) handler(this, args);
            }
        }
        //===================================================================
        // 外部インタフェース
        //===================================================================
        /// アプリケーションの起動処理
        /// - Argsで指定されたPathのProfileを読み込む or
        /// - LastProfileからProfileを読み込む or 
        /// - Profileを新規作成
        /// @param[in] path Argsで指定されたPath
        public void Startup(string path)
        {
            // SCFF DirectShow Filterがインストールされているか
            string message;
            var result = EnvironmentChecker.CheckSCFFDSFInstalled(out message);
            if (!result) {
              // Event: StartupErrorOccured
              {
            var args = new ErrorOccuredEventArgs(message, false);
            var handler = this.OnStartupErrorOccured;
            if (handler != null) handler(this, args);
              }
            }

            /// @todo(me) WPFではカラーチェックを簡単にやる方法が見つからなかったので要調査

            // Options
            var optionsFile = new OptionsFile(this.Options);
            var optionsFilePath = Utilities.ApplicationDirectory + Constants.OptionsFileName;
            optionsFile.ReadFile(optionsFilePath);

            // RuntimeOptions
            this.RuntimeOptions.RefreshDirectory(this.Interprocess);

            // 起動時にAeroがOnだったかを記録
            this.RuntimeOptions.SaveStartupAeroState();

            // Profile
            this.InitProfileInternal(path);
        }
        /// Profileの共有メモリへの書き込み
        public bool SendProfile(bool quiet, bool forceNullLayout)
        {
            // 送る先のプロセスが存在しているか
            var processID = this.RuntimeOptions.CurrentProcessID;
            if (!Utilities.IsProcessAlive(processID)) {
              // Event: ErrorOccured
              {
            var header = "Couldn't send the profile to shared memory: ";
            var message = header + "\n  - Couldn't find process: " + processID;
            var args = new ErrorOccuredEventArgs(message, quiet);
            var handler = this.OnErrorOccured;
            if (handler != null) handler(this, args);
              }
              // モニターを解除
              this.DSFMonitor.RemoveZombie(processID);
              return false;
            }

            // 検証
            if (!forceNullLayout) {
              var errors = this.ValidateProfileInternal();
              if (!errors.IsNoError) {
            // Event: ErrorOccured
            {
              var header = "Couldn't send the profile to shared memory: ";
              var message = errors.ToErrorMessage(header);
              var args = new ErrorOccuredEventArgs(message, quiet);
              var handler = this.OnErrorOccured;
              if (handler != null) handler(this, args);
            }
            return false;
              }
            }
            // 共有メモリに書き込み
            var success = this.SendProfileInternal(forceNullLayout);
            if (!success) {
              // Event: ErrorOccured
              {
            var header = "Couldn't send the profile to shared memory: ";
            var message = header + "\n  - Couldn't access shared memory.";
            var args = new ErrorOccuredEventArgs(message, quiet);
            var handler = this.OnErrorOccured;
            if (handler != null) handler(this, args);
              }
              return false;
            }

            // DSFエラー監視開始
            this.DSFMonitor.Start(this.RuntimeOptions.CurrentProcessID);

            // Event: ProfileSent
            {
              var handler = this.OnProfileSent;
              if (handler != null) handler(this, EventArgs.Empty);
            }

            return true;
        }
        /// Profileの保存
        public bool SaveProfile(SaveActions action)
        {
            // Event: ProfileSaving
            var path = this.RuntimeOptions.ProfilePath;
            {
              var fileName = this.HasSaved
              ? this.RuntimeOptions.ProfileName
              : "Untitled";
              var initialDirectory = this.HasSaved
              ? Path.GetDirectoryName(this.RuntimeOptions.ProfilePath)
              : Utilities.ApplicationDirectory;

              var args = new ProfileSavingEventArgs(action, path, fileName, initialDirectory);
              var handler = this.OnProfileSaving;
              if (handler != null) handler(this, args);

              if (args.Cancel) {
            return false;
              } else {
            path = args.Path;
              }
            }

            // データの書き込み
            var success = this.SaveProfileInternal(path);
            if (!success) {
              // Event: ErrorOccured
              {
            var message = "Couldn't save the profile";
            if (path != null && path != string.Empty) {
              message = string.Format("Couldn't save the profile to {0}.", path);
            }
            var args = new ErrorOccuredEventArgs(message, false);
            var handler = this.OnErrorOccured;
            if (handler != null) handler(this, args);
              }
              return false;
            }

            // Event: SavedProfile
            {
              var handler = this.OnProfileSaved;
              if (handler != null) handler(this, EventArgs.Empty);
            }

            return true;
        }
        /// Profileの読み込み
        public bool OpenProfile(string path)
        {
            if (!this.CloseProfile()) return false;

            // 拡張子のチェック
            if (path != null && path != string.Empty &&
            Path.GetExtension(path) != Constants.ProfileExtension) {
              // Event: ErrorOccured
              {
            var message = string.Format("{0} must be SCFF profile(*.{1})",
                                    path, Constants.ProfileExtension);
            var args = new ErrorOccuredEventArgs(message, false);
            var handler = this.OnErrorOccured;
            if (handler != null) handler(this, args);
              }
              return false;
            }

            // Event: OpeningProfile
            {
              var initialDirectory = this.HasSaved
              ? Path.GetDirectoryName(this.RuntimeOptions.ProfilePath)
              : Utilities.ApplicationDirectory;
              var args = new ProfileOpeningEventArgs(path, initialDirectory);
              var handler = this.OnProfileOpening;
              if (handler != null) handler(this, args);

              if (args.Cancel) {
            return false;
              } else {
            path = args.Path;
              }
            }

            // データの読み込み
            var success = this.OpenProfileInternal(path);

            if (!success) {
              // Event: ErrorOccured
              {
            var message = "Couldn't open the profile";
            if (path != null && path != string.Empty) {
              message = string.Format("Couldn't open the profile from {0}.", path);
            }
            var args = new ErrorOccuredEventArgs(message, false);
            var handler = this.OnErrorOccured;
            if (handler != null) handler(this, args);
              }
              return false;
            }

            // Event: ProfileOpened
            {
              var handler = this.OnProfileOpened;
              if (handler != null) handler(this, EventArgs.Empty);
            }

            return true;
        }
        /// Profileの共有メモリへの書き込み
        public bool SendProfile(bool quiet, bool forceNullLayout)
        {
            Func <bool, bool, bool> sendprofile = (quiet1, forceNullLayout1) =>
            {
                // 送る先のプロセスが存在しているか
                var processID = this.RuntimeOptions.CurrentProcessID;
                if (!Utilities.IsProcessAlive(processID))
                {
                    // Event: ErrorOccured
                    {
                        var header  = "Couldn't send the profile to shared memory: ";
                        var message = header + "\n  - Couldn't find process: " + processID;
                        var args    = new ErrorOccuredEventArgs(message, quiet);
                        var handler = this.OnErrorOccured;
                        if (handler != null)
                        {
                            handler(this, args);
                        }
                    }
                    // モニターを解除
                    this.DSFMonitor.RemoveZombie(processID);
                    return(false);
                }

                // 検証
                if (!forceNullLayout)
                {
                    var errors = this.ValidateProfileInternal();
                    if (!errors.IsNoError)
                    {
                        // Event: ErrorOccured
                        {
                            var header  = "Couldn't send the profile to shared memory: ";
                            var message = errors.ToErrorMessage(header);
                            var args    = new ErrorOccuredEventArgs(message, quiet);
                            var handler = this.OnErrorOccured;
                            if (handler != null)
                            {
                                handler(this, args);
                            }
                        }
                        return(false);
                    }
                }
                // 共有メモリに書き込み
                var success = this.SendProfileInternal(forceNullLayout);
                if (!success)
                {
                    // Event: ErrorOccured
                    {
                        var header  = "Couldn't send the profile to shared memory: ";
                        var message = header + "\n  - Couldn't access shared memory.";
                        var args    = new ErrorOccuredEventArgs(message, quiet);
                        var handler = this.OnErrorOccured;
                        if (handler != null)
                        {
                            handler(this, args);
                        }
                    }
                    return(false);
                }

                // DSFエラー監視開始
                this.DSFMonitor.Start(this.RuntimeOptions.CurrentProcessID);

                // Event: ProfileSent
                {
                    var handler = this.OnProfileSent;
                    if (handler != null)
                    {
                        handler(this, EventArgs.Empty);
                    }
                }

                return(true);
            };

            bool ret = true;
            uint lastCurrentProcessId = RuntimeOptions.CurrentProcessID;

            foreach (var entry in this.RuntimeOptions.EntryLabels)
            {
                if (entry.Key != lastCurrentProcessId)
                {
                    RuntimeOptions.CurrentProcessID = entry.Key;
                    if (sendprofile(quiet, forceNullLayout) == false)
                    {
                        ret = false;
                    }
                }
            }
            RuntimeOptions.CurrentProcessID = lastCurrentProcessId;
            if (sendprofile(quiet, forceNullLayout) == false)
            {
                ret = false;
            }
            return(ret);
        }
        /// Profileの保存
        public bool SaveProfile(SaveActions action)
        {
            // Event: ProfileSaving
            var path = this.RuntimeOptions.ProfilePath;
            {
                var fileName = this.HasSaved
          ? this.RuntimeOptions.ProfileName
          : "Untitled";
                var initialDirectory = this.HasSaved
          ? Path.GetDirectoryName(this.RuntimeOptions.ProfilePath)
          : Utilities.ApplicationDirectory;

                var args    = new ProfileSavingEventArgs(action, path, fileName, initialDirectory);
                var handler = this.OnProfileSaving;
                if (handler != null)
                {
                    handler(this, args);
                }

                if (args.Cancel)
                {
                    return(false);
                }
                else
                {
                    path = args.Path;
                }
            }

            // データの書き込み
            var success = this.SaveProfileInternal(path);

            if (!success)
            {
                // Event: ErrorOccured
                {
                    var message = "Couldn't save the profile";
                    if (path != null && path != string.Empty)
                    {
                        message = string.Format("Couldn't save the profile to {0}.", path);
                    }
                    var args    = new ErrorOccuredEventArgs(message, false);
                    var handler = this.OnErrorOccured;
                    if (handler != null)
                    {
                        handler(this, args);
                    }
                }
                return(false);
            }

            // Event: SavedProfile
            {
                var handler = this.OnProfileSaved;
                if (handler != null)
                {
                    handler(this, EventArgs.Empty);
                }
            }

            return(true);
        }
        /// Profileの読み込み
        public bool OpenProfile(string path)
        {
            if (!this.CloseProfile())
            {
                return(false);
            }

            // 拡張子のチェック
            if (path != null && path != string.Empty &&
                Path.GetExtension(path) != Constants.ProfileExtension)
            {
                // Event: ErrorOccured
                {
                    var message = string.Format("{0} must be SCFF profile(*.{1})",
                                                path, Constants.ProfileExtension);
                    var args    = new ErrorOccuredEventArgs(message, false);
                    var handler = this.OnErrorOccured;
                    if (handler != null)
                    {
                        handler(this, args);
                    }
                }
                return(false);
            }

            // Event: OpeningProfile
            {
                var initialDirectory = this.HasSaved
          ? Path.GetDirectoryName(this.RuntimeOptions.ProfilePath)
          : Utilities.ApplicationDirectory;
                var args    = new ProfileOpeningEventArgs(path, initialDirectory);
                var handler = this.OnProfileOpening;
                if (handler != null)
                {
                    handler(this, args);
                }

                if (args.Cancel)
                {
                    return(false);
                }
                else
                {
                    path = args.Path;
                }
            }

            // データの読み込み
            var success = this.OpenProfileInternal(path);

            if (!success)
            {
                // Event: ErrorOccured
                {
                    var message = "Couldn't open the profile";
                    if (path != null && path != string.Empty)
                    {
                        message = string.Format("Couldn't open the profile from {0}.", path);
                    }
                    var args    = new ErrorOccuredEventArgs(message, false);
                    var handler = this.OnErrorOccured;
                    if (handler != null)
                    {
                        handler(this, args);
                    }
                }
                return(false);
            }

            // Event: ProfileOpened
            {
                var handler = this.OnProfileOpened;
                if (handler != null)
                {
                    handler(this, EventArgs.Empty);
                }
            }

            return(true);
        }
 //===================================================================
 // SCFF.Common.ClientApplicationイベントハンドラ
 //===================================================================
 /// @copybrief SCFF::Common::ClientApplication::OnErrorOccured
 /// @param[in] sender 使用しない
 /// @param[in] e エラー表示用のデータが格納されたオブジェクト
 private void OnErrorOccured(object sender, ErrorOccuredEventArgs e)
 {
     if (e.Quiet) return;
     MessageBox.Show(e.Message, "SCFF.GUI",
             MessageBoxButton.OK,
             MessageBoxImage.Error,
             MessageBoxResult.OK,
             MessageBoxOptions.DefaultDesktopOnly);
 }