예제 #1
0
        private static bool Install(RZUpdater oRZSW)
        {
            if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
            {
                oRZSW.SoftwareUpdate.GetInstallType();
                if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                {
                    Console.WriteLine("PreRequisites not valid for '" + oRZSW.SoftwareUpdate.SW.ShortName + "'...!");
                    return(false);
                }
            }


            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)
            {
                if (!string.IsNullOrEmpty(sPreReq))
                {
                    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, bRetry).Result)
                        {
                            Console.WriteLine("... done.");
                        }
                        else
                        {
                            Console.WriteLine("... Error. The installation failed.");
                            return(false);
                        }
                    }
                }
            }
            if (oRZSW.SoftwareUpdate.Download().Result)
            {
                Console.WriteLine("... done.");
                Console.Write("Installing...");
                if (oRZSW.SoftwareUpdate.Install(false, bRetry).Result)
                {
                    Console.WriteLine("... done.");
                    return(true);
                }
                else
                {
                    Console.WriteLine("... Error. The installation failed.");
                    return(false);
                }
            }

            return(false);
        }
예제 #2
0
        private void btOpenXML_Click(object sender, RoutedEventArgs e)
        {
            var ofd = new Microsoft.Win32.OpenFileDialog()
            {
                Filter = "RuckZuck Files|*.xml;*.json"
            };

            ofd.FileName = "";
            var result = ofd.ShowDialog();

            if (result != false)
            {
                RZUpdater oUpd = new RZUpdater(ofd.FileName);
                OpenXML(oUpd.SoftwareUpdate.SW);
            }
        }
