/// <summary> /// Checks the specified file or folder into the repository. /// </summary> /// <exception>Exception</exception> private void Checkin(string fileName) { string normalizedPath = RepositoryPath.NormalizeFolder(fileName); if (IsVaultFolder(normalizedPath)) { VaultClientFolder vaultClientFolder = ClientInstance.TreeCache.Repository.Root.FindFolderRecursive(normalizedPath); if (!String.IsNullOrEmpty(WorkingFolder)) { ClientInstance.TreeCache.SetWorkingFolder(vaultClientFolder.FullPath, WorkingFolder); } ClientInstance.Refresh(); ChangeSetItemColl changeSet; BuildChangeSetOfCheckedOutFiles(vaultClientFolder, out changeSet); if (!ClientInstance.Commit(changeSet)) { string errMsg = VaultConnection.GetSoapExceptionMessage(changeSet[0].Request.Response.Status); throw new Exception(string.Format(Properties.Resources.VaultCheckinFolderException, normalizedPath, errMsg)); } else { Version = Convert.ToInt32(vaultClientFolder.Version); Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultCheckinSuccessful), vaultClientFolder.Name); } } else if (IsVaultFile(normalizedPath)) { string previousWorkingFolder = ""; string repositoryFolderPath = ""; string tmpdiskPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), string.Format("msbuild_checkinfor_{0}", System.IO.Path.GetFileName(normalizedPath))); VaultClientFile vaultClientFile = ClientInstance.TreeCache.Repository.Root.FindFileRecursive(normalizedPath); if (!String.IsNullOrEmpty(WorkingFolder)) { ClientInstance.TreeCache.SetWorkingFolder(vaultClientFile.Parent.FullPath, WorkingFolder); } string diskFilename = System.IO.Path.Combine(ClientInstance.GetWorkingFolder(vaultClientFile).GetLocalFolderPath(), normalizedPath.Substring(normalizedPath.LastIndexOf(VaultDefine.PathSeparator) + 1)); bool bChangeWorkingFolder = false; if (!Misc.stringIsBlank(_diskFile) && _diskFile != diskFilename) { bChangeWorkingFolder = true; if (!File.Exists(_diskFile)) { throw new Exception(string.Format(Properties.Resources.VaultDiskFileDoesNotExist, _diskFile)); } // They've specified a different disk file (no working folder) repositoryFolderPath = vaultClientFile.Parent.FullPath; previousWorkingFolder = ClientInstance.TreeCache.GetWorkingFolder(repositoryFolderPath); if (Directory.Exists(tmpdiskPath) == false) { Directory.CreateDirectory(tmpdiskPath); } // Set a different working folder to avoid interference with the real working folder ClientInstance.TreeCache.SetWorkingFolder(repositoryFolderPath, tmpdiskPath); diskFilename = System.IO.Path.Combine(tmpdiskPath, vaultClientFile.Name); Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultSetNewWorkingFolder, repositoryFolderPath, tmpdiskPath, previousWorkingFolder)); ClientInstance.CheckOut(vaultClientFile, 2, "Temp checkout for MSBuild Vault task."); ClientInstance.Get(vaultClientFile, true, MakeWritableType.MakeAllFilesWritable, SetFileTimeType.Current, MergeType.OverwriteWorkingCopy, null); if (File.Exists(diskFilename)) { File.SetAttributes(diskFilename, FileAttributes.Normal); File.Delete(diskFilename); } File.Copy(_diskFile, diskFilename); ClientInstance.Refresh(); } try { ChangeSetItemColl requestedChange = new ChangeSetItemColl(); requestedChange.Add(new ChangeSetItem_Modified(DateTime.Now, _comment, "", vaultClientFile.ID, vaultClientFile.ObjVerID, diskFilename, normalizedPath, false, vaultClientFile.EOL)); if (!ClientInstance.Commit(requestedChange)) { string errMsg = VaultConnection.GetSoapExceptionMessage(requestedChange[0].Request.Response.Status); throw new Exception(string.Format(Properties.Resources.VaultCheckinFileException, normalizedPath, errMsg)); } else { Version = Convert.ToInt32(vaultClientFile.Version); Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultCheckinSuccessful, vaultClientFile.Name)); } } finally { if (bChangeWorkingFolder) { if (Misc.stringIsBlank(previousWorkingFolder)) { Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultWorkingFolderCleared, repositoryFolderPath)); ClientInstance.TreeCache.RemoveWorkingFolder(repositoryFolderPath); } else { Log.LogMessage(MessageImportance.Normal, string.Format(Properties.Resources.VaultWorkingFolderRestored, repositoryFolderPath, previousWorkingFolder)); ClientInstance.TreeCache.SetWorkingFolder(repositoryFolderPath, previousWorkingFolder); } } if (Directory.Exists(tmpdiskPath)) { Misc.DeleteDirectoryRecursivelyIncludingReadOnly(tmpdiskPath); } } } else { throw new Exception(string.Format(Properties.Resources.VaultCheckinFileNotFoundException, normalizedPath)); } }