feat: finish porting azure function to .NET 5

This commit is contained in:
2021-07-22 10:42:01 -04:00
parent da7f2f2709
commit dcb0d8ccc2
15 changed files with 159 additions and 155 deletions

View File

@@ -6,8 +6,6 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Habittodo.Data\Habittodo.Data.csproj" />
<ProjectReference Include="..\Habittodo.Model\Habittodo.Model.csproj" />
<ProjectReference Include="..\Habittodo.Service\Habittodo.Service.csproj" />
</ItemGroup>
@@ -16,4 +14,10 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<None Update="secrets.json.sample">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@@ -1,9 +1,6 @@
using Habittodo.Data;
using Habittodo.Model.Storage;
using Habittodo.Service;
using Habittodo.Service;
using Microsoft.Extensions.Configuration;
using System.IO;
using System.Linq;
namespace Habitica.Todoist.Integration.Console
{
@@ -21,25 +18,26 @@ namespace Habitica.Todoist.Integration.Console
{
ConfigBuild();
// initialize all the clients
var habiticaClient = new HabiticaServiceClient(habiticaUserId, habiticaApiKey);
var todoistClient = new TodoistServiceClient(todoistApiKey);
var tableStorageClient = new TableStorageClient(tableStorageConnectionString);
// get todoist sync token if available
var syncToken = "";
try { syncToken = tableStorageClient.Query<TodoistSync>().Where(x => x.PartitionKey == giosUserId).ToList()
.OrderByDescending(x => x.Timestamp).First().RowKey; } catch { }
// initialize integration services
var todoistService = new TodoistIntegrationService(todoistApiKey,
tableStorageConnectionString,
giosUserId);
var habiticaService = new HabiticaIntegrationService(habiticaUserId,
habiticaApiKey,
tableStorageConnectionString,
giosUserId);
// get all changed items from todoist
var response = todoistClient.GetItemChanges(syncToken).ConfigureAwait(false).GetAwaiter().GetResult();
var changedItems = response.Items;
var items = todoistService.ReadItemChanges().GetAwaiter().GetResult();
/* TESTING */
// store sync token
var todoistSync = new TodoistSync(giosUserId, response.Sync_token);
tableStorageClient.InsertOrUpdate(todoistSync).ConfigureAwait(false).GetAwaiter().GetResult();
// perform actions
habiticaService.Add(items.WhereAdded()).GetAwaiter().GetResult();
habiticaService.Update(items.WhereUpdated()).GetAwaiter().GetResult();
habiticaService.Complete(items.WhereCompleted()).GetAwaiter().GetResult();
habiticaService.Delete(items.WhereDeleted()).GetAwaiter().GetResult();
// commit read changes
todoistService.CommitRead().GetAwaiter().GetResult();
}
static void ConfigBuild()

View File

@@ -0,0 +1,12 @@
{
"habitica": {
"userId": "4ef54610-742d-4503-ba88-faa5d820287c",
"apiKey": "d1446942-cc77-4aa7-aec9-adfda9f901b2"
},
"todoist": {
"apiKey": "8ff2969e-84d0-4014-9d48-f96c2587fedf"
},
"tableStorage": {
"connectionString": "your-azure-table-storage-connection-string-here"
}
}