public void checkDeploymentStatus(SDeployInfo deployInfo) { //forever: user can cancel checking at any time while (true) { int status = -2; try { status = deployInfo.proxy.GetInstallationStatus(deployInfo.installId); } catch (Exception) { } if (status == 0) { break; } if (status == -2) { Thread.Sleep(1000); continue; } throw new Exception("UploadAndInstallMsiFile failed." + status.ToString()); } }
public SDeployInfo uploadAndInstallMsi(string adminPassword, string msiPath) { Stream fileStream = null; SDeployInfo deployInfo = new SDeployInfo(); try { if (string.IsNullOrEmpty(_publicDns) == true) { getSiteUrl(); } // // Get administrator's password // string password = adminPassword; if (string.IsNullOrEmpty(password) == true) { password = getAdministratorPassord(); if (string.IsNullOrEmpty(password)) { throw new Exception("Invalid password."); } } //user can cancel the thread if wanted. while (true) { try { downloadAndInstallCertificate(); break; } catch (Exception) { Thread.Sleep(1000); continue; } } string fileName; if (string.IsNullOrEmpty(msiPath) == true) { // // Get the MSI file // OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "MSI files (*.msi)|*.msi"; ofd.Title = "Select your setup program to install on EC2 instance:"; if (DialogResult.OK != ofd.ShowDialog()) { throw new Exception("Error: open file dialog failed"); } fileName = Path.GetFileName(ofd.FileName); fileStream = ofd.OpenFile(); } else { fileStream = File.OpenRead(msiPath); fileName = Path.GetFileName(msiPath); } if (fileStream == null) { throw new Exception("Error: failed to open selected file"); } byte[] fileBytes = new byte[fileStream.Length]; fileStream.Read(fileBytes, 0, (int)fileStream.Length); // // Create the web service proxy // deployInfo.proxy = new Ec2FileUploadProxy.Ec2FileUpload(); deployInfo.proxy.Url = "https://" + _publicDns + "/ec2fileupload/ec2fileupload.asmx"; // // Get client credentials // CredentialCache cache = new CredentialCache(); cache.Add( new Uri(deployInfo.proxy.Url), "Basic", new NetworkCredential("administrator", password)); deployInfo.proxy.Credentials = cache; // // Call the web service // while (true) { try { deployInfo.installId = deployInfo.proxy.UploadAndInstallMsiFile( fileName, Convert.ToBase64String(fileBytes)); break; } catch (Exception) { } } if (string.IsNullOrEmpty(deployInfo.installId) == true) { throw new Exception("Error: UploadAndInstallMsiFile failed."); } } catch (Exception ex) { throw new Exception("UploadAndInstallMsi fails." + ex.Message); } finally { if (fileStream != null) { fileStream.Close(); } } return(deployInfo); }
public SDeployInfo uploadAndInstallMsi(string adminPassword, string msiPath) { Stream fileStream = null; SDeployInfo deployInfo = new SDeployInfo(); try { if (string.IsNullOrEmpty(_publicDns) == true) getSiteUrl(); // // Get administrator's password // string password = adminPassword; if (string.IsNullOrEmpty(password) == true) { password = getAdministratorPassord(); if (string.IsNullOrEmpty(password)) { throw new Exception("Invalid password."); } } //user can cancel the thread if wanted. while (true) { try { downloadAndInstallCertificate(); break; } catch (Exception) { Thread.Sleep(1000); continue; } } string fileName; if (string.IsNullOrEmpty(msiPath) == true) { // // Get the MSI file // OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "MSI files (*.msi)|*.msi"; ofd.Title = "Select your setup program to install on EC2 instance:"; if (DialogResult.OK != ofd.ShowDialog()) { throw new Exception("Error: open file dialog failed"); } fileName = Path.GetFileName(ofd.FileName); fileStream = ofd.OpenFile(); } else { fileStream = File.OpenRead(msiPath); fileName = Path.GetFileName(msiPath); } if (fileStream == null) { throw new Exception("Error: failed to open selected file"); } byte[] fileBytes = new byte[fileStream.Length]; fileStream.Read(fileBytes, 0, (int)fileStream.Length); // // Create the web service proxy // deployInfo.proxy = new Ec2FileUploadProxy.Ec2FileUpload(); deployInfo.proxy.Url = "https://" + _publicDns + "/ec2fileupload/ec2fileupload.asmx"; // // Get client credentials // CredentialCache cache = new CredentialCache(); cache.Add( new Uri(deployInfo.proxy.Url), "Basic", new NetworkCredential("administrator", password)); deployInfo.proxy.Credentials = cache; // // Call the web service // while (true) { try { deployInfo.installId = deployInfo.proxy.UploadAndInstallMsiFile( fileName, Convert.ToBase64String(fileBytes)); break; } catch (Exception) { } } if (string.IsNullOrEmpty(deployInfo.installId) == true) { throw new Exception("Error: UploadAndInstallMsiFile failed."); } } catch (Exception ex) { throw new Exception("UploadAndInstallMsi fails." + ex.Message); } finally { if (fileStream != null) fileStream.Close(); } return deployInfo; }