ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/AnywhereTS-MSSQL/trunk/TSAdminTool/Globals.cs
(Generate patch)

Comparing trunk/TSAdminTool/Globals.cs (file contents):
Revision 92 by william, Fri Jul 13 20:56:44 2012 UTC vs.
Revision 93 by william, Sat Jul 14 02:35:50 2012 UTC

--- trunk/TSAdminTool/Globals.cs	2012/07/14 00:55:41	92
+++ trunk/TSAdminTool/Globals.cs	2012/07/14 02:35:50	93
@@ -12,6 +12,7 @@ namespace AnywhereTS
 {
     public static class ATSGlobals
     {
+        #region Global Definitions
         // Version
         public const string strDatabaseVersion = "1.0.0.4"; // The version string for the ATS database
         public const string strDatabaseName = "AnywhereTS"; // THe name of the ATS database
@@ -61,7 +62,8 @@ namespace AnywhereTS
 
         // Client connect time options
         public static int[,] ScreenResolutions = new int[,] { { 640, 480 }, { 800, 600 }, { 1024, 600 }, { 1024, 768 }, { 1152, 864 }, { 1280, 768 }, { 1280, 800 }, { 1280, 960 }, { 1280, 1024 }, { 1368, 768 }, { 1400, 1050 }, { 1440, 900 }, { 1440, 1050 }, { 1600, 1000 }, { 1600, 1024 }, { 1600, 1200 }, { 1680, 1050 }, { 1792, 1344 }, { 1856, 1392 }, { 1920, 1080 }, { 1920, 1200 }, { 1920, 1440 } };
-
+#endregion
+        #region static ATSGlobals()
         // Constructor
         static ATSGlobals()
         {
@@ -127,32 +129,41 @@ namespace AnywhereTS
             SelectedSoundAdaptersFile = SoundAdaptersA;
 
         }
+        #endregion
 
+        #region public static string GetATSRegValueString(string regValue)
         // Get a registry string
         public static string GetATSRegValueString(string regValue)
         {
             return GetRegValue(strATSregRoot, regValue);
         }
+        #endregion
 
-
+        #region public static int GetATSRegValueInt(string regValue)
         // Get a registry integer from the application key
         public static int GetATSRegValueInt(string regValue)
         {
             return GetRegValueInt(strATSregRoot, regValue);
         }
+        #endregion
 
+        #region public static void SetATSRegValue(string regValue, int value)
         // Set a registry integer in the the application key
         public static void SetATSRegValue(string regValue, int value)
         {
             SetRegValue(strATSregRoot, regValue, value);
         }
+        #endregion
 
+        #region public static void SetATSRegValue(string regValue, string value)
         // Set a registry string in the the application key
         public static void SetATSRegValue(string regValue, string value)
         {
             SetRegValue(strATSregRoot, regValue, value);
         }
+        #endregion
 
+        #region public static string GetRegValue(string regKey, string regValue)
         // Get a registry string
         public static string GetRegValue(string regKey, string regValue)
         {
@@ -224,7 +235,7 @@ namespace AnywhereTS
                 else
                 {
                     MessageBox.Show("Error when reading from registry (55222). Value missing. Key: " + regKey + " Value: " + regValue);
-                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                    using (log4net.NDC.Push(string.Format("key={0}", regKey)))
                     {
                         using (log4net.NDC.Push("Value is missing"))
                         {
@@ -249,7 +260,9 @@ namespace AnywhereTS
             }
             return ""; // No value could be retrieved from registry
         }
+        #endregion
 
+        #region public static int GetRegValueInt(string regKey, string regValue)
         // Get a registry integer
         public static int GetRegValueInt(string regKey, string regValue)
         {
@@ -325,7 +338,7 @@ namespace AnywhereTS
                 {
                     MessageBox.Show("Error when reading from registry (55222). Value missing. Key: " + regKey + " Value: " + regValue);
                  
-                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                        using (log4net.NDC.Push(string.Format("key={0}", regKey)))
                         {
                             using (log4net.NDC.Push("Value is missing"))
                             {
@@ -353,7 +366,9 @@ namespace AnywhereTS
             }
             return 0; // No value could be retrieved from registry
         }
+        #endregion
 
+        #region public static void SetRegValue(string regKey, string regValue, int value)
         // Set a registry integer
         public static void SetRegValue(string regKey, string regValue, int value)
         {
@@ -440,7 +455,9 @@ namespace AnywhereTS
                 Application.Exit();
             }
         }
+        #endregion
 
+        #region public static void SetRegValue(string regKey, string regValue, string value)
         // Set a registry string
         public static void SetRegValue(string regKey, string regValue, string value)
         {
@@ -526,7 +543,9 @@ namespace AnywhereTS
                 Application.Exit();
             }
         }
+        #endregion
 
+        #region public static bool RegValueExists(string regKey, string regValue)
         // Check if a registry int value exists
         public static bool RegValueExists(string regKey, string regValue)
         {
@@ -609,7 +628,9 @@ namespace AnywhereTS
             }
             return false; // No value could be retrieved from registry
         }
+        #endregion
 
+        #region public static string IsValidMAC(string macAddress)
         // Validate MAC a MAC address.
         public static string IsValidMAC(string macAddress)
         {
@@ -635,7 +656,9 @@ namespace AnywhereTS
                 return result;
             }
         }
+        #endregion
 
+        #region public static string GetMacFromATSname(string name)
         // Try to extract a mac address from an ATS client name in the format 'ATSxxxxxxxxxxxx', where xxxxxxxxxx is a mac address.
         public static string GetMacFromATSname(string name)
         {
@@ -656,7 +679,9 @@ namespace AnywhereTS
             // We have a MAC address
             return strMac;
         }
-
+        #endregion
+       
+        #region public static void CreateRegistryValues()
         // Create all needed registry values
         public static void CreateRegistryValues()
         {
@@ -707,183 +732,197 @@ namespace AnywhereTS
                 CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "IP_Pool", 335601418);
                 CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "Mask", 65535);
                 CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "PoolSize", 200);
