Ejemplo n.º 1
0
 private void OSCAN_OnInstalledSWAdded(object sender, EventArgs e)
 {
     oSCAN.CheckUpdatesAsync(new List <AddSoftware>()
     {
         ((AddSoftware)sender)
     });
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Check if RuckZuck Token is still valid or request a new token if last refresh was mor than an hour
        /// </summary>
        /// <param name="request"></param>
        //private void _reAuthenticate(Request request)
        //{
        //    //Check if there is a token..
        //    //Guid gToken;
        //    //if (!Guid.TryParse(_AuthenticationToken, out gToken))
        //    //{
        //    //    dLastTokenRefresh = new DateTime();
        //    //}

        //    //Re-Authenticate after 30min
        //    if ((DateTime.Now - dLastTokenRefresh).TotalMinutes >= 30)
        //    {


        //        if (string.IsNullOrEmpty(Properties.Settings.Default.Location))
        //        {
        //            //Properties.Settings.Default.Location = WebServiceURL;
        //            //Properties.Settings.Default.Save();

        //        }

        //        //RZRestAPI.sURL = Properties.Settings.Default.Location;

        //        if (!string.IsNullOrEmpty(Properties.Settings.Default.Username))
        //        {
        //            //_AuthenticationToken = RZRestAPI.GetAuthToken(Properties.Settings.Default.Username, ToInsecureString(DecryptString(Properties.Settings.Default.Password)));
        //            //dLastTokenRefresh = DateTime.Now;
        //            request.Debug("RZ Account: " + Properties.Settings.Default.Username);
        //        }
        //        else
        //        {
        //            //_AuthenticationToken = RZRestAPI.GetAuthToken("FreeRZ", GetTimeToken());
        //            dLastTokenRefresh = DateTime.Now;
        //            request.Debug("RZ Account: FreeRZ");
        //        }

        //        //if (!Guid.TryParse(_AuthenticationToken, out gToken))
        //        //{
        //        //    dLastTokenRefresh = new DateTime();
        //        //    request.Warning(_AuthenticationToken);
        //        //    _AuthenticationToken = "";
        //        //    return;
        //        //}

        //        request.Debug("RZ Authentication Token:" + _AuthenticationToken);
        //    }
        //}

        private void _findPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, Request request)
        {
            //_reAuthenticate(request); //Check if AuthToken is still valid

            try
            {
                bool exactSearch = true;
                if (request.OptionKeys.Contains("Contains"))
                {
                    name = request.GetOptionValue("Contains");
                    request.Message("exact search disabled.");
                    exactSearch = false;
                }

                //Search all if no name is specified
                if (string.IsNullOrEmpty(name))
                {
                    exactSearch = false;
                }

                bool bUpdate = false;
                if (request.OptionKeys.Contains("Updates"))
                {
                    request.Message("check updates for installed Software.");
                    bUpdate = true;
                }

                List <GetSoftware> lResult = new List <GetSoftware>();

                //Get all installed SW
                if (bUpdate)
                {
                    oScan.GetSWRepository().Wait(6000);
                    oScan.bCheckUpdates = false;
                    oScan.SWScanAsync().Wait();
                    oScan.CheckUpdatesAsync(null).Wait();
                    lSoftware = oScan.InstalledSoftware;

                    List <AddSoftware> RequiredUpdates = oScan.NewSoftwareVersions; // RZApi.CheckForUpdate(lSoftware.ToArray()).ToList().Where(t => t.Architecture != "new").ToList();
                    foreach (var SW in RequiredUpdates)
                    {
                        try
                        {
                            if (string.IsNullOrEmpty(name))
                            {
                                lResult.Add(new GetSoftware()
                                {
                                    ProductName = SW.ProductName, ProductVersion = SW.ProductVersion, Manufacturer = SW.Manufacturer, ShortName = SW.ShortName, Description = SW.Description, ProductURL = SW.ProductURL
                                });
                            }
                            else
                            {
                                if ((SW.ProductName.ToLowerInvariant() == name.ToLowerInvariant() | SW.ShortName.ToLowerInvariant() == name.ToLowerInvariant()) && exactSearch)
                                {
                                    lResult.Add(new GetSoftware()
                                    {
                                        ProductName = SW.ProductName, ProductVersion = SW.ProductVersion, Manufacturer = SW.Manufacturer, ShortName = SW.ShortName, Description = SW.Description, ProductURL = SW.ProductURL
                                    });
                                }
                                if ((SW.ProductName.ToLowerInvariant().Contains(name.ToLowerInvariant()) | SW.ShortName.ToLowerInvariant().Contains(name.ToLowerInvariant())) && !exactSearch)
                                {
                                    lResult.Add(new GetSoftware()
                                    {
                                        ProductName = SW.ProductName, ProductVersion = SW.ProductVersion, Manufacturer = SW.Manufacturer, ShortName = SW.ShortName, Description = SW.Description, ProductURL = SW.ProductURL
                                    });
                                }
                            }
                        }
                        catch { }
                    }
                    if (lResult.Count == 0)
                    {
                        request.Warning("No updates found...");
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(requiredVersion))
                    {
                        //Find by ShortName
                        if (exactSearch)
                        {
                            if (!string.IsNullOrEmpty(name))
                            {
                                lResult = RZRestAPIv2.GetCatalog().Where(t => t.ShortName.ToLower() == name.ToLower()).OrderBy(t => t.ShortName).ToList();
                            }

                            if (lResult.Count == 0)
                            {
                                //Find any
                                lResult = RZRestAPIv2.GetCatalog().Where(t => t.ProductName.ToLower() == name.ToLower()).OrderBy(t => t.ProductName).ToList();
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(name))
                            {
                                lResult = RZRestAPIv2.GetCatalog().Where(t => t.ShortName.ToLower().Contains(name.ToLower())).OrderBy(t => t.ShortName).ToList();
                            }

                            if (lResult.Count == 0)
                            {
                                //Find any
                                lResult = RZRestAPIv2.GetCatalog().Where(t => t.ProductName.ToLower().Contains(name.ToLower())).OrderBy(t => t.ShortName).ToList();
                            }
                            if (lResult.Count == 0)
                            {
                                //Find any
                                lResult = RZRestAPIv2.GetCatalog().Where(t => t.Manufacturer.ToLower().Contains(name.ToLower())).OrderBy(t => t.ShortName).ToList();
                            }
                        }
                    }
                    else
                    {
                        //Find by Shortname
                        if (exactSearch)
                        {
                            lResult = RZRestAPIv2.GetCatalog().Where(t => t.ShortName.ToLower() == name.ToLower() && t.ProductVersion.ToLower() == requiredVersion.ToLower()).OrderBy(t => t.ShortName).ToList();
                        }
                        else
                        {
                            //Find any
                            lResult = RZRestAPIv2.GetCatalog().Where(t => t.ShortName.ToLower().Contains(name.ToLower()) && t.ProductVersion.ToLower() == requiredVersion.ToLower()).OrderBy(t => t.ShortName).ToList();

                            if (lResult.Count == 0)
                            {
                                lResult = RZRestAPIv2.GetCatalog().Where(t => t.ProductName.ToLower().Contains(name.ToLower()) && t.ProductVersion.ToLower() == requiredVersion.ToLower()).OrderBy(t => t.ShortName).ToList();
                            }

                            if (lResult.Count == 0)
                            {
                                lResult = RZRestAPIv2.GetCatalog().Where(t => t.Manufacturer.ToLower().Contains(name.ToLower()) && t.ProductVersion.ToLower() == requiredVersion.ToLower()).OrderBy(t => t.ShortName).ToList();
                            }
                        }
                    }
                }


                if (minimumVersion != null)
                {
                    try
                    {
                        lResult = lResult.Where(p => Version.Parse(p.ProductVersion) >= Version.Parse(minimumVersion)).ToList();
                    }
                    catch
                    {
                        lResult = lResult.Where(p => p.ProductVersion == minimumVersion).ToList();
                    }
                }
                if (maximumVersion != null)
                {
                    try
                    {
                        lResult = lResult.Where(p => Version.Parse(p.ProductVersion) <= Version.Parse(maximumVersion)).ToList();
                    }
                    catch
                    {
                        lResult = lResult.Where(p => p.ProductVersion == maximumVersion).ToList();
                    }
                }


                foreach (var SW in lResult.OrderBy(t => t.ShortName))
                {
                    request.YieldSoftwareIdentity(SW.ProductName + ";" + SW.ProductVersion + ";" + SW.Manufacturer, SW.ProductName, SW.ProductVersion, "", SW.Description, RZRestAPIv2.sURL, name, SW.SWId.ToString(), SW.ShortName);
                    //Trust the original RucKZuck source
                    request.AddMetadata("FromTrustedSource", "True");
                    //if (string.Equals(Properties.Settings.Default.Location, RZRestAPIv2.sURL , StringComparison.InvariantCultureIgnoreCase))
                    //{
                    //    request.AddMetadata("FromTrustedSource", "True");
                    //}
                }
            }
            catch (Exception ex)
            {
                request.Debug("E334:" + ex.Message);
            }
        }