Beispiel #1
0
        static void AddDependency(string assetPath, XElement templateNode, List <string> dependencies)
        {
            bool   hasSrc = false;
            string src    = null;

            foreach (var xAttribute in templateNode.Attributes())
            {
                switch (xAttribute.Name.LocalName)
                {
                case k_GenericSrcAttr:
                    hasSrc = true;
                    src    = xAttribute.Value;
                    break;
                }
            }

            if (hasSrc)
            {
                string errorMessage, projectRelativePath;

                URIValidationResult result = URIHelpers.ValidAssetURL(assetPath, src, out errorMessage, out projectRelativePath);

                if (result == URIValidationResult.OK)
                {
                    dependencies.Add(projectRelativePath);
                }
            }
        }
Beispiel #2
0
        static void AddDependency(string assetPath, XElement templateNode, List <string> dependencies)
        {
            bool   hasSrc = false;
            string src    = null;

            foreach (var xAttribute in templateNode.Attributes())
            {
                switch (xAttribute.Name.LocalName)
                {
                case k_GenericSrcAttr:
                    hasSrc = true;
                    src    = xAttribute.Value;
                    break;
                }
            }

            if (!hasSrc)
            {
                return;
            }

            URIValidationResult result = URIHelpers.ValidAssetURL(assetPath, src, out string errorMessage, out string projectRelativePath);

            if (result != URIValidationResult.OK)
            {
                return;
            }

            switch (templateNode.Name.LocalName)
            {
            case k_TemplateNode:
                var templateDependencies = new HashSet <string>();
                templateDependencies.Add(assetPath);

                if (!HasTemplateCircularDependencies(projectRelativePath, templateDependencies))
                {
                    dependencies.Add(projectRelativePath);
                }
                else
                {
                    logger.LogError(ImportErrorType.Semantic, ImportErrorCode.TemplateHasCircularDependency, projectRelativePath, Error.Level.Warning, templateNode);
                }
                break;

            default:
                dependencies.Add(projectRelativePath);
                break;
            }
        }
        static void AddAssetDependency(string assetPath, string src, List <string> dependencies)
        {
            if (string.IsNullOrEmpty(src))
            {
                return;
            }

            var result = URIHelpers.ValidAssetURL(assetPath, src, out var _, out var projectRelativePath);

            if (result != URIValidationResult.OK)
            {
                return;
            }

            dependencies.Add(projectRelativePath);
        }
Beispiel #4
0
        void LoadStyleReferenceNode(VisualElementAsset vea, XElement styleElt, VisualTreeAsset vta)
        {
            XAttribute pathAttr = styleElt.Attribute(k_GenericPathAttr);
            bool       hasPath  = pathAttr != null && !String.IsNullOrEmpty(pathAttr.Value);

            XAttribute srcAttr = styleElt.Attribute(k_GenericSrcAttr);
            bool       hasSrc  = srcAttr != null && !String.IsNullOrEmpty(srcAttr.Value);

            if (hasPath == hasSrc)
            {
                LogWarning(vta,
                           ImportErrorType.Semantic,
                           hasPath ? ImportErrorCode.StyleReferenceSrcAndPathBothSpecified : ImportErrorCode.StyleReferenceEmptyOrMissingPathOrSrcAttr,
                           null,
                           styleElt);
                return;
            }

            if (hasPath)
            {
                vea.stylesheetPaths.Add(pathAttr.Value);
            }
            else if (hasSrc)
            {
                string errorMessage, projectRelativePath;

                URIValidationResult result = URIHelpers.ValidAssetURL(assetPath, srcAttr.Value, out errorMessage, out projectRelativePath);

                if (result != URIValidationResult.OK)
                {
                    LogError(vta, ImportErrorType.Semantic, ConvertErrorCode(result), errorMessage, styleElt);
                }
                else
                {
                    Object asset = DeclareDependencyAndLoad(projectRelativePath);

                    if (asset is StyleSheet)
                    {
                        vea.stylesheets.Add(asset as StyleSheet);
                    }
                    else
                    {
                        LogError(vta, ImportErrorType.Semantic, ImportErrorCode.ReferenceInvalidAssetType, projectRelativePath, styleElt);
                    }
                }
            }
        }
