Skip to content

Commit

Permalink
Update to now use values from TfsAttachmentEnricherOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHinsh committed Mar 25, 2024
1 parent 87a3fbf commit 1cb01e5
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ namespace MigrationTools.ProcessorEnrichers
public class TfsAttachmentEnricher : WorkItemProcessorEnricher, IAttachmentMigrationEnricher
{
private WorkItemServer _server;
private string _exportBasePath;
private string _exportWiPath;
private int _maxAttachmentSize;
private TfsAttachmentEnricherOptions _options;
private WorkItemServer _workItemServer;

public TfsAttachmentEnricherOptions Options { get { return _options; } }

public TfsAttachmentEnricher(IServiceProvider services, ILogger<WorkItemProcessorEnricher> logger) : base(services, logger)
{

}

public void ProcessAttachemnts(WorkItemData source, WorkItemData target, bool save = true)
Expand All @@ -46,7 +44,7 @@ public void ProcessAttachemnts(WorkItemData source, WorkItemData target, bool sa
throw new ArgumentNullException(nameof(target));
}
Log.LogInformation("AttachmentMigrationEnricher: Migrating {AttachmentCount} attachemnts from {SourceWorkItemID} to {TargetWorkItemID}", source.ToWorkItem().Attachments.Count, source.Id, target.Id);
_exportWiPath = Path.Combine(_exportBasePath, source.ToWorkItem().Id.ToString());
_exportWiPath = Path.Combine(Options.ExportBasePath, source.ToWorkItem().Id.ToString());
if (Directory.Exists(_exportWiPath))
{
Directory.Delete(_exportWiPath, true);
Expand Down Expand Up @@ -139,7 +137,7 @@ private void ImportAttachment(WorkItem targetWorkItem, Attachment wia, string fi
SetupWorkItemServer();
var filename = Path.GetFileName(filepath);
FileInfo fi = new FileInfo(filepath);
if (_maxAttachmentSize > fi.Length)
if (Options.MaxAttachmentSize > fi.Length)
{
string originalId = "[originalId:" + wia.Id + "]";
var attachments = targetWorkItem.Attachments.Cast<Attachment>();
Expand Down Expand Up @@ -169,7 +167,7 @@ private void ImportAttachment(WorkItem targetWorkItem, Attachment wia, string fi
}
else
{
Log.LogWarning(" [SKIP] Attachment {filename} on Work Item {targetWorkItemId} is bigger than the limit of {maxAttachmentSize} bites for Azure DevOps.", filename, targetWorkItem.Id, _maxAttachmentSize);
Log.LogWarning(" [SKIP] Attachment {filename} on Work Item {targetWorkItemId} is bigger than the limit of {maxAttachmentSize} bites for Azure DevOps.", filename, targetWorkItem.Id, Options.MaxAttachmentSize);
}
}

Expand Down

0 comments on commit 1cb01e5

Please sign in to comment.