Exemplo n.º 1
0
        private List <SynonymDTO> getSynonyms(string temp)
        {
            List <SynonymDTO> results = new List <SynonymDTO>();
            int    locationA          = 0;
            int    locationB          = 0;
            string ulSubstring        = string.Empty;

            locationA   = temp.IndexOf("<ul>");
            locationB   = temp.IndexOf("</div>", locationA);
            ulSubstring = temp.Substring(locationA, locationB - locationA);
            while (ulSubstring.Contains("data-complexity"))
            {
                locationA = ulSubstring.IndexOf("<li>");
                locationB = ulSubstring.IndexOf("</li>");
                string li = ulSubstring.Substring(locationA, locationB + 5 - locationA);
                ulSubstring = ulSubstring.Substring(locationB + 5);
                locationA   = li.IndexOf("data-complexity=");
                locationA   = locationA + "data-complexity=".Length;
                locationA   = li.IndexOf('"', locationA);
                locationB   = li.IndexOf('"', locationA + 1);
                string complexity = li.Substring(locationA + 1, locationB - locationA - 1);
                locationA = li.IndexOf("<span class=\"text\">");
                locationA = locationA + "<span class=\"text\">".Length;
                locationB = li.IndexOf("<", locationA);
                string     syn = li.Substring(locationA, locationB - locationA);
                SynonymDTO tmp = new SynonymDTO();
                tmp.complexity = int.Parse(complexity);
                tmp.word       = syn;
                results.Add(tmp);
            }

            return(results);
        }
Exemplo n.º 2
0
        private void insertSynonyms(int wordId, SynonymDTO wd)
        {
            try
            {
                using (SqlCommand cmd = new SqlCommand("sp_insert_Synonym", con))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add("@wordID", SqlDbType.Int).Value     = wordId;
                    cmd.Parameters.Add("@syn", SqlDbType.VarChar).Value    = wd.word;
                    cmd.Parameters.Add("@complexity", SqlDbType.Int).Value = wd.complexity;
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                throw;
            }
        }