Beispiel #1
0
        //
        // Handle the SourceFileResolve Event from MarkupCompiler.
        // It tries to GetResolvedFilePath for the new SourceDir and new RelativePath.
        //
        private void OnSourceFileResolve(Object sender, SourceFileResolveEventArgs e)
        {
            SourceFileInfo sourceFileInfo = e.SourceFileInfo;
            string         newSourceDir   = _sourceDir;
            string         newRelativeFilePath;

            if (String.IsNullOrEmpty(sourceFileInfo.OriginalFilePath))
            {
                newRelativeFilePath = sourceFileInfo.OriginalFilePath;
            }
            else
            {
                newRelativeFilePath = GetResolvedFilePath(sourceFileInfo.OriginalFilePath, ref newSourceDir);

                _taskLogger.LogMessageFromResources(MessageImportance.Low, SRID.FileResolved, sourceFileInfo.OriginalFilePath, newRelativeFilePath, newSourceDir);
            }

            if (sourceFileInfo.IsXamlFile)
            {
                //
                // For Xaml Source file, we need to remove the .xaml extension part.
                //
                int fileExtIndex = newRelativeFilePath.LastIndexOf(MarkupCompiler.DOT, StringComparison.Ordinal);
                newRelativeFilePath = newRelativeFilePath.Substring(0, fileExtIndex);
            }

            //
            // Update the SourcePath and RelativeSourceFilePath property in SourceFileInfo object.
            //
            sourceFileInfo.SourcePath             = newSourceDir;
            sourceFileInfo.RelativeSourceFilePath = newRelativeFilePath;

            // Put the stream here.
            sourceFileInfo.Stream = TaskFileService.GetContent(sourceFileInfo.OriginalFilePath);
        }
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        /// <summary>
        /// Execute method in Task
        /// </summary>
        /// <returns></returns>
        public override bool Execute()
        {
            TaskHelper.DisplayLogo(Log, SR.Get(SRID.MarkupCompilePass2Task));

            //
            // Create the TaskFileService instance here
            //
            _taskFileService = new TaskFileService(this) as ITaskFileService;

            try
            {
                IsSupportedOutputType(OutputType);

                Log.LogMessageFromResources(MessageImportance.Low, SRID.CurrentDirectory, SourceDir);

                // If wrong files are set to some properties, the task
                // should stop here immediatelly.

                if (_nErrors > 0)
                {
                    Log.LogErrorWithCodeFromResources(SRID.WrongPropertySetting);
                }
                else
                {
                    bool hasLocalXamlFiles;

                    hasLocalXamlFiles = InitLocalXamlCache();

                    if (!hasLocalXamlFiles)
                    {
                        // There is no valid input xaml files.
                        // No need to do further work.
                        // stop here.
                        return true;
                    }

                    // create output directory
                    if (!Directory.Exists(OutputPath))
                    {
                        Directory.CreateDirectory(OutputPath);
                    }

                    // Call the Markup Compiler to do the real compiling work

                    ArrayList referenceList;
                    FileUnit localApplicationFile;
                    FileUnit[] localXamlPageFileList;

                    // Prepare the appropriate file lists required by MarkupCompiler.
                    PrepareForMarkupCompilation(out localApplicationFile, out localXamlPageFileList, out referenceList);

                    // Do the real Pass2 compilation work here.
                    DoLocalReferenceMarkupCompilation(localApplicationFile, localXamlPageFileList, referenceList);

                    // Generate the required output items.
                    GenerateOutputItems();

                    Log.LogMessageFromResources(MessageImportance.Low, SRID.CompilationDone);
                }
            }
#pragma warning disable 6500
            catch (Exception e)
            {
                string message;
                string errorId;

                errorId = Log.ExtractMessageCode(e.Message, out message);

                if (String.IsNullOrEmpty(errorId))
                {
                    errorId = UnknownErrorID;
                    message = SR.Get(SRID.UnknownBuildError, message);
                }

                Log.LogError(null, errorId, null, null, 0, 0, 0, 0, message, null);

                _nErrors++;

            }
            catch // Non-CLS compliant errors
            {
                Log.LogErrorWithCodeFromResources(SRID.NonClsError);

                _nErrors++;
            }
#pragma warning restore 6500

            CleanupReferenceAssemblyCacheForTargetAssembly();

            if (_nErrors > 0)
            {
                // When error counter is changed, the appropriate error message should have
                // been reported.

                //
                // The task should cleanup all the cache files so that all the xaml files will
                // get chance to recompile next time.
                //

                string stateFileName = OutputPath + AssemblyName +
                                      (TaskFileService.IsRealBuild? SharedStrings.StateFile : SharedStrings.IntellisenseStateFile);

                string localTypeCacheFileName = OutputPath + AssemblyName +
                                      (TaskFileService.IsRealBuild? SharedStrings.LocalTypeCacheFile : SharedStrings.IntellisenseLocalTypeCacheFile);

                if (TaskFileService.Exists(stateFileName))
                {
                    TaskFileService.Delete(stateFileName);
                }

                if (TaskFileService.Exists(localTypeCacheFileName))
                {
                    TaskFileService.Delete(localTypeCacheFileName);
                }

                return false;
            }
            else
            {
                // Mark Pass2 as completed in the cache
                string stateFileName = OutputPath + AssemblyName +
                      (TaskFileService.IsRealBuild ? SharedStrings.StateFile : SharedStrings.IntellisenseStateFile);
                if (TaskFileService.Exists(stateFileName))
                {
                    CompilerState compilerState = new CompilerState(stateFileName, TaskFileService);
                    compilerState.LoadStateInformation();
                    if (compilerState.Pass2Required)
                    {
                        compilerState.Pass2Required = false;
                        compilerState.SaveStateInformation();
                    }
                }

                Log.LogMessageFromResources(SRID.CompileSucceed_Pass2);
                return true;
            }
        }
