private static void OnUpdateChildsBindingsChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs e) { if (!DesignerProperties.GetIsInDesignMode(depObj)) { if (e.NewValue != null) { void action(DependencyObject w) { int count = VisualTreeHelper.GetChildrenCount(w); DependencyObject child; for (int i = 0; i < count; i++) { child = VisualTreeHelper.GetChild(w, i); UpdateBindings(child); } } Instance.Add(depObj, action, e.NewValue.ToString().Split(',')); } else { Instance.Remove(depObj); } } }
public static ComponentInfo Init() { Id = StaticIdAllocator <ComponentData <TComponent> > .AllocateId(); OnInit += Init; OnRemove += entity => { if (EntityIndexToComponentIndex[entity.Index] != NoEntityIndex) { DoRemove(entity); } }; OnGrow += Grow; OnClear += Clear; return(new ComponentInfo { Type = typeof(TComponent), HasComponent = id => Instance.Has <TComponent>(new Entity <TScope>(id)), GetComponent = id => Instance.Get <TComponent>(new Entity <TScope>(id)), AddComponent = (id, value) => Instance.Add(new Entity <TScope>(id), (TComponent)value), RemoveComponent = id => Instance.Remove <TComponent>(new Entity <TScope>(id)), ReplaceComponent = (id, value) => Instance.Replace(new Entity <TScope>(id), (TComponent)value) }); }
/// <summary> /// Gets a cache entry lock for the object related with the specified key /// </summary> /// <param name="key">the identifier for the cache item to retrieve</param> /// <param name="refreshInterval"></param> /// <param name="slidingExpiration">the interval between the time the added object /// was last accessed and the time at wich that object expires. If /// this value is the equivalent of 1 minute, the object expires and is removed /// from the cache 1 minute after it is last accessed.</param> /// <param name="cacheLoader">a delegate that, if provided, is called to reload /// the object when it is removed from the cache</param> /// <returns>an object that can be used to synchronize access to the cached object</returns> /// <remarks> /// If the specified key is not found, a new lock entry will be created for it. /// </remarks> public static object GetLock(string key, TimeSpan refreshInterval, TimeSpan slidingExpiration, NCache.CacheLoaderDelegate cacheLoader) { // lock the CacheLockBox for read lock (_readLock) { CacheEntry entry; if (TryGetCacheEntry(key, out entry)) { entry.LastUse = DateTime.Now; } else { // lock the CacheLockBoxx for write lock (_writeLock) { // If the object does not have a entry into // the lookup table create a new one. entry = new CacheEntry(); entry.CacheLoader = cacheLoader; entry.RefreshInterval = refreshInterval; entry.SlidingExpiration = slidingExpiration; entry.LastUse = DateTime.Now; Instance.Add(key, entry); } } return(entry.Locker); } }
public void Test_TryRemove_Failure() { var testObj = new Object(); bool operationSuccess = true; if (!Instance.Contains <object>(testObj)) { operationSuccess = Instance.TryRemove(testObj); } Assert.IsFalse(operationSuccess); Instance.Add(testObj); Instance.BeforeChange += (sender, args) => args.RejectOperation(); operationSuccess = Instance.TryRemove(testObj); var result = Instance.SingleOrDefault(o => o == testObj); Assert.AreEqual(testObj, result); Assert.IsFalse(operationSuccess); }
public void Remove_Reject_Throws_Correct_Exception() { var testObj = new Object(); // Add it before try to remove it otherwise // another exception will be thrown Instance.Add(testObj); Instance.BeforeChange += (sender, args) => args.RejectOperation(); try { Instance.Remove(testObj); } catch (InvalidOperationException e) { if (e.GetType().BaseType == typeof(InvalidOperationException)) { return; } else { Assert.Fail("When an operation is rejected, the type of the exception should be a subtype of InvalidOperationException."); return; } } Assert.Fail("When an operation is rejected, the Remove method should throw an exception."); }
public void InsertOrUpdate(TModel model) { //return Task.Run(() => //{ TDbo existsDbo = null; lock (this) { var allDbo = Instance.All <TDbo>(); existsDbo = allDbo != null && allDbo.Any() ? allDbo.FirstOrDefault(EqualDboToModel(model)) : null; using (var transaction = Instance.BeginWrite()) { Instance.Add(ConvertToDBO(existsDbo, model), existsDbo != null); transaction.Commit(); } } if (existsDbo != null) { Mvx.Resolve <IMvxMessenger>().Publish(new DataBaseUpdatedMessage <TModel>(this, new List <TModel> { model })); } else { Mvx.Resolve <IMvxMessenger>().Publish(new DataBaseAddedMessage <TModel>(this, new List <TModel> { model })); } //}); }
/// <summary> /// Loads the settings from the file and overwrites them if they are already loaded. /// </summary> public static void Load() { if (!File.Exists(Instance.Path)) { return; } SettingsManager sm = null; try { sm = AutoSerializer.LoadFromXml(Instance.Path); } catch { } if (sm == null) { return; } foreach (KeyValuePair <string, Property> p in sm) { // TODO: Handle nested properties if (Instance.ContainsKey(p.Key)) { Instance[p.Key].Init(p.Value.Value); } else { Instance.Add(p.Key, p.Value); } } }
public static object GetLock(string key, TimeSpan refreshInterval, TimeSpan slidingExpiration, TCache.CacheLoaderDelegate cacheLoader) { lock (_ReadLockbox) { CacheEntry entry; if (ContainsCacheEntry(key)) { entry = Instance[key]; entry.LastUse = DateTime.Now; } else { lock (_WriteLockbox) { entry = new CacheEntry(); entry.CacheLoader = cacheLoader; entry.RefreshInterval = refreshInterval; entry.SlidingExpiration = slidingExpiration; entry.LastUse = DateTime.Now; Instance.Add(key, entry); } } return(entry.Locker); } }
private static void OnUpdateWindowChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs e) { if (!(depObj is UIElement element)) { return; } if (!DesignerProperties.GetIsInDesignMode(element)) { if (e.NewValue != null) { void action(DependencyObject w) { (w as Window).Language = XmlLanguage.GetLanguage(LocalizeDictionary.Instance.Culture.IetfLanguageTag); } Instance.Add(element, action, e.NewValue.ToString().Split(',')); action(element); } else { Instance.Remove(element); } } }
public void Add(IMembershipUser user) { lock (_lockObj) { Instance.Add(user.Instance); _castList.Add(user); } }
public MethodPropertiesJson(string initial, DateTimeOffset now, SmalltalkProperty[] properties) { var intialString = $"{initial} {now.ToString("g")}"; foreach (var property in properties) { Instance.Add(property.Name, intialString); } }
/// <summary> /// Prints an error message. /// </summary> public static void Error(object message) { string txt = GetStringFromObject(message); if (txt == null) { return; } Instance.Add(txt, ErrorColor); }
public void Test_ChangeEventArgs_Add() { var testObj = new Object(); var result = GetEventArgs(Instance, () => Instance.Add(testObj)); Assert.AreEqual(Operation.Add, result.Item1); Assert.AreEqual(Instance, result.Item2); Assert.AreEqual(Instance.Count(), result.Item3); }
static FieldTypeDictionary() { Instance.Add <Guid>(FieldType.Guid); Instance.Add <string>(FieldType.String); Instance.Add <string[]>(FieldType.StringArray); Instance.Add <BinaryField>(FieldType.BinaryField); Instance.Add <DateTimeField>(FieldType.DateTimeField); Instance.Add <StreamField>(FieldType.StreamField); Instance.Add <StringField>(FieldType.StringField); }
public void Test_Add() { var testObj = new Object(); Instance.Add(testObj); var result = Instance.Contains <object>(testObj); Assert.IsTrue(result); }
public void Test_Remove() { var testObj = new Object(); Instance.Add(testObj); Instance.Remove(testObj); var result = Instance.Contains <object>(testObj); Assert.IsFalse(result); }
public void ShouldBeAValidBinarySearchTree() { Instance.Add(20); Instance.Add(10); Instance.Add(30); Instance.Add(5); Instance.Add(40); var actual = BinarySearchTreeIsValid(((BinaryTree <int>)Instance).RootNode); actual.Should().BeTrue(); }
public void Add_ProductNameIsInvalid_ResultIsNull() { // Arrange GetMockFor <IProductValidator>() .Setup(o => o.IsValidName(AnyKindOf.String)).Returns(false); // Act var result = Instance.Add("coca-cola"); // Assert result.ShouldBeNull(); }
public void InstanceAdd_when_newInstanceFunc_is_null_throws_ArgumentNullException() { ICollection <string> testCollection = null; Assert.IsNull(testCollection); Assert.Throws <ArgumentNullException>(() => { testCollection = Instance <string> .Add(testCollection, "testItem", default(Func <ICollection <string> >)); }); }
public TestDetailsViewModel(WSManager ds) : base(ds) { if (IsInDesignMode) { SetInstance(new List <TestDetails>()); Instance.Add(new TestDetails { QuestionText = "kerdes", ChekedAnswer = "jo valasz", CorrectAnswer = "jo valasz" }); Instance.Add(new TestDetails { QuestionText = "kerdes", ChekedAnswer = "valasz", CorrectAnswer = "rossz valasz" }); } }
public void Test_TryRemove_Success() { var testObj = new Object(); Instance.Add(testObj); var operationSuccess = Instance.TryRemove(testObj); var result = Instance.SingleOrDefault(o => o == testObj); Assert.AreEqual(null, result); Assert.IsTrue(operationSuccess); }
public static void Log(string text) { if (!Application.isPlaying) { Debug.Log(text); return; } if (_lastText == text) { return; } _lastText = text; Instance.Add(text, PrintColor); }
public void Test_Contains() { var testObj = new Object(); bool result = Instance.Contains(testObj); Assert.IsFalse(result); Instance.Add(testObj); result = Instance.Contains(testObj); Assert.IsTrue(result); }
private static RecordLocks Load() { DataTable dt = new DataTable(); dt = DABase.Instance.ExecSP(cn_spList); foreach (DataRow dr in dt.Rows) { RecordLock bld; bld = new RecordLock(dr); Instance.Add(bld); } return(mInstance); }
/// <summary> /// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1" />. /// </summary> /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1" />.</param> /// <exception cref="Exception">Too many consecutive duplicates added to <see cref="SafeHashSet"/></exception> public void Add(T item) { if (Instance.Add(item) == false) { if (++AddRetryCount > MaxAddRetries) { throw new SafeHashSetException(MaxAddRetries); } } else { AddRetryCount = 0; } }
public async ValueTask InitializeComponent(ILifetimeScope scope, Type type) { if (!type.IsAssignableTo <IViewComponent>()) { throw new InvalidCastException(); } ComponentScopes.Add(type, scope); await WindowManager.BeginUIThreadScope(async() => { var instance = scope.Resolve(type) as IViewComponent; await instance.Initialize(ComponentScopes[type]); Instance.Add(type, instance); this.Add(instance); }); }
public void Test_BeforeChange_Event() { int hitCount = 0; Instance.BeforeChange += (sender, listArgs) => { hitCount++; }; object o1 = new Object(); Instance.Add(o1); Instance.Remove(o1); Assert.AreEqual(2, hitCount); }
public static void SetAuthor(short index, string name, Phone phone, string email) { Author author; if (!Instance.TryGetValue(index, out author)) { author = new Author(); Instance.Add(index, author); } if (index > Max) { Max = index; } author.Name = name; author.Phone = phone; author.Email = email; }
public static void SetPhone(short index, string tag, string home, string office, string cellphone) { Phone phone; if (!Instance.TryGetValue(index, out phone)) { phone = new Phone(); Instance.Add(index, phone); } if (index > Max) { Max = index; } phone.Tag = tag; phone.HomePhone = home; phone.OfficePhone = office; phone.CellPhone = cellphone; }
public T CreateObject <T> () where T : RealmObject, IIdentifiable, new () { // create the instance var instance = new T(); // generate a unique id string id; do { id = GenerateId(); } while (GetItem <T>(id) != null); // assign the id and return the instance instance.Id = id; Instance.Add(instance); return(instance); }