/// <summary> /// Called to initially register a device with the TVM. /// </summary> /// <param name="deviceId">A 32 character device id.</param> /// <param name="tvmKey">A 32 character user defined key</param> /// <param name="callback">The callback method</param> public void RegisterDevice(string deviceId, string tvmKey, Action <bool, Exception> callback) { IDictionary <string, string> parameters = new Dictionary <string, string>(); parameters["uid"] = deviceId; parameters["key"] = tvmKey; string queryString = AWSSDKUtils.GetParametersAsString(parameters); var uri = new Uri(string.Format("{0}/registerdevice?{1}", TvmUrl, queryString)); var hwr = WebRequest.Create(uri) as HttpWebRequest; if (hwr == null) { throw new NullReferenceException("Could not create HttpWebRequest"); } hwr.Method = "GET"; var tokenPackage = new TemporaryTokenPackage() { DeviceId = deviceId, Request = hwr }; AsyncCallback responseHandler = (async) => { TemporaryTokenPackage temporaryTokenPackage = (TemporaryTokenPackage)async.AsyncState; HttpWebRequest request = temporaryTokenPackage.Request; HttpWebResponse response = null; try { response = (HttpWebResponse)request.EndGetResponse(async); callback(true, null); } catch (WebException we) { if (((HttpWebResponse)we.Response).StatusDescription == "Conflict") { callback(true, null); } else { callback(false, we); } } }; hwr.BeginGetResponse(responseHandler, tokenPackage); }
/// <summary> /// Called to initially register a device with the TVM. /// </summary> /// <param name="deviceId">A 32 character device id.</param> /// <param name="tvmKey">A 32 character user defined key</param> /// <param name="callback">The callback method</param> public void RegisterDevice(string deviceId, string tvmKey, Action<bool, Exception> callback) { IDictionary<string, string> parameters = new Dictionary<string, string>(); parameters["uid"] = deviceId; parameters["key"] = tvmKey; string queryString = AWSSDKUtils.GetParametersAsString(parameters); var uri = new Uri(string.Format("{0}/registerdevice?{1}", TvmUrl, queryString)); var hwr = WebRequest.Create(uri) as HttpWebRequest; if (hwr == null) { throw new NullReferenceException("Could not create HttpWebRequest"); } hwr.Method = "GET"; var tokenPackage = new TemporaryTokenPackage() {DeviceId = deviceId, Request = hwr}; AsyncCallback responseHandler = (async) => { TemporaryTokenPackage temporaryTokenPackage = (TemporaryTokenPackage) async.AsyncState; HttpWebRequest request = temporaryTokenPackage.Request; HttpWebResponse response = null; try { response = (HttpWebResponse) request.EndGetResponse(async); callback(true, null); } catch (WebException we) { if (((HttpWebResponse) we.Response).StatusDescription == "Conflict") { callback(true, null); } else { callback(false, we); } } }; hwr.BeginGetResponse(responseHandler, tokenPackage); }