コード例 #1
0
 public static T GetXaml <T>(string path)
 {
     using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(path))
     {
         return((T)XamlConfigurationParser.LoadFrom(stream));
     }
 }
コード例 #2
0
 private static UIElement Read(string path)
 {
     using (var stream = File.OpenRead(path))
     {
         Throws.IfNot(stream != null, "The requested file is not exist.");
         // создаем экземпляр
         return((UIElement)XamlConfigurationParser.LoadFrom(stream));
     }
 }
コード例 #3
0
        protected virtual T GetOrAdd <T>(string key, Func <T> func)
        {
            var paths = new List <string>()
            {
                Path.Combine(DataDirectory, key)
            };

            if (ArchiveFiles)
            {
                paths.Insert(0, Path.Combine(DataDirectory, $"{key}.zip"));
            }
            foreach (var path in paths)
            {
                if (File.Exists(path))
                {
                    if (path.EndsWith("zip"))
                    {
                        using (var archive = ZipFile.OpenRead(path))
                        {
                            var entry = archive.Entries.FirstOrDefault();
                            using (var stream = entry.Open())
                            {
                                return((T)XamlConfigurationParser.LoadFrom(stream));
                            }
                        }
                    }
                    else
                    {
                        return((T)XamlConfigurationParser.LoadFrom(path));
                    }
                }
            }

            var data = func();

            if (data != null)
            {
                var path = paths[0];
                if (path.EndsWith("zip"))
                {
                    using (var memoryStream = File.Create(path))
                    {
                        using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create))
                        {
                            var entry = archive.CreateEntry(key);

                            using (var stream = entry.Open())
                            {
                                XamlConfigurationParser.SaveTo(stream, data);
                            }
                        }
                    }
                }
            }

            return(data);
        }
コード例 #4
0
 protected T GetXaml <T>(string path)
 {
     using (var stream = Assembly.GetExecutingAssembly()
                         .GetManifestResourceStream(path))
     {
         Throws.IfNot(stream != null, "The requested file is not found in embedded resource.");
         // создаем экземпляр
         return((T)XamlConfigurationParser.LoadFrom(stream));
     }
 }
コード例 #5
0
 public Task <Article> Read(Stream stream)
 {
     return(Task.Run <Article>(() => (Article)XamlConfigurationParser.LoadFrom(stream)));
 }
コード例 #6
0
 public Task <Content> Read(Stream stream)
 {
     return(Task.Run <Content>(() => (Content)XamlConfigurationParser.LoadFrom(stream)));
 }