/// <summary> Adds the file or directpry to the repository.</summary> /// <param name="parentFolder">StarTeam folder underwhich items will be added.</param> /// <param name="file">the file or directory to add</param> /// <returns>true if the file was successfully added otherwise false.</returns> private bool add(InterOpStarTeam.StFolder parentFolder, FileInfo file) { // If the current file is a Directory, we need to process all of its children as well. if (Directory.Exists(file.FullName)) { if (!_createFolders) { Log(Level.Info, "Could not add new folder as createfolders is disabled: {0}", file.FullName); return(false); } Log(Level.Info, "Adding new folder to repository: {0}", file.FullName); InterOpStarTeam.StFolder newFolder = starteamFolderFactory.Create(parentFolder); newFolder.Name = file.Name; newFolder.update(); // now visit this new folder to take care of adding any files or subfolders within it. if (this.recursive) { visit(newFolder, file); } } else { Log(Level.Info, "Adding new file to repository: {0}", file.FullName); InterOpStarTeam.StFile newFile = starteamFileFactory.Create(parentFolder); newFile.Add(file.FullName, file.Name, null, _comment, starTeamLockTypeStatics.UNLOCKED, true, true); _updateLabel(newFile); } return(true); }
/// <summary> /// Creates the versionumber.xml file in the repository. /// </summary> /// <param name="stFolder">StarTeam folder desired to put the versionnumber.xml files into</param> /// <returns>StarTeam File handle to the created file.</returns> private InterOpStarTeam.StFile createVersionStFile(InterOpStarTeam.StFolder stFolder) { // instantiated here as they are only necessary when adding InterOpStarTeam.StFileFactoryClass starteamFileFactory = new InterOpStarTeam.StFileFactoryClass(); string versionFilePath = stFolder.getFilePath(_versionFile); // create xml and save to local file try { StreamWriter s = new StreamWriter(versionFilePath, false, System.Text.ASCIIEncoding.ASCII); XmlTextWriter xmlWriter = new XmlTextWriter(s); xmlWriter.WriteStartDocument(false); xmlWriter.WriteStartElement("stautolabel"); xmlWriter.WriteStartElement("version"); xmlWriter.WriteAttributeString("major", "1"); xmlWriter.WriteAttributeString("minor", "0"); xmlWriter.WriteAttributeString("build", "0"); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.Close(); } catch (System.Security.SecurityException ex) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "You do not have access to '{0}'.", versionFilePath), Location, ex); } catch (IOException ex) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Version filepath '{0}' is invalid.", versionFilePath), Location, ex); } //add local file to starteam InterOpStarTeam.StFile newFile = starteamFileFactory.Create(stFolder); string comment = "version number xml created by stautonumber NAnt task"; newFile.Add(versionFilePath, _versionFile, comment, comment, starTeamLockTypeStatics.UNLOCKED, true, true); return(newFile); }