public UpdateCacheItemAccessObj MapToAccessUpdateCacheItem(UpdateCacheItem cacheItem) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <UpdateCacheItem, UpdateCacheItemAccessObj>(); }); IMapper mapper = config.CreateMapper(); var source = cacheItem; var final = mapper.Map <UpdateCacheItem, UpdateCacheItemAccessObj>(source); return(final); }
public static void Add(_Update update) { var searchUpdate = _updateCache.FirstOrDefault(u => u.MD5.EqualsIgnoreCase(update.MD5)); if (searchUpdate == null) { var newCache = new UpdateCacheItem(); newCache.FileName = Path.GetFileName(update.Location); newCache.Size = update.Size; newCache.PackageName = update.PackageName; newCache.PackageVersion = update.PackageVersion; newCache.Type = update.UpdateType; if (update.MD5.EqualsIgnoreCase("N/A")) { newCache.MD5 = FileHandling.GetMD5(update.Location); } else { newCache.MD5 = update.MD5; } newCache.Architecture = update.Architecture; newCache.PackageDescription = update.Description; newCache.Language = update.Language; newCache.AppliesTo = update.AppliesTo.TryParse <decimal>(); newCache.Support = update.Support; newCache.CreatedDate = update.Date; newCache.AllowedOffline = update.AllowedOffline; lock (_updateCache) { if (update.PackageName.EqualsIgnoreCase("default") || update.PackageName.EqualsIgnoreCase("1.0") || update.PackageName.Equals("000000") || update.AppliesTo.ToString() == "1.0") { newCache.Type = UpdateType.Unknown; xError.Add(newCache.XML); } else { xUpdates.Add(newCache.XML); } _updateCache.Add(newCache); Save(); } } }
public static void Load() { if (File.Exists(CACHE_PATH_XML)) { var xDoc = new XmlDocument(); xDoc.Load(CACHE_PATH_XML); var xParent = (XmlElement)xDoc.LastChild; foreach (XmlElement E in xParent.ChildNodes) { var newCache = new UpdateCacheItem { FileName = E.Attributes["Filename"].InnerText, Size = long.Parse(E.Attributes["Size"].InnerText), PackageName = E.Attributes["Name"].InnerText, PackageVersion = E.Attributes["Version"].InnerText, Architecture = (Architecture)Enum.Parse(typeof(Architecture), E.Attributes["Arc"].InnerText), MD5 = E.Attributes["MD5"].InnerText, PackageDescription = E.Attributes["Desc"].InnerText, AppliesTo = E.Attributes["AppliesTo"].InnerText.TryParse <decimal>(), Support = E.Attributes["Support"].InnerText, CreatedDate = DateTime.Parse(E.Attributes["CreatedDate"].InnerText) }; if (E.HasAttribute("Offline")) { newCache.AllowedOffline = bool.Parse(E.Attributes["Offline"].InnerText); } if (E.HasAttribute("Type")) { newCache.Type = (UpdateType)Enum.Parse(typeof(UpdateType), E.Attributes["Type"].InnerText); } if (E.HasAttribute("Lang")) { newCache.Language = E.Attributes["Lang"].InnerText; } _updateCache.Add(newCache); } } }
public void UpdateItem(UpdateCacheItem item) { var mapped = _accessObjectMapper.MapToAccessUpdateCacheItem(item); _dbConnection.UpdateItem(mapped); }