Example #1
0
        private void OnItemAdded(object sender, WatchingItemEventArgs e)
        {
            int directoryCount = 0;
            int count          = rawItems.Count;

            for (; directoryCount < count; directoryCount++)
            {
                if (rawItems[directoryCount].Type == ItemType.File)
                {
                    break;
                }
            }

            int max        = 0;
            int indexofRaw = 0;

            if (e.Type == ItemType.Directory)
            {
                max        = directoryCount;
                indexofRaw = 0;
            }
            else
            {
                max        = count;
                indexofRaw = directoryCount;
            }
            for (; indexofRaw < max; indexofRaw++)
            {
                if (rawItems[indexofRaw].Name.CompareTo(e.Name) < 1)
                {
                    continue;
                }
                else
                {
                    break;
                }
            }

            Dispatcher.Invoke(() =>
            {
                ItemInfo item = ItemInfo.FromPath(e.Path, e.Type);
                if (rawItems.Count == currentItems.Count)
                {
                    currentItems.Insert(indexofRaw, item);
                }
                rawItems.Insert(indexofRaw, item);
            });
        }
Example #2
0
        private void OnItemRemoved(object sender, WatchingItemEventArgs e)
        {
            int      index = 0;
            int      count = rawItems.Count;
            ItemInfo item;

            for (; index < count; index++)
            {
                item = rawItems[index];
                if (item.Name == e.Name && item.FullPath == e.Path && item.Type == e.Type)
                {
                    break;
                }
            }
            if (index < count)
            {
                rawItems.RemoveAt(index);
            }

            index = 0;
            count = currentItems.Count;
            for (; index < count; index++)
            {
                item = currentItems[index];
                if (item.Name == e.Name && item.FullPath == e.Path && item.Type == e.Type)
                {
                    break;
                }
            }
            if (index < count)
            {
                Dispatcher.Invoke(() =>
                {
                    currentItems.RemoveAt(index);
                });
            }
        }