示例#1
0
        bool GenerateEXaml(string xamlFilePath, ModuleDefinition module, out IList <Exception> thrownExceptions)
        {
            thrownExceptions = null;

            LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Parsing Xaml");
            Stream xamlStream = File.Open(xamlFilePath, FileMode.Open);

            string className;

            if (!CecilExtensions.IsXaml(xamlStream, module, out className))
            {
                thrownExceptions.Add(new Exception($"{xamlFilePath} is not xaml format file"));
            }

            xamlStream.Seek(0, SeekOrigin.Begin);
            var typeDef = module.GetTypeDefinition(className);

            if (null == typeDef)
            {
                throw new Exception($"Can't find type \"{className}\" in assembly \"{module.Assembly.FullName}\"");
            }

            var rootnode = ParseXaml(xamlStream, typeDef);

            xamlStream.Close();

            if (rootnode == null)
            {
                LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}failed.");
                return(false);
            }
            LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}done.");

            hasCompiledXamlResources = true;

            LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Replacing {0}.InitializeComponent ()");
            Exception e;

            var visitorContext = new EXamlContext(typeDef, module, null);

            if (!TryCoreCompile(rootnode, visitorContext, out e))
            {
                LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}failed.");
                (thrownExceptions = thrownExceptions ?? new List <Exception>()).Add(e);
                if (e is XamlParseException xpe)
                {
                    LoggingHelper.LogError(null, null, null, xamlFilePath, xpe.XmlInfo.LineNumber, xpe.XmlInfo.LinePosition, 0, 0, xpe.Message, xpe.HelpLink, xpe.Source);
                }
                else if (e is XmlException xe)
                {
                    LoggingHelper.LogError(null, null, null, xamlFilePath, xe.LineNumber, xe.LinePosition, 0, 0, xe.Message, xe.HelpLink, xe.Source);
                }
                else
                {
                    LoggingHelper.LogError(null, null, null, xamlFilePath, 0, 0, 0, 0, e.Message, e.HelpLink, e.Source);
                }

                if (null != e.StackTrace)
                {
                    LoggingHelper.LogMessage(Low, e.StackTrace);
                }

                return(false);
            }
            else
            {
                var examlDir = outputRootPath + @"res/examl/";
                if (Directory.Exists(examlDir))
                {
                    Directory.CreateDirectory(examlDir);
                }

                var examlFilePath = examlDir + typeDef.FullName + ".examl";

                EXamlOperation.WriteOpertions(examlFilePath, visitorContext);
            }

            return(true);
        }
示例#2
0
        bool GenerateEXaml(TypeDefinition typeDef, EmbeddedResource resource, out IList <Exception> thrownExceptions)
        {
            thrownExceptions = null;

            ModuleDefinition module = typeDef.Module;

            CustomAttribute xamlFilePathAttr;
            var             xamlFilePath = typeDef.HasCustomAttributes && (xamlFilePathAttr = typeDef.CustomAttributes.FirstOrDefault(ca => ca.AttributeType.FullName == "Tizen.NUI.Xaml.XamlFilePathAttribute")) != null ?
                                           (string)xamlFilePathAttr.ConstructorArguments[0].Value :
                                           resource.Name;

            LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Parsing Xaml");
            var rootnode = ParseXaml(resource.GetResourceStream(), typeDef);

            if (rootnode == null)
            {
                LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}failed.");
                return(false);
            }
            LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}done.");

            hasCompiledXamlResources = true;

            LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Replacing {0}.InitializeComponent ()");
            Exception e;

            var embeddedResourceNameSpace = GetNameSpaceOfResource(resource);
            var visitorContext            = new EXamlContext(typeDef, typeDef.Module, embeddedResourceNameSpace);

            if (!TryCoreCompile(rootnode, visitorContext, out e))
            {
                LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}failed.");
                (thrownExceptions = thrownExceptions ?? new List <Exception>()).Add(e);
                if (e is XamlParseException xpe)
                {
                    LoggingHelper.LogError(null, null, null, xamlFilePath, xpe.XmlInfo.LineNumber, xpe.XmlInfo.LinePosition, 0, 0, xpe.Message, xpe.HelpLink, xpe.Source);
                }
                else if (e is XmlException xe)
                {
                    LoggingHelper.LogError(null, null, null, xamlFilePath, xe.LineNumber, xe.LinePosition, 0, 0, xe.Message, xe.HelpLink, xe.Source);
                }
                else
                {
                    LoggingHelper.LogError(null, null, null, xamlFilePath, 0, 0, 0, 0, e.Message, e.HelpLink, e.Source);
                }

                if (null != e.StackTrace)
                {
                    LoggingHelper.LogError(e.StackTrace);
                }

                return(false);
            }
            else
            {
                var examlDir = outputRootPath + @"res/examl/";
                if (Directory.Exists(examlDir))
                {
                    Directory.CreateDirectory(examlDir);
                }

                var examlFilePath = examlDir + typeDef.FullName + ".examl";

                EXamlOperation.WriteOpertions(examlFilePath, visitorContext);
            }

            return(true);
        }