Example #1
0
        private static int Process(string templatePath, string dataPath, string outputPath)
        {
            var ext = SupportedType.FindExtension(templatePath);

            if (ext == null)
            {
                Console.Error.WriteLine("Unsupported extension: " + templatePath);
                return(2);
            }

            if (dataPath != null && !File.Exists(dataPath))
            {
                Console.Error.WriteLine("Unable to find specified data file: " + dataPath);
                return(2);
            }
            var json = dataPath == null ? Console.In : new StreamReader(new FileStream(dataPath, FileMode.Open, FileAccess.Read));

            var newtonsoft = new Newtonsoft.Json.JsonSerializer();

            newtonsoft.Converters.Add(new DictionaryConverter());

            using (var fis = new FileStream(templatePath, FileMode.Open, FileAccess.Read))
                using (var fos = outputPath == null ? Console.OpenStandardOutput() : new FileStream(outputPath, FileMode.Create, FileAccess.Write))
                {
                    var deser = newtonsoft.Deserialize <IDictionary <string, object> >(new JsonTextReader(json));
                    using (var td = Configuration.Factory.Open(fis, fos, ext))
                        td.Process(deser);
                }

            return(0);
        }
Example #2
0
        private static int Process(string templatePath, string dataPath, string outputPath)
        {
            var ext = SupportedType.FindExtension(templatePath);

            if (ext == null)
            {
                Console.Error.WriteLine("Unsupported extension: " + templatePath);
                return(2);
            }

            if (dataPath != null && !File.Exists(dataPath))
            {
                Console.Error.WriteLine("Unable to find specified data file: " + dataPath);
                return(2);
            }
            var json = dataPath == null ? Console.In : new StreamReader(Open(dataPath));

            var newtonsoft = new Newtonsoft.Json.JsonSerializer();

            newtonsoft.Converters.Add(new DictionaryConverter());

            using (var fis = Open(templatePath))
                using (var fos = outputPath == null ? Console.OpenStandardOutput() : new FileStream(outputPath, FileMode.Create, FileAccess.Write))
                {
                    while (char.IsWhiteSpace((char)json.Peek()))
                    {
                        json.Read();
                    }
                    //disable low level plugins so it works on more platforms without GDI library for System.Drawing
                    var config = Configuration.Builder
                                 .Include(Base64Image)
                                 .Include(Xml)
                                 .BuiltInLowLevelPlugins(false);
                    if (json.Peek() == '[')
                    {
                        var deser = newtonsoft.Deserialize <IDictionary <string, object>[]>(new JsonTextReader(json));
                        using (var td = config.Build().Open(fis, fos, ext))
                            td.Process(deser);
                    }
                    else
                    {
                        var deser = newtonsoft.Deserialize <IDictionary <string, object> >(new JsonTextReader(json));
                        using (var td = config.Build().Open(fis, fos, ext))
                            td.Process(deser);
                    }
                }

            return(0);
        }