-            }            
+            }
         }
+        #endregion
 
+        #region public static void CreateRegistryValue(string regKey, string regValue, int value)
         // If a registry key does not exist, create it with the given default value
-        public static void CreateRegistryValue(string regKey, string regValue, int value)
+        public static void CreateRegistryValue(string regKey, string regValue, int value)        
         {
-            Microsoft.Win32.RegistryKey objRegkey;
-            
-            try
+            using (log4net.NDC.Push(string.Format("key={0} name={1} data={2}",regKey, regValue, value)))
             {
-                objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey);
-            }
-            catch (ArgumentNullException e)
-            {
-                MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (92411)");
-                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                Logging.ATSAdminLog.InfoFormat(@"Creating value in Registry: {0}\{1}={2}", regKey, regValue, value);
+                Microsoft.Win32.RegistryKey objRegkey;
+
+                try
                 {
-                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                    objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey);
+                }
+                catch (ArgumentNullException e)
+                {
+                    MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (92411)");
+                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
                     {
-                        using (log4net.NDC.Push("Installation info missing"))
+                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
                         {
-                            Logging.ATSAdminLog.Error("Error when reading from registry.");
+                            using (log4net.NDC.Push("Installation info missing"))
+                            {
+                                Logging.ATSAdminLog.Error("Failed to create value in registry");
+                            }
                         }
                     }
+                    Application.Exit();
+                    return;
                 }
