Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / BuildTasks / Microsoft / Build / Tasks / Windows / FileClassifier.cs / 1305600 / FileClassifier.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: An MSBuild task that classify the input files to different // categories based on the input item's attributes. // // Spec: http://avalon/app/Compilation/Avalon-MSBUILD%20Targets.doc // // History: // 06/20/03: weibz rewrite and moved over to WCP tree // //--------------------------------------------------------------------------- using System; using System.IO; using System.Collections.Generic; using System.Globalization; using System.Diagnostics; using System.Reflection; using System.Resources; using System.Runtime.InteropServices; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using MS.Utility; using MS.Internal.Tasks; // Since we disable PreSharp warnings in this file, PreSharp warning is unknown to C# compiler. // We first need to disable warnings about unknown message numbers and unknown pragmas. #pragma warning disable 1634, 1691 namespace Microsoft.Build.Tasks.Windows { ////// The File Classification task puts all the input baml files, image files into different /// output resource groups, such as Resources for Main assembly and Resources for satellite /// assembly. /// public sealed class FileClassifier : Task { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors ////// Constrcutor /// public FileClassifier() : base(SR.ResourceManager) { // set default values for some non-required input items _culture = null; } #endregion Constructors //------------------------------------------------------ // // Public Methods // //----------------------------------------------------- #region Public Methods ////// ITask Execute method /// ///public override bool Execute() { bool ret = false; var mainEmbeddedList = new List (); var satelliteEmbeddedList = new List (); var clrEmbeddedResourceList = new List (); var clrSatelliteEmbeddedResourceList = new List (); try { TaskHelper.DisplayLogo(Log, SR.Get(SRID.FileClassifierTask)); ret = VerifyTaskInputs(); if (ret != false) { // Do the real work to classify input files. Classify(SourceFiles, mainEmbeddedList, satelliteEmbeddedList); if (CLRResourceFiles != null) { // Generate the output CLR embedded resource list. Classify(CLRResourceFiles, clrEmbeddedResourceList, clrSatelliteEmbeddedResourceList); } // move the arraylist to the TaskItem array. MainEmbeddedFiles = mainEmbeddedList.ToArray(); SatelliteEmbeddedFiles = satelliteEmbeddedList.ToArray(); CLREmbeddedResource = clrEmbeddedResourceList.ToArray(); CLRSatelliteEmbeddedResource = clrSatelliteEmbeddedResourceList.ToArray(); } } catch (Exception e) { // PreSharp Complaint 6500 - do not handle null-ref or SEH exceptions. if (e is NullReferenceException || e is SEHException) { throw; } else { 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); } return false; } #pragma warning disable 6500 catch // Non-CLS compliant errors { Log.LogErrorWithCodeFromResources(SRID.NonClsError); return false; } #pragma warning restore 6500 return ret; } #endregion Public Methods //------------------------------------------------------ // // Public Properties // //------------------------------------------------------ #region Public Properties /// /// SourceFiles: List of Items thatare to be classified /// [Required] public ITaskItem [] SourceFiles { get; set; } ////// Can have values (exe, or dll) /// [Required] public string OutputType { get; set; } ////// Culture of the build. Can be null if the build is non-localizable /// public string Culture { get { return _culture != null ? _culture.ToLower(CultureInfo.InvariantCulture) : null; } set { _culture = value; } } ////// The CLR resource file list. /// In Project file, those files will be define by type CLRResource. /// such as: ///- ///
public ITaskItem[] CLRResourceFiles { get; set; } /// /// Output Item list for the CLR resources that will be saved in /// the main assembly. /// ///[Output] public ITaskItem[] CLREmbeddedResource { get; set; } /// /// Output Item list for the CLR resources that will be saved in /// the satellite assembly. /// ///[Output] public ITaskItem[] CLRSatelliteEmbeddedResource { get; set; } /// /// MainEmbeddedFiles /// /// Non-localizable resources which will be embedded into the Main assembly. /// [Output] public ITaskItem [] MainEmbeddedFiles { get; set; } ////// SatelliteEmbeddedFiles /// /// Localizable files which are embedded to the Satellite assembly for the /// culture which is set in Culture property.. /// [Output] public ITaskItem [] SatelliteEmbeddedFiles { get; set; } #endregion Public Properties //----------------------------------------------------- // // Public Events // //------------------------------------------------------ //----------------------------------------------------- // // Protected Methods // //----------------------------------------------------- //----------------------------------------------------- // // Internal Methods // //------------------------------------------------------ //----------------------------------------------------- // // Internal Properties // //------------------------------------------------------ //------------------------------------------------------ // // Internal Events // //----------------------------------------------------- //------------------------------------------------------ // // Private Methods // //----------------------------------------------------- #region Private Methods // // Verify all the propety values set from project file. // If any input value is set wrongly, report appropriate build error // and return false. // private bool VerifyTaskInputs() { bool bValidInput = true; // // Verify different property values // // OutputType is marked as Required, it should never be null or emtpy. // otherwise, the task should have been failed before the code goes here. string targetType = OutputType.ToLowerInvariant( ); switch (targetType) { case SharedStrings.Library : case SharedStrings.Module : case SharedStrings.WinExe : case SharedStrings.Exe : break; default : Log.LogErrorWithCodeFromResources(SRID.TargetIsNotSupported, targetType); bValidInput = false; break; } // SourceFiles property is marked as Required. // MSBUILD Engine should have checked the setting for this property // so don't need to recheck here. if (TaskHelper.IsValidCultureName(Culture) == false) { Log.LogErrorWithCodeFromResources(SRID.InvalidCulture, Culture); bValidInput = false; } return bValidInput; } private void Classify(IEnumerableinputItems, List mainList, List satelliteList) { foreach (ITaskItem inputItem in inputItems) { ITaskItem outputItem = new TaskItem { ItemSpec = inputItem.ItemSpec, }; // Selectively copy metadata over. outputItem.SetMetadata(SharedStrings.Link, inputItem.GetMetadata(SharedStrings.Link)); if (IsItemLocalizable(inputItem)) { satelliteList.Add(outputItem); } else { mainList.Add(outputItem); } } } // // Check if the item is localizable or not. // // //private bool IsItemLocalizable(ITaskItem fileItem) { bool isLocalizable = false; // if the default culture is not set, by default all // the items are not localizable. if (Culture != null && Culture.Equals("") == false) { string localizableString; // Default culture is set, by default the item is localizable // unless it is set as false in the Localizable attribute. isLocalizable = true; localizableString = fileItem.GetMetadata(SharedStrings.Localizable); if (localizableString != null && String.Compare(localizableString, "false", StringComparison.OrdinalIgnoreCase) ==0 ) { isLocalizable = false; } } return isLocalizable; } #endregion Private Methods //----------------------------------------------------- // // Private Properties // //----------------------------------------------------- //------------------------------------------------------ // // Private Fields // //----------------------------------------------------- #region Private Fields private string _culture; private const string UnknownErrorID = "FC1000"; #endregion Private Fields } } // 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 MSBuild task that classify the input files to different // categories based on the input item's attributes. // // Spec: http://avalon/app/Compilation/Avalon-MSBUILD%20Targets.doc // // History: // 06/20/03: weibz rewrite and moved over to WCP tree // //--------------------------------------------------------------------------- using System; using System.IO; using System.Collections.Generic; using System.Globalization; using System.Diagnostics; using System.Reflection; using System.Resources; using System.Runtime.InteropServices; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using MS.Utility; using MS.Internal.Tasks; // Since we disable PreSharp warnings in this file, PreSharp warning is unknown to C# compiler. // We first need to disable warnings about unknown message numbers and unknown pragmas. #pragma warning disable 1634, 1691 namespace Microsoft.Build.Tasks.Windows { ////// The File Classification task puts all the input baml files, image files into different /// output resource groups, such as Resources for Main assembly and Resources for satellite /// assembly. /// public sealed class FileClassifier : Task { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors ////// Constrcutor /// public FileClassifier() : base(SR.ResourceManager) { // set default values for some non-required input items _culture = null; } #endregion Constructors //------------------------------------------------------ // // Public Methods // //----------------------------------------------------- #region Public Methods ////// ITask Execute method /// ///public override bool Execute() { bool ret = false; var mainEmbeddedList = new List (); var satelliteEmbeddedList = new List (); var clrEmbeddedResourceList = new List (); var clrSatelliteEmbeddedResourceList = new List (); try { TaskHelper.DisplayLogo(Log, SR.Get(SRID.FileClassifierTask)); ret = VerifyTaskInputs(); if (ret != false) { // Do the real work to classify input files. Classify(SourceFiles, mainEmbeddedList, satelliteEmbeddedList); if (CLRResourceFiles != null) { // Generate the output CLR embedded resource list. Classify(CLRResourceFiles, clrEmbeddedResourceList, clrSatelliteEmbeddedResourceList); } // move the arraylist to the TaskItem array. MainEmbeddedFiles = mainEmbeddedList.ToArray(); SatelliteEmbeddedFiles = satelliteEmbeddedList.ToArray(); CLREmbeddedResource = clrEmbeddedResourceList.ToArray(); CLRSatelliteEmbeddedResource = clrSatelliteEmbeddedResourceList.ToArray(); } } catch (Exception e) { // PreSharp Complaint 6500 - do not handle null-ref or SEH exceptions. if (e is NullReferenceException || e is SEHException) { throw; } else { 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); } return false; } #pragma warning disable 6500 catch // Non-CLS compliant errors { Log.LogErrorWithCodeFromResources(SRID.NonClsError); return false; } #pragma warning restore 6500 return ret; } #endregion Public Methods //------------------------------------------------------ // // Public Properties // //------------------------------------------------------ #region Public Properties /// /// SourceFiles: List of Items thatare to be classified /// [Required] public ITaskItem [] SourceFiles { get; set; } ////// Can have values (exe, or dll) /// [Required] public string OutputType { get; set; } ////// Culture of the build. Can be null if the build is non-localizable /// public string Culture { get { return _culture != null ? _culture.ToLower(CultureInfo.InvariantCulture) : null; } set { _culture = value; } } ////// The CLR resource file list. /// In Project file, those files will be define by type CLRResource. /// such as: ///- ///
public ITaskItem[] CLRResourceFiles { get; set; } /// /// Output Item list for the CLR resources that will be saved in /// the main assembly. /// ///[Output] public ITaskItem[] CLREmbeddedResource { get; set; } /// /// Output Item list for the CLR resources that will be saved in /// the satellite assembly. /// ///[Output] public ITaskItem[] CLRSatelliteEmbeddedResource { get; set; } /// /// MainEmbeddedFiles /// /// Non-localizable resources which will be embedded into the Main assembly. /// [Output] public ITaskItem [] MainEmbeddedFiles { get; set; } ////// SatelliteEmbeddedFiles /// /// Localizable files which are embedded to the Satellite assembly for the /// culture which is set in Culture property.. /// [Output] public ITaskItem [] SatelliteEmbeddedFiles { get; set; } #endregion Public Properties //----------------------------------------------------- // // Public Events // //------------------------------------------------------ //----------------------------------------------------- // // Protected Methods // //----------------------------------------------------- //----------------------------------------------------- // // Internal Methods // //------------------------------------------------------ //----------------------------------------------------- // // Internal Properties // //------------------------------------------------------ //------------------------------------------------------ // // Internal Events // //----------------------------------------------------- //------------------------------------------------------ // // Private Methods // //----------------------------------------------------- #region Private Methods // // Verify all the propety values set from project file. // If any input value is set wrongly, report appropriate build error // and return false. // private bool VerifyTaskInputs() { bool bValidInput = true; // // Verify different property values // // OutputType is marked as Required, it should never be null or emtpy. // otherwise, the task should have been failed before the code goes here. string targetType = OutputType.ToLowerInvariant( ); switch (targetType) { case SharedStrings.Library : case SharedStrings.Module : case SharedStrings.WinExe : case SharedStrings.Exe : break; default : Log.LogErrorWithCodeFromResources(SRID.TargetIsNotSupported, targetType); bValidInput = false; break; } // SourceFiles property is marked as Required. // MSBUILD Engine should have checked the setting for this property // so don't need to recheck here. if (TaskHelper.IsValidCultureName(Culture) == false) { Log.LogErrorWithCodeFromResources(SRID.InvalidCulture, Culture); bValidInput = false; } return bValidInput; } private void Classify(IEnumerableinputItems, List mainList, List satelliteList) { foreach (ITaskItem inputItem in inputItems) { ITaskItem outputItem = new TaskItem { ItemSpec = inputItem.ItemSpec, }; // Selectively copy metadata over. outputItem.SetMetadata(SharedStrings.Link, inputItem.GetMetadata(SharedStrings.Link)); if (IsItemLocalizable(inputItem)) { satelliteList.Add(outputItem); } else { mainList.Add(outputItem); } } } // // Check if the item is localizable or not. // // //private bool IsItemLocalizable(ITaskItem fileItem) { bool isLocalizable = false; // if the default culture is not set, by default all // the items are not localizable. if (Culture != null && Culture.Equals("") == false) { string localizableString; // Default culture is set, by default the item is localizable // unless it is set as false in the Localizable attribute. isLocalizable = true; localizableString = fileItem.GetMetadata(SharedStrings.Localizable); if (localizableString != null && String.Compare(localizableString, "false", StringComparison.OrdinalIgnoreCase) ==0 ) { isLocalizable = false; } } return isLocalizable; } #endregion Private Methods //----------------------------------------------------- // // Private Properties // //----------------------------------------------------- //------------------------------------------------------ // // Private Fields // //----------------------------------------------------- #region Private Fields private string _culture; private const string UnknownErrorID = "FC1000"; #endregion Private Fields } } // 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
- SecurityRuntime.cs
- PropertyKey.cs
- Rect3D.cs
- ResourceKey.cs
- HttpListenerException.cs
- InternalConfigSettingsFactory.cs
- Parser.cs
- SynchronizedInputPattern.cs
- CommandEventArgs.cs
- EntityDataSourceWrapperCollection.cs
- XDeferredAxisSource.cs
- ClientTargetSection.cs
- MediaPlayerState.cs
- ConnectionPoolRegistry.cs
- PackageProperties.cs
- StructuredTypeInfo.cs
- QueueException.cs
- ContentTypeSettingDispatchMessageFormatter.cs
- FileDialogPermission.cs
- RotateTransform3D.cs
- GifBitmapDecoder.cs
- CheckBoxDesigner.cs
- WindowsImpersonationContext.cs
- ValidatedControlConverter.cs
- HostingEnvironmentSection.cs
- DateTimeValueSerializerContext.cs
- SystemColors.cs
- CodeIterationStatement.cs
- NetDataContractSerializer.cs
- TreeNode.cs
- Claim.cs
- userdatakeys.cs
- StreamedFramingRequestChannel.cs
- XpsSerializerWriter.cs
- BindingCollection.cs
- DbProviderFactories.cs
- FreeFormDesigner.cs
- KerberosTicketHashIdentifierClause.cs
- RegionInfo.cs
- PrintDialog.cs
- ParserHooks.cs
- XmlSchemaSequence.cs
- CompilationLock.cs
- MetadataPropertyvalue.cs
- ToolboxItemAttribute.cs
- PopupRoot.cs
- EpmCustomContentDeSerializer.cs
- ResourceProviderFactory.cs
- HttpProtocolImporter.cs
- ParameterExpression.cs
- SocketInformation.cs
- PageContentAsyncResult.cs
- SqlHelper.cs
- selecteditemcollection.cs
- ImportContext.cs
- ParentQuery.cs
- Win32PrintDialog.cs
- SchemaCollectionPreprocessor.cs
- Regex.cs
- AlignmentXValidation.cs
- NestedContainer.cs
- MenuEventArgs.cs
- xml.cs
- Table.cs
- AnnotationHighlightLayer.cs
- ScrollBarRenderer.cs
- ResXDataNode.cs
- ExpressionBuilder.cs
- BuildTopDownAttribute.cs
- SystemColors.cs
- WebServiceResponse.cs
- CompositeDuplexBindingElement.cs
- HashMembershipCondition.cs
- Timer.cs
- RoleManagerSection.cs
- DockPattern.cs
- NumericUpDownAccelerationCollection.cs
- ADMembershipUser.cs
- InboundActivityHelper.cs
- PageAction.cs
- AssemblyAssociatedContentFileAttribute.cs
- FormViewDeleteEventArgs.cs
- MapPathBasedVirtualPathProvider.cs
- HttpModulesSection.cs
- PropertyItem.cs
- AnnotationAuthorChangedEventArgs.cs
- JoinCqlBlock.cs
- AppLevelCompilationSectionCache.cs
- ZipIOExtraFieldElement.cs
- WindowsListViewGroupHelper.cs
- FontStyle.cs
- OutputScopeManager.cs
- StyleXamlParser.cs
- HttpCapabilitiesSectionHandler.cs
- DataGridViewRowEventArgs.cs
- Pen.cs
- GridView.cs
- QueryConverter.cs
- BindingNavigator.cs
- DbMetaDataColumnNames.cs