Ejemplo n.º 1
0
        public static IList <Client> GetClientList()
        {
            var result = new Perforce();

            var con = result.Repository?.Connection;

            if (con == null)
            {
                return(null);
            }

            con.UserName = result.Username;

            IList <Client> clients = null;

            try
            {
                con.Connect(null);
                var options = new ClientsCmdOptions(ClientsCmdFlags.None, result.Username, string.Empty, 64, string.Empty);
                clients = result.Repository.GetClients(options);
            }
            finally
            {
                con.Disconnect();
            }

            return(clients);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        //private const string PerforceHost = "snowlion";
        //private static readonly string PerforceServer = $"ssl:{PerforceHost}:1666";

        public static Perforce ConnectToPath(string path)
        {
            var result = new Perforce();

            if (result.Server == null)
            {
                return(null);
            }

            if (result.Repository == null)
            {
                return(null);
            }

            try
            {
                result.DiscoverClient(path);
            }
            catch (Exception)
            {
                return(null);
            }

            return(result);
        }
Ejemplo n.º 4
0
        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());
        }
Ejemplo n.º 5
0
        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);
        }