示例#1
0
        //
        // Create instance from a cache text string.
        //
        internal static LocalReferenceFile Deserialize(string cacheInfo)
        {
            // cachInfo string must follow pattern like Localizable + FilePath.
            // Localizable contains one character.
            LocalReferenceFile lrf = null;

            if (!String.IsNullOrEmpty(cacheInfo))
            {
                bool   localizable;
                string filePath;
                string linkAlias;
                string logicalName;

                string[] subStrs = cacheInfo.Split(semiColonChar);

                filePath    = subStrs[0];
                linkAlias   = subStrs[1];
                logicalName = subStrs[2];

                localizable = (filePath[0] == trueChar) ? true : false;

                filePath = filePath.Substring(1);

                lrf = new LocalReferenceFile(filePath, localizable, linkAlias, logicalName);
            }

            return(lrf);
        }
示例#2
0
        //
        // Read the Local Reference cache file, load the cached information
        // to the corresponding data fields in this class.
        //
        internal bool LoadCacheFile()
        {
            Debug.Assert(String.IsNullOrEmpty(_localCacheFile) != true, "_localCacheFile must not be empty.");

            bool loadSuccess = false;

            Stream stream = _taskFileService.GetContent(_localCacheFile);

            // using Disposes the StreamReader when it ends.  Disposing the StreamReader
            // also closes the underlying MemoryStream.  Don't look for BOM at the beginning
            // of the stream, since we don't add it when writing.  TaskFileService takes care
            // of this.
            using (StreamReader srCache = new StreamReader(stream, false))
            {
                // The first line must be for InternalTypeHelperFile.
                // The second line is for Local Application Defintion file.
                // For Library, the second line is an empty line.

                InternalTypeHelperFile = srCache.ReadLine();

                string lineText;

                lineText = srCache.ReadLine();

                LocalApplicationFile = LocalReferenceFile.Deserialize(lineText);

                ArrayList alMarkupPages = new ArrayList();

                while (srCache.EndOfStream != true)
                {
                    lineText = srCache.ReadLine();
                    LocalReferenceFile lrf = LocalReferenceFile.Deserialize(lineText);

                    if (lrf != null)
                    {
                        alMarkupPages.Add(lrf);
                    }
                }

                if (alMarkupPages.Count > 0)
                {
                    LocalMarkupPages = (LocalReferenceFile [])alMarkupPages.ToArray(typeof(LocalReferenceFile));
                }

                loadSuccess = true;
            }

            return(loadSuccess);
        }
        //
        // Generate new list of files that require to recompile for incremental build based on _analyzeResult
        //
        private void UpdateFileListForIncrementalBuild(List <FileUnit> modifiedXamlFiles)
        {
            List <FileUnit> recompiledXaml    = new List <FileUnit>();
            bool            recompileApp      = false;
            int             numLocalTypeXamls = 0;

            if ((_analyzeResult & RecompileCategory.ContentFiles) == RecompileCategory.ContentFiles)
            {
                RecompileContentFiles();
            }

            if ((_analyzeResult & RecompileCategory.ApplicationFile) == RecompileCategory.ApplicationFile)
            {
                recompileApp = true;
            }

            if ((_analyzeResult & RecompileCategory.PagesWithLocalType) == RecompileCategory.PagesWithLocalType && TaskFileService.IsRealBuild)
            {
                CompilerLocalReference.LoadCacheFile();

                if (CompilerLocalReference.LocalApplicationFile != null)
                {
                    // Application file contains local types, it will be recompiled.
                    recompileApp = true;
                }

                if (ListIsNotEmpty(CompilerLocalReference.LocalMarkupPages))
                {
                    numLocalTypeXamls = CompilerLocalReference.LocalMarkupPages.Length;

                    for (int i = 0; i < CompilerLocalReference.LocalMarkupPages.Length; i++)
                    {
                        LocalReferenceFile localRefFile = CompilerLocalReference.LocalMarkupPages[i];
                        recompiledXaml.Add(new FileUnit(
                                               localRefFile.FilePath,
                                               localRefFile.LinkAlias,
                                               localRefFile.LogicalName));
                    }
                }
            }

            if ((_analyzeResult & RecompileCategory.ModifiedPages) == RecompileCategory.ModifiedPages)
            {
                // If the xaml is already in the local-type-ref xaml file list, don't add a duplicate file path to recompiledXaml list.

                for (int i = 0; i < modifiedXamlFiles.Count; i++)
                {
                    FileUnit xamlfile = modifiedXamlFiles[i];
                    bool     addToList;

                    addToList = true;

                    if (numLocalTypeXamls > 0)
                    {
                        for (int j = 0; j < numLocalTypeXamls; j++)
                        {
                            if (String.Compare(xamlfile.Path, CompilerLocalReference.LocalMarkupPages[j].FilePath, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                addToList = false;
                                break;
                            }
                        }
                    }

                    if (addToList)
                    {
                        recompiledXaml.Add(xamlfile);
                    }
                }
            }

            if (recompiledXaml.Count > 0)
            {
                _recompileMarkupPages = recompiledXaml.ToArray();
            }

            // Set ApplicationFile appropriatelly for this incremental build.
            ProcessApplicationFile(recompileApp);
        }
        //
        // Create instance from a cache text string.
        //
        internal static LocalReferenceFile Deserialize(string cacheInfo)
        {
            // cachInfo string must follow pattern like Localizable + FilePath.
            // Localizable contains one character.
            LocalReferenceFile lrf = null;

            if (!String.IsNullOrEmpty(cacheInfo))
            {
                bool  localizable;
                string filePath;
                string linkAlias;
                string logicalName;

                string[] subStrs = cacheInfo.Split(semiColonChar);

                filePath = subStrs[0];
                linkAlias = subStrs[1];
                logicalName = subStrs[2];

                localizable = (filePath[0] == trueChar) ? true : false;

                filePath = filePath.Substring(1);

                lrf = new LocalReferenceFile(filePath, localizable, linkAlias, logicalName);
            }

            return lrf;
        }
示例#5
0
        //
        // Generate appropriate output file list for local-type xaml file. This information will be saved
        // into the .lref cache file so that the MarkupCompilePass2 can take it.
        //
        private LocalReferenceFile GenerateLocalTypeItem(string localTypeXamlFile, ITaskItem[] inputXamlItemList)
        {
            LocalReferenceFile localFile = null;
            bool isLocalizable = false;
            string linkAlias = String.Empty;
            string logicalName = String.Empty;

            //
            // Check if the local-type xaml file is localizable or not.
            //
            for (int i = 0; i < inputXamlItemList.Length; i++)
            {
                ITaskItem inputXamlItem = inputXamlItemList[i];

                string xamlInputFullPath = TaskHelper.CreateFullFilePath(inputXamlItem.ItemSpec, SourceDir);

                if (String.Compare(localTypeXamlFile, xamlInputFullPath, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    //
                    // Got this file from the original XamlFile TaskItem list.
                    // Check if this item is localizable or not and stop the search here.
                    //
                    isLocalizable = IsItemLocalizable(inputXamlItem);
                    linkAlias = inputXamlItem.GetMetadata(SharedStrings.Link);
                    logicalName = inputXamlItem.GetMetadata(SharedStrings.LogicalName);
                    break;
                }
            }

            //
            // Generate the instance of LocalReferenceFile for this local-type xaml file.
            //
            localFile = new LocalReferenceFile(localTypeXamlFile, isLocalizable, linkAlias, logicalName);

            if (isLocalizable)
            {
                _requirePass2ForSatelliteAssembly = true;
            }
            else
            {
                _requirePass2ForMainAssembly = true;
            }

            return localFile;
        }
示例#6
0
        //
        // Generate new list of files that require to recompile for incremental build based on _analyzeResult
        //
        private void UpdateFileListForIncrementalBuild(List <FileUnit> modifiedXamlFiles)
        {
            List <FileUnit> recompiledXaml    = new List <FileUnit>();
            bool            recompileApp      = false;
            int             numLocalTypeXamls = 0;

            if ((_analyzeResult & RecompileCategory.ContentFiles) == RecompileCategory.ContentFiles)
            {
                RecompileContentFiles();
            }

            if ((_analyzeResult & RecompileCategory.ApplicationFile) == RecompileCategory.ApplicationFile)
            {
                recompileApp = true;
            }

            if ((_analyzeResult & RecompileCategory.PagesWithLocalType) == RecompileCategory.PagesWithLocalType && TaskFileService.IsRealBuild)
            {
                CompilerLocalReference.LoadCacheFile();

                if (CompilerLocalReference.LocalApplicationFile != null)
                {
                    // Application file contains local types, it will be recompiled.
                    recompileApp = true;
                }

                if (ListIsNotEmpty(CompilerLocalReference.LocalMarkupPages))
                {
                    numLocalTypeXamls = CompilerLocalReference.LocalMarkupPages.Length;

                    // Under incremental builds of SDK projects, we can have a state where the cache contains some XAML files but the Page blob
                    // no longer contains them.  To avoid attempting to recompile a file that no longer exists, ensure that any cached XAML file
                    // still exists in the Page blob prior to queuing it up for recompilation.
                    HashSet <string> localMarkupPages = new HashSet <string>(_mcPass1.PageMarkup.Select(x => x.GetMetadata(SharedStrings.FullPath)), StringComparer.OrdinalIgnoreCase);

                    for (int i = 0; i < numLocalTypeXamls; i++)
                    {
                        LocalReferenceFile localRefFile = CompilerLocalReference.LocalMarkupPages[i];

                        if (localMarkupPages.Contains(localRefFile.FilePath))
                        {
                            recompiledXaml.Add(new FileUnit(
                                                   localRefFile.FilePath,
                                                   localRefFile.LinkAlias,
                                                   localRefFile.LogicalName));
                        }
                    }
                }
            }

            if ((_analyzeResult & RecompileCategory.ModifiedPages) == RecompileCategory.ModifiedPages)
            {
                // If the xaml is already in the local-type-ref xaml file list, don't add a duplicate file path to recompiledXaml list.

                for (int i = 0; i < modifiedXamlFiles.Count; i++)
                {
                    FileUnit xamlfile = modifiedXamlFiles[i];
                    bool     addToList;

                    addToList = true;

                    if (numLocalTypeXamls > 0)
                    {
                        for (int j = 0; j < numLocalTypeXamls; j++)
                        {
                            if (String.Compare(xamlfile.Path, CompilerLocalReference.LocalMarkupPages[j].FilePath, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                addToList = false;
                                break;
                            }
                        }
                    }

                    if (addToList)
                    {
                        recompiledXaml.Add(xamlfile);
                    }
                }
            }

            if (recompiledXaml.Count > 0)
            {
                _recompileMarkupPages = recompiledXaml.ToArray();
            }

            // Set ApplicationFile appropriatelly for this incremental build.
            ProcessApplicationFile(recompileApp);
        }