public static async Task <string> TopologySubmit(string clusterUrl, string clusterUsername, string clusterPassword, string specFile, string packageFile) { if (!File.Exists(specFile) || !File.Exists(packageFile)) { throw new FileNotFoundException("Could not find the spec file or package file. Make sure you have published the SCPNet topology project."); } var specFileInfo = new FileInfo(specFile); var resourceFileInfo = new FileInfo(packageFile); string action = string.Format("{0}", "TopologySubmit"); HttpClientHandler handler = new HttpClientHandler() { Credentials = new NetworkCredential() { UserName = clusterUsername, Password = clusterPassword } }; var sb = new StringBuilder(); using (var client = new HttpClient(handler)) { client.BaseAddress = new Uri(clusterUrl); var wc = new WebClient(); string url = string.Format(SCPAPI_Format_String, action); var multipart = new MultipartFormDataContent(); var specFileContent = new FileContent(specFileInfo.FullName); specFileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = specFileInfo.Name }; var resourceFileContent = new FileContent(resourceFileInfo.FullName); resourceFileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = resourceFileInfo.Name }; multipart.Add(specFileContent); multipart.Add(resourceFileContent); HttpResponseMessage response = client.PostAsync(url, multipart).Result; sb.AppendLine("Response StatusCode: " + response.StatusCode); string responseBody = await response.Content.ReadAsStringAsync(); sb.AppendLine("Response Content: "); var unescapedResponseBody = Regex.Unescape(responseBody); sb.AppendLine(unescapedResponseBody); if (response.StatusCode != HttpStatusCode.Created) { sb.AppendLine( String.Format( "Topology submission did return 'Created' status code. " + "SpecFile: {0}, StatusCode: {1}", specFile, response.StatusCode)); throw new ApplicationException(sb.ToString()); } } return(sb.ToString()); }
public static async Task<string> TopologySubmit(string clusterUrl, string clusterUsername, string clusterPassword, string specFile, string packageFile) { if (!File.Exists(specFile) || !File.Exists(packageFile)) { throw new FileNotFoundException("Could not find the spec file or package file. Make sure you have published the SCPNet topology project."); } var specFileInfo = new FileInfo(specFile); var resourceFileInfo = new FileInfo(packageFile); string action = string.Format("{0}", "TopologySubmit"); HttpClientHandler handler = new HttpClientHandler() { Credentials = new NetworkCredential() { UserName = clusterUsername, Password = clusterPassword } }; var sb = new StringBuilder(); using (var client = new HttpClient(handler)) { client.BaseAddress = new Uri(clusterUrl); var wc = new WebClient(); string url = string.Format(SCPAPI_Format_String, action); var multipart = new MultipartFormDataContent(); var specFileContent = new FileContent(specFileInfo.FullName); specFileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = specFileInfo.Name }; var resourceFileContent = new FileContent(resourceFileInfo.FullName); resourceFileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = resourceFileInfo.Name }; multipart.Add(specFileContent); multipart.Add(resourceFileContent); HttpResponseMessage response = client.PostAsync(url, multipart).Result; sb.AppendLine("Response StatusCode: " + response.StatusCode); string responseBody = await response.Content.ReadAsStringAsync(); sb.AppendLine("Response Content: "); var unescapedResponseBody = Regex.Unescape(responseBody); sb.AppendLine(unescapedResponseBody); if (response.StatusCode != HttpStatusCode.Created) { sb.AppendLine( String.Format( "Topology submission did return 'Created' status code. " + "SpecFile: {0}, StatusCode: {1}", specFile, response.StatusCode)); throw new ApplicationException(sb.ToString()); } } return sb.ToString(); }