OzZy_M

Get all active servers

Feb 15th, 2012
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1.     public static SectionClasses.Server[] GetAllActiveServers()
  2.     {
  3.       SectionClasses.Server[] RC = null;
  4.       System.Collections.Hashtable ServerData = new System.Collections.Hashtable();
  5.  
  6.       using (var Context = new STDBEntities())
  7.       {
  8.         try
  9.         {
  10.           var Query = (
  11.             from s in Context.Servers
  12.             from c in Context.Contacts
  13.             where s.PrimaryContactID == c.ContactID &&
  14.             s.Active == true
  15.             select new
  16.             {
  17.               s.ServerName,
  18.               s.PrimaryContactID,
  19.               s.ServerLocation,
  20.               s.ServerType.ServerTypeName,
  21.               s.IsLocked,
  22.               c.Name,
  23.               s.ServerID
  24.             }
  25.           );
  26.           int i = 0;
  27.           RC = new SectionClasses.Server[Query.Count()];
  28.           foreach (var Set in Query)
  29.           {
  30.             ServerData.Clear();
  31.             ServerData.Add("ServerID", Set.ServerID);
  32.             ServerData.Add("ServerName", Set.ServerName);
  33.             ServerData.Add("ServerLocation", Set.ServerLocation);
  34.             ServerData.Add("ServerTypeID", Set.ServerTypeName);
  35.             ServerData.Add("IsLocked", Set.IsLocked);
  36.             System.Collections.Hashtable temp = new System.Collections.Hashtable();
  37.             temp.Add("ContactID", Set.PrimaryContactID);
  38.             temp.Add("Name", Set.Name);
  39.             ServerData.Add("PrimaryContactID", new SectionClasses.Contact(temp));
  40.             RC[i++] = new SectionClasses.Server(ServerData);
  41.           }
  42.         }
  43.         catch (InvalidKeyException e)
  44.         {
  45.           Context.Connection.Close();
  46.           Console.WriteLine(e.Message);
  47.         }
  48.         catch
  49.         {
  50.           Context.Connection.Close();
  51.           throw new Exception("Connection to Database could not be established");
  52.         }
  53.       }
  54.  
  55.       return RC;
  56.     }
Advertisement
Add Comment
Please, Sign In to add comment