Beispiel #1
0
 private void timerTick(object sender, EventArgs e)
 {
     for (int i = 0; i < blockedSites.Count; i++)
     {
         Blocked blocked = blockedSites[i];
         if (blocked.time != null)
         {
             if (blocked.time < DateTime.Now)
             {
                 int removed = deleteBlock(blocked.name);
                 listBox1.Items.RemoveAt(removed);
                 continue;
             }
         }
     }
 }
Beispiel #2
0
        public void ReadBlocked()
        {
            int count = 0;

            using (StreamReader reader = File.OpenText(hostLoc)) {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (!String.IsNullOrEmpty(line) && !line.Contains("#"))
                    {
                        int index = line.IndexOf(" ");
                        listBox1.Items.Add(line.Substring(index + 1));
                        Blocked blocked = new Blocked(line.Substring(index + 1), null);
                        blockedSites.Add(blocked);
                    }

                    count++;
                }
            }
        }
Beispiel #3
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(textBox1.Text))
            {
                return;
            }

            if (!checkBox1.Checked)
            {
                string newSite = "127.0.0.1 " + textBox1.Text;

                File.AppendAllText(hostLoc,
                                   newSite + Environment.NewLine);

                listBox1.Items.Add(textBox1.Text);

                Blocked blocked = new Blocked(textBox1.Text, null);
                blockedSites.Add(blocked);
            }
            else
            {
                if (datePicker.Value <= DateTime.Now)
                {
                    MessageBox.Show("Şu andan ileri bir tarih seçin");
                    return;
                }


                Blocked blocked = new Blocked(textBox1.Text, datePicker.Value);
                blockedSites.Add(blocked);

                string newSite = textBox1.Text + " : " + blocked.time.ToString();

                File.AppendAllText(hostLoc, "127.0.0.1 " + newSite + Environment.NewLine);

                listBox1.Items.Add(newSite);
            }
        }