public async Task <bool> GetSWRepository(string RepositoryPath) { //var tGetSWRepo = bool bResult = await Task.Run(() => { try { //var oDB = RZRestAPI.SWResults("").Distinct().OrderBy(t => t.Shortname).ThenByDescending(t => t.ProductVersion).ThenByDescending(t => t.ProductName).ToList(); DirectoryInfo dInfo = new DirectoryInfo(RepositoryPath); foreach (FileInfo dFile in dInfo.GetFiles("*.xml", SearchOption.AllDirectories)) { try { var oAddRemSW = RZUpdater.ParseXML(dFile.FullName); string sFile = dFile.DirectoryName + "\\" + oAddRemSW.ContentID + ".png"; if (!File.Exists(sFile)) { byte[] image = oAddRemSW.Image; MemoryStream ms = new MemoryStream(image); Image img = Image.FromStream(ms); img.Save(dFile.DirectoryName + "\\" + oAddRemSW.ContentID + ".png", System.Drawing.Imaging.ImageFormat.Png); } SoftwareRepository.Add(new GetSoftware() { ProductName = oAddRemSW.ProductName, Description = oAddRemSW.Description, Categories = (oAddRemSW.Category ?? "Local Repository").Split(';').ToList(), isInstalled = false, Manufacturer = oAddRemSW.Manufacturer, ProductURL = oAddRemSW.ProductURL, ProductVersion = oAddRemSW.ProductVersion, Shortname = oAddRemSW.ProductName + " (" + oAddRemSW.Architecture + ")", Downloads = 0, IconId = 0, IconFile = sFile, XMLFile = dFile.FullName, Quality = 100 }); } catch { } } /*lock (SoftwareRepository) * { * SoftwareRepository = oDB.Select(item => new GetSoftware() * { * Categories = item.Categories.ToList(), * Description = item.Description, * Downloads = item.Downloads, * IconId = item.IconId, * Image = item.Image, * Manufacturer = item.Manufacturer, * ProductName = item.ProductName, * ProductURL = item.ProductURL, * ProductVersion = item.ProductVersion, * Quality = item.Quality, * Shortname = item.Shortname * }).ToList(); * }*/ } catch (Exception ex) { Debug.WriteLine(ex.Message.ToString()); } OnSWRepoLoaded(this, new EventArgs()); return(true); }); return(bResult); }
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 (!string.IsNullOrEmpty(dgr.XMLFile)) { if (System.IO.File.Exists(dgr.XMLFile)) { oSW = new SWUpdate(RZUpdater.ParseXML(dgr.XMLFile)); oSW.SendFeedback = false; } } 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()); } }