public FiguresList.FigureList LoadFiguresList(FileStream fs, List <Type> types)
        {
            FiguresList.FigureList Rezlist     = new FiguresList.FigureList();
            SerialFiguresList      SerFigsList = (SerialFiguresList)formatter.Deserialize(fs);

            for (int i = 0; i < SerFigsList.Size(); i++)
            {
                Type typ = null;
                for (int j = 0; j < types.Count(); j++)
                {
                    if (types[j].FullName == SerFigsList.Item(i).figtype)
                    {
                        typ = types[j];
                    }
                }
                if (typ == null)
                {
                    throw new SerializationException("Unable to load item " + SerFigsList.Item(i).figtype + ": Assembly is not found.");
                }
                var pen = new Pen(SerFigsList.Item(i).penColor, SerFigsList.Item(i).penWidth);
                var fig = (Figure.Figure)Activator.CreateInstance(typ, new Object[] { pen, SerFigsList.Item(i).X1, SerFigsList.Item(i).Y1, SerFigsList.Item(i).X2, SerFigsList.Item(i).Y2 });
                if (fig is MyInterfaces.IFillingable)
                {
                    ((MyInterfaces.IFillingable)fig).isFilled = SerFigsList.Item(i).isFilled;
                }
                Rezlist.Add(fig);
            }
            return(Rezlist);
        }
示例#2
0
        public FiguresList.FigureList LoadFiguresList(FileStream fs, List <Type> types, List <string> nameslist, List <FiguresList.FigureList> srclists)
        {
            FiguresList.FigureList Rezlist     = new FiguresList.FigureList();
            SerialFiguresList      SerFigsList = (SerialFiguresList)formatter.Deserialize(fs);
            UserFigure             tmpusrfig   = new UserFigure("UserFigure", new Pen(Brushes.Black, 1), 0, 0, 0, 0);

            int i = 0;

            while (i < SerFigsList.Size())
            {
                //if (SerFigsList.Item(i).Name == "UserFigure" && SerFigsList.Item(i).isUserFigure == false)
                if (CheckUserName(nameslist, SerFigsList.Item(i).Name) && SerFigsList.Item(i).isUserFigure == false)
                {
                    if (srclists[FindNumberInList(nameslist, SerFigsList.Item(i).Name)].CalculateHash() == SerFigsList.Item(i).Hash)
                    {
                        tmpusrfig = new UserFigure(SerFigsList.Item(i).Name, new Pen(SerFigsList.Item(i).penColor, SerFigsList.Item(i).penWidth), SerFigsList.Item(i).X1, SerFigsList.Item(i).Y1, SerFigsList.Item(i).X2, SerFigsList.Item(i).Y2);
                        i++;
                        while (SerFigsList.Item(i).isUserFigure == true)
                        {
                            Type typ = null;
                            for (int j = 0; j < types.Count(); j++)
                            {
                                if (types[j].FullName == SerFigsList.Item(i).figtype)
                                {
                                    typ = types[j];
                                }
                            }
                            if (typ == null)
                            {
                                throw new SerializationException("Unable to load item " + SerFigsList.Item(i).figtype + ": Assembly is not found.");
                            }
                            var pen = new Pen(SerFigsList.Item(i).penColor, SerFigsList.Item(i).penWidth);
                            var fig = (Figure.Figure)Activator.CreateInstance(typ, new Object[] { pen, SerFigsList.Item(i).X1, SerFigsList.Item(i).Y1, SerFigsList.Item(i).X2, SerFigsList.Item(i).Y2 });
                            if (fig is MyInterfaces.IFillingable)
                            {
                                ((MyInterfaces.IFillingable)fig).isFilled = SerFigsList.Item(i).isFilled;
                            }
                            fig.isUserFigure = SerFigsList.Item(i).isUserFigure;
                            tmpusrfig.SourceFigures.Add(fig);
                            i++;
                            if (i == SerFigsList.Size())
                            {
                                break;
                            }
                        }
                        tmpusrfig.OnDeserialize();
                        Rezlist.Add(tmpusrfig);
                    }
                    else
                    {
                        throw new SerializationException("Unable to load item \"UserFigure." + SerFigsList.Item(i).Name + "\": Saved picture doesn't match with loaded.");
                    }
                }
                //else if (SerFigsList.Item(i).Name != "UserFigure" && SerFigsList.Item(i).isUserFigure == false)
                else if (!CheckUserName(nameslist, SerFigsList.Item(i).Name) && SerFigsList.Item(i).isUserFigure == false)
                {
                    Type typ = null;
                    for (int j = 0; j < types.Count(); j++)
                    {
                        if (types[j].FullName == SerFigsList.Item(i).figtype)
                        {
                            typ = types[j];
                        }
                    }
                    if (typ == null)
                    {
                        if (SerFigsList.Item(i).figtype != "Lab1.UserFigure")
                        {
                            throw new SerializationException("Unable to load item \"" + SerFigsList.Item(i).figtype + "\": Assembly is not found.");
                        }
                        else
                        {
                            throw new SerializationException("Unable to load item \"UserFigure." + SerFigsList.Item(i).Name + "\": UserFigure is not found.");
                        }
                    }
                    var pen = new Pen(SerFigsList.Item(i).penColor, SerFigsList.Item(i).penWidth);
                    var fig = (Figure.Figure)Activator.CreateInstance(typ, new Object[] { pen, SerFigsList.Item(i).X1, SerFigsList.Item(i).Y1, SerFigsList.Item(i).X2, SerFigsList.Item(i).Y2 });
                    if (fig is MyInterfaces.IFillingable)
                    {
                        ((MyInterfaces.IFillingable)fig).isFilled = SerFigsList.Item(i).isFilled;
                    }
                    fig.isUserFigure = SerFigsList.Item(i).isUserFigure;
                    Rezlist.Add(fig);
                    i++;
                    if (i == SerFigsList.Size())
                    {
                        break;
                    }
                }
            }

            return(Rezlist);
        }