public static JArray CheckForUpdates(JArray Softwares) { JArray jResult = new JArray(); foreach (JObject jObj in Softwares) { bool bFound = false; try { string manufacturer = Base.clean(jObj["Manufacturer"].ToString().ToLower()); string productname = Base.clean(jObj["ProductName"].ToString().ToLower()); string productversion = Base.clean(jObj["ProductVersion"].ToString().ToLower()); string sID = Hash.CalculateMD5HashString((manufacturer + productname + productversion).Trim()); JObject oRes = new JObject(); string sRes = ""; //Try to get value from Memory if (_cache.TryGetValue("noupd-" + sID, out sRes)) { continue; } //Try to get value from Memory if (_cache.TryGetValue("upd-" + sID, out oRes)) { jResult.Add(oRes); continue; } string shortname = GetShortname(productname, productversion, manufacturer); #region compare versions if (!string.IsNullOrEmpty(shortname)) { JArray oCat = GetCatalog("", false); var jobj = oCat.SelectTokens("[*].ShortName").Where(t => t.ToString().ToLower() == shortname.ToLower()); if (jobj.FirstOrDefault() == null) { var cacheEntryOptions2 = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(900)); //cache result for 15min _cache.Set("noupd-" + sID, "no", cacheEntryOptions2); continue; } JObject jSW = jobj.FirstOrDefault().Parent.Parent as JObject; try { string sRZVersion = jSW["ProductVersion"].ToString(); if (!string.IsNullOrEmpty(sRZVersion)) { if (productversion == sRZVersion) //same version... { continue; } } try { if (Version.Parse(productversion) > Version.Parse(sRZVersion)) //version is newer { Base.SetShortname(jSW["ProductName"].Value <string>(), productversion, jSW["Manufacturer"].Value <string>(), jSW["ShortName"].Value <string>()); Base.StoreFeedback(jSW["ProductName"].Value <string>(), productversion, jSW["Manufacturer"].Value <string>(), jSW["ShortName"].Value <string>(), "NEW Version ?!", "RZ", true); continue; } if (Version.Parse(productversion) == Version.Parse(sRZVersion)) //version is same { continue; } } catch { try { if (string.Compare(productversion, sRZVersion, true) >= 1) { Base.SetShortname(jSW["ProductName"].Value <string>(), productversion, jSW["Manufacturer"].Value <string>(), jSW["ShortName"].Value <string>()); Base.StoreFeedback(jSW["ProductName"].Value <string>(), productversion, jSW["Manufacturer"].Value <string>(), jSW["ShortName"].Value <string>(), "NEW Version ?!", "RZ", true); continue; } } catch { } } JObject oCatItem = new JObject(); oCatItem.Add("ShortName", jSW["ShortName"]); oCatItem.Add("Description", jSW["Description"]); oCatItem.Add("Manufacturer", jSW["Manufacturer"]); oCatItem.Add("ProductName", jSW["ProductName"]); oCatItem.Add("ProductVersion", jSW["ProductVersion"]); oCatItem.Add("ProductURL", jSW["ProductURL"]); oCatItem.Add("MSIProductID", productversion); //to show the old version in RuckZuck.exe if (jSW["Downloads"] == null) { oCatItem.Add("Downloads", 0); } else { oCatItem.Add("Downloads", jSW["Downloads"]); } if (jSW["SWId"] != null) { if (!string.IsNullOrEmpty(jSW["SWId"].ToString())) { oCatItem.Add("IconId", jSW["SWId"].Value <Int32>()); //for old older Versions only... oCatItem.Add("SWId", jSW["SWId"].Value <Int32>()); } } if (!string.IsNullOrEmpty(jSW["IconHash"].ToString())) { oCatItem.Add("IconHash", jSW["IconHash"].ToString()); } //Cache result var cacheEntryOptions = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(930)); //cache result for 15min _cache.Set("upd-" + sID, oCatItem, cacheEntryOptions); jResult.Add(oCatItem); bFound = true; continue; } catch { } //JArray jItems = GetSoftwares(shortname); //foreach (JObject jSW in jItems) //{ //} } else { if (shortname == null) //if shortname = ""; it's in SWLookup but without a shortname so we dont need to store it... { ThreadPool.QueueUserWorkItem(s => { //Add Item to Catalog SetShortname(productname, productversion, manufacturer, ""); //No Shortname }); } } #endregion if (!bFound) { var cacheEntryOptions2 = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(900)); //cache result for 15min _cache.Set("noupd-" + sID, "no", cacheEntryOptions2); } } catch (Exception ex) { jObj.ToString(); ex.Message.ToString(); } } return(jResult); }
public static JArray CheckForUpdates(JArray Softwares, string customerid = "") { if (Plugins._SWLookupPlugins.Count == 0) { return(new JArray()); } if (bForward == null) { try { foreach (var item in Plugins._SWLookupPlugins.OrderBy(t => t.Key)) { try { if (item.Value.Forward) { bForward = true; } } catch { } } } catch { bForward = false; } if (bForward == null) { bForward = false; } } if (bForward == true) { try { foreach (var item in Plugins._SWLookupPlugins.OrderBy(t => t.Key)) { try { return(item.Value.CheckForUpdates(Softwares, customerid)); } catch { } } } catch { } } //check if softwares do not et updates.. JArray jResult = new JArray(); JArray SWsorted = new JArray(Softwares.OrderBy(obj => (string)obj["ProductName"])); string lID = Hash.CalculateMD5HashString(SWsorted.ToString()); string sOut = ""; if (_cache.TryGetValue("noupd-" + lID, out sOut)) { return(jResult); } if (_cache.TryGetValue("upd-" + lID, out sOut)) { return(JArray.Parse(sOut)); } JArray oCat = GetCatalog("", false); foreach (JObject jObj in Softwares) { bool bFound = false; try { string manufacturer = Base.clean(jObj["Manufacturer"].ToString().ToLower()); string productname = Base.clean(jObj["ProductName"].ToString().ToLower()); string productversion = Base.clean(jObj["ProductVersion"].ToString().ToLower()); string sID = Hash.CalculateMD5HashString((manufacturer + productname + productversion).Trim()); JObject oRes = new JObject(); string sRes = ""; //Try to get value from Memory if (_cache.TryGetValue("noupd-" + sID, out sRes)) { continue; } //Try to get value from Memory if (_cache.TryGetValue("upd-" + sID, out oRes)) { jResult.Add(oRes); continue; } string shortname = GetShortname(productname, productversion, manufacturer); #region compare versions if (!string.IsNullOrEmpty(shortname)) { try { var jobj = oCat.SelectTokens("[*].ShortName").Where(t => t.ToString().ToLower() == shortname.ToLower()); if (jobj.FirstOrDefault() == null) { var cacheEntryOptions2 = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(900)); //cache result for 15min _cache.Set("noupd-" + sID, "no", cacheEntryOptions2); continue; } JObject jSW = jobj.FirstOrDefault().Parent.Parent as JObject; string sRZVersion = jSW["ProductVersion"].ToString(); try { if (!string.IsNullOrEmpty(sRZVersion)) { if (productversion == sRZVersion.ToLower()) //same version... { var cacheEntryOptions2 = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(900)); //cache result for 15min _cache.Set("noupd-" + sID, "no", cacheEntryOptions2); continue; } } } catch { } try { if (TrimVersion(Version.Parse(productversion.Replace('-', '.').Trim())) > TrimVersion(Version.Parse(sRZVersion.Replace('-', '.').Trim()))) //version is newer { Base.SetShortname(jSW["ProductName"].Value <string>(), productversion, jSW["Manufacturer"].Value <string>(), jSW["ShortName"].Value <string>()); Base.StoreFeedback(jSW["ProductName"].Value <string>(), productversion, jSW["Manufacturer"].Value <string>(), jSW["ShortName"].Value <string>(), "NEW Version ?!", "Version", true); var cacheEntryOptions2 = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(900)); //cache result for 15min _cache.Set("noupd-" + sID, "no", cacheEntryOptions2); continue; } if (TrimVersion(Version.Parse(productversion.Replace('-', '.').Trim())) == TrimVersion(Version.Parse(sRZVersion.Replace('-', '.').Trim()))) //version is same { var cacheEntryOptions2 = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(900)); //cache result for 15min _cache.Set("noupd-" + sID, "no", cacheEntryOptions2); continue; } } catch { try { if (string.Compare(productversion, sRZVersion, true) >= 1) { Base.SetShortname(jSW["ProductName"].Value <string>(), productversion, jSW["Manufacturer"].Value <string>(), jSW["ShortName"].Value <string>()); Base.StoreFeedback(jSW["ProductName"].Value <string>(), productversion, jSW["Manufacturer"].Value <string>(), jSW["ShortName"].Value <string>(), "NEW Version ?!", "String", true); var cacheEntryOptions2 = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(900)); //cache result for 15min _cache.Set("noupd-" + sID, "no", cacheEntryOptions2); continue; } } catch { } } JObject oCatItem = new JObject(); oCatItem.Add("ShortName", jSW["ShortName"]); oCatItem.Add("Description", jSW["Description"]); oCatItem.Add("Manufacturer", jSW["Manufacturer"]); oCatItem.Add("ProductName", jSW["ProductName"]); oCatItem.Add("ProductVersion", jSW["ProductVersion"]); oCatItem.Add("ProductURL", jSW["ProductURL"]); oCatItem.Add("MSIProductID", productversion); //to show the old version in RuckZuck.exe if (jSW["Downloads"] == null) { oCatItem.Add("Downloads", 0); } else { oCatItem.Add("Downloads", jSW["Downloads"]); } if (jSW["SWId"] != null) { if (!string.IsNullOrEmpty(jSW["SWId"].ToString())) { oCatItem.Add("IconId", jSW["SWId"].Value <Int32>()); //for old older Versions only... oCatItem.Add("SWId", jSW["SWId"].Value <Int32>()); } } if (!string.IsNullOrEmpty(jSW["IconHash"].ToString())) { oCatItem.Add("IconHash", jSW["IconHash"].ToString()); } //Cache result var cacheEntryOptions = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(930)); //cache result for 15min _cache.Set("upd-" + sID, oCatItem, cacheEntryOptions); jResult.Add(oCatItem); bFound = true; continue; } catch { //var cacheEntryOptions2 = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(900)); //cache result for 15min //_cache.Set("noupd-" + sID, "no", cacheEntryOptions2); } //JArray jItems = GetSoftwares(shortname); //foreach (JObject jSW in jItems) //{ //} } else { //var cacheEntryOptions2 = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(900)); //cache result for 15min //_cache.Set("noupd-" + sID, "no", cacheEntryOptions2); if (shortname == null) //if shortname = ""; it's in SWLookup but without a shortname so we dont need to store it... { ThreadPool.QueueUserWorkItem(s => { //Add Item to Catalog SetShortname(productname, productversion, manufacturer, ""); //No Shortname }); } } #endregion if (!bFound) { var cacheEntryOptions2 = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(900)); //cache result for 15min _cache.Set("noupd-" + sID, "no", cacheEntryOptions2); } } catch (Exception ex) { jObj.ToString(); Console.WriteLine(ex.Message); } } if (jResult.Count == 0) { var cacheEntryOptions2 = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(900)); //cache result for 15min _cache.Set("noupd-" + lID, "no", cacheEntryOptions2); } else { var cacheEntryOptions2 = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(120)); //cache result for 3min _cache.Set("upd-" + lID, jResult.ToString(Newtonsoft.Json.Formatting.None), cacheEntryOptions2); } return(jResult); }