public T Find_By_Uuid <T>(string uuid) where T : XenObject <T> { Type t = typeof(T); PropertyInfo p = t.GetProperty("uuid", BindingFlags.Public | BindingFlags.Instance); if (p == null) { return(null); } ChangeableDictionary <XenRef <T>, T> d = GetCollectionForType(t) as ChangeableDictionary <XenRef <T>, T>; if (d == null) { return(null); } lock (d) { foreach (T m in d.Values) { if (string.Equals((string)p.GetValue(m, null), uuid, StringComparison.OrdinalIgnoreCase)) { return(m); } } } return(null); }
public void DeregisterCollectionChanged <T>(CollectionChangeEventHandler h) where T : XenObject <T> { ChangeableDictionary <XenRef <T>, T> d = GetCollectionForType(typeof(T)) as ChangeableDictionary <XenRef <T>, T>; d.CollectionChanged -= h; }
/// <summary> /// Find a XenRef corresponding to the given XenObject, using its UUID. /// Returns null if no such object is found. /// </summary> public XenRef <T> FindRef <T>(T needle) where T : XenObject <T> { Type t = typeof(T); PropertyInfo p = t.GetProperty("uuid", BindingFlags.Public | BindingFlags.Instance); if (p == null) { return(null); } string uuid = (string)p.GetValue(needle, null); ChangeableDictionary <XenRef <T>, T> d = (ChangeableDictionary <XenRef <T>, T>)GetCollectionForType(t); lock (d) { foreach (KeyValuePair <XenRef <T>, T> kvp in d) { if (((string)p.GetValue(kvp.Value, null)) == uuid) { return(kvp.Key); } } } return(null); }
/// <summary> /// Find a XenRef corresponding to the given XenObject, using its UUID. /// Returns null if no such object is found. /// </summary> public XenRef <T> FindRef <T>(T needle) where T : XenObject <T> { Type t = typeof(T); PropertyInfo p = t.GetProperty("uuid", BindingFlags.Public | BindingFlags.Instance); if (p == null) { return(null); } string uuid = (string)p.GetValue(needle, null); ChangeableDictionary <XenRef <T>, T> d = GetCollectionForType(t) as ChangeableDictionary <XenRef <T>, T>; if (d == null) { return(null); } lock (d) { foreach (KeyValuePair <XenRef <T>, T> kvp in d) { if (string.Equals((string)p.GetValue(kvp.Value, null), uuid, StringComparison.OrdinalIgnoreCase)) { return(kvp.Key); } } } return(null); }
public void Remove() { ChangeableDictionary <int> d = Setup(); d.RemoveAndShift(5); Assert.AreEqual(20, d[2]); Assert.AreEqual(40, d[4]); Assert.AreEqual(60, d[5]); Assert.AreEqual(70, d[6]); }
public void DeregisterBatchCollectionChanged <T>(EventHandler h) where T : XenObject <T> { ChangeableDictionary <XenRef <T>, T> d = GetCollectionForType(typeof(T)) as ChangeableDictionary <XenRef <T>, T>; if (d == null) { return; } d.BatchCollectionChanged -= h; }
public void Insert() { ChangeableDictionary <int> d = Setup(); d.InsertAndShift(5, 1); d.Add(5, 500); Assert.AreEqual(500, d[5]); Assert.AreEqual(50, d[6]); Assert.AreEqual(80, d[9]); Assert.AreEqual(90, d[10]); }
internal void ReindexWorksheetDictionary() { var index = 0; var worksheets = new ChangeableDictionary <ExcelWorksheet>(); foreach (var entry in _worksheets) { entry.PositionId = index + _pck._worksheetAdd; worksheets.Add(index++, entry); } _worksheets = worksheets; }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="xenRef">May be null, in which case null is returned. May not be a null ref.</param> /// <returns></returns> public T Resolve <T>(XenRef <T> xenRef) where T : XenObject <T> { if (xenRef == null) { return(null); } ChangeableDictionary <XenRef <T>, T> d = (ChangeableDictionary <XenRef <T>, T>)GetCollectionForType(typeof(T)); T result; return(d.TryGetValue(xenRef, out result) ? result : null); }
/// <summary> /// Dispose the worksheets collection /// </summary> public void Dispose() { if (_worksheets != null) { foreach (var sheet in this._worksheets) { ((IDisposable)sheet).Dispose(); } _worksheets = null; _pck = null; } }
private void Clear_ <T>(ChangeableDictionary <XenRef <T>, T> o) where T : XenObject <T> { // explicitly remove each element so change events are fired XenRef <T>[] keys = new XenRef <T> [o.Keys.Count]; o.Keys.CopyTo(keys, 0); foreach (XenRef <T> key in keys) { lock (o) { o.Remove(key); } } }
private static T[] contents <T>(ChangeableDictionary <XenRef <T>, T> d) where T : XenObject <T> { lock (d) { T[] result = new T[d.Values.Count]; int i = 0; foreach (T o in d.Values) { result[i] = o; i++; } return(result); } }
private static ChangeableDictionary <int> Setup() { var d = new ChangeableDictionary <int>(); d.Add(2, 20); d.Add(8, 80); d.Add(5, 50); d.Add(0, 0); d.Add(3, 30); d.Add(6, 60); d.Add(4, 40); d.Add(7, 70); d.Add(9, 90); return(d); }
public void Add() { ChangeableDictionary <int> d = Setup(); //Validate order var prev = -1; foreach (var item in d) { Assert.IsTrue(prev < item); } //Validate values Assert.AreEqual(20, d[2]); Assert.AreEqual(60, d[6]); Assert.AreEqual(90, d[9]); }
void HostBatchCollectionChanged(object sender, EventArgs e) { ChangeableDictionary <XenRef <Host>, Host> d = sender as ChangeableDictionary <XenRef <Host>, Host>; if (d == null) { return; } foreach (var host in d.Values) { var row = storedRows.FirstOrDefault(r => GetXenObject(r) == host); if (row != null) { RedrawRow(row); } } }
private void UpdateFrom_ <T>(Network.IXenConnection connection, ChangeableDictionary <XenRef <T>, T> target, ObjectChange source) where T : XenObject <T>, new() { XenRef <T> xenref = source.xenref as XenRef <T>; if (xenref == null) { xenref = new XenRef <T>((string)source.xenref); } if (source.value != null) { T to_update = null; lock (target) { if (!target.TryGetValue(xenref, out to_update)) { // add T obj = new T(); obj.Connection = connection; obj.UpdateFrom((T)source.value); obj.opaque_ref = xenref.opaque_ref; target.Add(xenref, obj); } } // Update the object that we found above. Note that this needs to be done out of the // scope of the lock(target), as UpdateFrom is going to fire events. if (to_update != null) { to_update.UpdateFrom((T)source.value); } } else { // delete the source object from our model lock (target) { target.Remove(xenref); } } }
internal ExcelWorksheets(ExcelPackage pck, XmlNamespaceManager nsm, XmlNode topNode) : base(nsm, topNode) { _pck = pck; _namespaceManager = nsm; int ix = 0; _worksheets = new ChangeableDictionary <ExcelWorksheet>(); foreach (XmlNode sheetNode in topNode.ChildNodes) { if (sheetNode.NodeType == XmlNodeType.Element) { string name = sheetNode.Attributes["name"].Value; //Get the relationship id string relId = sheetNode.Attributes.GetNamedItem("id", ExcelPackage.schemaRelationships).Value; int sheetID = Convert.ToInt32(sheetNode.Attributes["sheetId"].Value); if (!String.IsNullOrEmpty(relId)) { var sheetRelation = pck.Workbook.Part.GetRelationship(relId); Uri uriWorksheet = UriHelper.ResolvePartUri(pck.Workbook.WorkbookUri, sheetRelation.TargetUri); //add the worksheet int positionID = ix + _pck._worksheetAdd; if (sheetRelation.RelationshipType.EndsWith("chartsheet")) { _worksheets.Add(ix, new ExcelChartsheet(_namespaceManager, _pck, relId, uriWorksheet, name, sheetID, positionID, null)); } else { _worksheets.Add(ix, new ExcelWorksheet(_namespaceManager, _pck, relId, uriWorksheet, name, sheetID, positionID, null)); } ix++; } } } }
public T Find_By_Uuid <T>(string uuid) where T : XenObject <T> { Type t = typeof(T); PropertyInfo p = t.GetProperty("uuid", BindingFlags.Public | BindingFlags.Instance); if (p == null) { return(null); } ChangeableDictionary <XenRef <T>, T> d = (ChangeableDictionary <XenRef <T>, T>)GetCollectionForType(t); lock (d) { foreach (T m in d.Values) { if (((string)p.GetValue(m, null)) == uuid) { return(m); } } } return(null); }