コード例 #1
0
        /// <summary>
        /// Reads the .cache file from disk into a ResGenDependencies object.
        /// </summary>
        /// <param name="stateFile"></param>
        /// <param name="useSourcePath"></param>
        /// <returns></returns>
        internal static ResGenDependencies DeserializeCache(string stateFile, bool useSourcePath, TaskLoggingHelper log)
        {
            ResGenDependencies retVal = (ResGenDependencies)StateFileBase.DeserializeCache(stateFile, log, typeof(ResGenDependencies));

            if (retVal == null)
            {
                retVal = new ResGenDependencies();
            }

            // Ensure that the cache is properly initialized with respect to how resgen will
            // resolve linked files within .resx files.  ResGen has two different
            // ways for resolving relative file-paths in linked files. The way
            // that ResGen resolved relative paths before Whidbey was always to
            // resolve from the current working directory. In Whidbey a new command-line
            // switch "/useSourcePath" instructs ResGen to use the folder that
            // contains the .resx file as the path from which it should resolve
            // relative paths. So we should base our timestamp/existence checking
            // on the same switch & resolve in the same manner as ResGen.
            retVal.UseSourcePath = useSourcePath;

            return(retVal);
        }
コード例 #2
0
        public void DirtyCleanScenario()
        {
            ResGenDependencies cache = new ResGenDependencies();

            string resx = CreateSampleResx();
            string stateFile = FileUtilities.GetTemporaryFile();

            try
            {
                // A newly created cache is not dirty.
                Assert.IsTrue(!cache.IsDirty);

                // Getting a file that wasn't in the cache is a write operation.
                cache.GetResXFileInfo(resx);
                Assert.IsTrue(cache.IsDirty);

                // Writing the file to disk should make the cache clean.
                cache.SerializeCache(stateFile, /* Log */ null);
                Assert.IsTrue(!cache.IsDirty);

                // Deserialize from disk. Result should not be dirty.
                cache = ResGenDependencies.DeserializeCache(stateFile, true, /* Log */ null);
                Assert.IsTrue(!cache.IsDirty);

                // Asking for a file that's in the cache should not dirty the cache.
                cache.GetResXFileInfo(resx);
                Assert.IsTrue(!cache.IsDirty);

                // Changing UseSourcePath to false should dirty the cache.
                cache.UseSourcePath = false;
                Assert.IsTrue(cache.IsDirty);
            }
            finally
            {
                File.Delete(resx);
                File.Delete(stateFile);
            }
        }
コード例 #3
0
ファイル: GenerateResource.cs プロジェクト: ChronosWS/msbuild
        /// <summary>
        /// Read the state file if able.
        /// </summary>
        private void ReadStateFile()
        {
            // First we look to see if we have a resgen linked files cache.  If so, then we can use that
            // cache to speed up processing.  If there's a problem reading the cache file (or it
            // just doesn't exist, then this method will return a brand new cache object.

            // This method eats IO Exceptions
            _cache = ResGenDependencies.DeserializeCache((StateFile == null) ? null : StateFile.ItemSpec, UseSourcePath, Log);
            ErrorUtilities.VerifyThrow(_cache != null, "We did not create a cache!");
        }
コード例 #4
0
ファイル: GenerateResource.cs プロジェクト: ChronosWS/msbuild
        /// <summary>
        /// Given a cached portable library that is up to date, create ITaskItems to represent the output of the task, as if we did real work.
        /// </summary>
        /// <param name="library">The portable library cache entry to extract output files & metadata from.</param>
        /// <param name="cachedOutputFiles">List of output files produced from the cache.</param>
        private void AppendCachedOutputTaskItems(ResGenDependencies.PortableLibraryFile library, List<ITaskItem> cachedOutputFiles)
        {
            foreach (string outputFileName in library.OutputFiles)
            {
                ITaskItem item = new TaskItem(outputFileName);
                item.SetMetadata("ResourceIndexName", library.AssemblySimpleName);
                if (library.NeutralResourceLanguage != null)
                {
                    item.SetMetadata("NeutralResourceLanguage", library.NeutralResourceLanguage);
                }

                cachedOutputFiles.Add(item);
            }
        }
コード例 #5
0
        /// <summary>
        /// Reads the .cache file from disk into a ResGenDependencies object.
        /// </summary>
        /// <param name="stateFile"></param>
        /// <param name="useSourcePath"></param>
        /// <returns></returns>
        internal static ResGenDependencies DeserializeCache(string stateFile, bool useSourcePath, TaskLoggingHelper log)
        {
            ResGenDependencies retVal = (ResGenDependencies)StateFileBase.DeserializeCache(stateFile, log, typeof(ResGenDependencies));

            if (retVal == null)
            {
                retVal = new ResGenDependencies();
            }

            // Ensure that the cache is properly initialized with respect to how resgen will 
            // resolve linked files within .resx files.  ResGen has two different
            // ways for resolving relative file-paths in linked files. The way
            // that ResGen resolved relative paths before Whidbey was always to
            // resolve from the current working directory. In Whidbey a new command-line
            // switch "/useSourcePath" instructs ResGen to use the folder that
            // contains the .resx file as the path from which it should resolve
            // relative paths. So we should base our timestamp/existence checking
            // on the same switch & resolve in the same manner as ResGen.
            retVal.UseSourcePath = useSourcePath;

            return retVal;
        }