Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
CommandContextBase.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System.Collections.Generic;
4 using SiliconStudio.Core.Storage;
5 using System.Threading.Tasks;
6 
7 using SiliconStudio.Core.Diagnostics;
8 using SiliconStudio.Core.Serialization.Assets;
9 
10 namespace SiliconStudio.BuildEngine
11 {
12  public abstract class CommandContextBase : ICommandContext
13  {
14  public Command CurrentCommand { get; private set; }
15 
16  public abstract Logger Logger { get; }
17 
18  public BuildParameterCollection BuildParameters { get; private set; }
19 
20  public IMetadataProvider MetadataProvider { get; private set; }
21 
22  protected internal readonly CommandResultEntry ResultEntry;
23 
24  protected abstract Task<ResultStatus> ScheduleAndExecuteCommandInternal(Command command);
25 
26  public abstract IEnumerable<IDictionary<ObjectUrl, OutputObject>> GetOutputObjectsGroups();
27 
28  internal protected abstract ObjectId ComputeInputHash(UrlType type, string filePath);
29 
30  protected CommandContextBase(Command command, BuilderContext builderContext)
31  {
32  CurrentCommand = command;
33  BuildParameters = builderContext.Parameters;
34  ResultEntry = new CommandResultEntry();
35  MetadataProvider = builderContext.MetadataProvider;
36  }
37 
39  {
40  ResultEntry.SpawnedCommands.Add(command);
41  return ScheduleAndExecuteCommandInternal(command);
42  }
43 
45  {
46  ResultEntry.InputDependencyVersions.Add(url, ComputeInputHash(url.Type, url.Path));
47  }
48 
49  public void RegisterOutput(ObjectUrl url, ObjectId hash)
50  {
51  ResultEntry.OutputObjects.Add(url, hash);
52  }
53 
54  public void AddTag(ObjectUrl url, TagSymbol tagSymbol)
55  {
56  ResultEntry.TagSymbols.Add(new KeyValuePair<ObjectUrl, string>(url, tagSymbol.Name));
57  }
58 
60  {
61  ResultEntry.SpawnedCommands.Add(command);
62  }
63  }
64 }
void RegisterSpawnedCommandWithoutScheduling(Command command)
CommandContextBase(Command command, BuilderContext builderContext)
Base implementation for ILogger.
Definition: Logger.cs:10
void RegisterOutput(ObjectUrl url, ObjectId hash)
Task< ResultStatus > ScheduleAndExecuteCommand(Command command)
void AddTag(ObjectUrl url, TagSymbol tagSymbol)
A hash to uniquely identify data.
Definition: ObjectId.cs:13