Skip to content

Commit

Permalink
Update attachement migrator
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHinsh committed Mar 5, 2024
1 parent c87dc10 commit efe901b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
6 changes: 6 additions & 0 deletions configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
"ReplayRevisions": true,
"MaxRevisions": 0
},
{
"$type": "TfsAttachmentEnricherOptions",
"Enabled": true,
"ExportBasePath": "c:\\temp\\WorkItemAttachmentExport",
"MaxRevisions": 480000000
},
{
"$type": "StringManipulatorEnricherOptions",
"Enabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public class TfsAttachmentEnricherOptions : ProcessorEnricherOptions, ITfsAttach
/// For Azure DevOps Services the default is 480,000,000 bites (60mb), for TFS its 32,000,000 bites (4mb).
/// </summary>
/// <default>480000000</default>
public string MaxAttachmentSize { get; set; }
public int MaxAttachmentSize { get; set; }

public override void SetDefaults()
{
Enabled = true;
ExportBasePath = @"c:\temp\WorkItemAttachmentExport";
MaxAttachmentSize = "480000000";
MaxAttachmentSize = 480000000;
}

static public TfsAttachmentEnricherOptions GetDefaults()
Expand All @@ -42,7 +42,7 @@ static public TfsAttachmentEnricherOptions GetDefaults()
public interface ITfsAttachmentEnricherOptions
{
public string ExportBasePath { get; set; }
public string MaxAttachmentSize { get; set; }
public int MaxAttachmentSize { get; set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static void AddMigrationToolServicesForClientAzureDevOpsObjectModel(this
context.AddTransient<TfsAreaAndIterationProcessor>();

// Enrichers
context.AddSingleton<TfsAttachmentEnricher>();
context.AddSingleton<TfsValidateRequiredField>();
context.AddSingleton<TfsWorkItemLinkEnricher>();
context.AddSingleton<TfsWorkItemEmbededLinkEnricher>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected void PullCommonEnrichersConfig<TEnricher, TEnricherOptions> (List<IPro
var result = new TEnricherOptions();
result.SetDefaults();
commonEnricher.Configure(result);
Log.LogWarning("Using `{TEnricherOptions}` with Defaults... add a `{TEnricherOptions}` entry to `CommonEnrichersConfig` to customise the settings.", typeof(TEnricherOptions).Name);
Log.LogInformation("Using `{TEnricherOptions}` with Defaults... add a `{TEnricherOptions}` entry to `CommonEnrichersConfig` to customise the settings.", typeof(TEnricherOptions).Name);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class WorkItemMigrationContext : MigrationProcessorBase
private List<string> _ignore;

private ILogger contextLog;
private TfsAttachmentEnricher attachmentEnricher;
private TfsAttachmentEnricher _attachmentEnricher;
private IWorkItemProcessorEnricher embededImagesEnricher;
private IWorkItemProcessorEnricher _workItemEmbededLinkEnricher;
private StringManipulatorEnricher _stringManipulatorEnricher;
Expand All @@ -80,6 +80,7 @@ public WorkItemMigrationContext(IMigrationEngine engine,
IServiceProvider services,
ITelemetryLogger telemetry,
ILogger<WorkItemMigrationContext> logger,
TfsAttachmentEnricher attachmentEnricher,
TfsNodeStructure nodeStructureEnricher,
TfsRevisionManager revisionManager,
TfsWorkItemLinkEnricher workItemLinkEnricher,
Expand All @@ -92,6 +93,7 @@ public WorkItemMigrationContext(IMigrationEngine engine,
_telemetry = telemetry;
_engineConfig = engineConfig.Value;
contextLog = Serilog.Log.ForContext<WorkItemMigrationContext>();
_attachmentEnricher = attachmentEnricher;
_nodeStructureEnricher = nodeStructureEnricher;
_revisionManager = revisionManager;
_workItemLinkEnricher = workItemLinkEnricher;
Expand Down Expand Up @@ -121,7 +123,7 @@ private void ImportCommonEnricherConfigs()
PullCommonEnrichersConfig<TfsRevisionManager, TfsRevisionManagerOptions>(_engineConfig.CommonEnrichersConfig, _revisionManager);
PullCommonEnrichersConfig<TfsWorkItemLinkEnricher, TfsWorkItemLinkEnricherOptions>(_engineConfig.CommonEnrichersConfig, _workItemLinkEnricher);
PullCommonEnrichersConfig<StringManipulatorEnricher, StringManipulatorEnricherOptions>(_engineConfig.CommonEnrichersConfig, _stringManipulatorEnricher);
PullCommonEnrichersConfig<TfsAttachmentEnricher, TfsAttachmentEnricherOptions>(_engineConfig.CommonEnrichersConfig, attachmentEnricher);
PullCommonEnrichersConfig<TfsAttachmentEnricher, TfsAttachmentEnricherOptions>(_engineConfig.CommonEnrichersConfig, _attachmentEnricher);
}

internal void TraceWriteLine(LogEventLevel level, string message, Dictionary<string, object> properties = null)
Expand Down Expand Up @@ -673,10 +675,10 @@ private async Task ProcessWorkItemAsync(WorkItemData sourceWorkItem, int retryLi

private void ProcessWorkItemAttachments(WorkItemData sourceWorkItem, WorkItemData targetWorkItem, bool save = true)
{
if (targetWorkItem != null && attachmentEnricher.Options.Enabled && sourceWorkItem.ToWorkItem().Attachments.Count > 0)
if (targetWorkItem != null && _attachmentEnricher.Options.Enabled && sourceWorkItem.ToWorkItem().Attachments.Count > 0)
{
TraceWriteLine(LogEventLevel.Information, "Attachemnts {SourceWorkItemAttachmentCount} | LinkMigrator:{AttachmentMigration}", new Dictionary<string, object>() { { "SourceWorkItemAttachmentCount", sourceWorkItem.ToWorkItem().Attachments.Count }, { "AttachmentMigration", attachmentEnricher.Options.Enabled } });
attachmentEnricher.ProcessAttachemnts(sourceWorkItem, targetWorkItem, save);
TraceWriteLine(LogEventLevel.Information, "Attachemnts {SourceWorkItemAttachmentCount} | LinkMigrator:{AttachmentMigration}", new Dictionary<string, object>() { { "SourceWorkItemAttachmentCount", sourceWorkItem.ToWorkItem().Attachments.Count }, { "AttachmentMigration", _attachmentEnricher.Options.Enabled } });
_attachmentEnricher.ProcessAttachemnts(sourceWorkItem, targetWorkItem, save);
AddMetric("Attachments", processWorkItemMetrics, targetWorkItem.ToWorkItem().AttachedFileCount);
}
}
Expand Down Expand Up @@ -881,7 +883,7 @@ private WorkItemData ReplayRevisions(List<RevisionItem> revisionsToMigrate, Work
}
targetWorkItem.SaveToAzureDevOps();

attachmentEnricher.CleanUpAfterSave();
_attachmentEnricher.CleanUpAfterSave();
TraceWriteLine(LogEventLevel.Information, "...Saved as {TargetWorkItemId}", new Dictionary<string, object> { { "TargetWorkItemId", targetWorkItem.Id } });
}
}
Expand Down

0 comments on commit efe901b

Please sign in to comment.