Beispiel #1
0
        public Generator(string schemaFilePath, GeneratorSetting setting)
        {
            this.schemaFilePath = schemaFilePath;
            this.setting        = setting;

            convertActions = new Dictionary <string, Action <string> >()
            {
                { NameSpaceLabel, OutputNameSpace },
                { ClassNameLabel, OutputClassName },

                { "@InheritanceBlock", OutputInheritanceBlock },
                { "@FunctionBlock", OutputFunctionBlock },
                { "@ClassBlock", OutputClassBlock },

                { "@Interfaces", OutputInterfaces },
                { "@Constructor", OutputConstructor },
                { "@Peroperties", OutputProperties },
                { "@InterfacePeroperties", OutputInterfaceProperties },
                { "@DeserializeActions", OutputDeserializeActions },
                { "@Deserialize", OutputDeserialize },
                { "@ToString", OutputToString },
                { "@ToJson", OutputToJson },
                { "@AppendJson", OutputAppendJson },
                { "@SetterInterface", OutputSetterInterface },
            };
        }
Beispiel #2
0
        public static void GenerateAll(GeneratorSetting setting)
        {
            if (!Directory.Exists(setting.SchemaDirUri.AbsolutePath))
            {
                throw new Exception(setting.SchemaDirUri.AbsolutePath + " does not exist.");
            }

            if (!Directory.Exists(setting.OutputDirUri.AbsolutePath))
            {
                Directory.CreateDirectory(setting.OutputDirUri.AbsolutePath);
            }

            Dictionary <string, Exception> exceptions = new Dictionary <string, Exception>();

            foreach (var path in Directory.GetFiles(setting.SchemaDirUri.AbsolutePath, Filter, SearchOption.AllDirectories))
            {
                var g = new Generator(path, setting);
                g.Generate();
                //try
                //{
                //    Generate(path, setting);
                //}
                //catch (Exception e)
                //{
                //    exceptions.Add(path, e);
                //}
            }

            if (exceptions.Count > 0)
            {
                if (setting.NotifyExceptionsFunc != null)
                {
                    setting.NotifyExceptionsFunc.Invoke(exceptions);
                }
                else
                {
                    throw new Exception(exceptions
                                        .Select(p => string.Format("[{0}] {1}", p.Key, p.Value.ToString()))
                                        .Aggregate((s1, s2) => string.Format("{0}\n{1}", s1, s2)));
                }
            }
        }