Ejemplo n.º 1
0
        /// <summary>
        /// Loads the settings of the application from the configuration file.
        /// </summary>
        public void LoadSettings()
        {
            //we must use Globals.GetAppPath because the Globals instance will not have
            //been created yet
            string ConfigFile = Globals.GetAppPath() + "data\\CrawlWave.Client.Config.xml";

            try
            {
                if (!File.Exists(ConfigFile))
                {
                    //perhaps the file does not exist - probably because it has not been
                    //created yet. In this case just let the class retain default values.
                    return;
                }
                Stream        ReadStream = File.Open(ConfigFile, FileMode.Open);
                XmlSerializer serializer = new XmlSerializer(typeof(AppSettings));
                AppSettings   settings   = (AppSettings)serializer.Deserialize(ReadStream);
                ReadStream.Close();
                this.ClientID        = settings.ClientID;
                this.ConnectionSpeed = settings.ConnectionSpeed;
                this.Email           = settings.Email;
                this.EnableScheduler = settings.EnableScheduler;
                this.HardwareInfo    = settings.HardwareInfo;
                this.LoadAtStartup   = settings.LoadAtStartup;
                this.MinimizeOnExit  = settings.MinimizeOnExit;
                this.MinimizeToTray  = settings.MinimizeToTray;
                this.Password        = settings.Password;
                this.StartTime       = settings.StartTime;
                this.StopTime        = settings.StopTime;
                this.UserID          = settings.UserID;
                this.UserName        = settings.UserName;
            }
            catch
            {}
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs a new instance of the <see cref="ClientSettings"/> class and attempts
        /// to load the settings from the provided file.
        /// </summary>
        /// <param name="fileName">The path of the configuration file.</param>
        public ClientSettings(string fileName)
        {
            if ((fileName == null) || (fileName == String.Empty))
            {
                throw new ArgumentException("The filename cannot be empty");
            }
            LoadAtStartup   = false;
            MinimizeToTray  = false;
            MinimizeOnExit  = false;
            EnableScheduler = false;
            StartTime       = DateTime.Now;
            StopTime        = DateTime.Now;
            UserID          = 0;
            UserName        = String.Empty;
            Password        = null;
            Email           = String.Empty;
            ClientID        = Guid.Empty;
            HardwareInfo    = 0;
            LogLevel        = CWLogLevel.LogInfo;
            ConnectionSpeed = CWConnectionSpeed.Unknown;

            RemotingHost     = "localhost";
            RemotingProtocol = "tcp";
            RemotingPort     = 15461;

            configFile = fileName;
            LoadSettings();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructs an instance of <see cref="CWComputerInfo"/> struct and initializes it
 /// with the supplied values.
 /// </summary>
 /// <param name="CPU">A string describibg the CPU type and speed in MHz.</param>
 /// <param name="RAM">The RAM size in MB.</param>
 /// <param name="HDD">The free HDD space in MB.</param>
 /// <param name="Speed">The <see cref="CWConnectionSpeed">Internet connection speed</see> of the system.</param>
 public CWComputerInfo(string CPU, int RAM, int HDD, CWConnectionSpeed Speed)
 {
     CPUType = CPU;
     if (RAM < 0)
     {
         throw new ArgumentOutOfRangeException("RAM", "The RAM size cannot be negative.");
     }
     RAMSize = RAM;
     if (HDD < 0)
     {
         throw new ArgumentOutOfRangeException("HDD", "The HDD space cannot be negative.");
     }
     HDDSpace        = HDD;
     ConnectionSpeed = Speed;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructs an instance of the <see cref="AppSettings"/> class with the default values.
 /// </summary>
 public AppSettings()
 {
     LoadAtStartup   = false;
     MinimizeToTray  = false;
     MinimizeOnExit  = false;
     EnableScheduler = false;
     StartTime       = DateTime.Now;
     StopTime        = DateTime.Now;
     UserID          = 0;
     UserName        = String.Empty;
     Password        = null;
     Email           = String.Empty;
     ClientID        = Guid.Empty;
     HardwareInfo    = 0;
     LogLevel        = CWLogLevel.LogInfo;
     ConnectionSpeed = CWConnectionSpeed.Unknown;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Loads the settings of the application from the configuration file.
        /// </summary>
        public void LoadSettings()
        {
            if (configFile == String.Empty)
            {
                throw new InvalidOperationException("The class cannot load its settings because the Config File path has not been initialized. Use ClientSettings(string fileName) instead.");
            }
            try
            {
                if (!File.Exists(configFile))
                {
                    //perhaps the file does not exist - probably because it has not been
                    //created yet. In this case just let the class retain default values.
                    return;
                }
                Stream         ReadStream = File.Open(configFile, FileMode.Open);
                XmlSerializer  serializer = new XmlSerializer(typeof(ClientSettings));
                ClientSettings settings   = (ClientSettings)serializer.Deserialize(ReadStream);
                ReadStream.Close();
                this.ClientID        = settings.ClientID;
                this.ConnectionSpeed = settings.ConnectionSpeed;
                this.Email           = settings.Email;
                this.EnableScheduler = settings.EnableScheduler;
                this.HardwareInfo    = settings.HardwareInfo;
                this.LoadAtStartup   = settings.LoadAtStartup;
                this.MinimizeOnExit  = settings.MinimizeOnExit;
                this.MinimizeToTray  = settings.MinimizeToTray;
                this.Password        = settings.Password;
                this.StartTime       = settings.StartTime;
                this.StopTime        = settings.StopTime;
                this.UserID          = settings.UserID;
                this.UserName        = settings.UserName;

                this.RemotingHost     = settings.RemotingHost;
                this.RemotingProtocol = settings.RemotingProtocol;
                this.RemotingPort     = settings.RemotingPort;
            }
            catch
            {}
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Constructs an instance of the <see cref="ClientSettings"/> class with the default values.
        /// </summary>
        public ClientSettings()
        {
            LoadAtStartup   = false;
            MinimizeToTray  = false;
            MinimizeOnExit  = false;
            EnableScheduler = false;
            StartTime       = DateTime.Now;
            StopTime        = DateTime.Now;
            UserID          = 0;
            UserName        = String.Empty;
            Password        = null;
            Email           = String.Empty;
            ClientID        = Guid.Empty;
            HardwareInfo    = 0;
            LogLevel        = CWLogLevel.LogInfo;
            ConnectionSpeed = CWConnectionSpeed.Unknown;

            RemotingHost     = "localhost";
            RemotingProtocol = "tcp";
            RemotingPort     = 15461;

            configFile = String.Empty;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Constructs an instance of <see cref="CWComputerInfo"/> struct and initializes it
 /// with the supplied values.
 /// </summary>
 /// <param name="CPU">A string describibg the CPU type and speed in MHz.</param>
 /// <param name="RAM">The RAM size in MB.</param>
 /// <param name="HDD">The free HDD space in MB.</param>
 /// <param name="Speed">The <see cref="CWConnectionSpeed">Internet connection speed</see> of the system.</param>
 public CWComputerInfo(string CPU, int RAM, int HDD, CWConnectionSpeed Speed)
 {
     CPUType = CPU;
     if(RAM<0)
     {
         throw new ArgumentOutOfRangeException("RAM","The RAM size cannot be negative.");
     }
     RAMSize = RAM;
     if(HDD<0)
     {
         throw new ArgumentOutOfRangeException("HDD","The HDD space cannot be negative.");
     }
     HDDSpace = HDD;
     ConnectionSpeed = Speed;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Loads the settings of the application from the configuration file.
 /// </summary>
 public void LoadSettings()
 {
     //we must use Globals.GetAppPath because the Globals instance will not have
     //been created yet
     string ConfigFile=Globals.GetAppPath()+"data\\CrawlWave.Client.Config.xml";
     try
     {
         if(!File.Exists(ConfigFile))
         {
             //perhaps the file does not exist - probably because it has not been
             //created yet. In this case just let the class retain default values.
             return;
         }
         Stream ReadStream=File.Open(ConfigFile, FileMode.Open);
         XmlSerializer serializer=new XmlSerializer(typeof(AppSettings));
         AppSettings settings=(AppSettings)serializer.Deserialize(ReadStream);
         ReadStream.Close();
         this.ClientID=settings.ClientID;
         this.ConnectionSpeed=settings.ConnectionSpeed;
         this.Email=settings.Email;
         this.EnableScheduler=settings.EnableScheduler;
         this.HardwareInfo=settings.HardwareInfo;
         this.LoadAtStartup=settings.LoadAtStartup;
         this.MinimizeOnExit=settings.MinimizeOnExit;
         this.MinimizeToTray=settings.MinimizeToTray;
         this.Password=settings.Password;
         this.StartTime = settings.StartTime;
         this.StopTime = settings.StopTime;
         this.UserID = settings.UserID;
         this.UserName = settings.UserName;
     }
     catch
     {}
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Constructs an instance of the <see cref="AppSettings"/> class with the default values.
 /// </summary>
 public AppSettings()
 {
     LoadAtStartup = false;
     MinimizeToTray = false;
     MinimizeOnExit = false;
     EnableScheduler = false;
     StartTime = DateTime.Now;
     StopTime = DateTime.Now;
     UserID = 0;
     UserName = String.Empty;
     Password = null;
     Email = String.Empty;
     ClientID = Guid.Empty;
     HardwareInfo = 0;
     LogLevel = CWLogLevel.LogInfo;
     ConnectionSpeed = CWConnectionSpeed.Unknown;
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Loads the settings of the application from the configuration file.
        /// </summary>
        public void LoadSettings()
        {
            if(configFile == String.Empty)
            {
                throw new InvalidOperationException("The class cannot load its settings because the Config File path has not been initialized. Use ClientSettings(string fileName) instead.");
            }
            try
            {
                if(!File.Exists(configFile))
                {
                    //perhaps the file does not exist - probably because it has not been
                    //created yet. In this case just let the class retain default values.
                    return;
                }
                Stream ReadStream=File.Open(configFile, FileMode.Open);
                XmlSerializer serializer=new XmlSerializer(typeof(ClientSettings));
                ClientSettings settings=(ClientSettings)serializer.Deserialize(ReadStream);
                ReadStream.Close();
                this.ClientID=settings.ClientID;
                this.ConnectionSpeed=settings.ConnectionSpeed;
                this.Email=settings.Email;
                this.EnableScheduler=settings.EnableScheduler;
                this.HardwareInfo=settings.HardwareInfo;
                this.LoadAtStartup=settings.LoadAtStartup;
                this.MinimizeOnExit=settings.MinimizeOnExit;
                this.MinimizeToTray=settings.MinimizeToTray;
                this.Password=settings.Password;
                this.StartTime = settings.StartTime;
                this.StopTime = settings.StopTime;
                this.UserID = settings.UserID;
                this.UserName = settings.UserName;

                this.RemotingHost = settings.RemotingHost;
                this.RemotingProtocol = settings.RemotingProtocol;
                this.RemotingPort = settings.RemotingPort;

            }
            catch
            {}
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Constructs a new instance of the <see cref="ClientSettings"/> class and attempts
        /// to load the settings from the provided file.
        /// </summary>
        /// <param name="fileName">The path of the configuration file.</param>
        public ClientSettings(string fileName)
        {
            if((fileName == null)||(fileName == String.Empty))
            {
                throw new ArgumentException("The filename cannot be empty");
            }
            LoadAtStartup = false;
            MinimizeToTray = false;
            MinimizeOnExit = false;
            EnableScheduler = false;
            StartTime = DateTime.Now;
            StopTime = DateTime.Now;
            UserID = 0;
            UserName = String.Empty;
            Password = null;
            Email = String.Empty;
            ClientID = Guid.Empty;
            HardwareInfo = 0;
            LogLevel = CWLogLevel.LogInfo;
            ConnectionSpeed = CWConnectionSpeed.Unknown;

            RemotingHost = "localhost";
            RemotingProtocol = "tcp";
            RemotingPort = 15461;

            configFile = fileName;
            LoadSettings();
        }
Ejemplo n.º 12
0
        private string configFile; // holds the path of the configuration file

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructs an instance of the <see cref="ClientSettings"/> class with the default values.
        /// </summary>
        public ClientSettings()
        {
            LoadAtStartup = false;
            MinimizeToTray = false;
            MinimizeOnExit = false;
            EnableScheduler = false;
            StartTime = DateTime.Now;
            StopTime = DateTime.Now;
            UserID = 0;
            UserName = String.Empty;
            Password = null;
            Email = String.Empty;
            ClientID = Guid.Empty;
            HardwareInfo = 0;
            LogLevel = CWLogLevel.LogInfo;
            ConnectionSpeed = CWConnectionSpeed.Unknown;

            RemotingHost = "localhost";
            RemotingProtocol = "tcp";
            RemotingPort = 15461;

            configFile = String.Empty;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Selects the right item in the Connection Speed ComboBox
        /// </summary>
        /// <param name="speed">The Connection Speed to be selected.</param>
        private void SelectConnectionSpeed(CWConnectionSpeed speed)
        {
            switch(speed)
            {
                case CWConnectionSpeed.Unknown:
                    cmbNetSpeed.SelectedIndex = 0;
                    break;

                case CWConnectionSpeed.Modem56K:
                    cmbNetSpeed.SelectedIndex = 1;
                    break;

                case CWConnectionSpeed.ISDN64K:
                    cmbNetSpeed.SelectedIndex = 2;
                    break;

                case CWConnectionSpeed.ISDN128K:
                    cmbNetSpeed.SelectedIndex = 3;
                    break;

                case CWConnectionSpeed.DSL256K:
                    cmbNetSpeed.SelectedIndex = 4;
                    break;

                case CWConnectionSpeed.DSL384K:
                    cmbNetSpeed.SelectedIndex = 5;
                    break;

                case CWConnectionSpeed.DSL512K:
                    cmbNetSpeed.SelectedIndex = 6;
                    break;

                case CWConnectionSpeed.DSL1M:
                    cmbNetSpeed.SelectedIndex = 7;
                    break;

                case CWConnectionSpeed.T1:
                    cmbNetSpeed.SelectedIndex = 8;
                    break;

                case CWConnectionSpeed.T3:
                    cmbNetSpeed.SelectedIndex = 9;
                    break;

                case CWConnectionSpeed.Fiber:
                    cmbNetSpeed.SelectedIndex = 10;
                    break;

                case CWConnectionSpeed.ATM:
                    cmbNetSpeed.SelectedIndex = 11;
                    break;

                default:
                    cmbNetSpeed.SelectedIndex = 0;
                    break;
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Retrieves the Internet Connection Speed as a <see cref="CWConnectionSpeed"/>
        /// enumeration member.
        /// </summary>
        /// <returns>A <see cref="CWConnectionSpeed"/> enumeration member indicating the
        /// system's internet connection speed.</returns>
        private static CWConnectionSpeed NetSpeed()
        {
            CWConnectionSpeed speed         = CWConnectionSpeed.Unknown;
            int                        Kbps = 0;
            ManagementClass            cim  = new ManagementClass("Win32_NetworkAdapter");
            ManagementObjectCollection moc  = cim.GetInstances();

            foreach (ManagementObject mo in moc)
            {
                try
                {
                    string bps = mo.Properties["MaxSpeed"].Value.ToString();
                    Kbps = (int)(Convert.ToInt32(bps) / 1024);
                    if (Kbps > 0)
                    {
                        break;
                    }
                }
                catch (NullReferenceException)
                {
                    continue;
                }
            }
            //clean-up memory
            cim.Dispose();
            moc.Dispose();
            //determine which enumeration value fits best
            if ((Kbps > 0) && (Kbps <= 56))
            {
                speed = CWConnectionSpeed.Modem56K;
            }
            else if (Kbps == 64)
            {
                speed = CWConnectionSpeed.ISDN64K;
            }
            else if (Kbps == 128)
            {
                speed = CWConnectionSpeed.ISDN128K;
            }
            else if (Kbps == 256)
            {
                speed = CWConnectionSpeed.DSL256K;
            }
            else if (Kbps == 512)
            {
                speed = CWConnectionSpeed.DSL512K;
            }
            else if (Kbps == 1024)
            {
                speed = CWConnectionSpeed.DSL1M;
            }
            else if ((Kbps > 1024) && (Kbps <= 1536))
            {
                speed = CWConnectionSpeed.T1;
            }
            else if ((Kbps > 1536) && (Kbps <= 46080))
            {
                speed = CWConnectionSpeed.T3;
            }
            else if ((Kbps > 46080) && (Kbps < 158720))
            {
                speed = CWConnectionSpeed.Fiber;
            }
            else if (Kbps == 158720)
            {
                speed = CWConnectionSpeed.ATM;
            }
            else
            {
                speed = CWConnectionSpeed.Unknown;
            }
            return(speed);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Loads the detailed statistics of a user.
 /// </summary>
 private void LoadValues()
 {
     try
     {
         //Connect to the database
         SqlConnection dbcon = null;
         try
         {
             dbcon = new SqlConnection(globals.ProvideConnectionString());
             dbcon.Open();
         }
         catch (Exception e)
         {
             if (dbcon != null)
             {
                 dbcon.Dispose();
                 dbcon = null;
             }
             throw e;
         }
         //Load the values from the database
         SqlCommand cmd = new SqlCommand("cw_select_user_statistic", dbcon);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.Add("@user_id", SqlDbType.Int);
         cmd.Parameters[0].Value = userID;
         DataSet        ds = new DataSet();
         SqlDataAdapter da = new SqlDataAdapter(cmd);
         da.Fill(ds);
         da.Dispose();
         cmd.Dispose();
         dbcon.Close();
         //Add the entries in the list
         lstUserClients.Items.Clear();
         int itemCount = 0;
         foreach (DataRow dr in ds.Tables[0].Rows)
         {
             lstUserClients.Items.Add(((Guid)dr[3]).ToString());
             lstUserClients.Items[itemCount].SubItems.Add(((long)dr[4]).ToString());
             lstUserClients.Items[itemCount].SubItems.Add(((long)dr[5]).ToString());
             lstUserClients.Items[itemCount].SubItems.Add(((DateTime)dr[6]).ToString());
             if (dr[7] != DBNull.Value)
             {
                 lstUserClients.Items[itemCount].SubItems.Add(((string)dr[7]).Trim());
             }
             else
             {
                 lstUserClients.Items[itemCount].SubItems.Add(String.Empty);
             }
             if (dr[8] != DBNull.Value)
             {
                 lstUserClients.Items[itemCount].SubItems.Add(((short)dr[8]).ToString());
             }
             else
             {
                 lstUserClients.Items[itemCount].SubItems.Add(String.Empty);
             }
             if (dr[9] != DBNull.Value)
             {
                 CWConnectionSpeed speed = (CWConnectionSpeed)((byte)dr[9]);
                 lstUserClients.Items[itemCount].SubItems.Add(speed.ToString());
             }
             else
             {
                 lstUserClients.Items[itemCount].SubItems.Add("Unknown");
             }
             itemCount++;
         }
         if (itemCount > 0)
         {
             DataRow dr = ds.Tables[0].Rows[0];
             lblUsernameVal.Text     = ((string)dr[0]).Trim();
             lblEmailVal.Text        = ((string)dr[1]).Trim();
             lblRegistrationVal.Text = ((DateTime)dr[2]).ToString();
         }
         ds.Dispose();
     }
     catch (Exception e)
     {
         globals.Log.LogError("CrawlWave.ServerManager failed to load the list of Banned Hosts : " + e.ToString());
         MessageBox.Show(this.Text + " failed to load the list of Banned Hosts:\n" + e.Message);
         GC.Collect();
     }
 }
Ejemplo n.º 16
0
        /// <summary>
        /// DetectConnectionSpeed attempts to detect the computer's internet connection speed
        /// by measuring how much time it takes to download the contents of a web site.
        /// </summary>
        /// <returns>A <see cref="CWConnectionSpeed"/> value containing the estimated internet
        /// connection speed.</returns>
        public static CWConnectionSpeed DetectConnectionSpeed()
        {
            CWConnectionSpeed retVal = CWConnectionSpeed.Unknown;

            try
            {
                WebClient  client = new WebClient();
                HiResTimer timer  = new HiResTimer();
                byte[]     data;
                timer.Start();
                try
                {
                    data = client.DownloadData("http://www.in.gr/");
                }
                catch
                {
                    data = new byte[0];
                }
                finally
                {
                    timer.Stop();
                    client.Dispose();
                }
                if (data.Length > 0)
                {
                    double Kbps = ((data.Length * 8) / timer.Duration);
                    //determine which enumeration value fits best
                    if ((Kbps > 0) && (Kbps <= 56))
                    {
                        retVal = CWConnectionSpeed.Modem56K;
                    }
                    else if (Kbps <= 64)
                    {
                        retVal = CWConnectionSpeed.ISDN64K;
                    }
                    else if (Kbps <= 128)
                    {
                        retVal = CWConnectionSpeed.ISDN128K;
                    }
                    else if (Kbps <= 256)
                    {
                        retVal = CWConnectionSpeed.DSL256K;
                    }
                    else if (Kbps <= 512)
                    {
                        retVal = CWConnectionSpeed.DSL512K;
                    }
                    else if (Kbps <= 1024)
                    {
                        retVal = CWConnectionSpeed.DSL1M;
                    }
                    else if ((Kbps > 1024) && (Kbps <= 1536))
                    {
                        retVal = CWConnectionSpeed.T1;
                    }
                    else if ((Kbps > 1536) && (Kbps <= 46080))
                    {
                        retVal = CWConnectionSpeed.T3;
                    }
                    else if ((Kbps > 46080) && (Kbps < 158720))
                    {
                        retVal = CWConnectionSpeed.Fiber;
                    }
                    else if (Kbps >= 158720)
                    {
                        retVal = CWConnectionSpeed.ATM;
                    }
                    else
                    {
                        retVal = CWConnectionSpeed.Unknown;
                    }
                }
            }
            catch
            { }
            return(retVal);
        }