Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
TransactionAssetIndexMap.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;
4 using System.Collections.Generic;
5 using System.Linq;
6 
7 using SiliconStudio.Core.Storage;
8 using SiliconStudio.Core.Serialization.Assets;
9 
10 namespace SiliconStudio.BuildEngine
11 {
12  internal class BuildTransaction
13  {
14  private readonly Dictionary<ObjectUrl, ObjectId> transactionOutputObjects = new Dictionary<ObjectUrl, ObjectId>();
15  private readonly IEnumerable<IDictionary<ObjectUrl, OutputObject>> outputObjectsGroups;
16 
17  public BuildTransaction(IEnumerable<IDictionary<ObjectUrl, OutputObject>> outputObjectsGroups)
18  {
19  this.outputObjectsGroups = outputObjectsGroups;
20  }
21 
22  public IEnumerable<KeyValuePair<ObjectUrl, ObjectId>> GetTransactionIdMap()
23  {
24  return transactionOutputObjects;
25  }
26 
27  public IEnumerable<KeyValuePair<string, ObjectId>> SearchValues(Func<KeyValuePair<string, ObjectId>, bool> predicate)
28  {
29  lock (transactionOutputObjects)
30  {
31  return transactionOutputObjects.Select(x => new KeyValuePair<string, ObjectId>(x.Key.Path, x.Value)).Where(predicate).ToList();
32  }
33  }
34 
35  public bool TryGetValue(string url, out ObjectId objectId)
36  {
37  var objUrl = new ObjectUrl(UrlType.Internal, url);
38 
39  // Lock TransactionAssetIndexMap
40  lock (transactionOutputObjects)
41  {
42  if (transactionOutputObjects.TryGetValue(objUrl, out objectId))
43  return true;
44 
45  foreach (var outputObjects in outputObjectsGroups)
46  {
47  // Lock underlying EnumerableBuildStep.OutputObjects
48  lock (outputObjects)
49  {
50  OutputObject outputObject;
51  if (outputObjects.TryGetValue(objUrl, out outputObject))
52  {
53  objectId = outputObject.ObjectId;
54  return true;
55  }
56  }
57  }
58  }
59 
60  objectId = ObjectId.Empty;
61  return false;
62  }
63 
64  internal class DatabaseAssetIndexMap : IAssetIndexMap
65  {
66  private readonly BuildTransaction buildTransaction;
67 
68  public DatabaseAssetIndexMap(BuildTransaction buildTransaction)
69  {
70  this.buildTransaction = buildTransaction;
71  }
72 
73  public bool TryGetValue(string url, out ObjectId objectId)
74  {
75  return buildTransaction.TryGetValue(url, out objectId);
76  }
77 
78  public bool Contains(string url)
79  {
80  ObjectId objectId;
81  return TryGetValue(url, out objectId);
82  }
83 
84  public ObjectId this[string url]
85  {
86  get
87  {
88  ObjectId objectId;
89  if (!TryGetValue(url, out objectId))
90  throw new KeyNotFoundException();
91 
92  return objectId;
93  }
94  set
95  {
96  lock (buildTransaction.transactionOutputObjects)
97  {
98  buildTransaction.transactionOutputObjects[new ObjectUrl(UrlType.Internal, url)] = value;
99  }
100  }
101  }
102 
103  public IEnumerable<KeyValuePair<string, ObjectId>> SearchValues(Func<KeyValuePair<string, ObjectId>, bool> predicate)
104  {
105  return buildTransaction.SearchValues(predicate);
106  }
107 
108  public void WaitPendingOperations()
109  {
110  }
111 
112  public IEnumerable<KeyValuePair<string, ObjectId>> GetMergedIdMap()
113  {
114  // Shouldn't be used
115  throw new NotImplementedException();
116  }
117 
118  public void Dispose()
119  {
120  }
121  }
122  }
123 }
One bounding volume completely contains another.
A hash to uniquely identify data.
Definition: ObjectId.cs:13