OSDN Git Service

ビュアーモード時はサービスを起動しないよう変更。
authorくまかみ工房 <kumakamikoubou@gmail.com>
Sun, 6 Nov 2016 06:20:01 +0000 (15:20 +0900)
committerくまかみ工房 <kumakamikoubou@gmail.com>
Sun, 6 Nov 2016 06:20:01 +0000 (15:20 +0900)
StrokeStyleT/Program.cs
StrokeStyleT/StrokeStyleT.cs

index 309efab..2f6bd70 100644 (file)
@@ -15,42 +15,58 @@ namespace SST
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault( false );
 
-                       string serviceUri = "net.pipe://localhost/StrokeStyleT";
-                       string endPointName = "Viewer";
-                       string endPointUri = $"{serviceUri}/{endPointName}";
-
-                       // アプリを生成する。
+                       // アプリを生成する。ビュアーモードかどうかの判定も行う。
                        var app = new StrokeStyleT();
 
-                       // アプリのサービスホストを生成する。
-                       var serviceHost = new ServiceHost( app, new Uri( serviceUri ) );
+                       if( StrokeStyleT.ビュアーモードである )
+                       {
+                               #region " (A) ビュアーモードでの起動(WCFサービスあり)"
+                               //----------------
+                               string serviceUri = "net.pipe://localhost/StrokeStyleT";
+                               string endPointName = "Viewer";
+                               string endPointUri = $"{serviceUri}/{endPointName}";
 
-                       // 名前付きパイプにバインドしたエンドポイントをサービスホストへ追加する。
-                       serviceHost.AddServiceEndpoint(
-                               typeof( IStrokeStyleTService ),
-                               new NetNamedPipeBinding( NetNamedPipeSecurityMode.None ),
-                               endPointName );
+                               // アプリのサービスホストを生成する。
+                               var serviceHost = new ServiceHost( app, new Uri( serviceUri ) );
 
-                       // サービスの受付を開始する。
-                       try
-                       {
-                               serviceHost.Open();
-                       }
-                       catch( AddressAlreadyInUseException )
-                       {
-                               MessageBox.Show( "同じアプリがすでに起動しています。多重起動はできません。", "SST Error", MessageBoxButtons.OK );
-                               return;
-                       }
+                               // 名前付きパイプにバインドしたエンドポイントをサービスホストへ追加する。
+                               serviceHost.AddServiceEndpoint(
+                                       typeof( IStrokeStyleTService ),
+                                       new NetNamedPipeBinding( NetNamedPipeSecurityMode.None ),
+                                       endPointName );
 
-                       // アプリを実行する。
-                       try
-                       {
-                               app.Run();
+                               // サービスの受付を開始する。
+                               try
+                               {
+                                       serviceHost.Open();
+                               }
+                               catch( AddressAlreadyInUseException )
+                               {
+                                       MessageBox.Show( "同じアプリがすでに起動しています。多重起動はできません。", "SST Error", MessageBoxButtons.OK );
+                                       return;
+                               }
+
+                               // アプリを実行する。
+                               try
+                               {
+                                       app.Run();
+                               }
+                               finally
+                               {
+                                       // サービスの受付を終了する。
+                                       serviceHost.Close();
+                               }
+                               //----------------
+                               #endregion
                        }
-                       finally
+                       else
                        {
-                               // サービスの受付を終了する。
-                               serviceHost.Close();
+                               #region " (B) 通常の起動(WCFサービスなし)"
+                               //----------------
+                               // アプリを実行する。
+                               app.Run();
+                               //----------------
+                               #endregion
                        }
                }
        }
index de536cc..619c88f 100644 (file)
@@ -78,16 +78,6 @@ namespace SST
                }
                public StrokeStyleT()
                {
-                       this.State = ApplicationState.起動;
-                       this.MainForm = new SharpDX.Windows.RenderForm();
-                       this.MainForm.AllowUserResizing = false;        // ユーザはフォームサイズを変更できない。
-                       this.MainForm.UserResized += フォームサイズが変更された;
-               }
-
-               public void Run()
-               {
-                       Debug.Assert( null != this.MainForm );
-
                        #region " ビュアーモードかどうかを確認する。"
                        //----------------
                        foreach( var arg in Environment.GetCommandLineArgs() )
@@ -101,6 +91,17 @@ namespace SST
                        //----------------
                        #endregion
 
+                       this.State = ApplicationState.起動;
+
+                       this.MainForm = new SharpDX.Windows.RenderForm();
+                       this.MainForm.AllowUserResizing = false;        // ユーザはフォームサイズを変更できない。
+                       this.MainForm.UserResized += フォームサイズが変更された;
+               }
+
+               public void Run()
+               {
+                       Debug.Assert( null != this.MainForm );
+
                        SharpDX.Windows.RenderLoop.Run( this.MainForm, () => {
 
                                // アプリケーションの状態に応じて処理分岐。
@@ -125,7 +126,7 @@ namespace SST
                        } );
                }
 
-               #region " サービスインターフェースの実装 "
+               #region " WCF サービスインターフェースの実装 "
                //----------------
                // ・このサービスインターフェースは、シングルスレッド(GUIスレッド)で同期実行される。(StrokeStyleT クラスの ServiceBehavior属性を参照。)
                // ・このサービスホストはシングルトンであり、すべてのクライアントセッションは同一(単一)のサービスインスタンスへ接続される。(Program.Main() を参照。)
@@ -406,8 +407,9 @@ namespace SST
                        if( StrokeStyleT.Config.垂直帰線待ちを行う )
                        {
                                // We recommend that you use Flush when the CPU waits for an arbitrary amount of time
-                               // ( such as when you call the Sleep function). 
-                               // https://msdn.microsoft.com/ja-jp/library/windows/desktop/ff476425(v=vs.85).aspx
+                               // (such as when you call the Sleep function). 
+                               // → https://msdn.microsoft.com/ja-jp/library/windows/desktop/ff476425(v=vs.85).aspx
+
                                var d3dDevice = (SharpDX.Direct3D11.Device) null;
                                using( var d3dLock = new FDK.同期.AutoD3DDeviceLock( this.デバイスリソース.DXGIDeviceManager, out d3dDevice ) )
                                using( d3dDevice )