/// <summary> /// Create a zip containing the app for manual upload. /// </summary> /// <param name="stream">Stream to write the zip file data to.</param> public void Bundle(Stream stream) { var configFile = new StringBuilder(cleanedConfigFileContent); configFile.AppendLine(); configFile.AppendLine("SAPUI5ApplicationName=" + AppName); configFile.AppendLine("SAPUI5ApplicationPackage=" + Package); configFile.AppendLine("WorkbenchRequest=" + TransportRequest); configFile.AppendLine("SAPUI5ApplicationDescription=" + AppDescription); configFile.AppendLine("ExternalCodePage=" + ExternalCodepage); using (var zipHelper = new ZipHelper(stream)) { zipHelper.Zip(".Ui5RepositoryUploadParameters", Encoding.UTF8.GetBytes(configFile.ToString())); zipHelper.Zip(ProjectDir, string.IsNullOrEmpty(AppSubDir) ? new[] { "*" } : new[] { ".Ui5Repository*", AppSubDir }, IgnoreMasks.ToArray()); } }
/// <summary> /// Uploads the UI5 Project int <see cref="ProjectDir"/> to the SAP system specified by <see cref="Credentials"/>. If <see cref="Credentials.Username"/> is <c>null</c>, a single sign on authentification is performed. /// </summary> public void Upload() { if (string.IsNullOrWhiteSpace(ProjectDir)) throw new InvalidOperationException("ProjectDir not set."); if (!Directory.Exists(ProjectDir)) throw new InvalidOperationException("ProjectDir not set to a folder."); if (Credentials == null) throw new InvalidOperationException("Credentials not set."); if (string.IsNullOrWhiteSpace(Credentials.System)) throw new InvalidOperationException("Credentials.System not set."); if (string.IsNullOrWhiteSpace(AppName)) throw new InvalidOperationException("AppName not set."); if (TestMode) Log.Instance.Write("Test mode on!"); try { var uri = new Uri(this.Credentials.System); uri = uri.AddQuery("sap-client", Credentials.Mandant.ToString()); uri = uri.AddQuery("sapui5applicationname", AppName); uri = uri.AddQuery("sapui5applicationdescription", AppDescription); uri = uri.AddQuery("sapui5applicationpackage", Package); uri = uri.AddQuery("workbenchrequest", TransportRequest); uri = uri.AddQuery("externalcodepage", ExternalCodepage); uri = uri.AddQuery("deltamode", DeltaMode ? "true" : "false"); uri = uri.AddQuery("testmode", TestMode ? "true" : "false"); if (IgnoreCertificateErrors) { System.Net.ServicePointManager.ServerCertificateValidationCallback += ServerCertificateValidationIgnoreAll; } var cookieContainer = new System.Net.CookieContainer(); //Try to Authenticate with a HEAD request and retrieve an authentification token cookie before uploading the whole application. var headRequest = System.Net.HttpWebRequest.Create(uri); headRequest.PreAuthenticate = false; headRequest.Timeout = 10000; headRequest.Method = System.Net.WebRequestMethods.Http.Head; ((System.Net.HttpWebRequest)headRequest).CookieContainer = cookieContainer; if (Credentials.Username != null) { headRequest.Credentials = new System.Net.NetworkCredential(Credentials.Username, Credentials.Password); } else //SSO { headRequest.ImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; headRequest.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; } headRequest.GetResponse().Close(); //The actual POST request with the ziped project. var request = System.Net.HttpWebRequest.Create(uri); request.Timeout = Timeout * 1000; request.PreAuthenticate = true; request.UseDefaultCredentials = false; ((System.Net.HttpWebRequest)request).CookieContainer = cookieContainer; //Contains the authentification token if acquired if (Credentials.Username != null) //if not: credentials to reauthenficiate. { request.Credentials = new System.Net.NetworkCredential(Credentials.Username, Credentials.Password); } else //SSO { request.ImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; request.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; } Log.Instance.Write("Uploading project..."); request.Method = System.Net.WebRequestMethods.Http.Post; request.ContentType = "application/zip"; using (var stream = request.GetRequestStream()) { using (var zipHelper = new ZipHelper(stream)) { zipHelper.Zip(".Ui5RepositoryUploadParameters", Encoding.UTF8.GetBytes(cleanedConfigFileContent)); zipHelper.Zip(ProjectDir, new[] { ".Ui5Repository*", "WebContent" }, IgnoreMasks.ToArray()); } stream.Close(); } Log.Instance.Write("Installing App..."); var response = (System.Net.HttpWebResponse)request.GetResponse(); HandleResponse(response); } catch (System.Net.WebException ex) { if (ex.Response != null) { HandleResponse((System.Net.HttpWebResponse)ex.Response); } else { Log.Instance.Write(ex.ToString()); Log.Instance.Write("Upload failed!"); throw new UploadFailedException(); } } }
/// <summary> /// Uploads the UI5 Project int <see cref="ProjectDir"/> to the SAP system specified by <see cref="Credentials"/>. If <see cref="Credentials.Username"/> is <c>null</c>, a single sign on authentification is performed. /// </summary> public void Upload() { if (string.IsNullOrWhiteSpace(ProjectDir)) { throw new InvalidOperationException("ProjectDir not set."); } if (!Directory.Exists(ProjectDir)) { throw new InvalidOperationException("ProjectDir not set to a folder."); } if (Credentials == null) { throw new InvalidOperationException("Credentials not set."); } if (string.IsNullOrWhiteSpace(Credentials.System)) { throw new InvalidOperationException("Credentials.System not set."); } if (string.IsNullOrWhiteSpace(AppName)) { throw new InvalidOperationException("AppName not set."); } if (TestMode) { Log.Instance.Write("Test mode on!"); } try { var uri = new Uri(this.Credentials.System); uri = uri.AddQuery("sap-client", Credentials.Mandant.ToString()); uri = uri.AddQuery("sapui5applicationname", AppName); uri = uri.AddQuery("sapui5applicationdescription", AppDescription); uri = uri.AddQuery("sapui5applicationpackage", Package); uri = uri.AddQuery("workbenchrequest", TransportRequest); uri = uri.AddQuery("externalcodepage", ExternalCodepage); uri = uri.AddQuery("deltamode", DeltaMode ? "true" : "false"); uri = uri.AddQuery("testmode", TestMode ? "true" : "false"); if (IgnoreCertificateErrors) { System.Net.ServicePointManager.ServerCertificateValidationCallback += ServerCertificateValidationIgnoreAll; } var cookieContainer = new System.Net.CookieContainer(); //Try to Authenticate with a HEAD request and retrieve an authentification token cookie before uploading the whole application. var headRequest = System.Net.HttpWebRequest.Create(uri); headRequest.PreAuthenticate = false; headRequest.Timeout = 10000; headRequest.Method = System.Net.WebRequestMethods.Http.Head; ((System.Net.HttpWebRequest)headRequest).CookieContainer = cookieContainer; if (Credentials.Username != null) { headRequest.Credentials = new System.Net.NetworkCredential(Credentials.Username, Credentials.Password); } else //SSO { headRequest.ImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; headRequest.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; } headRequest.GetResponse().Close(); //The actual POST request with the ziped project. var request = System.Net.HttpWebRequest.Create(uri); request.Timeout = Timeout * 1000; request.PreAuthenticate = true; request.UseDefaultCredentials = false; ((System.Net.HttpWebRequest)request).CookieContainer = cookieContainer; //Contains the authentification token if acquired if (Credentials.Username != null) //if not: credentials to reauthenficiate. { request.Credentials = new System.Net.NetworkCredential(Credentials.Username, Credentials.Password); } else //SSO { request.ImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; request.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; } Log.Instance.Write("Uploading project..."); request.Method = System.Net.WebRequestMethods.Http.Post; request.ContentType = "application/zip"; using (var stream = request.GetRequestStream()) { using (var zipHelper = new ZipHelper(stream)) { zipHelper.Zip(".Ui5RepositoryUploadParameters", Encoding.UTF8.GetBytes(cleanedConfigFileContent)); zipHelper.Zip(ProjectDir, new[] { ".Ui5Repository*", "WebContent" }, IgnoreMasks.ToArray()); } stream.Close(); } Log.Instance.Write("Installing App..."); var response = (System.Net.HttpWebResponse)request.GetResponse(); HandleResponse(response); } catch (System.Net.WebException ex) { if (ex.Response != null) { HandleResponse((System.Net.HttpWebResponse)ex.Response); } else { Log.Instance.Write(ex.ToString()); Log.Instance.Write("Upload failed!"); throw new UploadFailedException(); } } }