public bool TryGetFile(string fileName, string indexString, SymStoreResult result, out Stream fileData) { // try and get the file from this store if (TryGetFileLocal(fileName, indexString, result, out fileData)) { return(true); } // if there is backing store try getting it from there and cache it in this store if (BackingStore != null) { Stream backingFileData; if (BackingStore.TryGetFile(fileName, indexString, result, out backingFileData)) { WriteFile(fileName, indexString, backingFileData); if (backingFileData != null) { backingFileData.Dispose(); } if (TryGetFileLocal(fileName, indexString, result, out fileData)) { return(true); } } } // if nothing has worked yet, fail return(false); }
public Word this[int index] { get { if (index >= Size || index < 0) { throw new MemoryAccessViolationException(); } if (BackingStore.ContainsKey(index)) { return(BackingStore[index]); } else { return(default(Word)); } } set { if (index >= Size || index < 0) { throw new MemoryAccessViolationException(); } if (BackingStore.ContainsKey(index)) { BackingStore[index] = value; } else { BackingStore.Add(index, value); } } }
public void CallBackingStoreSave() { var result = Feature.Save(); Assert.AreEqual(Feature, result); BackingStore.Verify(x => x.Save(Feature), Times.Once()); }
/// <summary> /// Adds the specified type. /// </summary> /// <param name="type">The type.</param> /// <param name="message">The message.</param> public void Add(string type, string message) { if (string.IsNullOrWhiteSpace(message)) { return; } IList <KeyValuePair <string, string> > messages; object temp; if (!BackingStore.TryGetValue(Key, out temp)) { messages = new List <KeyValuePair <string, string> >(); BackingStore.Add(Key, messages); } else { messages = (IList <KeyValuePair <string, string> >)temp; } var item = messages.FirstOrDefault(p => p.Key.Equals(type, StringComparison.OrdinalIgnoreCase)); if (!string.IsNullOrWhiteSpace(item.Value)) { messages.Remove(item); } messages.Add(new KeyValuePair <string, string>(type, message)); BackingStore.Keep(Key); }
public void SetGlobalPercentageTo100() { var result = Feature.Enable(); Assert.IsNotNull(result); Assert.AreEqual(100, result.GlobalPercentage); BackingStore.Verify(x => x.Save(Feature), Times.Once()); }
public void AddCredential(string resource, string userName, string password) { Dictionary <string, string> props = new Dictionary <string, string>(); props[PasswordKey] = password; Account account = new Account(userName, props); BackingStore.Save(account, resource); }
public void RemoveCredential(string resource, string userName) { var account = BackingStore.FindAccountsForService(resource).Where(a => a.Username == userName).First(); if (account != null) { BackingStore.Delete(account, resource); } }
static void TakeMemoryCriticalAction(object sender, object e) { var ejectionCount = BackingStore.Count / 2; for (var removalIndex = 0; removalIndex < ejectionCount; ejectionCount++) { BlockToWrite(); BackingStore.Remove(BackingStore.Last().Key); } }
public void CanSaveAndGetChildrenWithFixtures() { const string childName = "Lawrence McGee"; const string anotherName = "Richard Henderson"; var myChild = new Child { Name = childName }; var initialFixtureList = new List <Fixture> { new Fixture { Sport = "Rugby Union", Team = "U8", School = "Tockington", Kickoff = new DateTime(2016, 1, 1, 12, 00, 00), Players = { childName } } }; var myChildWithInitialFixture = myChild.UpdateFixtureList(initialFixtureList); var updatedFixtureList = new List <Fixture> { new Fixture { Sport = "Rugby Union", Team = "U8", School = "Tockington", Kickoff = new DateTime(2016, 1, 1, 12, 00, 00), Players = { anotherName } } }; var myChildWithUpdatedFixture = myChildWithInitialFixture.UpdateFixtureList(updatedFixtureList); const string backingStore = "test"; var persister = new BackingStore(backingStore); persister.SaveAll(new List <Child> { myChildWithUpdatedFixture }); var childList = persister.GetAll().ToList(); Assert.That(childList.Count, Is.EqualTo(1)); var myRestoredChild = childList[0]; Assert.That(myRestoredChild.ParentShouldBeInformed(), Is.True); Assert.That( myRestoredChild.GetMessageForParent() .Contains("Now NOT playing in U8 Rugby Union at Tockington on 01 January 2016 12:00")); }
public void SetGlobalPercentageToZero() { BuildFeatureWithPercentage(100); Assert.AreEqual(100, Feature.GlobalPercentage); var result = Feature.Disable(); Assert.IsNotNull(result); Assert.AreEqual(0, result.GlobalPercentage); BackingStore.Verify(x => x.Save(Feature), Times.Once()); }
public void CanSaveAndGetChildrenWithFixtures() { const string childName = "Lawrence McGee"; const string anotherName = "Richard Henderson"; var myChild = new Child { Name = childName }; var initialFixtureList = new List<Fixture> { new Fixture { Sport = "Rugby Union", Team = "U8", School = "Tockington", Kickoff = new DateTime(2016, 1, 1, 12, 00, 00), Players = {childName} } }; var myChildWithInitialFixture = myChild.UpdateFixtureList(initialFixtureList); var updatedFixtureList = new List<Fixture> { new Fixture { Sport = "Rugby Union", Team = "U8", School = "Tockington", Kickoff = new DateTime(2016, 1, 1, 12, 00, 00), Players = {anotherName} } }; var myChildWithUpdatedFixture = myChildWithInitialFixture.UpdateFixtureList(updatedFixtureList); const string backingStore = "test"; var persister = new BackingStore(backingStore); persister.SaveAll(new List<Child> {myChildWithUpdatedFixture}); var childList = persister.GetAll().ToList(); Assert.That(childList.Count, Is.EqualTo(1)); var myRestoredChild = childList[0]; Assert.That(myRestoredChild.ParentShouldBeInformed(), Is.True); Assert.That( myRestoredChild.GetMessageForParent() .Contains("Now NOT playing in U8 Rugby Union at Tockington on 01 January 2016 12:00")); }
private void ResetThreadBackingStoreImpl() { if (HttpContext.Current != null) { var keys = BackingStoreKeysList.Union(BackingStoreKeys); foreach (var key in keys) { BackingStore.Remove(key); } } _threadBackingStore = null; }
public void SetGlobalPercentageAndSave() { const int percentage = 57; Assert.AreEqual(0, Feature.GlobalPercentage); var result = Feature.EnablePercentage(percentage); Assert.IsNotNull(result); Assert.AreEqual(percentage, result.GlobalPercentage); BackingStore.Verify(x => x.Save(Feature), Times.Once()); }
public void NoChildrenForcesCreationOfInitialChildren() { const string backingStore = "test"; var persister = new BackingStore(backingStore); persister.RemoveBackingStore(); persister.GetInitialChildren = GetInitialChildren; var childList = persister.GetAll().ToList(); Assert.That(childList.Count, Is.EqualTo(1)); Assert.That(childList[0].Name, Is.EqualTo("Julian McGee")); }
public T Pop() { if (Count <= 0) { throw new InvalidOperationException(); } var itemToReturn = BackingStore[0]; --Count; BackingStore[0] = BackingStore[Count]; BackingStore.RemoveAt(Count); //Same as setting BackingStore[Count] == default(T); SwimDown(0); return(itemToReturn); }
public void Dispose() { if (BackingStore.Contains(this)) { object value = BackingStore[this]; var disposable = value as IDisposable; if (disposable != null) { disposable.Dispose(); } BackingStore.Remove(this); } }
public static void EndContextForTest() { if (!BackingStore.Contains(DatabaseContextKey)) { return; } var databaseEntities = BackingStore[DatabaseContextKey] as DatabaseEntities; if (databaseEntities != null) { databaseEntities.Dispose(); BackingStore[DatabaseContextKey] = null; } BackingStore.Remove(DatabaseContextKey); if (!BackingStore.Contains(TenantKey)) { return; } var tenant = BackingStore[TenantKey] as Tenant; if (tenant != null) { BackingStore[TenantKey] = null; } BackingStore.Remove(TenantKey); if (!BackingStore.Contains(PersonKey)) { return; } var person = BackingStore[PersonKey] as Person; if (person != null) { BackingStore[PersonKey] = null; } BackingStore.Remove(PersonKey); }
/// <summary>TOTO</summary> public override void ForEachSerial(Action <T> action) { BackingStore.ForEach(row => row.ForEach(lh => lh.ForEach(action))); }
public IEnumerable <T> Retrieve(Specification <T> specification) { // TODO: reconsider backing store -- this type casting is a slow operation return(BackingStore.Select(x => Convert.ChangeType(x.Value, x.Type)).OfType <T>().Where(specification)); }
public string RetrievePassword(string resource, string userName) { return(BackingStore.FindAccountsForService(resource).Where(a => a.Username == userName).First()?.Properties[PasswordKey]); }
public bool Contains(string resource, string userName) { return(BackingStore.FindAccountsForService(resource).Where(a => a.Username == userName).Count() > 0); }
/// <summary>TOTO</summary> public override void ForEachSerial(FastIteratorFunctor <T> functor) { BackingStore.ForEach(row => row.ForEach(lh => lh.ForEach(functor))); }
/// <summary> /// GetEnumerator /// </summary> /// <returns></returns> public IEnumerator <KeyValuePair <string, List <MarketData> > > GetEnumerator() { return(BackingStore.GetEnumerator()); }
public void Store(T item) { BackingStore.Add(item.Id, JsonConvert.SerializeObject(item)); }
/// <inheritdoc/>> public override void ForEach(FastIteratorFunctor <T> functor) { BackingStore.AsParallel().WithMergeOptions(ParallelMergeOptions.FullyBuffered) .ForAll(row => row.ForEach(lh => lh.ForEach(functor))); }
/// <inheritdoc/>> public override void ForEach(Action <T> action) { BackingStore.AsParallel().WithMergeOptions(ParallelMergeOptions.FullyBuffered) .ForAll(row => row.ForEach(lh => lh.ForEach(action))); }
static async void BlockToWrite() { await WriteAsync(BackingStore.Last().Key, BackingStore.Last().Value); }
private ITextStorageFactory GetBackingStore(BackingStore effectiveBackingStore) { ITextStorageFactory factory; switch (effectiveBackingStore) { default: Debug.Assert(false); throw new ArgumentException(); case BackingStore.String: effectiveBackingStore = BackingStore.String; factory = this.stringStorageFactory; break; case BackingStore.Utf8SplayGapBuffer: effectiveBackingStore = BackingStore.Utf8SplayGapBuffer; factory = this.utf8SplayGapBufferFactory; break; } return factory; }
/// <summary> /// For any <see cref="IDisposable"/> items in the store, call <see cref="IDisposable.Dispose"/> and clear out the reference to the item from the <see cref="BackingStore"/>. /// Call from <see cref="SitkaGlobalBase.ApplicationEndRequest" /> to free resources, particularly EntityFramework contexts otherwise may use up sql connection pool. /// </summary> public static void DisposeItemsAndClearStore() { BackingStore.Values.OfType <IDisposable>().ToList().ForEach(item => item.Dispose()); BackingStore.Clear(); }
public void Empty() { BackingStore.Clear(); }
public void Add(T item) { BackingStore.Add(item); SwimUp(Count); ++Count; }
public void LoadFile(string path) { string qualifier = null; string qualifier2 = null; int colon = path.IndexOf(':', Path.IsPathRooted(path) ? 2 : 0); if (colon >= 0) { qualifier = path.Substring(colon + 1); path = path.Substring(0, colon); } if (qualifier != null) { colon = qualifier.IndexOf(':'); if (colon >= 0) { qualifier2 = qualifier.Substring(colon + 1); qualifier = qualifier.Substring(0, colon); } } ITextStorageFactory factory = null; if (!String.IsNullOrEmpty(qualifier2)) { try { effectiveBackingStore = (BackingStore)Enum.Parse(typeof(BackingStore), qualifier2); } catch (ArgumentException) { throw new Exception(String.Format("Buffer qualifier '{0}' is not recognized - should be one of '{1}' or '{2}'", qualifier, BackingStore.String, BackingStore.Utf8SplayGapBuffer)); } factory = GetBackingStore(effectiveBackingStore); } else if (this.textEditControl.TextStorageFactory == null) { factory = GetBackingStore(MainClass.Config.BackingStore); } if (factory != null) { this.textEditControl.Reload(factory, factory.New()); } if (String.IsNullOrEmpty(qualifier)) { EncodingInfo encodingInfo = GuessEncoding(path); Type[] permittedEncodings = null; if (this.textEditControl.TextStorageFactory != null) { permittedEncodings = this.textEditControl.TextStorageFactory.PermittedEncodings; } if (permittedEncodings != null) { if (Array.FindIndex(permittedEncodings, delegate (Type candidate) { return candidate.IsInstanceOfType(encodingInfo.Encoding); }) < 0) { MessageBox.Show("Specified encoding is not permitted by specified backing store. Falling back to 'String' backing store.", "Text Editor", MessageBoxButtons.OK, MessageBoxIcon.Information); TextEditorWindow replacementWindow = new TextEditorWindow(false/*createBackingStore*/); ITextStorageFactory stringStorageFactory = replacementWindow.GetBackingStore(BackingStore.String); replacementWindow.textEditControl.Reload(stringStorageFactory, stringStorageFactory.New()); replacementWindow.LoadFile(path, encodingInfo); replacementWindow.Show(); throw new ApplicationException(); // cancel the old window } } LoadFile(path, encodingInfo); } else { switch (qualifier.ToLower()) { default: throw new Exception(String.Format("Encoding qualifier '{0}' is not recognized - should be one of 'ansi', 'utf8', 'utf16', or 'utf16be'", qualifier)); case "ansi": LoadFile(path, new EncodingInfo(Encoding_ANSI, 0)); break; case "utf8": LoadFile(path, new EncodingInfo(Encoding_UTF8, 0)); break; case "utf16": LoadFile(path, new EncodingInfo(Encoding_UTF16, 0)); break; case "utf16be": LoadFile(path, new EncodingInfo(Encoding_UTF16BigEndian, 0)); break; } } }
/// <summary> /// GetEnumerator /// </summary> /// <returns></returns> System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return(BackingStore.GetEnumerator()); }