예제 #1
0
        IMeasurements IDataLinkFactory.GetMeasurements(ICategoryObject target)
        {
            IAssociatedObject ao = target;
            object            o  = ao.Object;

            if (o is INamedComponent)
            {
                IMeasurements   ml   = null;
                INamedComponent comp = o as INamedComponent;
                IDesktop        d    = null;
                INamedComponent r    = comp.Root;
                if (r != null)
                {
                    d = r.Desktop;
                }
                else
                {
                    d = comp.Desktop;
                }
                if (d != null)
                {
                    d.ForEach((DataLink dl) =>
                    {
                        if (ml != null)
                        {
                            return;
                        }
                        object dt = dl.Target;
                        if (dt is IAssociatedObject)
                        {
                            IAssociatedObject aot = dt as IAssociatedObject;
                            if (aot.Object == o & (!(aot is IChildrenObject)))
                            {
                                ml = dl.Target as IMeasurements;
                            }
                        }
                    });
                    if (ml != null)
                    {
                        return(ml);
                    }
                }
            }
            IMeasurements m = MeasurementsWrapper.Create(target);

            if (m == null)
            {
                CategoryException.ThrowIllegalTargetException();
            }
            return(m);
        }
예제 #2
0
        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);
        }