/[AnywhereTS-MSSQL]/branches/TerminalServices/TSAdminTool/frmAdmin.cs
ViewVC logotype

Diff of /branches/TerminalServices/TSAdminTool/frmAdmin.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- branches/TerminalServices/TSAdminTool/frmAdmin.cs	2012/08/25 23:01:27	270
+++ branches/TerminalServices/TSAdminTool/frmAdmin.cs	2012/08/26 00:04:01	271
@@ -9,8 +9,11 @@
     using System.Windows.Forms;
     using System.Runtime.InteropServices;
     using System.IO;
+    using System.Linq;
+    using AnywhereTS.Extensions;
     using System.Data.SqlClient;
-    using System.Security.Permissions; // For File operations
+    using System.Security.Permissions;
+    using Cassia; // For File operations
     
 
     public partial class frmAdmin : Form
@@ -81,23 +84,22 @@
         // Update database from terminal server sessions
         private void UpdateClientsFromSession()
         {
-            List<TSManager.TS_SESSION_INFO> Sessions;
-            Sessions = TSManager.ListSessions();
-            foreach (TSManager.TS_SESSION_INFO session in Sessions)
+            var Sessions = TSManager.ListSessions();
+            foreach (var session in Sessions)
             {
-                if (session.macAddress != "")
+                if (session.ClientIPAddress.ToMacAddress() != "")
                 {   // The client is an (Un-named) ATS client. We have a MAC address.
 
                     // Does the MAC adress for the session alreay exist in database?
-                    if (datasetAllClients.Client.Rows.Find(session.macAddress) == null)
+                    if (datasetAllClients.Client.Rows.Find(session.ClientIPAddress.ToMacAddress()) == null)
                     {
                         // The MAC address did not exist in database. Add the client, using properties from the default record.
                         DataRow newRow = datasetAllClients.Client.NewRow();
                         ATSImageRuntimeConfig newConfig = new ATSImageRuntimeConfig();
                         newConfig.ReadDefaultFromDatabase();
                         newConfig.WriteToDatabase(newRow);
-                        newRow["macAddress"] = session.macAddress;
-                        newRow["clientName"] = session.name;
+                        newRow["macAddress"] = session.ClientIPAddress.ToMacAddress();
+                        newRow["clientName"] = session.ClientName;
                         datasetAllClients.Client.Rows.Add(newRow);
                     }
                 }
@@ -143,14 +145,14 @@
             treeView.Nodes[0].Nodes.Clear(); // Clear the clients node
             foreach (DataRow row in datasetLicensedClients.Client.Rows)
             {
-                AtsSession session; // Session for the current client
+                ITerminalServicesSession session; // Session for the current client
                 TreeNode addedNode;
 
                 session = TSManager.GetSession(row["MacAddress"].ToString());
-                if (session != null && session.username.Length > 0)
+                if (session != null && session.UserName.Length > 0)
                 {
                     // There is a user name for the client, display client name and user name.
-                    addedNode = treeView.Nodes[0].Nodes.Add(row["ClientName"].ToString() + " (" + session.username + ")");
+                    addedNode = treeView.Nodes[0].Nodes.Add(row["ClientName"].ToString() + " (" + session.UserName + ")");
                 }
                 else
                 {
@@ -163,7 +165,7 @@
                 if (session != null)
                 {
                     // There is a session for the client
-                    if (session.username.Length > 0)
+                    if (session.UserName.Length > 0)
                     {   // There is a user logged in
                         addedNode.ImageIndex = 3;
                         addedNode.SelectedImageIndex = 3;
@@ -209,28 +211,28 @@
                 //addedNode.ContextMenuStrip = contextMenuClient; // Add the context menu for the client. Enables to remove the client.
             
                 // Add sessions for the terminal server to the tree.
-                foreach (AtsSession session in ts.Session)
+                foreach (ITerminalServicesSession session in ts.Session)
                 {
                     string sessionText;
                     int imageIndex;
-                    if (session.sessionID == 0)
+                    if (session.SessionId == 0)
                     {   // This is a console session
                         sessionText = "Console";
-                        if (session.username.Length != 0)
+                        if (session.UserName.Length != 0)
                         {   // Session has a username
-                            sessionText += " (" + session.username + ")";
+                            sessionText += " (" + session.UserName + ")";
                         }
                         imageIndex = 7; // Display the active session icon
                     }
-                    else if (session.sessionID == 65536)
+                    else if (session.SessionId == 65536)
                     {   // This is the listener session
                         sessionText = "Listener";
                         imageIndex = 8; // Display the non-active session icon
                     }
                     else
                     {   // This is a "normal" session
-                        sessionText = session.sessionID.ToString() + " " + (session.username.Length != 0 ? " (" + session.username + ")" : "");
-                        if (session.state == Cassia.ConnectionState.Active)
+                        sessionText = session.SessionId.ToString() + " " + (session.UserName.Length != 0 ? " (" + session.UserName + ")" : "");
+                        if (session.ConnectionState == Cassia.ConnectionState.Active)
                         {   // Display the active session icon
                             imageIndex = 7;
                         }
@@ -251,36 +253,36 @@
 
             // Add sesions to the tree
             treeView.Nodes[2].Nodes.Clear(); // Clear the sessions node
-            foreach (AtsSession session in AtsEnvironment.Sessions)
+            foreach (ITerminalServicesSession session in AtsEnvironment.Sessions)
             {
                 string sessionText;
                 int imageIndex;
-                if (session.sessionID == 0)
+                if (session.SessionId == 0)
                 {   // This is a console session
                     sessionText = "Console";
-                    if (session.username.Length != 0)
+                    if (session.UserName.Length != 0)
                     {   // Session has a username
-                        sessionText += " (" + session.username + ")";
+                        sessionText += " (" + session.UserName + ")";
                     }
                     imageIndex = 7; // Display the active session icon
                 }
-                else if (session.sessionID == 65536)
+                else if (session.SessionId == 65536)
                 {   // This is the listener session
                     sessionText = "Listener";
                     imageIndex = 8; // Display the non-active session icon
                 }
                 else
                 {   // This is a "normal" session
-                    if (session.username.Length != 0)
+                    if (session.UserName.Length != 0)
                     {   // Session has a username
-                        sessionText = session.username;
+                        sessionText = session.UserName;
                     }
                     else
                     {   // Session does not have a username
                         sessionText = "Not logged on";
                     }
                     // Select the icon to display
-                    if (session.state == Cassia.ConnectionState.Active)
+                    if (session.ConnectionState == Cassia.ConnectionState.Active)
                     {   // Display the active session icon
                         imageIndex = 7;
                     }
@@ -292,7 +294,7 @@
                 // Add terminal server name if we have more than one terminal server
                 if (AtsEnvironment.TerminalServers.Count > 1)
                 {   // We have more than one terminal server, display the name of the terminal server
-                    sessionText += " (" + session.TerminalServerName + ")";
+                    sessionText += " (" + session.Server.ServerName + ")";
                 }
 
                 TreeNode addedSessionNode;
@@ -351,7 +353,7 @@
                     deleteClientToolStripMenuItem.Enabled = true;
 
                     // Display client data
-                    AtsSession sessionInfo; // Session info for the client that was selected in the tree
+                    ITerminalServicesSession sessionInfo; // Session info for the client that was selected in the tree
                     selectedClientMacAddress = datasetLicensedClients.Client.Rows[node.Index]["MacAddress"].ToString();
                     //selectedConfig.ReadFromDatabase(datasetClient.Client.Rows[e.Node.Index]);
 
@@ -399,7 +401,7 @@
                     // Or a session under a terminal server node is selected in the tree view
 
                     // Display the session data
-                    AtsSession session = (AtsSession)node.Tag;
+                    ITerminalServicesSession session = (ITerminalServicesSession)node.Tag;
 
                     PositionClientSessionPanels(true);
                     UpdateSessionPanel(session);
@@ -436,17 +438,17 @@
         }
 
         // Updates the session panel in the right pane with session data from the session in "session"
-        private void UpdateSessionPanel(AtsSession session)
+        private void UpdateSessionPanel(ITerminalServicesSession session)
         {
             tlpSessionDetails.Visible = true;
             lblClientHasNoSession.Visible = false;
-            lblUserName.Text = session.username.Length != 0 ? session.username : "-";
-            lblSessionID.Text = session.sessionID.ToString();
-            lblState.Text = TSManager.StateToString(session.state);
-            lblIPAddress.Text = session.ipAddress.Length != 0 ? session.ipAddress : "-";
-            if (session.HorizontalResolution != 0)
+            lblUserName.Text = session.UserName.Length != 0 ? session.UserName : "-";
+            lblSessionID.Text = session.SessionId.ToString();
+            lblState.Text = TSManager.StateToString(session.ConnectionState);
+            lblIPAddress.Text = session.ClientIPAddress.ToString().Length != 0 ? session.ClientIPAddress.ToString() : "-";
+            if (session.ClientDisplay.HorizontalResolution != 0)
             {
-                lblSessionScreenResolution.Text = session.HorizontalResolution.ToString() + "x" + session.VerticalResolution.ToString();
+                lblSessionScreenResolution.Text = session.ClientDisplay.HorizontalResolution.ToString() + "x" + session.ClientDisplay.VerticalResolution.ToString();
             }
             else
             {   // No screen resolution

 

  ViewVC Help
Powered by ViewVC 1.1.22