Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
{}
Wiki Markup
scrollbar

Problem

  • Reduce number of exchange items a Linkable component exposes through its interface

...

unmigrated-inline-wiki-markup
Code Block

        static List<IInputExchangeItem> FilteredExchangeItems(ILinkableComponent iLC)
        {
            List<IInputExchangeItem> items = new List<IInputExchangeItem>();

            if (iLC is IFilterable)
            {
                IFilterable iFilterable = (IFilterable)iLC;

                List<IFilter> activeFilters = new List<IFilter>();

                // Make all sugestions active, would be GUI controlled, 
                // and could include 3rd part supplied filters as well
                for (int n = 0; n < iFilterable.SuggestedFilterCount; ++n)
                    activeFilters.Add(iFilterable.FilterSugestion(n));

                for (int n = 0; n < iLC.InputExchangeItemCount; ++n)
                {
                    foreach (IFilter f in activeFilters)
                    {
                        if (f.Exclude(iLC.GetInputExchangeItem(n)))
                            continue;
                        items.Add(iLC.GetInputExchangeItem(n));
                    }
                }
            }
            else
            {
                for (int n = 0; n < iLC.InputExchangeItemCount; ++n)
                    items.Add(iLC.GetInputExchangeItem(n));
            }

            return items;
        }

    class LinkableComponent : ILinkableComponent, IFilterable
    {
        #region ILinkableComponent Members
        #endregion

        #region IPublisher Members
        #endregion

        #region IFilterable Members

        public int SuggestedFilterCount
        {
            get { return 1; }
        }

        public IFilter FilterSugestion(int index)
        {
            switch (index)
            {
                case 0:
                    return new FilterQuantity("Flow");
            }

            throw new Exception("Out of range");
        }

        #endregion
    }

    class FilterIdRegExp : IFilter
    {
        Regex _reg; 

        FilterIdRegExp(string reg)
        {
            _reg = new Regex(reg);
        }

        string ShortName()
        {
            return string.Format("Filter on \"{0}\"", _reg);
        }
        string Description()
        {
            return string.Format("Filter to match ElementSet Id against Regular Expression {0}", _reg);
        }

        bool Exclude(IExchangItem item)
        {
            return !_reg.Match(item.ElementSet().ID());
        }
    }

    class FilterQuantity : IFilter
    {
        string _quantity;

        FilterQuantity(string quantity)
        {
            _quantity = quantity;
        }

        string ShortName()
        {
            return string.Format("Filter on \"{0}\"", _quantity);
        }
        string Description()
        {
            return string.Format("Filter to match Quantity Id against \"{0}\"", _quantity);
        }

        bool Exclude(IExchangItem item)
        {
            return item.Quantity.ID() != _quantity;
        }
    }

    class FilterRegion : IFilter
    {
        List<IRegion> _regions;

        FilterRegion(List<IRegion> regions)
        {
            _regions = regions;
        }

        string ShortName()
        {
            return "Filter on regions";
        }
        string Description()
        {
            return "Filter on regions";
        }

        bool Exclude(IExchangItem item)
        {
            foreach (IRegion region in _regions)
                if (region.Contains(item.ElementSet()))
                    return false;

            return true;
        }
    }
{
}
scrollbar