Ejemplo n.º 1
0
        private void btnLoad_Click(object sender, RoutedEventArgs e)
        {
            MainWindow mainWindow = Window.GetWindow(this) as MainWindow;

            mainWindow.timerMove.Stop();

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = "Space Object files (*.xml;*json;*bin)|*.xml;*json;*bin";

            bool?result = dlg.ShowDialog();

            if (result == true)
            {
                try
                {
                    SpaceObject spaceObj = null;
                    Type        type     = centralObject.GetOrbitObjectsType();

                    switch (System.IO.Path.GetExtension(dlg.FileName).ToLower())
                    {
                    case ".xml":
                        if (type == typeof(Planet))
                        {
                            spaceObj = Serializer.XmlDeserialize(dlg.FileName, new Type[] { type, typeof(PlanetWithRings) });
                        }
                        else
                        {
                            spaceObj = Serializer.XmlDeserialize(dlg.FileName, new Type[] { type });
                        }
                        break;

                    case ".json":
                        // Не определяет тип десериализуемого
                        spaceObj = Serializer.JsonDeserialize(dlg.FileName, type);
                        break;

                    case ".bin":
                        spaceObj = Serializer.BinaryDeserialize(dlg.FileName);
                        break;
                    }
                    if (spaceObj == null)
                    {
                        throw new Exception();
                    }
                    centralObject.AddOrbitObject((OrbitObject)spaceObj);
                    spaceObj.Show(((SpaceObject)centralObject).ParentCanvas);
                    ShowChildrenList();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error");
                }
            }

            mainWindow.timerMove.Start();
        }
Ejemplo n.º 2
0
        public SpaceObjChildren(ICentral centralObject, Point pos, Canvas canvas)
        {
            InitializeComponent();

            this.pos           = pos;
            this.centralObject = centralObject;

            txtblockName.Text = (centralObject as SpaceObject).Name + " " + centralObject.GetOrbitObjectsType().Name.ToLower() + "s:";

            ShowChildrenList();
            Show(canvas);
        }