/*----< edit stored metadata >---------------------------------*/ /* * - set info.fileName to the name of package to be edited * - set info properties that are to be edited with new values * - only isOpen, name, and description can be changed * - once closed, metadata cannot be edited again */ public bool editMetadata(CheckinInfo info) { string found = findStoredMetaData(info.category, info.fileName); if (found.Length == 0) { return(false); } IMetaData md = loadMetaData(storagePath(info.category), found); if (md == null) { return(false); } if (md.isOpen == false) { TestUtilities.putLine("can't edit closed metadata"); return(false); } if (ClientEnvironment.verbose) { Console.Write("\n editing stored metadata file \"" + found + "\":"); md.show(); } if (info.isOpen == false) { md.isOpen = false; } if (info.name.Length > 0) { md.name = info.name; } if (info.description.Length > 0) { md.description = info.description; } bool test = TestUtilities.handleInvoke( () => { return(md.save(storagePath(info.category) + "/" + found)); } ); return(test); }
/*----< test editing of stored metadata >----------------------*/ /* * - test closing (checkin), changing name and description * - no other properties can be changed. */ public bool testEditMetadata() { if (ClientEnvironment.verbose) { TestUtilities.title("testing editMetaData in Storage"); } string found = checkin.findStoredMetaData("test", "testMd2.xml"); if (found.Length == 0) { return(false); } CheckinInfo info = new CheckinInfo(); info.fileName = "testMd2.xml"; info.category = "test"; info.name = "newFileName"; info.description = "new description"; info.isOpen = false; if (!checkin.editMetadata(info)) { return(false); } IMetaData md = null; bool test = TestUtilities.handleInvoke( () => { md = checkin.loadMetaData(checkin.storagePath("test"), found); return(md != null); } ); if (ClientEnvironment.verbose) { Console.Write("\n revised metadata file \"{0}\" contains:", found); md.show(); } return(test); }
/*----< test checkin including dependencies >------------------*/ /* * - places files testFile1.cs, testFile2.cs, and testFile3.cs in staging * - checks in first two files without dependencies * - checks in third file with dependencies on the first two */ public bool testDoCheckin() { TestUtilities.vbtitle("testing doCheckin"); testSetup(); // checkin file testFile1.cs CheckinInfo info1 = new CheckinInfo(); info1.category = "test"; info1.name = "testFile1.cs"; info1.isOpen = false; info1.fileName = "testFile1.cs"; info1.author = "Jim Fawcett"; info1.description = "first checkin test file"; FileStream fs = File.Create(RepoEnvironment.storage.stagingFilePath(info1.fileName)); fs.Close(); bool t1 = checkin.doCheckin(info1); // show the resulting metadata file bool t2 = false; TestUtilities.putLine(string.Format("first checkin of file \"{0}\":", info1.fileName)); FileName found = checkin.findStoredMetaData(info1.category, info1.name + ".xml"); TestUtilities.putLine(string.Format("metadata \"{0}\" stored in category \"{1}\" has contents:", found, info1.category)); IMetaData md = checkin.loadMetaData(checkin.storagePath(info1.category) + "/", found); if (md != null) { t2 = true; if (ClientEnvironment.verbose) { md.show(); } } TestUtilities.putLine(); // checkin file testFile1.cs again - should increase version number by 1 info1.description = "checking in the first file again - increases version number"; fs = File.Create(RepoEnvironment.storage.stagingFilePath(info1.fileName)); fs.Close(); bool t3 = checkin.doCheckin(info1); // show resulting metadata file bool t4 = false; TestUtilities.putLine(string.Format("second checkin of file \"{0}\":", info1.fileName)); found = checkin.findStoredMetaData(info1.category, info1.name + ".xml"); TestUtilities.putLine(string.Format("metadata \"{0}\" stored in category \"{1}\" has contents:", found, info1.category)); md = checkin.loadMetaData(checkin.storagePath(info1.category) + "/", found); if (md != null) { t4 = true; if (ClientEnvironment.verbose) { md.show(); } } TestUtilities.putLine(); // checkin second file testFile2.cs CheckinInfo info2 = new CheckinInfo(); info2.category = "test"; info2.name = "testFile2.cs"; info2.fileName = "testFile2.cs"; info2.isOpen = false; info2.author = "Jim Fawcett"; info2.description = "second checkin test file"; fs = File.Create(RepoEnvironment.storage.stagingFilePath(info2.fileName)); fs.Close(); bool t5 = checkin.doCheckin(info2); // show resulting metadata bool t6 = false; found = checkin.findStoredMetaData(info2.category, info2.name + ".xml"); TestUtilities.putLine(string.Format("metadata \"{0}\" stored in category \"{1}\" has contents:", found, info2.category)); md = checkin.loadMetaData(checkin.storagePath(info2.category) + "/", found); if (md != null) { t6 = true; if (ClientEnvironment.verbose) { md.show(); } } TestUtilities.putLine(); // checkin third file testFile3.cs that depends on the first two files CheckinInfo info3 = new CheckinInfo(); info3.category = "test"; info3.name = "testFile3.cs"; info3.fileName = "testFile3.cs"; fs = File.Create(RepoEnvironment.storage.stagingFilePath(info3.fileName)); fs.Close(); info3.author = "Jim Fawcett"; info3.description = "third checkin test file has dependencies on first two checkins"; // add dependencies FileName found1 = checkin.findStoredMetaData(info1.category, info1.name + ".xml"); found1 = "test/" + found1; info3.deps.Add(found1); FileName found2 = checkin.findStoredMetaData(info2.category, info2.name + ".xml"); found2 = "test/" + found2; info3.deps.Add(found2); bool t7 = checkin.doCheckin(info3); // show resulting metadata file bool t8 = false; found = checkin.findStoredMetaData(info3.category, info3.name + ".xml"); TestUtilities.putLine(string.Format("metadata \"{0}\" stored in category \"{1}\" has contents:", found, info3.category)); md = checkin.loadMetaData(checkin.storagePath(info3.category) + "/", found); if (md != null) { t8 = true; if (ClientEnvironment.verbose) { md.show(); } } return(t1 && t2 && t3 && t4 && t5 && t6 && t7 && t8); }
/*----< checkin file from staging area to storage area >-------*/ /* * - CheckinInfo is defined in IPluggable.cs * - it contains properties found in a MetaData instance */ public bool doCheckin(CheckinInfo info, bool prevIsOpen = false) { MetaData md = new MetaData(info.author, info.fileName); if (md == null) { return(false); } md.name = info.name; md.author = info.author; md.isOpen = info.isOpen; md.description = info.description; foreach (string dep in info.deps) { md.dependencies.Add(dep); } // should we create new version or modify old version int fileVer = RepoEnvironment.version.getLatestVersion(info.category, info.fileName); bool doModify; if (fileVer == 0) // no previous checkin so make new version { doModify = false; } else if (!prevIsOpen) // last checkin was closed so make new version { doModify = false; } else // last checkin was open so just modify existing version { doModify = true; } // move or copy source file to versioned file in Storage bool t1; if (doModify) { t1 = RepoEnvironment.storage.modifyFile(info.category, info.fileName); } else { t1 = RepoEnvironment.storage.addFile(info.category, info.fileName); } // get version from version cache, possibly updated by addFile fileVer = RepoEnvironment.version.getLatestVersion(info.category, info.fileName); // build versioned fileSpec and add to MetaData instance md.fileSpec = info.category + "/" + info.fileName + "." + fileVer.ToString(); string mdFileName = info.fileName + ".xml"; // update dependencies cache FileSpec parent = info.category + "/" + info.fileName + ".xml." + fileVer.ToString(); foreach (FileSpec dep in md.dependencies) { RepoEnvironment.storage.upDateDependencyCache(parent, dep); } md.save(RepoEnvironment.storage.stagingFilePath(mdFileName)); // move or copy metadata file to versioned file in storage bool t2; int metaVer = RepoEnvironment.version.getLatestVersion(info.category, mdFileName); if (doModify) { t2 = RepoEnvironment.storage.modifyFile(info.category, mdFileName); } else { t2 = RepoEnvironment.storage.addFile(info.category, mdFileName); } List <string> stagedFiles = RepoEnvironment.storage.stagedFiles(); RepoEnvironment.storage.deleteStagedFiles(); return(t1 && t2); }