Commit 7d17a6dd authored by Jason Williams's avatar Jason Williams Committed by GitHub
Browse files

Merge pull request #130 from WilliamsJason/master

Fix error cases in appx install and loose deploy
parents cb86d988 c4c0efe1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -176,7 +176,7 @@ namespace XboxWdpDriver
                {
                    DevicePortalException exception = e.InnerException as DevicePortalException;

                    Console.WriteLine(string.Format("HTTP Status: {0}, Hresult: 0x{1:X8}. {2}", exception.StatusCode, exception.HResult, exception.Message));
                    Console.WriteLine(string.Format("HTTP Status: {0}, Hresult: 0x{1:X8}. {2}", exception.StatusCode, exception.HResult, exception.Reason));
                }
            }
        }
+7 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ namespace XboxWdpDriver
            "        Installs the given AppX package, along with any given dependencies.\n" +
            "  /folder:<path to loose folder> [/depend:<path to dependency1>;<path to dependency2> /cer:<path to certificate> /transfer:<SMB or HTTP, SMB is the default> /destfoldername:<folder name, defaults to the same as the loose folder>]\n" +
            "        Installs the appx from a loose folder, along with any given dependencies.\n" +
            "  /register:<subpath on DevelopmentFiles\\LooseFolder to app to register>\n" +
            "  /register:<subpath on DevelopmentFiles\\LooseApps to app to register>\n" +
            "        Registers a loose folder that is already present on the device.\n";

        /// <summary>
@@ -124,6 +124,12 @@ namespace XboxWdpDriver
                        operation.mreAppInstall.Reset();
                        Task installTask = portal.InstallApplication(null, dependency, new List<string>());
                        operation.mreAppInstall.WaitOne();

                        if (operation.installResults.Status != ApplicationInstallStatus.Completed)
                        {
                            Console.WriteLine("Deploy failed during dependency installation. {0}", operation.installResults.Message);
                            return;
                        }
                    }

                    if (!Directory.Exists(folderPath))
+11 −9
Original line number Diff line number Diff line
@@ -199,20 +199,22 @@ namespace Microsoft.Tools.WindowsDevicePortal
            {
                DevicePortalException dpe = e as DevicePortalException;

                HttpStatusCode status = (HttpStatusCode)0;
                Uri request = null;
                if (dpe != null)
                {
                    status = dpe.StatusCode;
                    request = dpe.RequestUri;
                    this.SendAppInstallStatus(
                        ApplicationInstallStatus.Failed,
                        ApplicationInstallPhase.Idle,
                        string.Format("Failed to install {0}: {1}", appName, dpe.Reason));
                }

                else
                {
                    this.SendAppInstallStatus(
                        ApplicationInstallStatus.Failed,
                        ApplicationInstallPhase.Idle,
                        string.Format("Failed to install {0}: {1}", appName, installPhaseDescription));
                }
            }
        }

        /// <summary>
        /// Uninstalls the specified application.