예제 #3
0
        private void btTest_Click(object sender, RoutedEventArgs e)
        {
            string sTempFile = Path.Combine(Environment.ExpandEnvironmentVariables("%TEMP%"), Path.GetRandomFileName() + ".json");

            SaveAsJSON(sTempFile);

            if (!AttachConsole(-1)) // Attach to a parent process console
            {
                AllocConsole();     // Alloc a new console if none available
            }
            Thread thread = new Thread(() =>
            {
                Console.Clear();
                RZUpdater oRZSW = new RZUpdater(sTempFile);
                oRZSW.SoftwareUpdate.ProgressDetails += SoftwareUpdate_ProgressDetails;
                Console.WriteLine(oRZSW.SoftwareUpdate.SW.ProductName + " " + oRZSW.SoftwareUpdate.SW.ProductVersion + " :");

                Console.WriteLine("Downloading...");

                if (oRZSW.SoftwareUpdate.Download().Result)
                {
                    Console.WriteLine("Installing...");
                    if (oRZSW.SoftwareUpdate.Install(false, true).Result)
                    {
                        Console.WriteLine("done.");
                    }
                    else
                    {
                        Console.WriteLine("Error: The installation failed.");
                    }
                }

                try
                {
                    File.Delete(sTempFile);
                }
                catch { }

                oRZSW.SoftwareUpdate.ProgressDetails -= SoftwareUpdate_ProgressDetails;
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
예제 #4
0
        public void TestMethodDownloadUpdate()
        {
            Console.WriteLine("Check Update for SCCMCliCtr 1.0.3.9...");
            RZUpdater oRZSW   = new RZUpdater();
            var       oUpdate = oRZSW.CheckForUpdate("Adobe Acrobat Reader DC MUI", "19.021.20048", "Adobe Systems Incorporated");

            Console.WriteLine("found Version:" + oRZSW.SoftwareUpdate.SW.ProductVersion);
            Assert.IsNotNull(oUpdate, "Update detected successfully.");
            Assert.IsNotNull(oUpdate.SW.ContentID, "Update conatins ContentID");
            Console.Write("Downloading files..");
            bool bDLResult = oUpdate.Download().Result;

            Assert.IsTrue(bDLResult, "Files downloaded successfully.");
            if (bDLResult)
            {
                Console.WriteLine("..done.");
            }
            else
            {
                Console.WriteLine("download failed !!");
            }
        }
예제 #5
0
        public void TestMethodDownloadUpdate()
        {
            Console.WriteLine("Check Update for SCCMCliCtr 1.0.3.9...");
            RZUpdater oRZSW   = new RZUpdater();
            var       oUpdate = oRZSW.CheckForUpdate("Client Center for Configuration Manager", "1.0.3.9", "Zander Tools");

            Console.WriteLine("found Version:" + oRZSW.SoftwareUpdate.SW.ProductVersion);
            Assert.IsNotNull(oUpdate, "Update detected successfully.");
            Assert.IsNotNull(oUpdate.SW.ContentID, "Update conatins ContentID");
            Console.Write("Downloading files..");
            bool bDLResult = oUpdate.Download().Result;

            Assert.IsTrue(bDLResult, "Files downloaded successfully.");
            if (bDLResult)
            {
                Console.WriteLine("..done.");
            }
            else
            {
                Console.WriteLine("download failed !!");
            }
        }
예제 #6
0
        private void Connect()
        {
            try
            {
                connection.Stop();
                connection.Start().ContinueWith(task =>
                {
                    if (task.IsFaulted)
                    {
                        Console.WriteLine("There was an error opening the connection:{0}", task.Exception.GetBaseException());
                    }
                    else
                    {
                        //Obsolete
                        myHub.On <string, string>("getPS", (s1, s2) =>
                        {
                            //using (PowerShell PowerShellInstance = PowerShell.Create())
                            //{
                            //    try
                            //    {
                            //        PowerShellInstance.AddScript(s1);
                            //        var PSResult = PowerShellInstance.Invoke();
                            //        if (PSResult.Count() > 0)
                            //        {
                            //            string sResult = PSResult.Last().BaseObject.ToString();
                            //            if (sResult != sScriptResult) //obsolete from 1.0.07 -> returnPS
                            //            {
                            //                sScriptResult = sResult;
                            //                Random rnd = new Random();
                            //                tReInit.Interval = rnd.Next(1000, 10000); //wait max 10s to ReInit
                            //            }

                            //            myHub.Invoke<string>("Respond", s2, Environment.MachineName + ":" + sResult).ContinueWith(task1 =>
                            //            {
                            //                if (task1.IsFaulted)
                            //                {
                            //                    Console.WriteLine("There was an error calling send: {0}", task1.Exception.GetBaseException());
                            //                }
                            //            });
                            //        }
                            //    }
                            //    catch (Exception ex)
                            //    {
                            //        Console.WriteLine("There was an error: {0}", ex.Message);
                            //    }
                            //}

                            //Program.MinimizeFootprint();
                        });

                        myHub.On <string, string>("returnPS", (s1, s2) =>
                        {
                            TimeSpan timeout   = new TimeSpan(0, 5, 0); //default timeout = 5min
                            DateTime dStart    = DateTime.Now;
                            TimeSpan dDuration = DateTime.Now - dStart;

                            using (PowerShell PowerShellInstance = PowerShell.Create())
                            {
                                Trace.WriteLine(DateTime.Now.ToString() + "\t run PS... " + s1);
                                try
                                {
                                    PowerShellInstance.AddScript(s1);
                                    PSDataCollection <PSObject> outputCollection = new PSDataCollection <PSObject>();

                                    outputCollection.DataAdding += ConsoleOutput;
                                    PowerShellInstance.Streams.Error.DataAdding += ConsoleError;

                                    IAsyncResult async = PowerShellInstance.BeginInvoke <PSObject, PSObject>(null, outputCollection);
                                    while (async.IsCompleted == false || dDuration > timeout)
                                    {
                                        Thread.Sleep(200);
                                        dDuration = DateTime.Now - dStart;
                                        if (tReInit.Interval > 5000)
                                        {
                                            tReInit.Interval = 5000;
                                        }
                                    }

                                    //var PSResult = PowerShellInstance.Invoke();
                                    //if (PSResult.Count() > 0)
                                    //{
                                    //    string sResult = PSResult.Last().BaseObject.ToString();
                                    //    if (sResult != sScriptResult)
                                    //    {
                                    //        sScriptResult = sResult;
                                    //        Trace.WriteLine(" done. Result: " + sResult);
                                    //        Random rnd = new Random();
                                    //        tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max Xs to ReInit
                                    //    }
                                    //}
                                    //else
                                    //{
                                    //    Trace.WriteLine(" done. no result.");
                                    //}
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("There was an error: {0}", ex.Message);
                                }
                            }

                            Program.MinimizeFootprint();
                        });

                        //New 0.9.0.6
                        myHub.On <string, string>("returnPSAsync", (s1, s2) =>
                        {
                            Trace.WriteLine(DateTime.Now.ToString() + "\t run PS async... " + s1);
                            var tSWScan = Task.Run(() =>
                            {
                                using (PowerShell PowerShellInstance = PowerShell.Create())
                                {
                                    try
                                    {
                                        PowerShellInstance.AddScript(s1);
                                        var PSResult = PowerShellInstance.Invoke();
                                        if (PSResult.Count() > 0)
                                        {
                                            string sResult = PSResult.Last().BaseObject.ToString();

                                            if (!string.IsNullOrEmpty(sResult)) //Do not return empty results
                                            {
                                                if (sResult != sScriptResult)
                                                {
                                                    sScriptResult    = sResult;
                                                    Random rnd       = new Random();
                                                    tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max Xs to ReInit
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine("There was an error: {0}", ex.Message);
                                    }
                                }

                                Program.MinimizeFootprint();
                            });
                        });

                        myHub.On <string>("init", (s1) =>
                        {
                            try
                            {
                                Trace.Write(DateTime.Now.ToString() + "\t Agent init... ");
                                myHub.Invoke <string>("Init", Hostname).ContinueWith(task1 =>
                                {
                                });
                                Trace.WriteLine(" done.");
                            }
                            catch { }
                            try
                            {
                                foreach (string sGroup in Properties.Settings.Default.Groups.Split(';'))
                                {
                                    myHub.Invoke <string>("JoinGroup", sGroup).ContinueWith(task1 =>
                                    {
                                    });
                                }
                                Program.MinimizeFootprint();
                            }
                            catch { }
                        });

                        myHub.On <string>("reinit", (s1) =>
                        {
                            try
                            {
                                //Properties.Settings.Default.InventorySuccess = new DateTime();
                                //Properties.Settings.Default.HealthCheckSuccess = new DateTime();
                                //Properties.Settings.Default.Save();

                                Random rnd       = new Random();
                                tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit
                            }
                            catch { }
                        });

                        myHub.On <string>("status", (s1) =>
                        {
                            try
                            {
                                Trace.Write(DateTime.Now.ToString() + "\t send status...");
                                string sResult = "{}";
                                using (PowerShell PowerShellInstance = PowerShell.Create())
                                {
                                    try
                                    {
                                        PowerShellInstance.AddScript(Properties.Settings.Default.PSStatus);
                                        var PSResult = PowerShellInstance.Invoke();
                                        if (PSResult.Count() > 0)
                                        {
                                            sResult      = PSResult.Last().BaseObject.ToString();
                                            sResult      = sResult.Replace(Environment.MachineName, Hostname);
                                            JObject jRes = JObject.Parse(sResult);
                                            jRes.Add("ScriptResult", sScriptResult);
                                            jRes.Add("Groups", Properties.Settings.Default.Groups);
                                            sResult = jRes.ToString();
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(" There was an error: {0}", ex.Message);
                                    }
                                }

                                myHub.Invoke("Status", new object[] { Hostname, sResult }).ContinueWith(task1 =>
                                {
                                });
                                Trace.WriteLine(" done.");
                                Program.MinimizeFootprint();
                            }
                            catch (Exception ex)
                            {
                                Trace.Write(DateTime.Now.ToString() + " ERROR: " + ex.Message);
                            }
                        });

                        myHub.On <string>("version", (s1) =>
                        {
                            try
                            {
                                Trace.Write(DateTime.Now.ToString() + "\t Get Version... ");
                                //Get File-Version
                                sScriptResult = (FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location)).FileVersion.ToString();
                                Trace.WriteLine(sScriptResult);

                                Random rnd       = new Random();
                                tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit
                            }
                            catch (Exception ex)
                            {
                                Trace.Write(DateTime.Now.ToString() + " ERROR: " + ex.Message);
                            }
                        });

                        myHub.On <string>("wol", (s1) =>
                        {
                            try
                            {
                                if (!string.IsNullOrEmpty(s1))
                                {
                                    foreach (string sMAC in s1.Split(';'))
                                    {
                                        try
                                        {
                                            WOL.WakeUp(sMAC); //Send Broadcast

                                            //Send to local Gateway
                                            foreach (NetworkInterface f in NetworkInterface.GetAllNetworkInterfaces())
                                            {
                                                if (f.OperationalStatus == OperationalStatus.Up)
                                                {
                                                    foreach (GatewayIPAddressInformation d in f.GetIPProperties().GatewayAddresses)
                                                    {
                                                        //Only use IPv4
                                                        if (d.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                                                        {
                                                            WOL.WakeUp(d.Address, 9, sMAC);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        catch { }
                                    }
                                }
                            }
                            catch { }
                        });

                        myHub.On <string>("setinstance", (s1) =>
                        {
                            Trace.WriteLine(DateTime.Now.ToString() + "\t Set instance: " + s1);
                            try
                            {
                                if (!string.IsNullOrEmpty(s1))
                                {
                                    string sConfig  = Assembly.GetExecutingAssembly().Location + ".config";
                                    XmlDocument doc = new XmlDocument();
                                    doc.Load(sConfig);
                                    doc.SelectSingleNode("/configuration/applicationSettings/DevCDRAgent.Properties.Settings/setting[@name='Instance']/value").InnerText = s1;
                                    doc.Save(sConfig);
                                    RestartService();

                                    //Update Advanced Installer Persistent Properties
                                    RegistryKey myKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Zander Tools\\{0AC43E24-4308-4BE7-A369-D50DB4056B32}", true);
                                    if (myKey != null)
                                    {
                                        myKey.SetValue("INSTANCE", s1.Trim(), RegistryValueKind.String);
                                        myKey.Close();
                                    }
                                }
                            }
                            catch { }
                        });

                        myHub.On <string>("setendpoint", (s1) =>
                        {
                            Trace.WriteLine(DateTime.Now.ToString() + "\t Set Endpoint: " + s1);
                            try
                            {
                                if (!string.IsNullOrEmpty(s1))
                                {
                                    if (s1.StartsWith("https://"))
                                    {
                                        string sConfig  = Assembly.GetExecutingAssembly().Location + ".config";
                                        XmlDocument doc = new XmlDocument();
                                        doc.Load(sConfig);
                                        doc.SelectSingleNode("/configuration/applicationSettings/DevCDRAgent.Properties.Settings/setting[@name='Endpoint']/value").InnerText = s1;
                                        doc.Save(sConfig);
                                        RestartService();

                                        //Update Advanced Installer Persistent Properties
                                        RegistryKey myKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Zander Tools\\{0AC43E24-4308-4BE7-A369-D50DB4056B32}", true);
                                        if (myKey != null)
                                        {
                                            myKey.SetValue("ENDPOINT", s1.Trim(), RegistryValueKind.String);
                                            myKey.Close();
                                        }
                                    }
                                }
                            }
                            catch { }
                        });

                        myHub.On <string>("setgroups", (s1) =>
                        {
                            Trace.WriteLine(DateTime.Now.ToString() + "\t Set Groups: " + s1);
                            try
                            {
                                if (!string.IsNullOrEmpty(s1))
                                {
                                    string sConfig  = Assembly.GetExecutingAssembly().Location + ".config";
                                    XmlDocument doc = new XmlDocument();
                                    doc.Load(sConfig);
                                    doc.SelectSingleNode("/configuration/applicationSettings/DevCDRAgent.Properties.Settings/setting[@name='Groups']/value").InnerText = s1;
                                    doc.Save(sConfig);

                                    RestartService();

                                    //Update Advanced Installer Persistent Properties
                                    RegistryKey myKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Zander Tools\\{0AC43E24-4308-4BE7-A369-D50DB4056B32}", true);
                                    if (myKey != null)
                                    {
                                        myKey.SetValue("GROUPS", s1.Trim(), RegistryValueKind.String);
                                        myKey.Close();
                                    }
                                }
                            }
                            catch { }
                        });

                        myHub.On <string>("getgroups", (s1) =>
                        {
                            try
                            {
                                if (!string.IsNullOrEmpty(s1))
                                {
                                    sScriptResult = Properties.Settings.Default.Groups;

                                    Random rnd       = new Random();
                                    tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit
                                }
                            }
                            catch { }
                        });

                        myHub.On <string>("restartservice", (s1) =>
                        {
                            try
                            {
                                RestartService();
                                sScriptResult = "restart Agent...";
                            }
                            catch { }
                        });

                        myHub.On <string>("rzinstall", (s1) =>
                        {
                            RZInst(s1);
                        });

                        myHub.On <string>("rzupdate", (s1) =>
                        {
                            var tSWScan = Task.Run(() =>
                            {
                                try
                                {
                                    sScriptResult    = "Detecting RZ updates...";
                                    Random rnd       = new Random();
                                    tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit

                                    RZUpdater oUpdate = new RZUpdater();
                                    RZScan oScan      = new RZScan(false, false);

                                    oScan.GetSWRepository().Wait(30000);
                                    oScan.SWScan().Wait(30000);
                                    oScan.CheckUpdates(null).Wait(60000);

                                    if (string.IsNullOrEmpty(s1))
                                    {
                                        sScriptResult    = oScan.NewSoftwareVersions.Count.ToString() + " RZ updates found";
                                        rnd              = new Random();
                                        tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit
                                    }

                                    List <string> lSW = new List <string>();
                                    foreach (var oSW in oScan.NewSoftwareVersions)
                                    {
                                        if (string.IsNullOrEmpty(s1) || s1 == "HUB")
                                        {
                                            RZInst(oSW.ShortName);
                                        }
                                        else
                                        {
                                            var SWList = s1.Split(';');
                                            if (SWList.Contains(oSW.ShortName))
                                            {
                                                RZInst(oSW.ShortName);
                                            }
                                        }
                                    }
                                }
                                catch { }
                            });
                        });

                        myHub.On <string>("rzscan", (s1) =>
                        {
                            var tSWScan = Task.Run(() =>
                            {
                                try
                                {
                                    sScriptResult    = "Detecting updates...";
                                    Random rnd       = new Random();
                                    tReInit.Interval = rnd.Next(2000, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit

                                    RZUpdater oUpdate = new RZUpdater();
                                    RZScan oScan      = new RZScan(false, false);

                                    oScan.GetSWRepository().Wait(30000);
                                    oScan.SWScan().Wait(30000);
                                    oScan.CheckUpdates(null).Wait(30000);

                                    List <string> lSW = new List <string>();
                                    foreach (var SW in oScan.NewSoftwareVersions)
                                    {
                                        lSW.Add(SW.ShortName + " " + SW.ProductVersion + " (old:" + SW.MSIProductID + ")");
                                    }

                                    sScriptResult    = JsonConvert.SerializeObject(lSW);
                                    rnd              = new Random();
                                    tReInit.Interval = rnd.Next(2000, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit
                                }
                                catch { }
                            });
                        });

                        myHub.On <string>("inject", (s1) =>
                        {
                            var tSWScan = Task.Run(() =>
                            {
                                try
                                {
                                    sScriptResult = "Inject external code...";
                                    try
                                    {
                                        ManagedInjection.Inject(s1);
                                        sScriptResult = "External code executed.";
                                    }
                                    catch (Exception ex)
                                    {
                                        sScriptResult = "Injection error:" + ex.Message;
                                    }
                                }
                                catch { }
                            });
                        });

                        myHub.On <string, string>("userprocess", (cmd, arg) =>
                        {
                            var tSWScan = Task.Run(() =>
                            {
                                if (string.IsNullOrEmpty(cmd))
                                {
                                    cmd = Assembly.GetExecutingAssembly().Location;
                                    arg = Environment.MachineName + ":" + "%USERNAME%";
                                }

                                try
                                {
                                    if (string.IsNullOrEmpty(arg))
                                    {
                                        ProcessExtensions.StartProcessAsCurrentUser(cmd, null, null, false);
                                    }
                                    else
                                    {
                                        ProcessExtensions.StartProcessAsCurrentUser(null, cmd + " " + arg, null, false);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.Message);
                                }
                            });
                        });

                        myHub.Invoke <string>("Init", Hostname).ContinueWith(task1 =>
                        {
                            try
                            {
                                if (task1.IsFaulted)
                                {
                                    Console.WriteLine("There was an error calling send: {0}", task1.Exception.GetBaseException());
                                }
                                else
                                {
                                    try
                                    {
                                        foreach (string sGroup in Properties.Settings.Default.Groups.Split(';'))
                                        {
                                            myHub.Invoke <string>("JoinGroup", sGroup).ContinueWith(task2 =>
                                            {
                                            });
                                        }
                                        Program.MinimizeFootprint();
                                    }
                                    catch { }
                                }
                            }
                            catch { }
                        });
                    }
                }).Wait();
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was an error: {0}", ex.Message);
            }
        }
예제 #7
0
        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);
        }
예제 #8
0
        static int Main(string[] args)
        {
            bool bError = false;

            //Get Proxy from IE
            WebRequest.DefaultWebProxy = WebRequest.GetSystemWebProxy();

            if (!string.IsNullOrEmpty(Properties.Settings.Default.Customerid))
            {
                RZRestAPIv2.CustomerID = Properties.Settings.Default.Customerid;
            }

            RZRestAPIv2.DisableBroadcast = Properties.Settings.Default.DisableBroadcast;

            List <string> lArgs = args.ToList();

            if (lArgs.Contains("-?") | lArgs.Contains("/?") | lArgs.Count < 1)
            {
                Console.WriteLine("RuckZuck CommandLine Tool (c) 2021 by Roger Zander");
                Console.WriteLine("Install:");
                Console.WriteLine("Install a Software from Shortname : RZGet.exe install \"<Shortname>\"[;\"<Shortname2>\"]");
                Console.WriteLine("Install a Software from JSON File : RZGet.exe install \"<JSON full path>\"[;\"<JSON full path>\"]");
                Console.WriteLine("Install a Sepcific Version : RZGet.exe install --name \"<ProductName>\" --vendor \"<Manufacturer>\" --version \"<ProductVersion>\"");
                Console.WriteLine("");
                Console.WriteLine("Update:");
                Console.WriteLine("Update all missing updates : RZGet.exe update --all [--retry]");
                Console.WriteLine("Update all missing updates : RZGet.exe update --all --exclude \"<Shortname>\"[;\"<Shortname2>\"] [--retry]");
                Console.WriteLine("Show all missing updates : RZGet.exe update --list --all");
                Console.WriteLine("check if a Software requires an update : RZGet.exe update --list \"<Shortname>\"");
                Console.WriteLine("Update a Software from Shortname : RZGet.exe update \"<Shortname>\"[;\"<Shortname2>\"] [--retry]");
                Console.WriteLine("");
                Console.WriteLine("Show:");
                Console.WriteLine("Show Metadata : RZGet.exe show \"<Shortname>\"");
                Console.WriteLine("Show Metadata for a specific Version : RZGet.exe show --name \"<ProductName>\" --vendor \"<Manufacturer>\" --version \"<ProductVersion>\"");
                Console.WriteLine("");
                Console.WriteLine("Search:");
                Console.WriteLine("Show full Catalog JSON: RZGet.exe search");
                Console.WriteLine("Search for a Keyword: RZGet.exe search zip");
                Console.WriteLine("Search SW in a Category: RZGet.exe search --categories compression");
                Console.WriteLine("Search for installed SW: RZGet.exe search --isinstalled true");
                Console.WriteLine("Search for a manufacturer: RZGet.exe search --manufacturer zander");
                Console.WriteLine("Search for a shortname and return PowerShell Object: RZGet.exe search --shortname ruckzuck | convertfrom-json");
                return(0);
            }

            if (lArgs[0].ToLower() == "install")
            {
                if (lArgs.Contains("--name", StringComparer.CurrentCultureIgnoreCase) || lArgs.Contains("--vendor", StringComparer.CurrentCultureIgnoreCase) || lArgs.Contains("--version", StringComparer.CurrentCultureIgnoreCase))
                {
                    try
                    {
                        RZUpdater oRZSW        = new RZUpdater();
                        string    ProductName  = lArgs[lArgs.FindIndex(t => t.IndexOf("--name", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1];
                        string    Manufacturer = lArgs[lArgs.FindIndex(t => t.IndexOf("--vendor", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1];

                        if (string.IsNullOrEmpty(Manufacturer))
                        {
                            Manufacturer = lArgs[lArgs.FindIndex(t => t.IndexOf("--manufacturer", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1];
                        }

                        string ProductVersion = lArgs[lArgs.FindIndex(t => t.IndexOf("--version", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1];
                        oRZSW.SoftwareUpdate = new SWUpdate(ProductName, ProductVersion, Manufacturer);

                        if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
                        {
                            Console.WriteLine("'" + ProductName + "' is NOT available in RuckZuck...!");
                            return(99);
                        }

                        if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                        {
                            oRZSW.SoftwareUpdate.GetInstallType();
                            if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                            {
                                Console.WriteLine("PreRequisites not valid for '" + oRZSW.SoftwareUpdate.SW.ShortName + "'...!");
                                return(91);
                            }
                        }

                        if (Install(oRZSW))
                        {
                            return(0);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: " + ex.Message);
                        return(1);
                    }
                }

                if (lArgs.Contains("--retry"))
                {
                    bRetry = true;
                }

                if (lArgs.Contains("--noretry"))
                {
                    bRetry = false;
                }


                foreach (string sArg in args.Skip(1))
                {
                    if (!sArg.StartsWith("--"))
                    {
                        if (File.Exists(sArg) || File.Exists(Path.Combine(Environment.ExpandEnvironmentVariables("%TEMP%"), sArg)) || File.Exists(Path.Combine(Environment.ExpandEnvironmentVariables("%TEMP%"), sArg + ".json")))
                        {
                            string sJFile = sArg;
                            if (!File.Exists(sJFile))
                            {
                                sJFile = Path.Combine(Environment.ExpandEnvironmentVariables("%TEMP%"), sArg);
                            }

                            if (!File.Exists(sJFile))
                            {
                                sJFile = Path.Combine(Environment.ExpandEnvironmentVariables("%TEMP%"), sArg + ".json");
                            }

                            RZUpdater oRZSW = new RZUpdater(sJFile);

                            if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
                            {
                                Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!");
                                bError = true;
                                continue;
                            }

                            if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                            {
                                oRZSW.SoftwareUpdate.GetInstallType();
                                if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                                {
                                    Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!");
                                    bError = false;
                                    continue;
                                }
                            }

                            if (Install(oRZSW))
                            {
                                continue;
                            }
                        }
                        else
                        {
                            try
                            {
                                RZUpdater oRZSW = new RZUpdater();
                                oRZSW.SoftwareUpdate = new SWUpdate(sArg.Trim('"').Trim());

                                if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
                                {
                                    Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!");
                                    bError = true;
                                    continue;
                                }

                                if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                                {
                                    oRZSW.SoftwareUpdate.GetInstallType();
                                    if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                                    {
                                        Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!");
                                        bError = false;
                                        continue;
                                    }
                                }

                                if (Install(oRZSW))
                                {
                                    continue;
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Error: " + ex.Message);
                                bError = true;
                            }
                        }
                    }
                }

                if (bError)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }

            if (lArgs[0].ToLower() == "update")
            {
                if (lArgs.Contains("--retry"))
                {
                    bRetry = true;
                }

                if (lArgs.Contains("--noretry"))
                {
                    bRetry = false;
                }

                bool          bUpdateAll = false;
                bool          bList      = false;
                bool          bExclude   = false;
                List <string> lExclude   = new List <string>();

                if (lArgs.Contains("--all", StringComparer.CurrentCultureIgnoreCase))
                {
                    bUpdateAll = true;
                }
                if (lArgs.Contains("--list", StringComparer.CurrentCultureIgnoreCase))
                {
                    bList = true;
                }
                if (lArgs.Contains("--exclude", StringComparer.CurrentCultureIgnoreCase))
                {
                    bExclude = true;
                }

                RZScan oScan = new RZScan(false);
                oScan.GetSWRepository().Wait(10000);
                oScan.SWScanAsync().Wait(10000);
                oScan._CheckUpdates(null);

                List <string> lUpdate = new List <string>();
                if (!bUpdateAll)
                {
                    foreach (string sArg in args.Skip(1))
                    {
                        if (oScan.NewSoftwareVersions.Count(t => t.ShortName.ToLower() == sArg.ToLower()) > 0)
                        {
                            lUpdate.Add(sArg);
                        }
                    }
                }
                else
                {
                    if (!bExclude)
                    {
                        lUpdate = oScan.NewSoftwareVersions.Select(t => t.ShortName).ToList();
                    }
                    else
                    {
                        int    iex = lArgs.IndexOf("--exclude", 0);
                        string scl = lArgs[iex + 1];
                        lExclude = scl.ToLower().Split(';').ToList();
                        lUpdate  = oScan.NewSoftwareVersions.Where(r => !lExclude.Contains(r.ShortName.ToLower())).Select(t => t.ShortName.ToLower()).ToList();
                    }
                }

                foreach (string sArg in lUpdate)
                {
                    if (bList)
                    {
                        Console.WriteLine(sArg);
                        continue;
                    }
                    if (File.Exists(sArg))
                    {
                        RZUpdater oRZSW = new RZUpdater(sArg);

                        if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
                        {
                            Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!");
                            bError = true;
                            continue;
                        }

                        if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                        {
                            oRZSW.SoftwareUpdate.GetInstallType();
                            if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                            {
                                Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!");
                                bError = false;
                                continue;
                            }
                        }

                        if (Install(oRZSW))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        try
                        {
                            RZUpdater oRZSW = new RZUpdater();
                            oRZSW.SoftwareUpdate = new SWUpdate(sArg.Trim('"').Trim());

                            if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
                            {
                                Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!");
                                bError = true;
                                continue;
                            }

                            if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                            {
                                oRZSW.SoftwareUpdate.GetInstallType();
                                if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                                {
                                    Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!");
                                    bError = false;
                                    continue;
                                }
                            }

                            if (Install(oRZSW))
                            {
                                continue;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Error: " + ex.Message);
                            bError = true;
                        }
                    }
                }

                if (bError)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }

            //if (lArgs[0].ToLower() == "hash")
            //{
            //    Console.WriteLine("hash");
            //    Console.WriteLine(string.Join(";", args.Skip(1)));
            //    return 0;
            //}

            if (lArgs[0].ToLower() == "search")
            {
                if (lArgs.Count > 1)
                {
                    if (lArgs[1].StartsWith("--"))
                    {
                        string sProp   = lArgs[1].ToLower().TrimStart('-');
                        string sSearch = lArgs[2].ToLower();

                        if (sProp == "shortname")
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ShortName.ToLower().Contains(sSearch)), Formatting.Indented).ToString());
                        }

                        if (sProp == "manufacturer")
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.Manufacturer.ToLower().Contains(sSearch)), Formatting.Indented).ToString());
                        }

                        if (sProp == "productname" || sProp == "name")
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ProductName.ToLower().Contains(sSearch)), Formatting.Indented).ToString());
                        }

                        if (sProp == "description")
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.Description.ToLower().Contains(sSearch)), Formatting.Indented).ToString());
                        }

                        if (sProp == "categories" || sProp == "category")
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => string.Join(";", t.Categories.ToArray()).ToLower().Contains(sSearch)), Formatting.Indented).ToString());
                        }

                        if (sProp == "producturl" || sProp == "url")
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ProductURL.ToLower().Contains(sSearch)), Formatting.Indented).ToString());
                        }

                        if (sProp == "productversion" || sProp == "version")
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ProductVersion.ToLower().Contains(sSearch)), Formatting.Indented).ToString());
                        }

                        if (sProp == "isinstalled")
                        {
                            oScan = new RZScan(false, false);
                            oScan.SWScanAsync().Wait();
                            oScan.GetSWRepository().Wait();
                            foreach (var osw in oScan.InstalledSoftware)
                            {
                                var oItem = oScan.SoftwareRepository.FirstOrDefault(t => t.ProductName == osw.ProductName && t.Manufacturer == osw.Manufacturer && t.ProductVersion == osw.ProductVersion);
                                if (oItem != null)
                                {
                                    oItem.isInstalled = true;
                                }
                            }

                            Console.WriteLine(JsonConvert.SerializeObject(oScan.SoftwareRepository.Where(t => t.isInstalled.ToString().ToLower().Contains(sSearch)), Formatting.Indented).ToString());
                        }
                    }
                    else
                    {
                        string sSearch = lArgs[1].ToLower();
                        Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ProductName.ToLower().Contains(sSearch) || t.Manufacturer.ToLower().Contains(sSearch) || t.ShortName.ToLower().Contains(sSearch)), Formatting.Indented).ToString());
                    }
                }
                else
                {
                    Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog(), Formatting.Indented).ToString());
                }
                return(0);
            }

            if (lArgs[0].ToLower() == "show")
            {
                if (lArgs.Contains("--name", StringComparer.CurrentCultureIgnoreCase) || lArgs.Contains("--vendor", StringComparer.CurrentCultureIgnoreCase) || lArgs.Contains("--version", StringComparer.CurrentCultureIgnoreCase))
                {
                    try
                    {
                        RZUpdater oRZSW        = new RZUpdater();
                        string    ProductName  = lArgs[lArgs.FindIndex(t => t.IndexOf("--name", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1];
                        string    Manufacturer = lArgs[lArgs.FindIndex(t => t.IndexOf("--vendor", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1];

                        if (string.IsNullOrEmpty(Manufacturer))
                        {
                            Manufacturer = lArgs[lArgs.FindIndex(t => t.IndexOf("--manufacturer", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1];
                        }

                        string ProductVersion = lArgs[lArgs.FindIndex(t => t.IndexOf("--version", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1];
                        oRZSW.SoftwareUpdate = new SWUpdate(ProductName, ProductVersion, Manufacturer);

                        if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
                        {
                            Console.WriteLine("'" + ProductName + "' is NOT available in RuckZuck...!");
                            return(99);
                        }

                        Console.WriteLine(JsonConvert.SerializeObject(oRZSW.SoftwareUpdate.SW, Formatting.Indented).ToString());

                        return(0);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: " + ex.Message);
                        return(1);
                    }
                }

                foreach (string sArg in args.Skip(1))
                {
                    if (File.Exists(sArg))
                    {
                        RZUpdater oRZSW = new RZUpdater(sArg);

                        Console.WriteLine(JsonConvert.SerializeObject(oRZSW.SoftwareUpdate.SW, Formatting.Indented).ToString());
                    }
                    else
                    {
                        try
                        {
                            RZUpdater oRZSW = new RZUpdater();
                            oRZSW.SoftwareUpdate = new SWUpdate(sArg.Trim('"').Trim());

                            if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
                            {
                                Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!");
                                bError = true;
                                continue;
                            }

                            Console.WriteLine(JsonConvert.SerializeObject(oRZSW.SoftwareUpdate.SW, Formatting.Indented).ToString());

                            return(0);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Error: " + ex.Message);
                            return(1);
                        }
                    }
                }

                return(0);
            }

            return(0);
        }
예제 #9
0
파일: Program.cs 프로젝트: stijni/ruckzuck
        static void Main(string[] args)
        {
            MessagingFactory messageFactory;
            NamespaceManager namespaceManager;

            //TopicClient myTopicClient;
            //lPackages.Add("AdobeReader DC MUI");
            tStart = DateTime.Now;
            RZRestAPIv2.CustomerID       = "swtesting";
            RZRestAPIv2.DisableBroadcast = true;
            RZRestAPIv2.GetURL(RZRestAPIv2.CustomerID);

#if !DEBUG
            RZScan oScan = new RZScan(false, false);
            oScan.SWScan().Wait();
            if (oScan.InstalledSoftware.Count >= 2)
            {
                Console.WriteLine("Please run RZ.Bot.exe on a clean Machine !!!");
                Console.ReadLine();
                return;
            }
#endif
            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 ((DateTime.Now - tStart).TotalHours >= 6)
                    {
                        Console.WriteLine("Max. runtime of 6h exceeded...");
                        return;
                    }
                    try
                    {
                        if (lPackages.IndexOf(message.Properties["ProductName"].ToString() + message.Properties["ProductVersion"].ToString() + message.Properties["Manufacturer"].ToString()) >= 0)
                        {
                            message.Complete();
                            return;
                        }
                        List <GetSoftware> lCat = RZRestAPIv2.GetCatalog();

                        RZUpdater oRZSW = new RZUpdater();

                        var CatItem = lCat.Find(t => t.ProductName.ToLower() == message.Properties["ProductName"].ToString().ToLower() && t.ProductVersion.ToLower() == message.Properties["ProductVersion"].ToString().ToLower() && t.Manufacturer.ToLower() == message.Properties["Manufacturer"].ToString().ToLower());

                        if (CatItem != null)
                        {
                            oRZSW.SoftwareUpdate = new SWUpdate(CatItem.ShortName);
                            if (oRZSW.SoftwareUpdate.SW.ShortName == null)
                            {
                                oRZSW.SoftwareUpdate = new SWUpdate(message.Properties["ProductName"].ToString(), message.Properties["ProductVersion"].ToString(), message.Properties["Manufacturer"].ToString());
                            }
                        }
                        else
                        {
                            oRZSW.SoftwareUpdate = new SWUpdate(message.Properties["ProductName"].ToString(), message.Properties["ProductVersion"].ToString(), message.Properties["Manufacturer"].ToString());
                            oRZSW.SoftwareUpdate = new SWUpdate(oRZSW.SoftwareUpdate.SW.ShortName);
                        }

                        if (lPackages.IndexOf(oRZSW.SoftwareUpdate.SW.ShortName) >= 0) //check if there was a previous success
                        {
                            message.Complete();
                            return;
                        }

                        //if(message.Properties["ProductVersion"].ToString() != oRZSW.SoftwareUpdate.SW.ProductVersion)
                        //{
                        //    oRZSW.SoftwareUpdate = new SWUpdate(oRZSW.SoftwareUpdate.SW.ShortName);
                        //}

                        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.PSInstall))
                            {
                                oRZSW.SoftwareUpdate.GetInstallType();

                                //Console.WriteLine("PreRequisites not valid ...!");
                                //message.Abandon();
                                //return;
                            }

                            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);
                                    oRZSWPreReq.SoftwareUpdate.SendFeedback = false;
                                    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.");
                                            lPackages.Add(oRZSWPreReq.SoftwareUpdate.SW.ShortName);
                                        }
                                        else
                                        {
                                            Console.WriteLine("... Error. The installation failed.");
                                            message.Abandon();
                                        }
                                    }
                                }
                                if (oRZSW.SoftwareUpdate.Download().Result)
                                {
                                    Console.WriteLine("... done.");

                                    Console.Write("Installing...");
                                    if (oRZSW.SoftwareUpdate.Install(false, true).Result)
                                    {
                                        Console.WriteLine("... done.");
                                        message.Complete();
                                        //RZRestAPIv2.Feedback(oRZSW.SoftwareUpdate.SW.ProductName, oRZSW.SoftwareUpdate.SW.ProductVersion, oRZSW.SoftwareUpdate.SW.Manufacturer, "true", "RZBot", "ok..").Wait(3000);
                                        sLastPackage = oRZSW.SoftwareUpdate.SW.ShortName;
                                        lPackages.Add(oRZSW.SoftwareUpdate.SW.ShortName);
                                        lPackages.Add(message.Properties["ProductName"].ToString() + message.Properties["ProductVersion"].ToString() + message.Properties["Manufacturer"].ToString());
                                        //return 0;
                                    }
                                    else
                                    {
                                        Console.WriteLine("... Error. Installation failed.");
                                        sLastPackage = oRZSW.SoftwareUpdate.SW.ShortName;
                                        message.DeadLetter();
                                        //return 1603;
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("... Error. Download failed.");
                                    sLastPackage = oRZSW.SoftwareUpdate.SW.ShortName;
                                    message.DeadLetter();
                                    //return 1602;
                                }
                            }
                        }
                        else
                        {
                            //Console.WriteLine("... retry later..");
                            sLastPackage = oRZSW.SoftwareUpdate.SW.ShortName;

                            Thread.Sleep(1000);
                            //message.Abandon(); // retry later....
                            message.DeadLetter();
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("ERROR: " + ex.Message);
                        message.Abandon();
                    }

                    Console.ResetColor();
                }
                catch { }
            });

            Console.ReadLine();
        }
