Example #1
0
        private void LoadSolid(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.Filter = "All files (*.*)|*.*";
            if (dlg.ShowDialog() == true)
            {
                //zaƂadowanie informaccji z pliku
                IFormatter formatter = new BinaryFormatter();
                Stream     stream    = new FileStream(dlg.FileName,
                                                      FileMode.Open,
                                                      FileAccess.Read,
                                                      FileShare.Read);

                try
                {
                    ModelGrid OldModelGrid = (ModelGrid)formatter.Deserialize(stream);
                    ModelGrid.SetModelFromFile(OldModelGrid.GetGrid(), OldModelGrid.Width, OldModelGrid.Height, OldModelGrid.Length);
                }
                catch (SerializationException exc)
                {
                    Console.WriteLine("Failed to deserialize. Reason: " + exc.Message);
                    throw;
                }
                finally
                {
                    stream.Close();
                }
            }
        }