//public static string AADToken; public Task SWScan() { Intune_API oAPI = new Intune_API(); var tSWScan = Task.Run(() => { scan(oAPI); OnUpdScanCompleted(this, new EventArgs()); OnSWScanCompleted(this, new EventArgs()); }); return(tSWScan); }
internal void scan(Intune_API oAPI) { try { var lIDs = oAPI.getRZIDs(); //File.AppendAllLines(Environment.ExpandEnvironmentVariables("%TEMP%\\dbg.txt"), new string[] { "Repository-Items:" + SoftwareRepository.Count.ToString() }); #if DEBUG System.IO.File.AppendAllLines(Environment.ExpandEnvironmentVariables("%TEMP%\\RZDebug.txt"), new string[] { DateTime.Now.ToString() + ";S0;" + "RZItems detected: ", lIDs.Count.ToString() }); #endif #if DEBUG System.IO.File.AppendAllLines(Environment.ExpandEnvironmentVariables("%TEMP%\\RZDebug.txt"), new string[] { DateTime.Now.ToString() + ";S0;" + "Repository Items: ", SoftwareRepository.Count().ToString() }); #endif foreach (Intune_API.GraphRZ RZSW in lIDs) { try { if (SoftwareRepository.Count(t => t.SWId == RZSW.RZID) == 0) { //File.AppendAllLines(Environment.ExpandEnvironmentVariables("%TEMP%\\dbg.txt"), new string[] { "not match, IconId:" + SQLRZ.RZID.ToString() }); var oSW = SoftwareRepository.FirstOrDefault(t => t.ShortName == RZSW.Shortname); if (oSW != null) { AddSoftware oNew = new AddSoftware() { ProductName = oSW.ProductName, ProductVersion = oSW.ProductVersion, Manufacturer = oSW.Manufacturer, ShortName = oSW.ShortName, Description = oSW.Description, SWId = oSW.SWId, IconHash = oSW.IconHash, MSIProductID = RZSW.Version }; //if (RZSW.Bootstrap) // oNew.Author = "BootstrapTrue"; //else // oNew.Author = "BootstrapFalse"; #if DEBUG System.IO.File.AppendAllLines(Environment.ExpandEnvironmentVariables("%TEMP%\\RZDebug.txt"), new string[] { DateTime.Now.ToString() + ";S1;" + "New SWVersion: ", oNew.ProductName, oNew.ProductVersion, oNew.MSIProductID }); #endif NewSoftwareVersions.Add(oNew); } } else { try { var oSW = SoftwareRepository.FirstOrDefault(t => t.SWId == RZSW.RZID); if (oSW != null) { try { AddSoftware oExisting = new AddSoftware() { ProductName = oSW.ProductName, ProductVersion = oSW.ProductVersion, Manufacturer = oSW.Manufacturer, ShortName = oSW.ShortName, Description = oSW.Description, IconHash = oSW.IconHash, SWId = oSW.SWId }; //if (RZSW.Bootstrap) // oExisting.Author = "BootstrapTrue"; //else // oExisting.Author = "BootstrapFalse"; #if DEBUG System.IO.File.AppendAllLines(Environment.ExpandEnvironmentVariables("%TEMP%\\RZDebug.txt"), new string[] { DateTime.Now.ToString() + ";S2;" + "Installed SWVersion: ", oExisting.ProductName, oExisting.ProductVersion }); #endif InstalledSoftware.Add(oExisting); } catch { } } } catch { } } } catch (Exception ex) { System.IO.File.AppendAllLines(Environment.ExpandEnvironmentVariables("%TEMP%\\RZError.txt"), new string[] { DateTime.Now.ToString() + ";F1814E1" + ex.Message }); } } //Cleanup SW where new Version already exists foreach (var oSW in InstalledSoftware) { NewSoftwareVersions.RemoveAll(t => t.ShortName == oSW.ShortName); } } catch (Exception ex) { System.IO.File.AppendAllLines(Environment.ExpandEnvironmentVariables("%TEMP%\\RZError.txt"), new string[] { DateTime.Now.ToString() + ";F1845E1" + ex.Message }); } OnUpdScanCompleted(this, new EventArgs()); OnSWScanCompleted(this, new EventArgs()); }
public async Task <bool> InstallCM(bool Force = false, bool Retry = false) { try { downloadTask.Downloading = false; downloadTask.Installing = true; ProgressDetails(downloadTask, EventArgs.Empty); //Check if RuckZuckis running... try { using (var mutex = Mutex.OpenExisting(@"Global\RuckZuckCM")) { if (Retry) { Thread.Sleep(new TimeSpan(0, 0, 2)); } else { return(false); } } GC.Collect(); } catch { } bool bMutexCreated = false; using (Mutex mutex = new Mutex(false, "Global\\RuckZuckCM", out bMutexCreated)) { Intune_API oAPI = new Intune_API(); ProgressDetails(downloadTask, EventArgs.Empty); bool bBootStrap = false; if (!string.IsNullOrEmpty(SW.Author)) { if (SW.Author == "BootstrapTrue") { bBootStrap = true; } } oAPI.RuckZuckSync(SW, this.downloadTask, bBootStrap); //downloadTask.Installed = true; downloadTask.Installing = false; ProgressDetails(downloadTask, EventArgs.Empty); if (bMutexCreated) { mutex.Close(); } } GC.Collect(); } catch (Exception ex) { downloadTask.Status = ""; downloadTask.Installing = false; downloadTask.Downloading = false; downloadTask.Error = true; downloadTask.ErrorMessage = ex.Message; ProgressDetails(downloadTask, EventArgs.Empty); return(false); } return(true); }