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

# Line 12 | Line 12 | namespace AnywhereTS
12   {
13      public static class ATSGlobals
14      {
15 +        #region Global Definitions
16          // Version
17          public const string strDatabaseVersion = "1.0.0.4"; // The version string for the ATS database
18          public const string strDatabaseName = "AnywhereTS"; // THe name of the ATS database
# Line 61 | Line 62 | namespace AnywhereTS
62  
63          // Client connect time options
64          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 } };
65 <
65 > #endregion
66 >        #region static ATSGlobals()
67          // Constructor
68          static ATSGlobals()
69          {
# Line 127 | Line 129 | namespace AnywhereTS
129              SelectedSoundAdaptersFile = SoundAdaptersA;
130  
131          }
132 +        #endregion
133  
134 +        #region public static string GetATSRegValueString(string regValue)
135          // Get a registry string
136          public static string GetATSRegValueString(string regValue)
137          {
138              return GetRegValue(strATSregRoot, regValue);
139          }
140 +        #endregion
141  
142 <
142 >        #region public static int GetATSRegValueInt(string regValue)
143          // Get a registry integer from the application key
144          public static int GetATSRegValueInt(string regValue)
145          {
146              return GetRegValueInt(strATSregRoot, regValue);
147          }
148 +        #endregion
149  
150 +        #region public static void SetATSRegValue(string regValue, int value)
151          // Set a registry integer in the the application key
152          public static void SetATSRegValue(string regValue, int value)
153          {
154              SetRegValue(strATSregRoot, regValue, value);
155          }
156 +        #endregion
157  
158 +        #region public static void SetATSRegValue(string regValue, string value)
159          // Set a registry string in the the application key
160          public static void SetATSRegValue(string regValue, string value)
161          {
162              SetRegValue(strATSregRoot, regValue, value);
163          }
164 +        #endregion
165  
166 +        #region public static string GetRegValue(string regKey, string regValue)
167          // Get a registry string
168          public static string GetRegValue(string regKey, string regValue)
169          {
# Line 224 | Line 235 | namespace AnywhereTS
235                  else
236                  {
237                      MessageBox.Show("Error when reading from registry (55222). Value missing. Key: " + regKey + " Value: " + regValue);
238 <                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
238 >                    using (log4net.NDC.Push(string.Format("key={0}", regKey)))
239                      {
240                          using (log4net.NDC.Push("Value is missing"))
241                          {
# Line 249 | Line 260 | namespace AnywhereTS
260              }
261              return ""; // No value could be retrieved from registry
262          }
263 +        #endregion
264  
265 +        #region public static int GetRegValueInt(string regKey, string regValue)
266          // Get a registry integer
267          public static int GetRegValueInt(string regKey, string regValue)
268          {
# Line 325 | Line 338 | namespace AnywhereTS
338                  {
339                      MessageBox.Show("Error when reading from registry (55222). Value missing. Key: " + regKey + " Value: " + regValue);
340                  
341 <                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
341 >                        using (log4net.NDC.Push(string.Format("key={0}", regKey)))
342                          {
343                              using (log4net.NDC.Push("Value is missing"))
344                              {
# Line 353 | Line 366 | namespace AnywhereTS
366              }
367              return 0; // No value could be retrieved from registry
368          }
369 +        #endregion
370  
371 +        #region public static void SetRegValue(string regKey, string regValue, int value)
372          // Set a registry integer
373          public static void SetRegValue(string regKey, string regValue, int value)
374          {
# Line 440 | Line 455 | namespace AnywhereTS
455                  Application.Exit();
456              }
457          }
458 +        #endregion
459  
460 +        #region public static void SetRegValue(string regKey, string regValue, string value)
461          // Set a registry string
462          public static void SetRegValue(string regKey, string regValue, string value)
463          {
# Line 526 | Line 543 | namespace AnywhereTS
543                  Application.Exit();
544              }
545          }
546 +        #endregion
547  
548 +        #region public static bool RegValueExists(string regKey, string regValue)
549          // Check if a registry int value exists
550          public static bool RegValueExists(string regKey, string regValue)
551          {
# Line 609 | Line 628 | namespace AnywhereTS
628              }
629              return false; // No value could be retrieved from registry
630          }
631 +        #endregion
632  
633 +        #region public static string IsValidMAC(string macAddress)
634          // Validate MAC a MAC address.
635          public static string IsValidMAC(string macAddress)
636          {
# Line 635 | Line 656 | namespace AnywhereTS
656                  return result;
657              }
658          }
659 +        #endregion
660  
661 +        #region public static string GetMacFromATSname(string name)
662          // Try to extract a mac address from an ATS client name in the format 'ATSxxxxxxxxxxxx', where xxxxxxxxxx is a mac address.
663          public static string GetMacFromATSname(string name)
664          {
# Line 656 | Line 679 | namespace AnywhereTS
679              // We have a MAC address
680              return strMac;
681          }
682 <
682 >        #endregion
683 >      
684 >        #region public static void CreateRegistryValues()
685          // Create all needed registry values
686          public static void CreateRegistryValues()
687          {
# Line 707 | Line 732 | namespace AnywhereTS
732                  CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "IP_Pool", 335601418);
733                  CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "Mask", 65535);
734                  CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "PoolSize", 200);
735 <            }            
735 >            }
736          }
737 +        #endregion
738  
739 +        #region public static void CreateRegistryValue(string regKey, string regValue, int value)
740          // If a registry key does not exist, create it with the given default value
741 <        public static void CreateRegistryValue(string regKey, string regValue, int value)
741 >        public static void CreateRegistryValue(string regKey, string regValue, int value)        
742          {
743 <            Microsoft.Win32.RegistryKey objRegkey;
717 <            
718 <            try
743 >            using (log4net.NDC.Push(string.Format("key={0} name={1} data={2}",regKey, regValue, value)))
744              {
745 <                objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey);
746 <            }
747 <            catch (ArgumentNullException e)
748 <            {
724 <                MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (92411)");
725 <                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
745 >                Logging.ATSAdminLog.InfoFormat(@"Creating value in Registry: {0}\{1}={2}", regKey, regValue, value);
746 >                Microsoft.Win32.RegistryKey objRegkey;
747 >
748 >                try
749                  {
750 <                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
750 >                    objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey);
751 >                }
752 >                catch (ArgumentNullException e)
753 >                {
754 >                    MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (92411)");
755 >                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
756                      {
757 <                        using (log4net.NDC.Push("Installation info missing"))
757 >                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
758                          {
759 <                            Logging.ATSAdminLog.Error("Error when reading from registry.");
759 >                            using (log4net.NDC.Push("Installation info missing"))
760 >                            {
761 >                                Logging.ATSAdminLog.Error("Failed to create value in registry");
762 >                            }
763                          }
764                      }
765 +                    Application.Exit();
766 +                    return;
767                  }
768 <                Application.Exit();
736 <                return;
737 <            }
738 <            catch (SecurityException e)
739 <            {
740 <                MessageBox.Show("Error when reading from registry. You do not have the necessary permission (92412). Key: "+ regKey + " Value: " + regValue + " Error details:" + e.Message);
741 <                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
768 >                catch (SecurityException e)
769                  {
770 <                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
770 >                    MessageBox.Show("Error when reading from registry. You do not have the necessary permission (92412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
771 >                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
772                      {
773 <                        using (log4net.NDC.Push("Invalid user rights"))
773 >                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
774                          {
775 <                            Logging.ATSAdminLog.Error("Error when reading from registry.");
775 >                            using (log4net.NDC.Push("Invalid user rights"))
776 >                            {
777 >                                Logging.ATSAdminLog.Error("Failed to create value in registry");
778 >                            }
779                          }
780                      }
781 +                    Application.Exit();
782 +                    return;
783                  }
784 <                Application.Exit();
752 <                return;
753 <            }
754 <            catch (Exception e)
755 <            {
756 <                MessageBox.Show("Error when reading from registry (92413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
757 <                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
784 >                catch (Exception e)
785                  {
786 <                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
786 >                    MessageBox.Show("Error when reading from registry (92413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
787 >                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
788                      {
789 <                            Logging.ATSAdminLog.Error("Error when reading from registry.");
790 <                        
789 >                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
790 >                        {
791 >                            Logging.ATSAdminLog.Error("Failed to create value in registry");
792 >
793 >                        }
794                      }
795 +                    Application.Exit();
796 +                    return;
797                  }
798 <                Application.Exit();
799 <                return;
800 <            }
801 <            
802 <            if (objRegkey != null)
803 <            {
804 <                if (objRegkey.GetValue(regValue) == null)
772 <                {   // No reg value, create one
773 <                    SetRegValue(regKey, regValue, value);
798 >
799 >                if (objRegkey != null)
800 >                {
801 >                    if (objRegkey.GetValue(regValue) == null)
802 >                    {   // No reg value, create one
803 >                        SetRegValue(regKey, regValue, value);
804 >                    }
805                  }
806 <            }
807 <            else
808 <            {
809 <                MessageBox.Show("Error when reading from registry (95221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root);
779 <          
806 >                else
807 >                {
808 >                    MessageBox.Show("Error when reading from registry (95221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root);
809 >
810                      using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
811                      {
812 <                            Logging.ATSAdminLog.Error("Error when reading from registry.");                        
812 >                        Logging.ATSAdminLog.Error("Failed to create value in registry");
813                      }
814 <                
815 <                Application.Exit();
814 >
815 >                    Application.Exit();
816 >                }
817 >                Logging.ATSAdminLog.InfoFormat(@"Created value in Registry: {0}\{1}={2}", regKey, regValue, value);
818              }
819          }
820 + #endregion
821  
822 <
790 <
822 >        #region public static void CreateRegistryValue(string regKey, string regValue, string value)
823          // If a registry key does not exist, create it with the given default value
824          public static void CreateRegistryValue(string regKey, string regValue, string value)
825          {
826 <            Microsoft.Win32.RegistryKey objRegkey;
795 <
796 <            try
826 >            using (log4net.NDC.Push(string.Format("key={0} name={1} data={2}", regKey, regValue, value)))
827              {
828 <                objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey);
829 <            }
830 <            catch (ArgumentNullException e)
831 <            {
802 <                MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (92411)");
803 <                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
828 >                Logging.ATSAdminLog.InfoFormat(@"Creating value in Registry: {0}\{1}={2}", regKey, regValue, value);
829 >                Microsoft.Win32.RegistryKey objRegkey;
830 >
831 >                try
832                  {
833 <                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
833 >                    objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey);
834 >                }
835 >                catch (ArgumentNullException e)
836 >                {
837 >                    MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (92411)");
838 >                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
839                      {
840 <                        using (log4net.NDC.Push("Installation info missing"))
840 >                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
841                          {
842 <                            Logging.ATSAdminLog.Error("Error when reading from registry.");
842 >                            using (log4net.NDC.Push("Installation info missing"))
843 >                            {
844 >                                Logging.ATSAdminLog.Error("Failed to create value in registry");
845 >                            }
846                          }
847                      }
848 +                    Application.Exit();
849 +                    return;
850                  }
851 <                Application.Exit();
814 <                return;
815 <            }
816 <            catch (SecurityException e)
817 <            {
818 <                MessageBox.Show("Error when reading from registry. You do not have the necessary permission (92412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
819 <                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
851 >                catch (SecurityException e)
852                  {
853 <                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
853 >                    MessageBox.Show("Error when reading from registry. You do not have the necessary permission (92412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
854 >                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
855                      {
856 <                        using (log4net.NDC.Push("Invalid users rights"))
856 >                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
857                          {
858 <                            Logging.ATSAdminLog.Error("Error when reading from registry.");
858 >                            using (log4net.NDC.Push("Invalid users rights"))
859 >                            {
860 >                                Logging.ATSAdminLog.Error("Failed to create value in registry");
861 >                            }
862                          }
863                      }
864 +                    Application.Exit();
865 +                    return;
866                  }
867 <                Application.Exit();
830 <                return;
831 <            }
832 <            catch (Exception e)
833 <            {
834 <                MessageBox.Show("Error when reading from registry (92413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
835 <                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
867 >                catch (Exception e)
868                  {
869 <                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
869 >                    MessageBox.Show("Error when reading from registry (92413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
870 >                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
871                      {
872 <                            Logging.ATSAdminLog.Error("Error when reading from registry.");                        
872 >                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
873 >                        {
874 >                            Logging.ATSAdminLog.Error("Failed to create value in registry");
875 >                        }
876                      }
877 +                    Application.Exit();
878 +                    return;
879                  }
842                Application.Exit();
843                return;
844            }
880  
881 <            if (objRegkey != null)
882 <            {
883 <                if (objRegkey.GetValue(regValue) == null)
884 <                {   // No reg value, create one
885 <                    SetRegValue(regKey, regValue, value);
881 >                if (objRegkey != null)
882 >                {
883 >                    if (objRegkey.GetValue(regValue) == null)
884 >                    {   // No reg value, create one
885 >                        SetRegValue(regKey, regValue, value);
886 >                    }
887                  }
888 <            }
889 <            else
890 <            {
891 <                MessageBox.Show("Error when reading from registry (95221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root);
856 <            
888 >                else
889 >                {
890 >                    MessageBox.Show("Error when reading from registry (95221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root);
891 >
892                      using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
893                      {
894 <                            Logging.ATSAdminLog.Error("Error when reading from registry.");                      
894 >                        Logging.ATSAdminLog.Error("Failed to create value in registry");
895                      }
896 <                
897 <                Application.Exit();
896 >
897 >                    Application.Exit();
898 >                }
899 >                Logging.ATSAdminLog.InfoFormat(@"Created value in Registry: {0}\{1}={2}", regKey, regValue, value);
900              }
901          }
902 +        #endregion
903  
904 +        #region public static bool ExtractIntegers(string integers, char separator, out int[] parsed_integers)
905          // Extract two integers from a string, separated by a character
906          // Result: True = extraction ok, false = invalid string.
907          // twointegers: String with two integers, separated by a character
908          // separator: the character separating the strings
909          // value1: (out) The first integer in the string
910          // value2: (out) The second integer in the string
911 <        public static bool ExtractIntegers(string twointegers, char separator, out int value1, out int value2)
911 >        public static bool ExtractIntegers(string integers, char separator, out int[] parsed_integers)
912          {
913              string[] parts;
914 <            value1 = 0; // Default
915 <            value2 = 0; // Default
916 <            parts = twointegers.Split(separator);
917 <            if (parts.Length != 2)
914 >            parsed_integers = new int[0];
915 >            parts = integers.Split(separator);
916 >
917 >            List<int> t_ints = new List<int>();
918 >
919 >            foreach (string t in parts)
920              {
921 <                return false;
921 >                t_ints.Add(Convert.ToInt32(t));
922              }
923 <            // Convert and return
883 <            value1 = Convert.ToInt32(parts[0]); // Default
884 <            value2 = Convert.ToInt32(parts[1]); // Default
923 >            parsed_integers = t_ints.ToArray();    
924              return true;
925          }
926 <
926 >        #endregion
927      } // Class ATSGlobals
928   } // Namespace Anywhere TS

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines