public AssetResolverTests() { testVirtualPathProvider = new TestVirtualPathProvider(); bundleManager = new DefaultBundleManager(); bundleManager.VirtualPathProvider = testVirtualPathProvider; resolver = new AssetResolver(bundleManager); }
public static string[] GetSongNames() { return(new[] { AssetResolver.ResolveAsset(ModuleName, "alien_technology.mp3"), AssetResolver.ResolveAsset(ModuleName, "summer_shade.mp3") }); }
protected string ResolveAsset(string modName, string assetName) { if (GetType().IsSubclassOf(typeof(Tanks.Tank))) { return(AssetResolver.ResolveAsset(modName, assetName, ((Tanks.Tank) this).Player)); } return(AssetResolver.ResolveAsset(modName, assetName)); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var assets = AssetResolver.Resolve(new AssetResolutionContext( Assets, useBundledOutput: UseBundledOutput ?? Settings.UseBundledOutput, includeVersioning: UseVersioning ?? Settings.UseVersioning)); await ProcessStaticAssetTagAsync(context, output, assets); }
public void SetFixture(AssemblyFixture data) { ReflectionOnlyAssemblyLoader loader = new ReflectionOnlyAssemblyLoader(new MemoryCache("test"), new[] { Assembly.GetExecutingAssembly().Location }); foreach (Assembly assembly in data) { loader.Load(assembly.FullName); } this._resolver = new AssetResolver(loader); }
public void TestWithPackage() { var inputs = new List <AssetItem>(); var asset = new AssetObjectTest(); var package = new Package(); package.Assets.Add(new AssetItem("0", asset)); var session = new PackageSession(package); for (int i = 0; i < 10; i++) { var newAsset = new AssetObjectTest() { Id = asset.Id, Reference = new AssetReference(asset.Id, "bad") }; inputs.Add(new AssetItem("0", newAsset)); } // Tries to use existing ids var outputs = new List <AssetItem>(); AssetCollision.Clean(null, inputs, outputs, AssetResolver.FromPackage(package), true, false); // Make sure we are generating exactly the same number of elements Assert.Equal(inputs.Count, outputs.Count); // Make sure that asset has been cloned Assert.NotEqual(inputs[0], outputs[0]); // First Id should not change Assert.NotEqual(inputs[0].Id, outputs[0].Id); // Make sure that all ids are different var ids = new HashSet <AssetId>(outputs.Select(item => item.Id)); Assert.Equal(inputs.Count, ids.Count); // Make sure that all locations are different var locations = new HashSet <UFile>(outputs.Select(item => item.Location)); Assert.Equal(inputs.Count, locations.Count); // Reference location "bad"should be fixed to "0_1" pointing to the first element foreach (var output in outputs) { // Make sure of none of the locations are using "0" Assert.NotEqual((UFile)"0", output.Location); var assetRef = ((AssetObjectTest)output.Asset).Reference; Assert.Equal("0 (2)", assetRef.Location); Assert.Equal(outputs[0].Id, assetRef.Id); } }
public List <AssetViewModel> PasteAssets(List <AssetItem> assets, [CanBeNull] ProjectViewModel project) { var viewModels = new List <AssetViewModel>(); // Don't touch the action stack in this case. if (assets.Count == 0) { return(viewModels); } var fixedAssets = new List <AssetItem>(); using (var transaction = UndoRedoService.CreateTransaction()) { // Clean collision by renaming pasted asset if an asset with the same name already exists in that location. AssetCollision.Clean(null, assets, fixedAssets, AssetResolver.FromPackage(Package), false, false); // Temporarily add the new asset to the package fixedAssets.ForEach(x => Package.Assets.Add(x)); // Find which assets are referencing the pasted assets in order to fix the reference link. var assetsToFix = GetReferencers(Session.DependencyManager, Session, fixedAssets); // Remove temporarily added assets - they will be properly re-added with the correct action stack entry when creating the view model fixedAssets.ForEach(x => Package.Assets.Remove(x)); // Create directories and view models, actually add assets to package. foreach (var asset in fixedAssets) { var location = asset.Location.GetFullDirectory() ?? ""; var assetDirectory = project == null? GetOrCreateAssetDirectory(location, true) : project.GetOrCreateProjectDirectory(location, true); var assetViewModel = CreateAsset(assetDirectory, asset, true, null); viewModels.Add(assetViewModel); } // Fix references in the assets that references what we pasted. // We wrap this operation in an action item so the action stack can properly re-execute it. var fixReferencesAction = new FixAssetReferenceOperation(assetsToFix, false, true); fixReferencesAction.FixAssetReferences(); UndoRedoService.PushOperation(fixReferencesAction); UndoRedoService.SetName(transaction, "Paste assets"); } return(viewModels); }
public InlineStylesTests() { testVirtualPathProvider = new TestVirtualPathProvider(); bundleManager = new DefaultBundleManager(); bundleManager.VirtualPathProvider = testVirtualPathProvider; var context = new HttpContext(new HttpRequest(null, "http://tempuri.org", null), new HttpResponse(null)); //clear cache foreach (System.Collections.DictionaryEntry entry in context.Cache) { context.Cache.Remove((string)entry.Key); } bundleManager.Context = new HttpContextWrapper(context); resolver = new AssetResolver(bundleManager); TagContentBuilder.BundleManager = bundleManager; }
private protected override bool TryOpenSourceAsync( CancellationToken ct, int?targetWidth, int?targetHeight, out Task <ImageData> asyncImage) { if (WebUri is {} uri) { var hasFileScheme = uri.IsAbsoluteUri && uri.Scheme == "file"; // Local files are assumed as coming from the remote server var newUri = hasFileScheme switch { true => new Uri(uri.PathAndQuery.TrimStart('/'), UriKind.Relative), _ => uri }; asyncImage = AssetResolver.ResolveImageAsync(this, newUri, ScaleOverride); return(true); } if (_stream is {} stream) { void OnProgress(ulong position, ulong?length) { if (position > 0 && length is { } actualLength) { var percent = (int)((position / (float)actualLength) * 100); RaiseDownloadProgress(percent); } } var streamWithContentType = stream.TrySetContentType(ContentType); asyncImage = OpenFromStream(streamWithContentType, OnProgress, ct); return(true); } asyncImage = default; return(false); }
private protected override bool TryOpenSourceAsync(int?targetWidth, int?targetHeight, out Task <ImageData> asyncImage) { var uri = WebUri; if (uri != null) { var hasFileScheme = uri.IsAbsoluteUri && uri.Scheme == "file"; // Local files are assumed as coming from the remote server var newUri = hasFileScheme switch { true => new Uri(uri.PathAndQuery.TrimStart('/'), UriKind.Relative), _ => uri }; asyncImage = AssetResolver.ResolveImageAsync(newUri, ScaleOverride); return(true); } asyncImage = default; return(false); }
public AssetResolverTests() { List<Assembly> assemblies = new List<Assembly>(); assemblies.Add(Assembly.GetExecutingAssembly()); AssemblyName[] names = Assembly.GetExecutingAssembly().GetReferencedAssemblies(); assemblies.AddRange(names.Select(an => { Assembly asm = AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault( a => a. GetName (). FullName == an. FullName); return asm ?? Assembly.Load(an); })); this._resolver = new AssetResolver(assemblies); }
public void ValidateAssets(bool alwaysGenerateNewAssetId = false) { if (TemporaryAssets.Count == 0) { return; } try { // Make sure we are suspending notifications before updating all assets Assets.SuspendCollectionChanged(); Assets.Clear(); // Get generated output items var outputItems = new AssetItemCollection(); // Create a resolver from the package var resolver = AssetResolver.FromPackage(this); resolver.AlwaysCreateNewId = alwaysGenerateNewAssetId; // Clean assets AssetCollision.Clean(TemporaryAssets, outputItems, resolver, false); // Add them back to the package foreach (var item in outputItems) { Assets.Add(item); } TemporaryAssets.Clear(); } finally { // Restore notification on assets Assets.ResumeCollectionChanged(); } }
/// <summary> /// Performs the NuGet package resolution. /// </summary> public override bool Execute() { var analyzers = new List <ITaskItem>(); var references = new List <ITaskItem>(); var copyLocals = new List <ITaskItem>(); if (PackagesConfigs == null || PackagesConfigs.Length == 0) { Log.LogError("PackagesConfigs property not specified."); return(false); } if (PackagesConfigs.Any(pc => string.IsNullOrWhiteSpace(pc.ItemSpec))) { Log.LogError("A PackagesConfigs element was not specified."); } ITaskItem packagesConfigNotFound = PackagesConfigs.FirstOrDefault(pc => !File.Exists(pc.ItemSpec)); if (packagesConfigNotFound != default(ITaskItem)) { Log.LogError("File '{0}' not found.", packagesConfigNotFound.ItemSpec); return(false); } var targetFrameworks = new List <FrameworkName>(); var targetFramework = new FrameworkName(TargetFramework); if (targetFramework.Identifier == ".NETPortable") { // Let's convert var folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Reference Assemblies\Microsoft\Framework\.NETPortable", "v" + targetFramework.Version, "Profile", targetFramework.Profile, "SupportedFrameworks"); if (Directory.Exists(folder)) { foreach (var framework in Directory.EnumerateFiles(folder, "*.xml")) { var xml = XDocument.Load(framework).Root; targetFrameworks.Add(new FrameworkName(xml.Attribute("Identifier").Value, Version.Parse(xml.Attribute("MinimumVersion").Value))); } } else { // If the portable profile doesn't exist lets fallback to the default for Profile7. targetFrameworks.Add(new FrameworkName(".NETFramework", new Version(4, 5))); targetFrameworks.Add(new FrameworkName(".NETCore", new Version(4, 5))); } } else { targetFrameworks.Add(targetFramework); } var context = AssetResolutionContext.Empty .WithTargetFrameworks(new FrameworkNameSet(targetFrameworks)) .WithArchitecture(Platform ?? "") .WithAssemblyAssetTypes() .RegisterProperty("ProjectType", new LanguagePropertyDefinition()) .SetProperty("ProjectType", Language) .RegisterProperty("DesignTimeOnly", new AnythingGoesPropertyDefinition()) .SetProperty("DesignTimeOnly", "true") .RegisterAssetType("Analyzer"); var platformNames = new List <PlatformName>(); PlatformName singularPlatformName; if (PlatformName.TryParse(TargetPlatformMoniker, out singularPlatformName)) { platformNames.Add(singularPlatformName); } if (platformNames.Any()) { context = context.WithTargetPlatforms(new PlatformNameSet(platformNames)); } var resolver = new AssetResolver(context); var packagesConfigs = (from packageConfig in PackagesConfigs select new PackageReferenceFile(Path.GetFullPath(packageConfig.ItemSpec))).ToArray(); var succeeded = true; var repository = new SharedPackageRepository(PackageRoot); foreach (var packageReference in GetPackageReferences(packagesConfigs)) { IPackage package; if (!repository.TryFindPackage(packageReference.Id, packageReference.Version, out package)) { Log.LogError("Unable to find nupkg for {0}.", packageReference.Id); succeeded = false; continue; } var packageDescription = packageReference.Id + "." + packageReference.Version.ToString(); var manifest = ManifestDeclaration.Parse(Path.Combine(PackageRoot, packageDescription), package); // If there are no assets we cannot if (!manifest.Groups.Any()) { Log.LogMessage("no assets for " + packageDescription); continue; } try { Log.LogMessage("resolving assets for " + packageDescription); var assets = resolver.Resolve(manifest); foreach (var asset in assets) { switch (asset.Type) { case "Analyzer": analyzers.Add(new TaskItem(asset.Value)); Log.LogMessage("resolved analyzer: " + asset.Value); break; case WellKnownAssetType.ReferenceOnly: { var taskItem = new TaskItem(asset.Value); taskItem.SetMetadata("NuGetPackageId", packageReference.Id); taskItem.SetMetadata("NuGetPackageVersion", packageReference.Version.ToString()); taskItem.SetMetadata("ReferenceGrouping", packageReference.Id + ",Version=" + packageReference.Version.Version); taskItem.SetMetadata("ReferenceGroupingDisplayName", packageReference.Id); taskItem.SetMetadata("Private", "false"); references.Add(taskItem); Log.LogMessage("resolved reference: " + asset.Value); break; } case WellKnownAssetType.CopyLocal: { var taskItem = new TaskItem(asset.Value); taskItem.SetMetadata("CopyToOutputDirectory", "PreserveNewest"); copyLocals.Add(taskItem); Log.LogMessage("resolved copylocal: " + asset.Value); break; } } } } catch (AssetResolutionException ex) { Log.LogWarning("Unable to resolve the assets of {0}: {1}", packageReference.Id, ex.Message); } } ResolvedAnalyzers = analyzers.ToArray(); ResolvedReferences = references.ToArray(); ResolvedCopyLocal = copyLocals.ToArray(); return(succeeded); }