-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
176 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
az-appservice-dotnet/services/v1/ImageProcessing/IImageProcessorService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace az_appservice_dotnet.services.v1.ImageProcessing; | ||
|
||
public interface IImageProcessorService | ||
{ | ||
Task<string> ProcessImageAsync(string imageFilePath); | ||
} |
21 changes: 21 additions & 0 deletions
21
az-appservice-dotnet/services/v1/ImageProcessing/NullImageProcessorService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace az_appservice_dotnet.services.v1.ImageProcessing; | ||
|
||
public class NullImageProcessorService: IImageProcessorService | ||
{ | ||
public Task<string> ProcessImageAsync(string imageFilePath) | ||
{ | ||
if (!File.Exists(imageFilePath)) | ||
{ | ||
throw new FileNotFoundException($"NullImageProcessorService: File not found: {imageFilePath}"); | ||
} | ||
|
||
return Task.Run(() => | ||
{ | ||
// get tmp file path | ||
var tmpFilePath = Path.GetTempFileName(); | ||
// copy imageFilePath to tmpFilePath | ||
File.Copy(imageFilePath, tmpFilePath, true); | ||
return tmpFilePath; | ||
}); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
az-appservice-dotnet/services/v1/Monitor/ConsoleMonitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using az_appservice_dotnet.services.v1.State; | ||
|
||
namespace az_appservice_dotnet.services.v1.Monitor; | ||
|
||
public class ConsoleMonitor: IStateMonitor | ||
{ | ||
private readonly IProcessingStateService _processingStateService; | ||
|
||
public ConsoleMonitor(IProcessingStateService processingStateService) | ||
{ | ||
_processingStateService = processingStateService; | ||
} | ||
|
||
public void StartStateMonitor() | ||
{ | ||
_processingStateService.ListenToStateChanges(state => | ||
{ | ||
Console.WriteLine($"State changed to {state.Status}: file={state.FileName}, originalUrl={state.OriginalFileUrl}, processedUrl={state.ProcessedFileUrl}"); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace az_appservice_dotnet.services.v1.Monitor; | ||
|
||
public interface IStateMonitor | ||
{ | ||
void StartStateMonitor(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using az_appservice_dotnet.services.v1.Blob; | ||
using az_appservice_dotnet.services.v1.ImageProcessing; | ||
using az_appservice_dotnet.services.v1.State; | ||
|
||
namespace az_appservice_dotnet.services.v1; | ||
|
||
public class ProcessorService | ||
{ | ||
private IBlobService _blobService; | ||
private IProcessingStateService _processingStateService; | ||
private IImageProcessorService _imageProcessorService; | ||
|
||
public ProcessorService(IBlobService blobService, IProcessingStateService processingStateService, | ||
IImageProcessorService imageProcessorService) | ||
{ | ||
_imageProcessorService = imageProcessorService; | ||
_blobService = blobService; | ||
_processingStateService = processingStateService; | ||
} | ||
|
||
public void StartWaitForImagesToProcess() | ||
{ | ||
_processingStateService.ListenToStateChanges(async state => | ||
{ | ||
if (state.Status == IProcessingStateService.Status.WaitingForProcessing) | ||
{ | ||
Console.WriteLine(state.OriginalFileUrl); | ||
var tmpFilePath = Path.GetTempFileName(); | ||
var stateProcessing = await _processingStateService.MoveToProcessingStateAsync(state); | ||
try | ||
{ | ||
var ok = await _blobService.DownloadBlobAsync(state.FileName, tmpFilePath); | ||
var processedFilePath = await _imageProcessorService.ProcessImageAsync(tmpFilePath); | ||
var uploadedUri = | ||
await _blobService.UploadBlobAsync($"processed-{state.FileName}", processedFilePath); | ||
await _processingStateService.MoveToCompletedStateAsync(stateProcessing, uploadedUri.ToString()); | ||
} | ||
catch (Exception e) | ||
{ | ||
await _processingStateService.MoveToFailedStateAsync(stateProcessing, e.Message); | ||
Console.WriteLine(e); | ||
throw; | ||
} | ||
finally | ||
{ | ||
if (File.Exists(tmpFilePath)) | ||
{ | ||
File.Delete(tmpFilePath); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters