-
Notifications
You must be signed in to change notification settings - Fork 1
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
9 changed files
with
173 additions
and
3 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
15 changes: 15 additions & 0 deletions
15
Apps.Memoq/DataSourceHandlers/EnumDataHandlers/ProjectStatusDataHandler.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,15 @@ | ||
using Blackbird.Applications.Sdk.Common.Dictionaries; | ||
|
||
namespace Apps.MemoQ.DataSourceHandlers.EnumDataHandlers; | ||
|
||
public class ProjectStatusDataHandler : IStaticDataSourceHandler | ||
{ | ||
public Dictionary<string, string> GetData() | ||
{ | ||
return new() | ||
{ | ||
["Live"] = "Live", | ||
["WrappedUp"] = "Wrapped up", | ||
}; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
Apps.Memoq/Events/Polling/Models/Memory/EntityChangedMemory.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,8 @@ | ||
namespace Apps.Memoq.Events.Polling.Models.Memory; | ||
|
||
public class EntityChangedMemory | ||
{ | ||
public string Status { get; set; } | ||
|
||
public DateTime LastModificationDate { get; set; } | ||
} |
6 changes: 6 additions & 0 deletions
6
Apps.Memoq/Events/Polling/Models/Memory/EntityCreatedMemory.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 Apps.Memoq.Events.Polling.Models.Memory; | ||
|
||
public class EntityCreatedMemory | ||
{ | ||
public DateTime LastCreationDate { get; set; } | ||
} |
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,129 @@ | ||
using Apps.Memoq.Contracts; | ||
using Apps.MemoQ.DataSourceHandlers.EnumDataHandlers; | ||
using Apps.Memoq.Events.Polling.Models.Memory; | ||
using Apps.Memoq.Models; | ||
using Apps.Memoq.Models.Dto; | ||
using Apps.Memoq.Models.ServerProjects.Requests; | ||
using Apps.Memoq.Models.ServerProjects.Responses; | ||
using Blackbird.Applications.Sdk.Common; | ||
using Blackbird.Applications.Sdk.Common.Dictionaries; | ||
using Blackbird.Applications.Sdk.Common.Invocation; | ||
using Blackbird.Applications.Sdk.Common.Polling; | ||
using MQS.ServerProject; | ||
|
||
namespace Apps.Memoq.Events.Polling; | ||
|
||
[PollingEventList] | ||
public class PollingList : BaseInvocable | ||
{ | ||
public PollingList(InvocationContext invocationContext) : base(invocationContext) | ||
{ | ||
} | ||
|
||
[PollingEvent("On project created", "On a new project created")] | ||
public async Task<PollingEventResponse<EntityCreatedMemory, ListAllProjectsResponse>> OnProjectCreated( | ||
PollingEventRequest<EntityCreatedMemory> request) | ||
{ | ||
if (request.Memory is null) | ||
{ | ||
return new() | ||
{ | ||
FlyBird = false, | ||
Memory = new() | ||
{ | ||
LastCreationDate = DateTime.UtcNow | ||
} | ||
}; | ||
} | ||
|
||
var projectService = new MemoqServiceFactory<IServerProjectService>( | ||
SoapConstants.ProjectServiceUrl, InvocationContext.AuthenticationCredentialsProviders); | ||
|
||
var items = | ||
(await ListProjects(projectService)) | ||
.Where(x => x.CreationTime > request.Memory.LastCreationDate) | ||
.ToArray(); | ||
|
||
if (!items.Any()) | ||
{ | ||
return new() | ||
{ | ||
FlyBird = false, | ||
Memory = new() | ||
{ | ||
LastCreationDate = DateTime.UtcNow | ||
} | ||
}; | ||
} | ||
|
||
return new() | ||
{ | ||
FlyBird = true, | ||
Result = new() | ||
{ | ||
ServerProjects = items.Select(x => new ProjectDto(x)).ToList() | ||
}, | ||
Memory = new() | ||
{ | ||
LastCreationDate = DateTime.UtcNow | ||
} | ||
}; | ||
} | ||
|
||
[PollingEvent("On project status changed", "On status of a specific project changed")] | ||
public async Task<PollingEventResponse<EntityChangedMemory, ProjectDto>> OnProjectStatusChanged( | ||
PollingEventRequest<EntityChangedMemory> request, | ||
[PollingEventParameter] ProjectRequest projectRequest, | ||
[PollingEventParameter] [Display("Project status")] [StaticDataSource(typeof(ProjectStatusDataHandler))] | ||
string? projectStatus) | ||
{ | ||
var projectService = new MemoqServiceFactory<IServerProjectService>( | ||
SoapConstants.ProjectServiceUrl, InvocationContext.AuthenticationCredentialsProviders); | ||
|
||
var project = new ProjectDto(await GetProject(projectService, projectRequest.ProjectGuid)); | ||
|
||
if (request.Memory is null) | ||
{ | ||
return new() | ||
{ | ||
FlyBird = false, | ||
Memory = new() | ||
{ | ||
Status = project.Status, | ||
LastModificationDate = DateTime.UtcNow | ||
} | ||
}; | ||
} | ||
|
||
if (project.Status == request.Memory.Status || | ||
(!string.IsNullOrEmpty(projectStatus) && project.Status != projectStatus)) | ||
{ | ||
return new() | ||
{ | ||
FlyBird = false, | ||
Memory = new() | ||
{ | ||
Status = project.Status, | ||
LastModificationDate = DateTime.UtcNow | ||
} | ||
}; | ||
} | ||
|
||
return new() | ||
{ | ||
FlyBird = true, | ||
Result = project, | ||
Memory = new() | ||
{ | ||
Status = project.Status, | ||
LastModificationDate = DateTime.UtcNow, | ||
} | ||
}; | ||
} | ||
|
||
private Task<ServerProjectInfo[]> ListProjects(MemoqServiceFactory<IServerProjectService> projectService) => | ||
projectService.Service.ListProjectsAsync(new()); | ||
|
||
private Task<ServerProjectInfo> GetProject(MemoqServiceFactory<IServerProjectService> projectService, | ||
string projectId) => projectService.Service.GetProjectAsync(Guid.Parse(projectId)); | ||
} |
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
2 changes: 2 additions & 0 deletions
2
Apps.Memoq/Models/ServerProjects/Responses/ListAllProjectsResponse.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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
using Apps.Memoq.Models.Dto; | ||
using Blackbird.Applications.Sdk.Common; | ||
|
||
namespace Apps.Memoq.Models.ServerProjects.Responses; | ||
|
||
public class ListAllProjectsResponse | ||
{ | ||
[Display("Projects")] | ||
public List<ProjectDto> ServerProjects { get; set; } | ||
} |
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