Example #1
0
 public static ViewRegistry GetInstance(IGeneratorConfiguration configuration)
 {
     if (_viewRegistry == null)
     {
         _viewRegistry = new ViewRegistry(configuration);
     }
     return(_viewRegistry);
 }
Example #2
0
        public void AddSchemas(IEnumerable <SchemaData> schemas)
        {
            currentViewModel = null;
            List <SchemaData> convertibleSchemas = new List <SchemaData>();

            convertibleSchemas.AddRange(schemas);

            int nrTries = 0;

            while (convertibleSchemas.Count > 0 && nrTries++ < MaxTries)
            {
                _log.DebugFormat("trying to convert {0} schemas to viewmodel definitions, starting parsing round #{1}", convertibleSchemas.Count, nrTries);
                List <SchemaData> extraSchemas = new List <SchemaData>();
                foreach (var schema in convertibleSchemas)
                {
                    _log.Debug("starting converting schema " + schema.Title);
                    ConvertSchema(schema);
                }
                convertibleSchemas = convertibleSchemas.Where(a => ViewModels.Any(b => b.TcmUri == a.Id && b.HasUnresolvedProperties)).ToList();
                if (extraSchemas.Count > 0)
                {
                    _log.DebugFormat("adding {0} extra schemas (found during property parsing)", extraSchemas.Count);
                    convertibleSchemas.AddRange(extraSchemas);
                }
                _log.DebugFormat("after parsing round #{0} there are still {1} schemas to be converted", nrTries, convertibleSchemas.Count);
            }
            // after adding all schemas, we need to tell the ViewRegistry to add all component templates linked to the current set of schemas
            // this will trigger the ModelRegistry to create merged models in case a CT is linked to multiple schemas
            UsingItemsFilterData filter = new UsingItemsFilterData()
            {
                ItemTypes = new[] { ItemType.ComponentTemplate }
            };

            foreach (var schema in convertibleSchemas.Where(s => s.Purpose == SchemaPurpose.Component))
            {
                var associatedCTs = Client.GetList(schema.Id, filter).Cast <ComponentTemplateData>();
                associatedCTs?.Select(s => ViewRegistry.GetViewModelDefinition(s.Id)); // we don't care about the return value but we want this
            }
        }