private async void InfoWorker_DoWorkAsync(object sender, DoWorkEventArgs e) { try { string query = string.Format("SELECT * FROM SMS_G_System_COMPUTER_SYSTEM WHERE ResourceID = '{0}'", PropertyManager["ResourceID"].IntegerValue); IResultObject contentObject = Utility.GetFirstWMIInstance(ConnectionManager, query); if (contentObject["Manufacturer"].StringValue == "Dell Inc.") { labelModel.Text = contentObject["Model"].StringValue; query = string.Format("SELECT * FROM SMS_G_System_PC_BIOS WHERE ResourceID = '{0}'", PropertyManager["ResourceID"].IntegerValue); contentObject = Utility.GetFirstWMIInstance(ConnectionManager, query); string serviceTag = contentObject["SerialNumber"].StringValue; labelServiceTag.Text = serviceTag; log.InfoFormat("Processing warranty request for service tag : {0}", serviceTag); using (HttpClient client = new HttpClient()) { try { labelHttpResponse.Text = "Requesting data from API"; client.BaseAddress = new Uri(registry.ReadString("DellAPIURI")); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml")); log.InfoFormat("Connecting to dell API : {0}", client.BaseAddress); HttpResponseMessage response = await client.GetAsync(string.Format("getassetwarranty/{0}?apikey={1}", serviceTag, registry.ReadString("DellApiKey"))); log.DebugFormat("URL : {0}", response.RequestMessage.RequestUri.OriginalString); log.DebugFormat("Response status code : {0}", response.StatusCode); if (response.IsSuccessStatusCode) { labelHttpResponse.Text = "Success"; string resultContent = response.Content.ReadAsStringAsync().Result; XElement assetInformation = XElement.Parse(resultContent); XNamespace ns = assetInformation.GetDefaultNamespace(); log.Info("Connected successfully, processing xml data"); CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; TextInfo textInfo = cultureInfo.TextInfo; var headerData = assetInformation.Descendants(ns + "AssetHeaderData").First(); XElement node = headerData.Element(ns + "ShipDate"); if (node != null) { string shipDate = DateTime.Parse(node.Value).ToString(); labelShipDate.Text = shipDate; } IEnumerable <XElement> nodeList = assetInformation.Descendants(ns + "AssetEntitlement"); foreach (XElement entitlement in nodeList) { string serviceLevelDescription = entitlement.Element(ns + "ServiceLevelDescription").Value; if (serviceLevelDescription != "") { string type = entitlement.Element(ns + "EntitlementType").Value; listViewWarranty.Items.Add(new ListViewItem() { Text = serviceLevelDescription, SubItems = { textInfo.ToTitleCase(type.ToLower()), DateTime.Parse(entitlement.Element(ns + "StartDate").Value).ToShortDateString(), DateTime.Parse(entitlement.Element(ns + "EndDate").Value).ToShortDateString() } }); } } } else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { labelHttpResponse.Text = "Unauthorized - Check API Key"; log.Warn(labelHttpResponse.Text); } else if (response.StatusCode == System.Net.HttpStatusCode.NotFound) { labelHttpResponse.Text = "Resource Not found"; log.Warn(labelHttpResponse.Text); } } catch (HttpRequestException ex) { string msg = string.Format("{0}: {1}", ex.GetType().Name, ex.Message); log.Error(msg); throw new InvalidOperationException(msg); } log.InfoFormat("Finished processing request for service tag : {0}", serviceTag); } } else { labelServiceTag.Text = "The device is not manufacutred by Dell Inc"; labelModel.Text = contentObject["Manufacturer"].StringValue; } contentObject.Dispose(); } catch (Exception ex) { string msg = string.Format("{0}: {1}", ex.GetType().Name, ex.Message); log.Error(msg); throw new InvalidOperationException(msg); } }