Esempio n. 1
0
        /// <summary>
        /// Selects and returns the statistics for a certain user.
        /// </summary>
        /// <param name="ci">The <see cref="ClientInfo"/> of the client requesting the statistics.</param>
        /// <param name="stats">The <see cref="UserStatistics"/> of the user.</param>
        /// <returns>Null if the operation succeeds, or <see cref="SerializedException"/> 
        /// encapsulating the error that occured if the operation fails.</returns>
        public SerializedException SelectUserStatistics(ClientInfo ci, ref UserStatistics stats)
        {
            SerializedException sx = null;
            try
            {
                if (!ConnectToDatabase())
                {
                    throw new CWDBConnectionFailedException();
                }
                SqlCommand cmd = new SqlCommand("cw_select_user_statistic", dbcon);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@user_id", SqlDbType.Int);
                cmd.Parameters[0].Value = ci.UserID;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds);
                da.Dispose();
                cmd.Dispose();
                if (ds.Tables[0].Rows.Count > 0)
                {
                    stats.RegistrationDate = (DateTime)ds.Tables[0].Rows[0][2];
                    stats.LastActive = (DateTime)ds.Tables[0].Rows[0][6];

                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        stats.NumClients++;
                        stats.UrlsAssigned += (long)dr[4];
                        stats.UrlsReturned += (long)dr[5];
                        DateTime la = (DateTime)dr[6];
                        if (la > stats.LastActive)
                        {
                            stats.LastActive = la;
                        }
                    }
                }
                ds.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("SelectUserStatistics failed for user " + ci.UserID.ToString() + ":" + e.ToString());
                }
            }
            finally
            {
                UpdateClientLastActive(ci);
                LogClientAction(ci, CWClientActions.LogSendUserStatistics);
            }
            return sx;
        }
Esempio n. 2
0
 /// <summary>
 /// Attempts to retrieve the user's statistics from the server.
 /// </summary>
 /// <param name="stats">The statistics of the user.</param>
 /// <returns>Null if the operation succeeds, or a <see cref="SerializedException"/> 
 /// encapsulating the error that occured if the operation fails.</returns>
 public SerializedException GetUserStatistics(ref UserStatistics stats)
 {
     SerializedException sx = null;
     try
     {
         //WebServiceProxy proxy = WebServiceProxy.Instance();
         UserStatistics userstats = null;
         sx = proxy.SendUserStatistics(globals.Client_Info, out userstats);
         if(sx!=null)
         {
             log.LogError("An error occured while retrieving the statistics:" + sx.Message);
             globals.FileLog.LogWarning("CrawlWave.Client: Failed to retrieve user's statistics: " + sx.Message);
             stats = userstats;
         }
     }
     catch(Exception e)
     {
         log.LogWarning("An error occured while retrieving the statistics: " + e.Message);
         globals.FileLog.LogWarning("CrawlWave.Client: Failed to retrieve user's statistics: " + e.ToString());
         sx = new SerializedException(e.GetType().ToString(), e.Message, e.StackTrace);
     }
     finally
     {
         GC.Collect();
     }
     return sx;
 }
Esempio n. 3
0
 public SerializedException SendUserStatistics(ClientInfo ci, out UserStatistics stats)
 {
     stats = new UserStatistics();
     engine.LogClientAction(ci, CWClientActions.LogSendUserStatistics);
     return engine.SelectUserStatistics(ci, ref stats);
 }