Esempio 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);
                    }
                }
            }
        }
Esempio 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();
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 public LineTwoPoints(IFigureList dependencies)
 {
     Dependencies = dependencies;
     RegisterWithDependencies();
 }
Esempio n. 4
0
 public MidPoint(IFigureList dependencies)
 {
     Dependencies = dependencies;
     RegisterWithDependencies();
 }
Esempio n. 5
0
 public static LineTwoPoints CreateLineTwoPoints(IFigureList dependencies)
 {
     return(new LineTwoPoints(dependencies));
 }
Esempio n. 6
0
        public static MidPoint CreateMidPoint(IFigureList dependencies)
        {
            MidPoint result = new MidPoint(dependencies);

            return(result);
        }
Esempio n. 7
0
 public LineTwoPoints(IFigureList dependencies)
 {
     Dependencies = dependencies;
     RegisterWithDependencies();
 }
Esempio n. 8
0
 public static MidPoint CreateMidPoint(IFigureList dependencies)
 {
     MidPoint result = new MidPoint(dependencies);
     return result;
 }
Esempio n. 9
0
 public static LineTwoPoints CreateLineTwoPoints(IFigureList dependencies)
 {
     return new LineTwoPoints(dependencies);
 }
Esempio n. 10
0
 public MidPoint(IFigureList dependencies)
 {
     Dependencies = dependencies;
     RegisterWithDependencies();
 }
Esempio 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;
        }