Skip to content

Commit

Permalink
added polling events
Browse files Browse the repository at this point in the history
  • Loading branch information
bZverok committed Jun 12, 2024
1 parent 5256ae5 commit 5dcc23e
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Apps.Memoq/Apps.MemoQ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<Nullable>enable</Nullable>
<Product>memoQ</Product>
<Description>Computer-assisted translation</Description>
<Version>1.1.12</Version>
<Version>1.2.0</Version>
<AssemblyName>Apps.MemoQ</AssemblyName>
<LangVersion>12</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Blackbird.Applications.Sdk.Common" Version="2.6.0" />
<PackageReference Include="Blackbird.Applications.Sdk.Common" Version="2.8.0" />
<PackageReference Include="Blackbird.Applications.SDK.Extensions.FileManagement" Version="1.0.1" />
<PackageReference Include="Blackbird.Applications.Sdk.Glossaries.Utils" Version="1.0.0-alpha11" />
<PackageReference Include="Blackbird.Applications.Sdk.Utils" Version="1.0.24" />
Expand Down
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",
};
}
}
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; }
}
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; }
}
129 changes: 129 additions & 0 deletions Apps.Memoq/Events/Polling/PollingList.cs
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));
}
8 changes: 8 additions & 0 deletions Apps.Memoq/Models/Dto/ProjectDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ public class ProjectDto
public string? Domain { get; set; }

public string? Subject { get; set; }

public string Status { get; set; }

public DateTime Deadline { get; set; }

[Display("Last time changed")]
public DateTime LastChanged { get; set; }

[Display("Created at")]
public DateTime CreatedAt { get; set; }

[Display("Source language code")]
public string SourceLanguageCode { get; set; }

Expand All @@ -40,5 +45,8 @@ public ProjectDto(ServerProjectInfo project)
LastChanged = project.LastChanged;
SourceLanguageCode = project.SourceLanguageCode;
TargetLanguageCodes = project.TargetLanguageCodes.ToList();
TargetLanguageCodes = project.TargetLanguageCodes.ToList();
CreatedAt = project.CreationTime;
Status = project.ProjectStatus.ToString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Apps.Memoq.Models.ServerProjects.Requests;

public class ProjectRequest
{
[Display("Project")]
[Display("Project ID")]
[DataSource(typeof(ProjectDataHandler))]
public string ProjectGuid { get; set; }
}
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; }
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ Another important consideration is that our glossaries implementation adheres to
## Events

- **On document delivered** is triggered when any project document was delivered.
- **On project created** is triggered when a new project is created.
- **On project status changed** is triggered when status of a specific project has changed.

## Missing features

Expand Down

0 comments on commit 5dcc23e

Please sign in to comment.