private void InstallSW(List <AddSoftware> lSW) { foreach (AddSoftware oItem in lSW) { try { SWUpdate oSW = new SWUpdate(oItem); oSW.GetInstallType(); oSW.SW.Author = oItem.Author; //Author is used to store the Bootstrap flag if (dm.lDLTasks.FirstOrDefault(t => t.ProductName == oSW.SW.ProductName) == null) { oSW.ProgressDetails += OSW_ProgressDetails; oSW.downloadTask.AutoInstall = true; oSW.Download(false).ConfigureAwait(false); dm.lDLTasks.Add(oSW.downloadTask); if (oSW.SW.PreRequisites != null) { foreach (string sPreReq in oSW.SW.PreRequisites) { try { SWUpdate oPreReq = new SWUpdate(sPreReq); oPreReq.GetInstallType(); if (dm.lDLTasks.FirstOrDefault(t => t.ProductName == oPreReq.SW.ProductName) == null) { oPreReq.ProgressDetails += OSW_ProgressDetails; oPreReq.downloadTask.AutoInstall = true; oPreReq.Download(false).ConfigureAwait(false); dm.lDLTasks.Add(oPreReq.downloadTask); } } catch { } } } } dm.Show(); } catch { } OnSWUpdated(this, new EventArgs()); } }
private void btInstall_Click(object sender, RoutedEventArgs e) { if (lvSW.SelectedItem != null) { tSearch.Stop(); try { foreach (var oItem in lvSW.SelectedItems) { try { SWUpdate oSW = null; if (oItem.GetType() == typeof(GetSoftware)) { GetSoftware dgr = oItem as GetSoftware; if (oSW == null) { oSW = new SWUpdate(dgr.ProductName, dgr.ProductVersion, dgr.Manufacturer); } if (oSW.SW == null) { dm.lDLTasks.Add(new DLTask() { ProductName = dgr.ProductName, ProductVersion = dgr.ProductVersion, Error = true, ErrorMessage = "Requirements not valid. Installation will not start." }); dm.Show(); continue; } } if (oItem.GetType() == typeof(AddSoftware)) { AddSoftware dgr = oItem as AddSoftware; //sPS = GetSWInstallPS(dgr.ProductName, dgr.ProductVersion, ""); oSW = new SWUpdate(dgr); if (oSW.SW == null) { dm.lDLTasks.Add(new DLTask() { ProductName = dgr.ProductName, ProductVersion = dgr.ProductVersion, Error = true, ErrorMessage = "Requirements not valid. Installation will not start." }); dm.Show(); continue; } } oSW.sUserName = Properties.Settings.Default.UserKey; try { var xRem = dm.lDLTasks.Where(x => x.ProductName == oSW.SW.ProductName && (x.Error || (x.PercentDownloaded == 100 && x.AutoInstall == false) || (x.Status == "Waiting" && x.DownloadedBytes == 0 && x.Downloading == false) || x.UnInstalled)).ToList(); foreach (var o in xRem) { try { dm.lDLTasks.Remove(o); } catch { } } //xRem.ForEach(x => lDLTasks.Remove(x)); } catch { } //Allow only one entry if (dm.lDLTasks.FirstOrDefault(t => t.ProductName == oSW.SW.ProductName) == null) { //oSW.Downloaded += OSW_Downloaded; oSW.ProgressDetails += OSW_ProgressDetails; oSW.downloadTask.AutoInstall = true; oSW.Download(false).ConfigureAwait(false);; dm.lDLTasks.Add(oSW.downloadTask); foreach (string sPreReq in oSW.SW.PreRequisites) { try { SWUpdate oPreReq = new SWUpdate(sPreReq); if (oPreReq.GetInstallType()) { oPreReq.sUserName = Properties.Settings.Default.UserKey; if (dm.lDLTasks.FirstOrDefault(t => t.ProductName == oPreReq.SW.ProductName) == null) { //oPreReq.Downloaded += OSW_Downloaded; oPreReq.ProgressDetails += OSW_ProgressDetails; oPreReq.downloadTask.AutoInstall = true; oPreReq.Download(false).ConfigureAwait(false);; dm.lDLTasks.Add(oPreReq.downloadTask); } } } catch { } } } dm.Show(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } catch { } OnSWUpdated(this, new EventArgs()); } }