Esempio n. 1
0
 public ConnectionsSectionReader(IXmlLoadLogger logger,
                                 IConditionParser conditionParser,
                                 IComponentPointParser componentPointParser)
 {
     this.logger               = logger;
     this.conditionParser      = conditionParser;
     this.componentPointParser = componentPointParser;
 }
Esempio n. 2
0
 public TextCommandWithDefinitionsReader(
     IXmlLoadLogger logger,
     IComponentPointParser componentPointParser,
     ISectionRegistry sectionRegistry)
 {
     this.logger = logger;
     this.componentPointParser = componentPointParser;
     definitionsSection        = sectionRegistry.GetSection <DefinitionsSection>();
 }
Esempio n. 3
0
        public static bool GetAttribute(this XElement element, string name, IXmlLoadLogger logger, out XAttribute attr)
        {
            attr = element.Attribute(name);
            if (attr == null)
            {
                logger.LogError(element, $"Missing attribute '{name}' for <{element.Name.LocalName}> tag");
                return(false);
            }

            return(true);
        }
Esempio n. 4
0
        public static bool GetAttributeValue(this XElement element, string name, IXmlLoadLogger logger, out string value)
        {
            if (element.GetAttribute(name, logger, out var attribute))
            {
                value = attribute.Value;
                return(true);
            }

            value = null;
            return(false);
        }
Esempio n. 5
0
 public RenderSectionReader(
     IXmlLoadLogger logger,
     IConditionParser conditionParser,
     IComponentPointParser componentPointParser,
     IAutoRotateOptionsReader autoRotateOptionsReader,
     IIndex <string, IRenderCommandReader> renderCommandReaders)
 {
     this.logger                  = logger;
     this.conditionParser         = conditionParser;
     this.componentPointParser    = componentPointParser;
     this.autoRotateOptionsReader = autoRotateOptionsReader;
     this.renderCommandReaders    = renderCommandReaders;
 }
Esempio n. 6
0
 public RenderSectionWithDefinitionsReader(IXmlLoadLogger logger,
                                           IConditionParser conditionParser,
                                           IComponentPointParser componentPointParser,
                                           IComponentPointTemplateParser componentPointTemplateParser,
                                           ISectionRegistry sectionRegistry)
     : base(logger, conditionParser, componentPointParser)
 {
     this.logger                       = logger;
     this.conditionParser              = conditionParser;
     this.componentPointParser         = componentPointParser;
     this.componentPointTemplateParser = componentPointTemplateParser;
     definitionsSection                = sectionRegistry.GetSection <DefinitionsSection>();
     availableDefinitions              = definitionsSection?.Definitions.Select(x => x.Key).ToHashSet() ?? new HashSet <string>();
 }
Esempio n. 7
0
        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);
            }
        }
Esempio n. 8
0
 public RectCommandReader(IXmlLoadLogger logger, IComponentPointParser componentPointParser)
 {
     this.logger = logger;
     this.componentPointParser = componentPointParser;
 }
Esempio n. 9
0
 public static bool Parse(this IConditionParser parser, XAttribute conditionsAttribute, ComponentDescription description, IXmlLoadLogger logger, out IConditionTreeItem value)
 {
     try
     {
         value = parser.Parse(description, conditionsAttribute.Value);
         return(true);
     }
     catch (ConditionFormatException ex)
     {
         IXmlLineInfo line     = conditionsAttribute;
         int          startCol = line.LinePosition + conditionsAttribute.Name.LocalName.Length + 2 + ex.PositionStart;
         var          position = new FileRange(line.LineNumber, startCol, line.LineNumber, startCol + ex.Length);
         logger.Log(LogLevel.Error, position, ex.Message, null);
         value = null;
         return(false);
     }
 }
 public ComponentPointTemplateParser([KeyFilter("default")] IComponentPointParser baseParser, IFeatureSwitcher featureSwitcher, IXmlLoadLogger logger)
 {
     this.baseParser      = baseParser;
     this.featureSwitcher = featureSwitcher;
     this.logger          = logger;
 }
 public DefinitionsSectionReader(IXmlLoadLogger logger, IConditionParser conditionParser, ISectionRegistry sectionRegistry)
 {
     this.logger          = logger;
     this.conditionParser = conditionParser;
     this.sectionRegistry = sectionRegistry;
 }
 public DeclarationSectionReader(IXmlLoadLogger logger, FeatureSwitcher featureSwitcher, IConditionParser conditionParser)
 {
     this.logger          = logger;
     this.featureSwitcher = featureSwitcher;
     this.conditionParser = conditionParser;
 }
