예제 #1
0
        private void getKeywords()
        {
            int criteriaId = int.Parse(listView1.SelectedItems[0].SubItems[0].Text);

            fbEntities              = new FBNewsDbEntities();
            listView3.View          = View.Details;
            listView3.GridLines     = true;
            listView3.FullRowSelect = true;
            ListViewItem itm;

            listView3.Clear();

            //Add column header
            listView3.Columns.Add("ID", 100);
            listView3.Columns.Add("Keyword Name", 100);

            var keywords = fbEntities.keywords.Where(c => c.cirteriaId == criteriaId).ToList();

            foreach (keyword keyword in keywords)
            {
                string[] arrkeywords = new string[4];
                arrkeywords[0] = keyword.id + "";
                arrkeywords[1] = keyword.keywords;
                itm            = new ListViewItem(arrkeywords);
                listView3.Items.Add(itm);
            }
        }
예제 #2
0
        private void getcriterias()
        {
            fbEntities              = new FBNewsDbEntities();
            listView1.View          = View.Details;
            listView1.GridLines     = true;
            listView1.FullRowSelect = true;
            ListViewItem itm;

            listView1.Clear();

            //Add column header
            listView1.Columns.Add("ID", 100);
            listView1.Columns.Add("Cratiria Name", 100);

            var criterias = fbEntities.criterias.ToList();

            foreach (criteria criteria in criterias)
            {
                string[] arrcriterias = new string[4];
                arrcriterias[0] = criteria.id + "";
                arrcriterias[1] = criteria.criterianame;
                itm             = new ListViewItem(arrcriterias);
                listView1.Items.Add(itm);
            }
        }
예제 #3
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();
        }
예제 #4
0
        private void getpages()
        {
            int criteriaId = int.Parse(listView1.SelectedItems[0].SubItems[0].Text);

            fbEntities              = new FBNewsDbEntities();
            listView2.View          = View.Details;
            listView2.GridLines     = true;
            listView2.FullRowSelect = true;
            ListViewItem itm;

            listView2.Clear();

            //Add column header
            listView2.Columns.Add("ID", 50);
            listView2.Columns.Add("Page Name", 80);
            listView2.Columns.Add("Page Category", 80);
            listView2.Columns.Add("Page Location", 80);
            listView2.Columns.Add("Page Url", 150);



            var pages = fbEntities.pages.Where(c => c.criteriaId == criteriaId).ToList();

            foreach (page page in pages)
            {
                string[] arrpages = new string[5];
                arrpages[0] = page.id + "";
                arrpages[1] = page.pagename;
                arrpages[2] = page.category;
                arrpages[3] = page.location;
                arrpages[4] = page.pageurl;

                itm = new ListViewItem(arrpages);
                listView2.Items.Add(itm);
            }
        }
예제 #5
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();
        }
예제 #6
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 = "";
        }
예제 #7
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 = "";
        }