Example #1
0
        public static async Task <Copyable> DecodeFile(string[] paths, Window sender, Type ensure)
        {
            Copyable ret = new Copyable();

            try {
                foreach (string path in paths)
                {
                    Copyable copyable;

                    using (FileStream file = File.Open(path, FileMode.Open, FileAccess.Read))
                        copyable = await Decoder.Decode(file, typeof(Copyable));

                    if (!ensure.IsAssignableFrom(copyable.Type))
                    {
                        throw new InvalidDataException();
                    }

                    ret.Merge(copyable);
                }

                return(ret);
            } catch {
                await MessageWindow.CreateReadError(sender);

                return(null);
            }
        }