Example #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);
        }
Example #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);
        }
Example #3
0
        /// <summary>
        /// Performs the registration of a new client for a registered user of the system.
        /// </summary>
        /// <param name="ci">The <see cref="ClientInfo"/> of the client that wishes to be
        /// registered to the system.</param>
        /// <param name="info">The <see cref="CWComputerInfo"/> of the computer running the
        /// client.</param>
        /// <returns>Null if the operation succeeds, or <see cref="SerializedException"/>
        /// encapsulating the error that occured if the operation fails.</returns>
        public SerializedException StoreClientRegistrationInfo(ref ClientInfo ci, CWComputerInfo info)
        {
            SerializedException sx = null;

            try
            {
                if (!ConnectToDatabase())
                {
                    throw new CWDBConnectionFailedException();
                }
                ci.ClientID = Guid.NewGuid();
                SqlCommand cmd = new SqlCommand("cw_insert_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("StoreClientRegistrationInfo failed: " + e.ToString());
                }
            }
            finally
            {
                LogClientAction(ci, CWClientActions.LogRegisterClient);
            }
            return(sx);
        }
Example #4
0
        /// <summary>
        /// Attempts to perform the registration of a new user.
        /// </summary>
        /// <param name="UserName">The user's username.</param>
        /// <param name="Password">The user's password.</param>
        /// <param name="Email">The user's email address.</param>
        /// <returns>Null if the operation succeeds, or a <see cref="SerializedException"/>
        /// encapsulating the error that occured if the operation fails.</returns>
        public SerializedException RegisterUser(string UserName, string Password, string Email)
        {
            SerializedException sx = null;

            try
            {
                //WebServiceProxy proxy = WebServiceProxy.Instance();
                int     ID       = 0;
                byte [] password = MD5Hash.md5(Password);
                sx = proxy.RegisterUser(ref ID, UserName, password, Email);
                if (sx != null)
                {
                    if (sx.Type == "CrawlWave.Common.CWUserExistsException")
                    {
                        log.LogWarning("User already exists, attempting to register client.");
                    }
                }
                globals.Settings.UserID   = ID;
                globals.Settings.UserName = UserName;
                globals.Settings.Password = password;
                globals.Settings.Email    = Email;
                CWComputerInfo info = ComputerInfo.GetComputerInfo();
                globals.Settings.HardwareInfo = ComputerInfo.GetSHA1HashCode(info);
                globals.Settings.SaveSettings();
                //proxy.ForceInitializeProxies();
                ClientInfo ci = new ClientInfo();
                ci.UserID = globals.Settings.UserID;
                sx        = proxy.RegisterClient(ref ci, info);
                globals.Settings.ClientID = ci.ClientID;
                globals.Settings.SaveSettings();
            }
            catch (Exception ex)
            {
                sx = new SerializedException(ex.GetType().ToString(), ex.Message, ex.StackTrace);
            }
            return(sx);
        }
Example #5
0
 public SerializedException RegisterClient(ref ClientInfo ci, CWComputerInfo info)
 {
     return(engine.StoreClientRegistrationInfo(ref ci, info));
 }
Example #6
0
 public SerializedException GetClientComputerInfo(ClientInfo ci, CWComputerInfo info)
 {
     return(engine.StoreNewClientComputerInfo(ci, info));
 }