Пример #1
0
        //This method tests the setRestrictions method
        public void Test2()
        {
            SettingsStorageImp st = new SettingsStorageImp();
            Console.WriteLine("[] Trying to set constraints to the task : \"b80dcfdd-d8c4-4176-aef1-6b76add16fb3\"");
            Constraints constraints = new Constraints(13, false, "org ru uk ","com co.il ac.il gov.il");

            st.setRestrictions("b80dcfdd-d8c4-4176-aef1-6b76add16fb3", constraints);
            Console.WriteLine(" - PASSED -");
            Console.WriteLine("=============================================================");
        }
Пример #2
0
    protected void Button12_Click(object sender, EventArgs e)
    {
        if ((string)Session["TID"] != null)
        {
            List<string> seeds = getListBoxContent(ListBox1);
            StorageSystem.getInstance().setSeedList((string)Session["TID"], seeds);

            List<string> crawl = getListBoxContent(ListBox2);
            List<string> restrict = getListBoxContent(ListBox3);
            bool paramAllowed = false;
            if (DropDownList1.SelectedIndex == 1) paramAllowed = true;
            uint depth = Convert.ToUInt32(TextBox1.Text);
            Constraints constraints = new Constraints(depth, paramAllowed, restrict, crawl);
            StorageSystem.getInstance().setRestrictions((string)Session["TID"], constraints);
        }
    }
Пример #3
0
        public static void MainTest()
        {
            List<Category> categories = new List<Category>();
            Constraints constraints   = new Constraints(5, true, "", "www.facebook.com");
            Initializer initializer   = new Initializer(constraints, categories);

            Url task1 = new Url("http://www.facebook.com/admirer4", 34243432, 35, "http://www.facebook.com/", 34243432);
            //Url task2 = new Url("http://www.nana10.co.il/", 34223432, 35, "http://www.nana10.co.il/", 34223432);

            Queue<Url> taskQueue = new Queue<Url>();
            taskQueue.Enqueue(task1);
            //taskQueue.Enqueue(task2);

            Queue<Url> feedBackQueue = new Queue<Url>();

            Worker worker = new Worker(initializer, taskQueue, feedBackQueue);
            worker.run();
        }
Пример #4
0
 public Initializer(String taskId, Constraints _constraints, List <Category> _categories)
 {
     constraintsOptions = _constraints;
     categoryList       = _categories;
     _taskId            = taskId;
 }
Пример #5
0
 /**
  * Constructs a new Filter class with the specified options and prefix
  */
 public Filter(String protocolPerfix, Constraints filterOptions)
 {
     prefix = protocolPerfix;
     constraints = filterOptions;
 }
Пример #6
0
 /**
  * initialize the initializer object which will be used in the system objects
  */
 protected static void SetInitializer(String taskId)
 {
     System.Console.Write("$$$ Getting Constraints .. ");
     if (_operationMode == operationMode_t.Manual)
     {
         _categories  = new List<Category>();
         _constraints = new Constraints(1, false, "", ".com");
     }
     else if (_operationMode == operationMode_t.Auto)
     {
         _categories  = StorageSystem.StorageSystem.getInstance().getCategories(taskId);
         _constraints = StorageSystem.StorageSystem.getInstance().getRestrictions(taskId);
     }
     _initializer = new Initializer(taskId, _constraints, _categories);
     System.Console.WriteLine("SUCCESS");
 }
Пример #7
0
 /**
  * set a new work restriction which will be activited in the next run
  */
 public void setRestrictions(String taskId, Constraints constrains)
 {
     _settingsStorageImp.setRestrictions(taskId, constrains);
 }
Пример #8
0
 public Initializer(String taskId, Constraints _constraints, List<Category> _categories)
 {
     constraintsOptions = _constraints;
     categoryList = _categories;
     _taskId = taskId;
 }
