Beispiel #1
0
        public void Sync()
        {
            try
            {
                // new connection for every thread.
                Perforce.P4.Server     server = new Perforce.P4.Server(new Perforce.P4.ServerAddress(options.Server));
                Perforce.P4.Repository rep    = new Perforce.P4.Repository(server);
                Perforce.P4.Connection con    = rep.Connection;


                con.UserName    = options.User;
                con.Client      = new Perforce.P4.Client();
                con.Client.Name = options.ClientSpec;
                con.Connect(null);
                Perforce.P4.Credential Creds = con.Login(options.Passwd, null, null);
                con.InfoResultsReceived += new P4Server.InfoResultsDelegate(con_InfoResultsReceived);
                con.ErrorReceived       += new P4Server.ErrorDelegate(con_ErrorReceived);
                con.TextResultsReceived += new P4Server.TextResultsDelegate(con_TextResultsReceived);


                // get server metadata and check version
                // (using null for options parameter)
                ServerMetaData p4info  = rep.GetServerMetaData();
                ServerVersion  version = p4info.Version;
                string         release = version.Major;

                // lets get all the files which need to be synced.
                SyncFilesCmdOptions syncOpts    = new SyncFilesCmdOptions(SyncFilesCmdFlags.None, -1);
                IList <FileSpec>    syncedFiles = con.Client.SyncFiles(syncOpts, FilesToSync.ToArray());
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("Perforce error - Thread exiting ");
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var options = new Options();

            if (!CommandLine.Parser.Default.ParseArguments(args, options))
            {
                System.Console.WriteLine("Wrong Parameters");
            }

            Perforce.P4.Server     server = new Perforce.P4.Server(new Perforce.P4.ServerAddress(options.Server));
            Perforce.P4.Repository rep    = new Perforce.P4.Repository(server);
            Perforce.P4.Connection con    = rep.Connection;

            con.UserName    = options.User;
            con.Client      = new Perforce.P4.Client();
            con.Client.Name = options.ClientSpec;
            con.Connect(null);
            Perforce.P4.Credential Creds = con.Login(options.Passwd, null, null);
            con.InfoResultsReceived += new P4Server.InfoResultsDelegate(con_InfoResultsReceived);
            con.ErrorReceived       += new P4Server.ErrorDelegate(con_ErrorReceived);
            con.TextResultsReceived += new P4Server.TextResultsDelegate(con_TextResultsReceived);

            // lets get all the files which need to be synced.
            SyncFilesCmdOptions syncOpts    = new SyncFilesCmdOptions(SyncFilesCmdFlags.Preview, -1);
            IList <FileSpec>    syncedFiles = con.Client.SyncFiles(syncOpts, null);

            con.Disconnect();

            if (syncedFiles != null)
            {
                var           ChunkedLists = Chunk(syncedFiles.AsEnumerable(), syncedFiles.Count() / options.Threads).ToList();
                List <P4Sync> Syncs        = new List <P4Sync>();
                System.Console.WriteLine("We have {0} files to sync. Creating {1} Threads", syncedFiles.Count(), ChunkedLists.Count());
                for (int i = 0; i < ChunkedLists.Count(); i++)
                {
                    Syncs.Add(new P4Sync(options, ChunkedLists[i].ToList(), i));
                }
            }
        }