using System; using System.Collections.Generic; using System.Text; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Microsoft.Build.BuildEngine; using P4API; namespace P4.Net.P4MSBuildTasks { public class P4Sync : P4BaseTask { private bool _keep; public bool Keep { get { return _keep; } set { _keep = value; } } private bool _force; public bool Force { get { return _force; } set { _force = value; } } private bool _noSync; public bool NoSync { get { return _noSync; } set { _noSync = value; } } private bool _populateOnly; public bool PopulateOnly { get { return _populateOnly; } set { _populateOnly = value; } } private string[] _syncPaths; [Required] public string[] SyncPaths { get { return _syncPaths; } set { _syncPaths = value; } } public override void P4Execute() { List<string> args = new List<string>(); if (_populateOnly) args.Add("-p"); if (_force) args.Add("-f"); if (_keep) args.Add("-k"); if (_noSync) args.Add("-n"); args.AddRange(_syncPaths); SyncCallback callback = new SyncCallback(Log); _p4.RunCallback("sync", true, callback, args.ToArray()); } } internal class SyncCallback : P4Callback { private TaskLoggingHelper Log; public SyncCallback(TaskLoggingHelper log) { Log = log; } #region P4Callback Members public void Finished() { } public void OutputMessage(P4Message message) { if (message.Identity == 554768772) // file(s) up-to-date. { Log.LogMessage(message.Format()); } else { Log.LogError("Code: {0}", message.Identity); Log.LogError(message.Format()); } } public void OutputRecord(P4Record record) { if (record.Fields.ContainsKey("totalFileCount")) { Log.LogMessage("Syncing {0} files, {1} bytes", record["totalFileCount"], record["totalFileSize"]); } string message = string.Format("{0}#{1} - {2} {3}", record["depotFile"], record["rev"], record["action"], record["clientFile"]); Log.LogMessage(message); } #endregion } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 6335 | Jim Gomes | Branch P4.Net. | ||
//guest/shawn_hladky/P4.Net/main/samples/P4MSBuildTasks/src/P4MSBuildTasks/P4Sync.cs | |||||
#2 | 6243 | Shawn Hladky | P4.Net: Change Callback from interface to abstract class | ||
#1 | 6182 | Shawn Hladky |
P4.Net. First stab at a callback interface for real-time handling of perforce output. Upgrade to VS 2008. |