Beispiel #5
0
        internal static bool HasTemplateCircularDependencies(XElement templateElement, HashSet <string> templateDependencies, string rootAssetPath)
        {
            bool hasCircularDependencies = false;

            var elements = templateElement.Elements();

            foreach (var child in elements)
            {
                switch (child.Name.LocalName)
                {
                case k_TemplateNode:
                    var attributes = child.Attributes();

                    foreach (var xAttribute in attributes)
                    {
                        if (xAttribute.Name.LocalName != k_GenericSrcAttr)
                        {
                            continue;
                        }

                        var src = xAttribute.Value;
                        URIValidationResult result = URIHelpers.ValidAssetURL(rootAssetPath, src, out string errorMessage, out string projectRelativePath);
                        hasCircularDependencies = HasTemplateCircularDependencies(projectRelativePath, templateDependencies);

                        if (!hasCircularDependencies)
                        {
                            templateDependencies.Remove(projectRelativePath);
                        }
                    }

                    break;

                default:
                    hasCircularDependencies = HasTemplateCircularDependencies(child, templateDependencies, rootAssetPath);
                    break;
                }

                if (hasCircularDependencies)
                {
                    break;
                }
            }

            return(hasCircularDependencies);
        }
Beispiel #6
0
        void LoadTemplateNode(VisualTreeAsset vta, XElement elt, XElement child)
        {
            bool   hasPath = false;
            bool   hasSrc  = false;
            string name    = null;
            string path    = null;
            string src     = null;

            foreach (var xAttribute in child.Attributes())
            {
                switch (xAttribute.Name.LocalName)
                {
                case k_GenericPathAttr:
                    hasPath = true;
                    path    = xAttribute.Value;
                    break;

                case k_GenericSrcAttr:
                    hasSrc = true;
                    src    = xAttribute.Value;
                    break;

                case k_TemplateNameAttr:
                    name = xAttribute.Value;
                    if (String.IsNullOrEmpty(name))
                    {
                        logger.LogError(ImportErrorType.Semantic,
                                        ImportErrorCode.TemplateHasEmptyName,
                                        child,
                                        Error.Level.Fatal,
                                        child
                                        );
                    }
                    break;

                default:
                    logger.LogError(ImportErrorType.Semantic,
                                    ImportErrorCode.UnknownAttribute,
                                    xAttribute.Name.LocalName,
                                    Error.Level.Fatal,
                                    child
                                    );
                    break;
                }
            }

            if (hasPath == hasSrc)
            {
                logger.LogError(ImportErrorType.Semantic,
                                hasPath ? ImportErrorCode.TemplateSrcAndPathBothSpecified : ImportErrorCode.TemplateMissingPathOrSrcAttribute,
                                null,
                                Error.Level.Fatal,
                                elt
                                );
                return;
            }

            if (String.IsNullOrEmpty(name))
            {
                name = Path.GetFileNameWithoutExtension(path);
            }

            if (vta.TemplateExists(name))
            {
                logger.LogError(ImportErrorType.Semantic,
                                ImportErrorCode.DuplicateTemplateName,
                                name,
                                Error.Level.Fatal,
                                elt
                                );
                return;
            }

            if (hasPath)
            {
                vta.RegisterTemplate(name, path);
            }
            else if (hasSrc)
            {
                string errorMessage, projectRelativePath;

                URIValidationResult result = URIHelpers.ValidAssetURL(assetPath, src, out errorMessage, out projectRelativePath);

                if (result != URIValidationResult.OK)
                {
                    logger.LogError(ImportErrorType.Semantic, ConvertErrorCode(result), errorMessage, Error.Level.Fatal, elt);
                }
                else
                {
                    Object asset = DeclareDependencyAndLoad(projectRelativePath);

                    if (asset is VisualTreeAsset)
                    {
                        vta.RegisterTemplate(name, asset as VisualTreeAsset);
                    }
                    else
                    {
                        logger.LogError(ImportErrorType.Semantic, ImportErrorCode.ReferenceInvalidAssetType, projectRelativePath, Error.Level.Fatal, elt);
                    }
                }
            }
        }