No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SearchLocks.cs 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections.Generic;
  3. using Codice.Client.Commands.WkTree;
  4. using Codice.Client.Common;
  5. using Codice.Client.Common.Locks;
  6. using Codice.Client.Common.WkTree;
  7. using Codice.CM.Common;
  8. using Codice.CM.WorkspaceServer.DataStore.Guids;
  9. namespace Unity.PlasticSCM.Editor.AssetsOverlays.Cache
  10. {
  11. internal static class SearchLocks
  12. {
  13. internal static Dictionary<WorkspaceTreeNode, LockInfo> GetLocksInfo(
  14. WorkspaceInfo wkInfo,
  15. Dictionary<RepositorySpec, List<WorkspaceTreeNode>> locksCandidates)
  16. {
  17. Dictionary<WorkspaceTreeNode, LockInfo> result =
  18. new Dictionary<WorkspaceTreeNode, LockInfo>();
  19. Dictionary<string, Dictionary<Guid, LockInfo>> locksByItemByServer =
  20. new Dictionary<string, Dictionary<Guid, LockInfo>>(
  21. StringComparer.InvariantCultureIgnoreCase);
  22. foreach (KeyValuePair<RepositorySpec, List<WorkspaceTreeNode>> each in locksCandidates)
  23. {
  24. FillRepositoryLocks(
  25. wkInfo, each.Key, each.Value,
  26. locksByItemByServer, result);
  27. }
  28. return result;
  29. }
  30. static void FillRepositoryLocks(
  31. WorkspaceInfo wkInfo,
  32. RepositorySpec repSpec,
  33. List<WorkspaceTreeNode> candidates,
  34. Dictionary<string, Dictionary<Guid, LockInfo>> locksByItemByServer,
  35. Dictionary<WorkspaceTreeNode, LockInfo> locks)
  36. {
  37. if (candidates.Count == 0)
  38. return;
  39. LockRule lockRule = ServerLocks.GetLockRule(repSpec);
  40. if (lockRule == null)
  41. return;
  42. candidates = GetLockableCandidates(candidates, lockRule);
  43. if (candidates.Count == 0)
  44. return;
  45. string lockServer = string.IsNullOrEmpty(lockRule.LockServer) ?
  46. repSpec.Server : lockRule.LockServer;
  47. Dictionary<Guid, LockInfo> serverlocksByItem =
  48. ServerLocks.GetServerLocksByItem(
  49. lockServer, locksByItemByServer);
  50. if (serverlocksByItem == null || serverlocksByItem.Count == 0)
  51. return;
  52. IList<Guid> candidatesGuids = GetCandidatesGuids(
  53. wkInfo, repSpec, candidates);
  54. for (int index = 0; index < candidates.Count; index++)
  55. {
  56. LockInfo serverLock;
  57. if (!serverlocksByItem.TryGetValue(
  58. candidatesGuids[index], out serverLock))
  59. continue;
  60. locks[candidates[index]] = serverLock;
  61. }
  62. }
  63. static List<WorkspaceTreeNode> GetLockableCandidates(
  64. List<WorkspaceTreeNode> candidates,
  65. LockRule lockRule)
  66. {
  67. List<WorkspaceTreeNode> result = new List<WorkspaceTreeNode>();
  68. LockedFilesFilter filter = new LockedFilesFilter(lockRule.Rules);
  69. foreach (WorkspaceTreeNode candidate in candidates)
  70. {
  71. string cmPath = WorkspaceNodeOperations.GetCmPath(candidate);
  72. if (cmPath == null)
  73. {
  74. //The node could not be on the head tree (like copied items) so when we
  75. //cannot calculate the path we assume that it's lockable.
  76. result.Add(candidate);
  77. continue;
  78. }
  79. if (filter.IsLockable(cmPath))
  80. result.Add(candidate);
  81. }
  82. return result;
  83. }
  84. static IList<Guid> GetCandidatesGuids(
  85. WorkspaceInfo wkInfo,
  86. RepositorySpec repSpec,
  87. List<WorkspaceTreeNode> candidates)
  88. {
  89. RepositoryInfo repInfo = RepositorySpecResolverProvider.
  90. Get().GetRepInfo(repSpec);
  91. IList<long> ids = new List<long>(candidates.Count);
  92. foreach (WorkspaceTreeNode candidate in candidates)
  93. ids.Add(candidate.RevInfo.ItemId);
  94. return GuidResolver.Get().GetObjectGuids(repInfo, wkInfo, ids);
  95. }
  96. }
  97. }