暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RemoteStatusCache.cs 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using System;
  2. using System.Collections.Generic;
  3. using Codice.Client.BaseCommands;
  4. using Codice.Client.Commands;
  5. using Codice.Client.Common;
  6. using Codice.Client.Common.Threading;
  7. using Codice.Client.GameUI;
  8. using Codice.Client.GameUI.Update;
  9. using Codice.CM.Common;
  10. using Codice.CM.Common.Merge;
  11. using Codice.Utils;
  12. using GluonGui.WorkspaceWindow.Views;
  13. namespace Unity.PlasticSCM.Editor.AssetsOverlays.Cache
  14. {
  15. internal class RemoteStatusCache
  16. {
  17. internal RemoteStatusCache(
  18. WorkspaceInfo wkInfo,
  19. bool isGluonMode,
  20. Action repaintProjectWindow)
  21. {
  22. mWkInfo = wkInfo;
  23. mIsGluonMode = isGluonMode;
  24. mRepaintProjectWindow = repaintProjectWindow;
  25. }
  26. internal AssetStatus GetStatus(string fullPath)
  27. {
  28. if (!mIsGluonMode)
  29. return AssetStatus.UpToDate;
  30. lock(mLock)
  31. {
  32. if (mStatusByPathCache == null)
  33. {
  34. mStatusByPathCache = BuildPathDictionary.ForPlatform<AssetStatus>();
  35. mCurrentCancelToken.Cancel();
  36. mCurrentCancelToken = new CancelToken();
  37. AsyncCalculateStatus(mCurrentCancelToken);
  38. return AssetStatus.UpToDate;
  39. }
  40. AssetStatus result;
  41. if (mStatusByPathCache.TryGetValue(fullPath, out result))
  42. return result;
  43. return AssetStatus.UpToDate;
  44. }
  45. }
  46. internal void Clear()
  47. {
  48. lock (mLock)
  49. {
  50. mCurrentCancelToken.Cancel();
  51. mStatusByPathCache = null;
  52. }
  53. }
  54. void AsyncCalculateStatus(CancelToken cancelToken)
  55. {
  56. Dictionary<string, AssetStatus> statusByPathCache = null;
  57. IThreadWaiter waiter = ThreadWaiter.GetWaiter(50);
  58. waiter.Execute(
  59. /*threadOperationDelegate*/ delegate
  60. {
  61. OutOfDateItems outOfDateItems =
  62. OutOfDateUpdater.CalculateOutOfDateItems(
  63. mWkInfo, new List<ErrorMessage>(),
  64. OutOfDateCalculator.Options.IsIncomingChanges);
  65. if (cancelToken.IsCancelled())
  66. return;
  67. statusByPathCache = BuildStatusByPathCache.
  68. ForOutOfDateItems(outOfDateItems, mWkInfo.ClientPath);
  69. },
  70. /*afterOperationDelegate*/ delegate
  71. {
  72. if (waiter.Exception != null)
  73. {
  74. ExceptionsHandler.LogException(
  75. "RemoteStatusCache",
  76. waiter.Exception);
  77. return;
  78. }
  79. if (cancelToken.IsCancelled())
  80. return;
  81. lock (mLock)
  82. {
  83. mStatusByPathCache = statusByPathCache;
  84. }
  85. mRepaintProjectWindow();
  86. });
  87. }
  88. static class BuildStatusByPathCache
  89. {
  90. internal static Dictionary<string, AssetStatus> ForOutOfDateItems(
  91. OutOfDateItems outOfDateItems,
  92. string wkPath)
  93. {
  94. Dictionary<string, AssetStatus> result =
  95. BuildPathDictionary.ForPlatform<AssetStatus>();
  96. if (outOfDateItems == null)
  97. return result;
  98. foreach (OutOfDateItemsByMount diffs in
  99. outOfDateItems.GetOutOfDateItemsByMountList())
  100. {
  101. foreach (Difference diff in diffs.Changed)
  102. {
  103. if (diff is DiffXlinkChanged)
  104. continue;
  105. string path = GetPathForDiff(wkPath, diffs.Mount, diff.Path);
  106. result.Add(path, AssetStatus.OutOfDate);
  107. }
  108. foreach (Difference diff in diffs.Deleted)
  109. {
  110. string path = GetPathForDiff(wkPath, diffs.Mount, diff.Path);
  111. result.Add(path, AssetStatus.DeletedOnServer);
  112. }
  113. }
  114. foreach (GluonFileConflict fileConflict in
  115. outOfDateItems.GetFileConflicts())
  116. {
  117. string path = GetPathForConflict(wkPath, fileConflict.CmPath);
  118. result.Add(path, AssetStatus.Conflicted);
  119. }
  120. return result;
  121. }
  122. static string GetPathForDiff(
  123. string wkPath,
  124. MountPointWithPath mountPoint,
  125. string cmSubPath)
  126. {
  127. return WorkspacePath.GetWorkspacePathFromCmPath(
  128. wkPath,
  129. WorkspacePath.ComposeMountPath(mountPoint.MountPath, cmSubPath),
  130. PathHelper.GetDirectorySeparatorChar(wkPath));
  131. }
  132. static string GetPathForConflict(
  133. string wkPath,
  134. string cmPath)
  135. {
  136. return WorkspacePath.GetWorkspacePathFromCmPath(
  137. wkPath, cmPath,
  138. PathHelper.GetDirectorySeparatorChar(wkPath));
  139. }
  140. }
  141. CancelToken mCurrentCancelToken = new CancelToken();
  142. Dictionary<string, AssetStatus> mStatusByPathCache;
  143. readonly Action mRepaintProjectWindow;
  144. readonly bool mIsGluonMode;
  145. readonly WorkspaceInfo mWkInfo;
  146. static object mLock = new object();
  147. }
  148. }