Example #1
0
        private void button6_Click(object sender, EventArgs e)
        {
            string  key     = "";
            keyword keyword = new keyword();

            if (textBox4.Text == null)
            {
                MessageBox.Show("Please Empty values not allowed");
                return;
            }

            key = textBox4.Text;
            keyword.keywords = key;

            if (fbEntities.keywords.Any(c => c.keywords.Trim().ToLower() == key.ToLower().Trim()))
            {
                MessageBox.Show("This Keyword already exist !");
                return;
            }

            fbEntities.keywords.Add(keyword);
            if (fbEntities.SaveChanges() == 1)
            {
                MessageBox.Show("Added Sucessfully ");
            }
        }
Example #2
0
        //Add Criteria
        private void button7_Click(object sender, EventArgs e)
        {
            fbEntities = new FBNewsDbEntities();
            criteria criteria = new criteria();

            criteria.criterianame = textBox6.Text;
            fbEntities.criterias.Add(criteria);
            fbEntities.SaveChanges();
            getcriterias();
        }
Example #3
0
        private void deletecriteria()
        {
            int criteriaId = int.Parse(listView1.SelectedItems[0].SubItems[0].Text);

            fbEntities = new FBNewsDbEntities();
            var dcriteria = fbEntities.criterias.Where(c => c.id == criteriaId).SingleOrDefault();
            var dkeywords = fbEntities.keywords.Where(c => c.cirteriaId == criteriaId).ToList();
            var dpages    = fbEntities.pages.Where(c => c.criteriaId == criteriaId).ToList();

            foreach (keyword keyword in dkeywords)
            {
                if (keyword != null)
                {
                    fbEntities.keywords.Remove(keyword);
                    fbEntities.SaveChanges();
                }
            }

            foreach (page page in dpages)
            {
                if (page != null)
                {
                    fbEntities.pages.Remove(page);
                    fbEntities.SaveChanges();
                }
            }


            if (dcriteria != null)
            {
                fbEntities.criterias.Remove(dcriteria);
                fbEntities.SaveChanges();
            }
            getcriterias();
            clearlist();
        }
Example #4
0
        //Add Keyword
        private void button6_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please choose  criteria");
                return;
            }
            string key        = "";
            int    criteriaId = int.Parse(listView1.SelectedItems[0].SubItems[0].Text);



            keyword keyword = new keyword();

            if (textBox4.Text == null)
            {
                MessageBox.Show("Please Empty values not allowed");
                return;
            }

            key = textBox4.Text;
            keyword.keywords   = key;
            keyword.cirteriaId = criteriaId;

            if (fbEntities.keywords.Any(c => c.keywords.Trim().ToLower() == key.ToLower().Trim()))
            {
                MessageBox.Show("This Keyword already exist !");
                return;
            }

            fbEntities.keywords.Add(keyword);
            if (fbEntities.SaveChanges() == 1)
            {
                MessageBox.Show("Added Sucessfully ");
            }
        }
Example #5
0
        private void button4_Click(object sender, EventArgs e)
        {
            int postcount = 0;

            fbEntities  = new FBNewsDbEntities();
            label6.Text = "Loading";

            //  Url = Url + token;
            pages    = fbEntities.pages.ToList();
            keywords = fbEntities.keywords.Select(c => c.keywords).ToArray();


            foreach (page page in pages)
            {
                path = "https://graph.facebook.com/" + page.pagefbid + "/posts?limit=100&access_token=" + token;
                var clientRepsonse = "";
                try
                {
                    using (var client = new WebClient())
                    {
                        clientRepsonse = client.DownloadString(path);
                    }
                    int count = 0;

                    dynamic deserialize_post = JsonConvert.DeserializeObject(clientRepsonse);
                    if (deserialize_post.data != null)
                    {
                        // check if posts exist
                        var      listresponse  = deserialize_post.data;
                        DateTime lastCheckDate = listresponse[0].created_time;

                        for (int i = 0; i < listresponse.Count; i++)
                        {
                            count = listresponse.Count;
                            string   message    = listresponse[i].message;
                            DateTime createdate = listresponse[i].created_time;
                            string   id         = listresponse[i].id;



                            if (!string.IsNullOrEmpty(message))
                            {
                                foreach (string keyword in keywords)
                                {
                                    if (message.ToLower().Contains(keyword.ToLower()) && !(fbEntities.FBNews.Any(c => c.post_id == id)))
                                    {
                                        FBNew fb = new FBNew();
                                        fb.created_at = createdate;
                                        fb.message    = message;
                                        fb.pagename   = page.pagename;
                                        fb.post_id    = id;
                                        fbEntities.FBNews.Add(fb);
                                        fbEntities.SaveChanges();
                                        postcount++;
                                    }
                                }
                            }
                        }
                        page.lastcheckdate = lastCheckDate;
                        fbEntities.SaveChanges();
                    }
                    // MessageBox.Show(count + "");

                    // Do further processing.
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "");
                }
            }

            MessageBox.Show("Done ! We Found  " + postcount + "  new posts");
            label6.Text = "";
        }
