public void AddProject(Project project) { string projectFile; projectFile = Path.Combine(dbDirPath, project.ID.ToString()); project.Description.LastModified = DateTime.UtcNow; projectsDB.Add(project.Description); try { if (File.Exists(projectFile)) { File.Delete(projectFile); } Serializer.Save(project, projectFile); } catch (Exception ex) { Log.Exception(ex); projectsDB.Delete(project.Description.ID); } }
public void Reload() { projectsDB = new LiteDB(dbPath); DirectoryInfo dbDir = new DirectoryInfo(dbDirPath); foreach (FileInfo file in dbDir.GetFiles()) { if (file.FullName == dbPath) { continue; } try { Project project = Serializer.Load <Project> (file.FullName); projectsDB.Add(project.Description); } catch (Exception ex) { Log.Exception(ex); } } projectsDB.Save(); }
public void AddProject(Project project) { string projectFile; bool update = false; Log.Debug(string.Format("Add project {0}", project.ID)); projectFile = Path.Combine(dbDirPath, project.ID.ToString()); string tmpProjectFile = projectFile + ".tmp"; project.Description.LastModified = DateTime.UtcNow; if (projectsDB.ProjectsDict.ContainsKey(project.Description.ProjectID)) { update = true; } projectsDB.Add(project.Description); try { serializer.Save(project, tmpProjectFile); if (File.Exists(projectFile)) { File.Replace(tmpProjectFile, projectFile, null); } else { File.Move(tmpProjectFile, projectFile); } } catch (Exception ex) { Log.Exception(ex); // FIXME: This is dirty, but I can't find another way right now. if (!update) { projectsDB.Delete(project.Description.ProjectID); } throw; } }
public void Reload() { projectsDB = new LiteDB (dbPath); DirectoryInfo dbDir = new DirectoryInfo (dbDirPath); foreach (FileInfo file in dbDir.GetFiles ()) { if (file.FullName == dbPath) { continue; } try { Project project = serializer.Load<Project> (file.FullName); projectsDB.Add (project.Description); } catch (Exception ex) { Log.Exception (ex); } } projectsDB.Save (); }