/// <summary> /// Provides the list of unknown words and quantities for given /// project. /// </summary> /// <param name="project"></param> /// <returns></returns> public Dictionary <string, int> GetUnknownWords(Lingva lang, string project) { Dictionary <string, int> words = new Dictionary <string, int>(); SQLiteParameter projectParam = new SQLiteParameter("@project"); projectParam.Value = project; projectParam.DbType = System.Data.DbType.String; SQLiteParameter langParam = new SQLiteParameter("@lang"); langParam.Value = lang.Language; langParam.DbType = System.Data.DbType.String; string sql = "SELECT word, SUM(quantity) as sum " + "FROM Words JOIN Files on Words.file = Files.path " + "WHERE project=@project AND lang=@lang " + "GROUP BY word ORDER BY sum DESC LIMIT 100"; using (SQLiteCommand cmd = new SQLiteCommand(sql, dbConn)) { cmd.Parameters.Add(projectParam); cmd.Parameters.Add(langParam); SQLiteDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { words[dr.GetString(0)] = dr.GetInt32(1); } dr.Close(); } return(words); }
/// <summary> /// Removes the project from DB. /// </summary> /// <param name="language"></param> /// <param name="project"></param> public void RemoveProject(Lingva language, string project) { SQLiteParameter langParam = new SQLiteParameter("@lang"); langParam.Value = language.Language; langParam.DbType = System.Data.DbType.String; SQLiteParameter projectParam = new SQLiteParameter("@project"); projectParam.Value = project; projectParam.DbType = System.Data.DbType.String; using (SQLiteCommand cmd = new SQLiteCommand(dbConn)) { cmd.Parameters.Add(langParam); cmd.Parameters.Add(projectParam); // Delete all words from previous analysis. cmd.CommandText = "DELETE FROM Words WHERE file IN " + "(SELECT path FROM Files WHERE lang=@lang AND project=@project)"; cmd.ExecuteNonQuery(); // Delete all stats from previous analysis cmd.CommandText = "DELETE FROM Files WHERE lang=@lang AND project=@project"; cmd.ExecuteNonQuery(); } }
/// <summary> /// Removes language from viewModel and model. /// </summary> /// <param name="languageViewModel"></param> public void RemoveLanguage(LingvaViewModel languageViewModel) { Lingva lang = languageViewModel.CurrentLanguage; L.Logger.Debug(string.Format("Removing {0} language from {1}.", lang.Language, lang.Folder)); model.RemoveOldLanguage(lang); }
/// <summary> /// Adds new language to viewmodel and model. /// </summary> /// <param name="languageViewModel"></param> public void AddNewLanguage(LingvaViewModel languageViewModel) { L.Logger.Debug("Adding new language."); // Use copy constructor. Lingva lang = new Lingva(languageViewModel.CurrentLanguage); model.AddNewLanguage(lang); }
// Equals override public override bool Equals(object obj) { Lingva item = obj as Lingva; if (item == null) { return(false); } return(this.Folder == item.Folder); }
/// <summary> /// Adds new language and it's folder to DB. /// </summary> /// <param name="language"></param> /// <param name="directory"></param> /// <returns></returns> public void AddLanguage(Lingva lang) { string sql = "INSERT INTO Languages VALUES(@lang, @directory)"; using (SQLiteCommand cmd = new SQLiteCommand(sql, dbConn)) { SQLiteParameter param = new SQLiteParameter("@lang"); param.Value = lang.Language; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = new SQLiteParameter("@directory"); param.Value = lang.Folder; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); } }
/// <summary> /// Removes the stats of the given language from DB. /// </summary> /// <param name="language"></param> public void RemoveLanguage(Lingva language) { SQLiteParameter param = new SQLiteParameter("@lang"); param.Value = language.Language; param.DbType = System.Data.DbType.String; using (SQLiteCommand cmd = new SQLiteCommand(dbConn)) { cmd.Parameters.Add(param); // Delete all words from previous analysis. cmd.CommandText = "DELETE FROM Words WHERE file IN " + "(SELECT path FROM Files WHERE lang=@lang)"; cmd.ExecuteNonQuery(); // Delete language and files. cmd.CommandText = "DELETE FROM Languages WHERE lang=@lang"; cmd.ExecuteNonQuery(); } }
/// <summary> /// Return projects for chosen language. /// </summary> /// <param name="selectedLang"></param> /// <returns></returns> public List <string> GetProjects(Lingva selectedLang) { List <string> projects = new List <string>(); string sql = "SELECT project FROM Files WHERE lang=@lang GROUP BY project"; using (SQLiteCommand cmd = new SQLiteCommand(sql, dbConn)) { SQLiteParameter param = new SQLiteParameter("@lang"); param.Value = selectedLang.Language; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); SQLiteDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { projects.Add(dr.GetString(0)); } dr.Close(); } return(projects); }
/// <summary> /// Returns list of fileStats for given language and project. /// </summary> /// <param name="language"></param> /// <param name="project"></param> /// <returns></returns> public List <FileStats> GetFilesStats(Lingva language, string project) { SQLiteParameter langParam = new SQLiteParameter("@lang"); langParam.Value = language.Language; langParam.DbType = System.Data.DbType.String; SQLiteParameter projectParam = new SQLiteParameter("@project"); projectParam.Value = project; projectParam.DbType = System.Data.DbType.String; string sql = "SELECT name, path, size, known, maybe, unknown FROM Files " + "WHERE lang=@lang AND project=@project"; List <FileStats> stats = new List <FileStats>(); using (SQLiteCommand cmd = new SQLiteCommand(sql, dbConn)) { cmd.Parameters.Add(langParam); cmd.Parameters.Add(projectParam); SQLiteDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { stats.Add(new FileStats( dr.GetString(0), dr.GetString(1), language, project) { Size = dr.GetInt32(2), Known = dr.GetInt32(3), Maybe = dr.GetInt32(4), Unknown = dr.GetInt32(5) }); } dr.Close(); } return(stats); }
public Lingva(Lingva other) { Language = other.Language; Folder = other.Folder; }
// Constructors public LingvaViewModel(Lingva language) { currentLanguage = language; validProperties.Add("Language", false); validProperties.Add("Folder", false); }