Ejemplo n.º 1
0
 /// <summary>
 /// Gets hardware and internet connection information about a computer.
 /// </summary>
 /// <returns>A <see cref="CWComputerInfo"/> struct.</returns>
 public static CWComputerInfo GetComputerInfo()
 {
     CWComputerInfo info=new CWComputerInfo();
     info.CPUType=CPUType();
     info.RAMSize=MemorySize();
     info.HDDSpace=FreeDiskSpace();
     info.ConnectionSpeed=NetSpeed();
     return info;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Produces a hash code for a <see cref="CWComputerInfo"/> object not including
 /// the HDDSize value in order to make the detection of hardware changes easy.
 /// </summary>
 /// <param name="info">
 /// The <see cref="CWComputerInfo"/> whose hash code is to be calculated.
 /// </param>
 /// <returns>
 /// The lower part of the input's SHA1 Hash Code as a 64 bit unsigned long.
 /// </returns>
 public static ulong GetSHA1HashCode(CWComputerInfo info)
 {
     UInt64 hash=0;
     string hwinfo=info.CPUType + " " + info.RAMSize.ToString() + " " + info.ConnectionSpeed.ToString();
     byte [] hashcode=SHA1Hash.SHA1(System.Text.Encoding.GetEncoding(1253).GetBytes(hwinfo));
     for(int i=0; i<8; i++)
     {
         hash <<= 8;
         hash |= hashcode[hashcode.Length-i-1];
     }
     GC.Collect();
     return hash;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Updates the computer hardware info related to a client.
 /// </summary>
 /// <param name="ci">The <see cref="ClientInfo"/> of the client.</param>
 /// <param name="info">The <see cref="CWComputerInfo"/> of the client computer.</param>
 /// <returns>Null if the operation succeeds, or <see cref="SerializedException"/> 
 /// encapsulating the error that occured if the operation fails.</returns>
 public SerializedException StoreNewClientComputerInfo(ClientInfo ci, CWComputerInfo info)
 {
     SerializedException sx = null;
     try
     {
         if (!ConnectToDatabase())
         {
             throw new CWDBConnectionFailedException();
         }
         SqlCommand cmd = new SqlCommand("cw_update_client", dbcon);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.Add("@client_id", SqlDbType.UniqueIdentifier);
         cmd.Parameters.Add("@user_id", SqlDbType.Int);
         cmd.Parameters.Add("@info_cpu", SqlDbType.NVarChar, 50);
         cmd.Parameters.Add("@info_ram", SqlDbType.SmallInt);
         cmd.Parameters.Add("@info_hdd", SqlDbType.Int);
         cmd.Parameters.Add("@info_net", SqlDbType.TinyInt);
         cmd.Parameters[0].Value = ci.ClientID;
         cmd.Parameters[1].Value = ci.UserID;
         cmd.Parameters[2].Value = info.CPUType;
         cmd.Parameters[3].Value = info.RAMSize;
         cmd.Parameters[4].Value = info.HDDSpace;
         cmd.Parameters[5].Value = (byte)info.ConnectionSpeed;
         cmd.ExecuteNonQuery();
         cmd.Dispose();
         if (!DisconnectFromDatabase())
         {
             throw new CWDBConnectionFailedException("Disconnect from database failure.");
         }
     }
     catch (Exception e)
     {
         sx = new SerializedException(e.GetType().ToString(), e.Message, e.ToString());
         if (settings.LogLevel <= CWLogLevel.LogWarning)
         {
             settings.Log.LogWarning("StoreNewClientComputerInfo failed: " + e.ToString());
         }
     }
     finally
     {
         LogClientAction(ci, CWClientActions.LogGetClientComputerInfo);
     }
     return sx;
 }
Ejemplo n.º 4
0
 public SerializedException RegisterClient(ref ClientInfo ci, CWComputerInfo info)
 {
     return engine.StoreClientRegistrationInfo(ref ci, info);
 }
Ejemplo n.º 5
0
 public SerializedException GetClientComputerInfo(ClientInfo ci, CWComputerInfo info)
 {
     return engine.StoreNewClientComputerInfo(ci, info);
 }