Beispiel #3
0
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        /// <summary>
        /// Execute method in Task
        /// </summary>
        /// <returns></returns>
        public override bool Execute()
        {

            //CASRemoval:(new PermissionSet(PermissionState.Unrestricted)).Assert();

            TaskHelper.DisplayLogo(Log, SR.Get(SRID.MarkupCompilePass1Task));

            bool bSuccess = true;

            try
            {

                //
                // Create the TaskFileService instance here
                //

                _taskFileService = new TaskFileService(this) as ITaskFileService;

                _compilerState = new CompilerState(
                    OutputPath + AssemblyName + (TaskFileService.IsRealBuild? SharedStrings.StateFile : SharedStrings.IntellisenseStateFile),
                    TaskFileService);

                _compilerLocalRefCache = new CompilerLocalReference(
                    OutputPath + AssemblyName + (TaskFileService.IsRealBuild? SharedStrings.LocalTypeCacheFile : SharedStrings.IntellisenseLocalTypeCacheFile),
                    TaskFileService);

                if ((PageMarkup == null || PageMarkup.Length == 0) &&
                    (ApplicationMarkup == null || ApplicationMarkup.Length == 0))
                {
                    // Don't need to do further work.
                    // stop here.
                    CleanupCacheFiles();
                    return true;
                }

                VerifyInputs();

                Log.LogMessageFromResources(MessageImportance.Low, SRID.CurrentDirectory, SourceDir);

                // If wrong files are set to some properties, the task
                // should stop here immediatelly.

                if (_nErrors > 0)
                {
                    Log.LogErrorWithCodeFromResources(SRID.WrongPropertySetting);
                }
                else
                {

                    // create output directory
                    if (!Directory.Exists(OutputPath))
                    {
                        Directory.CreateDirectory(OutputPath);
                    }

                    // Analyze project inputs to detect which xaml files require to recompile.
                    AnalyzeInputsAndSetting();

                    Log.LogMessageFromResources(MessageImportance.Low, SRID.AnalysisResult, CompilerAnalyzer.AnalyzeResult);

                    if (!SkipMarkupCompilation)
                    {

                        if (CompilerAnalyzer.RecompileMarkupPages != null)
                        {
                            for (int i = 0; i < CompilerAnalyzer.RecompileMarkupPages.Length; i++)
                            {

                                Log.LogMessageFromResources(MessageImportance.Low, SRID.RecompiledXaml, CompilerAnalyzer.RecompileMarkupPages[i]);
                            }
                        }

                        // If recompile is required, CompilerAnalyzer contains all the files which need to recompile.

                        // Cleanup baml files and code files generated in previous build.
                        if (TaskFileService.IsRealBuild)
                        {
                            CleanupGeneratedFiles();
                        }

                        // Call the Markup Compiler to do the real compiling work
                        DoMarkupCompilation();
                    }


                    // Generate the required output items.
                    GenerateOutputItems();

                    Log.LogMessageFromResources(MessageImportance.Low, SRID.CompilationDone);
                }

            }
#pragma warning disable 6500
            catch (Exception e)
            {
                string message;
                string errorId;

                errorId = Log.ExtractMessageCode(e.Message, out message);

                if (String.IsNullOrEmpty(errorId))
                {
                    errorId = UnknownErrorID;
                    message = SR.Get(SRID.UnknownBuildError, message);
                }

                Log.LogError(null, errorId, null, null, 0, 0, 0, 0, message, null);

                _nErrors++;
            }
            catch // Non-CLS compliant errors
            {
                Log.LogErrorWithCodeFromResources(SRID.NonClsError);
                _nErrors++;
            }
#pragma warning restore 6500

            if (_nErrors > 0)
            {
                // When error counter is changed, the appropriate error message should have
                // been reported, simply return false here.
                bSuccess = false;
                CleanupCacheFiles();
            }
            else
            {
                Log.LogMessageFromResources(MessageImportance.Low, SRID.CompileSucceed_Pass1);
            }

            return bSuccess;
        }