/// <summary> /// Read the list of categories from the server. /// </summary> public void Refresh() { Thread t = new Thread(() => { if (CIX.Online) { HttpWebRequest wrGeturl = APIRequest.Get("directory/categories", APIRequest.APIFormat.XML); Stream objStream = APIRequest.ReadResponse(wrGeturl); if (objStream != null) { using (XmlReader reader = XmlReader.Create(objStream)) { XmlSerializer serializer = new XmlSerializer(typeof(CategoryResultSet)); CategoryResultSet inboxSet = (CategoryResultSet)serializer.Deserialize(reader); List <DirCategory> newCategories = new List <DirCategory>(); foreach (CategoryResult conv in inboxSet.Categories) { DirCategory newCategory = CategoryByName(conv.Name, conv.Sub); if (newCategory == null) { newCategory = new DirCategory { Name = conv.Name, Sub = conv.Sub }; List <DirCategory> subCategories; if (!_allCategories.TryGetValue(conv.Name, out subCategories)) { subCategories = new List <DirCategory>(); _allCategories[conv.Name] = subCategories; } subCategories.Add(newCategory); newCategories.Add(newCategory); } } if (newCategories.Count > 0) { lock (CIX.DBLock) { CIX.DB.InsertAll(newCategories); } LogFile.WriteLine(@"Directory refreshed with {0} new categories", newCategories.Count); if (DirectoryChanged != null) { DirectoryChanged(this, new DirectoryEventArgs { CategoryName = null }); } } RefreshCategories(); } } } }); t.Start(); }
//rset ,guid list private void Categorization() { ArrayList names = new ArrayList(); names.Add("accident"); names.Add("earth quick"); names.Add("fire and kill"); names.Add("kidnap"); names.Add("public call strike"); names.Add("terrorism"); ArrayList rset = new ArrayList(); ArrayList guid = new ArrayList(); ArrayList importantfeed_sentences = new ArrayList(); String conn = Properties.Settings.Default.RTSMSDBConnectionString; Properties.Settings.Default.AppName = "Hello World"; AddItem(Properties.Settings.Default.AppName); using (SqlConnection sql = new SqlConnection()) { sql.ConnectionString = @conn; sql.Open(); SqlCommand sqlcommand = new SqlCommand(unMappedRSSItemquery, sql); SqlDataReader reader = sqlcommand.ExecuteReader(); while (reader.Read()) { rset.Add(reader.GetString(2)); guid.Add(reader.GetString(0)); } AddItem("Total Rows:" + rset.Count); reader.Close(); sql.Close(); } for (int i = 0; i < rset.Count; i++) { // Console.WriteLine("Counter = " + rset.Count); char[] separray = { '^' }; RSSItemSentences feed = new RSSItemSentences(); feed.SetGuid((string)guid[i]); string Tokens = (string)rset[i]; Tokens = Tokens.Replace("<STRONG>", " "); Tokens = Tokens.Replace("</STRONG>", " "); Tokens = Tokens.Replace("<br>", " "); Tokens = Tokens.Replace("</br>", " "); Tokens = Tokens.Replace("<strong>", " "); Tokens = Tokens.Replace("</strong>", " "); Tokens = Tokens.Replace(". ", "^"); Tokens = Tokens.Replace(".", ""); Tokens = Tokens.Replace(",", ""); Tokens = Tokens.Replace(":", ""); Tokens = Tokens.Replace(";", ""); Tokens = Tokens.Replace("&", ""); Tokens = Tokens.Replace("?", ""); Tokens = Tokens.Replace("#", ""); Tokens = Tokens.Replace("'", ""); Tokens = Tokens.Replace("\"", ""); Tokens = Tokens.Replace("/", ""); Tokens = Tokens.Replace("'", ""); Tokens = Tokens.Replace(";", ""); string[] Pieces = Tokens.Split(separray, 2048); for (int j = 0; j < Pieces.Length; j++) { // AddItem(Pieces[j]); // Console.WriteLine(Pieces[j]); feed.AddSentence(Pieces[j]); } ArrayList results = new ArrayList(); CategorizationProcess ctg = new CategorizationProcess(); ctg.LoadCategories(names); results = ctg.CategorizeFeed(feed.GetFeeds()); // Console.WriteLine(); int matchcount = 0; List <CategoryResultSet> listofresult = new List <CategoryResultSet>(); for (int k = 0; k < results.Count; k++) { CategoryResultSet tmp = (CategoryResultSet)results[k]; AddItem(tmp.categoryname + ", Match(s) " + tmp.noofmatched.ToString()); matchcount += tmp.noofmatched; listofresult.Add(tmp); } String json = JsonConvert.SerializeObject(listofresult); InsertCategorizationResult((string)guid[i], json); AddItem("Total Matched(" + matchcount); // if totalmatchcount > 0 then add this rssitemsentencesfeed in //FinalArrayList and update MainMiner Table [Categorization] Column //value to 1 according to each RSSItemID if (matchcount > 0) { //Update MainMiner Table //feed.GetGuid(); // these two fields will make the RSSItem back. //feed.GetFeeds(); //write sql to update MainMiner importantfeed_sentences.Add(feed); } InsertCategorizationRow((string)guid[i]); UpdateCategorizationRow((string)guid[i]); AddItem("=========================="); } AddItem("Total Count of Feed(Categorized Found)" + guid.Count); // Thread.Sleep(2 * 1000); // change progress of the status bar. // backgroundWorker1.ReportProgress(i * 100); }