private static Dictionary<string, string> DictionaryForProfileItem(string key, string displayKey, string value, string displayValue) { Dictionary<string, string> item = new Dictionary<string, string>(); item.SetValueForKey(key, SUConstants.SUProfileItemKeyKey); item.SetValueForKey(displayKey, SUConstants.SUProfileItemDisplayKeyKey); item.SetValueForKey(value, SUConstants.SUProfileItemValueKey); item.SetValueForKey(displayValue, SUConstants.SUProfileItemDisplayValueKey); return item; }
public KNKVOKeyPathObserver(Object aBaseObject, String aKeyPath, KNKVOObserver anObserver, KNKeyValueObservingOptions someOptions, Object aContext) { changes = new Stack<KNKVOObservationChangeTracker>(); previousObservations = new ArrayList(); baseObjectRef = new WeakReference(aBaseObject); keyPath = aKeyPath; context = aContext; options = someOptions; observer = anObserver; //this.ObserveValueForKeyPathOfObject(aKeyPath, observedObject, null, context); ResetObservationTree(); if ((options & KNKeyValueObservingOptions.KNKeyValueObservingOptionInitial) == KNKeyValueObservingOptions.KNKeyValueObservingOptionInitial) { Dictionary<String, Object> change = new Dictionary<String, Object>(); if ((options & KNKeyValueObservingOptions.KNKeyValueObservingOptionNew) == KNKeyValueObservingOptions.KNKeyValueObservingOptionNew) { change.SetValueForKey(observedObject.ValueForKeyPath(keyPath), KNKVOConstants.KNKeyValueChangeNewKey); } observer.ObserveValueForKeyPathOfObject(keyPath, observedObject, change, context); } }
public void ObserveValueForKeyPathOfObject(String aKeyPath, Object anObj, Dictionary<String, Object> change, Object aContext) { if (change != null && change.ValueForKey(KNKVOConstants.KNKeyValueChangeNotificationIsPriorKey) != null) { Object oldValue = observedObject.ValueForKeyPath(keyPath); KNKVOObservationChangeTracker tracker = new KNKVOObservationChangeTracker(oldValue, aKeyPath); changes.Push(tracker); // Remove our observers completely Object currentObj = observedObject; ArrayList keys = new ArrayList(keyPath.Split('.')); foreach (String key in keys) { previousObservations.Add(new KeyValuePair<Object, String>(currentObj, key)); currentObj = currentObj.ValueForKey(key); if (currentObj == null) { break; } } if ((options & KNKeyValueObservingOptions.KNKeyValueObservingOptionPrior) == KNKeyValueObservingOptions.KNKeyValueObservingOptionPrior) { Dictionary<String, Object> changeDict = new Dictionary<String, Object>(); changeDict.SetValueForKey(true, KNKVOConstants.KNKeyValueChangeNotificationIsPriorKey); changeDict.SetValueForKey(oldValue, KNKVOConstants.KNKeyValueChangeOldKey); observer.ObserveValueForKeyPathOfObject(keyPath, observedObject, changeDict, context); } } else { ResetObservationTree(); Dictionary<String, Object> changeDict = new Dictionary<String, Object>(); if (changes.Count > 0) { KNKVOObservationChangeTracker tracker = changes.Pop(); if (((options & KNKeyValueObservingOptions.KNKeyValueObservingOptionOld) == KNKeyValueObservingOptions.KNKeyValueObservingOptionOld) && (tracker != null)) { changeDict.SetValueForKey(tracker.OldValue, KNKVOConstants.KNKeyValueChangeOldKey); } } changeDict.SetValueForKey(observedObject.ValueForKeyPath(keyPath), KNKVOConstants.KNKeyValueChangeNewKey); observer.ObserveValueForKeyPathOfObject(keyPath, observedObject, changeDict, context); } }
private void HandleAppcast(string appcast) { XmlNodeList xmlItems = null; try { XmlDocument doc = new XmlDocument(); doc.LoadXml(appcast); xmlItems = doc.SelectNodes("/rss/channel/item"); } catch (Exception ex) { ReportError(ex); return; } List<SUAppcastItem> appcastItems = new List<SUAppcastItem>(); foreach (XmlNode node in xmlItems) { Dictionary<string, ArrayList> nodesDict = new Dictionary<string, ArrayList>(); Dictionary<string, Object> itemDescription = new Dictionary<string, object>(); // Create a dictionary of nodes for each name present, // so we can parse by xml:lang later. foreach (XmlNode childNode in node.ChildNodes) { string nodeName = childNode.Name; ArrayList nodesForName = null; if (!nodesDict.TryGetValue(nodeName, out nodesForName)) { nodesForName = new ArrayList(); nodesDict.Add(nodeName, nodesForName); } nodesForName.Add(childNode); } foreach (string itemKey in nodesDict.Keys) { ArrayList nodes = null; nodesDict.TryGetValue(itemKey, out nodes); XmlNode bestNodeForKey = BestNodeInNodes(nodes); if (bestNodeForKey.Name.Equals("enclosure")) { // enclosure is flattened as a separate dictionary for some reason Dictionary<string, string> enclosureDict = new Dictionary<string, string>(); foreach (XmlAttribute attribute in bestNodeForKey.Attributes) { enclosureDict.SetValueForKey(attribute.InnerText, attribute.Name); } itemDescription.SetValueForKey(enclosureDict, "enclosure"); } else if (bestNodeForKey.Name.Equals("pubDate")) { try { DateTime date = DateTime.Parse(bestNodeForKey.InnerText); itemDescription.SetValueForKey(date, bestNodeForKey.Name); } catch { // Nothing } } else { itemDescription.SetValueForKey(bestNodeForKey.InnerText.Trim(), bestNodeForKey.Name); } } try { SUAppcastItem item = new SUAppcastItem(itemDescription); appcastItems.Add(item); } catch { } } appcastItems.Sort(); appcastItems.Reverse(); // new to old Items = appcastItems; if (Delegate != null) { Delegate.AppcastDidFinishLoading(this); } }
private void fireObservation(Object newValue, Object oldValue, Boolean isPrior) { Dictionary<String, Object> change = new Dictionary<String, Object>(); if ((options & KNKeyValueObservingOptions.KNKeyValueObservingOptionNew) == KNKeyValueObservingOptions.KNKeyValueObservingOptionNew) { if (newValue != null) { change.SetValueForKey(newValue, KNKVOConstants.KNKeyValueChangeNewKey); } } if ((options & KNKeyValueObservingOptions.KNKeyValueObservingOptionOld) == KNKeyValueObservingOptions.KNKeyValueObservingOptionOld) { if (oldValue != null) { change.SetValueForKey(oldValue, KNKVOConstants.KNKeyValueChangeOldKey); } } if (isPrior) { change.SetValueForKey(true, KNKVOConstants.KNKeyValueChangeNotificationIsPriorKey); } observer.ObserveValueForKeyPathOfObject(key, observedObject, change, context); }