Adding WCF server implementation.
authorsl
Tue, 12 Aug 2014 20:37:57 +0200
changeset 1719c1aaf900dc
parent 16 985ca4b6e099
child 18 7acec5059fa6
Adding WCF server implementation.
MainForm.Designer.cs
MainForm.cs
MarqueeLabel.cs
Program.cs
Servers.cs
Services.cs
SharpDisplayManager.csproj
     1.1 --- a/MainForm.Designer.cs	Mon Aug 11 23:18:45 2014 +0200
     1.2 +++ b/MainForm.Designer.cs	Tue Aug 12 20:37:57 2014 +0200
     1.3 @@ -35,8 +35,6 @@
     1.4              this.checkBoxConnectOnStartup = new System.Windows.Forms.CheckBox();
     1.5              this.panelDisplay = new System.Windows.Forms.Panel();
     1.6              this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
     1.7 -            this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel();
     1.8 -            this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel();
     1.9              this.checkBoxShowBorders = new System.Windows.Forms.CheckBox();
    1.10              this.trackBarBrightness = new System.Windows.Forms.TrackBar();
    1.11              this.buttonFill = new System.Windows.Forms.Button();
    1.12 @@ -53,6 +51,8 @@
    1.13              this.toolStripStatusLabelSpring = new System.Windows.Forms.ToolStripStatusLabel();
    1.14              this.toolStripStatusLabelPower = new System.Windows.Forms.ToolStripStatusLabel();
    1.15              this.toolStripStatusLabelFps = new System.Windows.Forms.ToolStripStatusLabel();
    1.16 +            this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel();
    1.17 +            this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel();
    1.18              this.tabControl.SuspendLayout();
    1.19              this.tabPageDisplay.SuspendLayout();
    1.20              this.panelDisplay.SuspendLayout();
    1.21 @@ -202,39 +202,6 @@
    1.22              this.tableLayoutPanel.Size = new System.Drawing.Size(256, 64);
    1.23              this.tableLayoutPanel.TabIndex = 5;
    1.24              // 
    1.25 -            // marqueeLabelTop
    1.26 -            // 
    1.27 -            this.marqueeLabelTop.AutoEllipsis = true;
    1.28 -            this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent;
    1.29 -            this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill;
    1.30 -            this.marqueeLabelTop.Location = new System.Drawing.Point(1, 1);
    1.31 -            this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0);
    1.32 -            this.marqueeLabelTop.Name = "marqueeLabelTop";
    1.33 -            this.marqueeLabelTop.OwnTimer = false;
    1.34 -            this.marqueeLabelTop.PixelsPerSecond = 64;
    1.35 -            this.marqueeLabelTop.Separator = "|";
    1.36 -            this.marqueeLabelTop.Size = new System.Drawing.Size(254, 30);
    1.37 -            this.marqueeLabelTop.TabIndex = 2;
    1.38 -            this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
    1.39 -            this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
    1.40 -            this.marqueeLabelTop.UseCompatibleTextRendering = true;
    1.41 -            // 
    1.42 -            // marqueeLabelBottom
    1.43 -            // 
    1.44 -            this.marqueeLabelBottom.AutoEllipsis = true;
    1.45 -            this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill;
    1.46 -            this.marqueeLabelBottom.Location = new System.Drawing.Point(1, 32);
    1.47 -            this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0);
    1.48 -            this.marqueeLabelBottom.Name = "marqueeLabelBottom";
    1.49 -            this.marqueeLabelBottom.OwnTimer = false;
    1.50 -            this.marqueeLabelBottom.PixelsPerSecond = 64;
    1.51 -            this.marqueeLabelBottom.Separator = null;
    1.52 -            this.marqueeLabelBottom.Size = new System.Drawing.Size(254, 31);
    1.53 -            this.marqueeLabelBottom.TabIndex = 3;
    1.54 -            this.marqueeLabelBottom.Text = "abcdefghijklmnopqrst-0123456789";
    1.55 -            this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
    1.56 -            this.marqueeLabelBottom.UseCompatibleTextRendering = true;
    1.57 -            // 
    1.58              // checkBoxShowBorders
    1.59              // 
    1.60              this.checkBoxShowBorders.AutoSize = true;
    1.61 @@ -375,6 +342,39 @@
    1.62              this.toolStripStatusLabelFps.Size = new System.Drawing.Size(26, 17);
    1.63              this.toolStripStatusLabelFps.Text = "FPS";
    1.64              // 
    1.65 +            // marqueeLabelTop
    1.66 +            // 
    1.67 +            this.marqueeLabelTop.AutoEllipsis = true;
    1.68 +            this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent;
    1.69 +            this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill;
    1.70 +            this.marqueeLabelTop.Location = new System.Drawing.Point(1, -124);
    1.71 +            this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0);
    1.72 +            this.marqueeLabelTop.Name = "marqueeLabelTop";
    1.73 +            this.marqueeLabelTop.OwnTimer = false;
    1.74 +            this.marqueeLabelTop.PixelsPerSecond = 64;
    1.75 +            this.marqueeLabelTop.Separator = "|";
    1.76 +            this.marqueeLabelTop.Size = new System.Drawing.Size(254, 20);
    1.77 +            this.marqueeLabelTop.TabIndex = 2;
    1.78 +            this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
    1.79 +            this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
    1.80 +            this.marqueeLabelTop.UseCompatibleTextRendering = true;
    1.81 +            // 
    1.82 +            // marqueeLabelBottom
    1.83 +            // 
    1.84 +            this.marqueeLabelBottom.AutoEllipsis = true;
    1.85 +            this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill;
    1.86 +            this.marqueeLabelBottom.Location = new System.Drawing.Point(1, -40);
    1.87 +            this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0);
    1.88 +            this.marqueeLabelBottom.Name = "marqueeLabelBottom";
    1.89 +            this.marqueeLabelBottom.OwnTimer = false;
    1.90 +            this.marqueeLabelBottom.PixelsPerSecond = 64;
    1.91 +            this.marqueeLabelBottom.Separator = null;
    1.92 +            this.marqueeLabelBottom.Size = new System.Drawing.Size(254, 20);
    1.93 +            this.marqueeLabelBottom.TabIndex = 3;
    1.94 +            this.marqueeLabelBottom.Text = "abcdefghijklmnopqrst-0123456789";
    1.95 +            this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
    1.96 +            this.marqueeLabelBottom.UseCompatibleTextRendering = true;
    1.97 +            // 
    1.98              // MainForm
    1.99              // 
   1.100              this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
   1.101 @@ -385,6 +385,7 @@
   1.102              this.MinimumSize = new System.Drawing.Size(640, 480);
   1.103              this.Name = "MainForm";
   1.104              this.Text = "Sharp Display Manager";
   1.105 +            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing);
   1.106              this.Load += new System.EventHandler(this.MainForm_Load);
   1.107              this.Resize += new System.EventHandler(this.MainForm_Resize);
   1.108              this.tabControl.ResumeLayout(false);
   1.109 @@ -422,8 +423,8 @@
   1.110          private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelPower;
   1.111          private System.Windows.Forms.Panel panelDisplay;
   1.112          private System.Windows.Forms.TableLayoutPanel tableLayoutPanel;
   1.113 -        private MarqueeLabel marqueeLabelTop;
   1.114 -        private MarqueeLabel marqueeLabelBottom;
   1.115 +        public MarqueeLabel marqueeLabelTop;
   1.116 +        public MarqueeLabel marqueeLabelBottom;
   1.117          private System.Windows.Forms.CheckBox checkBoxConnectOnStartup;
   1.118          private System.Windows.Forms.CheckBox checkBoxReverseScreen;
   1.119      }
     2.1 --- a/MainForm.cs	Mon Aug 11 23:18:45 2014 +0200
     2.2 +++ b/MainForm.cs	Tue Aug 12 20:37:57 2014 +0200
     2.3 @@ -10,6 +10,7 @@
     2.4  using System.IO;
     2.5  using CodeProject.Dialog;
     2.6  using System.Drawing.Imaging;
     2.7 +using System.ServiceModel;
     2.8  
     2.9  
    2.10  namespace SharpDisplayManager
    2.11 @@ -20,6 +21,7 @@
    2.12          Display iDisplay;
    2.13          System.Drawing.Bitmap iBmp;
    2.14          bool iCreateBitmap; //Workaround render to bitmap issues when minimized
    2.15 +        ServiceHost iServiceHost;
    2.16  
    2.17          public MainForm()
    2.18          {
    2.19 @@ -44,6 +46,8 @@
    2.20  
    2.21          private void MainForm_Load(object sender, EventArgs e)
    2.22          {
    2.23 +            StartServer();
    2.24 +
    2.25              if (Properties.Settings.Default.DisplayConnectOnStartup)
    2.26              {
    2.27                  iDisplay.Open();
    2.28 @@ -92,6 +96,8 @@
    2.29              //Bitmap bmpToSave = new Bitmap(bmp);
    2.30              bmp.Save("D:\\capture.png");
    2.31  
    2.32 +            marqueeLabelTop.Text = "Sweet";
    2.33 +
    2.34              /*
    2.35              string outputFileName = "d:\\capture.png";
    2.36              using (MemoryStream memory = new MemoryStream())
    2.37 @@ -334,5 +340,29 @@
    2.38              }
    2.39          }
    2.40  
    2.41 +        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
    2.42 +        {
    2.43 +            StopServer();
    2.44 +        }
    2.45 +
    2.46 +        public void StartServer()
    2.47 +        {
    2.48 +            iServiceHost = new ServiceHost
    2.49 +                (
    2.50 +                    typeof(DisplayServer),
    2.51 +                    new Uri[] { new Uri("net.pipe://localhost") }
    2.52 +                );
    2.53 +
    2.54 +            iServiceHost.AddServiceEndpoint(typeof(IDisplayService), new NetNamedPipeBinding(), "DisplayService");
    2.55 +            iServiceHost.Open();
    2.56 +        }
    2.57 +
    2.58 +        public void StopServer()
    2.59 +        {
    2.60 +            //Tell connected client first? Is that possible?
    2.61 +            iServiceHost.Close();
    2.62 +        }
    2.63 +
    2.64 +
    2.65      }
    2.66  }
     3.1 --- a/MarqueeLabel.cs	Mon Aug 11 23:18:45 2014 +0200
     3.2 +++ b/MarqueeLabel.cs	Tue Aug 12 20:37:57 2014 +0200
     3.3 @@ -12,7 +12,7 @@
     3.4  namespace SharpDisplayManager
     3.5  {
     3.6      [System.ComponentModel.DesignerCategory("Code")]
     3.7 -    class MarqueeLabel : Label
     3.8 +    public class MarqueeLabel : Label
     3.9      {
    3.10          private bool iOwnTimer;
    3.11          private StringFormat iStringFormat;
     4.1 --- a/Program.cs	Mon Aug 11 23:18:45 2014 +0200
     4.2 +++ b/Program.cs	Tue Aug 12 20:37:57 2014 +0200
     4.3 @@ -8,6 +8,7 @@
     4.4  {
     4.5      static class Program
     4.6      {
     4.7 +        public static MainForm iMainForm;
     4.8          /// <summary>
     4.9          /// The main entry point for the application.
    4.10          /// </summary>
    4.11 @@ -16,7 +17,8 @@
    4.12          {
    4.13              Application.EnableVisualStyles();
    4.14              Application.SetCompatibleTextRenderingDefault(false);
    4.15 -            Application.Run(new MainForm());
    4.16 +            iMainForm = new MainForm();
    4.17 +            Application.Run(iMainForm);
    4.18          }
    4.19      }
    4.20  }
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/Servers.cs	Tue Aug 12 20:37:57 2014 +0200
     5.3 @@ -0,0 +1,27 @@
     5.4 +using System;
     5.5 +using System.Windows.Forms;
     5.6 +
     5.7 +namespace SharpDisplayManager
     5.8 +{
     5.9 +    /// <summary>
    5.10 +    /// Implement our display service.
    5.11 +    /// This class is instantiated anew whenever a client send a request.
    5.12 +    /// </summary>
    5.13 +    class DisplayServer : IDisplayService
    5.14 +    {
    5.15 +        //From IDisplayService
    5.16 +        public void SetText(int aLineIndex, string aText)
    5.17 +        {
    5.18 +            if (aLineIndex == 0)
    5.19 +            {
    5.20 +                Program.iMainForm.marqueeLabelTop.Text = aText;
    5.21 +            }
    5.22 +            else if (aLineIndex == 1)
    5.23 +            {
    5.24 +                Program.iMainForm.marqueeLabelBottom.Text = aText;
    5.25 +            }
    5.26 +        }
    5.27 +
    5.28 +    }
    5.29 +
    5.30 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/Services.cs	Tue Aug 12 20:37:57 2014 +0200
     6.3 @@ -0,0 +1,12 @@
     6.4 +using System;
     6.5 +using System.ServiceModel;
     6.6 +
     6.7 +namespace SharpDisplayManager
     6.8 +{
     6.9 +    [ServiceContract]
    6.10 +    public interface IDisplayService
    6.11 +    {
    6.12 +        [OperationContract]
    6.13 +        void SetText(int aLineIndex, string aText);
    6.14 +    }
    6.15 +}
     7.1 --- a/SharpDisplayManager.csproj	Mon Aug 11 23:18:45 2014 +0200
     7.2 +++ b/SharpDisplayManager.csproj	Tue Aug 12 20:37:57 2014 +0200
     7.3 @@ -36,6 +36,7 @@
     7.4      <Reference Include="Microsoft.VisualBasic.PowerPacks.Vs, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
     7.5      <Reference Include="System" />
     7.6      <Reference Include="System.Core" />
     7.7 +    <Reference Include="System.ServiceModel" />
     7.8      <Reference Include="System.Xml.Linq" />
     7.9      <Reference Include="System.Data.DataSetExtensions" />
    7.10      <Reference Include="Microsoft.CSharp" />
    7.11 @@ -58,6 +59,8 @@
    7.12      <Compile Include="MarqueeLabel.cs" />
    7.13      <Compile Include="Program.cs" />
    7.14      <Compile Include="Properties\AssemblyInfo.cs" />
    7.15 +    <Compile Include="Servers.cs" />
    7.16 +    <Compile Include="Services.cs" />
    7.17      <Compile Include="Win32API.cs" />
    7.18      <Compile Include="WindowsHook.cs" />
    7.19      <Compile Include="WndProcRetHook.cs" />