/// <summary> /// Request uninstall to package manager /// </summary> /// <param name="device">Jedi device</param> /// <param name="hpkfile">Hpk file Information</param> public void UninstallPackage(JediDevice device, HpkFileInfo hpkfile) { Uri delete_packages_uri = new Uri($"https://{device.Address}/hp/device/webservices/ext/pkgmgt/installer/uninstall?uuid={hpkfile.Uuid}&clientId=ciGallery"); ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; HttpClientHandler httphandler = new HttpClientHandler(); httphandler.Credentials = new NetworkCredential("admin", device.AdminPassword); var client = new HttpClient(httphandler); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, delete_packages_uri); try { using (HttpResponseMessage message = client.SendAsync(request).Result) { string s = message.Content.ReadAsStringAsync().Result; } } catch (Exception ex) { Logger.LogError(ex.Message + $"Device : {device.Address}"); throw ex; } }
private void delete_button_Click(object sender, EventArgs e) { if (_SelectedHpkInstall == null || _selectedRow == null) { return; } string name = string.Empty; string uuid = string.Empty; string path = string.Empty; var row = hpkInstallGridView.CurrentRow; if (row == null) { return; } name = row.Cells[0].Value.ToString(); uuid = row.Cells[1].Value.ToString(); path = row.Cells[2].Value.ToString(); _SelectedHpkInstall = _hpkInstallList.InstallFileList.FirstOrDefault(x => x.PackageName == name && x.Uuid == uuid && x.FilePath == path); _viewList.Remove(_viewList.FirstOrDefault(x => x.PackageName == _SelectedHpkInstall.PackageName && x.Uuid == _SelectedHpkInstall.Uuid && x.FilePath == _SelectedHpkInstall.FilePath)); _hpkInstallList.InstallFileList.Remove(_SelectedHpkInstall); _SelectedHpkInstall = null; _selectedRow = null; hpkInstallTableDataBindingSource.ResetBindings(false); validate_configurationData(); }
/// <summary> /// Control the installation process. /// </summary> /// <param name="hpkfile">Hpk file infomation</param> /// <param name="device">Jedi device</param> /// <param name="assetInfo">Asset information</param> /// <param name="pluginData">Plugin execution data</param> /// <returns></returns> public bool UpdateHpk(HpkFileInfo hpkfile, JediDevice device, AssetInfo assetInfo, PluginExecutionData pluginData) { bool success = false; int count = 0; DeviceConfigResultLog log = new DeviceConfigResultLog(pluginData, assetInfo.AssetId); string progressState = null; try { while (success == false && count < RetryCount) { if (InstallPackage(device, hpkfile)) { progressState = TrackPackage(device, hpkfile); while (progressState == "psInProgress" || progressState == "404 Not Found" || progressState == "503 Service Unavailable" || string.IsNullOrEmpty(progressState)) { Thread.Sleep(3000); progressState = TrackPackage(device, hpkfile); } if (progressState == "psCompleted") { success = true; } else if (progressState == "psFailed") { success = false; } else { success = false; } } else { success = false; Thread.Sleep(10000); } count++; } } catch (Exception ex) { Logger.LogError($"Failed to install HPK : (Device:{device.Address}){hpkfile.PackageName}, {ex.Message}, progressState = {progressState}"); _failedSettings.AppendLine($"Failed to install HPK: (Device:{device.Address}){hpkfile.PackageName}, {ex.Message}"); success = false; } log.FieldChanged = hpkfile.PackageName; log.Result = success ? "Passed" : "Failed"; log.Value = "HpkInstall Values"; log.ControlChanged = $@"HpkInstall :{hpkfile.PackageName}"; ExecutionServices.DataLogger.Submit(log); return(success); }
/// <summary> /// Tracking state of installation /// </summary> /// <param name="device">Jedi device</param> /// <param name="hpkfile">Hpk file information</param> /// <returns></returns> public string TrackPackage(JediDevice device, HpkFileInfo hpkfile) { Uri track_install_uri = new Uri($"https://{device.Address}/hp/device/webservices/ext/pkgmgt/installer/install/{hpkfile.Uuid}"); ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; HttpClientHandler httphandler = new HttpClientHandler(); httphandler.Credentials = new NetworkCredential("admin", device.AdminPassword); var client = new HttpClient(httphandler); try { using (HttpResponseMessage message = client.GetAsync(track_install_uri).Result) { string s = message.Content.ReadAsStringAsync().Result; if (s.Contains("psInProgress")) { return("psInProgress"); } else if (s.Contains("psCompleted")) { return("psCompleted"); } else if (s.Contains("psFailed")) { return("psFailed"); } else if (s.Contains("404 Not Found")) { return("404 Not Found"); } else if (s.Contains("503 Service Unavailable")) { return("503 Service Unavailable"); } else { Logger.LogError($"TrackPackage unknown state error:{device.Address}:{hpkfile.PackageName}:{s}"); return(null); } } } catch (AggregateException ex) { Logger.LogError(ex.Message + $"Device : {device.Address}"); return(null); } catch (Exception ex) { Logger.LogError(ex.Message + $"Device : {device.Address}"); throw ex; } }
/// <summary> /// Check the package is already installed /// </summary> /// <param name="device">Jedi device</param> /// <param name="hpkfile">Hpk file information</param> /// <param name="installedPackages">List of installed packages</param> /// <returns></returns> public bool isExistPackage(JediDevice device, HpkFileInfo hpkfile, List <DevicePackageInfo> installedPackages) { string fileName = hpkfile.FilePath.Split('\\').Last(); foreach (DevicePackageInfo p in installedPackages) { if (p.installedFileName.Split('.').First() == fileName.Split('.').First()) { Console.WriteLine($"{hpkfile.FilePath.Split('\\').Last()}({device.Address}) is already installed"); return(true); } } return(false); }
private void PopulateHpkInstallOptions(object sender, EventArgs e) { var row = hpkInstallGridView.CurrentRow; if (row == null) { return; } var name = row.Cells[0].Value.ToString(); var uuid = row.Cells[1].Value.ToString(); var path = row.Cells[2].Value.ToString(); _selectedRow = _viewList.FirstOrDefault(x => x.PackageName == name && x.Uuid == uuid && x.FilePath == path); _SelectedHpkInstall = _hpkInstallList.InstallFileList.FirstOrDefault(x => x.PackageName == name && x.Uuid == uuid && x.FilePath == path); }
private void open_Button_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "HPK file | *.hpk"; ofd.Title = "Select HPK file"; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { openedHpkFileInfo = new HpkFileInfo(ofd); field1_Textbox.Text = openedHpkFileInfo.PackageName; field2_Textbox.Text = openedHpkFileInfo.Uuid; field3_Textbox.Text = openedHpkFileInfo.FilePath; } }
/// <summary> /// Request install to package manager /// </summary> /// <param name="device">Jedi device</param> /// <param name="hpkfile">Hpk file information</param> /// <returns></returns> public bool InstallPackage(JediDevice device, HpkFileInfo hpkfile) { Uri install_packages_uri = new Uri($"https://{device.Address}/hp/device/webservices/ext/pkgmgt/installer/install?clientId=ciJamc&installSource=isStandardRepository&forceInstall=true&acceptPermissions=true"); ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; HttpClientHandler httphandler = new HttpClientHandler(); httphandler.Credentials = new NetworkCredential("admin", device.AdminPassword); httphandler.PreAuthenticate = true; var client = new HttpClient(httphandler); client.Timeout = TimeSpan.FromSeconds(110); client.DefaultRequestHeaders.ExpectContinue = false; client.DefaultRequestHeaders.Connection.Clear(); client.DefaultRequestHeaders.ConnectionClose = true; // true = keepalive off ByteArrayContent fileContent = new ByteArrayContent(System.IO.File.ReadAllBytes(hpkfile.FilePath)); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data"); fileContent.Headers.ContentDisposition.Name = "\"file\""; fileContent.Headers.ContentDisposition.FileName = "\"" + hpkfile.PackageName + "\""; fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.hp.package-archive"); MultipartFormDataContent content = new MultipartFormDataContent(); content.Add(fileContent); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, install_packages_uri); request.Content = content; try { using (HttpResponseMessage message = client.SendAsync(request).Result) { //string s = message.Content.ReadAsStringAsync().Result; string s = message.Headers.Location.ToString(); if (s.Contains(hpkfile.Uuid)) { return(true); } else { return(false); } } } catch (WebException ex) { Logger.LogError(ex.Message + $"Device : {device.Address}"); return(false); } catch (HttpRequestException ex) { Logger.LogError(ex.Message + $"Device : {device.Address}"); return(false); } catch (SocketException ex) { Logger.LogError(ex.Message + $"Device : {device.Address}"); return(false); } catch (AggregateException ex) { Logger.LogError(ex.Message + $"Device : {device.Address}"); return(false); } catch (Exception ex) { Logger.LogError($"InstallPackage Error : {hpkfile.PackageName}, {ex.Message}"); _failedSettings.AppendLine($"InstallPackage Error: {hpkfile.PackageName}, {ex.Message}"); throw ex; } }