LongoMatch.DB.DataBase.AddProject C# (CSharp) Method

AddProject() public method

public AddProject ( Project project ) : void
project Project
return void
        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;
            }
        }

Usage Example

Esempio n. 1
0
 public void TestAddProject()
 {
     string dbdir = Path.Combine (tmpdir, "test.ldb");
     DataBase db = new DataBase (dbdir);
     ProjectDescriptionLongoMatch pd1 = new ProjectDescriptionLongoMatch ();
     ProjectLongoMatch p1 = new ProjectLongoMatch {Description = pd1};
     Assert.IsTrue (db.AddProject (p1));
     Assert.IsTrue (File.Exists (Path.Combine (dbdir, p1.ID.ToString())));
     Assert.IsTrue (db.AddProject (p1));
     Assert.AreEqual (db.Count, 1);
     db = new DataBase (dbdir);
     Assert.AreEqual (db.Count, 1);
 }
All Usage Examples Of LongoMatch.DB.DataBase::AddProject