public static async Task <IActionResult> CreateCampaign( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "campaigns/create")] HttpRequest req, [CosmosDB(databaseName: "campaigns", collectionName: "campaigns", ConnectionStringSetting = "CosmosDBConnection", CreateIfNotExists = true)] IAsyncCollector <RemoteCampaign> createdCampaigns, ILogger logger) { string name = req.Query["name"]; if (name == null) { return(new BadRequestObjectResult("Must include a name for the campaign")); } var id = Guid.NewGuid(); var document = new RemoteCampaign { id = id, Part = id.ToString()[0].ToString(), Name = name, Secret = Guid.NewGuid() }; logger.LogInformation($"Creating campaign {document.Name} at {document.id}"); await createdCampaigns.AddAsync(document); return(new OkObjectResult(document)); }
public ConnectCampaignRequestViewModel(RemoteCampaign campaign) { Campaign = campaign ?? throw new ArgumentNullException(nameof(campaign)); JoinCommand = new RelayCommand(() => { MessengerInstance.Send(new JoinConnectCampaignMessage(Campaign)); IsOpen = false; }); }
private async void OnJoin() { this.cancelSource?.Cancel(); this.cancelSource = new CancellationTokenSource(20000); IsBusy = true; try { RemoteCampaign campaign = await this.liveClient.GetCampaignDetailsAsync(Input, this.cancelSource.Token); MessengerInstance.Send(new JoinCampaignMessage(campaign)); } catch (OperationCanceledException) { } finally { IsBusy = false; } }
public StartGameResult StartGame( [SignalRTrigger] InvocationContext context, [SignalRParameter] StartGameMessage message, [CosmosDB("campaigns", "campaigns", ConnectionStringSetting = "CosmosDBConnection", Id = "{message.CampaignId}")] RemoteCampaign campaign, ILogger logger) { if (campaign == null) { return(StartGameResult.CampaignNotFound); } logger.LogInformation($"{context.ConnectionId}:{context.UserId} attempting to start game {message.CampaignId}"); if (message.CampaignSecret != campaign?.Secret.ToString()) { return(StartGameResult.Unauthorized); } logger.LogInformation($"{context.ConnectionId}:{context.UserId} authorized to start game {message.CampaignId}"); context.Claims.Add(OwnerClaim, "true"); return(StartGameResult.Success); }
internal async Task <CampaignElement> CreateCampaignAsync(RemoteCampaign campaign) { CampaignElement c = Elements.FirstOrDefault(e => e.Id == campaign.id.ToString()); if (c != null) { return(c); } c = new CampaignElement { Id = campaign.id.ToString(), IsRemote = true, Name = campaign.Name, Secret = campaign.Secret, }; await SyncService.SaveElementAsync(c); NotifyAddElement(c); return(c); }
public ConnectCampaignMessage(RemoteCampaign campaign) : base(campaign) { }
public JoinCampaignMessage(RemoteCampaign campaign) : base(campaign) { }
public RemoteCampaignMessage(RemoteCampaign campaign) { Campaign = campaign ?? throw new ArgumentNullException(nameof(campaign)); }