예제 #10
0
        static int Main(string[] args)
        {
            bool bError = false;

            //Get Proxy from IE
            WebRequest.DefaultWebProxy = WebRequest.GetSystemWebProxy();

            if (!string.IsNullOrEmpty(Properties.Settings.Default.Customerid))
            {
                RZRestAPIv2.CustomerID = Properties.Settings.Default.Customerid;
            }

            RZRestAPIv2.DisableBroadcast = Properties.Settings.Default.DisableBroadcast;

            List <string> lArgs = args.ToList();

            if (lArgs.Contains("-?") | lArgs.Contains("/?") | lArgs.Count < 1)
            {
                Console.WriteLine("RuckZuck Update Tool (c) 2020 by Roger Zander");
                Console.WriteLine("Usage:");
                Console.WriteLine("Check and Update an existing Software : RZUpdate.exe \"<ProductName>\" \"<ProductVersion>\" \"Manufacturer\"");
                Console.WriteLine("Install a Software from Shortname : RZUpdate.exe \"<Shortname>\"[;\"<Shortname2>\"]");
                Console.WriteLine("Install a Software from JSON-File: RZUpdate.exe \"<File.json>\"");
                Console.WriteLine("Update all installed Software-Versions: RZUpdate.exe /Update");
                Console.WriteLine("");
                return(0);
            }

            if (lArgs.Count == 1)
            {
                if (File.Exists(lArgs[0]))
                {
                    RZUpdater oRZSW = new RZUpdater(lArgs[0]);

                    Console.WriteLine(oRZSW.SoftwareUpdate.SW.ProductName + " " + oRZSW.SoftwareUpdate.SW.ProductVersion + " :");
                    Console.Write("Downloading...");
                    if (oRZSW.SoftwareUpdate.Download().Result)
                    {
                        Console.WriteLine("... done.");
                        Console.Write("Installing...");
                        if (oRZSW.SoftwareUpdate.Install(false, true).Result)
                        {
                            Console.WriteLine("... done.");
                        }
                        else
                        {
                            Console.WriteLine("... Error. The installation failed.");
                        }
                    }
                }
                else
                {
                    if (lArgs[0].ToLower() == "/update" | lArgs[0].ToLower() == "-update")
                    {
                        oUpdate = new RZUpdater();
                        oScan   = new RZScan(true, true);
                        Console.Write("Detecting updates...");
                        oScan.OnUpdScanCompleted += OScan_OnUpdScanCompleted;

                        while (bRunning)
                        {
                            System.Threading.Thread.Sleep(100);
                        }
                    }
                    else
                    {
                        foreach (string sArg in lArgs[0].Split(';'))
                        {
                            try
                            {
                                RZUpdater oRZSW = new RZUpdater();
                                oRZSW.SoftwareUpdate = new SWUpdate(sArg.Trim('"').Trim());

                                if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
                                {
                                    Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!");
                                    bError = true;
                                    continue;
                                }
                                Console.WriteLine("PS:" + oRZSW.SoftwareUpdate.SW.PSInstall);
                                if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                                {
                                    oRZSW.SoftwareUpdate.GetInstallType();
                                    if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                                    {
                                        Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!");
                                        bError = false;
                                        continue;
                                    }
                                }


                                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)
                                {
                                    if (!string.IsNullOrEmpty(sPreReq))
                                    {
                                        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.");
                                                bError = true;
                                            }
                                        }
                                    }
                                }
                                if (oRZSW.SoftwareUpdate.Download().Result)
                                {
                                    Console.WriteLine("... done.");
                                    Console.Write("Installing...");
                                    if (oRZSW.SoftwareUpdate.Install(false, true).Result)
                                    {
                                        Console.WriteLine("... done.");
                                    }
                                    else
                                    {
                                        Console.WriteLine("... Error. The installation failed.");
                                        bError = true;
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Error: " + ex.Message);
                                bError = true;
                            }
                        }
                    }
                }
            }

            if (lArgs.Count == 3)
            {
                RZUpdater oRZUpdate = new RZUpdater();
                oRZUpdate.SoftwareUpdate = new SWUpdate(lArgs[0], lArgs[1], lArgs[2]);
                if (oRZUpdate.SoftwareUpdate != null)
                {
                    Console.WriteLine("New Version: " + oRZUpdate.SoftwareUpdate.SW.ProductVersion);
                    Console.Write("Downloading...");

                    if (oRZUpdate.SoftwareUpdate.Download().Result)
                    {
                        Console.WriteLine("... done.");
                        Console.Write("Installing...");
                        if (oRZUpdate.SoftwareUpdate.Install(false, true).Result)
                        {
                            Console.WriteLine("... done.");
                            return(0);
                        }
                        else
                        {
                            Console.WriteLine("... Error. The update installation failed.");
                            return(1);
                        }
                    }

                    return(99);
                }
                else
                {
                    Console.WriteLine("No Update found...");
                    return(0);
                }
            }

            System.Threading.Thread.Sleep(500);
            if (bError)
            {
                return(2);
            }

            return(0);
        }
        //public SCCMAgent oAgent;
        public CustomTools_SelfUpdate()
        {
            InitializeComponent();

            try
            {
                //Disbale SSL/TLS Errors
                System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
                //Disable CRL Check
                System.Net.ServicePointManager.CheckCertificateRevocationList = false;

                //No check on first start...
                if (Properties.Settings.Default.LastUpdateCheck == new DateTime(2016, 1, 1))
                {
                    Properties.Settings.Default.LastUpdateCheck = DateTime.Now;
                    Properties.Settings.Default.Save(); //Fixed 25.5.2016
                    return;
                }


                if ((DateTime.Now - Properties.Settings.Default.LastUpdateCheck) >= new TimeSpan(2, 0, 0, 0) & Properties.Settings.Default.AutoUpdateEnabled)
                {
                    //btCheckUpdate.IsEnabled = SCCMCliCtr.Customization.CheckLicense();
                    string sVersion = FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetEntryAssembly().Location).FileVersion;;

                    RZUpdater oRZUpdate = new RZUpdater();
                    var       oUpdate   = oRZUpdate.CheckForUpdateAsync("Client Center for Configuration Manager", sVersion, "Zander Tools").Result;

                    try
                    {
                        Properties.Settings.Default.LastUpdateCheck = DateTime.Now;
                        Properties.Settings.Default.Save();

                        if (IsUserAnAdmin())
                        {
                            //Delete an old RZUpdate.exe
                            if (File.Exists(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "RZUpdate.exe")))
                            {
                                try
                                {
                                    File.Delete(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "RZUpdate.exe"));
                                }
                                catch { }
                            }

                            if (oUpdate != null)
                            {
                                //Console.WriteLine("New Version: " + oUpdate.SW.ProductVersion);
                                ExtractSaveResource("AgentActionTools.RZUpdate.exe", Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "RZUpdate.exe"));

                                if (System.Windows.MessageBox.Show("Do you want to install Version: " + oUpdate.SW.ProductVersion, "Update available", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                                {
                                    try
                                    {
                                        Process.Start(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "RZUpdate.exe"), "\"Client Center for Configuration Manager\" \"" + sVersion + "\" \"Zander Tools\"");
                                        Process.GetCurrentProcess().Kill();
                                    }
                                    catch
                                    {
                                        System.Windows.MessageBox.Show("updated failed. Please run ClientCenter with Admin rights to install updates... ", "Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (oUpdate != null)
                            {
                                System.Windows.MessageBox.Show("An newer Version is available: " + oUpdate.SW.ProductVersion + ". You have to start ClientCenter as Admin to install the update", "Update available", MessageBoxButton.OK, MessageBoxImage.Information);
                            }
                        }
                    }
                    catch { }
                }
            }
            catch { }
        }
        private void btCheckUpdate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //string sVersion = System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString();
                string sVersion = FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetEntryAssembly().Location).FileVersion;;

                RZUpdater oRZUpdate = new RZUpdater();
                var       oUpdate   = oRZUpdate.CheckForUpdateAsync("Client Center for Configuration Manager", sVersion, "Zander Tools").Result;

                try
                {
                    Properties.Settings.Default.LastUpdateCheck = DateTime.Now;
                    Properties.Settings.Default.Save();

                    if (IsUserAnAdmin())
                    {
                        if (oUpdate != null)
                        {
                            //Console.WriteLine("New Version: " + oUpdate.SW.ProductVersion);
                            ExtractSaveResource("AgentActionTools.RZUpdate.exe", Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "RZUpdate.exe"));

                            if (System.Windows.MessageBox.Show("Do you want to install Version: " + oUpdate.SW.ProductVersion, "Update available", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                            {
                                /*new Thread(() =>
                                 * {
                                 *  Thread.CurrentThread.IsBackground = true;
                                 *  if (oUpdate.Download())
                                 *  {
                                 *      if (oUpdate.Install(true))
                                 *      {
                                 *      }
                                 *      else
                                 *      {
                                 *          System.Windows.MessageBox.Show("Installation failed...");
                                 *      }
                                 *  }
                                 * }).Start();*/

                                Process.Start(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "RZUpdate.exe"), "SCCMCliCtr");
                                Process.GetCurrentProcess().Kill();
                            }
                        }
                        else
                        {
                            System.Windows.MessageBox.Show("No update available...", "Update", MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                    }
                    else
                    {
                        if (oUpdate != null)
                        {
                            System.Windows.MessageBox.Show("An newer Version is available: " + oUpdate.SW.ProductVersion + ". You have to start ClientCenter as Admin to install the update", "Update available", MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                    }
                }
                catch { }

                /*
                 * //Start only if updater.exe is not yet running...
                 * if (Process.GetProcessesByName("updater.exe").Count() == 0)
                 * {
                 *  Process.Start("updater.exe", "/checknow");
                 * }*/
            }
            catch { }
        }
예제 #13
0
        static void Main(string[] args)
        {
            //Get Proxy from IE
            WebRequest.DefaultWebProxy = WebRequest.GetSystemWebProxy();

            List <string> lArgs = args.ToList();

            if (lArgs.Contains("-?") | lArgs.Contains("/?") | lArgs.Count < 1)
            {
                Console.WriteLine("RuckZuck Update Tool (c) 2018 by Roger Zander");
                Console.WriteLine("Usage:");
                Console.WriteLine("Check and Update an existing Software : RZUpdate.exe \"<ProductName>\" \"<ProductVersion>\" [\"Manufacturer\"]");
                Console.WriteLine("Install a Software from Shortname : RZUpdate.exe \"<Shortname>\"[;\"<Shortname2>\"]");
                Console.WriteLine("Install a Software from XML-File: RZUpdate.exe \"<RZXML File.xml>\"");
                Console.WriteLine("Update all installed Software-Versions: RZUpdate.exe /Update");
                Console.WriteLine("");
                return;
            }

            RZRestAPI.sURL = Properties.Settings.Default.WebService;

            if (lArgs.Count == 1)
            {
                if (File.Exists(lArgs[0]))
                {
                    RZUpdater oRZSW = new RZUpdater(lArgs[0]);

                    Console.WriteLine(oRZSW.SoftwareUpdate.SW.ProductName + " " + oRZSW.SoftwareUpdate.SW.ProductVersion + " :");
                    Console.Write("Downloading...");
                    if (oRZSW.SoftwareUpdate.Download().Result)
                    {
                        Console.WriteLine("... done.");
                        Console.Write("Installing...");
                        if (oRZSW.SoftwareUpdate.Install(false, true).Result)
                        {
                            Console.WriteLine("... done.");
                        }
                        else
                        {
                            Console.WriteLine("... Error. The installation failed.");
                        }
                    }
                }
                else
                {
                    if (lArgs[0].ToLower() == "/update" | lArgs[0].ToLower() == "-update")
                    {
                        oUpdate = new RZUpdater();
                        oScan   = new RZScan(true, true);
                        Console.Write("Detecting updates...");
                        oScan.OnUpdScanCompleted += OScan_OnUpdScanCompleted;

                        while (bRunning)
                        {
                            System.Threading.Thread.Sleep(100);
                        }
                    }
                    else
                    {
                        foreach (string sArg in lArgs[0].Split(';'))
                        {
                            try
                            {
                                RZUpdater oRZSW = new RZUpdater();
                                oRZSW.SoftwareUpdate = new SWUpdate(sArg.Trim('"').Trim());

                                if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
                                {
                                    Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!");
                                    continue;
                                }


                                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)
                                {
                                    if (!string.IsNullOrEmpty(sPreReq))
                                    {
                                        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.");
                                    }
                                    else
                                    {
                                        Console.WriteLine("... Error. The installation failed.");
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Error: " + ex.Message);
                            }
                        }
                    }
                }
            }
            if (lArgs.Count == 2)
            {
                RZUpdater oRZUpdate = new RZUpdater();
                var       oUpdate   = oRZUpdate.CheckForUpdate(lArgs[0], lArgs[1]);
                if (oUpdate != null)
                {
                    Console.WriteLine("New Version: " + oUpdate.SW.ProductVersion);
                    Console.Write("Downloading...");

                    if (oUpdate.Download().Result)
                    {
                        Console.WriteLine("... done.");
                        Console.Write("Installing...");
                        if (oUpdate.Install(false, true).Result)
                        {
                            Console.WriteLine("... done.");
                        }
                        else
                        {
                            Console.WriteLine("... Error. The update installation failed.");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("No Update found...");
                }
            }

            if (lArgs.Count == 3)
            {
                RZUpdater oRZUpdate = new RZUpdater();
                var       oUpdate   = oRZUpdate.CheckForUpdate(lArgs[0], lArgs[1], lArgs[2]);
                if (oUpdate != null)
                {
                    Console.WriteLine("New Version: " + oUpdate.SW.ProductVersion);
                    Console.Write("Downloading...");

                    if (oUpdate.Download().Result)
                    {
                        Console.WriteLine("... done.");
                        Console.Write("Installing...");
                        if (oUpdate.Install(false, true).Result)
                        {
                            Console.WriteLine("... done.");
                        }
                        else
                        {
                            Console.WriteLine("... Error. The update installation failed.");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("No Update found...");
                }
            }

            System.Threading.Thread.Sleep(1000);
        }
예제 #14
0
        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());
            }
        }
예제 #15
0
        public void RZInst(string s1)
        {
            try
            {
                Random    rnd   = new Random();
                RZUpdater oRZSW = new RZUpdater();
                oRZSW.SoftwareUpdate = new SWUpdate(s1);
                if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
                {
                    sScriptResult    = "'" + s1 + "' is NOT available in RuckZuck...!";
                    rnd              = new Random();
                    tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit
                }

                if (oRZSW.SoftwareUpdate.SW.PreRequisites == null)
                {
                    oRZSW.SoftwareUpdate.SW.PreRequisites = new string[0];
                }

                foreach (string sPreReq in oRZSW.SoftwareUpdate.SW.PreRequisites)
                {
                    if (!string.IsNullOrEmpty(sPreReq))
                    {
                        RZUpdater oRZSWPreReq = new RZUpdater();
                        oRZSWPreReq.SoftwareUpdate = new SWUpdate(sPreReq);
                        sScriptResult    = "..downloading dependencies (" + oRZSWPreReq.SoftwareUpdate.SW.ShortName + ")";
                        rnd              = new Random();
                        tReInit.Interval = rnd.Next(2000, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit

                        if (oRZSWPreReq.SoftwareUpdate.Download().Result)
                        {
                            sScriptResult    = "..installing dependencies (" + oRZSWPreReq.SoftwareUpdate.SW.ShortName + ")";
                            rnd              = new Random();
                            tReInit.Interval = rnd.Next(2000, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit

                            if (oRZSWPreReq.SoftwareUpdate.Install(false, true).Result)
                            {
                            }
                            else
                            {
                                sScriptResult    = oRZSWPreReq.SoftwareUpdate.SW.ShortName + " failed.";
                                rnd              = new Random();
                                tReInit.Interval = rnd.Next(2000, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit
                            }
                        }
                    }
                }

                sScriptResult    = "..downloading " + oRZSW.SoftwareUpdate.SW.ShortName;
                rnd              = new Random();
                tReInit.Interval = rnd.Next(2000, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit

                if (oRZSW.SoftwareUpdate.Download().Result)
                {
                    sScriptResult    = "..installing " + oRZSW.SoftwareUpdate.SW.ShortName;
                    rnd              = new Random();
                    tReInit.Interval = rnd.Next(2000, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit

                    if (oRZSW.SoftwareUpdate.Install(false, true).Result)
                    {
                        sScriptResult    = "Installed: " + oRZSW.SoftwareUpdate.SW.ShortName;
                        rnd              = new Random();
                        tReInit.Interval = rnd.Next(3000, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit
                    }
                    else
                    {
                        sScriptResult    = "Failed: " + oRZSW.SoftwareUpdate.SW.ShortName;
                        rnd              = new Random();
                        tReInit.Interval = rnd.Next(3000, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit
                    }
                }
            }
            catch (Exception ex)
            {
                sScriptResult = s1 + " : " + ex.Message;
                Random rnd = new Random();
                tReInit.Interval = rnd.Next(3000, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit
            }
        }
예제 #16
0
        private static int ProcessBotQueue()
        {
            Console.WriteLine("Get failed installations from queue...");
            List <GetSoftware> lCat = RZRestAPIv2.GetCatalog();

            string sURL     = "https://ruckzuck.queue.core.windows.net/rzbot/messages";
            string sasToken = Properties.Settings.Default.SASToken;

            List <string> DLQueue  = new List <string>();
            List <string> BotQueue = new List <string>();
            Dictionary <string, string> IDQueue = new Dictionary <string, string>();
            int iMessageCount = 33;
            int iResult       = 0;
            int icount        = 0;

            //Get bulk of 32 Messages
            while (iMessageCount >= 32 && icount <= 20 && iResult <= 20)
            {
#if !DEBUG
                if ((DateTime.Now - tStart).TotalHours >= 2)
                {
                    Console.WriteLine("Max. runtime of 2h exceeded...");

                    return(-1);
                }
#endif

                using (HttpClient oClient = new HttpClient())
                {
                    string url  = $"{sURL}?numofmessages=32&{sasToken}";
                    var    oRes = oClient.GetStringAsync(url);
                    oRes.Wait();
                    string      sXML   = oRes.Result.ToString();
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(sXML);
                    iMessageCount = xmlDoc.SelectNodes("QueueMessagesList/QueueMessage").Count;
                    icount++;
                    foreach (XmlNode xNode in xmlDoc.SelectNodes("QueueMessagesList/QueueMessage"))
                    {
                        iResult++;
                        //if (iResult > 10)
                        //    continue;
                        try
                        {
                            string sMessageID  = xNode["MessageId"].InnerText;
                            string Shortname   = xNode["MessageText"].InnerText;
                            string sPopReceipt = xNode["PopReceipt"].InnerText;

                            if (lDelete.Contains(Shortname.ToLower()))
                            {
                                IDQueue.Add(sMessageID, sPopReceipt);
                                continue;
                            }

                            if (lDone.Contains(Shortname.ToLower()))
                            {
                                continue;
                            }

                            try
                            {
                                try
                                {
                                    RZUpdater oRZSW = new RZUpdater();
                                    oRZSW.SoftwareUpdate = new SWUpdate(Shortname);

                                    oRZSW.SoftwareUpdate.SendFeedback = false; //we already process feedback...
                                    if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                                    {
                                        oRZSW.SoftwareUpdate.GetInstallType();
                                    }

                                    if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
                                    {
                                        Console.ForegroundColor = ConsoleColor.Red;
                                        Console.WriteLine("Error: Product not valid... " + Shortname);
                                        Console.ResetColor();
                                        continue;
                                    }
                                    else
                                    {
                                        Console.ForegroundColor = ConsoleColor.Blue;
                                        Console.WriteLine(oRZSW.SoftwareUpdate.SW.Manufacturer + " " + oRZSW.SoftwareUpdate.SW.ProductName + " " + oRZSW.SoftwareUpdate.SW.ProductVersion);
                                        Console.ResetColor();

                                        Console.Write("Downloading...");
                                        foreach (string sPreReq in oRZSW.SoftwareUpdate.SW.PreRequisites)
                                        {
                                            RZUpdater oRZSWPreReq = new RZUpdater();
                                            oRZSWPreReq.SoftwareUpdate = new SWUpdate(sPreReq);
                                            oRZSWPreReq.SoftwareUpdate.SendFeedback = false;
                                            Console.WriteLine();
                                            Console.Write("\tDownloading dependencies (" + oRZSWPreReq.SoftwareUpdate.SW.ShortName + ")...");
                                            if (oRZSWPreReq.SoftwareUpdate.Download().Result)
                                            {
                                                Console.ForegroundColor = ConsoleColor.Green;
                                                Console.WriteLine("... done.");
                                                Console.ResetColor();
                                                Console.Write("\tInstalling dependencies (" + oRZSWPreReq.SoftwareUpdate.SW.ShortName + ")...");
                                                if (oRZSWPreReq.SoftwareUpdate.Install(false, true).Result)
                                                {
                                                    Console.ForegroundColor = ConsoleColor.Green;
                                                    Console.WriteLine("... done.");
                                                    Console.ResetColor();
                                                    //lPackages.Add(oRZSWPreReq.SoftwareUpdate.SW.ShortName);
                                                }
                                                else
                                                {
                                                    Console.ForegroundColor = ConsoleColor.Red;
                                                    Console.WriteLine("... Error. The installation failed.");
                                                    Console.ResetColor();
                                                    continue;
                                                }
                                            }
                                        }
                                        if (oRZSW.SoftwareUpdate.Download().Result)
                                        {
                                            Console.ForegroundColor = ConsoleColor.Green;
                                            Console.WriteLine("... done.");
                                            Console.ResetColor();

                                            Console.Write("Installing...");
                                            if (oRZSW.SoftwareUpdate.Install(false, true).Result)
                                            {
                                                Console.ForegroundColor = ConsoleColor.Green;
                                                Console.WriteLine("... done.");
                                                DeleteFromQueueAsync(sURL, sasToken, sMessageID, sPopReceipt).Wait(2000);
                                                lDone.Add(Shortname.ToLower());
                                                lDelete.Add(Shortname.ToLower());
                                                Console.ResetColor();
                                            }
                                            else
                                            {
                                                Console.ForegroundColor = ConsoleColor.Red;
                                                Console.WriteLine("... Error. Installation failed.");
                                                Console.ResetColor();
                                                lDone.Add(Shortname.ToLower());
                                                continue;
                                            }
                                        }
                                        else
                                        {
                                            Console.ForegroundColor = ConsoleColor.Red;
                                            Console.WriteLine("... Error. Download failed.");
                                            Console.ResetColor();
                                            lDone.Add(Shortname.ToLower());
                                            continue;
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.ForegroundColor = ConsoleColor.Red;
                                    Console.WriteLine("ERROR(1): " + ex.Message);
                                    Console.ResetColor();
                                    lDone.Add(Shortname.ToLower());
                                    continue;
                                }

                                Console.ResetColor();

                                //lDone.Add(Shortname.ToLower());
                                //IDQueue.Add(sMessageID, sPopReceipt);
                            }
                            catch { }
                        }
                        catch (Exception ex)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("ERROR(2): " + ex.Message);
                            Console.ResetColor();
                        }
                    }
                }
            }

            foreach (var sID in IDQueue)
            {
                DeleteFromQueueAsync(sURL, sasToken, sID.Key, sID.Value).Wait(2000);
            }

            return(iResult);
        }
예제 #17
0
        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();
                                        RZRestAPIv2.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();
        }
예제 #18
0
        static int Main(string[] args)
        {
            bool bError = false;

            //Get Proxy from IE
            WebRequest.DefaultWebProxy = WebRequest.GetSystemWebProxy();

            if (!string.IsNullOrEmpty(Properties.Settings.Default.Customerid))
            {
                RZRestAPIv2.CustomerID = Properties.Settings.Default.Customerid;
            }

            RZRestAPIv2.DisableBroadcast = Properties.Settings.Default.DisableBroadcast;

            List <string> lArgs = args.ToList();

            if (lArgs.Contains("-?") | lArgs.Contains("/?") | lArgs.Count < 1)
            {
                Console.WriteLine("RuckZuck CommandLine Tool (c) 2020 by Roger Zander");
                Console.WriteLine("Install:");
                Console.WriteLine("Install a Software from Shortname : RZGet.exe install \"<Shortname>\"[;\"<Shortname2>\"]");
                Console.WriteLine("Install a Software from JSON File : RZGet.exe install \"<JSON full path>\"[;\"<JSON full path>\"]");
                Console.WriteLine("Install a Sepcific Version : RZGet.exe install --name \"<ProductName>\" --vendor \"<Manufacturer>\" --version \"<ProductVersion>\"");
                Console.WriteLine("");
                Console.WriteLine("Update:");
                Console.WriteLine("Update all missing updates : RZGet.exe update --all");
                Console.WriteLine("Show all missing updates : RZGet.exe update --list --all");
                Console.WriteLine("check if a Software requires an update : RZGet.exe update --list \"<Shortname>\"");
                Console.WriteLine("Update a Software from Shortname : RZGet.exe update \"<Shortname>\"[;\"<Shortname2>\"]");
                Console.WriteLine("");
                Console.WriteLine("Show:");
                Console.WriteLine("Show Metadata : RZGet.exe show \"<Shortname>\"");
                Console.WriteLine("Show Metadata for a specific Version : RZGet.exe show --name \"<ProductName>\" --vendor \"<Manufacturer>\" --version \"<ProductVersion>\"");
                Console.WriteLine("");
                Console.WriteLine("Search:");
                Console.WriteLine("Show full Catalog JSON: RZGet.exe search");
                Console.WriteLine("Search for a Keyword: RZGet.exe search zip");
                Console.WriteLine("Search SW in a Category: RZGet.exe search --categories compression");
                Console.WriteLine("Search for installed SW: RZGet.exe search --isinstalled true");
                Console.WriteLine("Search for a manufacturer: RZGet.exe search --manufacturer zander");
                Console.WriteLine("Search for a shortname and return PowerShell Object: RZGet.exe search --shortname ruckzuck | convertfrom-json");
                return(0);
            }

            if (lArgs[0].ToLower() == "install")
            {
                if (lArgs.Contains("--name", StringComparer.CurrentCultureIgnoreCase) || lArgs.Contains("--vendor", StringComparer.CurrentCultureIgnoreCase) || lArgs.Contains("--version", StringComparer.CurrentCultureIgnoreCase))
                {
                    try
                    {
                        RZUpdater oRZSW        = new RZUpdater();
                        string    ProductName  = lArgs[lArgs.FindIndex(t => t.IndexOf("--name", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1];
                        string    Manufacturer = lArgs[lArgs.FindIndex(t => t.IndexOf("--vendor", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1];

                        if (string.IsNullOrEmpty(Manufacturer))
                        {
                            Manufacturer = lArgs[lArgs.FindIndex(t => t.IndexOf("--manufacturer", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1];
                        }

                        string ProductVersion = lArgs[lArgs.FindIndex(t => t.IndexOf("--version", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1];
                        oRZSW.SoftwareUpdate = new SWUpdate(ProductName, ProductVersion, Manufacturer);

                        if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
                        {
                            Console.WriteLine("'" + ProductName + "' is NOT available in RuckZuck...!");
                            return(99);
                        }

                        if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                        {
                            oRZSW.SoftwareUpdate.GetInstallType();
                            if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                            {
                                Console.WriteLine("PreRequisites not valid for '" + oRZSW.SoftwareUpdate.SW.ShortName + "'...!");
                                return(91);
                            }
                        }

                        if (Install(oRZSW))
                        {
                            return(0);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: " + ex.Message);
                        return(1);
                    }
                }

                foreach (string sArg in args.Skip(1))
                {
                    if (File.Exists(sArg))
                    {
                        RZUpdater oRZSW = new RZUpdater(sArg);

                        if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
                        {
                            Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!");
                            bError = true;
                            continue;
                        }

                        if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                        {
                            oRZSW.SoftwareUpdate.GetInstallType();
                            if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                            {
                                Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!");
                                bError = false;
                                continue;
                            }
                        }

                        if (Install(oRZSW))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        try
                        {
                            RZUpdater oRZSW = new RZUpdater();
                            oRZSW.SoftwareUpdate = new SWUpdate(sArg.Trim('"').Trim());

                            if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
                            {
                                Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!");
                                bError = true;
                                continue;
                            }

                            if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                            {
                                oRZSW.SoftwareUpdate.GetInstallType();
                                if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                                {
                                    Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!");
                                    bError = false;
                                    continue;
                                }
                            }

                            if (Install(oRZSW))
                            {
                                continue;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Error: " + ex.Message);
                            bError = true;
                        }
                    }
                }

                if (bError)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }

            if (lArgs[0].ToLower() == "update")
            {
                bool bUpdateAll = false;
                bool bList      = false;

                if (lArgs.Contains("--all", StringComparer.CurrentCultureIgnoreCase))
                {
                    bUpdateAll = true;
                }
                if (lArgs.Contains("--list", StringComparer.CurrentCultureIgnoreCase))
                {
                    bList = true;
                }

                RZScan oScan = new RZScan(false);
                oScan.GetSWRepository().Wait(10000);
                oScan.SWScanAsync().Wait(10000);
                oScan._CheckUpdates(null);

                List <string> lUpdate = new List <string>();
                if (!bUpdateAll)
                {
                    foreach (string sArg in args.Skip(1))
                    {
                        if (oScan.NewSoftwareVersions.Count(t => t.ShortName.ToLower() == sArg.ToLower()) > 0)
                        {
                            lUpdate.Add(sArg);
                        }
                    }
                }
                else
                {
                    lUpdate = oScan.NewSoftwareVersions.Select(t => t.ShortName).ToList();
                }

                foreach (string sArg in lUpdate)
                {
                    if (bList)
                    {
                        Console.WriteLine(sArg);
                        continue;
                    }
                    if (File.Exists(sArg))
                    {
                        RZUpdater oRZSW = new RZUpdater(sArg);

                        if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
                        {
                            Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!");
                            bError = true;
                            continue;
                        }

                        if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                        {
                            oRZSW.SoftwareUpdate.GetInstallType();
                            if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                            {
                                Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!");
                                bError = false;
                                continue;
                            }
                        }

                        if (Install(oRZSW))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        try
                        {
                            RZUpdater oRZSW = new RZUpdater();
                            oRZSW.SoftwareUpdate = new SWUpdate(sArg.Trim('"').Trim());

                            if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
                            {
                                Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!");
                                bError = true;
                                continue;
                            }

                            if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                            {
                                oRZSW.SoftwareUpdate.GetInstallType();
                                if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
                                {
                                    Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!");
                                    bError = false;
                                    continue;
                                }
                            }

                            if (Install(oRZSW))
                            {
                                continue;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Error: " + ex.Message);
                            bError = true;
                        }
                    }
                }

                if (bError)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }

            //if (lArgs[0].ToLower() == "hash")
            //{
            //    Console.WriteLine("hash");
            //    Console.WriteLine(string.Join(";", args.Skip(1)));
            //    return 0;
            //}

            if (lArgs[0].ToLower() == "search")
            {
                if (lArgs[1] != null)
                {
                    if (lArgs[1].StartsWith("--"))
                    {
                        string sProp   = lArgs[1].ToLower().TrimStart('-');
                        string sSearch = lArgs[2].ToLower();

                        if (sProp == "shortname")
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ShortName.ToLower().Contains(sSearch)), Formatting.Indented).ToString());
                        }

                        if (sProp == "manufacturer")
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.Manufacturer.ToLower().Contains(sSearch)), Formatting.Indented).ToString());
                        }

                        if (sProp == "productname" || sProp == "name")
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ProductName.ToLower().Contains(sSearch)), Formatting.Indented).ToString());
                        }

                        if (sProp == "description")
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.Description.ToLower().Contains(sSearch)), Formatting.Indented).ToString());
                        }

                        if (sProp == "categories" || sProp == "category")
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => string.Join(";", t.Categories.ToArray()).ToLower().Contains(sSearch)), Formatting.Indented).ToString());
                        }

                        if (sProp == "producturl" || sProp == "url")
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ProductURL.ToLower().Contains(sSearch)), Formatting.Indented).ToString());
                        }

                        if (sProp == "productversion" || sProp == "version")
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ProductVersion.ToLower().Contains(sSearch)), Formatting.Indented).ToString());
                        }

                        if (sProp == "isinstalled")
                        {
                            oScan = new RZScan(false, false);
                            oScan.SWScanAsync().Wait();
                            oScan.GetSWRepository().Wait();
                            foreach (var osw in oScan.InstalledSoftware)
                            {
                                var oItem = oScan.SoftwareRepository.FirstOrDefault(t => t.ProductName == osw.ProductName && t.Manufacturer == osw.Manufacturer && t.ProductVersion == osw.ProductVersion);
                                if (oItem != null)
                                {
                                    oItem.isInstalled = true;
                                }
                            }

                            Console.WriteLine(JsonConvert.SerializeObject(oScan.SoftwareRepository.Where(t => t.isInstalled.ToString().ToLower().Contains(sSearch)), Formatting.Indented).ToString());
                        }
                    }
                    else
                    {
                        string sSearch = lArgs[1].ToLower();
                        Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ProductName.ToLower().Contains(sSearch) || t.Manufacturer.ToLower().Contains(sSearch) || t.ShortName.ToLower().Contains(sSearch)), Formatting.Indented).ToString());
                    }
                }
                else
                {
                    Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog(), Formatting.Indented).ToString());
                }
                return(0);
            }

            if (lArgs[0].ToLower() == "show")
            {
                if (lArgs.Contains("--name", StringComparer.CurrentCultureIgnoreCase) || lArgs.Contains("--vendor", StringComparer.CurrentCultureIgnoreCase) || lArgs.Contains("--version", StringComparer.CurrentCultureIgnoreCase))
                {
                    try
                    {
                        RZUpdater oRZSW        = new RZUpdater();
                        string    ProductName  = lArgs[lArgs.FindIndex(t => t.IndexOf("--name", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1];
                        string    Manufacturer = lArgs[lArgs.FindIndex(t => t.IndexOf("--vendor", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1];

                        if (string.IsNullOrEmpty(Manufacturer))
                        {
                            Manufacturer = lArgs[lArgs.FindIndex(t => t.IndexOf("--manufacturer", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1];
                        }

                        string ProductVersion = lArgs[lArgs.FindIndex(t => t.IndexOf("--version", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1];
                        oRZSW.SoftwareUpdate = new SWUpdate(ProductName, ProductVersion, Manufacturer);

                        if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
                        {
                            Console.WriteLine("'" + ProductName + "' is NOT available in RuckZuck...!");
                            return(99);
                        }

                        Console.WriteLine(JsonConvert.SerializeObject(oRZSW.SoftwareUpdate.SW, Formatting.Indented).ToString());

                        return(0);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: " + ex.Message);
                        return(1);
                    }
                }

                foreach (string sArg in args.Skip(1))
                {
                    if (File.Exists(sArg))
                    {
                        RZUpdater oRZSW = new RZUpdater(sArg);

                        Console.WriteLine(JsonConvert.SerializeObject(oRZSW.SoftwareUpdate.SW, Formatting.Indented).ToString());
                    }
                    else
                    {
                        try
                        {
                            RZUpdater oRZSW = new RZUpdater();
                            oRZSW.SoftwareUpdate = new SWUpdate(sArg.Trim('"').Trim());

                            if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
                            {
                                Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!");
                                bError = true;
                                continue;
                            }

                            Console.WriteLine(JsonConvert.SerializeObject(oRZSW.SoftwareUpdate.SW, Formatting.Indented).ToString());

                            return(0);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Error: " + ex.Message);
                            return(1);
                        }
                    }
                }

                return(0);
            }

            //if (lArgs[0].ToLower() == "source")
            //{
            //    Console.WriteLine("source");
            //    Console.WriteLine(string.Join(";", args.Skip(1)));
            //    return 0;
            //}

            //if (lArgs[0].ToLower() == "validate")
            //{
            //    Console.WriteLine("validate");
            //    Console.WriteLine(string.Join(";", args.Skip(1)));
            //    return 0;
            //}

            //if (lArgs.Count == 1)
            //{
            //    if (File.Exists(lArgs[0]))
            //    {
            //        RZUpdater oRZSW = new RZUpdater(lArgs[0]);

            //        Console.WriteLine(oRZSW.SoftwareUpdate.SW.ProductName + " " + oRZSW.SoftwareUpdate.SW.ProductVersion + " :");
            //        Console.Write("Downloading...");
            //        if (oRZSW.SoftwareUpdate.Download().Result)
            //        {
            //            Console.WriteLine("... done.");
            //            Console.Write("Installing...");
            //            if (oRZSW.SoftwareUpdate.Install(false,true).Result)
            //            {
            //                Console.WriteLine("... done.");
            //            }
            //            else
            //            {
            //                Console.WriteLine("... Error. The installation failed.");
            //            }
            //        }
            //    }
            //    else
            //    {
            //        if (lArgs[0].ToLower() == "/update" | lArgs[0].ToLower() == "-update")
            //        {
            //            oUpdate = new RZUpdater();
            //            oScan = new RZScan(true, true);
            //            Console.Write("Detecting updates...");
            //            oScan.OnUpdScanCompleted += OScan_OnUpdScanCompleted;

            //            while (bRunning)
            //            {
            //                System.Threading.Thread.Sleep(100);
            //            }
            //        }
            //        else
            //        {
            //            foreach (string sArg in lArgs[0].Split(';'))
            //            {
            //                try
            //                {
            //                    RZUpdater oRZSW = new RZUpdater();
            //                    oRZSW.SoftwareUpdate = new SWUpdate(sArg.Trim('"').Trim());

            //                    if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName))
            //                    {
            //                        Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!");
            //                        bError = true;
            //                        continue;
            //                    }
            //                    Console.WriteLine("PS:" + oRZSW.SoftwareUpdate.SW.PSInstall);
            //                    if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
            //                    {
            //                        oRZSW.SoftwareUpdate.GetInstallType();
            //                        if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall))
            //                        {
            //                            Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!");
            //                            bError = false;
            //                            continue;
            //                        }
            //                    }


            //                    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)
            //                    {
            //                        if (!string.IsNullOrEmpty(sPreReq))
            //                        {
            //                            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.");
            //                                    bError = true;
            //                                }
            //                            }
            //                        }

            //                    }
            //                    if (oRZSW.SoftwareUpdate.Download().Result)
            //                    {
            //                        Console.WriteLine("... done.");
            //                        Console.Write("Installing...");
            //                        if (oRZSW.SoftwareUpdate.Install(false, true).Result)
            //                        {
            //                            Console.WriteLine("... done.");
            //                        }
            //                        else
            //                        {
            //                            Console.WriteLine("... Error. The installation failed.");
            //                            bError = true;
            //                        }
            //                    }
            //                }
            //                catch (Exception ex)
            //                {
            //                    Console.WriteLine("Error: " + ex.Message);
            //                    bError = true;
            //                }
            //            }


            //        }
            //    }
            //}

            //if (lArgs.Count == 3)
            //{
            //    RZUpdater oRZUpdate = new RZUpdater();
            //    oRZUpdate.SoftwareUpdate = new SWUpdate(lArgs[0], lArgs[1], lArgs[2]);
            //    if (oRZUpdate.SoftwareUpdate != null)
            //    {
            //        Console.WriteLine("New Version: " + oRZUpdate.SoftwareUpdate.SW.ProductVersion);
            //        Console.Write("Downloading...");

            //        if (oRZUpdate.SoftwareUpdate.Download().Result)
            //        {
            //            Console.WriteLine("... done.");
            //            Console.Write("Installing...");
            //            if (oRZUpdate.SoftwareUpdate.Install(false, true).Result)
            //            {
            //                Console.WriteLine("... done.");
            //                return 0;
            //            }
            //            else
            //            {
            //                Console.WriteLine("... Error. The update installation failed.");
            //                return 1;
            //            }
            //        }

            //        return 99;
            //    }
            //    else
            //    {
            //        Console.WriteLine("No Update found...");
            //        return 0;
            //    }
            //}

            //System.Threading.Thread.Sleep(500);
            //if(bError)
            //    return 2;

            return(0);
        }
예제 #19
0
        private void Connect()
        {
            try
            {
                connection.Stop();
                connection.Start().ContinueWith(task => {
                    if (task.IsFaulted)
                    {
                        Console.WriteLine("There was an error opening the connection:{0}", task.Exception.GetBaseException());
                    }
                    else
                    {
                        //Obsolete
                        myHub.On <string, string>("getPS", (s1, s2) =>
                        {
                            //using (PowerShell PowerShellInstance = PowerShell.Create())
                            //{
                            //    try
                            //    {
                            //        PowerShellInstance.AddScript(s1);
                            //        var PSResult = PowerShellInstance.Invoke();
                            //        if (PSResult.Count() > 0)
                            //        {
                            //            string sResult = PSResult.Last().BaseObject.ToString();
                            //            if (sResult != sScriptResult) //obsolete from 1.0.07 -> returnPS
                            //            {
                            //                sScriptResult = sResult;
                            //                Random rnd = new Random();
                            //                tReInit.Interval = rnd.Next(1000, 10000); //wait max 10s to ReInit
                            //            }

                            //            myHub.Invoke<string>("Respond", s2, Environment.MachineName + ":" + sResult).ContinueWith(task1 =>
                            //            {
                            //                if (task1.IsFaulted)
                            //                {
                            //                    Console.WriteLine("There was an error calling send: {0}", task1.Exception.GetBaseException());
                            //                }
                            //            });
                            //        }
                            //    }
                            //    catch (Exception ex)
                            //    {
                            //        Console.WriteLine("There was an error: {0}", ex.Message);
                            //    }
                            //}

                            //Program.MinimizeFootprint();
                        });

                        myHub.On <string, string>("returnPS", (s1, s2) =>
                        {
                            using (PowerShell PowerShellInstance = PowerShell.Create())
                            {
                                try
                                {
                                    PowerShellInstance.AddScript(s1);
                                    var PSResult = PowerShellInstance.Invoke();
                                    if (PSResult.Count() > 0)
                                    {
                                        string sResult = PSResult.Last().BaseObject.ToString();
                                        if (sResult != sScriptResult)
                                        {
                                            sScriptResult    = sResult;
                                            Random rnd       = new Random();
                                            tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max Xs to ReInit
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("There was an error: {0}", ex.Message);
                                }
                            }

                            Program.MinimizeFootprint();
                        });

                        //New 0.9.0.6
                        myHub.On <string, string>("returnPSAsync", (s1, s2) =>
                        {
                            var tSWScan = Task.Run(() =>
                            {
                                using (PowerShell PowerShellInstance = PowerShell.Create())
                                {
                                    try
                                    {
                                        PowerShellInstance.AddScript(s1);
                                        var PSResult = PowerShellInstance.Invoke();
                                        if (PSResult.Count() > 0)
                                        {
                                            string sResult = PSResult.Last().BaseObject.ToString();
                                            if (sResult != sScriptResult)
                                            {
                                                sScriptResult    = sResult;
                                                Random rnd       = new Random();
                                                tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max Xs to ReInit
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine("There was an error: {0}", ex.Message);
                                    }
                                }

                                Program.MinimizeFootprint();
                            });
                        });

                        myHub.On <string>("init", (s1) =>
                        {
                            try
                            {
                                myHub.Invoke <string>("Init", Hostname).ContinueWith(task1 =>
                                {
                                });
                            }
                            catch { }
                            try
                            {
                                foreach (string sGroup in Properties.Settings.Default.Groups.Split(';'))
                                {
                                    myHub.Invoke <string>("JoinGroup", sGroup).ContinueWith(task1 =>
                                    {
                                    });
                                }
                                Program.MinimizeFootprint();
                            }
                            catch { }
                        });

                        myHub.On <string>("status", (s1) =>
                        {
                            try
                            {
                                string sResult = "{}";
                                using (PowerShell PowerShellInstance = PowerShell.Create())
                                {
                                    try
                                    {
                                        PowerShellInstance.AddScript(Properties.Settings.Default.PSStatus);
                                        var PSResult = PowerShellInstance.Invoke();
                                        if (PSResult.Count() > 0)
                                        {
                                            sResult      = PSResult.Last().BaseObject.ToString();
                                            sResult      = sResult.Replace(Environment.MachineName, Hostname);
                                            JObject jRes = JObject.Parse(sResult);
                                            jRes.Add("ScriptResult", sScriptResult);
                                            jRes.Add("Groups", Properties.Settings.Default.Groups);
                                            sResult = jRes.ToString();
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine("There was an error: {0}", ex.Message);
                                    }
                                }

                                myHub.Invoke("Status", new object[] { Hostname, sResult }).ContinueWith(task1 =>
                                {
                                });
                                Program.MinimizeFootprint();
                            }
                            catch { }
                        });

                        myHub.On <string>("version", (s1) =>
                        {
                            try
                            {
                                //Get File-Version
                                sScriptResult = (FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location)).FileVersion.ToString();

                                Random rnd       = new Random();
                                tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit
                            }
                            catch { }
                        });

                        myHub.On <string>("wol", (s1) =>
                        {
                            try
                            {
                                if (!string.IsNullOrEmpty(s1))
                                {
                                    foreach (string sMAC in s1.Split(';'))
                                    {
                                        WOL.WakeUp(sMAC);
                                    }
                                }
                            }
                            catch { }
                        });

                        myHub.On <string>("setinstance", (s1) =>
                        {
                            try
                            {
                                if (!string.IsNullOrEmpty(s1))
                                {
                                    string sConfig  = Assembly.GetExecutingAssembly().Location + ".config";
                                    XmlDocument doc = new XmlDocument();
                                    doc.Load(sConfig);
                                    doc.SelectSingleNode("/configuration/applicationSettings/DevCDRAgent.Properties.Settings/setting[@name='Instance']/value").InnerText = s1;
                                    doc.Save(sConfig);
                                    RestartService();

                                    //Update Advanced Installer Persistent Properties
                                    RegistryKey myKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Zander Tools\\{0AC43E24-4308-4BE7-A369-D50DB4056B32}", true);
                                    if (myKey != null)
                                    {
                                        myKey.SetValue("INSTANCE", s1.Trim(), RegistryValueKind.String);
                                        myKey.Close();
                                    }
                                }
                            }
                            catch { }
                        });

                        myHub.On <string>("setendpoint", (s1) =>
                        {
                            try
                            {
                                if (!string.IsNullOrEmpty(s1))
                                {
                                    if (s1.StartsWith("https://"))
                                    {
                                        string sConfig  = Assembly.GetExecutingAssembly().Location + ".config";
                                        XmlDocument doc = new XmlDocument();
                                        doc.Load(sConfig);
                                        doc.SelectSingleNode("/configuration/applicationSettings/DevCDRAgent.Properties.Settings/setting[@name='Endpoint']/value").InnerText = s1;
                                        doc.Save(sConfig);
                                        RestartService();

                                        //Update Advanced Installer Persistent Properties
                                        RegistryKey myKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Zander Tools\\{0AC43E24-4308-4BE7-A369-D50DB4056B32}", true);
                                        if (myKey != null)
                                        {
                                            myKey.SetValue("ENDPOINT", s1.Trim(), RegistryValueKind.String);
                                            myKey.Close();
                                        }
                                    }
                                }
                            }
                            catch { }
                        });

                        myHub.On <string>("setgroups", (s1) =>
                        {
                            try
                            {
                                if (!string.IsNullOrEmpty(s1))
                                {
                                    string sConfig  = Assembly.GetExecutingAssembly().Location + ".config";
                                    XmlDocument doc = new XmlDocument();
                                    doc.Load(sConfig);
                                    doc.SelectSingleNode("/configuration/applicationSettings/DevCDRAgent.Properties.Settings/setting[@name='Groups']/value").InnerText = s1;
                                    doc.Save(sConfig);

                                    RestartService();

                                    //Update Advanced Installer Persistent Properties
                                    RegistryKey myKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Zander Tools\\{0AC43E24-4308-4BE7-A369-D50DB4056B32}", true);
                                    if (myKey != null)
                                    {
                                        myKey.SetValue("GROUPS", s1.Trim(), RegistryValueKind.String);
                                        myKey.Close();
                                    }
                                }
                            }
                            catch { }
                        });

                        myHub.On <string>("getgroups", (s1) =>
                        {
                            try
                            {
                                if (!string.IsNullOrEmpty(s1))
                                {
                                    sScriptResult = Properties.Settings.Default.Groups;

                                    Random rnd       = new Random();
                                    tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit
                                }
                            }
                            catch { }
                        });

                        myHub.On <string>("restartservice", (s1) =>
                        {
                            try
                            {
                                RestartService();
                                sScriptResult = "restart Agent...";
                            }
                            catch { }
                        });

                        myHub.On <string>("rzinstall", (s1) =>
                        {
                            RZInst(s1);
                        });

                        myHub.On <string>("rzupdate", (s1) =>
                        {
                            var tSWScan = Task.Run(() =>
                            {
                                try
                                {
                                    sScriptResult    = "Detecting RZ updates...";
                                    Random rnd       = new Random();
                                    tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit

                                    RZUpdater oUpdate = new RZUpdater();
                                    RZScan oScan      = new RZScan(false, false);

                                    oScan.GetSWRepository().Wait(30000);
                                    oScan.SWScan().Wait(30000);
                                    oScan.CheckUpdates(null).Wait(30000);

                                    sScriptResult    = oScan.NewSoftwareVersions.Count.ToString() + " RZ updates found";
                                    rnd              = new Random();
                                    tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit

                                    List <string> lSW = new List <string>();
                                    foreach (var oSW in oScan.NewSoftwareVersions)
                                    {
                                        RZInst(oSW.Shortname);
                                    }
                                }
                                catch { }
                            });
                        });

                        myHub.On <string>("rzscan", (s1) =>
                        {
                            var tSWScan = Task.Run(() =>
                            {
                                try
                                {
                                    sScriptResult    = "Detecting updates...";
                                    Random rnd       = new Random();
                                    tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit

                                    RZUpdater oUpdate = new RZUpdater();
                                    RZScan oScan      = new RZScan(false, false);

                                    oScan.GetSWRepository().Wait(30000);
                                    oScan.SWScan().Wait(30000);
                                    oScan.CheckUpdates(null).Wait(30000);

                                    List <string> lSW = new List <string>();
                                    foreach (var SW in oScan.NewSoftwareVersions)
                                    {
                                        lSW.Add(SW.Shortname + " " + SW.ProductVersion + " (old:" + SW.MSIProductID + ")");
                                    }

                                    sScriptResult    = JsonConvert.SerializeObject(lSW);
                                    rnd              = new Random();
                                    tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit
                                }
                                catch { }
                            });
                        });

                        myHub.Invoke <string>("Init", Hostname).ContinueWith(task1 => {
                            if (task1.IsFaulted)
                            {
                                Console.WriteLine("There was an error calling send: {0}", task1.Exception.GetBaseException());
                            }
                            else
                            {
                                try
                                {
                                    foreach (string sGroup in Properties.Settings.Default.Groups.Split(';'))
                                    {
                                        myHub.Invoke <string>("JoinGroup", sGroup).ContinueWith(task2 =>
                                        {
                                        });
                                    }
                                    Program.MinimizeFootprint();
                                }
                                catch { }
                            }
                        });
                    }
                }).Wait();
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was an error: {0}", ex.Message);
            }
        }