public void InsertNew(DBCollisionAction collisionAction, string path) { string escapedPath = path.Replace("'", "''"); int lastSlash = path.LastIndexOf(@"\"); if (lastSlash == -1) { return; } //create a new entry in the user preferences table for this file List <DBParameter> userPreferenceParameters = new List <DBParameter>(); userPreferenceParameters.Add(new DBParameter("path", escapedPath)); userPreferenceParameters.Add(new DBParameter("tags", "")); userPreferenceParameters.Add(new DBParameter("is_favorite", "0")); userPreferenceParameters.Add(new DBParameter("is_hidden", "0")); m_database.Insert(DBCollisionAction.IGNORE, "UserPreferences", userPreferenceParameters); /*insert the path into the database, pulling existing user preferences from the UserPreferences table*/ List <DBParameter> insertParameters = new List <DBParameter>(); insertParameters.Add(new DBParameter("path", escapedPath)); insertParameters.Add(new DBParameter("name", escapedPath.Substring(lastSlash + 1).ToLower())); insertParameters.Add(new DBParameter("type", "0")); m_database.Insert(DBCollisionAction.IGNORE, "FileCache", insertParameters); }
private void _DirectoryMonitor_MonitoredFileRenamed(object sender, MonitoredFileRenamedArgs e) { try { //first find the file in the database var rawResult = m_database.Select <RawFileData>("FileCache", new DBPredicate("path", DBOperator.EQUALS, e.OldPath), new RawFileDataCreator()); if (rawResult == null) { //if it doesn't exist already, add it now int fileType = 0; int lastSlash = e.NewPath.LastIndexOf(@"\"); if (lastSlash == -1) { return; } if (File.Exists(e.NewPath)) { fileType = 1; } m_database.Insert <RawFileData>(DBCollisionAction.IGNORE, "FileCache", new RawFileData(-1, e.NewPath, e.NewPath.Substring(lastSlash + 1).ToLower(), fileType, null, 0, false, false)); } else { //if the file does exist in the database, update the old record int lastSlash = e.NewPath.LastIndexOf(@"\"); if (lastSlash == -1) { return; } List <DBPredicate> updateValues = new List <DBPredicate>(); updateValues.Add(new DBPredicate("path", DBOperator.EQUALS, e.NewPath)); updateValues.Add(new DBPredicate("name", DBOperator.EQUALS, e.NewPath.Substring(lastSlash + 1).ToLower())); m_database.Update("FileCache", updateValues, new DBPredicate("path", DBOperator.EQUALS, e.OldPath)); } } catch (Exception crap) { Settings.SessionLog += crap.Message + "\n"; Debug.WriteLine(crap.Message); } }