private static async void SendDeviceToCloudMessagesAsync() { double min = 600; Random rand = new Random(); Console.WriteLine("How many messages you want to send ? (ex : enter 1 to send single msg)"); var times = Convert.ToInt32(Console.ReadLine()); if (times == 0) { times = 1; } var count = 0; while (count < times) { Console.ForegroundColor = ConsoleColor.Red; var registerDevice = new RegisterDeviceCommand(); var messageString = JsonConvert.SerializeObject(registerDevice); var message = new Message(Encoding.ASCII.GetBytes(messageString)); await _deviceClient.SendEventAsync(message); Console.WriteLine("{0} > Sending message: {1}", DateTime.Now, messageString); count++; } Console.ResetColor(); Console.WriteLine("\nEnter to continue........"); }
public void RegisterForRemoteNotifications() { if (this.notificationManager == null) { return; } this.notificationManager.RegisterForRemoteNotifications(); string deviceToken = this.notificationManager.GetDeviceToken(); if (!string.IsNullOrEmpty(deviceToken)) { RegisterDeviceRequest registerDeviceRequest = new RegisterDeviceRequest(); registerDeviceRequest.DeviceToken = deviceToken; CurrentPlayer currentPlayer = Service.Get <CurrentPlayer>(); if (currentPlayer == null) { Service.Get <StaRTSLogger>().Warn("Trying to register for remote notification before CurrentPlayer is available"); return; } registerDeviceRequest.PlayerId = currentPlayer.PlayerId; RegisterDeviceCommand registerDeviceCommand = new RegisterDeviceCommand(registerDeviceRequest); registerDeviceCommand.AddSuccessCallback(new AbstractCommand <RegisterDeviceRequest, RegisterDeviceResponse> .OnSuccessCallback(this.OnRegisterSuccess)); if (!Service.Get <ServerAPI>().Enabled&& Service.Get <CurrentPlayer>().CampaignProgress.FueInProgress) { Service.Get <ServerAPI>().Enabled = true; } Service.Get <ServerAPI>().Sync(registerDeviceCommand); Service.Get <BILoggingController>().TrackNetworkMappingInfo("ur", deviceToken); } }
public void RegisterForRemoteNotifications() { if (this.notificationManager == null) { return; } this.notificationManager.RegisterForRemoteNotifications(); string deviceToken = this.notificationManager.GetDeviceToken(); RegisterDeviceRequest registerDeviceRequest = new RegisterDeviceRequest(); registerDeviceRequest.DeviceToken = deviceToken; CurrentPlayer currentPlayer = Service.CurrentPlayer; if (currentPlayer == null) { Service.Logger.Warn("Trying to register for remote notification before CurrentPlayer is available"); return; } registerDeviceRequest.PlayerId = currentPlayer.PlayerId; RegisterDeviceCommand registerDeviceCommand = new RegisterDeviceCommand(registerDeviceRequest); registerDeviceCommand.AddSuccessCallback(new AbstractCommand <RegisterDeviceRequest, RegisterDeviceResponse> .OnSuccessCallback(this.OnRegisterSuccess)); if (!Service.ServerAPI.Enabled && Service.CurrentPlayer.CampaignProgress.FueInProgress) { Service.ServerAPI.Enabled = true; } Service.ServerAPI.Sync(registerDeviceCommand); }
public ActionResult Register(RegisterDeviceCommand command) { var result = new RegisterDevicesResult(); var commandResult = commandBus.Send(command); return(new JsonResult() { Data = result.Create(commandResult.Values) }); }
public static async Task <HttpResponseMessage> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "PUT", Route = null)] HttpRequestMessage req, TraceWriter log) { if (req.Headers.Authorization == null || !req.Headers.Authorization.Scheme.Equals("BetaKey", StringComparison.OrdinalIgnoreCase) || !req.Headers.Authorization.Parameter.Equals(Config.Instance.BetaKey)) { return(req.CreateResponse(HttpStatusCode.Unauthorized, "BetaKey authorization required")); } var body = await req.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(body)) { return(req.CreateResponse(HttpStatusCode.BadRequest, "Id is required")); } HttpResponseMessage errorResponse = null; var registration = JsonConvert.DeserializeObject <DeviceRegistrationRequest>(await req.Content.ReadAsStringAsync(), new JsonSerializerSettings { Error = (obj, args) => { errorResponse = req.CreateResponse(HttpStatusCode.BadRequest, args.ErrorContext.Error.Message); args.ErrorContext.Handled = true; } }); if (errorResponse != null) { return(errorResponse); } if (registration?.DeviceId == null || registration?.DeviceId == Guid.Empty) { log.Error("Invalid Request - Id is required."); return(req.CreateResponse(HttpStatusCode.BadRequest, "Id is required")); } log.Info($"Put Device - {registration.DeviceId.Value}"); var command = new RegisterDeviceCommand(registration.DeviceId.Value, ConnectionFactory.Instance.DeviceRegistration, ConnectionFactory.Instance.IoTHubClient); var result = await command.ExecuteAsync(); return(req.CreateResponse(HttpStatusCode.OK, new DeviceRegistrationResponse { RegistrationCode = result.RegistrationCode })); }
public async Task <IActionResult> Register([FromBody] RegisterDeviceCommand registerDeviceCommand) { _logger.LogInformation("Registering new device", registerDeviceCommand); var success = await _mediator.Send(registerDeviceCommand); if (!success) { return(BadRequest()); } return(Ok()); }
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) { var token = deviceToken.Description.Trim('<', '>').Replace(" ", ""); if (token != Config.DeviceToken) { Config.DeviceToken = token; var cmd = new RegisterDeviceCommand { DeviceToken = token, User = Config.Person }; Task.Run(() => ResilientCall.ExecuteWithRetry(() => _azureIoTHub.InvokeMethod("RegisterAppForPushNotifications", JsonConvert.SerializeObject(cmd)))); } }
public async Task RegisterDevice_Call() { //-------------- Arrange ------------- CommonArrangements(); var request = new RegisterDeviceRequest(); var command = new RegisterDeviceCommand(); A.CallTo(() => mapper.Map <RegisterDeviceRequest, RegisterDeviceCommand>(request)).Returns(command); //-------------- Act ------------- var resp = deviceService.RegisterDeviceAsync(request); //-------------- Assert ------------- A.CallTo(() => bus.SendAsync(command)).MustHaveHappened(Repeated.Exactly.Once); }
public async Task <IActionResult> Create([FromBody] RegisterDeviceCommand command) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var deviceId = await _mediator.Send(command); //We can replace this with CreatedAtAction as well return(StatusCode(StatusCodes.Status201Created, deviceId)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, "Sorry We are unable to register device")); } }
public ReturnValue RegisterDevice(RegisterDeviceCommand command) { throw new NotImplementedException(); }