public void SaveData(SectionRegistry sectionRegistry) { if (sectionRegistry == null) { throw new ArgumentException("Empty"); } fileOperation.Save(sectionRegistry); }
internal SubSectionInfo(PropertyInfo propertyInfo) { var subSectionAttribute = propertyInfo.GetCustomAttribute <SubSectionAttribute>(); Type genericType = null; for (var type = propertyInfo.PropertyType; type != null; type = type.BaseType) { if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List <>)) { genericType = type.GetGenericArguments()[0]; break; } } if (genericType != null) { IsListType = true; IsSectionType = typeof(ISection).IsAssignableFrom(genericType); if (IsSectionType) { SectionInfo = SectionRegistry.GetOrRegisterSectionInfo(genericType); } else { SectionInfo = SectionRegistry.GetOrRegisterSectionInfo(subSectionAttribute.SectionType); } } else { IsSectionType = typeof(ISection).IsAssignableFrom(propertyInfo.PropertyType); if (IsSectionType) { SectionInfo = SectionRegistry.GetOrRegisterSectionInfo(propertyInfo.PropertyType); } else { SectionInfo = SectionRegistry.GetOrRegisterSectionInfo(subSectionAttribute.SectionType); } } PropertyInfo = propertyInfo; Priority = subSectionAttribute.Priority; }
void IComponent.Attach(RenderHandle renderHandle) { _registry = renderHandle.Dispatcher.SectionRegistry; }
public bool Load(Stream stream, IXmlLoadLogger logger, out ComponentDescription description) { description = new ComponentDescription(); if (stream is FileStream fs) { description.Source = new ComponentDescriptionSource(fs.Name); } var errorCheckingLogger = new ErrorCheckingLogger(logger); var sectionRegistry = new SectionRegistry(); try { var root = XElement.Load(stream, LoadOptions.SetLineInfo); ReadHeader(root, description); var featureSwitcher = new FeatureSwitcher(); // Read declaration var declaration = root.Element(ComponentNamespace + "declaration"); if (declaration == null) { logger.LogError(root, "Missing required element: 'declaration'"); return(false); } var declarationReader = container.Value.ResolveNamed <IXmlSectionReader>(declaration.Name.NamespaceName + ":" + declaration.Name.LocalName, new TypedParameter(typeof(IXmlLoadLogger), errorCheckingLogger), new TypedParameter(typeof(FeatureSwitcher), featureSwitcher)); declarationReader.ReadSection(declaration, description); var descriptionInstance = description; var scope = container.Value.BeginLifetimeScope(configure => { configure.RegisterInstance(errorCheckingLogger).As <IXmlLoadLogger>(); configure.RegisterInstance(sectionRegistry).As <ISectionRegistry>(); configure.RegisterInstance(descriptionInstance); configure.RegisterInstance(featureSwitcher).As <IFeatureSwitcher>(); foreach (var feature in features) { if (featureSwitcher.IsFeatureEnabled(feature.Key, out var featureSourceElement)) { logger.Log(LogLevel.Information, featureSourceElement, $"Feature enabled: {feature.Key}"); feature.Value(configure); } } }); try { // Read remaining elements foreach (var element in root.Elements().Except(new[] { declaration })) { var sectionReader = scope.ResolveOptionalNamed <IXmlSectionReader>(element.Name.NamespaceName + ":" + element.Name.LocalName); sectionReader?.ReadSection(element, description); } return(!errorCheckingLogger.HasErrors); } finally { scope.Dispose(); } } catch (Exception ex) { logger.Log(LogLevel.Error, new FileRange(1, 1, 1, 2), ex.Message, ex); return(false); } }