private void InsertAllSolutionsToCache(Collection <string> solutions, IProgress <ProgressResult> prog) { var cmd = new SQLiteCommand(CacheConnection); cmd.CommandText = Constants.CREATE_REPO_DB; cmd.ExecuteNonQuery(); var SQLsol = "insert into solutions (solution_id,solution_path,solution_file) values ('{0}','{1}','{2}')"; var SQLProj = "insert into projects (project_id,solution_id,dll_id,project_path,project_file) values ('{0}','{1}','{2}','{3}','{4}')"; var SQLSource = "insert into source_files (source_file_id,project_id,solution_id,source_path,source_file,source) values ('{0}','{1}','{2}','{3}','{4}','{5}')"; var SQLDll = "insert into dlls (dll_id,dll_name) values ('{0}','{1}')"; var solCounter = 0; using (SQLiteTransaction trans = CacheConnection.BeginTransaction()) { foreach (var s in solutions) { solCounter++; var current = ((float)solCounter / (float)solutions.Count) * 100; prog.Report(new ProgressResult { ProgressValue = (int)current, WorkingOn = s }); var newSolId = Guid.NewGuid().ToString(); cmd.CommandText = String.Format(SQLsol, newSolId, Path.GetDirectoryName(s).FixForSQL(), Path.GetFileName(s).FixForSQL()); cmd.ExecuteNonQuery(); //insert projects in this solution var projs = GetAllProjectsInSolution(s); foreach (var p in projs) { //insert into dll table first var newDLLId = Guid.NewGuid().ToString(); cmd.CommandText = String.Format(SQLDll, newDLLId, p.DLLName); cmd.ExecuteNonQuery(); var newProjId = Guid.NewGuid().ToString(); cmd.CommandText = String.Format(SQLProj, newProjId, newSolId, newDLLId, Path.GetDirectoryName(p.ProjectName).FixForSQL(), Path.GetFileName(p.ProjectName).FixForSQL()); cmd.ExecuteNonQuery(); var sourceFiles = GetAllSourceFiles(p.ProjectName); foreach (var sf in sourceFiles) { var newFileId = Guid.NewGuid().ToString(); var lines = String.Empty; try { if (File.Exists(Uri.UnescapeDataString(sf.Replace("?", String.Empty)))) { lines = File.ReadAllText(Uri.UnescapeDataString(sf)); cmd.CommandText = String.Format(SQLSource, newFileId, newProjId, newSolId, Path.GetDirectoryName(sf).FixForSQL(), Path.GetFileName(sf).FixForSQL(), lines.FixForSQL()); cmd.ExecuteNonQuery(); } } catch (Exception ex) { //ignore } } } } trans.Commit(); } //put into file-based database Cache2File(); }