Example #6
0
        //Search
        private void button4_Click(object sender, EventArgs e)
        {
            int postcount = 0;

            fbEntities  = new FBNewsDbEntities();
            label6.Text = "Loading";
            var criterias = fbEntities.criterias.ToList();

            //Task f = Task.Factory.StartNew(() =>
            //{



            foreach (criteria criteria in criterias)
            {
                pages    = fbEntities.pages.Where(c => c.criteriaId == criteria.id).ToList();
                keywords = fbEntities.keywords.Where(c => c.cirteriaId == criteria.id).Select(c => c.keywords).ToArray();

                if (pages.Count == 0 || keywords.Length == 0)
                {
                    continue;
                }

                foreach (page page in pages)
                {
                    path = "https://graph.facebook.com/" + page.pagefbid + "/posts?limit=100&access_token=" + token;
                    var clientRepsonse = "";
                    try
                    {
                        using (var client = new WebClient())
                        {
                            clientRepsonse = client.DownloadString(path);
                        }
                        int count = 0;

                        dynamic deserialize_post = JsonConvert.DeserializeObject(clientRepsonse);
                        if (deserialize_post.data != null)
                        {
                            // check if posts exist
                            var      listresponse  = deserialize_post.data;
                            DateTime lastCheckDate = listresponse[0].created_time;

                            for (int i = 0; i < listresponse.Count; i++)
                            {
                                count = listresponse.Count;
                                string   message    = listresponse[i].message;
                                DateTime createdate = listresponse[i].created_time;
                                string   id         = listresponse[i].id;



                                if (!string.IsNullOrEmpty(message))
                                {
                                    foreach (string keyword in keywords)
                                    {
                                        string[] splitkeyword = keyword.Split(',');

                                        if (splitkeyword.Length == 1)
                                        {
                                            if (message.ToLower().Contains(keyword.ToLower()) && !(fbEntities.FBNews.Any(c => c.post_id == id)))
                                            {
                                                string[] url = id.Split('_');
                                                FBNew    fb  = new FBNew();
                                                fb.created_at = createdate;
                                                fb.message    = message;
                                                fb.pagename   = page.pagename;
                                                fb.post_id    = id;

                                                fb.location = page.location;
                                                fb.category = page.category;
                                                fb.keyword  = keyword;
                                                fb.url      = page.pageurl + url[1];
                                                fbEntities.FBNews.Add(fb);
                                                fbEntities.SaveChanges();
                                                postcount++;
                                            }
                                        }
                                        else if (splitkeyword.Length > 1)
                                        {
                                            for (int k = 0; k < splitkeyword.Length; k++)
                                            {
                                                if (splitkeyword[k].ToLower().Trim().Contains("بدون"))
                                                {
                                                    if (message.ToLower().Contains(splitkeyword[k].ToLower()) &&
                                                        message.ToLower().Contains(splitkeyword[k - 1].ToLower()) &&
                                                        !(fbEntities.FBNews.Any(c => c.post_id == id)))
                                                    {
                                                        string[] url = id.Split('_');
                                                        FBNew    fb  = new FBNew();
                                                        fb.created_at = createdate;
                                                        fb.message    = message;
                                                        fb.pagename   = page.pagename;
                                                        fb.post_id    = id;

                                                        fb.location = page.location;
                                                        fb.category = page.category;
                                                        fb.keyword  = keyword;
                                                        fb.url      = page.pageurl + url[1];
                                                        fbEntities.FBNews.Add(fb);
                                                        fbEntities.SaveChanges();
                                                        postcount++;
                                                    }
                                                }
                                                else if (message.ToLower().Contains(splitkeyword[k].ToLower()) && !(fbEntities.FBNews.Any(c => c.post_id == id)))
                                                {
                                                    string[] url = id.Split('_');
                                                    FBNew    fb  = new FBNew();
                                                    fb.created_at = createdate;
                                                    fb.message    = message;
                                                    fb.pagename   = page.pagename;
                                                    fb.post_id    = id;

                                                    fb.location = page.location;
                                                    fb.category = page.category;
                                                    fb.keyword  = splitkeyword[k];
                                                    fb.url      = page.pageurl + url[1];
                                                    fbEntities.FBNews.Add(fb);
                                                    fbEntities.SaveChanges();
                                                    postcount++;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            page.lastcheckdate = lastCheckDate;
                            fbEntities.SaveChanges();
                        }
                        // MessageBox.Show(count + "");

                        // Do further processing.
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + "");
                    }
                }
            }
            //});
            MessageBox.Show("Done ! We Found  " + postcount + "  new posts");
            label6.Text = "";
        }