Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- LocationFactory.cs
- LateBoundChannelParameterCollection.cs
- ListMarkerLine.cs
- ZipIOExtraFieldPaddingElement.cs
- GenericQueueSurrogate.cs
- SafeIUnknown.cs
- SqlNodeTypeOperators.cs
- xml.cs
- ProfilePropertySettingsCollection.cs
- LicenseException.cs
- XamlWriter.cs
- MessageQueuePermissionEntryCollection.cs
- XmlSchemaInferenceException.cs
- SqlSupersetValidator.cs
- TextDecorationUnitValidation.cs
- ContentElementAutomationPeer.cs
- SqlMethods.cs
- FaultDesigner.cs
- CorrelationActionMessageFilter.cs
- StrokeIntersection.cs
- Vector3DAnimation.cs
- SectionRecord.cs
- TripleDESCryptoServiceProvider.cs
- CompilerGeneratedAttribute.cs
- UnwrappedTypesXmlSerializerManager.cs
- EntityViewGenerationConstants.cs
- ProvidePropertyAttribute.cs
- FrameworkTextComposition.cs
- ContainerCodeDomSerializer.cs
- ElementNotAvailableException.cs
- PersonalizationProvider.cs
- AttachmentService.cs
- DeriveBytes.cs
- SequentialUshortCollection.cs
- ConfigurationManagerHelper.cs
- ControlPaint.cs
- SerializationSectionGroup.cs
- QilList.cs
- EntityContainer.cs
- FormViewDeleteEventArgs.cs
- RequiredFieldValidator.cs
- UnsafeNativeMethods.cs
- OrderByExpression.cs
- Rules.cs
- IntPtr.cs
- SoapWriter.cs
- COM2TypeInfoProcessor.cs
- OdbcCommand.cs
- BinaryCommonClasses.cs
- TemplateBindingExtension.cs
- WorkflowRuntimeService.cs
- CodeDOMUtility.cs
- HighlightComponent.cs
- TypeNameConverter.cs
- PropertyGridView.cs
- ComponentChangingEvent.cs
- RemoteWebConfigurationHost.cs
- ImageClickEventArgs.cs
- AttachInfo.cs
- ConfigXmlText.cs
- RelationshipType.cs
- AttributeSetAction.cs
- WindowsProgressbar.cs
- RectangleGeometry.cs
- DataGridViewRowPostPaintEventArgs.cs
- BridgeDataReader.cs
- Hashtable.cs
- ArcSegment.cs
- BuildProviderCollection.cs
- CodeObjectCreateExpression.cs
- Stopwatch.cs
- DataGridViewCellEventArgs.cs
- XmlQueryCardinality.cs
- NamespaceListProperty.cs
- PngBitmapEncoder.cs
- DmlSqlGenerator.cs
- BuildProvidersCompiler.cs
- ExtentJoinTreeNode.cs
- PasswordTextNavigator.cs
- Int32CAMarshaler.cs
- FloaterParagraph.cs
- SelectionPatternIdentifiers.cs
- ArraySubsetEnumerator.cs
- XmlAttributes.cs
- BooleanProjectedSlot.cs
- CatalogPartCollection.cs
- WmlListAdapter.cs
- WriterOutput.cs
- SystemPens.cs
- ControlCollection.cs
- DoubleAnimationBase.cs
- ContextInformation.cs
- GridViewUpdatedEventArgs.cs
- DataPagerCommandEventArgs.cs
- ServiceNameElement.cs
- followingquery.cs
- NavigationPropertyEmitter.cs
- _ShellExpression.cs
- ThreadSafeList.cs
- GCHandleCookieTable.cs