Beispiel #1
0
        /// <summary>
        ///     Synchronizes the collection with changes made in a child collection.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">Information about the event.</param>
        private void ChildCollectionCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            Debug.Assert(e.Action != NotifyCollectionChangedAction.Reset, "Reset is not supported.");
            var collectionSender = sender as IList;

            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                int startingIndex = GetStartingIndexOfCollectionAtIndex(ChildCollections.IndexOf(collectionSender));
                e.NewItems
                .OfType <T>()
                .ForEachWithIndex(
                    (item, index) => Mutate(that => that.Insert(startingIndex + e.NewStartingIndex + index, item)));
            }
            else if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                foreach (T item in e.OldItems.OfType <T>())
                {
                    Mutate(that => that.Remove(item));
                }
            }
            else if (e.Action == NotifyCollectionChangedAction.Replace)
            {
                for (int cnt = 0; cnt < e.NewItems.Count; cnt++)
                {
                    var oldItem      = (T)e.OldItems[cnt];
                    var newItem      = (T)e.NewItems[cnt];
                    int oldItemIndex = IndexOf(oldItem);
                    Mutate(that => { that[oldItemIndex] = newItem; });
                }
            }
        }
Beispiel #2
0
 /// <summary>
 ///     Returns the starting index of a collection in the aggregate
 ///     collection.
 /// </summary>
 /// <param name="index">The starting index of a collection.</param>
 /// <returns>
 ///     The starting index of the collection in the aggregate
 ///     collection.
 /// </returns>
 private int GetStartingIndexOfCollectionAtIndex(int index)
 {
     return
         (ChildCollections.OfType <IEnumerable>()
          .Select(collection => collection.Cast <T>())
          .Take(index)
          .SelectMany(collection => collection)
          .Count());
 }
Beispiel #3
0
        public void ImportKey(VaultKeyInfo keyInfo, Database db = null)
        {
            VaultKey key = VaultKeysByVaultId.AddNew();

            key.RsaKey   = keyInfo.RsaKey;
            key.Password = keyInfo.Password;
            key.Save(db);
            _items = null;
            ChildCollections.Clear();
        }
Beispiel #4
0
        public VaultKeyInfo ExportKey(Database db = null)
        {
            db = db ?? Database;
            VaultKey key = VaultKeysByVaultId.FirstOrDefault();

            _items = null;
            VaultKeysByVaultId.Delete(db);
            ChildCollections.Clear();
            VaultKeyInfo result = key.CopyAs <VaultKeyInfo>();

            return(result);
        }
Beispiel #5
0
 /// <summary>
 /// Rebuild the list in the correct order when a child collection
 /// changes.
 /// </summary>
 private void Rebuild()
 {
     this.Mutate(that => that.Clear());
     this.Mutate(that =>
     {
         IList <T> items = ChildCollections.OfType <IEnumerable>().Select(collection => collection.Cast <T>()).SelectMany(collection => collection).ToList();
         foreach (T item in items)
         {
             that.Add(item);
         }
     });
 }
        /// <summary>
        /// Rebuild the list in the correct order when a child collection
        /// changes.
        /// </summary>
        private void Rebuild()
        {
            this.Clear();
            //this.Items.Clear();

            IList <T> items = ChildCollections.OfType <IEnumerable>().Select(collection => collection.CastWrapper <T>()).SelectMany(collection => collection).ToList();

            foreach (T item in items)
            {
                //this.Items.Add(item);
                this.Add(item);
            }
        }
 /// <summary>
 /// Rebuild the list in the correct order when a child collection
 /// changes.
 /// </summary>
 private void Rebuild()
 {
     this.Mutate(that =>
     {
         IList <T> items = ChildCollections.SelectMany(collection => collection).ToList();
         foreach (T item in items)
         {
             that.Remove(item);
         }
         foreach (T item in items)
         {
             that.Add(item);
         }
     });
 }
Beispiel #8
0
        private static IEnumerable <JToken> GetFlattenedObjects(JToken token, IEnumerable <JProperty> otherProperties = null)
        {
            if (token is JObject obj)
            {
                var children = obj.Children <JProperty>().GroupBy(prop => prop.Value?.Type == JTokenType.Array).ToDictionary(gr => gr.Key);
                if (children.TryGetValue(false, out var directProps))
                {
                    otherProperties = otherProperties?.Concat(directProps) ?? directProps;
                }

                if (children.TryGetValue(true, out var ChildCollections))
                {
                    foreach (var childObj in ChildCollections.SelectMany(childColl => childColl.Values()).SelectMany(childColl => GetFlattenedObjects(childColl, otherProperties)))
                    {
                        yield return(childObj);
                    }
                }
                else
                {
                    var res = new JObject();
                    if (otherProperties != null)
                    {
                        foreach (var prop in otherProperties)
                        {
                            res.Add(prop);
                        }
                    }
                    yield return(res);
                }
            }
            else if (token is JArray arr)
            {
                foreach (var co in token.Children().SelectMany(c => GetFlattenedObjects(c, otherProperties)))
                {
                    yield return(co);
                }
            }
            else
            {
                throw new NotImplementedException(token.GetType().Name);
            }
        }
 /// <summary>
 /// Returns the starting index of a collection in the aggregate
 /// collection.
 /// </summary>
 /// <param name="index">The starting index of a collection.</param>
 /// <returns>The starting index of the collection in the aggregate
 /// collection.</returns>
 private int GetStartingIndexOfCollectionAtIndex(int index)
 {
     return(ChildCollections.Take(index).SelectMany(collection => collection).Count());
 }