private void lazyInit() { if (m_algorithms == null) { m_algorithms = new Tfs2008AnalysisAlgorithms(this); } }
private void generateDeltaTableForSnapshot(List <string> paths, int snapshotChangeset) { List <string> pathsToGet = new List <string>(); VersionSpec snapshotVersionSpec = new ChangesetVersionSpec(snapshotChangeset); foreach (string mappingPath in paths) { // Always query at one level down the mapping ItemSet itemSet = m_tfsClient.GetItems(mappingPath, snapshotVersionSpec, RecursionType.OneLevel); Item[] items = itemSet.Items; foreach (Item childItem in items) { // Avoid the item itself. if (!VersionControlPath.Equals(childItem.ServerItem, mappingPath)) { pathsToGet.Add(childItem.ServerItem); } } } int countDownToCreateNewChangeGroup = m_snapshotCheckinBatchSize; ChangeGroup batchGroup = createChangeGroupForSnapshot(snapshotChangeset, snapshotChangeset); foreach (string path in pathsToGet) { TraceManager.TraceInformation("Getting snapshot at changeset: {0}, path: {1}", snapshotChangeset, path); ItemSet itemSet = m_tfsClient.GetItems(path, snapshotVersionSpec, RecursionType.Full); Item[] items = itemSet.Items; itemSet = null; TraceManager.TraceInformation("Snapshot contains {0} items", items.Length); for (int i = 0; i < items.Length; i++) { if (FindMappedPath(items[i].ServerItem) != null) { countDownToCreateNewChangeGroup--; if (countDownToCreateNewChangeGroup == 0) { TraceManager.TraceInformation("Saving {0} change actions", m_snapshotCheckinBatchSize); batchGroup.Save(); batchGroup.Actions.Clear(); batchGroup = null; batchGroup = createChangeGroupForSnapshot(snapshotChangeset, snapshotChangeset); countDownToCreateNewChangeGroup = m_snapshotCheckinBatchSize; TraceManager.TraceInformation("Saved {0} change actions", snapshotChangeset); } batchGroup.CreateAction( WellKnownChangeActionId.Add, new TfsMigrationItem(items[i]), null, items[i].ServerItem, null, null, TfsAnalysisAlgorithms.convertContentType(items[i].ItemType), null); } items[i] = null; // Dispose this object to reduce memory consumption. } } if (batchGroup.Actions.Count > 0) { int numRemainingItems = batchGroup.Actions.Count; TraceManager.TraceInformation("Saving {0} change actions", numRemainingItems); batchGroup.Save(); TraceManager.TraceInformation("Saved {0} change actions", numRemainingItems); } }
/// <summary> /// Create a changegroup that contains all change actions needed to bring a migration target to the specificed snapshot /// </summary> /// <param name="changeGroupName">The change group name of the snapshot</param> private void generateSnapshotForVCSession() { foreach (var setting in ConfigurationService.VcCustomSetting.Settings.Setting) { if (setting.SettingKey == "SnapshotStartPoint") { m_sessionLevelSnapshotChangeset = parseSnapShotStartPoint(setting.SettingValue); } else if (setting.SettingKey == "SnapshotBatchSize") { try { m_snapshotCheckinBatchSize = int.Parse(setting.SettingValue); } catch (Exception) { // wrong format, use the default batch size } } } m_hwmDelta.Reload(); if (m_hwmDelta.Value >= m_sessionLevelSnapshotChangeset) { // We've already passed snapshot changeset Id, just return. m_sessionlevelSnapshotCompleted = true; return; } VersionSpec snapshotVersionSpec = new ChangesetVersionSpec(m_sessionLevelSnapshotChangeset); List <string> pathsToGet = new List <string>(); foreach (MappingEntry mappingEntry in ConfigurationService.Filters) { if (mappingEntry.Cloak) { continue; } // Always query at one level down the mapping ItemSet itemSet = m_tfsClient.GetItems(mappingEntry.Path, snapshotVersionSpec, RecursionType.OneLevel); Item[] items = itemSet.Items; foreach (Item childItem in items) { // Avoid the item itself. if (!VersionControlPath.Equals(childItem.ServerItem, mappingEntry.Path)) { pathsToGet.Add(childItem.ServerItem); } } } int countDownToCreateNewChangeGroup = m_snapshotCheckinBatchSize; int batchExecutionOrder = m_sessionLevelSnapshotChangeset; ChangeGroup batchGroup = createChangeGroupForSnapshot(m_sessionLevelSnapshotChangeset, batchExecutionOrder); foreach (string path in pathsToGet) { TraceManager.TraceInformation("Getting snapshot at changeset: {0}, path: {1}", m_sessionLevelSnapshotChangeset, path); ItemSet itemSet = m_tfsClient.GetItems(path, snapshotVersionSpec, RecursionType.Full); Item[] items = itemSet.Items; itemSet = null; TraceManager.TraceInformation("Snapshot contains {0} items", items.Length); for (int i = 0; i < items.Length; i++) { // We want to include the situation where a snapshot on a path is the same as the snapshot of the VC session. // In this situation, we want to include the item in the session snapshot changeset. // So we use changesetId + 1 as the reference changeset id. if (IsPathMapped(items[i].ServerItem, m_sessionLevelSnapshotChangeset + 1) == MappingResult.Mapped) { countDownToCreateNewChangeGroup--; if (countDownToCreateNewChangeGroup == 0) { TraceManager.TraceInformation("Saving {0} change actions", m_snapshotCheckinBatchSize); batchGroup.Save(); batchGroup.Actions.Clear(); batchGroup = null; batchExecutionOrder--; batchGroup = createChangeGroupForSnapshot(m_sessionLevelSnapshotChangeset, batchExecutionOrder); countDownToCreateNewChangeGroup = m_snapshotCheckinBatchSize; TraceManager.TraceInformation("Saved {0} change actions", m_snapshotCheckinBatchSize); } batchGroup.CreateAction( WellKnownChangeActionId.Add, new TfsMigrationItem(items[i]), null, items[i].ServerItem, null, null, TfsAnalysisAlgorithms.convertContentType(items[i].ItemType), null); } items[i] = null; // Dispose this object to reduce memory consumption. } } if (batchGroup.Actions.Count > 0) { int numRemainingItems = batchGroup.Actions.Count; TraceManager.TraceInformation("Saving {0} change actions", numRemainingItems); batchGroup.Save(); TraceManager.TraceInformation("Saved {0} change actions", numRemainingItems); } m_hwmDelta.Update(m_sessionLevelSnapshotChangeset); m_changeGroupService.PromoteDeltaToPending(); m_sessionlevelSnapshotCompleted = true; }