Exemplo n.º 1
0
        public static IEnumerable <IFigure> GetAllFiguresRecursive(this IFigure rootFigure)
        {
            yield return(rootFigure);

            IFigureList list = rootFigure as IFigureList;

            if (list != null)
            {
                foreach (var item in list)
                {
                    foreach (var recursive in item.GetAllFiguresRecursive())
                    {
                        yield return(recursive);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static void CheckConsistency(this IFigureList list)
        {
            foreach (var figure in list)
            {
                if (figure.Dependencies != null)
                {
                    foreach (var dependency in figure.Dependencies)
                    {
                        //if (!list.Contains(dependency))
                        //{
                        //    throw new Exception();
                        //}

                        if (!dependency.Dependents.Contains(figure))
                        {
                            throw new Exception();
                        }
                    }
                }
                if (figure.Dependents != null)
                {
                    foreach (var dependent in figure.Dependents)
                    {
                        //if (!list.Contains(dependent))
                        //{
                        //    throw new Exception();
                        //}

                        if (!dependent.Dependencies.Contains(figure))
                        {
                            throw new Exception();
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 public LineTwoPoints(IFigureList dependencies)
 {
     Dependencies = dependencies;
     RegisterWithDependencies();
 }
Exemplo n.º 4
0
 public MidPoint(IFigureList dependencies)
 {
     Dependencies = dependencies;
     RegisterWithDependencies();
 }
Exemplo n.º 5
0
 public static LineTwoPoints CreateLineTwoPoints(IFigureList dependencies)
 {
     return(new LineTwoPoints(dependencies));
 }
Exemplo n.º 6
0
        public static MidPoint CreateMidPoint(IFigureList dependencies)
        {
            MidPoint result = new MidPoint(dependencies);

            return(result);
        }
Exemplo n.º 7
0
 public LineTwoPoints(IFigureList dependencies)
 {
     Dependencies = dependencies;
     RegisterWithDependencies();
 }
Exemplo n.º 8
0
 public static MidPoint CreateMidPoint(IFigureList dependencies)
 {
     MidPoint result = new MidPoint(dependencies);
     return result;
 }
Exemplo n.º 9
0
 public static LineTwoPoints CreateLineTwoPoints(IFigureList dependencies)
 {
     return new LineTwoPoints(dependencies);
 }
Exemplo n.º 10
0
 public MidPoint(IFigureList dependencies)
 {
     Dependencies = dependencies;
     RegisterWithDependencies();
 }
Exemplo n.º 11
0
        private static IFigure ReadFigure(
            XElement figureNode,
            Dictionary<string, IFigure> dictionary,
            Drawing drawing)
        {
            Type type = FindType(figureNode.Name.LocalName);
            if (type == null)
            {
                return null;
            }

            IFigure instance = null;
            IFigureList dependencies = ReadDependencies(figureNode, dictionary);

            var defaultCtor = type.GetConstructor(Type.EmptyTypes);
            if (defaultCtor != null)
            {
                instance = Activator.CreateInstance(type) as IFigure;
                instance.Dependencies = dependencies;
                instance.Drawing = drawing;
            }
            else
            {
                var ctorWithDependencies = type.GetConstructor(new Type[] { typeof(IFigureList) });
                if (ctorWithDependencies != null)
                {
                    instance = Activator.CreateInstance(type, dependencies) as IFigure;
                }
                else
                {
                    var ctorWithDrawingAndDependencies = type.GetConstructor(new Type[] { typeof(Drawing), typeof(IFigureList) });
                    if (ctorWithDrawingAndDependencies != null)
                    {
                        instance = Activator.CreateInstance(type, drawing, dependencies) as IFigure;
                    }
                }
            }

            instance.Name = figureNode.ReadString("Name");

            // get the max id , 07-23-2009 scott
            if (!(instance is Game.PBPlayer) && !(instance is Game.PBBall))
            {
                int index = instance.Name.Length - 1;
                for (int len = instance.Name.Length - 1; len >= 0; len--)
                {
                    if (Char.IsLetter(instance.Name[len]))
                    {
                        index = len;
                        break;
                    }
                }

                string strNum = instance.Name.Substring(index + 1);

                FigureBase.ID = System.Math.Max(FigureBase.ID, int.Parse(strNum));
            }
            // end

            instance.ReadXml(figureNode);
            if (!(instance is Game.PBBall))
            {
                dictionary.Add(instance.Name, instance);
            }
            return instance;
        }