コード例 #1
0
 void New(object sender, RoutedEventArgs e)
 {
     Program.Project?.Dispose();
     Program.Project = new Project();
     ProjectWindow.Create(this);
     Close();
 }
コード例 #2
0
        public async void ReadFile(string path)
        {
            Project loaded;

            try {
                using (FileStream file = File.Open(path, FileMode.Open, FileAccess.Read))
                    loaded = await Decoder.Decode(file, typeof(Project));
            } catch {
                await MessageWindow.Create(
                    $"An error occurred while reading the file.\n\n" +
                    "You may not have sufficient privileges to read from the destination folder, or\n" +
                    "the file you're attempting to read is invalid.",
                    null, this
                    );

                return;
            }

            loaded.FilePath = path;
            loaded.Undo.SavePosition();

            Program.Project = loaded;
            ProjectWindow.Create(this);

            Close();
        }
コード例 #3
0
        async void ReadFile(string path, bool recovery)
        {
            Project  loaded   = null;
            Copyable imported = null;

            try {
                try {
                    using (FileStream file = File.Open(path, FileMode.Open, FileAccess.Read))
                        loaded = await Decoder.Decode(file, typeof(Project));

                    if (!recovery)
                    {
                        loaded.FilePath = path;
                        loaded.Undo.SavePosition();
                        Preferences.RecentsAdd(path);
                    }

                    Program.Project?.Dispose();
                    Program.Project = loaded;
                } catch (InvalidDataException) {
                    using (FileStream file = File.Open(path, FileMode.Open, FileAccess.Read))
                        imported = await Decoder.Decode(file, typeof(Copyable));

                    Program.Project?.Dispose();
                    Program.Project = new Project(
                        tracks: (imported.Type == typeof(Track))
                            ? imported.Contents.Cast <Track>().ToList()
                            : new List <Track>()
                    {
                        new Track(new Chain((imported.Type == typeof(Chain))
                                    ? new List <Device>()
                        {
                            new Group(imported.Contents.Cast <Chain>().ToList())
                        }
                                    : imported.Contents.Cast <Device>().ToList()
                                            ))
                    }
                        );
                }
            } catch {
                await MessageWindow.Create(
                    $"An error occurred while reading the file.\n\n" +
                    "You may not have sufficient privileges to read from the destination folder, or\n" +
                    "the file you're attempting to read is invalid.",
                    null, this
                    );

                return;
            }

            ProjectWindow.Create(this);
            Close();
        }
コード例 #4
0
        async void ReadFile(string path, bool recovery)
        {
            Project  loaded   = null;
            Copyable imported = null;

            try {
                try {
                    using (FileStream file = File.Open(path, FileMode.Open, FileAccess.Read))
                        loaded = await Decoder.Decode <Project>(file);

                    if (!recovery)
                    {
                        loaded.FilePath = path;
                        loaded.Undo.SavePosition();
                        Preferences.RecentsAdd(path);
                    }

                    Program.Project?.Dispose();
                    Program.Project = loaded;
                } catch (InvalidDataException) {
                    using (FileStream file = File.Open(path, FileMode.Open, FileAccess.Read))
                        imported = await Decoder.Decode <Copyable>(file);

                    Program.Project?.Dispose();
                    Program.Project = new Project(
                        tracks: (imported.Type == typeof(Track))
                            ? imported.Contents.Cast <Track>().ToList()
                            : new List <Track>()
                    {
                        new Track(new Chain((imported.Type == typeof(Chain))
                                    ? new List <Device>()
                        {
                            new Group(imported.Contents.Cast <Chain>().ToList())
                        }
                                    : imported.Contents.Cast <Device>().ToList()
                                            ))
                    }
                        );
                }
            } catch {
                await MessageWindow.CreateReadError(this);

                Program.Project = null;

                return;
            }

            ProjectWindow.Create(this);
            Close();
        }