public void LazyAddTest() { var lazyList = new LazyList<string>(); lazyList.Add("item"); var initialized = lazyList.IsInitialized; Assert.True(initialized); }
public IAsyncOperation<IList<SynchronizedView>> GetViewsAsync(IList<string> viewNames) { if (viewNames.IsNullOrEmpty()) { throw new ArgumentException("viewNames"); } return AsyncInfo.Run<IList<SynchronizedView>>(async cancelToken => { LazyList<SynchronizedView> views = new LazyList<SynchronizedView>(); foreach(string viewName in viewNames) { SynchronizedView view = await this.GetViewAsync(viewName, cancelToken); if (view != null) { views.Add(view); } } return views.HasValue ? views.Value : null; }); }
public void TestRemoveobjectint() { object list = null; Assert.IsTrue(LazyList.Remove(list, 0) == null); list = LazyList.Add(list, "a"); Assert.AreEqual("a", LazyList.Remove(list, 1)); Assert.IsTrue(LazyList.Remove(list, 0) == null); list = LazyList.Add(list, "b"); list = LazyList.Remove(list, 1); list = LazyList.Add(list, "b"); list = LazyList.Add(list, "c"); list = LazyList.Add(list, "d"); list = LazyList.Add(list, "e"); list = LazyList.Remove(list, 0); list = LazyList.Remove(list, 2); list = LazyList.Remove(list, 2); Assert.AreEqual(2, LazyList.Size(list)); Assert.AreEqual("b", LazyList.Get(list, 0)); Assert.AreEqual("c", LazyList.Get(list, 1)); list = LazyList.Remove(list, 0); list = LazyList.Remove(list, 0); Assert.AreEqual(null, list); }
/// <summary> /// Add Event Listener /// (thread safe) /// </summary> /// <param name="listener"></param> public void AddEventListener(IContainerListener listener) { lock (_lock) { _listeners = LazyList.Add(_listeners, listener); } }
public void GivenLazyListWhenAddShouldNotLoad() { var lazyList = new LazyList <Stub>(_lazyLoadResolverMock.Object); lazyList.Add(new Stub()); _lazyLoadResolverMock.Verify(x => x.Resolve(It.IsAny <LazyLoadParameter>()), Times.Never()); }
public void Add(StructuredNameValue item) { if (item == null) { throw new ArgumentNullException("item"); } m_items.Add(item); }
public void Add(ExerciseSegment item) { if (item == null) { throw new ArgumentNullException("item"); } m_items.Add(item); }
public void LazyAddTest() { var lazyList = new LazyList <string>(); lazyList.Add("item"); var initialized = lazyList.IsInitialized; Assert.True(initialized); }
public void Add(VersionInformation item) { if (item == null) { throw new ArgumentNullException("item"); } m_items.Add(item); }
public void LazyAddTest() { // Arrange var lazyList = new LazyList <string>(); // Act lazyList.Add("item"); var initialized = lazyList.IsInitialized; // Assert Assert.True(initialized); }
public void LazyAddTest() { // Arrange var lazyList = new LazyList<string>(); // Act lazyList.Add("item"); var initialized = lazyList.IsInitialized; // Assert Assert.True(initialized); }
internal async Task <IList <RecordItem> > GetItemsAsyncImpl(IEnumerable <ItemKey> keys, bool includeNullItems) { var items = new LazyList <RecordItem>(); foreach (ItemKey key in keys) { key.Validate(); RecordItem item = await GetItemAsyncImpl(key); if (includeNullItems) { items.Add(item); } else if (item != null) { items.Add(item); } } return((items.Count > 0) ? items.Value : null); }
internal async Task <IList <IItemDataTyped> > GetMultipleAsyncImpl( IEnumerable <ItemKey> keys, bool includeNullItems) { var items = new LazyList <IItemDataTyped>(); foreach (ItemKey key in keys) { key.Validate(); IItemDataTyped item = await GetAsyncImpl(key); if (includeNullItems) { items.Add(item); } else if (item != null) { items.Add(item); } } return((items.Count > 0) ? items.Value : null); }
public void GivenLazyListWhenLoadAfterAddShouldBeAddedLast() { _lazyLoadResolverMock.Setup(x => x.Resolve(It.IsAny <LazyLoadParameter>())) .Returns(new[] { new Stub(), new Stub() }) .Verifiable(); var lazyList = new LazyList <Stub>(_lazyLoadResolverMock.Object); var stub = new Stub(); lazyList.Add(stub); lazyList.Should().HaveCount(3); lazyList.Should().HaveElementAt(2, stub); _lazyLoadResolverMock.VerifyAll(); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Module name</param> /// <param name="mvid">Module version ID</param> /// <param name="corLibAssemblyRef">Corlib assembly ref or <c>null</c></param> public ModuleDefUser(UTF8String name, Guid?mvid, AssemblyRef corLibAssemblyRef) { this.Kind = ModuleKind.Windows; this.Characteristics = DefaultCharacteristics; this.DllCharacteristics = DefaultDllCharacteristics; this.RuntimeVersion = MDHeaderRuntimeVersion.MS_CLR_20; this.Machine = Machine.I386; this.Cor20HeaderFlags = ComImageFlags.ILOnly; this.Cor20HeaderRuntimeVersion = 0x00020005; // .NET 2.0 or later should use 2.5 this.TablesHeaderVersion = 0x0200; // .NET 2.0 or later should use 2.0 this.corLibTypes = new CorLibTypes(this, corLibAssemblyRef); this.types = new LazyList <TypeDef>(this); this.name = name; this.mvid = mvid; types.Add(CreateModuleType()); UpdateRowId(this); }
private async Task EnsureVocabsImplAsync(IList <VocabIdentifier> vocabIDs, TimeSpan maxAge) { var staleVocabs = new LazyList <VocabIdentifier>(); for (int i = 0; i < vocabIDs.Count; ++i) { VocabIdentifier vocabID = vocabIDs[i]; if (await IsStale(vocabID, maxAge)) { staleVocabs.Add(vocabID); } } if (staleVocabs.Count > 0) { await DownloadVocabs(staleVocabs.Value); } }
// Collect queries for those views that can be synchronized. Return the list of views async Task <IList <ISynchronizedView> > CollectSynchronizableViews(IList <ISynchronizedView> views) { LazyList <ISynchronizedView> synchronizableViews = new LazyList <ISynchronizedView>(); foreach (ISynchronizedView view in views) { ItemQuery query = await this.GetSyncQuery(view); m_syncQueries.Add(query); if (query != null) { m_queriesToRun.Add(query); synchronizableViews.Add(view); } } return(synchronizableViews.HasValue ? synchronizableViews.Value : null); }
// Returns null if no matches public IAsyncOperation <IList <ItemKey> > GetKeysForItemsNeedingDownload(int startAt, int count) { return(AsyncInfo.Run <IList <ItemKey> >(async cancelToken => { IList <ItemKey> keys = this.Keys.SelectItemKeys(startAt, count); LazyList <ItemKey> candidates = new LazyList <ItemKey>(); foreach (ItemKey key in keys) { if (await this.LoadLocalItemAsync(key) == null) { candidates.Add(key); } } return candidates.HasValue ? candidates.Value : null; })); }
internal IList <ItemKey> CollectKeysNeedingDownload(IList <ItemKey> requestedKeys, IList <string> typeVersions, IList <RecordItem> collectedLocalItems) { var checkVersion = typeVersions != null; var typeVersionHash = checkVersion ? new HashSet <string>(typeVersions) : null; var pendingKeys = new LazyList <ItemKey>(); for (int i = 0, count = requestedKeys.Count; i < count; ++i) { RecordItem localItem = collectedLocalItems[i]; if (localItem == null || (checkVersion && !typeVersionHash.Contains(localItem.Type.ID))) { pendingKeys.Add(requestedKeys[i]); } } return((pendingKeys.Count > 0) ? pendingKeys.Value : null); }
internal async Task <IList <IItemDataTyped> > EnsureItemsAvailableAndGetAsync(int startAt, int count, CancellationToken cancelToken) { if (!m_data.HasKeys) { return(null); } m_data.ValidateIndex(startAt); count = m_data.Keys.GetCorrectedCount(startAt, count); var items = new LazyList <IItemDataTyped>(); for (int i = startAt, max = startAt + count; i < max; ++i) { IItemDataTyped item = await EnsureItemAvailableAndGetAsync(i).AsTask(cancelToken); items.Add(item); } return(items.HasValue ? items.Value : null); }
internal async Task <IList <IItemDataTyped> > GetItemsAsync(int startAt, int count, bool shouldAwaitRefresh, CancellationToken cancelToken) { if (!m_data.HasKeys) { return(null); } m_data.ValidateIndex(startAt); count = m_data.Keys.GetCorrectedCount(startAt, count); var items = new LazyList <IItemDataTyped>(); for (int i = startAt, max = startAt + count; i < max; ++i) { IItemDataTyped item = await GetItemAsync(i, shouldAwaitRefresh, cancelToken); items.Add(item); } return(items.HasValue ? items.Value : null); }
public void TestAddobjectintobject() { object list = null; list = LazyList.Add(list, 0, "c"); list = LazyList.Add(list, 0, "a"); list = LazyList.Add(list, 1, "b"); list = LazyList.Add(list, 3, "d"); Assert.AreEqual(4, LazyList.Size(list)); Assert.AreEqual("a", LazyList.Get(list, 0)); Assert.AreEqual("b", LazyList.Get(list, 1)); Assert.AreEqual("c", LazyList.Get(list, 2)); Assert.AreEqual("d", LazyList.Get(list, 3)); list = LazyList.Add(null, 0, null); Assert.IsTrue(list is IList); list = LazyList.Add(null, 0, new List <object>()); Assert.IsTrue(list is IList); }
public IAsyncOperation <IList <SynchronizedView> > GetViewsAsync(IList <string> viewNames) { if (viewNames.IsNullOrEmpty()) { throw new ArgumentException("viewNames"); } return(AsyncInfo.Run <IList <SynchronizedView> >(async cancelToken => { LazyList <SynchronizedView> views = new LazyList <SynchronizedView>(); foreach (string viewName in viewNames) { SynchronizedView view = await this.GetViewAsync(viewName, cancelToken); if (view != null) { views.Add(view); } } return views.HasValue ? views.Value : null; })); }
internal IList <ItemKey> CollectKeysNeedingDownload(int startAt, int count) { lock (m_keys) { this.EnsureOrdered(); count = CorrectCount(startAt, count); var keys = new LazyList <ItemKey>(); for (int i = startAt, max = i + count; i < max; ++i) { ViewKey key = m_keys[i]; if (!key.IsLoadPending && !key.Key.IsLocal) { keys.Add(key.Key); key.IsLoadPending = true; } } return(keys.HasValue ? keys.Value : null); } }
public void TestAddobjectobject() { object list = null; Assert.AreEqual(0, LazyList.Size(list)); list = LazyList.Add(list, "a"); Assert.AreEqual(1, LazyList.Size(list)); Assert.AreEqual("a", LazyList.Get(list, 0)); list = LazyList.Add(list, "b"); Assert.AreEqual(2, LazyList.Size(list)); Assert.AreEqual("a", LazyList.Get(list, 0)); Assert.AreEqual("b", LazyList.Get(list, 1)); list = null; list = LazyList.Add(list, null); Assert.AreEqual(1, LazyList.Size(list)); Assert.AreEqual(null, LazyList.Get(list, 0)); list = "a"; list = LazyList.Add(list, null); Assert.AreEqual(2, LazyList.Size(list)); Assert.AreEqual("a", LazyList.Get(list, 0)); Assert.AreEqual(null, LazyList.Get(list, 1)); list = LazyList.Add(list, null); Assert.AreEqual(3, LazyList.Size(list)); Assert.AreEqual("a", LazyList.Get(list, 0)); Assert.AreEqual(null, LazyList.Get(list, 1)); Assert.AreEqual(null, LazyList.Get(list, 2)); list = LazyList.Add(null, list); Assert.AreEqual(1, LazyList.Size(list)); object l = LazyList.Get(list, 0); Assert.IsTrue(l is IList); }
public IAsyncOperation<IList<IItemDataTyped>> EnsureItemsAvailableAndGetAsync(int startAt, int count) { if (!m_data.HasKeys) { return null; } m_data.ValidateIndex(startAt); count = m_data.Keys.GetCorrectedCount(startAt, count); return AsyncInfo.Run<IList<IItemDataTyped>>( async cancelToken => { var items = new LazyList<IItemDataTyped>(); for (int i = startAt, max = startAt + count; i < max; ++i) { IItemDataTyped item = await EnsureItemAvailableAndGetAsync(i).AsTask(cancelToken); items.Add(item); } return items.HasValue ? items.Value : null; }); }
// Collect queries for those views that can be synchronized. Return the list of views async Task<IList<ISynchronizedView>> CollectSynchronizableViews(IList<ISynchronizedView> views) { LazyList<ISynchronizedView> synchronizableViews = new LazyList<ISynchronizedView>(); foreach (ISynchronizedView view in views) { ItemQuery query = await this.GetSyncQuery(view); m_syncQueries.Add(query); if (query != null) { m_queriesToRun.Add(query); synchronizableViews.Add(view); } } return synchronizableViews.HasValue ? synchronizableViews.Value : null; }
// Update is called once per frame public void Update() { { FullShardAddress t; while (newNeighbors.TryTake(out t)) { Debug.Log(name + ": received neighbor update: " + t); OnNewNeighbor(t.ShardID, t.ObserverAddress); } } if (sdsChanged) { sdsChanged = false; { var id = privateID; if (id != publicID) { Debug.Log("ID change detected: " + id); publicID = id; name = publicID.ToString(); transform.name = publicID.ToString(); onNewID?.Invoke(id); if (cube != null) { cube.transform.position = Convert(publicID.XYZ) * Scale; } } } //Debug.Log("Sector: processing change"); updateNo++; SDS source = SDS; //Debug.Log("Sector: got "+transform.childCount+" children"); LazyList <GameObject> toDestroy = new LazyList <GameObject>(); foreach (Transform child in transform) { var obj = child.gameObject; if (obj.name == "cube") { //Debug.Log("Sector: got cube"); continue; } if (obj.hideFlags == HideFlags.HideAndDontSave) { continue; } obj.hideFlags = HideFlags.HideAndDontSave; obj.GetComponent <Renderer>().enabled = false; if (!availableEntityObjects.ContainsKey(obj.name)) { availableEntityObjects.Add(obj.name, obj); } else { toDestroy.Add(obj); } } foreach (var obj in toDestroy) { if (availableEntityObjects.ContainsValue(obj)) { Debug.LogError("Object " + obj.name + " still in use"); } else { Destroy(obj); } } //Debug.Log("Sector: recovered " + availableEntityObjects.Count + " objects"); int reused = 0; foreach (var e in source.FinalEntities) { GameObject obj; var next = Convert(e.ID.Position) * Scale; Vector3 prev = next; string key = e.ID.Guid.ToString(); if (!availableEntityObjects.ContainsKey(key)) { obj = entityPrototype != null?Instantiate(entityPrototype, transform) : new GameObject(); obj.GetComponent <Renderer>().material.color = myColor; obj.transform.parent = transform; obj.name = key; } else { obj = availableEntityObjects[key]; availableEntityObjects.Remove(key); if (obj == null) { Debug.LogError("Object " + key + " is null. Bad shit will happen"); } obj.hideFlags = HideFlags.None; obj.GetComponent <Renderer>().enabled = true; prev = obj.transform.position; reused++; } var c = obj.GetComponent <EntityComponent>(); if (c == null) { c = obj.AddComponent <EntityComponent>(); } c.SetState(next - Convert(e.Velocity) * Scale, next, secondsPerTLG); obj.transform.position = next; } //Debug.Log("Sector: got " + transform.childCount + " children, reusing "+reused); } }
/// <summary> /// Gets the list of <see cref="WebTestLocation"/> objects. /// </summary> /// <param name="locations"><see cref="TestLocations"/> value.</param> /// <returns>Returns the list of the <see cref="WebTestLocation"/> objects.</returns> public static IList <WebTestLocation> GetWebTestLocations(TestLocations locations) { if (locations == TestLocations.None) { throw new ArgumentException("Invalid test locations"); } var results = new LazyList <WebTestLocation>(); if (locations.HasFlag(TestLocations.UsIlChicago)) { results.Add(UsIlChicago); } if (locations.HasFlag(TestLocations.UsCaSanJose)) { results.Add(UsCaSanJose); } if (locations.HasFlag(TestLocations.UsTxSanAntonio)) { results.Add(UsTxSanAntonio); } if (locations.HasFlag(TestLocations.UsVaAshburn)) { results.Add(UsVaAshburn); } if (locations.HasFlag(TestLocations.UsFlMiami)) { results.Add(UsFlMiami); } if (locations.HasFlag(TestLocations.SgSingapore)) { results.Add(SgSingapore); } if (locations.HasFlag(TestLocations.SeStockholm)) { results.Add(SeStockholm); } if (locations.HasFlag(TestLocations.RuMoscow)) { results.Add(RuMoscow); } if (locations.HasFlag(TestLocations.NlAmsterdam)) { results.Add(NlAmsterdam); } if (locations.HasFlag(TestLocations.JpKawaguchi)) { results.Add(JpKawaguchi); } if (locations.HasFlag(TestLocations.IeDublin)) { results.Add(IeDublin); } if (locations.HasFlag(TestLocations.HkHongKong)) { results.Add(HkHongKong); } if (locations.HasFlag(TestLocations.FrParis)) { results.Add(FrParis); } if (locations.HasFlag(TestLocations.ChZurich)) { results.Add(ChZurich); } if (locations.HasFlag(TestLocations.BrSaoPaulo)) { results.Add(BrSaoPaulo); } if (locations.HasFlag(TestLocations.AuSydney)) { results.Add(AuSydney); } return(results); }
private async Task EnsureVocabsImplAsync(IList<VocabIdentifier> vocabIDs, TimeSpan maxAge) { var staleVocabs = new LazyList<VocabIdentifier>(); for (int i = 0; i < vocabIDs.Count; ++i) { VocabIdentifier vocabID = vocabIDs[i]; if (await IsStale(vocabID, maxAge)) { staleVocabs.Add(vocabID); } } if (staleVocabs.Count > 0) { await DownloadVocabs(staleVocabs.Value); } }
internal async Task<IList<IItemDataTyped>> EnsureItemsAvailableAndGetAsync(int startAt, int count, CancellationToken cancelToken) { if (!m_data.HasKeys) { return null; } m_data.ValidateIndex(startAt); count = m_data.Keys.GetCorrectedCount(startAt, count); var items = new LazyList<IItemDataTyped>(); for (int i = startAt, max = startAt + count; i < max; ++i) { IItemDataTyped item = await EnsureItemAvailableAndGetAsync(i).AsTask(cancelToken); items.Add(item); } return items.HasValue ? items.Value : null; }
internal async Task<IList<RecordItem>> GetItemsAsyncImpl(IEnumerable<ItemKey> keys, bool includeNullItems) { var items = new LazyList<RecordItem>(); foreach (ItemKey key in keys) { key.Validate(); RecordItem item = await GetItemAsyncImpl(key); if (includeNullItems) { items.Add(item); } else if (item != null) { items.Add(item); } } return (items.Count > 0) ? items.Value : null; }
internal IList<ItemKey> CollectKeysNeedingDownload( IList<ItemKey> requestedKeys, IList<string> typeVersions, IList<RecordItem> collectedLocalItems) { var checkVersion = typeVersions != null; var typeVersionHash = checkVersion ? new HashSet<string>(typeVersions) : null; var pendingKeys = new LazyList<ItemKey>(); for (int i = 0, count = requestedKeys.Count; i < count; ++i) { var localItem = collectedLocalItems[i]; if (localItem == null || (checkVersion && !typeVersionHash.Contains(localItem.Type.ID))) { pendingKeys.Add(requestedKeys[i]); } } return (pendingKeys.Count > 0) ? pendingKeys.Value : null; }
// Returns null if no matches public IAsyncOperation<IList<ItemKey>> GetKeysForItemsNeedingDownload(int startAt, int count) { return AsyncInfo.Run<IList<ItemKey>>(async cancelToken => { IList<ItemKey> keys = this.Keys.SelectItemKeys(startAt, count); LazyList<ItemKey> candidates = new LazyList<ItemKey>(); foreach(ItemKey key in keys) { if (await this.LoadLocalItemAsync(key) == null) { candidates.Add(key); } } return candidates.HasValue ? candidates.Value : null; }); }
private IList<ItemKey> CollectKeysNeedingDownload(int startAt, int keyCount) { IList<ViewKey> viewKeys = m_data.Keys.SelectKeysNotAlreadyLoading(startAt, keyCount); if (viewKeys.IsNullOrEmpty()) { return null; } var keys = new LazyList<ItemKey>(); for (int i = 0, count = viewKeys.Count; i < count; ++i) { ViewKey viewKey = viewKeys[i]; viewKey.IsLoadPending = true; keys.Add(viewKey.Key); } return keys.HasValue ? keys.Value : null; }
internal async Task<IList<IItemDataTyped>> GetItemsAsync(int startAt, int count, bool shouldAwaitRefresh, CancellationToken cancelToken) { if (!m_data.HasKeys) { return null; } m_data.ValidateIndex(startAt); count = m_data.Keys.GetCorrectedCount(startAt, count); var items = new LazyList<IItemDataTyped>(); for (int i = startAt, max = startAt + count; i < max; ++i) { IItemDataTyped item = await GetItemAsync(i, shouldAwaitRefresh, cancelToken); items.Add(item); } return items.HasValue ? items.Value : null; }
public void Add(string item) { ValidateItem(item); m_items.Add(item); }
public void Add(ItemFilter item) { ValidateItem(item); m_items.Add(item); }
public void Add(Blob item) { ValidateItem(item); m_items.Add(item); }
public void Add(CodedValue item) { ValidateItem(item); m_items.Add(item); }
internal async Task<IList<IItemDataTyped>> GetMultipleAsyncImpl( IEnumerable<ItemKey> keys, bool includeNullItems) { var items = new LazyList<IItemDataTyped>(); foreach (ItemKey key in keys) { key.Validate(); IItemDataTyped item = await GetAsyncImpl(key); if (includeNullItems) { items.Add(item); } else if (item != null) { items.Add(item); } } return (items.Count > 0) ? items.Value : null; }
/// <summary> /// Adds a new local and then returns it /// </summary> /// <param name="local">The local that should be added to the list</param> /// <returns>The input is always returned</returns> public Local Add(Local local) { locals.Add(local); return(local); }
public void Add(object item) { ValidateItem(item); m_items.Add(item); }