public static List <FileMetaData> FileStatus(string[] filePathList) { IList <FileMetaData> filesMetaData = null; Perforce server = new Perforce(); try { string fixedFilePath = GetFilePath(filePathList.FirstOrDefault()); server.DiscoverClient(fixedFilePath); // connect to the server server.Connect(); List <FileSpec> filesToCheck = new List <FileSpec>(); foreach (string filePath in filePathList) { fixedFilePath = GetFilePath(filePath); filesToCheck.Add(new ClientPath(fixedFilePath)); } GetFileMetaDataCmdOptions options = new GetFileMetaDataCmdOptions(GetFileMetadataCmdFlags.None, null, null, 0, null, null, null); filesMetaData = server.Repository.GetFileMetaData(options, filesToCheck.ToArray()); } finally { server.Disconnect(); } return(filesMetaData != null ? new List <FileMetaData>(filesMetaData) : null); }
public static List <string> FileOperation(List <string> filePathList, FileAction action) { IList <FileSpec> filesEdited = null; Perforce server = new Perforce(); if (server.Enabled == false) { return(new List <string>()); } try { server.DiscoverClient(GetFilePath(filePathList[0])); // connect to the server server.Connect(); foreach (string filePath in filePathList) { string fixedFilePath = GetFilePath(filePath); FileSpec fileToAdd = new FileSpec(new ClientPath(fixedFilePath)); if (System.IO.File.Exists(fixedFilePath) == true) { EditCmdOptions options = new EditCmdOptions(EditFilesCmdFlags.None, 0, null); // run the command with the current connection if (action == FileAction.Add) { filesEdited = server.Repository.Connection.Client.AddFiles(options, fileToAdd); } else if (action == FileAction.Edit) { filesEdited = server.Repository.Connection.Client.EditFiles(options, fileToAdd); } else if (action == FileAction.Delete) { filesEdited = server.Repository.Connection.Client.DeleteFiles(options, fileToAdd); } else if (action == FileAction.Reverted) { filesEdited = server.Repository.Connection.Client.RevertFiles(options, fileToAdd); } } } } finally { server.Disconnect(); } List <FileSpec> fileSpecList = new List <FileSpec>(); if (filesEdited != null) { fileSpecList = new List <FileSpec>(filesEdited); } return(fileSpecList.Select(x => x.ClientPath.ToString()).ToList()); }
public static List <FileMetaData> FileStatus(string filePath) { IList <FileMetaData> filesMetaData = null; Perforce server = new Perforce(); try { string fixedFilePath = GetFilePath(filePath); server.DiscoverClient(fixedFilePath); // connect to the server server.Connect(); FileSpec[] fileToCheck = new FileSpec[] { new ClientPath(fixedFilePath) }; GetFileMetaDataCmdOptions options = new GetFileMetaDataCmdOptions(GetFileMetadataCmdFlags.None, null, null, 0, null, null, null); filesMetaData = server.Repository.GetFileMetaData(options, fileToCheck); } finally { server.Disconnect(); } return(filesMetaData != null ? new List <FileMetaData>(filesMetaData) : null); }