Пример #9
0
        /**
         * returns the saved constrains for the specified task
         */
        public Constraints getRestrictions(String taskId)
        {
            Constraints constrains;
            SqlConnection conn = null;
            SqlDataReader rdr = null;

            try
            {
                bool taskExist = false;
                string restrict = "", crawl = "";
                int linkDepth = 1;
                bool parametersAllowed = false;
                conn = new SqlConnection(SettingsReader.getConnectionString());

                conn.Open();
                SqlCommand cmd = new SqlCommand("SELECT LinkDepth,AllowUrlParam" +
                    " FROM Task WHERE TaskID=\'" + taskId + "\'", conn);

                rdr = cmd.ExecuteReader();
                if (rdr.HasRows)
                {
                    if (rdr.Read())
                    {
                        taskExist = true;
                        linkDepth = Convert.ToInt32(rdr["LinkDepth"]);
                        int allowParameters = Convert.ToInt32(rdr["AllowUrlParam"]);
                        parametersAllowed = (allowParameters != 0);
                    }
                    else throw new Exception();
                }

                cmd = new SqlCommand("SELECT Value" +
                    " FROM TaskProperties WHERE TaskID=\'" + taskId + "\' AND Property=\'RESTRICT\'", conn);

                if (rdr != null) rdr.Close();
                rdr = cmd.ExecuteReader();
                if (rdr.HasRows)
                {
                    while (rdr.Read())
                    {
                        restrict = restrict + rdr["Value"] + ' ';
                    }
                    if (restrict.Length != 0) restrict = restrict.TrimEnd(new char[] { ' ' });
                }

                cmd = new SqlCommand("SELECT Value" +
                    " FROM TaskProperties WHERE TaskID=\'" + taskId + "\' AND Property=\'ALLOW\'", conn);
                if (rdr != null) rdr.Close();
                rdr = cmd.ExecuteReader();
                if (rdr.HasRows)
                {
                    while (rdr.Read())
                    {
                        crawl = crawl + rdr["Value"] + ' ';
                    }
                    if (crawl.Length != 0) crawl = crawl.TrimEnd(new char[] { ' ' });
                }
                if (taskExist)
                    constrains = new Constraints((uint)linkDepth, parametersAllowed, restrict, crawl);
                else
                    constrains = null;
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Exception Caught: " + e.Message);
                constrains = null;
            }
            finally
            {
                if (rdr != null) rdr.Close();
                if (conn != null) conn.Close();
            }
            return constrains;
        }
Пример #10
0
        /**
         * sets a new restrictions for the specified task
         */
        public void setRestrictions(String taskId, Constraints constrains)
        {
            SqlConnection conn = null;
            SqlDataReader rdr = null;

            try
            {
                conn = new SqlConnection(SettingsReader.getConnectionString());

                conn.Open();
                SqlCommand cmd = new SqlCommand("UPDATE Task" +
                    " SET LinkDepth=\'" + constrains.getAllowedDepth() + "\', AllowUrlParam=\'" +
                    constrains.isParametrizationAllowed() + "\' WHERE TaskID=\'" + taskId + "\'", conn);
                cmd.ExecuteNonQuery();

                removeProperty(taskId, "ALLOW");
                foreach(String crawl in constrains.getCrawlList())
                {
                    cmd = new SqlCommand("INSERT INTO TaskProperties (TaskID,Property,Value)"
                            + " Values (\'" + taskId + "\',\'" + "ALLOW" + "\',\'" + crawl + "\')", conn);

                    cmd.ExecuteNonQuery();
                }

                removeProperty(taskId, "RESTRICT");
                foreach (String crawl in constrains.getRestrictionList())
                {
                    cmd = new SqlCommand("INSERT INTO TaskProperties (TaskID,Property,Value)"
                            + " Values (\'" + taskId + "\',\'" + "RESTRICT" + "\',\'" + crawl + "\')", conn);

                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Exception Caught: " + e.Message);
            }
            finally
            {
                if (rdr != null) rdr.Close();
                if (conn != null) conn.Close();
            }
        }