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 int[] _ignoredWarnings = { 554768772, // file(s) up-to-date. 554768759 // no such file(s). }; public int[] IgnoredWarnings { get { return _ignoredWarnings; } set { _ignoredWarnings = 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, _ignoredWarnings); _p4.RunCallback(callback, "sync", args.ToArray()); } } internal class SyncCallback : P4Callback { private TaskLoggingHelper Log; private List<int> _ignoredWarnings; public SyncCallback(TaskLoggingHelper log, int[] ignoredWarnings) { Log = log; _ignoredWarnings = new List<int>(ignoredWarnings); } #region P4Callback Members public override void Finished() { } public override void OutputMessage(P4Message message) { if (_ignoredWarnings.Contains(message.Identity)) { Log.LogMessage(message.Format()); } else { Log.LogError("Sync Error. Code: {0}. Message: {1}", message.Identity, message.Format()); } } public override 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 | 7341 | Erik Purins |
p4.net --- pull p4.net#head |
||
//guest/shawn_hladky/P4.Net/main/samples/P4MSBuildTasks/src/P4MSBuildTasks/P4Sync.cs | |||||
#3 | 6505 | Shawn Hladky |
P4.Net: Multiple Changes 1. Update samples to VS2008 and new bin paths 2. Update MSBuild sync tasks to have IgnoredWarnings parameter 3. Added public class for P4RecordsetCallback. This allows consumers to easily migrate code that uses Recordsets to also take advantage of callback hooks. 4. Reworked method signiture of RunCallback. Removed tagged parameter and added RunCallbackUnparsed method. Made Callback parameter first so command and arguments are next to one-another. Note: this is a BREAKING CHANGE if you are using callbacks. 5. Reworked so switching between tagged and untagged runs will not disconnect/reconnect. 6. Add initial work for a file diffing object. |
||
#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. |