4 using SiliconStudio.Core;
5 using SiliconStudio.Core.Storage;
6 using SiliconStudio.Core.Serialization;
7 using SiliconStudio.Core.Serialization.Assets;
9 using System.Collections.Generic;
11 using System.Reflection;
12 using System.Threading;
13 using System.Threading.Tasks;
15 namespace SiliconStudio.BuildEngine
17 [DataContract(Inherited =
true)]
23 protected const int CommandCacheVersion = 1;
28 public abstract string Title {
get; }
39 internal bool BasePreCommandCalled =
false;
44 internal bool BasePostCommandCalled =
false;
49 protected internal CancellationToken CancellationToken;
54 protected internal Dictionary<string, TagSymbol> TagSymbols =
new Dictionary<string, TagSymbol>();
69 if (CancellationToken.IsCancellationRequested)
70 return Task.FromResult(ResultStatus.Cancelled);
72 return DoCommandOverride(commandContext);
78 BasePreCommandCalled =
true;
84 BasePostCommandCalled =
true;
89 var copy = (
Command)Activator.CreateInstance(GetType());
90 foreach (PropertyInfo property
in GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
92 if (property.GetSetMethod() != null)
94 var value = property.GetValue(
this);
95 property.SetValue(copy, value);
102 public abstract override string ToString();
142 var inputFiles = GetInputFiles();
143 if (inputFiles == null)
146 foreach (var inputFile
in inputFiles)
148 var hash = prepareContext.ComputeInputHash(inputFile.Type, inputFile.Path);
151 writer.NativeStream.WriteByte(0);
164 writer.Write(CommandCacheVersion);
167 ComputeAssemblyHash(writer);
170 ComputeParameterHash(writer);
173 ComputeInputFilesHash(writer, prepareContext);
179 writer.Write(DataSerializer.BinaryFormatVersion);
182 writer.Write(AssemblyHash.ComputeAssemblyHash(GetType().Assembly));
187 var tagSymbol =
new TagSymbol(name, getValue);
188 TagSymbols.Add(name, tagSymbol);
196 ComputeCommandHash(stream, prepareContext);
198 return stream.CurrentHash;
virtual void PreCommand(ICommandContext commandContext)
virtual bool ShouldSpawnNewProcess()
virtual void ComputeAssemblyHash(BinarySerializationWriter writer)
Task< ResultStatus > DoCommand(ICommandContext commandContext)
The method that indirectly call DoCommandOverride to execute the actual command code. It is called by the current Builder when the command is triggered
virtual void PostCommand(ICommandContext commandContext, ResultStatus status)
virtual void ComputeParameterHash(BinarySerializationWriter writer)
virtual bool ShouldForceExecution()
Check some conditions that determine if the command should be executed. This method may not be called...
Implements SerializationStream as a binary writer.
virtual void Cancel()
Callback called by Builder.CancelBuild. It can be useful for commands in a blocking call that can be ...
ResultStatus
Status of a command.
TagSymbol RegisterTag(string name, Func< string > getValue)
void ComputeCommandHash(Stream stream, IPrepareContext prepareContext)
virtual IEnumerable< ObjectUrl > GetInputFiles()
Gets the list of input files (that can be deduced without running the command, only from command para...
static readonly ObjectId Empty
A hash to uniquely identify data.
void ComputeInputFilesHash(BinarySerializationWriter writer, IPrepareContext prepareContext)