public MinifyFileCommand(IContentType contentType, MinifyCommandId id) { Mef.SatisfyImportsOnce(this); ContentType = contentType; _sourceExtensions = FileExtensionRegistry.GetFileExtensionSet(contentType); Command = new OleMenuCommand((s, e) => Execute(), new CommandID(CommandGuids.guidMinifyCmdSet, (int)id)); Command.BeforeQueryStatus += (s, e) => CheckVisible(); }
public void RemoveContentType(string typeName) { lock (this.syncLock) { // Make sure first the content type map is built BuildContentTypes(); } // Since file extension registry will call back the content type registry when it gets initialized, // make sure we force the initialization before obtaining the lock. This will guarantee we won't deadlock // when we'll ask the registered extension later, after we obtained the content types lock FileExtensionRegistry.GetContentTypeForExtension(""); string uppercaseTypeName = typeName.ToUpperInvariant(); lock (this.syncLock) { ContentTypeImpl type = null; if (!this.contentTypes.TryGetValue(uppercaseTypeName, out type)) { // If the type was not registered, removal is successful return; } // Check if the type to be removed is not the Unknown content type if (uppercaseTypeName == ContentTypeRegistryImpl.UnknownContentTypeName) { throw new InvalidOperationException(Strings.ContentTypeRegistry_CannotRemoveTheUnknownType); } // Check if the type is base type for another registered type ContentTypeImpl derivedType; if (IsBaseType(type, out derivedType)) { throw new InvalidOperationException(String.Format(System.Globalization.CultureInfo.CurrentUICulture, Strings.ContentTypeRegistry_CannotRemoveBaseType, type.TypeName, derivedType.TypeName)); } // If there are file extensions using this content type we won't allow removing it IEnumerable <string> extensions = FileExtensionRegistry.GetExtensionsForContentType(type); if (extensions != null && extensions.GetEnumerator().MoveNext()) { throw new InvalidOperationException(String.Format(System.Globalization.CultureInfo.CurrentUICulture, Strings.ContentTypeRegistry_CannotRemoveTypeUsedByFileExtensions, type.TypeName)); } // Remove the content type this.contentTypes.Remove(uppercaseTypeName); } }
private async Task Minify() { _dte.StatusBar.Text = "Web Essentials: Minifying files..."; var extensions = new HashSet <string>( Mef.GetSupportedExtensions <IFileMinifier>(), StringComparer.OrdinalIgnoreCase ); var files = ProjectHelpers.GetAllProjects() .Select(ProjectHelpers.GetRootFolder) .SelectMany(p => Directory.EnumerateFiles(p, "*", SearchOption.AllDirectories)) .Where(f => extensions.Contains(Path.GetExtension(f))); await Task.WhenAll(files.AsParallel().Select(async file => await MinificationSaveListener.ReMinify( FileExtensionRegistry.GetContentTypeForExtension(Path.GetExtension(file).TrimStart('.')), file, false ))); WebEssentialsPackage.DTE.StatusBar.Clear(); }