Skip to content

Commit

Permalink
Added Paratext Registration Info form (#1260)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjcouch-sil authored Nov 6, 2024
2 parents 10ab2bd + 61dd887 commit 63002a6
Show file tree
Hide file tree
Showing 65 changed files with 28,704 additions and 156 deletions.
1 change: 1 addition & 0 deletions assets/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"%about_versionLabel_format%": "Version: {version}",
"%about_licenseLabel_format%": "License: {license}",
"%insertNote%": "Insert Note",
"%general_error_title%": "Error",
"%mainMenu_about%": "About Platform.Bible",
"%mainMenu_downloadSlashInstallResources%": "Download/Install Resources",
"%mainMenu_downloadSlashUpdateProject%": "Download/Update Project",
Expand Down
93 changes: 93 additions & 0 deletions c-sharp/JsonUtils/RegistrationDataConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Paratext.Data.Users;

namespace Paranext.DataProvider.JsonUtils;

public class RegistrationDataConverter : JsonConverter<RegistrationData>
{
private const string NAME = "name";
private const string CODE = "code";
private const string EMAIL = "email";
private const string SUPPORTER_NAME = "supporterName";

public override RegistrationData Read(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options
)
{
string name = "";
string code = "";
string email = "";
string supporterName = "";

string? lastPropertyName = null;
// The starting token is consumed before we get the reader
int onObjectLevel = 1;
while (onObjectLevel > 0 && reader.Read())
{
switch (reader.TokenType)
{
case JsonTokenType.StartObject:
case JsonTokenType.StartArray:
onObjectLevel++;
break;
case JsonTokenType.EndObject:
case JsonTokenType.EndArray:
onObjectLevel--;
break;
case JsonTokenType.PropertyName:
lastPropertyName = reader.GetString();
break;
case JsonTokenType.True:
case JsonTokenType.False:
lastPropertyName = null;
break;
case JsonTokenType.Number:
lastPropertyName = null;
break;
case JsonTokenType.String:
switch (lastPropertyName)
{
case NAME:
name = reader.GetString() ?? "";
break;
case CODE:
code = reader.GetString() ?? "";
break;
case EMAIL:
email = reader.GetString() ?? "";
break;
case SUPPORTER_NAME:
supporterName = reader.GetString() ?? "";
break;
}
lastPropertyName = null;
break;
}
}

return new RegistrationData
{
Name = name,
Code = code,
Email = email,
SupporterName = supporterName,
};
}

public override void Write(
Utf8JsonWriter writer,
RegistrationData value,
JsonSerializerOptions options
)
{
writer.WriteStartObject();
writer.WriteString(NAME, value.Name);
writer.WriteString(CODE, value.Code);
writer.WriteString(EMAIL, value.Email);
writer.WriteString(SUPPORTER_NAME, value.SupporterName);
writer.WriteEndObject();
}
}
1 change: 1 addition & 0 deletions c-sharp/JsonUtils/SerializationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static JsonSerializerOptions CreateSerializationOptions()
};
options.Converters.Add(new CommentConverter());
options.Converters.Add(new VerseRefConverter());
options.Converters.Add(new RegistrationDataConverter());
return options;
}

Expand Down
25 changes: 24 additions & 1 deletion c-sharp/PapiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ await _webSocket.CloseAsync(
}

/// <summary>
/// Send a request to the server
/// Send a request to the server expecting a returned value
/// </summary>
/// <param name="requestType">Type of request intended for the server</param>
/// <param name="requestContents">Objects to send as parameters to the request</param>
/// <returns>The request response's resulting value</returns>
public virtual async Task<T?> SendRequestAsync<T>(
string requestType,
IReadOnlyList<object?>? requestContents
Expand All @@ -164,6 +165,28 @@ await _webSocket.CloseAsync(
);
}

/// <summary>
/// Send a request to the server expecting no returned value (as if the request is pointing to a void method)
/// </summary>
/// <param name="requestType">Type of request intended for the server</param>
/// <param name="requestContents">Objects to send as parameters to the request</param>
public virtual async Task SendRequestAsync(
string requestType,
IReadOnlyList<object?>? requestContents
)
{
ObjectDisposedException.ThrowIf(_isDisposed, this);

if (_localMethods.TryGetValue(requestType, out Delegate? handler) && handler != null)
handler.DynamicInvoke(requestContents?.ToArray());
else
await _jsonRpc.InvokeWithCancellationAsync(
requestType,
requestContents,
_cancellationToken
);
}

/// <summary>
/// Register a request handler with the server.
/// </summary>
Expand Down
5 changes: 4 additions & 1 deletion c-sharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Paranext.DataProvider.NetworkObjects;
using Paranext.DataProvider.Projects;
using Paranext.DataProvider.Services;
using Paranext.DataProvider.Users;
using Paratext.Data;
using PtxUtils;

Expand Down Expand Up @@ -31,9 +32,11 @@ public static async Task Main()

var paratextFactory = new ParatextProjectDataProviderFactory(papi, paratextProjects);
var checkRunner = new CheckRunner(papi);
var paratextRegistrationService = new ParatextRegistrationService(papi);
await Task.WhenAll(
paratextFactory.InitializeAsync(),
checkRunner.RegisterDataProviderAsync()
checkRunner.RegisterDataProviderAsync(),
paratextRegistrationService.InitializeAsync()
);

// Things that only run in our "noisy dev mode" go here
Expand Down
Loading

0 comments on commit 63002a6

Please sign in to comment.