Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / BuildTasks / MS / Internal / Tasks / CompilerState.cs / 1 / CompilerState.cs
//----------------------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
// Description:
// An internal class which handles compiler information cache. It can read
// write the cache file, this is for incremental build support.
//
// History:
//
// 11/21/05: weibz Created
//
//---------------------------------------------------------------------------------------
using System;
using System.IO;
using System.Collections;
using System.Diagnostics;
using System.Text;
using System.Globalization;
using Microsoft.Build.Tasks.Windows;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using MS.Utility;
namespace MS.Internal.Tasks
{
//
// Only cache information for below types.
//
internal enum CompilerStateType : int
{
AssemblyName = 0x00,
AssemblyVersion,
AssemblyPublicKeyToken,
OutputType,
Language,
LanguageSourceExtension,
OutputPath,
RootNamespace,
LocalizationDirectivesToLocFile,
HostInBrowser,
DefineConstants,
ApplicationFile,
PageMarkup,
ContentFiles,
SourceCodeFiles,
References,
PageMarkupFileNames,
SplashImage,
MaxCount,
}
//
// CompilerState
//
internal class CompilerState
{
//
// ctor of CompilerState
//
internal CompilerState(string stateFilePath, ITaskFileService taskFileService)
{
_cacheInfoList = new String[(int)CompilerStateType.MaxCount];
_stateFilePath = stateFilePath;
_taskFileService = taskFileService;
}
#region internal methods
//
// Detect whether the state file exists or not.
//
//
internal bool StateFileExists()
{
return _taskFileService.Exists(_stateFilePath);
}
//
// Clean up the state file.
//
internal void CleanupCache()
{
if (StateFileExists() )
{
_taskFileService.Delete(_stateFilePath);
}
}
internal bool SaveStateInformation(MarkupCompilePass1 mcPass1)
{
Debug.Assert(String.IsNullOrEmpty(_stateFilePath) != true, "StateFilePath must not be empty.");
Debug.Assert(mcPass1 != null, "A valid instance of MarkupCompilePass1 must be passed to method SaveCacheInformation.");
Debug.Assert(_cacheInfoList.Length == (int)CompilerStateType.MaxCount, "The Cache string array should be already allocated.");
bool bSuccess = false;
// Transfer the cache related information from mcPass1 to this instance.
AssemblyName = mcPass1.AssemblyName;
AssemblyVersion = mcPass1.AssemblyVersion;
AssemblyPublicKeyToken = mcPass1.AssemblyPublicKeyToken;
OutputType = mcPass1.OutputType;
Language = mcPass1.Language;
LanguageSourceExtension = mcPass1.LanguageSourceExtension;
OutputPath = mcPass1.OutputPath;
RootNamespace = mcPass1.RootNamespace;
LocalizationDirectivesToLocFile = mcPass1.LocalizationDirectivesToLocFile;
HostInBrowser = mcPass1.HostInBrowser;
DefineConstants = mcPass1.DefineConstants;
ApplicationFile = mcPass1.ApplicationFile;
PageMarkup = mcPass1.PageMarkupCache;
ContentFiles = mcPass1.ContentFilesCache;
SourceCodeFiles = mcPass1.SourceCodeFilesCache;
References = mcPass1.ReferencesCache;
PageMarkupFileNames = GenerateStringFromFileNames(mcPass1.PageMarkup);
SplashImage = mcPass1.SplashImageName;
// Save the cache information to the cache file.
MemoryStream memStream = new MemoryStream();
// using Disposes the StreamWriter when it ends. Disposing the StreamWriter
// also closes the underlying MemoryStream. Furthermore, don't add BOM here
// since TaskFileService.WriteFile adds it.
using (StreamWriter sw = new StreamWriter(memStream, new UTF8Encoding(false)))
{
for (int i =0; i<(int)CompilerStateType.MaxCount; i++)
{
sw.WriteLine(_cacheInfoList[i]);
}
sw.Flush();
_taskFileService.WriteFile(memStream.ToArray(), _stateFilePath);
bSuccess = true;
}
return bSuccess;
}
//
// Read the markupcompiler cache file, load the cached information
// to the corresponding data fields in this class.
//
internal bool LoadStateInformation( )
{
Debug.Assert(String.IsNullOrEmpty(_stateFilePath) != true, "_stateFilePath must be not be empty.");
Debug.Assert(_cacheInfoList.Length == (int)CompilerStateType.MaxCount, "The Cache string array should be already allocated.");
bool loadSuccess = false;
Stream stream = _taskFileService.GetContent(_stateFilePath);
// 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))
{
int i = 0;
while (srCache.EndOfStream != true)
{
if (i >= (int)CompilerStateType.MaxCount)
{
break;
}
_cacheInfoList[i] = srCache.ReadLine();
i++;
}
loadSuccess = true;
}
return loadSuccess;
}
//
// Generate cache string for item lists such as PageMarkup, References,
// ContentFiles and CodeFiles etc.
//
internal static string GenerateCacheForFileList(ITaskItem[] fileItemList)
{
string cacheString = String.Empty;
if (fileItemList != null && fileItemList.Length > 0)
{
int iHashCode = 0;
int iCount = fileItemList.Length;
for (int i = 0; i < iCount; i++)
{
iHashCode += fileItemList[i].ItemSpec.GetHashCode();
}
StringBuilder sb = new StringBuilder();
sb.Append(iCount);
sb.Append(iHashCode);
cacheString = sb.ToString();
}
return cacheString;
}
private static string GenerateStringFromFileNames(ITaskItem[] fileItemList)
{
string fileNames = String.Empty;
if (fileItemList != null)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < fileItemList.Length; i++)
{
sb.Append(fileItemList[i].ItemSpec);
sb.Append(";");
}
fileNames = sb.ToString();
}
return fileNames;
}
#endregion
#region internal properties
internal string CacheFilePath
{
get { return _stateFilePath; }
}
internal string AssemblyName
{
get { return _cacheInfoList[(int)CompilerStateType.AssemblyName]; }
set { _cacheInfoList[(int)CompilerStateType.AssemblyName] = value; }
}
internal string AssemblyVersion
{
get { return _cacheInfoList[(int)CompilerStateType.AssemblyVersion]; }
set { _cacheInfoList[(int)CompilerStateType.AssemblyVersion] = value; }
}
internal string AssemblyPublicKeyToken
{
get { return _cacheInfoList[(int)CompilerStateType.AssemblyPublicKeyToken]; }
set { _cacheInfoList[(int)CompilerStateType.AssemblyPublicKeyToken] = value; }
}
internal string OutputType
{
get { return _cacheInfoList[(int)CompilerStateType.OutputType]; }
set { _cacheInfoList[(int)CompilerStateType.OutputType] = value; }
}
internal string Language
{
get { return _cacheInfoList[(int)CompilerStateType.Language]; }
set { _cacheInfoList[(int)CompilerStateType.Language] = value; }
}
internal string LanguageSourceExtension
{
get { return _cacheInfoList[(int)CompilerStateType.LanguageSourceExtension]; }
set { _cacheInfoList[(int)CompilerStateType.LanguageSourceExtension] = value; }
}
internal string OutputPath
{
get { return _cacheInfoList[(int)CompilerStateType.OutputPath]; }
set { _cacheInfoList[(int)CompilerStateType.OutputPath] = value; }
}
internal string RootNamespace
{
get { return _cacheInfoList[(int)CompilerStateType.RootNamespace]; }
set { _cacheInfoList[(int)CompilerStateType.RootNamespace] = value; }
}
internal string LocalizationDirectivesToLocFile
{
get { return _cacheInfoList[(int)CompilerStateType.LocalizationDirectivesToLocFile]; }
set { _cacheInfoList[(int)CompilerStateType.LocalizationDirectivesToLocFile] = value; }
}
internal string HostInBrowser
{
get { return _cacheInfoList[(int)CompilerStateType.HostInBrowser]; }
set { _cacheInfoList[(int)CompilerStateType.HostInBrowser] = value; }
}
internal string DefineConstants
{
get { return _cacheInfoList[(int)CompilerStateType.DefineConstants]; }
set { _cacheInfoList[(int)CompilerStateType.DefineConstants] = value; }
}
internal string ApplicationFile
{
get { return _cacheInfoList[(int)CompilerStateType.ApplicationFile]; }
set { _cacheInfoList[(int)CompilerStateType.ApplicationFile] = value; }
}
internal string PageMarkup
{
get { return _cacheInfoList[(int)CompilerStateType.PageMarkup]; }
set { _cacheInfoList[(int)CompilerStateType.PageMarkup] = value; }
}
internal string ContentFiles
{
get { return _cacheInfoList[(int)CompilerStateType.ContentFiles]; }
set { _cacheInfoList[(int)CompilerStateType.ContentFiles] = value; }
}
internal string SourceCodeFiles
{
get { return _cacheInfoList[(int)CompilerStateType.SourceCodeFiles]; }
set { _cacheInfoList[(int)CompilerStateType.SourceCodeFiles] = value; }
}
internal string References
{
get { return _cacheInfoList[(int)CompilerStateType.References]; }
set { _cacheInfoList[(int)CompilerStateType.References] = value; }
}
internal string PageMarkupFileNames
{
get { return _cacheInfoList[(int)CompilerStateType.PageMarkupFileNames]; }
set { _cacheInfoList[(int)CompilerStateType.PageMarkupFileNames] = value; }
}
internal string SplashImage
{
get { return _cacheInfoList[(int)CompilerStateType.SplashImage]; }
set { _cacheInfoList[(int)CompilerStateType.SplashImage] = value; }
}
#endregion
#region private data
private String [] _cacheInfoList;
private string _stateFilePath;
private ITaskFileService _taskFileService = null;
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
// Description:
// An internal class which handles compiler information cache. It can read
// write the cache file, this is for incremental build support.
//
// History:
//
// 11/21/05: weibz Created
//
//---------------------------------------------------------------------------------------
using System;
using System.IO;
using System.Collections;
using System.Diagnostics;
using System.Text;
using System.Globalization;
using Microsoft.Build.Tasks.Windows;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using MS.Utility;
namespace MS.Internal.Tasks
{
//
// Only cache information for below types.
//
internal enum CompilerStateType : int
{
AssemblyName = 0x00,
AssemblyVersion,
AssemblyPublicKeyToken,
OutputType,
Language,
LanguageSourceExtension,
OutputPath,
RootNamespace,
LocalizationDirectivesToLocFile,
HostInBrowser,
DefineConstants,
ApplicationFile,
PageMarkup,
ContentFiles,
SourceCodeFiles,
References,
PageMarkupFileNames,
SplashImage,
MaxCount,
}
//
// CompilerState
//
internal class CompilerState
{
//
// ctor of CompilerState
//
internal CompilerState(string stateFilePath, ITaskFileService taskFileService)
{
_cacheInfoList = new String[(int)CompilerStateType.MaxCount];
_stateFilePath = stateFilePath;
_taskFileService = taskFileService;
}
#region internal methods
//
// Detect whether the state file exists or not.
//
//
internal bool StateFileExists()
{
return _taskFileService.Exists(_stateFilePath);
}
//
// Clean up the state file.
//
internal void CleanupCache()
{
if (StateFileExists() )
{
_taskFileService.Delete(_stateFilePath);
}
}
internal bool SaveStateInformation(MarkupCompilePass1 mcPass1)
{
Debug.Assert(String.IsNullOrEmpty(_stateFilePath) != true, "StateFilePath must not be empty.");
Debug.Assert(mcPass1 != null, "A valid instance of MarkupCompilePass1 must be passed to method SaveCacheInformation.");
Debug.Assert(_cacheInfoList.Length == (int)CompilerStateType.MaxCount, "The Cache string array should be already allocated.");
bool bSuccess = false;
// Transfer the cache related information from mcPass1 to this instance.
AssemblyName = mcPass1.AssemblyName;
AssemblyVersion = mcPass1.AssemblyVersion;
AssemblyPublicKeyToken = mcPass1.AssemblyPublicKeyToken;
OutputType = mcPass1.OutputType;
Language = mcPass1.Language;
LanguageSourceExtension = mcPass1.LanguageSourceExtension;
OutputPath = mcPass1.OutputPath;
RootNamespace = mcPass1.RootNamespace;
LocalizationDirectivesToLocFile = mcPass1.LocalizationDirectivesToLocFile;
HostInBrowser = mcPass1.HostInBrowser;
DefineConstants = mcPass1.DefineConstants;
ApplicationFile = mcPass1.ApplicationFile;
PageMarkup = mcPass1.PageMarkupCache;
ContentFiles = mcPass1.ContentFilesCache;
SourceCodeFiles = mcPass1.SourceCodeFilesCache;
References = mcPass1.ReferencesCache;
PageMarkupFileNames = GenerateStringFromFileNames(mcPass1.PageMarkup);
SplashImage = mcPass1.SplashImageName;
// Save the cache information to the cache file.
MemoryStream memStream = new MemoryStream();
// using Disposes the StreamWriter when it ends. Disposing the StreamWriter
// also closes the underlying MemoryStream. Furthermore, don't add BOM here
// since TaskFileService.WriteFile adds it.
using (StreamWriter sw = new StreamWriter(memStream, new UTF8Encoding(false)))
{
for (int i =0; i<(int)CompilerStateType.MaxCount; i++)
{
sw.WriteLine(_cacheInfoList[i]);
}
sw.Flush();
_taskFileService.WriteFile(memStream.ToArray(), _stateFilePath);
bSuccess = true;
}
return bSuccess;
}
//
// Read the markupcompiler cache file, load the cached information
// to the corresponding data fields in this class.
//
internal bool LoadStateInformation( )
{
Debug.Assert(String.IsNullOrEmpty(_stateFilePath) != true, "_stateFilePath must be not be empty.");
Debug.Assert(_cacheInfoList.Length == (int)CompilerStateType.MaxCount, "The Cache string array should be already allocated.");
bool loadSuccess = false;
Stream stream = _taskFileService.GetContent(_stateFilePath);
// 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))
{
int i = 0;
while (srCache.EndOfStream != true)
{
if (i >= (int)CompilerStateType.MaxCount)
{
break;
}
_cacheInfoList[i] = srCache.ReadLine();
i++;
}
loadSuccess = true;
}
return loadSuccess;
}
//
// Generate cache string for item lists such as PageMarkup, References,
// ContentFiles and CodeFiles etc.
//
internal static string GenerateCacheForFileList(ITaskItem[] fileItemList)
{
string cacheString = String.Empty;
if (fileItemList != null && fileItemList.Length > 0)
{
int iHashCode = 0;
int iCount = fileItemList.Length;
for (int i = 0; i < iCount; i++)
{
iHashCode += fileItemList[i].ItemSpec.GetHashCode();
}
StringBuilder sb = new StringBuilder();
sb.Append(iCount);
sb.Append(iHashCode);
cacheString = sb.ToString();
}
return cacheString;
}
private static string GenerateStringFromFileNames(ITaskItem[] fileItemList)
{
string fileNames = String.Empty;
if (fileItemList != null)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < fileItemList.Length; i++)
{
sb.Append(fileItemList[i].ItemSpec);
sb.Append(";");
}
fileNames = sb.ToString();
}
return fileNames;
}
#endregion
#region internal properties
internal string CacheFilePath
{
get { return _stateFilePath; }
}
internal string AssemblyName
{
get { return _cacheInfoList[(int)CompilerStateType.AssemblyName]; }
set { _cacheInfoList[(int)CompilerStateType.AssemblyName] = value; }
}
internal string AssemblyVersion
{
get { return _cacheInfoList[(int)CompilerStateType.AssemblyVersion]; }
set { _cacheInfoList[(int)CompilerStateType.AssemblyVersion] = value; }
}
internal string AssemblyPublicKeyToken
{
get { return _cacheInfoList[(int)CompilerStateType.AssemblyPublicKeyToken]; }
set { _cacheInfoList[(int)CompilerStateType.AssemblyPublicKeyToken] = value; }
}
internal string OutputType
{
get { return _cacheInfoList[(int)CompilerStateType.OutputType]; }
set { _cacheInfoList[(int)CompilerStateType.OutputType] = value; }
}
internal string Language
{
get { return _cacheInfoList[(int)CompilerStateType.Language]; }
set { _cacheInfoList[(int)CompilerStateType.Language] = value; }
}
internal string LanguageSourceExtension
{
get { return _cacheInfoList[(int)CompilerStateType.LanguageSourceExtension]; }
set { _cacheInfoList[(int)CompilerStateType.LanguageSourceExtension] = value; }
}
internal string OutputPath
{
get { return _cacheInfoList[(int)CompilerStateType.OutputPath]; }
set { _cacheInfoList[(int)CompilerStateType.OutputPath] = value; }
}
internal string RootNamespace
{
get { return _cacheInfoList[(int)CompilerStateType.RootNamespace]; }
set { _cacheInfoList[(int)CompilerStateType.RootNamespace] = value; }
}
internal string LocalizationDirectivesToLocFile
{
get { return _cacheInfoList[(int)CompilerStateType.LocalizationDirectivesToLocFile]; }
set { _cacheInfoList[(int)CompilerStateType.LocalizationDirectivesToLocFile] = value; }
}
internal string HostInBrowser
{
get { return _cacheInfoList[(int)CompilerStateType.HostInBrowser]; }
set { _cacheInfoList[(int)CompilerStateType.HostInBrowser] = value; }
}
internal string DefineConstants
{
get { return _cacheInfoList[(int)CompilerStateType.DefineConstants]; }
set { _cacheInfoList[(int)CompilerStateType.DefineConstants] = value; }
}
internal string ApplicationFile
{
get { return _cacheInfoList[(int)CompilerStateType.ApplicationFile]; }
set { _cacheInfoList[(int)CompilerStateType.ApplicationFile] = value; }
}
internal string PageMarkup
{
get { return _cacheInfoList[(int)CompilerStateType.PageMarkup]; }
set { _cacheInfoList[(int)CompilerStateType.PageMarkup] = value; }
}
internal string ContentFiles
{
get { return _cacheInfoList[(int)CompilerStateType.ContentFiles]; }
set { _cacheInfoList[(int)CompilerStateType.ContentFiles] = value; }
}
internal string SourceCodeFiles
{
get { return _cacheInfoList[(int)CompilerStateType.SourceCodeFiles]; }
set { _cacheInfoList[(int)CompilerStateType.SourceCodeFiles] = value; }
}
internal string References
{
get { return _cacheInfoList[(int)CompilerStateType.References]; }
set { _cacheInfoList[(int)CompilerStateType.References] = value; }
}
internal string PageMarkupFileNames
{
get { return _cacheInfoList[(int)CompilerStateType.PageMarkupFileNames]; }
set { _cacheInfoList[(int)CompilerStateType.PageMarkupFileNames] = value; }
}
internal string SplashImage
{
get { return _cacheInfoList[(int)CompilerStateType.SplashImage]; }
set { _cacheInfoList[(int)CompilerStateType.SplashImage] = value; }
}
#endregion
#region private data
private String [] _cacheInfoList;
private string _stateFilePath;
private ITaskFileService _taskFileService = null;
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ObjectManager.cs
- RoleGroupCollection.cs
- Types.cs
- OrderPreservingPipeliningSpoolingTask.cs
- HashSet.cs
- SerializerDescriptor.cs
- TypeResolver.cs
- MemberRelationshipService.cs
- WebServiceTypeData.cs
- ApplicationTrust.cs
- ResourcePropertyMemberCodeDomSerializer.cs
- SchemaObjectWriter.cs
- EntityDataSourceSelectingEventArgs.cs
- ManagementQuery.cs
- Propagator.JoinPropagator.cs
- WrapPanel.cs
- IBuiltInEvidence.cs
- ListBase.cs
- StatusBar.cs
- OciLobLocator.cs
- ConfigXmlSignificantWhitespace.cs
- IconHelper.cs
- SafeRightsManagementQueryHandle.cs
- PieceDirectory.cs
- ComEventsInfo.cs
- StatusBarAutomationPeer.cs
- ModuleConfigurationInfo.cs
- ScrollContentPresenter.cs
- RepeatButton.cs
- DetailsViewUpdateEventArgs.cs
- WebServiceErrorEvent.cs
- LoginName.cs
- StringDictionaryWithComparer.cs
- WebZone.cs
- BindableTemplateBuilder.cs
- SoapSchemaMember.cs
- GPRECT.cs
- PropertyBuilder.cs
- CellTreeNode.cs
- ParameterToken.cs
- _NestedSingleAsyncResult.cs
- SafeFileMappingHandle.cs
- BitmapMetadataBlob.cs
- ActivityExecutionWorkItem.cs
- MimeImporter.cs
- CodeMemberEvent.cs
- OracleBinary.cs
- ConnectionsZone.cs
- DataProviderNameConverter.cs
- SelectionWordBreaker.cs
- GeneralTransform.cs
- SubclassTypeValidator.cs
- GeneratedCodeAttribute.cs
- PropertyValue.cs
- ErrorWrapper.cs
- SystemColorTracker.cs
- PropertyInfoSet.cs
- XmlEncodedRawTextWriter.cs
- FastPropertyAccessor.cs
- PrivateUnsafeNativeCompoundFileMethods.cs
- XPathQueryGenerator.cs
- TypeSchema.cs
- AppSettingsSection.cs
- NavigateEvent.cs
- RepeatBehavior.cs
- CodeGenerator.cs
- BitmapEffectvisualstate.cs
- DesignerActionItem.cs
- EmissiveMaterial.cs
- ImageInfo.cs
- StringSource.cs
- ResolveNameEventArgs.cs
- DateTimeValueSerializerContext.cs
- ContractBase.cs
- HtmlFormAdapter.cs
- EdmEntityTypeAttribute.cs
- EntityDataSourceDesignerHelper.cs
- InstanceDescriptor.cs
- UnsignedPublishLicense.cs
- ISAPIRuntime.cs
- SqlClientMetaDataCollectionNames.cs
- IsolatedStoragePermission.cs
- CustomTypeDescriptor.cs
- ErrorStyle.cs
- XmlIncludeAttribute.cs
- ViewLoader.cs
- PipelineComponent.cs
- XmlSchemaNotation.cs
- QuotaExceededException.cs
- ProfessionalColors.cs
- SafeUserTokenHandle.cs
- SponsorHelper.cs
- ColorTranslator.cs
- WindowsTreeView.cs
- OutputChannel.cs
- CreatingCookieEventArgs.cs
- SplayTreeNode.cs
- InputBinding.cs
- ByteStack.cs
- ErrorProvider.cs