+66 −13
Original line number Diff line number Diff line
@@ -34,9 +34,44 @@ namespace Microsoft.Tools.WindowsDevicePortal
        /// <summary>
        /// Initializes a new instance of the <see cref="DevicePortalException"/> class.
        /// </summary>
        /// <param name="responseMessage">Http response message</param>
        /// <param name="message">Optional exception message</param>
        /// <param name="innerException">Optional inner exception</param>
        /// <param name="statusCode">The Http status code.</param>
        /// <param name="errorResponse">Http parsed error response message.</param>
        /// <param name="requestUri">Request URI which threw the exception.</param>
        /// <param name="message">Optional exception message.</param>
        /// <param name="innerException">Optional inner exception.</param>
        public DevicePortalException(
            HttpStatusCode statusCode,
            HttpErrorResponse errorResponse,
            Uri requestUri = null,
            string message = "",
            Exception innerException = null) : this(
                                                    statusCode,
                                                    errorResponse.Reason,
                                                    requestUri,
                                                    message,
                                                    innerException)
        {
            this.HResult = errorResponse.ErrorCode;
            this.Reason = errorResponse.ErrorMessage;

            // If we didn't get the Hresult and reason from these properties, try the other ones.
            if (this.HResult == 0)
            {
                this.HResult = errorResponse.Code;
            }

            if (string.IsNullOrEmpty(this.Reason))
            {
                this.Reason = errorResponse.Reason;
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="DevicePortalException"/> class.
        /// </summary>
        /// <param name="responseMessage">Http response message.</param>
        /// <param name="message">Optional exception message.</param>
        /// <param name="innerException">Optional inner exception.</param>
        public DevicePortalException(
            HttpResponseMessage responseMessage,
            string message = "",
@@ -91,6 +126,12 @@ namespace Microsoft.Tools.WindowsDevicePortal
                        this.HResult = errorResponse.ErrorCode;
                        this.Reason = errorResponse.ErrorMessage;

                        // If we didn't get the Hresult and reason from these properties, try the other ones.
                        if (this.HResult == 0)
                        {
                            this.HResult = errorResponse.Code;
                        }

                        if (string.IsNullOrEmpty(this.Reason))
                        {
                            this.Reason = errorResponse.Reason;
@@ -107,11 +148,11 @@ namespace Microsoft.Tools.WindowsDevicePortal
        /// <summary>
        /// Initializes a new instance of the <see cref="DevicePortalException"/> class.
        /// </summary>
        /// <param name="statusCode">Http status code</param>
        /// <param name="reason">Reason for exception</param>
        /// <param name="requestUri">Request URI which threw the exception</param>
        /// <param name="message">Optional message</param>
        /// <param name="innerException">Optional inner exception</param>
        /// <param name="statusCode">Http status code.</param>
        /// <param name="reason">Reason for exception.</param>
        /// <param name="requestUri">Request URI which threw the exception.</param>
        /// <param name="message">Optional message.</param>
        /// <param name="innerException">Optional inner exception.</param>
        public DevicePortalException(
            HttpStatusCode statusCode,
            string reason,
@@ -127,17 +168,17 @@ namespace Microsoft.Tools.WindowsDevicePortal
        }

        /// <summary>
        /// Gets the HTTP Status code
        /// Gets the HTTP Status code.
        /// </summary>
        public HttpStatusCode StatusCode { get; private set; }
        
        /// <summary>
        /// Gets a reason for the exception
        /// Gets a reason for the exception.
        /// </summary>
        public string Reason { get; private set; }

        /// <summary>
        /// Gets the request URI that threw the exception
        /// Gets the request URI that threw the exception.
        /// </summary>
        public Uri RequestUri { get; private set; }

@@ -161,7 +202,7 @@ namespace Microsoft.Tools.WindowsDevicePortal
        /// an HTTP response.
        /// </summary>
        [DataContract]
        private class HttpErrorResponse
        public class HttpErrorResponse
        {
            /// <summary>
            /// Gets or sets the ErrorCode
@@ -169,6 +210,12 @@ namespace Microsoft.Tools.WindowsDevicePortal
            [DataMember(Name = "ErrorCode")]
            public int ErrorCode { get; set; }

            /// <summary>
            /// Gets or sets the Code (used by some endpoints instead of ErrorCode).
            /// </summary>
            [DataMember(Name = "Code")]
            public int Code { get; set; }

            /// <summary>
            /// Gets or sets the ErrorMessage
            /// </summary>
@@ -176,10 +223,16 @@ namespace Microsoft.Tools.WindowsDevicePortal
            public string ErrorMessage { get; set; }

            /// <summary>
            /// Gets or sets the Reason
            /// Gets or sets the Reason (used by some endpoints instead of ErrorMessage).
            /// </summary>
            [DataMember(Name = "Reason")]
            public string Reason { get; set; }

            /// <summary>
            /// Gets or sets the Success. For an error this should generally be false if present.
            /// </summary>
            [DataMember(Name = "Success")]
            public bool Success { get; set; }
        }

        #endregion
+10 −0
Original line number Diff line number Diff line
@@ -41,6 +41,16 @@ namespace Microsoft.Tools.WindowsDevicePortal
            await this.Post(
                RegisterPackageApi,
                string.Format("folder={0}", Utilities.Hex64Encode(folderName)));

            // Poll the status until complete.
            ApplicationInstallStatus status = ApplicationInstallStatus.InProgress;
            do
            {
                await Task.Delay(TimeSpan.FromMilliseconds(500));

                status = await this.GetInstallStatus();
            }
            while (status == ApplicationInstallStatus.InProgress);
        }

        /// <summary>
Loading