public void TestCreate() { ElementFactory ef = new ElementFactory(); ef.AddType(new global::Jabber.protocol.iq.Factory()); string g = new Guid().ToString(); FileMap <DiscoInfo> fm = new FileMap <DiscoInfo>("test.xml", ef); fm.Clear(); Assert.AreEqual(0, fm.Count); fm[g] = Element; Assert.IsTrue(fm.Contains(g)); Assert.IsFalse(fm.Contains("foo")); Assert.IsInstanceOf <DiscoInfo>(fm[g]); Assert.AreEqual(1, fm.Count); // re-read, to reparse fm = new FileMap <DiscoInfo>("test.xml", ef); Assert.IsTrue(fm.Contains(g)); Assert.IsInstanceOf <DiscoInfo>(fm[g]); fm[g] = null; Assert.AreEqual(1, fm.Count); fm.Remove(g); Assert.AreEqual(0, fm.Count); }
public void TestCreate() { ElementFactory ef = new ElementFactory(); ef.AddType(new global::jabber.protocol.iq.Factory()); string g = new Guid().ToString(); FileMap<DiscoInfo> fm = new FileMap<DiscoInfo>("test.xml", ef); fm.Clear(); Assert.AreEqual(0, fm.Count); fm[g] = Element; Assert.IsTrue(fm.Contains(g)); Assert.IsFalse(fm.Contains("foo")); Assert.IsInstanceOfType(typeof(DiscoInfo), fm[g]); Assert.AreEqual(1, fm.Count); // re-read, to reparse fm = new FileMap<DiscoInfo>("test.xml", ef); Assert.IsTrue(fm.Contains(g)); Assert.IsInstanceOfType(typeof(DiscoInfo), fm[g]); fm[g] = null; Assert.AreEqual(1, fm.Count); fm.Remove(g); Assert.AreEqual(0, fm.Count); }
// // Outer funcs // /// <summary> /// This functions asks the AAS REST repository on given location, which AasIds would be availble. /// Using the AasIds, details are retrieved for each inidivudal AAS and synchronized with the /// repository. /// Note: for the time being, the list of file items is recreated, but not synchronized /// Note: due to the nature of long-lasting actions, this is by design async! /// </summary> /// <returns>If a successfull retrieval could be made</returns> public async Task <bool> SyncronizeFromServerAsync() { // access if (true != _connector?.IsValid()) { return(false); } // try get a list of items from the connector var items = await _connector.GenerateRepositoryFromEndpointAsync(); // just re-set FileMap.Clear(); foreach (var fi in items) { if (fi != null) { FileMap.Add(fi); fi.ContainerList = this; } } // ok return(true); }
/// <summary> /// GC safe dispose wrapper /// </summary> /// <param name="disposing">truth check</param> protected virtual void Dispose(bool disposing) { if (Disposed) { return; } Hasher?.Dispose(); Prefetch.Dispose(); foreach (var(_, cache) in CacheFiles) { cache?.Dispose(); } if (disposing) { CacheFiles.Clear(); CacheFiles = default; FileMap.Clear(); FileMap = default; Prefetch = default; } Disposed = true; }
IDictionary <UInt32, UInt32> CorrectOffsets() { var changes = new SortedDictionary <UInt32, UInt32>(); var list = FileMap.ToList(); var firstinstructioindex = list.FindIndex(x => x.Value is Bytecode.Instruction); var itemoffset = list[firstinstructioindex].Key; for (var i = firstinstructioindex; i >= 0 && i < list.Count; ++i) { var item = list[i]; if (itemoffset != item.Key) { var diff = itemoffset - item.Key; list[i] = new KeyValuePair <UInt32, Object>(itemoffset, item.Value); changes[item.Key] = itemoffset; } var size = (UInt32)GetObjectSize(item.Value); itemoffset += size; } FileMap.Clear(); foreach (var item in list) { FileMap.Add(item.Key, item.Value); } return(changes); }
public virtual void Clear() { if (Directory.Exists(CachePath)) { try { Directory.Delete(CachePath, true); } catch (IOException) { } } FileMap.Clear(); }
private void LoadCore(IEnumerable <FileModel> models) { EventHandler fileOrBaseDirChangedHandler = HandleFileOrBaseDirChanged; EventHandler <PropertyChangedEventArgs <ImmutableArray <UidDefinition> > > uidsChangedHandler = HandleUidsChanged; EventHandler contentAccessedHandler = null; if (!Environment.Is64BitProcess) { contentAccessedHandler = ContentAccessedHandler; } if (Models != null) { foreach (var m in Models) { m.FileOrBaseDirChanged -= fileOrBaseDirChangedHandler; m.UidsChanged -= uidsChangedHandler; m.ContentAccessed -= contentAccessedHandler; } } Models = models.ToImmutableList(); _uidIndex.Clear(); FileMap.Clear(); foreach (var m in Models) { m.FileOrBaseDirChanged += fileOrBaseDirChangedHandler; m.UidsChanged += uidsChangedHandler; m.ContentAccessed += contentAccessedHandler; foreach (var uid in m.Uids) { List <FileModel> list; if (!_uidIndex.TryGetValue(uid.Name, out list)) { list = new List <FileModel>(); _uidIndex.Add(uid.Name, list); } list.Add(m); } if (m.Type != DocumentType.Overwrite) { FileMap[m.FileAndType] = m.FileAndType; } } }
// Interface public override void Clear() { base.Clear(); Name = Default.Name; Group.Clear(); Router.Clear(); DownloadFolder = FileUtil.GetDownloadFolder(); lock (SharedFolders) SharedFolders.Clear(); lock (FileMap) FileMap.Clear(); lock (FolderMap) FolderMap.Clear(); }