Esempio n. 13
0
 public static void Log(this IXmlLoadLogger logger, LogLevel level, XElement element, string message)
 {
     logger.Log(level, element.GetFileRange(), message, null);
 }
 public ComponentPointWithDefinitionParser(IXmlLoadLogger logger, ISectionRegistry sectionRegistry)
     : base(logger)
 {
     this.logger        = logger;
     definitionsSection = sectionRegistry.GetSection <DefinitionsSection>();
 }
Esempio n. 15
0
 public ErrorCheckingLogger(IXmlLoadLogger underlying)
 {
     this.underlying = underlying;
 }
Esempio n. 16
0
 public static void Log(this IXmlLoadLogger logger, LogLevel level, XAttribute attribute, string message)
 {
     logger.Log(level, attribute.GetFileRange(), message, null);
 }
 public ComponentPointParser(IXmlLoadLogger logger)
 {
     _logger = logger;
 }
Esempio n. 18
0
        public static IEnumerable <T> FlattenRoot <T>(this IRootFlattenable <T> rootFlattenable, IXmlLoadLogger logger)
        {
            if (rootFlattenable.AutoRotate == AutoRotateType.Off)
            {
                var autoRotateContext = new AutoRotateContext(false, FlipType.None, FlipState.None);
                var context           = new FlattenContext(logger, ConditionTree.Empty, autoRotateContext);
                return(rootFlattenable.Flatten(context));
            }
            else
            {
                var horizontalAutoRotateContext = new AutoRotateContext(false, FlipType.None, FlipState.None);
                var horizontalConditions        = new ConditionTreeLeaf(ConditionType.State, "horizontal", ConditionComparison.Equal, new PropertyValue(true));
                var horizontalContext           = new FlattenContext(logger, horizontalConditions, horizontalAutoRotateContext);

                var flipType = FlipType.None;
                if ((rootFlattenable.AutoRotateFlip & FlipState.Primary) == FlipState.Primary)
                {
                    flipType |= FlipType.Vertical;
                }
                if ((rootFlattenable.AutoRotateFlip & FlipState.Secondary) == FlipState.Secondary)
                {
                    flipType |= FlipType.Horizontal;
                }

                var verticalAutoRotateContext = new AutoRotateContext(true, flipType, rootFlattenable.AutoRotateFlip);
                var verticalConditions        = new ConditionTreeLeaf(ConditionType.State, "horizontal", ConditionComparison.Equal, new PropertyValue(false));
                var verticalContext           = new FlattenContext(logger, verticalConditions, verticalAutoRotateContext);

                return(rootFlattenable.Flatten(horizontalContext).Concat(rootFlattenable.Flatten(verticalContext)));
            }
        }
Esempio n. 19
0
 public static void LogError(this IXmlLoadLogger logger, XAttribute attribute, string message)
 {
     logger.Log(LogLevel.Error, attribute, message);
 }
Esempio n. 20
0
 public static void LogWarning(this IXmlLoadLogger logger, XAttribute attribute, string message)
 {
     logger.Log(LogLevel.Warning, attribute, message);
 }
Esempio n. 21
0
 public static void LogError(this IXmlLoadLogger logger, XElement element, string message)
 {
     logger.Log(LogLevel.Error, element, message);
 }
Esempio n. 22
0
 public static void LogWarning(this IXmlLoadLogger logger, XElement element, string message)
 {
     logger.Log(LogLevel.Warning, element, message);
 }
Esempio n. 23
0
 public AutoRotateOptionsReader(IXmlLoadLogger logger)
 {
     this.logger = logger;
 }
Esempio n. 24
0
 public FlattenContext(IXmlLoadLogger logger, IConditionTreeItem ancestorConditions, AutoRotateContext autoRotate)
 {
     Logger             = logger;
     AncestorConditions = ancestorConditions;
     AutoRotate         = autoRotate;
 }