Example #1
0
        public async Task <QuickTaskList> Add(QuickTaskList taskList)
        {
            var response = await _httpClient.PostAsJsonAsync("task-lists", taskList);

            var content = await response.Content.ReadAsStringAsync();

            return(JsonSerializer.Deserialize <QuickTaskList>(content, new JsonSerializerOptions {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            }));
        }
        public static void Run(
            [SignalRTrigger(Constants.SignalRTasksHubName, "messages", GetSingleTaskListMessage.MethodName, ConnectionStringSetting = Constants.SignalRConnectionStringSetting)] InvocationContext invocationContext,
            [SignalRParameter] GetSingleTaskListMessage argument,
            [CosmosDB(Constants.CosmosDbDatabase, Constants.CosmosDbTasksCollection, Id = "{argument.Id}", PartitionKey = "{argument.Id}", ConnectionStringSetting = Constants.CosmosDbConnectionStringSetting)] QuickTaskList taskList,
            [SignalR(HubName = Constants.SignalRTasksHubName, ConnectionStringSetting = Constants.SignalRConnectionStringSetting)] IAsyncCollector <SignalRMessage> signalRMessages,
            [SignalR(HubName = Constants.SignalRTasksHubName, ConnectionStringSetting = Constants.SignalRConnectionStringSetting)] IAsyncCollector <SignalRGroupAction> signalRGroupActions,
            ILogger log)
        {
            if (taskList == null)
            {
                log.LogWarning($"Could not find tasklist: {argument.Id}");
                // TODO: Send message when no tasklist is found
                return;
            }

            signalRMessages.AddAsync(new SignalRMessage
            {
                ConnectionId = invocationContext.ConnectionId,
                Target       = GotSingleTaskListMessage.MethodName,
                Arguments    = new [] { new GotSingleTaskListMessage(taskList) }
            });

            log.LogInformation($"User {invocationContext.UserId} is added to group. ");

            signalRGroupActions.AddAsync(new SignalRGroupAction
            {
                UserId    = invocationContext.UserId,
                GroupName = taskList.Id,
                Action    = GroupAction.Add
            });


            // Console.WriteLine("Found one!");

            // // var userIdClaim = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier);
            // // signalRGroupActions.AddAsync(new SignalRGroupAction
            // // {
            // //     UserId = userIdClaim.Value,
            // //     GroupName = id,
            // //     Action = GroupAction.Add
            // // });


            // return new OkObjectResult(taskList);
        }
Example #3
0
 public GotSingleTaskListMessage(QuickTaskList taskList)
 {
     TaskList = taskList;
 }