Example #1
0
        /// <summary>
        /// Ensure every entity has an alias.
        /// </summary>
        /// <param name="configPaths">The config file paths.</param>
        /// <param name="aliases">Set that gets filled with the discovered alaises.</param>
        private static void CheckAliases(List <string> configPaths, HashSet <string> aliases)
        {
            // Process config files and get stream of entities
            IEnumerable <Entity> entities = XmlParser.ReadEntities(configPaths);
            var aliasResolver             = new EntityStreamAliasResolver(entities);

            foreach (Entity e in entities)
            {
                // Ensure that every entity has an alias
                if (e.Alias == null || string.IsNullOrEmpty(e.Alias.Value))
                {
                    string msg = string.Format("{0}: error E1: Entity does not specify alias.", e.LocationInfo);
                    Console.WriteLine(msg);
                }
                else
                {
                    aliases.Add(e.Alias.Namespace + ":" + e.Alias.Value);
                }
            }
        }
Example #2
0
        /// <summary>
        ///     Generates the template instances.
        /// </summary>
        public static int GenerateTemplateInstances(List <string> xmlFiles, List <string> templateFiles, string outputPath, string namespaceName)
        {
            IEnumerable <Entity> entities = XmlParser.ReadEntities(xmlFiles);

            /////
            // Construct the alias and schema resolver instances.
            /////
            IList <Entity> entityList = entities as IList <Entity> ?? entities.ToList( );

            Decorator.DecorateEntities(entityList);

            IAliasResolver aliasResolver  = new EntityStreamAliasResolver(entityList);
            var            schemaResolver = new SchemaResolver(entityList, aliasResolver);

            schemaResolver.Initialize( );

            /////
            // Set the required values into the static model class.
            /////
            SetTemplateParameters(namespaceName, schemaResolver, aliasResolver);

            /////
            // Create the transform engine.
            /////
            var engine = new Engine( );

            var host = new TransformHost( );

            /////
            // Method return code.
            /////
            int returnCode = 0;

            /////
            // Cycle through the template files.
            /////
            foreach (string templateFile in templateFiles)
            {
                try
                {
                    var fi = new FileInfo(templateFile);

                    host.TemplateFileValue = fi.Name;

                    if (templateFile.Contains("Combined"))
                    {
                        AcceptAnyTypePrefix();

                        GenerateResultFile(outputPath, engine, host, templateFile, "");
                    }
                    else
                    {
                        ResetTypePrefix();

                        while (MoveToNextTypePrefix())
                        {
                            string outputSuffix = "." + CurrentTypePrefix().ToString().ToUpperInvariant();
                            GenerateResultFile(outputPath, engine, host, templateFile, outputSuffix);
                        }
                    }
                }
                catch (Exception exc)
                {
                    Console.WriteLine("Failed to generate instance for template '{0}'. Exception: {1}", templateFile, exc.Message);

                    returnCode = 1;
                }
            }

            return(returnCode);
        }