示例#1
0
        public static void CreateFromTemplate(this ITextTransform transform, LPath source, LPath destination)
        {
            // Console.WriteLine("{0} -> {1}", source, destination);

            if (source.IsFile)
            {
                destination.EnsureParentDirectoryExists();
                if (IsBinaryFile(source))
                {
                    source.CopyFile(destination);
                }
                else
                {
                    using (var w = destination.WriteText())
                        using (var r = source.ReadText())
                        {
                            transform.Transform(r, w);
                        }
                }
            }
            else
            {
                foreach (var i in source.Info.GetChildren())
                {
                    transform.CreateFromTemplate(i.FullName, destination.CatDir(transform.Transform(i.Name)));
                }
            }
        }
示例#2
0
        static T ReadYamlConfig <T>(LPath yamlFile) where T : new()
        {
            if (yamlFile.IsFile)
            {
                var deserializer = new DeserializerBuilder()
                                   .WithNamingConvention(CamelCaseNamingConvention.Instance)
                                   .Build();

                using (var r = yamlFile.ReadText())
                {
                    return(deserializer.Deserialize <T>(r));
                }
            }
            else
            {
                yamlFile.EnsureParentDirectoryExists();
                var serializer = new SerializerBuilder()
                                 .WithNamingConvention(CamelCaseNamingConvention.Instance)
                                 .Build();

                using (var w = yamlFile.WriteText())
                {
                    var c = new T();
                    serializer.Serialize(w, c);
                    return(c);
                }
            }
        }
示例#3
0
 public LPath Capture(Rectangle bounds, LPath destination)
 {
     using (var bitmap = Capture(bounds))
     {
         destination.EnsureParentDirectoryExists();
         bitmap.Save(destination.ToString(), System.Drawing.Imaging.ImageFormat.Png);
         log.InfoFormat("Screenshot of {0} saved in {1}", bounds, destination);
         return(destination);
     }
 }