private async Task JoinDataOceanTiles(FileData dxfFile, MasterDataModels.Point tileTopLeft, MasterDataModels.Point tileBottomRight, Image <Rgba32> tileBitmap, int zoomLevel) { var fileName = DataOceanFileUtil.DataOceanFileName(dxfFile.Name, dxfFile.ImportedFileType == ImportedFileType.SurveyedSurface || dxfFile.ImportedFileType == ImportedFileType.GeoTiff, Guid.Parse(dxfFile.ImportedFileUid), dxfFile.SurveyedUtc); fileName = DataOceanFileUtil.GeneratedFileName(fileName, dxfFile.ImportedFileType); var dataOceanFileUtil = new DataOceanFileUtil($"{DataOceanUtil.PathSeparator}{dataOceanRootFolder}{dxfFile.Path}{DataOceanUtil.PathSeparator}{fileName}"); log.LogDebug($"{nameof(JoinDataOceanTiles)}: fileName: {fileName} dataOceanFileUtil.FullFileName {dataOceanFileUtil.FullFileName}"); for (int yTile = (int)tileTopLeft.y; yTile <= (int)tileBottomRight.y; yTile++) { for (int xTile = (int)tileTopLeft.x; xTile <= (int)tileBottomRight.x; xTile++) { var targetFile = dataOceanFileUtil.GetTileFileName(zoomLevel, yTile, xTile); log.LogDebug($"JoinDxfTiles: getting tile {targetFile}"); var file = await dataOceanClient.GetFile(targetFile, authn.CustomHeaders()); if (file != null) { Image <Rgba32> tile = Image.Load <Rgba32>(file); Point offset = new Point( (xTile - (int)tileTopLeft.x) * MasterDataModels.WebMercatorProjection.TILE_SIZE, (yTile - (int)tileTopLeft.y) * MasterDataModels.WebMercatorProjection.TILE_SIZE); tileBitmap.Mutate(ctx => ctx.DrawImage(tile, PixelBlenderMode.Normal, 1f, offset)); } } } }
/// <summary> /// Writes the importedFile to DataOcean as a create or update, /// if it already exists, old version will be deleted first. /// </summary> public static async Task WriteFileToDataOcean( Stream fileContents, string rootFolder, string customerUid, string projectUid, string dataOceanFileName, ILogger log, IServiceExceptionHandler serviceExceptionHandler, IDataOceanClient dataOceanClient, ITPaaSApplicationAuthentication authn, Guid fileUid, IConfigurationStore configStore) { var dataOceanEnabled = configStore.GetValueBool("ENABLE_DATA_OCEAN", false); if (dataOceanEnabled) { if (!dataOceanFileName.StartsWith(fileUid.ToString())) { throw new ServiceException(HttpStatusCode.InternalServerError, new ContractExecutionResult(ContractExecutionStatesEnum.InternalProcessingError, $"Invalid DataOcean file name {dataOceanFileName}")); } var customHeaders = authn.CustomHeaders(); var dataOceanPath = DataOceanFileUtil.DataOceanPath(rootFolder, customerUid, projectUid); var ccPutFileResult = false; var folderAlreadyExists = false; try { log.LogInformation($"{nameof(WriteFileToDataOcean)}: dataOceanPath: '{dataOceanPath}', dataOceanFileName: '{dataOceanFileName}'"); folderAlreadyExists = await dataOceanClient.FolderExists(dataOceanPath, customHeaders); if (!folderAlreadyExists) { await dataOceanClient.MakeFolder(dataOceanPath, customHeaders); } ccPutFileResult = await dataOceanClient.PutFile(dataOceanPath, dataOceanFileName, fileContents, customHeaders); } catch (Exception e) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 57, "dataOceanClient.PutFile", e.Message); } if (!ccPutFileResult) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 116); } log.LogInformation($"{nameof(WriteFileToDataOcean)}: dataOceanFileName '{dataOceanFileName}' written to DataOcean, folderAlreadyExists: {folderAlreadyExists}"); } else { log.LogInformation($"{nameof(WriteFileToDataOcean)}: File not saved. DataOcean disabled"); } }
public DataRepository(ILogger log, ITPaaSApplicationAuthentication authorization, IProjectInternalProxy projectProxy, IDeviceInternalProxy deviceProxy, ITRexCompactionDataProxy tRexCompactionDataProxy, IHeaderDictionary requestCustomHeaders) { _log = log; _projectProxy = projectProxy; _deviceProxy = deviceProxy; _tRexCompactionDataProxy = tRexCompactionDataProxy; _mergedCustomHeaders = requestCustomHeaders; foreach (var header in authorization.CustomHeaders()) { _mergedCustomHeaders.Add(header); } }
/// <summary> /// Deletes the importedFile from DataOcean /// </summary> public static async Task <ImportedFileInternalResult> DeleteFileFromDataOcean( string fileName, string rootFolder, string customerUid, Guid projectUid, Guid importedFileUid, ILogger log, IDataOceanClient dataOceanClient, ITPaaSApplicationAuthentication authn, IConfigurationStore configStore) { var dataOceanEnabled = configStore.GetValueBool("ENABLE_DATA_OCEAN", false); if (dataOceanEnabled) { var dataOceanPath = DataOceanFileUtil.DataOceanPath(rootFolder, customerUid, projectUid.ToString()); var fullFileName = $"{dataOceanPath}{Path.DirectorySeparatorChar}{fileName}"; log.LogInformation($"{nameof(DeleteFileFromDataOcean)}: fullFileName {JsonConvert.SerializeObject(fullFileName)}"); var customHeaders = authn.CustomHeaders(); bool ccDeleteFileResult; try { ccDeleteFileResult = await dataOceanClient.DeleteFile(fullFileName, customHeaders); } catch (Exception e) { log.LogError(e, $"{nameof(DeleteFileFromDataOcean)}: failed for {fileName} (importedFileUid:{importedFileUid}) with exception {e.Message}"); return(ImportedFileInternalResult.CreateImportedFileInternalResult(HttpStatusCode.InternalServerError, 57, "dataOceanClient.DeleteFile", e.Message)); } if (!ccDeleteFileResult) { log.LogWarning( $"{nameof(DeleteFileFromDataOcean)}: failed to delete {fileName} (importedFileUid:{importedFileUid})."); //Not an error if it doesn't delete the file? //return ImportedFileInternalResult.CreateImportedFileInternalResult(HttpStatusCode.InternalServerError, 117); } } else { log.LogInformation($"{nameof(DeleteFileFromDataOcean)}: File not deleted. DataOcean disabled"); } return(null); }
/// <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"); } }
public async Task Setup(object o, object context) { _headers = _authn.CustomHeaders(); }