private HashStorage CreateNew([NotNull] RulesEntry[] rulesSet, string[] carIds) { var hashStorage = new HashStorage(_rulesKeys); foreach (var car in carIds) { var carLocation = FileUtils.GetCarDirectory(_acRoot, car); if (!Directory.Exists(carLocation)) { continue; } var carData = DataWrapper.FromCarDirectory(carLocation); var bytes = new byte[rulesSet.Length][]; for (var i = 0; i < rulesSet.Length; i++) { var set = rulesSet[i]; bytes[i] = set.Rules.GetHash(carData); } hashStorage.Add(car, bytes); } hashStorage.ParamsHashCode = _paramsHashCode; hashStorage.SaveTo(_storageLocation); return(hashStorage); }
public async Task EnsureActualAsync() { if (_hashStorage == null || _paramsHashCode != _hashStorage.ParamsHashCode) { _hashStorage = await Task.Run(() => CreateNew(_rules, _donorIds)); } }
public void EnsureActual() { if (_hashStorage == null || _paramsHashCode != _hashStorage.ParamsHashCode) { var w = Stopwatch.StartNew(); _hashStorage = CreateNew(_rules, _donorIds); AcToolsLogging.Write($"Update storage: {w.Elapsed.TotalMilliseconds:F2} ms"); } }
public RulesWrapper(string acRoot, string rules, string storageLocation, string[] donorIds) { _acRoot = acRoot; _rules = TagFile.FromData(rules).Select(RulesEntry.Create).ToArray(); _rulesKeys = _rules.Select(x => x.Id).ToArray(); _storageLocation = storageLocation; _donorIds = donorIds; _paramsHashCode = acRoot.GetHashCode() ^ _rules.GetEnumerableHashCode() ^ donorIds.GetEnumerableHashCode(); try { _hashStorage = File.Exists(storageLocation) ? HashStorage.FromFile(_rulesKeys, storageLocation) : new HashStorage(_rulesKeys); } catch (HashStorageObsoleteException) { _hashStorage = null; } catch (Exception e) { AcToolsLogging.Write(e); _hashStorage = null; } }