-                Application.Exit();
-                return;
-            }
-            catch (SecurityException e)
-            {
-                MessageBox.Show("Error when reading from registry. You do not have the necessary permission (92412). Key: "+ regKey + " Value: " + regValue + " Error details:" + e.Message);
-                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                catch (SecurityException e)
                 {
-                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                    MessageBox.Show("Error when reading from registry. You do not have the necessary permission (92412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
+                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
                     {
-                        using (log4net.NDC.Push("Invalid user rights"))
+                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
                         {
-                            Logging.ATSAdminLog.Error("Error when reading from registry.");
+                            using (log4net.NDC.Push("Invalid user rights"))
+                            {
+                                Logging.ATSAdminLog.Error("Failed to create value in registry");
+                            }
                         }
                     }
+                    Application.Exit();
+                    return;
                 }
-                Application.Exit();
-                return;
-            }
-            catch (Exception e)
-            {
-                MessageBox.Show("Error when reading from registry (92413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
-                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                catch (Exception e)
                 {
-                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                    MessageBox.Show("Error when reading from registry (92413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
+                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
                     {
-                            Logging.ATSAdminLog.Error("Error when reading from registry.");
-                        
+                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                        {
+                            Logging.ATSAdminLog.Error("Failed to create value in registry");
+
+                        }
                     }
+                    Application.Exit();
+                    return;
                 }
-                Application.Exit();
-                return;
-            }
-            
-            if (objRegkey != null)
-            {
-                if (objRegkey.GetValue(regValue) == null)
-                {   // No reg value, create one
-                    SetRegValue(regKey, regValue, value);
+
+                if (objRegkey != null)
+                {
+                    if (objRegkey.GetValue(regValue) == null)
+                    {   // No reg value, create one
+                        SetRegValue(regKey, regValue, value);
+                    }
                 }
-            }
-            else
-            {
-                MessageBox.Show("Error when reading from registry (95221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root);
-          
+                else
+                {
+                    MessageBox.Show("Error when reading from registry (95221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root);
+
                     using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
                     {
-                            Logging.ATSAdminLog.Error("Error when reading from registry.");                        
+                        Logging.ATSAdminLog.Error("Failed to create value in registry");
                     }
-                
-                Application.Exit();
+
+                    Application.Exit();
+                }
+                Logging.ATSAdminLog.InfoFormat(@"Created value in Registry: {0}\{1}={2}", regKey, regValue, value);
             }
         }
+#endregion
 
-
-
+        #region public static void CreateRegistryValue(string regKey, string regValue, string value)
         // If a registry key does not exist, create it with the given default value
         public static void CreateRegistryValue(string regKey, string regValue, string value)
         {
-            Microsoft.Win32.RegistryKey objRegkey;
-
-            try
+            using (log4net.NDC.Push(string.Format("key={0} name={1} data={2}", regKey, regValue, value)))
             {
-                objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey);
-            }
-            catch (ArgumentNullException e)
-            {
-                MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (92411)");
-                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                Logging.ATSAdminLog.InfoFormat(@"Creating value in Registry: {0}\{1}={2}", regKey, regValue, value);
+                Microsoft.Win32.RegistryKey objRegkey;
+
+                try
                 {
-                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                    objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey);
+                }
+                catch (ArgumentNullException e)
+                {
+                    MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (92411)");
+                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
                     {
-                        using (log4net.NDC.Push("Installation info missing"))
+                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
                         {
-                            Logging.ATSAdminLog.Error("Error when reading from registry.");
+                            using (log4net.NDC.Push("Installation info missing"))
+                            {
+                                Logging.ATSAdminLog.Error("Failed to create value in registry");
+                            }
                         }
                     }
+                    Application.Exit();
+                    return;
                 }
-                Application.Exit();
-                return;
-            }
-            catch (SecurityException e)
-            {
-                MessageBox.Show("Error when reading from registry. You do not have the necessary permission (92412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
-                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                catch (SecurityException e)
                 {
-                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                    MessageBox.Show("Error when reading from registry. You do not have the necessary permission (92412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
+                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
                     {
-                        using (log4net.NDC.Push("Invalid users rights"))
+                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
                         {
-                            Logging.ATSAdminLog.Error("Error when reading from registry.");
+                            using (log4net.NDC.Push("Invalid users rights"))
+                            {
+                                Logging.ATSAdminLog.Error("Failed to create value in registry");
+                            }
                         }
                     }
+                    Application.Exit();
+                    return;
                 }
-                Application.Exit();
-                return;
-            }
-            catch (Exception e)
-            {
-                MessageBox.Show("Error when reading from registry (92413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
-                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                catch (Exception e)
                 {
-                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                    MessageBox.Show("Error when reading from registry (92413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
+                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
                     {
-                            Logging.ATSAdminLog.Error("Error when reading from registry.");                        
+                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                        {
+                            Logging.ATSAdminLog.Error("Failed to create value in registry");
+                        }
                     }
+                    Application.Exit();
+                    return;
                 }
-                Application.Exit();
-                return;
-            }
 
-            if (objRegkey != null)
-            {
-                if (objRegkey.GetValue(regValue) == null)
-                {   // No reg value, create one
-                    SetRegValue(regKey, regValue, value);
+                if (objRegkey != null)
+                {
+                    if (objRegkey.GetValue(regValue) == null)
+                    {   // No reg value, create one
+                        SetRegValue(regKey, regValue, value);
+                    }
                 }
-            }
-            else
-            {
-                MessageBox.Show("Error when reading from registry (95221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root);
-            
+                else
+                {
+                    MessageBox.Show("Error when reading from registry (95221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root);
+
                     using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
                     {
-                            Logging.ATSAdminLog.Error("Error when reading from registry.");                       
+                        Logging.ATSAdminLog.Error("Failed to create value in registry");
                     }
-                
-                Application.Exit();
+
+                    Application.Exit();
+                }
+                Logging.ATSAdminLog.InfoFormat(@"Created value in Registry: {0}\{1}={2}", regKey, regValue, value);
             }
         }
+        #endregion
 
+        #region public static bool ExtractIntegers(string integers, char separator, out int[] parsed_integers)
         // Extract two integers from a string, separated by a character
         // Result: True = extraction ok, false = invalid string.
         // twointegers: String with two integers, separated by a character
         // separator: the character separating the strings
         // value1: (out) The first integer in the string
         // value2: (out) The second integer in the string
-        public static bool ExtractIntegers(string twointegers, char separator, out int value1, out int value2)
+        public static bool ExtractIntegers(string integers, char separator, out int[] parsed_integers)
         {
             string[] parts;
-            value1 = 0; // Default
-            value2 = 0; // Default
-            parts = twointegers.Split(separator);
-            if (parts.Length != 2)
+            parsed_integers = new int[0];
+            parts = integers.Split(separator);
+
+            List<int> t_ints = new List<int>();
+
+            foreach (string t in parts)
             {
-                return false;
+                t_ints.Add(Convert.ToInt32(t));
             }
-            // Convert and return
-            value1 = Convert.ToInt32(parts[0]); // Default
-            value2 = Convert.ToInt32(parts[1]); // Default
+            parsed_integers = t_ints.ToArray();     
             return true;
         }
-
+        #endregion
     } // Class ATSGlobals
 } // Namespace Anywhere TS