public Dictionary <int, AddOnFile[]> Get(AddOnFileKey[] addonFileKeys) { var mapping = addonFileKeys.GroupBy(k => k.AddOnID).ToDictionary(k => k.Key, k => k.Select(fk => fk.FileID)); if (mapping.Keys.All(addonID => { if (!idCache.ContainsKey(addonID)) { return(false); } return(mapping[addonID].All(fileID => idCache[addonID].ContainsKey(fileID))); })) { var ret = new Dictionary <int, AddOnFile[]> (); foreach (var addonID in mapping.Keys) { var fileIDs = mapping[addonID].ToArray(); var files = new AddOnFile[fileIDs.Length]; for (int i = 0; i < files.Length; i++) { files[i] = GetFilePath(addonID, fileIDs[i]).FromJsonFile <AddOnFile> (); if (files[i] == null) { logger.LogError("Get AddonFile cannot Find {file}", GetFilePath(addonID, fileIDs[i])); return(null); } } ret[addonID] = files.OrderBy(f => f.FileDate).ToArray(); } return(ret); } return(null); }
public AddonFileBundle(AddOnFile file, AddOn addon) { Addon = addon; foreach (PropertyInfo oPropertyInfo in file.GetType().GetProperties()) { //Check the method is not static if (!oPropertyInfo.GetGetMethod().IsStatic) { //Check this property can write if (this.GetType().GetProperty(oPropertyInfo.Name).CanWrite) { //Check the supplied property can read if (oPropertyInfo.CanRead) { //Update the properties on this object this.GetType().GetProperty(oPropertyInfo.Name).SetValue(this, oPropertyInfo.GetValue(file, null), null); } } } } }
public bool Add(int addonID, AddOnFile addonFile, bool save = true) { idCache.TryAdd(addonID, new ConcurrentDictionary <int, byte> ()); // now the key exists Task.Run(() => { var directory = GetFileDir(addonID); Directory.CreateDirectory(directory); var path = GetFilePath(addonID, addonFile.Id); File.WriteAllText(path, addonFile.ToPrettyJson()); }); // update file in cache var changed = idCache[addonID].UpdateOrAdd(addonFile.Id, (byte)1); if (changed) { Save(save); } return(changed); }