コード例 #1
0
ファイル: DataLink.cs プロジェクト: Erroman/universal
        IDataConsumer IDataLinkFactory.GetConsumer(ICategoryObject source)
        {
            /*   if (source is IChildrenObject)
             * {
             *     IDataConsumer dcc = (source as IChildrenObject).GetChildren<IDataConsumer>();
             *     if (dcc != null)
             *     {
             *         return dcc;
             *     }
             * }*/
            IAssociatedObject ao = source;
            object            o  = ao.Object;

            if (o is INamedComponent)
            {
                IDataConsumer   dcl     = null;
                INamedComponent comp    = o as INamedComponent;
                IDesktop        desktop = comp.Root.Desktop;
                desktop.ForEach <DataLink>((DataLink dl) =>
                {
                    if (dcl != null)
                    {
                        return;
                    }
                    object dt = dl.Source;
                    if (dt is IAssociatedObject)
                    {
                        IAssociatedObject aot = dt as IAssociatedObject;
                        if (aot.Object == o)
                        {
                            dcl = dl.source as IDataConsumer;
                        }
                    }
                });

                if (dcl != null)
                {
                    return(dcl);
                }
            }

            IDataConsumer dc = DataConsumerWrapper.Create(source);

            if (dc == null)
            {
                CategoryException.ThrowIllegalTargetException();
            }
            return(dc);
        }
コード例 #2
0
        private static IDataConsumer Create(IAssociatedObject root,
                                            IDataConsumer master, IDataConsumer slave)
        {
            if (master == null)
            {
                return(slave);
            }
            if (slave == null)
            {
                return(master);
            }
            if (master is DataConsumerWrapper)
            {
                DataConsumerWrapper dw = master as DataConsumerWrapper;
                dw.Add(slave);
                return(dw);
            }
            DataConsumerWrapper wrapper = new DataConsumerWrapper(root);

            wrapper.Add(master);
            wrapper.Add(slave);
            return(wrapper);
        }