Example #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);
        }
        //
        // Return FileInfo for the given source file.
        //
        private SourceFileInfo OnSourceFileResolve(FileUnit file)
        {
            SourceFileInfo sourceFileInfo;

            if (SourceFileResolve != null)
            {
                //
                // If SourceFileResolve event handler is registered,  the handler
                // is responsible for generating the SourceFileInfo.
                // This is for MSBUILD tasks.
                //
                SourceFileResolveEventArgs scea = new SourceFileResolveEventArgs(file);

                SourceFileResolve(this, scea);

                sourceFileInfo = scea.SourceFileInfo;
            }
            else
            {
                // If SourceFileResolve event handler is not registered,  generate
                // the default SourceFileInfo for this file.
                //
                sourceFileInfo = new SourceFileInfo(file);

                sourceFileInfo.SourcePath = _compilationUnitSourcePath;

                if (sourceFileInfo.IsXamlFile)
                {
                    int fileExtIndex = file.Path.LastIndexOf(DOT, StringComparison.Ordinal);

                    sourceFileInfo.RelativeSourceFilePath = file.Path.Substring(0, fileExtIndex);
                }
            }

            return sourceFileInfo;
        }
Example #3
0
 /// <summary>
 /// constructor
 /// </summary>
 internal SourceFileResolveEventArgs(FileUnit file)
 {
     _sourceFileInfo = new SourceFileInfo(file);
 }
 /// <summary>
 /// constructor
 /// </summary>
 internal SourceFileResolveEventArgs(FileUnit file)
 {
     _sourceFileInfo = new SourceFileInfo(file);
 }