private void miSendFeedback_Click(object sender, RoutedEventArgs e) { if (lvSW.SelectedItems.Count > 0) { try { GetSoftware oSelectedItem = ((GetSoftware)lvSW.SelectedItem); var vDB = Task.Run(() => { try { AnonymousDelegate update = delegate() { FeedbackForm oFeedBack = new FeedbackForm(); oFeedBack.Title = oSelectedItem.ProductName + " " + oSelectedItem.ProductVersion; oFeedBack.ShowDialog(); if (oFeedBack.hasFeedback) { RZRestAPI.Feedback(oSelectedItem.ProductName, oSelectedItem.ProductVersion, oSelectedItem.Manufacturer, "", oFeedBack.isWorking.ToString(), Properties.Settings.Default.UserKey, oFeedBack.tbFeedback.Text).ConfigureAwait(false);; } }; Dispatcher.Invoke(update); } catch { } }); } catch { } } }
private void btInstall_Click(object sender, RoutedEventArgs e) { if (lvSW.SelectedItem != null) { Mouse.OverrideCursor = Cursors.Wait; try { foreach (var oItem in lvSW.SelectedItems) { try { //string sPS = ""; string sProdName = ""; string sProdVersion = ""; string sManuf = ""; if (oItem.GetType() == typeof(GetSoftware)) { GetSoftware dgr = oItem as GetSoftware; sProdName = dgr.ProductName; sProdVersion = dgr.ProductVersion; sManuf = dgr.Manufacturer; } bool bInstalled = false; foreach (var DT in RZRestAPI.GetSWDefinitions(sProdName, sProdVersion, sManuf)) { //Check PreReqs try { if (!string.IsNullOrEmpty(DT.PSPreReq) & !bInstalled) { if (!(bool)oAgent.Client.GetObjectsFromPS(DT.PSPreReq, true, new TimeSpan(0, 0, 0))[0].BaseObject) { //PreReq not match continue; } else { //Check if already installed if ((bool)oAgent.Client.GetObjectsFromPS(DT.PSDetection, true, new TimeSpan(0, 0, 0))[0].BaseObject) { MessageBox.Show("Software is already installed.", "Installation Status:", MessageBoxButton.OK, MessageBoxImage.Information); bInstalled = true; continue; } //Create target Folder oAgent.Client.GetStringFromPS("$Folder = join-path $env:TEMP '" + DT.ContentID + "'; New-Item -ItemType Directory -Force -Path $Folder -ErrorAction SilentlyContinue | Out-Null", true); //Download Files foreach (var File in DT.Files) { if (!File.URL.StartsWith("http", StringComparison.InvariantCultureIgnoreCase) & !File.URL.StartsWith("ftp", StringComparison.InvariantCultureIgnoreCase)) { try { File.URL = oAgent.Client.GetStringFromPS(File.URL); } catch { } } oAgent.Client.GetStringFromPS("$Folder = join-path $env:TEMP '" + DT.ContentID + "'; $Target = join-path $Folder '" + File.FileName + "' ;Invoke-WebRequest '" + File.URL + "' -MaximumRedirection 2 -OutFile $Target -UserAgent 'chocolatey command line' ", true); } //Install string sInst = "Set-Location -Path $Folder -ErrorAction SilentlyContinue; "; if (!string.IsNullOrEmpty(DT.PSPreInstall)) { sInst = sInst + "Invoke-Expression " + DT.PSPreInstall + " | Out-Null; "; } if (!string.IsNullOrEmpty(DT.PSInstall)) { sInst = sInst + "Invoke-Expression " + DT.PSInstall + " | Out-Null; "; } if (!string.IsNullOrEmpty(DT.PSPostInstall)) { sInst = sInst + "Invoke-Expression " + DT.PSPostInstall + " | Out-Null; "; } string sRes = oAgent.Client.GetStringFromPS(sInst, true); //Check if installed if ((bool)oAgent.Client.GetObjectsFromPS(DT.PSDetection, true, new TimeSpan(0, 0, 0))[0].BaseObject) { RZRestAPI.Feedback(DT.ProductName, DT.ProductVersion, DT.Manufacturer, DT.Architecture, "true", "SCCMCliCtr", "Ok...").ConfigureAwait(false); MessageBox.Show("Software installed successfully.", "Installation Status:", MessageBoxButton.OK, MessageBoxImage.Information); bInstalled = true; continue; } else { MessageBox.Show("Software installation failed.. " + sRes, "Installation Status:", MessageBoxButton.OK, MessageBoxImage.Warning); } } } } catch { } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } catch { } Mouse.OverrideCursor = null; } }
static void Main(string[] args) { MessagingFactory messageFactory; NamespaceManager namespaceManager; //TopicClient myTopicClient; System.Net.ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; System.Net.ServicePointManager.CheckCertificateRevocationList = false; Console.Write("Connecting ServiceBus..."); string sConnString = Properties.Settings.Default.ConnectionString; messageFactory = MessagingFactory.CreateFromConnectionString(sConnString); namespaceManager = NamespaceManager.CreateFromConnectionString(sConnString); if (namespaceManager == null) { Console.WriteLine("\nUnexpected Error"); return; } string TopicName = Properties.Settings.Default.TopicName; if (!namespaceManager.TopicExists(TopicName)) { namespaceManager.CreateTopic(TopicName); } Console.WriteLine("... connected."); if (!namespaceManager.SubscriptionExists(TopicName, string.Format(Properties.Settings.Default.Filtername, Environment.MachineName))) { SqlFilter dashboardFilter = new SqlFilter(Properties.Settings.Default.SQLFilter); namespaceManager.CreateSubscription(TopicName, string.Format(Properties.Settings.Default.Filtername, Environment.MachineName), dashboardFilter); return; } string sLastPackage = ""; var Client = messageFactory.CreateSubscriptionClient(TopicName, string.Format(Properties.Settings.Default.Filtername, Environment.MachineName), ReceiveMode.PeekLock); Client.OnMessage((message) => { try { /*if (message.Label.Contains(@"Feedback/failure")) * Console.ForegroundColor = ConsoleColor.Red; * if (message.Label.Contains(@"Feedback/success")) * Console.ForegroundColor = ConsoleColor.Green;*/ //Console.WriteLine(message.EnqueuedTimeUtc.ToLocalTime().ToString("HH:mm") + " " + message.Properties["WorkerServiceHost"].ToString() + "(" + message.Properties["Queue"].ToString() + ") : " + message.Properties["TargetComputer"].ToString() + " : " + message.GetBody<string>()); //Console.WriteLine(message.EnqueuedTimeUtc.ToLocalTime().ToString("HH:mm") + " " + message.Label + " " + message.GetBody<string>()); try { /*if (message.Properties["IP"].ToString() == "193.5.178.34") * { * message.Abandon(); * return; * } * if (message.Properties["ProductName"].ToString() == "Adobe Acrobat Reader DC") * { * message.Abandon(); * return; * } * if (message.Properties["ProductName"].ToString() == "Adobe Acrobat Reader DC MUI") * { * message.Abandon(); * return; * }*/ RZUpdater oRZSW = new RZUpdater(); oRZSW.SoftwareUpdate = new SWUpdate(message.Properties["ProductName"].ToString(), message.Properties["ProductVersion"].ToString(), message.Properties["Manufacturer"].ToString()); //oRZSW.SoftwareUpdate = new SWUpdate(message.Properties["ProductName"].ToString()); if (sLastPackage != oRZSW.SoftwareUpdate.SW.Shortname) { oRZSW.SoftwareUpdate = new SWUpdate(oRZSW.SoftwareUpdate.SW.Shortname); oRZSW.SoftwareUpdate.SendFeedback = false; //we already process feedback... if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName)) { Console.WriteLine("Error: ProductName not valid... " + message.Properties["ProductName"].ToString()); message.Abandon(); //Console.WriteLine("Error: Product not found in Repository..."); } else { Console.WriteLine(oRZSW.SoftwareUpdate.SW.Manufacturer + " " + oRZSW.SoftwareUpdate.SW.ProductName + " " + oRZSW.SoftwareUpdate.SW.ProductVersion); Console.Write("Downloading..."); foreach (string sPreReq in oRZSW.SoftwareUpdate.SW.PreRequisites) { RZUpdater oRZSWPreReq = new RZUpdater(); oRZSWPreReq.SoftwareUpdate = new SWUpdate(sPreReq); Console.WriteLine(); Console.Write("\tDownloading dependencies (" + oRZSWPreReq.SoftwareUpdate.SW.Shortname + ")..."); if (oRZSWPreReq.SoftwareUpdate.Download().Result) { Console.WriteLine("... done."); Console.Write("\tInstalling dependencies (" + oRZSWPreReq.SoftwareUpdate.SW.Shortname + ")..."); if (oRZSWPreReq.SoftwareUpdate.Install(false, true).Result) { Console.WriteLine("... done."); } else { Console.WriteLine("... Error. The installation failed."); } } } if (oRZSW.SoftwareUpdate.Download().Result) { Console.WriteLine("... done."); Console.Write("Installing..."); if (oRZSW.SoftwareUpdate.Install(false, true).Result) { Console.WriteLine("... done."); message.Complete(); RZRestAPI.Feedback(oRZSW.SoftwareUpdate.SW.ProductName, oRZSW.SoftwareUpdate.SW.ProductVersion, oRZSW.SoftwareUpdate.SW.Manufacturer, "true", "RZBot", "ok..").Wait(3000); sLastPackage = DateTime.Now.Ticks.ToString();; //return 0; } else { Console.WriteLine("... Error. Installation failed."); sLastPackage = oRZSW.SoftwareUpdate.SW.Shortname; message.Abandon(); //return 1603; } } else { Console.WriteLine("... Error. Download failed."); sLastPackage = oRZSW.SoftwareUpdate.SW.Shortname; message.Abandon(); //return 1602; } } } else { Console.WriteLine("... retry later.."); Thread.Sleep(5000); //message.Abandon(); // retry later.... } } catch { message.Abandon(); } Console.ResetColor(); } catch { } }); Console.ReadLine(); }