public void CreateDeviceLKS() { var deviceType = CWSDeviceTypeEnum.EC520; var serialNumber = "12456YU"; var deviceName = $"{deviceType}-{serialNumber}"; var deviceLKSModel = new DeviceLKSModel() { TimeStamp = DateTime.UtcNow.AddDays(1), Latitude = -2, Longitude = 3, Height = 1, AssetSerialNumber = serialNumber, AssetType = "Dozer", AssetNickname = "Little Nicky", DesignName = "Highway to hell", AppName = "Trimble Groundworks", AppVersion = "1.1.19200.96", Devices = new List <ConnectedDevice> { new ConnectedDevice { Model = "SNM940", SerialNumber = "123456" } } }; var route = $"/devicegateway/status/{deviceName}"; var expectedUrl = $"{baseUrl}{route}"; mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint( It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl)); MockUtilities.TestRequestSendsCorrectJson("Post device LKS", mockWebRequest, null, expectedUrl, HttpMethod.Post, async() => { var client = ServiceProvider.GetRequiredService <ICwsDeviceGatewayClient>(); await client.CreateDeviceLKS(deviceName, deviceLKSModel); return(true); }); }
/// <summary> /// Adding some LastKnownStatus values to cws using deviceName /// </summary> public Task CreateDeviceLKS(string deviceName, DeviceLKSModel deviceLksModel, IHeaderDictionary customHeaders = null) { log.LogDebug($"{nameof(CreateDeviceLKS)}: deviceName {deviceName} deviceLksModel {JsonConvert.SerializeObject(deviceLksModel)}"); return(PostData($"{ROUTE_PREFIX}/status/{deviceName}", deviceLksModel, null, customHeaders)); }
public Task CreateDeviceLKS(string deviceName, DeviceLKSModel deviceLKSModel, IHeaderDictionary customHeaders = null) { log.LogDebug($"{nameof(CreateDeviceLKS)} Mock: deviceName {deviceName} deviceLKSModel {JsonConvert.SerializeObject(deviceLKSModel)}"); return(Task.CompletedTask); }
/// <summary> /// Send devices lastKnownStatus to cws deviceGateway aka connected site /// Don't need to await as this process should be fire and forget /// We don't care if the post is valid, or device exists etc /// </summary> public void SendDeviceStatusToDeviceGateway(TagFileDetail tagFileDetail, TAGFilePreScan tagFilePreScan) { if (tagFilePreScan.PlatformType == CWSDeviceTypeEnum.EC520 || tagFilePreScan.PlatformType == CWSDeviceTypeEnum.EC520W || tagFilePreScan.PlatformType == CWSDeviceTypeEnum.Unknown) { _log.LogInformation($"#Progress# {nameof(SendDeviceStatusToDeviceGateway)} Not an applicable DeviceType: {tagFilePreScan.PlatformType}"); } else { var seedLatitude = MathUtilities.RadiansToDegrees(tagFilePreScan.SeedLatitude ?? 0.0); var seedLongitude = MathUtilities.RadiansToDegrees(tagFilePreScan.SeedLongitude ?? 0.0); var seedNorthing = tagFilePreScan.SeedNorthing; var seedEasting = tagFilePreScan.SeedEasting; if (Math.Abs(seedLatitude) < Consts.TOLERANCE_DECIMAL_DEGREE && Math.Abs(seedLongitude) < Consts.TOLERANCE_DECIMAL_DEGREE) { // This check is also done as a pre-check as the scenario is very frequent, to avoid the TFA API call overhead. var message = $"#Progress# {nameof(SendDeviceStatusToDeviceGateway)} tagfile: {tagFileDetail.tagFileName} doesn't have a valid Seed Lat/Long. {tagFilePreScan.SeedLatitude}/{tagFilePreScan.SeedLongitude}. "; if (seedNorthing != null && seedEasting != null) { message += $" It does have a Seed Northing/Easting {seedNorthing}/{seedEasting} however local grids are not currently supported for deviceGateway."; } _log.LogWarning(message); } else { var deviceLksModel = new DeviceLKSModel { TimeStamp = tagFilePreScan.SeedTimeUTC, Latitude = seedLatitude, Longitude = seedLongitude, Height = tagFilePreScan.SeedHeight, AssetSerialNumber = tagFilePreScan.HardwareID, AssetNickname = tagFilePreScan.MachineID, AppName = (tagFilePreScan.PlatformType == CWSDeviceTypeEnum.TMC) ? "TMC" : "GCS900", AppVersion = tagFilePreScan.ApplicationVersion, DesignName = tagFilePreScan.DesignName, // PlatformType is only passed as part of DeviceName {platformType}-{assetSerialNumber} AssetType = tagFilePreScan.MachineType.GetEnumMemberValue(), Devices = string.IsNullOrWhiteSpace(tagFilePreScan.RadioSerial) ? null : new List <ConnectedDevice> { new ConnectedDevice { Model = tagFilePreScan.RadioType, SerialNumber = tagFilePreScan.RadioSerial } } }; _log.LogInformation($"#Progress# {nameof(SendDeviceStatusToDeviceGateway)} Posting deviceLks to cws deviceGateway: {JsonConvert.SerializeObject(deviceLksModel)}"); var cwsDeviceGatewayClient = DIContext.Obtain <ICwsDeviceGatewayClient>(); var customHeaders = _tPaaSApplicationAuthentication.CustomHeaders(); _log.LogInformation($"#Progress# {nameof(SendDeviceStatusToDeviceGateway)} Got customHeaders"); // don't await this call, should be fire and forget cwsDeviceGatewayClient.CreateDeviceLKS($"{deviceLksModel.AssetType}-{deviceLksModel.AssetSerialNumber}", deviceLksModel, customHeaders) .ContinueWith((task) => { if (task.IsFaulted) { _log.LogError(task.Exception, $"#Progress# {nameof(SendDeviceStatusToDeviceGateway)}: Error Sending to Connected Site", null); } }, TaskContinuationOptions.OnlyOnFaulted); } _log.LogInformation($"#Progress# {nameof(SendDeviceStatusToDeviceGateway)} Post to ces deviceGateway completed"); } }