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 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; } }