public bool AddReference(string assetId) { if (string.IsNullOrEmpty(assetId)) { throw new ArgumentException("Argument cannot be null or empty.", "assetId"); } AssetIdentifier aid = AssetIdentifier.Parse(assetId); Debug.Assert(aid.ToString().Equals(assetId, StringComparison.Ordinal), "AssetIdentifier '{0}' failed to roundtrip.", assetId); if (aid.AssetId[aid.AssetId.Length - 1] == ']') { aid = new AssetIdentifier(aid.AssetId.Substring(0, aid.AssetId.LastIndexOf('[')), aid.Version); } object resolve = this.AssetResolver.Resolve(aid); Debug.Assert(resolve != null); Debug.Assert(!string.IsNullOrWhiteSpace(aid.AssetId)); if (this._references.Add(aid)) { TraceSources.GeneratorSource.TraceEvent(TraceEventType.Verbose, 1, "Reference: {0}", aid); return(true); } return(false); }
public LostDocFileInfo(string path) { this._assemblies = new List <AssemblyInfo>(); this.Path = path; XDocument xDoc = XDocument.Load(path); foreach (XElement asmElement in xDoc.Root.Elements("assembly")) { // name="Company.Project.AnotherLibrary" filename="Company.Project.AnotherLibrary.dll" assetId="{A:Company.Project.AnotherLibrary, V:2.1.3.5670}" this._assemblies.Add(new AssemblyInfo { Name = asmElement.Attribute("name").Value, Filename = asmElement.Attribute("filename").Value, AssetId = AssetIdentifier.Parse(asmElement.Attribute("assetId").Value), Phase = int.Parse(asmElement.Attribute("phase").Value, CultureInfo.InvariantCulture), }); } }
public XDocument Merge(out AssetRedirectCollection assetRedirects) { // merge assemblies Func <AssetIdentifier, string> keySelector; assetRedirects = new AssetRedirectCollection(); if (this._ignoreVersionComponent.HasValue) { TraceSources.BundleSource.TraceInformation("Merging assembly sections with version mask: {0}", this._ignoreVersionComponent.Value.ToString()); keySelector = aId => string.Format("{0}, {1}", aId.AssetId, aId.Version.ToString((int)this._ignoreVersionComponent.Value)); IEnumerable <XElement> allAssemblies = this._bundle.Root.XPathSelectElements("assembly[@phase = '0']"); foreach (XElement asm in allAssemblies) { Debug.WriteLine(keySelector(AssetIdentifier.Parse(asm.Attribute("assetId").Value))); } IEnumerable <IOrderedEnumerable <XElement> > groupedAssemblies = allAssemblies.GroupBy(xe => keySelector(AssetIdentifier.Parse(xe.Attribute("assetId").Value)), (key, grp) => grp.OrderByDescending( xe => AssetIdentifier.Parse(xe.Attribute("assetId").Value). Version)); foreach (IOrderedEnumerable <XElement> assemblyGroup in groupedAssemblies) { XElement primary = assemblyGroup.First(); IEnumerable <XElement> rest = assemblyGroup.Skip(1); IEnumerable <XAttribute> assetAttrs = ((IEnumerable)primary.XPathEvaluate(".//@assetId")).Cast <XAttribute>(); Dictionary <string, AssetIdentifier> assets = assetAttrs.Select(a => AssetIdentifier.Parse(a.Value)).ToDictionary(a => a.AssetId); TraceSources.BundleSource.TraceInformation("Primary assembly: " + primary.Attribute("assetId").Value); foreach (XElement secondary in rest) { TraceSources.BundleSource.TraceInformation("Shadowed assembly: " + secondary.Attribute("assetId").Value); secondary.Remove(); IEnumerable <XAttribute> secondaryAssetAttrs = ((IEnumerable)secondary.XPathEvaluate(".//@assetId")).Cast <XAttribute>(); IEnumerable <AssetIdentifier> secondaryAssets = secondaryAssetAttrs.Select(a => AssetIdentifier.Parse(a.Value)); foreach (AssetIdentifier asset in secondaryAssets) { AssetIdentifier primaryAsset; if (assets.TryGetValue(asset.AssetId, out primaryAsset)) { assetRedirects.Add(asset, primaryAsset); } else { // warnings, we merged and lost an asset! TraceSources.BundleSource.TraceWarning( "Failed to redirect asset {0}, no matching asset found in assembly {1}", asset.ToString(), primary.Attribute("assetId")); } } } } } TraceSources.BundleSource.TraceInformation("Sorting assemblies by version."); XElement[] asmElements = this._bundle.Root.Elements().OrderByDescending( e => AssetIdentifier.Parse(e.Attribute("assetId").Value). Version).ToArray(); this._bundle.Root.RemoveNodes(); this._bundle.Root.Add(asmElements); return(this._bundle); }