async Task <ITGeoTagger.WindAMSObjects.Component[]> SearchComponentsAsync(ComponentSearchBean CSB) { ITGeoTagger.WindAMSObjects.Component[] Components = null; HttpResponseMessage response = await this.windAMSClient.PostAsJsonAsync("component/search", CSB); response.EnsureSuccessStatusCode(); // Return the URI of the created resource. Components = await response.Content.ReadAsAsync <ITGeoTagger.WindAMSObjects.Component[]>(); return(Components); }
async public Task <bool> UploadToWindAMS(string workOrderNumber, string SiteName, string AssetName, string Blade, string processor, int pass, int sequence, ImageLocationAndExtraInfo ExtraInfo, ImageBladeGroup ImageGroup) { string assetName = AssetName; string componentType = "Blade" + Blade; WorkOrder myWorkOrder = new WorkOrder(); string myprocessor = processor; try {//search for workorder myWorkOrder = await GetWorkOrderAsync(workOrderNumber); } catch { //MessageBox.Show("error no results"); return(false); } //check if asset exists in the site AssetSearchBean ASB = new AssetSearchBean(); ASB.siteId = myWorkOrder.siteId; ASB.assetType = AssetType.Wind_Turbine_Tower; ASB.name = assetName; Asset[] myAssets = await SearchAssetsAsync(ASB); Asset myAsset = new Asset(); if (myAssets != null) { if (myAssets.Length > 0) { myAsset = myAssets[0]; if (myAsset.attributes == null) //check for atribute type patch // we can remove this once all offending object have been reverted { myAsset.attributes = new Dictionary <AssetAttributeType, string>(); myAsset = await UpdateAssetAsync(myAsset); } } else { myAsset = new Asset(); myAsset.attributes = new Dictionary <AssetAttributeType, string>(); myAsset.dateOfInstall = null; myAsset.id = System.Guid.NewGuid().ToString(); myAsset.location = new GeoPoint(); myAsset.location.accuracy = 1; // not sure how to use this myAsset.location.altitude = 0; // should be based on turbine info imported try { myAsset.location.latitude = Double.Parse(ImageGroup.Latitude); }// should be based on turbine info imported catch { myAsset.location.latitude = 0; }; try { myAsset.location.longitude = Double.Parse(ImageGroup.Longitude); } // should be based on turbine info imported catch { myAsset.location.longitude = 0; } myAsset.make = ""; myAsset.model = ""; myAsset.name = assetName; myAsset.serialNumber = ""; myAsset.siteId = myWorkOrder.siteId; myAsset.type = "Wind_Turbine_Tower"; myAsset = await CreateAssetAsync(myAsset); } } else { //MessageBox.Show("error no results"); return(false); } //search for asset inspections AssetInspection[] myAssetInspections; AssetInspectionSearchBean AISB = new AssetInspectionSearchBean(); AISB.siteId = myWorkOrder.siteId; AISB.assetId = myAsset.id; AISB.orderNumber = myWorkOrder.orderNumber; myAssetInspections = await SearchAssetInspectionsAsync(AISB); AssetInspection myAssetInspection = new AssetInspection(); if (myAssetInspections != null) { if (myAssetInspections.Length > 0) { myAssetInspection = myAssetInspections[0]; if (myAssetInspection.attributes == null) { myAssetInspection.attributes = new Dictionary <AssetInspectionAttributeType, string>(); myAssetInspection = await UpdateAssetInspectionAsync(myAssetInspection); } } else { //MessageBox.Show("error no results"); myAssetInspection.assetId = myAsset.id; myAssetInspection.attributes = new Dictionary <AssetInspectionAttributeType, string>(); myAssetInspection.dateOfInspection = this.DateTimeToWindamsDateString(ExtraInfo.Time); // date of inspection needs to be defined myAssetInspection.id = System.Guid.NewGuid().ToString(); myAssetInspection.orderNumber = myWorkOrder.orderNumber; myAssetInspection.processedBy = myprocessor; //needs to be defined on upload or sign in myAssetInspection.resources = null; myAssetInspection.type = "DroneBladeInspection"; myAssetInspection.siteId = myWorkOrder.siteId; myAssetInspection.status = "In_Process"; myAssetInspection = await CreateAssetInspectionAsync(myAssetInspection); } } else { //MessageBox.Show("error no results"); return(false); } //find component or create component WindAMSObjects.Component myComponent = new WindAMSObjects.Component(); ComponentSearchBean CSB = new ComponentSearchBean(); CSB.assetId = myAsset.id; CSB.componentType = componentType; CSB.siteId = myWorkOrder.siteId; WindAMSObjects.Component[] myComponents; myComponents = await SearchComponentsAsync(CSB); if (myComponents != null) { if (myComponents.Length > 0) { myComponent = myComponents[0]; if (myComponent.attributes == null) { myComponent.attributes = new Dictionary <ComponentAttributeType, string>(); myComponent = await UpdateComponentAsync(myComponent); } } else { //MessageBox.Show("error no results"); myComponent.assetId = myAsset.id; myComponent.attributes = new Dictionary <ComponentAttributeType, string>(); myComponent.type = componentType; myComponent.id = System.Guid.NewGuid().ToString(); myComponent.make = ""; //not sure if we shoud use this myComponent.siteId = myWorkOrder.siteId; myComponent = await CreateComponentAsync(myComponent); } } else { MessageBox.Show("error no results"); return(false); } //find componentInspection or create componentInspection ComponentInspection myComponentInspection = new ComponentInspection(); ComponentInspectionSearchBean CISB = new ComponentInspectionSearchBean(); CISB.assetId = myAsset.id; CISB.componentId = myComponent.id; CISB.siteId = myWorkOrder.siteId; CISB.orderNumber = myWorkOrder.orderNumber; CISB.assetInspectionId = myAssetInspection.id; ComponentInspection[] myComponentInspections; myComponentInspections = await SearchComponentInspectionsAsync(CISB); if (myComponentInspections != null) { if (myComponentInspections.Length > 0) { myComponentInspection = myComponentInspections[0]; if (myComponentInspection.statusHistory.Count == 0) { myComponentInspection.statusHistory = new List <ComponentInspectionStatusEvent>(); ComponentInspectionStatusEvent CISE_InspectionStarted = new ComponentInspectionStatusEvent(); CISE_InspectionStarted.status = "InspectionStarted"; CISE_InspectionStarted.timestamp = null; CISE_InspectionStarted.userId = null; ComponentInspectionStatusEvent CISE_InspectionCompleted = new ComponentInspectionStatusEvent(); CISE_InspectionCompleted.status = "InspectionCompleted"; CISE_InspectionCompleted.timestamp = null; CISE_InspectionCompleted.userId = null; myComponentInspection.statusHistory.Add(CISE_InspectionStarted); myComponentInspection.statusHistory.Add(CISE_InspectionCompleted); myComponentInspection = await UpdateComponentInspectionAsync(myComponentInspection); } } else { myComponentInspection.id = System.Guid.NewGuid().ToString(); myComponentInspection.assetId = myAsset.id; myComponentInspection.assetInspectionId = myAssetInspection.id; myComponentInspection.componentId = myComponent.id; myComponentInspection.inspectorUserId = System.Guid.NewGuid().ToString(); myComponentInspection.orderNumber = myWorkOrder.orderNumber; myComponentInspection.siteId = myWorkOrder.siteId; myComponentInspection.type = "DroneInspection"; myComponentInspection.resources = new List <string>(); myComponentInspection.statusHistory = new List <ComponentInspectionStatusEvent>(); ComponentInspectionStatusEvent CISE_InspectionStarted = new ComponentInspectionStatusEvent(); CISE_InspectionStarted.status = "InspectionStarted"; CISE_InspectionStarted.timestamp = null; CISE_InspectionStarted.userId = null; ComponentInspectionStatusEvent CISE_InspectionCompleted = new ComponentInspectionStatusEvent(); CISE_InspectionCompleted.status = "InspectionCompleted"; CISE_InspectionCompleted.timestamp = null; CISE_InspectionCompleted.userId = null; myComponentInspection.statusHistory.Add(CISE_InspectionStarted); myComponentInspection.statusHistory.Add(CISE_InspectionCompleted); myComponentInspection = await CreateComponentInspectionAsync(myComponentInspection); } } else { MessageBox.Show("error no results"); return(false); } //create the meta data tags for an image ResourceMetaData myResourceMetaData = new ResourceMetaData(); myResourceMetaData.assetId = myAsset.id; myResourceMetaData.assetInspectionId = myAssetInspection.id; myResourceMetaData.componentInspectionId = myComponentInspection.id; myResourceMetaData.componentId = myComponent.id; myResourceMetaData.contentType = "image/jpeg"; myResourceMetaData.formId = null; myResourceMetaData.location = new GeoPoint(); myResourceMetaData.location.accuracy = 1; // not sure how to use this myResourceMetaData.location.altitude = ExtraInfo.Altitude; // needs to be based on image myResourceMetaData.location.latitude = ExtraInfo.Longitude; // needs to be based on image myResourceMetaData.location.longitude = ExtraInfo.Latitude; // needs to be based on image myResourceMetaData.siteId = myWorkOrder.siteId; myResourceMetaData.name = Path.GetFileName(ExtraInfo.PathToDestination); myResourceMetaData.orderNumber = myWorkOrder.orderNumber; myResourceMetaData.pass = pass; // defined durring upload myResourceMetaData.readings = new List <SensorReading>(); //left undefined myResourceMetaData.resourceId = this.GetImageGUID(ExtraInfo.PathToDestination); myResourceMetaData.sequence = sequence; // defined durring upload myResourceMetaData.size = new Dimension(); List <int> heightWidthofImage = this.GetImageHeightWidth(ExtraInfo.PathToDestination); myResourceMetaData.size.width = heightWidthofImage[1]; // needs to be based on image myResourceMetaData.size.height = heightWidthofImage[0];; //needs to be based on image myResourceMetaData.size.depth = 1; //needs to be based on image myResourceMetaData.sourceURL = null; myResourceMetaData.status = "QueuedForUpload"; myResourceMetaData.submissionId = null; myResourceMetaData.timestamp = DateTimeToWindamsDateTimeString(ExtraInfo.Time); await CreateResourceMetaDataAsync(myResourceMetaData); HttpStatusCode response = await UploadImageDataAsync(myResourceMetaData.resourceId, ExtraInfo.PathToDestination, File.ReadAllBytes(ExtraInfo.PathToDestination)); if (response == HttpStatusCode.OK) { myResourceMetaData.status = "Processed"; await CreateResourceMetaDataAsync(myResourceMetaData); return(true); } else { return(false); } }