public async Task<HttpStatusCode> UninstallAppAsync(string packageFullName, string target, UserInfo credentials) { var url = string.Empty; var result = HttpStatusCode.BadRequest; IPAddress ipAddress = IPAddress.Parse(target); RestHelper restHelper = new RestHelper(ipAddress, credentials); CancellationToken? cts; EnterWebBCall(out cts); try { url = AppApiUrl + "package?package=" + packageFullName; using (var response = await restHelper.SendRequestAsync(url, HttpMethod.Delete, null, cts)) { result = response.StatusCode; } } catch (Exception ex) { Debug.WriteLine(ex.Message); } return result; }
public async Task<HttpStatusCode> DeployAppAsync(IEnumerable<FileInfo> files, string target, UserInfo credentials) { IPAddress ipAddress = IPAddress.Parse(target); RestHelper restHelper = new RestHelper(ipAddress, credentials); var url = AppxApiUrl + "package?package="; url += files.First().Name; var result = HttpStatusCode.BadRequest; CancellationToken? cts; EnterWebBCall(out cts); try { using (var response = await restHelper.SendRequestAsync(url, HttpMethod.Post, null, files, cts)) { result = response.StatusCode; using (var stream = response.GetResponseStream()) { if (stream != null) { using (var sr = new StreamReader(stream)) { Debug.WriteLine(sr.ReadToEnd()); } } } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } return result; }
public async Task<bool> PollInstallStateAsync(string target, UserInfo credentials) { IPAddress ipAddress = IPAddress.Parse(target); RestHelper restHelper = new RestHelper(ipAddress, credentials); var URL = AppxApiUrl + "state"; var result = HttpStatusCode.BadRequest; CancellationToken? cts; while (result != HttpStatusCode.NotFound && result != HttpStatusCode.OK) { EnterWebBCall(out cts); try { using (var response = await restHelper.SendRequestAsync(URL, HttpMethod.Get, string.Empty, cts)) { result = response.StatusCode; if (response.StatusCode == HttpStatusCode.NoContent) { await Task.Delay(QueryInterval); } else { var state = RestHelper.ProcessJsonResponse(response, typeof(DeploymentState)) as DeploymentState; if (state != null) { if (state.IsSuccess) { return true; } else { // This throws a COMException Marshal.ThrowExceptionForHR(state.HResult); } } } } } catch (COMException ex) { System.Console.WriteLine("Error: app did not deploy: {0}", ex.Message); Debug.WriteLine(ex.Message); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } return false; }