Ejemplo n.º 1
0
        //------------------------------------------------------------------------------------
        /// <summary>
        /// Returns an item of the given ItemType, representing a special in-memory-only
        /// dummyType of object, such as "All" or "None".
        /// </summary>
        //------------------------------------------------------------------------------------
        public static T GetDummyItem <T>(DummyItemType dummyType) where T : StoreItem, new()
        {
            lock (SyncLockDummyObject)
            {
                if (DummyItems == null)
                {
                    DummyItems = new Dictionary <string, Dictionary <DummyItemType, StoreItem> >();
                }

                string key = typeof(T).Name;

                if (!DummyItems.ContainsKey(key))
                {
                    DummyItems.Add(key, new Dictionary <DummyItemType, StoreItem>());
                }

                T item = null;
                Dictionary <DummyItemType, StoreItem> dummyItems = DummyItems[key];
                if (!dummyItems.ContainsKey(dummyType))
                {
                    switch (dummyType)
                    {
                    case DummyItemType.AllType:
                        item = new T();
                        item.DummyInitialize(Constants.c_All);
                        break;

                    case DummyItemType.NoneType:
                        item = new T();
                        item.DummyInitialize(Constants.c_None);
                        break;

                    default:
                        throw new ApplicationException();
                    }

                    dummyItems.Add(dummyType, item);
                }

                return(dummyItems[dummyType] as T);
            }
        }
Ejemplo n.º 2
0
        public static AsyncObservableCollection <T> GetItems <T>(AsyncObservableCollection <T> collection, DummyItemType collectionType) where T : StoreItem, new()
        {
            AsyncObservableCollection <T> items = collection.ToCollection();

            items.Sort((x, y) => x.Title.CompareTo(y.Title));

            if (collectionType == DummyItemType.NoneType || collectionType == DummyItemType.AllNoneType)
            {
                T item = StoreItem.GetDummyItem <T>(DummyItemType.NoneType);
                items.Insert(0, item);
            }

            if (collectionType == DummyItemType.AllType || collectionType == DummyItemType.AllNoneType)
            {
                T item = StoreItem.GetDummyItem <T>(DummyItemType.AllType);
                items.Insert(0, item);
            }

            return(items);
        }
Ejemplo n.º 3
0
        public static AsyncObservableCollection <T> GetItems <T>(AsyncObservableCollection <T> collection, DummyItemType collectionType, string sortPropName) where T : StoreItem, new()
        {
            AsyncObservableCollection <T> items = collection.ToCollection();

            if (collectionType == DummyItemType.NoneType || collectionType == DummyItemType.AllNoneType)
            {
                T item = StoreItem.GetDummyItem <T>(DummyItemType.NoneType);
                items.Add(item);
            }

            if (collectionType == DummyItemType.AllType || collectionType == DummyItemType.AllNoneType)
            {
                T item = StoreItem.GetDummyItem <T>(DummyItemType.AllType);
                items.Add(item);
            }

            ItemPropertySort <T> itemComparer = new ItemPropertySort <T>(sortPropName, System.ComponentModel.ListSortDirection.Ascending);

            items.Sort((x, y) => itemComparer.Compare(x, y));

            return(items);
        }
Ejemplo n.º 4
0
        public static AsyncObservableCollection <T> GetItems <T>(this AsyncObservableCollection <T> collection, DummyItemType collectionType) where T : StoreItem, new()
        {
            AsyncObservableCollection <T> items = collection.ToCollection();

            items.Sort((x, y) => x.Title.CompareTo(y.Title));

            if (collectionType == DummyItemType.NoneType || collectionType == DummyItemType.AllNoneType)
            {
                T item = StoreItem.GetDummyItem <T>(DummyItemType.NoneType);
                items.Insert(0, item);
            }

            if (collectionType == DummyItemType.AllType || collectionType == DummyItemType.AllNoneType)
            {
                T item = StoreItem.GetDummyItem <T>(DummyItemType.AllType);
                items.Insert(0, item);
            }

            // If there are no items at all in the collection, throw an 'All' on the list
            if (items.Count == 0)
            {
                T item = StoreItem.GetDummyItem <T>(DummyItemType.AllType);
                items.Insert(0, item);
            }

            return(items);
        }