コード例 #1
0
        public override bool Execute()
        {
            if (AttachDebugger)
            {
                System.Diagnostics.Debugger.Launch();
            }

            if (XamlApplications.Length > 1)
            {
                Log.LogError("More than one file has an ApplicationDefinition build action");

                foreach (ITaskItem xamlApplication in XamlApplications)
                {
                    Log.LogWarning(String.Empty, String.Empty, String.Empty, xamlApplication.GetRelativePath(), 0, 0, 0, 0, "This file has a GranularApplicationDefinition build action");
                }

                GeneratedCodeFiles = new ITaskItem[0];
                return(false);
            }

            List <ITaskItem> generatedCodeFiles = new List <ITaskItem>();

            ReflectionTypeParser reflectionTypeParser = new ReflectionTypeParser(ReferenceAssemblies.Select(referenceAssembly => referenceAssembly.GetMetadata("FullPath")).ToArray());

            ITypeParser typeParser = new MarkupExtensionTypeParser(reflectionTypeParser);

            if (XamlApplications.Length == 1)
            {
                try
                {
                    ITaskItem generatedCodeFile = GenerateCodeFile(XamlApplications[0], typeParser, XamlItemType.XamlApplicationDefinition);
                    if (generatedCodeFile != null)
                    {
                        generatedCodeFiles.Add(generatedCodeFile);
                    }
                }
                catch (Exception e)
                {
                    Log.LogError(String.Empty, String.Empty, String.Empty, XamlApplications[0].GetRelativePath(), 0, 0, 0, 0, e.Message);
                    return(false);
                }
            }

            foreach (ITaskItem xamlPage in XamlPages)
            {
                try
                {
                    ITaskItem generatedCodeFile = GenerateCodeFile(xamlPage, typeParser, XamlItemType.XamlPage);
                    if (generatedCodeFile != null)
                    {
                        generatedCodeFiles.Add(generatedCodeFile);
                    }
                }
                catch (Exception e)
                {
                    Log.LogError(String.Empty, String.Empty, String.Empty, xamlPage.GetRelativePath(), 0, 0, 0, 0, e.Message);
                    return(false);
                }
            }

            GeneratedCodeFiles = generatedCodeFiles.ToArray();
            return(true);
        }
コード例 #2
0
ファイル: CompileXaml.cs プロジェクト: portalninja/Granular
        public override bool Execute()
        {
            if (XamlApplications.Length > 1)
            {
                Log.LogError("More than one file has a GranularApplicationDefinition build action");

                foreach (ITaskItem xamlApplication in XamlApplications)
                {
                    Log.LogWarning(String.Empty, String.Empty, String.Empty, xamlApplication.GetRelativePath(), 0, 0, 0, 0, "This file has a GranularApplicationDefinition build action");
                }

                GeneratedCodeFiles = new ITaskItem[0];
                return(false);
            }

            AppDomain appDomain = AppDomain.CreateDomain("CompileXaml");

            try
            {
                List <ITaskItem> generatedCodeFiles = new List <ITaskItem>();

                ReflectionTypeParser reflectionTypeParser = (ReflectionTypeParser)appDomain.CreateInstanceFromAndUnwrap(typeof(ReflectionTypeParser).Assembly.Location, typeof(ReflectionTypeParser).FullName);
                reflectionTypeParser.LoadAssemblies(ReferenceAssemblies.Select(referenceAssembly => referenceAssembly.GetMetadata("FullPath")).ToArray());

                ITypeParser typeParser = new MarkupExtensionTypeParser(new TypeParserCollection(new KnownTypesParser(), reflectionTypeParser));

                if (XamlApplications.Length == 1)
                {
                    try
                    {
                        ITaskItem generatedCodeFile = GenerateCodeFile(XamlApplications[0], typeParser, XamlItemType.XamlApplicationDefinition);
                        if (generatedCodeFile != null)
                        {
                            generatedCodeFiles.Add(generatedCodeFile);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.LogError(String.Empty, String.Empty, String.Empty, XamlApplications[0].GetRelativePath(), 0, 0, 0, 0, e.Message);
                        return(false);
                    }
                }

                foreach (ITaskItem xamlPage in XamlPages)
                {
                    try
                    {
                        ITaskItem generatedCodeFile = GenerateCodeFile(xamlPage, typeParser, XamlItemType.XamlPage);
                        if (generatedCodeFile != null)
                        {
                            generatedCodeFiles.Add(generatedCodeFile);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.LogError(String.Empty, String.Empty, String.Empty, xamlPage.GetRelativePath(), 0, 0, 0, 0, e.Message);
                        return(false);
                    }
                }

                GeneratedCodeFiles = generatedCodeFiles.ToArray();
                return(true);
            }
            finally
            {
                AppDomain.Unload(appDomain);
            }
        }