# HG changeset patch # User StephaneLenclud # Date 1469624758 -7200 # Node ID f6272f65d8fcbc209b3a595d7dceeb8877fe7c24 # Parent 0e8c6c2f4777b07930576a931a498f4f2099ecbe Adding action move and test buttons. diff -r 0e8c6c2f4777 -r f6272f65d8fc Server/Actions/ActionCecActiveSource.cs --- a/Server/Actions/ActionCecActiveSource.cs Wed Jul 27 11:07:35 2016 +0200 +++ b/Server/Actions/ActionCecActiveSource.cs Wed Jul 27 15:05:58 2016 +0200 @@ -25,7 +25,7 @@ /// /// Set the defined device type as active source. /// - public override void Execute() + public override void DoExecute() { if (Cec.Client.Static == null) { diff -r 0e8c6c2f4777 -r f6272f65d8fc Server/Actions/ActionCecClose.cs --- a/Server/Actions/ActionCecClose.cs Wed Jul 27 11:07:35 2016 +0200 +++ b/Server/Actions/ActionCecClose.cs Wed Jul 27 15:05:58 2016 +0200 @@ -13,7 +13,7 @@ [AttributeAction(Id = "Cec.Close", Name = "CEC Close", Description = "Close CEC connection.")] class ActionCecClose : SharpLib.Ear.Action { - public override void Execute() + public override void DoExecute() { if (Cec.Client.Static == null) { diff -r 0e8c6c2f4777 -r f6272f65d8fc Server/Actions/ActionCecDevicePowerOn.cs --- a/Server/Actions/ActionCecDevicePowerOn.cs Wed Jul 27 11:07:35 2016 +0200 +++ b/Server/Actions/ActionCecDevicePowerOn.cs Wed Jul 27 15:05:58 2016 +0200 @@ -26,7 +26,7 @@ /// /// /// - public override void Execute() + public override void DoExecute() { if (Cec.Client.Static == null) { diff -r 0e8c6c2f4777 -r f6272f65d8fc Server/Actions/ActionCecDeviceStandby.cs --- a/Server/Actions/ActionCecDeviceStandby.cs Wed Jul 27 11:07:35 2016 +0200 +++ b/Server/Actions/ActionCecDeviceStandby.cs Wed Jul 27 15:05:58 2016 +0200 @@ -26,7 +26,7 @@ /// /// /// - public override void Execute() + public override void DoExecute() { if (Cec.Client.Static == null) { diff -r 0e8c6c2f4777 -r f6272f65d8fc Server/Actions/ActionCecInactiveSource.cs --- a/Server/Actions/ActionCecInactiveSource.cs Wed Jul 27 11:07:35 2016 +0200 +++ b/Server/Actions/ActionCecInactiveSource.cs Wed Jul 27 15:05:58 2016 +0200 @@ -13,7 +13,7 @@ [AttributeAction(Id = "Cec.InactiveSource", Name = "CEC Inactive Source", Description = "Set this CEC device as inactive source.")] class ActionCecInactiveSource : SharpLib.Ear.Action { - public override void Execute() + public override void DoExecute() { if (Cec.Client.Static == null) { diff -r 0e8c6c2f4777 -r f6272f65d8fc Server/Actions/ActionCecOpen.cs --- a/Server/Actions/ActionCecOpen.cs Wed Jul 27 11:07:35 2016 +0200 +++ b/Server/Actions/ActionCecOpen.cs Wed Jul 27 15:05:58 2016 +0200 @@ -13,7 +13,7 @@ [AttributeAction(Id = "Cec.Open", Name = "CEC Open", Description = "Open CEC connection.")] class ActionCecOpen : SharpLib.Ear.Action { - public override void Execute() + public override void DoExecute() { if (Cec.Client.Static == null) { diff -r 0e8c6c2f4777 -r f6272f65d8fc Server/Actions/ActionCecScan.cs --- a/Server/Actions/ActionCecScan.cs Wed Jul 27 11:07:35 2016 +0200 +++ b/Server/Actions/ActionCecScan.cs Wed Jul 27 15:05:58 2016 +0200 @@ -14,7 +14,7 @@ [AttributeAction(Id = "Cec.Scan", Name = "CEC Scan", Description = "Scan devices on your CEC HDMI network.")] class ActionCecScan : SharpLib.Ear.Action { - public override void Execute() + public override void DoExecute() { if (Cec.Client.Static == null) { diff -r 0e8c6c2f4777 -r f6272f65d8fc Server/Actions/ActionCecUserControlPressed.cs --- a/Server/Actions/ActionCecUserControlPressed.cs Wed Jul 27 11:07:35 2016 +0200 +++ b/Server/Actions/ActionCecUserControlPressed.cs Wed Jul 27 15:05:58 2016 +0200 @@ -56,7 +56,7 @@ /// /// /// - public override void Execute() + public override void DoExecute() { if (Cec.Client.Static == null) { diff -r 0e8c6c2f4777 -r f6272f65d8fc Server/Actions/ActionCecUserControlReleased.cs --- a/Server/Actions/ActionCecUserControlReleased.cs Wed Jul 27 11:07:35 2016 +0200 +++ b/Server/Actions/ActionCecUserControlReleased.cs Wed Jul 27 15:05:58 2016 +0200 @@ -48,7 +48,7 @@ /// /// /// - public override void Execute() + public override void DoExecute() { if (Cec.Client.Static == null) { diff -r 0e8c6c2f4777 -r f6272f65d8fc Server/FormEditAction.cs --- a/Server/FormEditAction.cs Wed Jul 27 11:07:35 2016 +0200 +++ b/Server/FormEditAction.cs Wed Jul 27 15:05:58 2016 +0200 @@ -142,7 +142,7 @@ //Data source is fine but it gives us duplicate entries for duplicated enum values //ctrl.DataSource = Enum.GetValues(aInfo.PropertyType); - //Therefore we need to explicitly create our items + //Therefore we need to explicitly create our items foreach (string name in aInfo.PropertyType.GetEnumNames()) { ctrl.Items.Add(name.ToString()); @@ -252,7 +252,8 @@ //Add our editor to our form iTableLayoutPanel.Controls.Add(ctrl, 1, iTableLayoutPanel.RowCount - 1); - + //Add tooltip to editor too + toolTip.SetToolTip(ctrl, attribute.Description); } diff -r 0e8c6c2f4777 -r f6272f65d8fc Server/MainForm.Designer.cs --- a/Server/MainForm.Designer.cs Wed Jul 27 11:07:35 2016 +0200 +++ b/Server/MainForm.Designer.cs Wed Jul 27 15:05:58 2016 +0200 @@ -110,6 +110,9 @@ this.labelHdmiPort = new System.Windows.Forms.Label(); this.comboBoxHdmiPort = new System.Windows.Forms.ComboBox(); this.tabPageEvent = new System.Windows.Forms.TabPage(); + this.buttonActionMoveUp = new System.Windows.Forms.Button(); + this.buttonActionMoveDown = new System.Windows.Forms.Button(); + this.buttonTestAction = new System.Windows.Forms.Button(); this.buttonDeleteAction = new System.Windows.Forms.Button(); this.buttonAddAction = new System.Windows.Forms.Button(); this.iTreeViewEvents = new System.Windows.Forms.TreeView(); @@ -969,6 +972,9 @@ // // tabPageEvent // + this.tabPageEvent.Controls.Add(this.buttonActionMoveUp); + this.tabPageEvent.Controls.Add(this.buttonActionMoveDown); + this.tabPageEvent.Controls.Add(this.buttonTestAction); this.tabPageEvent.Controls.Add(this.buttonDeleteAction); this.tabPageEvent.Controls.Add(this.buttonAddAction); this.tabPageEvent.Controls.Add(this.iTreeViewEvents); @@ -980,6 +986,39 @@ this.tabPageEvent.Text = "Events"; this.tabPageEvent.UseVisualStyleBackColor = true; // + // buttonActionMoveUp + // + this.buttonActionMoveUp.Enabled = false; + this.buttonActionMoveUp.Location = new System.Drawing.Point(6, 327); + this.buttonActionMoveUp.Name = "buttonActionMoveUp"; + this.buttonActionMoveUp.Size = new System.Drawing.Size(96, 23); + this.buttonActionMoveUp.TabIndex = 24; + this.buttonActionMoveUp.Text = "Move Up"; + this.buttonActionMoveUp.UseVisualStyleBackColor = true; + this.buttonActionMoveUp.Click += new System.EventHandler(this.buttonActionMoveUp_Click); + // + // buttonActionMoveDown + // + this.buttonActionMoveDown.Enabled = false; + this.buttonActionMoveDown.Location = new System.Drawing.Point(6, 356); + this.buttonActionMoveDown.Name = "buttonActionMoveDown"; + this.buttonActionMoveDown.Size = new System.Drawing.Size(96, 23); + this.buttonActionMoveDown.TabIndex = 23; + this.buttonActionMoveDown.Text = "Move Down"; + this.buttonActionMoveDown.UseVisualStyleBackColor = true; + this.buttonActionMoveDown.Click += new System.EventHandler(this.buttonActionMoveDown_Click); + // + // buttonTestAction + // + this.buttonTestAction.Enabled = false; + this.buttonTestAction.Location = new System.Drawing.Point(6, 64); + this.buttonTestAction.Name = "buttonTestAction"; + this.buttonTestAction.Size = new System.Drawing.Size(96, 23); + this.buttonTestAction.TabIndex = 22; + this.buttonTestAction.Text = "Test Action"; + this.buttonTestAction.UseVisualStyleBackColor = true; + this.buttonTestAction.Click += new System.EventHandler(this.buttonTestAction_Click); + // // buttonDeleteAction // this.buttonDeleteAction.Enabled = false; @@ -1007,6 +1046,7 @@ this.iTreeViewEvents.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.iTreeViewEvents.HideSelection = false; this.iTreeViewEvents.Location = new System.Drawing.Point(111, 3); this.iTreeViewEvents.Name = "iTreeViewEvents"; this.iTreeViewEvents.Size = new System.Drawing.Size(638, 376); @@ -1273,6 +1313,9 @@ private System.Windows.Forms.TreeView iTreeViewEvents; private System.Windows.Forms.Button buttonDeleteAction; private System.Windows.Forms.Button buttonAddAction; + private System.Windows.Forms.Button buttonActionMoveUp; + private System.Windows.Forms.Button buttonActionMoveDown; + private System.Windows.Forms.Button buttonTestAction; } } diff -r 0e8c6c2f4777 -r f6272f65d8fc Server/MainForm.cs --- a/Server/MainForm.cs Wed Jul 27 11:07:35 2016 +0200 +++ b/Server/MainForm.cs Wed Jul 27 15:05:58 2016 +0200 @@ -52,23 +52,33 @@ { //Types declarations public delegate uint ColorProcessingDelegate(int aX, int aY, uint aPixel); + public delegate int CoordinateTranslationDelegate(System.Drawing.Bitmap aBmp, int aInt); + //Delegates are used for our thread safe method public delegate void AddClientDelegate(string aSessionId, ICallback aCallback); + public delegate void RemoveClientDelegate(string aSessionId); + public delegate void SetFieldDelegate(string SessionId, DataField aField); + public delegate void SetFieldsDelegate(string SessionId, System.Collections.Generic.IList aFields); + public delegate void SetLayoutDelegate(string SessionId, TableLayout aLayout); + public delegate void SetClientNameDelegate(string aSessionId, string aName); + public delegate void SetClientPriorityDelegate(string aSessionId, uint aPriority); + public delegate void PlainUpdateDelegate(); + public delegate void WndProcDelegate(ref Message aMessage); /// /// Our Display manager main form /// - [System.ComponentModel.DesignerCategory("Form")] - public partial class MainForm : MainFormHid, IMMNotificationClient + [System.ComponentModel.DesignerCategory("Form")] + public partial class MainForm : MainFormHid, IMMNotificationClient { //public ManagerEventAction iManager = new ManagerEventAction(); DateTime LastTickTime; @@ -83,35 +93,35 @@ ClientData iCurrentClientData; // public bool iClosing; - // - public bool iSkipFrameRendering; + // + public bool iSkipFrameRendering; //Function pointer for pixel color filtering ColorProcessingDelegate iColorFx; //Function pointer for pixel X coordinate intercept CoordinateTranslationDelegate iScreenX; //Function pointer for pixel Y coordinate intercept CoordinateTranslationDelegate iScreenY; - //NAudio - private MMDeviceEnumerator iMultiMediaDeviceEnumerator; - private MMDevice iMultiMediaDevice; - //Network - private NetworkManager iNetworkManager; + //NAudio + private MMDeviceEnumerator iMultiMediaDeviceEnumerator; + private MMDevice iMultiMediaDevice; + //Network + private NetworkManager iNetworkManager; /// /// CEC - Consumer Electronic Control. /// Notably used to turn TV on and off as Windows broadcast monitor on and off notifications. /// private ConsumerElectronicControl iCecManager; - - /// - /// Manage run when Windows startup option - /// - private StartupManager iStartupManager; - - /// - /// System notification icon used to hide our application from the task bar. - /// - private SharpLib.Notification.Control iNotifyIcon; + + /// + /// Manage run when Windows startup option + /// + private StartupManager iStartupManager; + + /// + /// System notification icon used to hide our application from the task bar. + /// + private SharpLib.Notification.Control iNotifyIcon; /// /// System recording notification icon. @@ -145,18 +155,18 @@ ManagerEventAction.Current.Init(); } iSkipFrameRendering = false; - iClosing = false; + iClosing = false; iCurrentClientSessionId = ""; iCurrentClientData = null; LastTickTime = DateTime.Now; - //Instantiate our display and register for events notifications + //Instantiate our display and register for events notifications iDisplay = new Display(); - iDisplay.OnOpened += OnDisplayOpened; - iDisplay.OnClosed += OnDisplayClosed; - // - iClients = new Dictionary(); - iStartupManager = new StartupManager(); - iNotifyIcon = new SharpLib.Notification.Control(); + iDisplay.OnOpened += OnDisplayOpened; + iDisplay.OnClosed += OnDisplayClosed; + // + iClients = new Dictionary(); + iStartupManager = new StartupManager(); + iNotifyIcon = new SharpLib.Notification.Control(); iRecordingNotification = new SharpLib.Notification.Control(); //Have our designer initialize its controls @@ -172,50 +182,51 @@ //Populate optical drives PopulateOpticalDrives(); - //Initial status update + //Initial status update UpdateStatus(); //We have a bug when drawing minimized and reusing our bitmap //Though I could not reproduce it on Windows 10 - iBmp = new System.Drawing.Bitmap(iTableLayoutPanel.Width, iTableLayoutPanel.Height, PixelFormat.Format32bppArgb); + iBmp = new System.Drawing.Bitmap(iTableLayoutPanel.Width, iTableLayoutPanel.Height, + PixelFormat.Format32bppArgb); iCreateBitmap = false; - //Minimize our window if desired - if (Properties.Settings.Default.StartMinimized) - { - WindowState = FormWindowState.Minimized; - } + //Minimize our window if desired + if (Properties.Settings.Default.StartMinimized) + { + WindowState = FormWindowState.Minimized; + } } - /// - /// - /// - /// - /// + /// + /// + /// + /// + /// private void MainForm_Load(object sender, EventArgs e) { - //Check if we are running a Click Once deployed application - if (ApplicationDeployment.IsNetworkDeployed) - { - //This is a proper Click Once installation, fetch and show our version number - this.Text += " - v" + ApplicationDeployment.CurrentDeployment.CurrentVersion; - } - else - { - //Not a proper Click Once installation, assuming development build then - this.Text += " - development"; - } - - //NAudio - iMultiMediaDeviceEnumerator = new MMDeviceEnumerator(); - iMultiMediaDeviceEnumerator.RegisterEndpointNotificationCallback(this); - UpdateAudioDeviceAndMasterVolumeThreadSafe(); - - //Network - iNetworkManager = new NetworkManager(); - iNetworkManager.OnConnectivityChanged += OnConnectivityChanged; - UpdateNetworkStatus(); + //Check if we are running a Click Once deployed application + if (ApplicationDeployment.IsNetworkDeployed) + { + //This is a proper Click Once installation, fetch and show our version number + this.Text += " - v" + ApplicationDeployment.CurrentDeployment.CurrentVersion; + } + else + { + //Not a proper Click Once installation, assuming development build then + this.Text += " - development"; + } + + //NAudio + iMultiMediaDeviceEnumerator = new MMDeviceEnumerator(); + iMultiMediaDeviceEnumerator.RegisterEndpointNotificationCallback(this); + UpdateAudioDeviceAndMasterVolumeThreadSafe(); + + //Network + iNetworkManager = new NetworkManager(); + iNetworkManager.OnConnectivityChanged += OnConnectivityChanged; + UpdateNetworkStatus(); //CEC iCecManager = new ConsumerElectronicControl(); @@ -233,29 +244,29 @@ // To make sure start up with minimize to tray works if (WindowState == FormWindowState.Minimized && Properties.Settings.Default.MinimizeToTray) - { - Visible = false; - } + { + Visible = false; + } #if !DEBUG - //When not debugging we want the screen to be empty until a client takes over + //When not debugging we want the screen to be empty until a client takes over ClearLayout(); #else - //When developing we want at least one client for testing - StartNewClient("abcdefghijklmnopqrst-0123456789","ABCDEFGHIJKLMNOPQRST-0123456789"); + //When developing we want at least one client for testing + StartNewClient("abcdefghijklmnopqrst-0123456789", "ABCDEFGHIJKLMNOPQRST-0123456789"); #endif - //Open display connection on start-up if needed - if (Properties.Settings.Default.DisplayConnectOnStartup) - { - OpenDisplayConnection(); - } - - //Start our server so that we can get client requests - StartServer(); - - //Register for HID events - RegisterHidDevices(); + //Open display connection on start-up if needed + if (Properties.Settings.Default.DisplayConnectOnStartup) + { + OpenDisplayConnection(); + } + + //Start our server so that we can get client requests + StartServer(); + + //Register for HID events + RegisterHidDevices(); //Start Idle client if needed if (Properties.Settings.Default.StartIdleClient) @@ -264,40 +275,40 @@ } } - /// - /// Called when our display is opened. - /// - /// - private void OnDisplayOpened(Display aDisplay) - { + /// + /// Called when our display is opened. + /// + /// + private void OnDisplayOpened(Display aDisplay) + { //Make sure we resume frame rendering iSkipFrameRendering = false; - //Set our screen size now that our display is connected - //Our panelDisplay is the container of our tableLayoutPanel - //tableLayoutPanel will resize itself to fit the client size of our panelDisplay - //panelDisplay needs an extra 2 pixels for borders on each sides - //tableLayoutPanel will eventually be the exact size of our display - Size size = new Size(iDisplay.WidthInPixels() + 2, iDisplay.HeightInPixels() + 2); - panelDisplay.Size = size; - - //Our display was just opened, update our UI - UpdateStatus(); - //Initiate asynchronous request - iDisplay.RequestFirmwareRevision(); - - //Audio - UpdateMasterVolumeThreadSafe(); - //Network - UpdateNetworkStatus(); + //Set our screen size now that our display is connected + //Our panelDisplay is the container of our tableLayoutPanel + //tableLayoutPanel will resize itself to fit the client size of our panelDisplay + //panelDisplay needs an extra 2 pixels for borders on each sides + //tableLayoutPanel will eventually be the exact size of our display + Size size = new Size(iDisplay.WidthInPixels() + 2, iDisplay.HeightInPixels() + 2); + panelDisplay.Size = size; + + //Our display was just opened, update our UI + UpdateStatus(); + //Initiate asynchronous request + iDisplay.RequestFirmwareRevision(); + + //Audio + UpdateMasterVolumeThreadSafe(); + //Network + UpdateNetworkStatus(); #if DEBUG - //Testing icon in debug, no arm done if icon not supported - //iDisplay.SetIconStatus(Display.TMiniDisplayIconType.EMiniDisplayIconRecording, 0, 1); - //iDisplay.SetAllIconsStatus(2); + //Testing icon in debug, no arm done if icon not supported + //iDisplay.SetIconStatus(Display.TMiniDisplayIconType.EMiniDisplayIconRecording, 0, 1); + //iDisplay.SetAllIconsStatus(2); #endif - } + } /// /// Populate tree view with events and actions @@ -309,6 +320,8 @@ buttonDeleteAction.Enabled = false; Event currentEvent = CurrentEvent(); + SharpLib.Ear.Action currentAction = CurrentAction(); + TreeNode treeNodeToSelect = null; //Reset our tree iTreeViewEvents.Nodes.Clear(); @@ -316,7 +329,7 @@ foreach (string key in ManagerEventAction.Current.Events.Keys) { Event e = ManagerEventAction.Current.Events[key]; - TreeNode eventNode = iTreeViewEvents.Nodes.Add(key,e.Name); + TreeNode eventNode = iTreeViewEvents.Nodes.Add(key, e.Name); eventNode.Tag = e; eventNode.Nodes.Add(key + ".Description", e.Description); TreeNode actionsNodes = eventNode.Nodes.Add(key + ".Actions", "Actions"); @@ -326,82 +339,96 @@ { TreeNode actionNode = actionsNodes.Nodes.Add(a.Brief()); actionNode.Tag = a; + if (a == currentAction) + { + treeNodeToSelect = actionNode; + } } } iTreeViewEvents.ExpandAll(); SelectEvent(currentEvent); - //Select the last action if any - if (iTreeViewEvents.SelectedNode!= null && iTreeViewEvents.SelectedNode.Nodes[1].GetNodeCount(false) > 0) + + if (treeNodeToSelect != null) { - iTreeViewEvents.SelectedNode = iTreeViewEvents.SelectedNode.Nodes[1].Nodes[iTreeViewEvents.SelectedNode.Nodes[1].GetNodeCount(false)-1]; + iTreeViewEvents.SelectedNode = treeNodeToSelect; } + else if (iTreeViewEvents.SelectedNode != null && iTreeViewEvents.SelectedNode.Nodes[1].GetNodeCount(false) > 0) + { + //Select the last action if any + iTreeViewEvents.SelectedNode = + iTreeViewEvents.SelectedNode.Nodes[1].Nodes[ + iTreeViewEvents.SelectedNode.Nodes[1].GetNodeCount(false) - 1]; + } } - /// - /// Called when our display is closed. - /// - /// - private void OnDisplayClosed(Display aDisplay) - { + /// + /// Called when our display is closed. + /// + /// + private void OnDisplayClosed(Display aDisplay) + { //Our display was just closed, update our UI consequently UpdateStatus(); - } - - public void OnConnectivityChanged(NetworkManager aNetwork, NLM_CONNECTIVITY newConnectivity) - { - //Update network status - UpdateNetworkStatus(); - } - - /// - /// Update our Network Status - /// - private void UpdateNetworkStatus() - { - if (iDisplay.IsOpen()) - { - iDisplay.SetIconOnOff(MiniDisplay.IconType.Internet, iNetworkManager.NetworkListManager.IsConnectedToInternet); + } + + public void OnConnectivityChanged(NetworkManager aNetwork, NLM_CONNECTIVITY newConnectivity) + { + //Update network status + UpdateNetworkStatus(); + } + + /// + /// Update our Network Status + /// + private void UpdateNetworkStatus() + { + if (iDisplay.IsOpen()) + { + iDisplay.SetIconOnOff(MiniDisplay.IconType.Internet, + iNetworkManager.NetworkListManager.IsConnectedToInternet); iDisplay.SetIconOnOff(MiniDisplay.IconType.NetworkSignal, iNetworkManager.NetworkListManager.IsConnected); - } - } - - - int iLastNetworkIconIndex = 0; - int iUpdateCountSinceLastNetworkAnimation = 0; - - /// - /// - /// - private void UpdateNetworkSignal(DateTime aLastTickTime, DateTime aNewTickTime) - { - iUpdateCountSinceLastNetworkAnimation++; - iUpdateCountSinceLastNetworkAnimation = iUpdateCountSinceLastNetworkAnimation % 4; - - if (iDisplay.IsOpen() && iNetworkManager.NetworkListManager.IsConnected && iUpdateCountSinceLastNetworkAnimation==0) - { + } + } + + + int iLastNetworkIconIndex = 0; + int iUpdateCountSinceLastNetworkAnimation = 0; + + /// + /// + /// + private void UpdateNetworkSignal(DateTime aLastTickTime, DateTime aNewTickTime) + { + iUpdateCountSinceLastNetworkAnimation++; + iUpdateCountSinceLastNetworkAnimation = iUpdateCountSinceLastNetworkAnimation%4; + + if (iDisplay.IsOpen() && iNetworkManager.NetworkListManager.IsConnected && + iUpdateCountSinceLastNetworkAnimation == 0) + { int iconCount = iDisplay.IconCount(MiniDisplay.IconType.NetworkSignal); - if (iconCount <= 0) - { - //Prevents div by zero and other undefined behavior - return; - } - iLastNetworkIconIndex++; - iLastNetworkIconIndex = iLastNetworkIconIndex % (iconCount*2); - for (int i=0;i 3) && !(i == 1 && iLastNetworkIconIndex > 4)) - { + if (iconCount <= 0) + { + //Prevents div by zero and other undefined behavior + return; + } + iLastNetworkIconIndex++; + iLastNetworkIconIndex = iLastNetworkIconIndex%(iconCount*2); + for (int i = 0; i < iconCount; i++) + { + if (i < iLastNetworkIconIndex && !(i == 0 && iLastNetworkIconIndex > 3) && + !(i == 1 && iLastNetworkIconIndex > 4)) + { iDisplay.SetIconOn(MiniDisplay.IconType.NetworkSignal, i); - } - else - { + } + else + { iDisplay.SetIconOff(MiniDisplay.IconType.NetworkSignal, i); - } - } - } - } + } + } + } + } @@ -411,7 +438,7 @@ /// public void OnVolumeNotificationThreadSafe(AudioVolumeNotificationData data) { - UpdateMasterVolumeThreadSafe(); + UpdateMasterVolumeThreadSafe(); } /// @@ -421,42 +448,50 @@ /// private void trackBarMasterVolume_Scroll(object sender, EventArgs e) { - //Just like Windows Volume Mixer we unmute if the volume is adjusted - iMultiMediaDevice.AudioEndpointVolume.Mute = false; - //Set volume level according to our volume slider new position - iMultiMediaDevice.AudioEndpointVolume.MasterVolumeLevelScalar = trackBarMasterVolume.Value / 100.0f; + //Just like Windows Volume Mixer we unmute if the volume is adjusted + iMultiMediaDevice.AudioEndpointVolume.Mute = false; + //Set volume level according to our volume slider new position + iMultiMediaDevice.AudioEndpointVolume.MasterVolumeLevelScalar = trackBarMasterVolume.Value/100.0f; } - /// - /// Mute check box changed. - /// - /// - /// - private void checkBoxMute_CheckedChanged(object sender, EventArgs e) - { - iMultiMediaDevice.AudioEndpointVolume.Mute = checkBoxMute.Checked; - } + /// + /// Mute check box changed. + /// + /// + /// + private void checkBoxMute_CheckedChanged(object sender, EventArgs e) + { + iMultiMediaDevice.AudioEndpointVolume.Mute = checkBoxMute.Checked; + } /// /// Device State Changed /// - public void OnDeviceStateChanged([MarshalAs(UnmanagedType.LPWStr)] string deviceId, [MarshalAs(UnmanagedType.I4)] DeviceState newState){} + public void OnDeviceStateChanged([MarshalAs(UnmanagedType.LPWStr)] string deviceId, + [MarshalAs(UnmanagedType.I4)] DeviceState newState) + { + } /// /// Device Added /// - public void OnDeviceAdded([MarshalAs(UnmanagedType.LPWStr)] string pwstrDeviceId) { } + public void OnDeviceAdded([MarshalAs(UnmanagedType.LPWStr)] string pwstrDeviceId) + { + } /// /// Device Removed /// - public void OnDeviceRemoved([MarshalAs(UnmanagedType.LPWStr)] string deviceId) { } + public void OnDeviceRemoved([MarshalAs(UnmanagedType.LPWStr)] string deviceId) + { + } /// /// Default Device Changed /// - public void OnDefaultDeviceChanged(DataFlow flow, Role role, [MarshalAs(UnmanagedType.LPWStr)] string defaultDeviceId) + public void OnDefaultDeviceChanged(DataFlow flow, Role role, + [MarshalAs(UnmanagedType.LPWStr)] string defaultDeviceId) { if (role == Role.Multimedia && flow == DataFlow.Render) { @@ -469,73 +504,77 @@ /// /// /// - public void OnPropertyValueChanged([MarshalAs(UnmanagedType.LPWStr)] string pwstrDeviceId, PropertyKey key){} - - - - - /// - /// Update master volume indicators based our current system states. - /// This typically includes volume levels and mute status. - /// - private void UpdateMasterVolumeThreadSafe() - { - if (this.InvokeRequired) - { - //Not in the proper thread, invoke ourselves - PlainUpdateDelegate d = new PlainUpdateDelegate(UpdateMasterVolumeThreadSafe); - this.Invoke(d, new object[] { }); - return; - } - - //Update volume slider - float volumeLevelScalar = iMultiMediaDevice.AudioEndpointVolume.MasterVolumeLevelScalar; - trackBarMasterVolume.Value = Convert.ToInt32(volumeLevelScalar * 100); - //Update mute checkbox - checkBoxMute.Checked = iMultiMediaDevice.AudioEndpointVolume.Mute; - - //If our display connection is open we need to update its icons - if (iDisplay.IsOpen()) - { - //First take care our our volume level icons + public void OnPropertyValueChanged([MarshalAs(UnmanagedType.LPWStr)] string pwstrDeviceId, PropertyKey key) + { + } + + + + + /// + /// Update master volume indicators based our current system states. + /// This typically includes volume levels and mute status. + /// + private void UpdateMasterVolumeThreadSafe() + { + if (this.InvokeRequired) + { + //Not in the proper thread, invoke ourselves + PlainUpdateDelegate d = new PlainUpdateDelegate(UpdateMasterVolumeThreadSafe); + this.Invoke(d, new object[] {}); + return; + } + + //Update volume slider + float volumeLevelScalar = iMultiMediaDevice.AudioEndpointVolume.MasterVolumeLevelScalar; + trackBarMasterVolume.Value = Convert.ToInt32(volumeLevelScalar*100); + //Update mute checkbox + checkBoxMute.Checked = iMultiMediaDevice.AudioEndpointVolume.Mute; + + //If our display connection is open we need to update its icons + if (iDisplay.IsOpen()) + { + //First take care our our volume level icons int volumeIconCount = iDisplay.IconCount(MiniDisplay.IconType.Volume); - if (volumeIconCount > 0) - { - //Compute current volume level from system level and the number of segments in our display volume bar. - //That tells us how many segments in our volume bar needs to be turned on. - float currentVolume = volumeLevelScalar * volumeIconCount; - int segmentOnCount = Convert.ToInt32(currentVolume); - //Check if our segment count was rounded up, this will later be used for half brightness segment - bool roundedUp = segmentOnCount > currentVolume; - - for (int i = 0; i < volumeIconCount; i++) - { - if (i < segmentOnCount) - { - //If we are dealing with our last segment and our segment count was rounded up then we will use half brightness. - if (i == segmentOnCount - 1 && roundedUp) - { - //Half brightness - iDisplay.SetIconStatus(MiniDisplay.IconType.Volume, i, (iDisplay.IconStatusCount(MiniDisplay.IconType.Volume) - 1) / 2); - } - else - { - //Full brightness - iDisplay.SetIconStatus(MiniDisplay.IconType.Volume, i, iDisplay.IconStatusCount(MiniDisplay.IconType.Volume) - 1); - } - } - else - { + if (volumeIconCount > 0) + { + //Compute current volume level from system level and the number of segments in our display volume bar. + //That tells us how many segments in our volume bar needs to be turned on. + float currentVolume = volumeLevelScalar*volumeIconCount; + int segmentOnCount = Convert.ToInt32(currentVolume); + //Check if our segment count was rounded up, this will later be used for half brightness segment + bool roundedUp = segmentOnCount > currentVolume; + + for (int i = 0; i < volumeIconCount; i++) + { + if (i < segmentOnCount) + { + //If we are dealing with our last segment and our segment count was rounded up then we will use half brightness. + if (i == segmentOnCount - 1 && roundedUp) + { + //Half brightness + iDisplay.SetIconStatus(MiniDisplay.IconType.Volume, i, + (iDisplay.IconStatusCount(MiniDisplay.IconType.Volume) - 1)/2); + } + else + { + //Full brightness + iDisplay.SetIconStatus(MiniDisplay.IconType.Volume, i, + iDisplay.IconStatusCount(MiniDisplay.IconType.Volume) - 1); + } + } + else + { iDisplay.SetIconStatus(MiniDisplay.IconType.Volume, i, 0); - } - } - } - - //Take care of our mute icon + } + } + } + + //Take care of our mute icon iDisplay.SetIconOnOff(MiniDisplay.IconType.Mute, iMultiMediaDevice.AudioEndpointVolume.Mute); - } - - } + } + + } /// /// @@ -545,48 +584,48 @@ if (this.InvokeRequired) { //Not in the proper thread, invoke ourselves - PlainUpdateDelegate d = new PlainUpdateDelegate(UpdateAudioDeviceAndMasterVolumeThreadSafe); - this.Invoke(d, new object[] { }); + PlainUpdateDelegate d = new PlainUpdateDelegate(UpdateAudioDeviceAndMasterVolumeThreadSafe); + this.Invoke(d, new object[] {}); return; } - + //We are in the correct thread just go ahead. try - { + { //Get our master volume - iMultiMediaDevice = iMultiMediaDeviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); - //Update our label - labelDefaultAudioDevice.Text = iMultiMediaDevice.FriendlyName; + iMultiMediaDevice = iMultiMediaDeviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); + //Update our label + labelDefaultAudioDevice.Text = iMultiMediaDevice.FriendlyName; //Show our volume in our track bar - UpdateMasterVolumeThreadSafe(); + UpdateMasterVolumeThreadSafe(); //Register to get volume modifications - iMultiMediaDevice.AudioEndpointVolume.OnVolumeNotification += OnVolumeNotificationThreadSafe; + iMultiMediaDevice.AudioEndpointVolume.OnVolumeNotification += OnVolumeNotificationThreadSafe; // - trackBarMasterVolume.Enabled = true; + trackBarMasterVolume.Enabled = true; } catch (Exception ex) { Debug.WriteLine("Exception thrown in UpdateAudioDeviceAndMasterVolume"); Debug.WriteLine(ex.ToString()); //Something went wrong S/PDIF device ca throw exception I guess - trackBarMasterVolume.Enabled = false; + trackBarMasterVolume.Enabled = false; } } - /// - /// - /// - private void PopulateDeviceTypes() - { - int count = Display.TypeCount(); - - for (int i = 0; i < count; i++) - { - comboBoxDisplayType.Items.Add(Display.TypeName((MiniDisplay.Type)i)); - } - } + /// + /// + /// + private void PopulateDeviceTypes() + { + int count = Display.TypeCount(); + + for (int i = 0; i < count; i++) + { + comboBoxDisplayType.Items.Add(Display.TypeName((MiniDisplay.Type) i)); + } + } /// /// @@ -604,12 +643,12 @@ Debug.WriteLine("Drive " + d.Name); Debug.WriteLine(" Drive type: {0}", d.DriveType); - if (d.DriveType==DriveType.CDRom) + if (d.DriveType == DriveType.CDRom) { //This is an optical drive, add it now - comboBoxOpticalDrives.Items.Add(d.Name.Substring(0,2)); - } - } + comboBoxOpticalDrives.Items.Add(d.Name.Substring(0, 2)); + } + } } /// @@ -623,44 +662,44 @@ - /// - /// - /// - private void SetupTrayIcon() - { - iNotifyIcon.Icon = GetIcon("vfd.ico"); - iNotifyIcon.Text = "Sharp Display Manager"; - iNotifyIcon.Visible = true; - - //Double click toggles visibility - typically brings up the application - iNotifyIcon.DoubleClick += delegate(object obj, EventArgs args) - { - SysTrayHideShow(); - }; - - //Adding a context menu, useful to be able to exit the application - ContextMenu contextMenu = new ContextMenu(); - //Context menu item to toggle visibility - MenuItem hideShowItem = new MenuItem("Hide/Show"); - hideShowItem.Click += delegate(object obj, EventArgs args) - { - SysTrayHideShow(); - }; - contextMenu.MenuItems.Add(hideShowItem); - - //Context menu item separator - contextMenu.MenuItems.Add(new MenuItem("-")); - - //Context menu exit item - MenuItem exitItem = new MenuItem("Exit"); - exitItem.Click += delegate(object obj, EventArgs args) - { - Application.Exit(); - }; - contextMenu.MenuItems.Add(exitItem); - - iNotifyIcon.ContextMenu = contextMenu; - } + /// + /// + /// + private void SetupTrayIcon() + { + iNotifyIcon.Icon = GetIcon("vfd.ico"); + iNotifyIcon.Text = "Sharp Display Manager"; + iNotifyIcon.Visible = true; + + //Double click toggles visibility - typically brings up the application + iNotifyIcon.DoubleClick += delegate(object obj, EventArgs args) + { + SysTrayHideShow(); + }; + + //Adding a context menu, useful to be able to exit the application + ContextMenu contextMenu = new ContextMenu(); + //Context menu item to toggle visibility + MenuItem hideShowItem = new MenuItem("Hide/Show"); + hideShowItem.Click += delegate(object obj, EventArgs args) + { + SysTrayHideShow(); + }; + contextMenu.MenuItems.Add(hideShowItem); + + //Context menu item separator + contextMenu.MenuItems.Add(new MenuItem("-")); + + //Context menu exit item + MenuItem exitItem = new MenuItem("Exit"); + exitItem.Click += delegate(object obj, EventArgs args) + { + Application.Exit(); + }; + contextMenu.MenuItems.Add(exitItem); + + iNotifyIcon.ContextMenu = contextMenu; + } /// /// @@ -678,22 +717,22 @@ /// /// public static Icon GetIcon(string aName) - { - string[] names = Assembly.GetExecutingAssembly().GetManifestResourceNames(); - foreach (string name in names) - { + { + string[] names = Assembly.GetExecutingAssembly().GetManifestResourceNames(); + foreach (string name in names) + { //Find a resource name that ends with the given name - if (name.EndsWith(aName)) - { - using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name)) - { - return new Icon(stream); - } - } - } - - return null; - } + if (name.EndsWith(aName)) + { + using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name)) + { + return new Icon(stream); + } + } + } + + return null; + } /// @@ -701,7 +740,7 @@ /// This will take care of applying our client layout and set data fields. /// /// - void SetCurrentClient(string aSessionId, bool aForce=false) + void SetCurrentClient(string aSessionId, bool aForce = false) { if (aSessionId == iCurrentClientSessionId) { @@ -728,7 +767,8 @@ //Thus a background client can set this to zero allowing any other client to interrupt at any time //We could also compute this delay by looking at the requests frequencies? if (!aForce && - requestedClientData.Priority == iCurrentClientData.Priority && //Time sharing is only if clients have the same priority + requestedClientData.Priority == iCurrentClientData.Priority && + //Time sharing is only if clients have the same priority (lastSwitchToClientSecondsAgo < 30)) //Make sure a client is on for at least 30 seconds { //Don't switch clients too often @@ -773,7 +813,7 @@ { if (ctrl is MarqueeLabel) { - ((MarqueeLabel)ctrl).Font = fontDialog.Font; + ((MarqueeLabel) ctrl).Font = fontDialog.Font; } } @@ -809,7 +849,7 @@ { if (ctrl is MarqueeLabel) { - label = (MarqueeLabel)ctrl; + label = (MarqueeLabel) ctrl; break; } } @@ -817,7 +857,8 @@ //Now check font height and show a warning if needed. if (label != null && label.Font.Height > label.Height) { - labelWarning.Text = "WARNING: Selected font is too height by " + (label.Font.Height - label.Height) + " pixels!"; + labelWarning.Text = "WARNING: Selected font is too height by " + (label.Font.Height - label.Height) + + " pixels!"; labelWarning.Visible = true; } else @@ -834,7 +875,7 @@ //Bitmap bmpToSave = new Bitmap(bmp); bmp.Save("D:\\capture.png"); - ((MarqueeLabel)iTableLayoutPanel.Controls[0]).Text = "Captured"; + ((MarqueeLabel) iTableLayoutPanel.Controls[0]).Text = "Captured"; /* string outputFileName = "d:\\capture.png"; @@ -905,11 +946,11 @@ public static uint ColorChessboard(int aX, int aY, uint aPixel) { - if ((aX % 2 == 0) && (aY % 2 == 0)) + if ((aX%2 == 0) && (aY%2 == 0)) { return ~aPixel; } - else if ((aX % 2 != 0) && (aY % 2 != 0)) + else if ((aX%2 != 0) && (aY%2 != 0)) { return ~aPixel; } @@ -977,14 +1018,14 @@ //Update our animations DateTime NewTickTime = DateTime.Now; - UpdateNetworkSignal(LastTickTime, NewTickTime); + UpdateNetworkSignal(LastTickTime, NewTickTime); //Update animation for all our marquees foreach (Control ctrl in iTableLayoutPanel.Controls) { if (ctrl is MarqueeLabel) { - ((MarqueeLabel)ctrl).UpdateAnimation(LastTickTime, NewTickTime); + ((MarqueeLabel) ctrl).UpdateAnimation(LastTickTime, NewTickTime); } } @@ -993,82 +1034,84 @@ { CheckForRequestResults(); - //Check if frame rendering is needed - //Typically used when showing clock - if (!iSkipFrameRendering) - { - //Draw to bitmap - if (iCreateBitmap) - { - iBmp = new System.Drawing.Bitmap(iTableLayoutPanel.Width, iTableLayoutPanel.Height, PixelFormat.Format32bppArgb); + //Check if frame rendering is needed + //Typically used when showing clock + if (!iSkipFrameRendering) + { + //Draw to bitmap + if (iCreateBitmap) + { + iBmp = new System.Drawing.Bitmap(iTableLayoutPanel.Width, iTableLayoutPanel.Height, + PixelFormat.Format32bppArgb); iCreateBitmap = false; } - iTableLayoutPanel.DrawToBitmap(iBmp, iTableLayoutPanel.ClientRectangle); - //iBmp.Save("D:\\capture.png"); - - //Send it to our display - for (int i = 0; i < iBmp.Width; i++) - { - for (int j = 0; j < iBmp.Height; j++) - { - unchecked - { - //Get our processed pixel coordinates - int x = iScreenX(iBmp, i); - int y = iScreenY(iBmp, j); - //Get pixel color - uint color = (uint)iBmp.GetPixel(i, j).ToArgb(); - //Apply color effects - color = iColorFx(x, y, color); - //Now set our pixel - iDisplay.SetPixel(x, y, color); - } - } - } - - iDisplay.SwapBuffers(); - } + iTableLayoutPanel.DrawToBitmap(iBmp, iTableLayoutPanel.ClientRectangle); + //iBmp.Save("D:\\capture.png"); + + //Send it to our display + for (int i = 0; i < iBmp.Width; i++) + { + for (int j = 0; j < iBmp.Height; j++) + { + unchecked + { + //Get our processed pixel coordinates + int x = iScreenX(iBmp, i); + int y = iScreenY(iBmp, j); + //Get pixel color + uint color = (uint) iBmp.GetPixel(i, j).ToArgb(); + //Apply color effects + color = iColorFx(x, y, color); + //Now set our pixel + iDisplay.SetPixel(x, y, color); + } + } + } + + iDisplay.SwapBuffers(); + } } //Compute instant FPS - toolStripStatusLabelFps.Text = (1.0/NewTickTime.Subtract(LastTickTime).TotalSeconds).ToString("F0") + " / " + (1000/timer.Interval).ToString() + " FPS"; + toolStripStatusLabelFps.Text = (1.0/NewTickTime.Subtract(LastTickTime).TotalSeconds).ToString("F0") + " / " + + (1000/timer.Interval).ToString() + " FPS"; LastTickTime = NewTickTime; } - /// - /// Attempt to establish connection with our display hardware. - /// + /// + /// Attempt to establish connection with our display hardware. + /// private void OpenDisplayConnection() { CloseDisplayConnection(); - if (!iDisplay.Open((MiniDisplay.Type)cds.DisplayType)) - { - UpdateStatus(); - toolStripStatusLabelConnect.Text = "Connection error"; + if (!iDisplay.Open((MiniDisplay.Type) cds.DisplayType)) + { + UpdateStatus(); + toolStripStatusLabelConnect.Text = "Connection error"; } } private void CloseDisplayConnection() { - //Status will be updated upon receiving the closed event - - if (iDisplay == null || !iDisplay.IsOpen()) - { - return; - } - - //Do not clear if we gave up on rendering already. - //This means we will keep on displaying clock on MDM166AA for instance. - if (!iSkipFrameRendering) - { - iDisplay.Clear(); - iDisplay.SwapBuffers(); - } - - iDisplay.SetAllIconsStatus(0); //Turn off all icons + //Status will be updated upon receiving the closed event + + if (iDisplay == null || !iDisplay.IsOpen()) + { + return; + } + + //Do not clear if we gave up on rendering already. + //This means we will keep on displaying clock on MDM166AA for instance. + if (!iSkipFrameRendering) + { + iDisplay.Clear(); + iDisplay.SwapBuffers(); + } + + iDisplay.SetAllIconsStatus(0); //Turn off all icons iDisplay.Close(); } @@ -1137,13 +1180,14 @@ public float IsFixedWidth(Font ft) { Graphics g = CreateGraphics(); - char[] charSizes = new char[] { 'i', 'a', 'Z', '%', '#', 'a', 'B', 'l', 'm', ',', '.' }; + char[] charSizes = new char[] {'i', 'a', 'Z', '%', '#', 'a', 'B', 'l', 'm', ',', '.'}; float charWidth = g.MeasureString("I", ft, Int32.MaxValue, StringFormat.GenericTypographic).Width; bool fixedWidth = true; foreach (char c in charSizes) - if (g.MeasureString(c.ToString(), ft, Int32.MaxValue, StringFormat.GenericTypographic).Width != charWidth) + if (g.MeasureString(c.ToString(), ft, Int32.MaxValue, StringFormat.GenericTypographic).Width != + charWidth) fixedWidth = false; if (fixedWidth) @@ -1154,14 +1198,16 @@ return 0.0f; } - /// - /// Synchronize UI with settings - /// + /// + /// Synchronize UI with settings + /// private void UpdateStatus() - { + { //Load settings checkBoxShowBorders.Checked = cds.ShowBorders; - iTableLayoutPanel.CellBorderStyle = (cds.ShowBorders ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None); + iTableLayoutPanel.CellBorderStyle = (cds.ShowBorders + ? TableLayoutPanelCellBorderStyle.Single + : TableLayoutPanelCellBorderStyle.None); //Set the proper font to each of our labels foreach (MarqueeLabel ctrl in iTableLayoutPanel.Controls) @@ -1170,20 +1216,20 @@ } CheckFontHeight(); - //Check if "run on Windows startup" is enabled - checkBoxAutoStart.Checked = iStartupManager.Startup; - // + //Check if "run on Windows startup" is enabled + checkBoxAutoStart.Checked = iStartupManager.Startup; + // checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup; - checkBoxMinimizeToTray.Checked = Properties.Settings.Default.MinimizeToTray; - checkBoxStartMinimized.Checked = Properties.Settings.Default.StartMinimized; + checkBoxMinimizeToTray.Checked = Properties.Settings.Default.MinimizeToTray; + checkBoxStartMinimized.Checked = Properties.Settings.Default.StartMinimized; iCheckBoxStartIdleClient.Checked = Properties.Settings.Default.StartIdleClient; labelStartFileName.Text = Properties.Settings.Default.StartFileName; //Try find our drive in our drive list - int opticalDriveItemIndex=0; + int opticalDriveItemIndex = 0; bool driveNotFound = true; - string opticalDriveToEject=Properties.Settings.Default.OpticalDriveToEject; + string opticalDriveToEject = Properties.Settings.Default.OpticalDriveToEject; foreach (object item in comboBoxOpticalDrives.Items) { if (opticalDriveToEject == item.ToString()) @@ -1209,12 +1255,12 @@ //Mini Display settings checkBoxReverseScreen.Checked = cds.ReverseScreen; checkBoxInverseColors.Checked = cds.InverseColors; - checkBoxShowVolumeLabel.Checked = cds.ShowVolumeLabel; + checkBoxShowVolumeLabel.Checked = cds.ShowVolumeLabel; checkBoxScaleToFit.Checked = cds.ScaleToFit; maskedTextBoxMinFontSize.Enabled = cds.ScaleToFit; labelMinFontSize.Enabled = cds.ScaleToFit; maskedTextBoxMinFontSize.Text = cds.MinFontSize.ToString(); - maskedTextBoxScrollingSpeed.Text = cds.ScrollingSpeedInPixelsPerSecond.ToString(); + maskedTextBoxScrollingSpeed.Text = cds.ScrollingSpeedInPixelsPerSecond.ToString(); comboBoxDisplayType.SelectedIndex = cds.DisplayType; timer.Interval = cds.TimerInterval; maskedTextBoxTimerInterval.Text = cds.TimerInterval.ToString(); @@ -1228,29 +1274,29 @@ //Reflect that in our UI StartTimer(); - iTableLayoutPanel.Enabled = true; - panelDisplay.Enabled = true; + iTableLayoutPanel.Enabled = true; + panelDisplay.Enabled = true; //Only setup brightness if display is open trackBarBrightness.Minimum = iDisplay.MinBrightness(); trackBarBrightness.Maximum = iDisplay.MaxBrightness(); - if (cds.Brightness < iDisplay.MinBrightness() || cds.Brightness > iDisplay.MaxBrightness()) - { - //Brightness out of range, this can occur when using auto-detect - //Use max brightness instead - trackBarBrightness.Value = iDisplay.MaxBrightness(); - iDisplay.SetBrightness(iDisplay.MaxBrightness()); - } - else - { - trackBarBrightness.Value = cds.Brightness; - iDisplay.SetBrightness(cds.Brightness); - } - - //Try compute the steps to something that makes sense - trackBarBrightness.LargeChange = Math.Max(1, (iDisplay.MaxBrightness() - iDisplay.MinBrightness()) / 5); + if (cds.Brightness < iDisplay.MinBrightness() || cds.Brightness > iDisplay.MaxBrightness()) + { + //Brightness out of range, this can occur when using auto-detect + //Use max brightness instead + trackBarBrightness.Value = iDisplay.MaxBrightness(); + iDisplay.SetBrightness(iDisplay.MaxBrightness()); + } + else + { + trackBarBrightness.Value = cds.Brightness; + iDisplay.SetBrightness(cds.Brightness); + } + + //Try compute the steps to something that makes sense + trackBarBrightness.LargeChange = Math.Max(1, (iDisplay.MaxBrightness() - iDisplay.MinBrightness())/5); trackBarBrightness.SmallChange = 1; - + // buttonFill.Enabled = true; buttonClear.Enabled = true; @@ -1282,18 +1328,18 @@ buttonHideClock.Enabled = false; } - - //Check if Volume Label is supported. To date only MDM166AA supports that crap :) - checkBoxShowVolumeLabel.Enabled = iDisplay.IconCount(MiniDisplay.IconType.VolumeLabel)>0; - - if (cds.ShowVolumeLabel) - { + + //Check if Volume Label is supported. To date only MDM166AA supports that crap :) + checkBoxShowVolumeLabel.Enabled = iDisplay.IconCount(MiniDisplay.IconType.VolumeLabel) > 0; + + if (cds.ShowVolumeLabel) + { iDisplay.SetIconOn(MiniDisplay.IconType.VolumeLabel); - } - else - { + } + else + { iDisplay.SetIconOff(MiniDisplay.IconType.VolumeLabel); - } + } } else { @@ -1303,12 +1349,12 @@ //In debug start our timer even if we don't have a display connection StartTimer(); #else - //In production environment we don't need our timer if no display connection + //In production environment we don't need our timer if no display connection StopTimer(); #endif checkBoxShowVolumeLabel.Enabled = false; - iTableLayoutPanel.Enabled = false; - panelDisplay.Enabled = false; + iTableLayoutPanel.Enabled = false; + panelDisplay.Enabled = false; buttonFill.Enabled = false; buttonClear.Enabled = false; buttonOpen.Enabled = true; @@ -1325,22 +1371,24 @@ } - /// - /// - /// - /// - /// - private void checkBoxShowVolumeLabel_CheckedChanged(object sender, EventArgs e) - { - cds.ShowVolumeLabel = checkBoxShowVolumeLabel.Checked; - Properties.Settings.Default.Save(); - UpdateStatus(); - } + /// + /// + /// + /// + /// + private void checkBoxShowVolumeLabel_CheckedChanged(object sender, EventArgs e) + { + cds.ShowVolumeLabel = checkBoxShowVolumeLabel.Checked; + Properties.Settings.Default.Save(); + UpdateStatus(); + } private void checkBoxShowBorders_CheckedChanged(object sender, EventArgs e) { //Save our show borders setting - iTableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None); + iTableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked + ? TableLayoutPanelCellBorderStyle.Single + : TableLayoutPanelCellBorderStyle.None); cds.ShowBorders = checkBoxShowBorders.Checked; Properties.Settings.Default.Save(); CheckFontHeight(); @@ -1353,20 +1401,20 @@ Properties.Settings.Default.Save(); } - private void checkBoxMinimizeToTray_CheckedChanged(object sender, EventArgs e) - { - //Save our "Minimize to tray" setting - Properties.Settings.Default.MinimizeToTray = checkBoxMinimizeToTray.Checked; - Properties.Settings.Default.Save(); - - } - - private void checkBoxStartMinimized_CheckedChanged(object sender, EventArgs e) - { - //Save our "Start minimized" setting - Properties.Settings.Default.StartMinimized = checkBoxStartMinimized.Checked; - Properties.Settings.Default.Save(); - } + private void checkBoxMinimizeToTray_CheckedChanged(object sender, EventArgs e) + { + //Save our "Minimize to tray" setting + Properties.Settings.Default.MinimizeToTray = checkBoxMinimizeToTray.Checked; + Properties.Settings.Default.Save(); + + } + + private void checkBoxStartMinimized_CheckedChanged(object sender, EventArgs e) + { + //Save our "Start minimized" setting + Properties.Settings.Default.StartMinimized = checkBoxStartMinimized.Checked; + Properties.Settings.Default.Save(); + } private void checkBoxStartIdleClient_CheckedChanged(object sender, EventArgs e) { @@ -1375,9 +1423,9 @@ } private void checkBoxAutoStart_CheckedChanged(object sender, EventArgs e) - { - iStartupManager.Startup = checkBoxAutoStart.Checked; - } + { + iStartupManager.Startup = checkBoxAutoStart.Checked; + } private void checkBoxReverseScreen_CheckedChanged(object sender, EventArgs e) @@ -1419,8 +1467,8 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { iCecManager.Stop(); - iNetworkManager.Dispose(); - CloseDisplayConnection(); + iNetworkManager.Dispose(); + CloseDisplayConnection(); StopServer(); e.Cancel = iClosing; } @@ -1429,11 +1477,12 @@ { iServiceHost = new ServiceHost ( - typeof(Session), - new Uri[] { new Uri("net.tcp://localhost:8001/") } + typeof(Session), + new Uri[] {new Uri("net.tcp://localhost:8001/")} ); - iServiceHost.AddServiceEndpoint(typeof(IService), new NetTcpBinding(SecurityMode.None, true), "DisplayService"); + iServiceHost.AddServiceEndpoint(typeof(IService), new NetTcpBinding(SecurityMode.None, true), + "DisplayService"); iServiceHost.Open(); } @@ -1447,7 +1496,9 @@ } else if (iClosing) { - if (MessageBox.Show("Force exit?", "Waiting for clients...", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) + if ( + MessageBox.Show("Force exit?", "Waiting for clients...", MessageBoxButtons.YesNo, + MessageBoxIcon.Warning) == DialogResult.Yes) { iClosing = false; //We make sure we force close if asked twice } @@ -1471,7 +1522,7 @@ try { Trace.TraceInformation("BroadcastCloseEvent - " + client.Key); - client.Value.Callback.OnCloseOrder(/*eventData*/); + client.Value.Callback.OnCloseOrder( /*eventData*/); } catch (Exception ex) { @@ -1485,37 +1536,39 @@ foreach (var client in inactiveClients) { iClients.Remove(client); - Program.iMainForm.iTreeViewClients.Nodes.Remove(Program.iMainForm.iTreeViewClients.Nodes.Find(client, false)[0]); + Program.iMainForm.iTreeViewClients.Nodes.Remove( + Program.iMainForm.iTreeViewClients.Nodes.Find(client, false)[0]); } } - if (iClients.Count==0) - { - ClearLayout(); - } + if (iClients.Count == 0) + { + ClearLayout(); + } } - /// - /// Just remove all our fields. - /// - private void ClearLayout() - { - iTableLayoutPanel.Controls.Clear(); - iTableLayoutPanel.RowStyles.Clear(); - iTableLayoutPanel.ColumnStyles.Clear(); - iCurrentClientData = null; - } - - /// - /// Just launch a demo client. - /// - private void StartNewClient(string aTopText = "", string aBottomText = "") - { - Thread clientThread = new Thread(SharpDisplayClient.Program.MainWithParams); - SharpDisplayClient.StartParams myParams = new SharpDisplayClient.StartParams(new Point(this.Right, this.Top),aTopText,aBottomText); - clientThread.Start(myParams); - BringToFront(); - } + /// + /// Just remove all our fields. + /// + private void ClearLayout() + { + iTableLayoutPanel.Controls.Clear(); + iTableLayoutPanel.RowStyles.Clear(); + iTableLayoutPanel.ColumnStyles.Clear(); + iCurrentClientData = null; + } + + /// + /// Just launch a demo client. + /// + private void StartNewClient(string aTopText = "", string aBottomText = "") + { + Thread clientThread = new Thread(SharpDisplayClient.Program.MainWithParams); + SharpDisplayClient.StartParams myParams = new SharpDisplayClient.StartParams( + new Point(this.Right, this.Top), aTopText, aBottomText); + clientThread.Start(myParams); + BringToFront(); + } /// /// Just launch our idle client. @@ -1523,7 +1576,8 @@ private void StartIdleClient(string aTopText = "", string aBottomText = "") { Thread clientThread = new Thread(SharpDisplayIdleClient.Program.MainWithParams); - SharpDisplayIdleClient.StartParams myParams = new SharpDisplayIdleClient.StartParams(new Point(this.Right, this.Top), aTopText, aBottomText); + SharpDisplayIdleClient.StartParams myParams = + new SharpDisplayIdleClient.StartParams(new Point(this.Right, this.Top), aTopText, aBottomText); clientThread.Start(myParams); BringToFront(); } @@ -1531,7 +1585,7 @@ private void buttonStartClient_Click(object sender, EventArgs e) { - StartNewClient(); + StartNewClient(); } private void buttonSuspend_Click(object sender, EventArgs e) @@ -1587,13 +1641,13 @@ } //If the selected node is the root node of a client then switch to it - string sessionId=e.Node.Nodes[0].Text; //First child of a root node is the sessionId + string sessionId = e.Node.Nodes[0].Text; //First child of a root node is the sessionId if (iClients.ContainsKey(sessionId)) //Check that's actually what we are looking at { //We have a valid session just switch to that client - SetCurrentClient(sessionId,true); + SetCurrentClient(sessionId, true); } - + } @@ -1608,7 +1662,7 @@ { //Not in the proper thread, invoke ourselves AddClientDelegate d = new AddClientDelegate(AddClientThreadSafe); - this.Invoke(d, new object[] { aSessionId, aCallback }); + this.Invoke(d, new object[] {aSessionId, aCallback}); } else { @@ -1650,7 +1704,7 @@ { //Not in the proper thread, invoke ourselves RemoveClientDelegate d = new RemoveClientDelegate(RemoveClientThreadSafe); - this.Invoke(d, new object[] { aSessionId }); + this.Invoke(d, new object[] {aSessionId}); } else { @@ -1659,7 +1713,8 @@ if (Program.iMainForm.iClients.Keys.Contains(aSessionId)) { Program.iMainForm.iClients.Remove(aSessionId); - Program.iMainForm.iTreeViewClients.Nodes.Remove(Program.iMainForm.iTreeViewClients.Nodes.Find(aSessionId, false)[0]); + Program.iMainForm.iTreeViewClients.Nodes.Remove( + Program.iMainForm.iTreeViewClients.Nodes.Find(aSessionId, false)[0]); //Update recording status too whenever a client is removed UpdateRecordingNotification(); } @@ -1670,26 +1725,26 @@ iCurrentClientData = null; //Find the client with the highest priority and set it as current ClientData newCurrentClient = FindHighestPriorityClient(); - if (newCurrentClient!=null) + if (newCurrentClient != null) { SetCurrentClient(newCurrentClient.SessionId, true); - } + } } if (iClients.Count == 0) - { - //Clear our screen when last client disconnects - ClearLayout(); - - if (iClosing) - { - //We were closing our form - //All clients are now closed - //Just resume our close operation - iClosing = false; - Close(); - } - } + { + //Clear our screen when last client disconnects + ClearLayout(); + + if (iClosing) + { + //We were closing our form + //All clients are now closed + //Just resume our close operation + iClosing = false; + Close(); + } + } } } @@ -1704,7 +1759,7 @@ { //Not in the proper thread, invoke ourselves SetLayoutDelegate d = new SetLayoutDelegate(SetClientLayoutThreadSafe); - this.Invoke(d, new object[] { aSessionId, aLayout }); + this.Invoke(d, new object[] {aSessionId, aLayout}); } else { @@ -1743,7 +1798,7 @@ { //Not in the proper thread, invoke ourselves SetFieldDelegate d = new SetFieldDelegate(SetClientFieldThreadSafe); - this.Invoke(d, new object[] { aSessionId, aField }); + this.Invoke(d, new object[] {aSessionId, aField}); } else { @@ -1762,7 +1817,7 @@ /// /// private void SetClientField(string aSessionId, DataField aField) - { + { //TODO: should check if the field actually changed? ClientData client = iClients[aSessionId]; @@ -1796,22 +1851,22 @@ //If we are updating a field in our current client we need to update it in our panel if (aSessionId == iCurrentClientSessionId) { - Control ctrl=iTableLayoutPanel.GetControlFromPosition(tableField.Column, tableField.Row); + Control ctrl = iTableLayoutPanel.GetControlFromPosition(tableField.Column, tableField.Row); if (aField.IsTextField && ctrl is MarqueeLabel) { - TextField textField=(TextField)aField; + TextField textField = (TextField) aField; //Text field control already in place, just change the text - MarqueeLabel label = (MarqueeLabel)ctrl; + MarqueeLabel label = (MarqueeLabel) ctrl; contentChanged = (label.Text != textField.Text || label.TextAlign != textField.Alignment); label.Text = textField.Text; label.TextAlign = textField.Alignment; } else if (aField.IsBitmapField && ctrl is PictureBox) { - BitmapField bitmapField = (BitmapField)aField; + BitmapField bitmapField = (BitmapField) aField; contentChanged = true; //TODO: Bitmap comp or should we leave that to clients? //Bitmap field control already in place just change the bitmap - PictureBox pictureBox = (PictureBox)ctrl; + PictureBox pictureBox = (PictureBox) ctrl; pictureBox.Image = bitmapField.Bitmap; } else @@ -1821,7 +1876,7 @@ } } else - { + { layoutChanged = true; } @@ -1864,7 +1919,7 @@ { //Not in the proper thread, invoke ourselves SetFieldsDelegate d = new SetFieldsDelegate(SetClientFieldsThreadSafe); - this.Invoke(d, new object[] { aSessionId, aFields }); + this.Invoke(d, new object[] {aSessionId, aFields}); } else { @@ -1912,7 +1967,7 @@ { //Not in the proper thread, invoke ourselves SetClientNameDelegate d = new SetClientNameDelegate(SetClientNameThreadSafe); - this.Invoke(d, new object[] { aSessionId, aName }); + this.Invoke(d, new object[] {aSessionId, aName}); } else { @@ -1936,7 +1991,7 @@ { //Not in the proper thread, invoke ourselves SetClientPriorityDelegate d = new SetClientPriorityDelegate(SetClientPriorityThreadSafe); - this.Invoke(d, new object[] { aSessionId, aPriority }); + this.Invoke(d, new object[] {aSessionId, aPriority}); } else { @@ -1951,7 +2006,7 @@ UpdateClientTreeViewNode(client); //Change our current client as per new priority ClientData newCurrentClient = FindHighestPriorityClient(); - if (newCurrentClient!=null) + if (newCurrentClient != null) { SetCurrentClient(newCurrentClient.SessionId); } @@ -1967,7 +2022,7 @@ /// public static string Truncate(string value, int maxChars) { - return value.Length <= maxChars ? value : value.Substring(0, maxChars-3) + "..."; + return value.Length <= maxChars ? value : value.Substring(0, maxChars - 3) + "..."; } /// @@ -1977,12 +2032,12 @@ { //Go through each bool activeRecording = false; - string text=""; - RecordingField recField=new RecordingField(); + string text = ""; + RecordingField recField = new RecordingField(); foreach (var client in iClients) { - RecordingField rec=(RecordingField)client.Value.FindSameFieldAs(recField); - if (rec!=null && rec.IsActive) + RecordingField rec = (RecordingField) client.Value.FindSameFieldAs(recField); + if (rec != null && rec.IsActive) { activeRecording = true; //Don't break cause we are collecting the names/texts. @@ -1995,23 +2050,23 @@ //Not text for that recording, use client name instead text += client.Value.Name + " recording\n"; } - + } } //Update our text no matter what, can't have more than 63 characters otherwise it throws an exception. - iRecordingNotification.Text = Truncate(text,63); + iRecordingNotification.Text = Truncate(text, 63); //Change visibility of notification if needed if (iRecordingNotification.Visible != activeRecording) - { + { iRecordingNotification.Visible = activeRecording; //Assuming the notification icon is in sync with our display icon //Take care of our REC icon if (iDisplay.IsOpen()) { iDisplay.SetIconOnOff(MiniDisplay.IconType.Recording, activeRecording); - } + } } } @@ -2035,7 +2090,7 @@ //Check that our client node already exists //Get our client root node using its key which is our session ID TreeNode[] nodes = iTreeViewClients.Nodes.Find(aClient.SessionId, false); - if (nodes.Count()>0) + if (nodes.Count() > 0) { //We already have a node for that client node = nodes[0]; @@ -2078,7 +2133,7 @@ { if (field.IsTextField) { - TextField textField = (TextField)field; + TextField textField = (TextField) field; textsRoot.Nodes.Add(new TreeNode("[Text]" + textField.Text)); } else if (field.IsBitmapField) @@ -2087,7 +2142,7 @@ } else if (field.IsRecordingField) { - RecordingField recordingField = (RecordingField)field; + RecordingField recordingField = (RecordingField) field; textsRoot.Nodes.Add(new TreeNode("[Recording]" + recordingField.IsActive)); } } @@ -2105,7 +2160,7 @@ foreach (RowStyle rowStyle in iTableLayoutPanel.RowStyles) { rowStyle.SizeType = SizeType.Percent; - rowStyle.Height = 100 / iTableLayoutPanel.RowCount; + rowStyle.Height = 100/iTableLayoutPanel.RowCount; } } @@ -2119,11 +2174,11 @@ { Debug.Print("UpdateTableLayoutPanel"); - if (aClient == null) - { - //Just drop it - return; - } + if (aClient == null) + { + //Just drop it + return; + } TableLayout layout = aClient.Layout; @@ -2177,7 +2232,7 @@ continue; } - TableField tableField = (TableField)field; + TableField tableField = (TableField) field; //Create a control corresponding to the field specified for that cell Control control = CreateControlForDataField(tableField); @@ -2199,7 +2254,7 @@ /// private Control CreateControlForDataField(DataField aField) { - Control control=null; + Control control = null; if (aField.IsTextField) { MarqueeLabel label = new SharpDisplayManager.MarqueeLabel(); @@ -2219,7 +2274,7 @@ //control.TabIndex = 2; label.Font = cds.Font; - TextField field = (TextField)aField; + TextField field = (TextField) aField; label.TextAlign = field.Alignment; label.UseCompatibleTextRendering = true; label.Text = field.Text; @@ -2237,7 +2292,7 @@ picture.Margin = new System.Windows.Forms.Padding(0); picture.Name = "pictureBox" + aField; //Set our image - BitmapField field = (BitmapField)aField; + BitmapField field = (BitmapField) aField; picture.Image = field.Bitmap; // control = picture; @@ -2247,20 +2302,20 @@ return control; } - /// - /// Called when the user selected a new display type. - /// - /// - /// + /// + /// Called when the user selected a new display type. + /// + /// + /// private void comboBoxDisplayType_SelectedIndexChanged(object sender, EventArgs e) { - //Store the selected display type in our settings + //Store the selected display type in our settings Properties.Settings.Default.CurrentDisplayIndex = comboBoxDisplayType.SelectedIndex; cds.DisplayType = comboBoxDisplayType.SelectedIndex; Properties.Settings.Default.Save(); - //Try re-opening the display connection if we were already connected. - //Otherwise just update our status to reflect display type change. + //Try re-opening the display connection if we were already connected. + //Otherwise just update our status to reflect display type change. if (iDisplay.IsOpen()) { OpenDisplayConnection(); @@ -2296,39 +2351,39 @@ { cds.MinFontSize = minFontSize; Properties.Settings.Default.Save(); - //We need to recreate our layout for that change to take effect - UpdateTableLayoutPanel(iCurrentClientData); + //We need to recreate our layout for that change to take effect + UpdateTableLayoutPanel(iCurrentClientData); } } } - private void maskedTextBoxScrollingSpeed_TextChanged(object sender, EventArgs e) - { - if (maskedTextBoxScrollingSpeed.Text != "") - { - int scrollingSpeed = Convert.ToInt32(maskedTextBoxScrollingSpeed.Text); - - if (scrollingSpeed > 0) - { - cds.ScrollingSpeedInPixelsPerSecond = scrollingSpeed; - Properties.Settings.Default.Save(); - //We need to recreate our layout for that change to take effect - UpdateTableLayoutPanel(iCurrentClientData); - } - } - } + private void maskedTextBoxScrollingSpeed_TextChanged(object sender, EventArgs e) + { + if (maskedTextBoxScrollingSpeed.Text != "") + { + int scrollingSpeed = Convert.ToInt32(maskedTextBoxScrollingSpeed.Text); + + if (scrollingSpeed > 0) + { + cds.ScrollingSpeedInPixelsPerSecond = scrollingSpeed; + Properties.Settings.Default.Save(); + //We need to recreate our layout for that change to take effect + UpdateTableLayoutPanel(iCurrentClientData); + } + } + } private void textBoxScrollLoopSeparator_TextChanged(object sender, EventArgs e) { cds.Separator = textBoxScrollLoopSeparator.Text; Properties.Settings.Default.Save(); - //Update our text fields - foreach (MarqueeLabel ctrl in iTableLayoutPanel.Controls) - { - ctrl.Separator = cds.Separator; - } + //Update our text fields + foreach (MarqueeLabel ctrl in iTableLayoutPanel.Controls) + { + ctrl.Separator = cds.Separator; + } } @@ -2344,12 +2399,12 @@ private void buttonShowClock_Click(object sender, EventArgs e) { - ShowClock(); + ShowClock(); } private void buttonHideClock_Click(object sender, EventArgs e) { - HideClock(); + HideClock(); } private void buttonUpdate_Click(object sender, EventArgs e) @@ -2357,39 +2412,39 @@ InstallUpdateSyncWithInfo(); } - /// - /// - /// - void ShowClock() - { - if (!iDisplay.IsOpen()) - { - return; - } - - //Devices like MDM166AA don't support windowing and frame rendering must be stopped while showing our clock - iSkipFrameRendering = true; - //Clear our screen - iDisplay.Clear(); - iDisplay.SwapBuffers(); - //Then show our clock - iDisplay.ShowClock(); - } - - /// - /// - /// - void HideClock() - { - if (!iDisplay.IsOpen()) - { - return; - } - - //Devices like MDM166AA don't support windowing and frame rendering must be stopped while showing our clock - iSkipFrameRendering = false; - iDisplay.HideClock(); - } + /// + /// + /// + void ShowClock() + { + if (!iDisplay.IsOpen()) + { + return; + } + + //Devices like MDM166AA don't support windowing and frame rendering must be stopped while showing our clock + iSkipFrameRendering = true; + //Clear our screen + iDisplay.Clear(); + iDisplay.SwapBuffers(); + //Then show our clock + iDisplay.ShowClock(); + } + + /// + /// + /// + void HideClock() + { + if (!iDisplay.IsOpen()) + { + return; + } + + //Devices like MDM166AA don't support windowing and frame rendering must be stopped while showing our clock + iSkipFrameRendering = false; + iDisplay.HideClock(); + } private void InstallUpdateSyncWithInfo() { @@ -2406,125 +2461,135 @@ } catch (DeploymentDownloadException dde) { - MessageBox.Show("The new version of the application cannot be downloaded at this time. \n\nPlease check your network connection, or try again later. Error: " + dde.Message); + MessageBox.Show( + "The new version of the application cannot be downloaded at this time. \n\nPlease check your network connection, or try again later. Error: " + + dde.Message); return; } catch (InvalidDeploymentException ide) { - MessageBox.Show("Cannot check for a new version of the application. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " + ide.Message); + MessageBox.Show( + "Cannot check for a new version of the application. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " + + ide.Message); return; } catch (InvalidOperationException ioe) { - MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message); + MessageBox.Show( + "This application cannot be updated. It is likely not a ClickOnce application. Error: " + + ioe.Message); return; } - if (info.UpdateAvailable) - { - Boolean doUpdate = true; - - if (!info.IsUpdateRequired) - { - DialogResult dr = MessageBox.Show("An update is available. Would you like to update the application now?", "Update Available", MessageBoxButtons.OKCancel); - if (!(DialogResult.OK == dr)) - { - doUpdate = false; - } - } - else - { - // Display a message that the application MUST reboot. Display the minimum required version. - MessageBox.Show("This application has detected a mandatory update from your current " + - "version to version " + info.MinimumRequiredVersion.ToString() + - ". The application will now install the update and restart.", - "Update Available", MessageBoxButtons.OK, - MessageBoxIcon.Information); - } - - if (doUpdate) - { - try - { - ad.Update(); - MessageBox.Show("The application has been upgraded, and will now restart."); - Application.Restart(); - } - catch (DeploymentDownloadException dde) - { - MessageBox.Show("Cannot install the latest version of the application. \n\nPlease check your network connection, or try again later. Error: " + dde); - return; - } - } - } - else - { - MessageBox.Show("You are already running the latest version.", "Application up-to-date"); - } + if (info.UpdateAvailable) + { + Boolean doUpdate = true; + + if (!info.IsUpdateRequired) + { + DialogResult dr = + MessageBox.Show("An update is available. Would you like to update the application now?", + "Update Available", MessageBoxButtons.OKCancel); + if (!(DialogResult.OK == dr)) + { + doUpdate = false; + } + } + else + { + // Display a message that the application MUST reboot. Display the minimum required version. + MessageBox.Show("This application has detected a mandatory update from your current " + + "version to version " + info.MinimumRequiredVersion.ToString() + + ". The application will now install the update and restart.", + "Update Available", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + + if (doUpdate) + { + try + { + ad.Update(); + MessageBox.Show("The application has been upgraded, and will now restart."); + Application.Restart(); + } + catch (DeploymentDownloadException dde) + { + MessageBox.Show( + "Cannot install the latest version of the application. \n\nPlease check your network connection, or try again later. Error: " + + dde); + return; + } + } + } + else + { + MessageBox.Show("You are already running the latest version.", "Application up-to-date"); + } } } - /// - /// Used to - /// - private void SysTrayHideShow() - { - Visible = !Visible; - if (Visible) - { - Activate(); - WindowState = FormWindowState.Normal; - } - } - - /// - /// Use to handle minimize events. - /// - /// - /// - private void MainForm_SizeChanged(object sender, EventArgs e) - { - if (WindowState == FormWindowState.Minimized && Properties.Settings.Default.MinimizeToTray) - { - if (Visible) - { - SysTrayHideShow(); - } - } - } - - /// - /// - /// - /// - /// - private void tableLayoutPanel_SizeChanged(object sender, EventArgs e) - { - //Our table layout size has changed which means our display size has changed. - //We need to re-create our bitmap. - iCreateBitmap = true; - } - - /// - /// - /// - /// - /// - private void buttonSelectFile_Click(object sender, EventArgs e) - { - //openFileDialog1.InitialDirectory = "c:\\"; - //openFileDialog.Filter = "EXE files (*.exe)|*.exe|All files (*.*)|*.*"; - //openFileDialog.FilterIndex = 1; - openFileDialog.RestoreDirectory = true; - - if (DlgBox.ShowDialog(openFileDialog) == DialogResult.OK) - { - labelStartFileName.Text = openFileDialog.FileName; - Properties.Settings.Default.StartFileName = openFileDialog.FileName; - Properties.Settings.Default.Save(); - } - } + /// + /// Used to + /// + private void SysTrayHideShow() + { + Visible = !Visible; + if (Visible) + { + Activate(); + WindowState = FormWindowState.Normal; + } + } + + /// + /// Use to handle minimize events. + /// + /// + /// + private void MainForm_SizeChanged(object sender, EventArgs e) + { + if (WindowState == FormWindowState.Minimized && Properties.Settings.Default.MinimizeToTray) + { + if (Visible) + { + SysTrayHideShow(); + } + } + } + + /// + /// + /// + /// + /// + private void tableLayoutPanel_SizeChanged(object sender, EventArgs e) + { + //Our table layout size has changed which means our display size has changed. + //We need to re-create our bitmap. + iCreateBitmap = true; + } + + /// + /// + /// + /// + /// + private void buttonSelectFile_Click(object sender, EventArgs e) + { + //openFileDialog1.InitialDirectory = "c:\\"; + //openFileDialog.Filter = "EXE files (*.exe)|*.exe|All files (*.*)|*.*"; + //openFileDialog.FilterIndex = 1; + openFileDialog.RestoreDirectory = true; + + if (DlgBox.ShowDialog(openFileDialog) == DialogResult.OK) + { + labelStartFileName.Text = openFileDialog.FileName; + Properties.Settings.Default.StartFileName = openFileDialog.FileName; + Properties.Settings.Default.Save(); + } + } /// /// @@ -2559,11 +2624,11 @@ { LogsUpdate(); - if (OnWndProc!=null) + if (OnWndProc != null) { OnWndProc(ref aMessage); } - + base.WndProc(ref aMessage); } @@ -2591,7 +2656,7 @@ /// private void ResetCec() { - if (iCecManager==null) + if (iCecManager == null) { //Thus skipping initial UI setup return; @@ -2602,7 +2667,7 @@ if (Properties.Settings.Default.CecEnabled) { iCecManager.Start(Handle, "CEC", - Properties.Settings.Default.CecHdmiPort); + Properties.Settings.Default.CecHdmiPort); SetupCecLogLevel(); } @@ -2617,19 +2682,19 @@ iCecManager.Client.LogLevel = 0; if (checkBoxCecLogError.Checked) - iCecManager.Client.LogLevel |= (int)CecLogLevel.Error; + iCecManager.Client.LogLevel |= (int) CecLogLevel.Error; if (checkBoxCecLogWarning.Checked) - iCecManager.Client.LogLevel |= (int)CecLogLevel.Warning; + iCecManager.Client.LogLevel |= (int) CecLogLevel.Warning; if (checkBoxCecLogNotice.Checked) - iCecManager.Client.LogLevel |= (int)CecLogLevel.Notice; + iCecManager.Client.LogLevel |= (int) CecLogLevel.Notice; if (checkBoxCecLogTraffic.Checked) - iCecManager.Client.LogLevel |= (int)CecLogLevel.Traffic; + iCecManager.Client.LogLevel |= (int) CecLogLevel.Traffic; if (checkBoxCecLogDebug.Checked) - iCecManager.Client.LogLevel |= (int)CecLogLevel.Debug; + iCecManager.Client.LogLevel |= (int) CecLogLevel.Debug; iCecManager.Client.FilterOutPollLogs = checkBoxCecLogNoPoll.Checked; @@ -2650,7 +2715,7 @@ SetupCecLogLevel(); } - + /// /// /// @@ -2663,9 +2728,9 @@ } string key = aEvent.GetType().Name; - TreeNode[] res=iTreeViewEvents.Nodes.Find(key, false); + TreeNode[] res = iTreeViewEvents.Nodes.Find(key, false); if (res.Length > 0) - { + { iTreeViewEvents.SelectedNode = res[0]; iTreeViewEvents.Focus(); } @@ -2686,7 +2751,7 @@ { if (node.Tag is Event) { - selectedEvent = (Event)node.Tag; + selectedEvent = (Event) node.Tag; break; } node = node.Parent; @@ -2728,7 +2793,7 @@ DialogResult res = CodeProject.Dialog.DlgBox.ShowDialog(ea); if (res == DialogResult.OK) { - selectedEvent.Actions.Add(ea.Action); + selectedEvent.Actions.Add(ea.Action); Properties.Settings.Default.Actions = ManagerEventAction.Current; Properties.Settings.Default.Save(); PopulateEventsTreeView(); @@ -2760,7 +2825,98 @@ { //Enable buttons according to selected item buttonAddAction.Enabled = CurrentEvent() != null; - buttonDeleteAction.Enabled = CurrentAction() != null; + + SharpLib.Ear.Action currentAction = CurrentAction(); + //If an action is selected enable the following buttons + buttonTestAction.Enabled = + buttonDeleteAction.Enabled = + buttonActionMoveUp.Enabled = + buttonActionMoveDown.Enabled = + currentAction != null; + + if (currentAction != null) + { + //If an action is selected enable move buttons if needed + buttonActionMoveUp.Enabled = iTreeViewEvents.SelectedNode.Index != 0; + buttonActionMoveDown.Enabled = iTreeViewEvents.SelectedNode.Index < + iTreeViewEvents.SelectedNode.Parent.Nodes.Count - 1; + } + + } + + /// + /// + /// + /// + /// + private void buttonTestAction_Click(object sender, EventArgs e) + { + SharpLib.Ear.Action a = CurrentAction(); + if (a != null) + { + Console.WriteLine("Action test run"); + a.Execute(); + } + iTreeViewEvents.Focus(); + } + + /// + /// + /// + /// + /// + private void buttonActionMoveUp_Click(object sender, EventArgs e) + { + SharpLib.Ear.Action a = CurrentAction(); + if (a == null || + //Action already at the top of the list + iTreeViewEvents.SelectedNode.Index == 0) + { + return; + } + + //Swap actions in event's action list + Event currentEvent = CurrentEvent(); + int currentIndex = iTreeViewEvents.SelectedNode.Index; + SharpLib.Ear.Action movingUp = currentEvent.Actions[currentIndex]; + SharpLib.Ear.Action movingDown = currentEvent.Actions[currentIndex-1]; + currentEvent.Actions[currentIndex] = movingDown; + currentEvent.Actions[currentIndex-1] = movingUp; + + //Save and populate our tree again + Properties.Settings.Default.Actions = ManagerEventAction.Current; + Properties.Settings.Default.Save(); + PopulateEventsTreeView(); + + } + + /// + /// + /// + /// + /// + private void buttonActionMoveDown_Click(object sender, EventArgs e) + { + SharpLib.Ear.Action a = CurrentAction(); + if (a == null || + //Action already at the bottom of the list + iTreeViewEvents.SelectedNode.Index == iTreeViewEvents.SelectedNode.Parent.Nodes.Count - 1) + { + return; + } + + //Swap actions in event's action list + Event currentEvent = CurrentEvent(); + int currentIndex = iTreeViewEvents.SelectedNode.Index; + SharpLib.Ear.Action movingDown = currentEvent.Actions[currentIndex]; + SharpLib.Ear.Action movingUp = currentEvent.Actions[currentIndex + 1]; + currentEvent.Actions[currentIndex] = movingUp; + currentEvent.Actions[currentIndex + 1] = movingDown; + + //Save and populate our tree again + Properties.Settings.Default.Actions = ManagerEventAction.Current; + Properties.Settings.Default.Save(); + PopulateEventsTreeView(); } } } diff -r 0e8c6c2f4777 -r f6272f65d8fc SharpLibEar/Action.cs --- a/SharpLibEar/Action.cs Wed Jul 27 11:07:35 2016 +0200 +++ b/SharpLibEar/Action.cs Wed Jul 27 15:05:58 2016 +0200 @@ -12,7 +12,13 @@ [KnownType("DerivedTypes")] public abstract class Action: IComparable { - public abstract void Execute(); + public abstract void DoExecute(); + + public void Execute() + { + Console.WriteLine("Executing action: " + Brief()); + DoExecute(); + } public string Name { //Get the name of this object action attribute diff -r 0e8c6c2f4777 -r f6272f65d8fc SharpLibEar/ActionCallback.cs --- a/SharpLibEar/ActionCallback.cs Wed Jul 27 11:07:35 2016 +0200 +++ b/SharpLibEar/ActionCallback.cs Wed Jul 27 15:05:58 2016 +0200 @@ -17,7 +17,7 @@ iCallback = aCallback; } - public override void Execute() + public override void DoExecute() { if (iCallback != null) { diff -r 0e8c6c2f4777 -r f6272f65d8fc SharpLibEar/ActionSleep.cs --- a/SharpLibEar/ActionSleep.cs Wed Jul 27 11:07:35 2016 +0200 +++ b/SharpLibEar/ActionSleep.cs Wed Jul 27 15:05:58 2016 +0200 @@ -43,7 +43,7 @@ } - public override void Execute() + public override void DoExecute() { Thread.Sleep(TimeoutInMilliseconds); }