public override void HandleRequest(IRequestContext ctx) { string v; if (!ctx.UrlVariables.TryGetValue(RcParam, out v)) { v = ctx.QueryString[RcParam]; } if (v == null || v.Length == 0) { v = "index.htm"; } string rc = ResourcePrefix + "." + v; log.Debug("Servlet {0} trying to load {1}", MatchUrl, rc); ctx.ResponseContentType = MimeTypes.GetMimeTypeForExtension(Path.GetExtension(v)); using (Stream stm = SourceAssembly.GetManifestResourceStream(ResourcePrefix + "." + v)) { if (stm == null) { throw new NotFoundException(); } CopyStream(stm, ctx.OutputStream); } }
public void DeduplicatesReferencedAssemblies() { var assembly1a = new SourceAssembly( QualifiedName("1"), version: new Version(1, 0, 0), ImmutableArray <IAssembly> .Empty, ImmutableArray <IDocument> .Empty, new MockAssemblyCompiler()); var assembly1b = new SourceAssembly( QualifiedName("1"), version: new Version(1, 0, 0), ImmutableArray <IAssembly> .Empty, ImmutableArray <IDocument> .Empty, new MockAssemblyCompiler()); var assembly2 = new SourceAssembly( QualifiedName("2"), version: new Version(1, 0, 0), ImmutableArray.Create <IAssembly>(assembly1a), ImmutableArray <IDocument> .Empty, new MockAssemblyCompiler()); var assembly3 = new SourceAssembly( QualifiedName("3"), version: new Version(1, 0, 0), ImmutableArray.Create <IAssembly>(assembly1b), ImmutableArray <IDocument> .Empty, new MockAssemblyCompiler()); var assembly = (IAssembly) new SourceAssembly( QualifiedName("TestAssembly"), version: new Version(1, 0, 0), ImmutableArray.Create <IAssembly>(assembly2, assembly3), ImmutableArray <IDocument> .Empty, new MockAssemblyCompiler()); Assert.Equal(new[] { assembly1a, assembly2, assembly3, assembly }, assembly.ReferencedAssembliesAndSelf); }
private Assembly LoadThemePartAssembly() { try { var stream = SourceAssembly.GetResourceStream(ZipUri); using var archive = new ZipArchive(stream); foreach (var entry in archive.Entries) { if (!entry.Name.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) { continue; } using var entryStream = entry.Open(); using var ms = new MemoryStream(); entryStream.CopyTo(ms); return(Assembly.Load(ms.ToArray())); } return(null); } catch (Exception e) { LogService.LogError(e); return(null); } }
public void CanReadDependencies() { var dep1Name = "a1"; var dep2Name = "a2"; var dep1Version = new Version(1, 2, 3); var dep2Version = new Version(4, 5, 6, "alpha1"); var dep1 = new SourceAssembly( QualifiedName(dep1Name), dep1Version, ImmutableArray <IAssembly> .Empty, ImmutableArray <IDocument> .Empty, _assemblyCompiler); var dep2 = new SourceAssembly( QualifiedName(dep2Name), dep2Version, ImmutableArray <IAssembly> .Empty, ImmutableArray <IDocument> .Empty, _assemblyCompiler); var assembly = new SourceAssembly( QualifiedName("a"), new Version(0, 0, 0), ImmutableArray.Create <IAssembly>(dep1, dep2), ImmutableArray <IDocument> .Empty, _assemblyCompiler); assembly.VerifyDiagnostics().VerifyEmit( testEmittedAssembly: (_, a, _1) => Assert.Equal(new[] { new Dependency(dep1Name, dep1Version.ToString()), new Dependency(dep2Name, dep2Version.ToString()) }, new DependencyAttributeReader().ReadDependencies(a))); }
/// <summary> /// Initializes a new instance of the <see cref="ZpCodedException"/> class. /// </summary> /// <param name="aSourceAssembly">A source assembly.</param> /// <param name="aMessage">A message.</param> /// <param name="aMessageCode">A message code.</param> /// <param name="aMethodCode">A method code.</param> /// <param name="aObjectCode">A object code.</param> /// <param name="aInnerException">A inner exception.</param> public ZpCodedException(SourceAssembly aSourceAssembly, string aMessage, string aMessageCode, string aMethodCode, string aObjectCode, Exception aInnerException) : base(aMessage, aInnerException) { _sourceAssembly = aSourceAssembly; _messageCode = aMessageCode; _methodCode = aMethodCode; _objectCode = aObjectCode; }
/// <summary> /// Initializes a new instance of the <see cref="ZpCodedException"/> class. /// </summary> /// <param name="aSourceAssembly">A source assembly.</param> /// <param name="aMessage">A message.</param> /// <param name="aMessageCode">A message code.</param> /// <param name="aMethodCode">A method code.</param> /// <param name="aObjectCode">A object code.</param> /// <param name="aInnerException">A inner exception.</param> public ZpCodedException(SourceAssembly aSourceAssembly, string aMessage, string aMessageCode, string aMethodCode, string aObjectCode, Exception aInnerException) : base(aMessage, aInnerException) { _sourceAssembly = aSourceAssembly; _messageCode = aMessageCode; _methodCode = aMethodCode; _objectCode = aObjectCode; }
/// <summary> /// This method loads all the relationship type that this entity takes part in /// </summary> private void LoadRelationshipTypes() { foreach ( EdmRelationshipAttribute roleAttribute in SourceAssembly.GetCustomAttributes(typeof(EdmRelationshipAttribute), false /*inherit*/)) { // Check if there is an entry already with this name if (TryFindNullParametersInRelationshipAttribute(roleAttribute)) { // don't give more errors for these same bad parameters continue; } var errorEncountered = false; // return error if the role names are the same if (roleAttribute.Role1Name == roleAttribute.Role2Name) { SessionData.EdmItemErrors.Add( new EdmItemError( Strings.SameRoleNameOnRelationshipAttribute(roleAttribute.RelationshipName, roleAttribute.Role2Name))); errorEncountered = true; } if (!errorEncountered) { var associationType = new AssociationType( roleAttribute.RelationshipName, roleAttribute.RelationshipNamespaceName, roleAttribute.IsForeignKey, DataSpace.OSpace); SessionData.TypesInLoading.Add(associationType.FullName, associationType); TrackClosure(roleAttribute.Role1Type); TrackClosure(roleAttribute.Role2Type); // prevent lifting of loop vars var r1Name = roleAttribute.Role1Name; var r1Type = roleAttribute.Role1Type; var r1Multiplicity = roleAttribute.Role1Multiplicity; AddTypeResolver( () => ResolveAssociationEnd(associationType, r1Name, r1Type, r1Multiplicity)); // prevent lifting of loop vars var r2Name = roleAttribute.Role2Name; var r2Type = roleAttribute.Role2Type; var r2Multiplicity = roleAttribute.Role2Multiplicity; AddTypeResolver( () => ResolveAssociationEnd(associationType, r2Name, r2Type, r2Multiplicity)); // get assembly entry and add association type to the list of types in the assembly Debug.Assert( !CacheEntry.ContainsType(associationType.FullName), "Relationship type must not be present in the list of types"); CacheEntry.TypesInAssembly.Add(associationType); } } }
private string[] ExtractSourceAssemblies() { List <string> srcAssemblies = new List <string>(); if (AdditionalSourceAssemblies != null) { srcAssemblies.AddRange(AdditionalSourceAssemblies.Select(c => c.ItemSpec)); } if (SourceAssembly != null) { srcAssemblies.AddRange(SourceAssembly.Select(c => Path.Combine(ProjectRoot, c.ItemSpec))); } return(srcAssemblies.ToArray()); }
/// <summary> /// Initializes a new instance of the <see cref="ZpCodedException"/> class. /// </summary> /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param> /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is null. </exception> /// <exception cref="T:System.Runtime.Serialization.SerializationException">The class name is null or <see cref="P:System.Exception.HResult"/> is zero (0). </exception> protected ZpCodedException(SerializationInfo info, StreamingContext context) : base(info, context) { if (info == null) { return; } _sourceAssembly = (SourceAssembly)info.GetInt32("_sourceAssembly"); _messageCode = info.GetString("_messageCode"); _methodCode = info.GetString("_methodCode"); _objectCode = info.GetString("_objectCode"); _messagePairList = (List <MessagePair>)info.GetValue("_messagePairList", typeof(List <MessagePair>)); }
protected override void LoadTypesFromAssembly() { foreach (var type in SourceAssembly.GetAccessibleTypes()) { EdmType cspaceType; if (TryGetCSpaceTypeMatch(type, out cspaceType)) { if (type.IsValueType && !type.IsEnum) { SessionData.LoadMessageLogger.LogLoadMessage( Strings.Validator_OSpace_Convention_Struct(cspaceType.FullName, type.FullName), cspaceType); continue; } EdmType ospaceType; if (TryCreateType(type, cspaceType, out ospaceType)) { Debug.Assert( ospaceType is StructuralType || Helper.IsEnumType(ospaceType), "Only StructuralType or EnumType expected."); CacheEntry.TypesInAssembly.Add(ospaceType); // check for duplicates so we don't cause an ArgumentException, // Mapping will do the actual error for the duplicate type later if (!SessionData.CspaceToOspace.ContainsKey(cspaceType)) { SessionData.CspaceToOspace.Add(cspaceType, ospaceType); } else { // at this point there is already a Clr Type that is structurally matched to this CSpace type, we throw exception var previousOSpaceType = SessionData.CspaceToOspace[cspaceType]; SessionData.EdmItemErrors.Add( new EdmItemError( Strings.Validator_OSpace_Convention_AmbiguousClrType( cspaceType.Name, previousOSpaceType.ClrType.FullName, type.FullName))); } } } } if (SessionData.TypesInLoading.Count == 0) { Debug.Assert(CacheEntry.ClosureAssemblies.Count == 0, "How did we get closure assemblies?"); // since we didn't find any types, don't lock into convention based SessionData.ObjectItemAssemblyLoaderFactory = null; } }
/// <summary> /// Assigns the fields and properties of aSource to this instance. /// </summary> /// <param name="aSource">A source TransactionStatus.</param> public void AssignFromSource(TransactionStatus aSource) { if (aSource == null) { return; } _transactionResult = aSource._transactionResult; _sourceAssembly = aSource._sourceAssembly; _targetUrl = aSource._targetUrl; _message = aSource._message; _innerMessage = aSource._innerMessage; aSource._messagePairList.ForEach(vSourceMessagePair => { var vTargetMessagePair = new MessagePair(vSourceMessagePair.Message, vSourceMessagePair.Subject); _messagePairList.Add(vTargetMessagePair); }); }
// <summary> // Loads the set of types from the given assembly and adds it to the given list of types // </summary> protected override void LoadTypesFromAssembly() { Debug.Assert(CacheEntry.TypesInAssembly.Count == 0); LoadRelationshipTypes(); // Loop through each type in the assembly and process it foreach (var type in SourceAssembly.GetAccessibleTypes()) { // If the type doesn't have the same EdmTypeAttribute defined, then it's not a special type // that we care about, skip it. if (!type.GetCustomAttributes <EdmTypeAttribute>(inherit: false).Any()) { continue; } // Generic type is not supported, if the user attributed this generic type using EdmTypeAttribute, // then the exception message can help them better understand what is going on instead of just // failing at a much later point of OC type mapping lookup with a super generic error message if (type.IsGenericType()) { SessionData.EdmItemErrors.Add(new EdmItemError(Strings.GenericTypeNotSupported(type.FullName))); continue; } // Load the metadata for this type LoadType(type); } if (_referenceResolutions.Count != 0) { SessionData.RegisterForLevel1PostSessionProcessing(this); } if (_unresolvedNavigationProperties.Count != 0) { SessionData.RegisterForLevel2PostSessionProcessing(this); } }
public void ErrorsIfReferencedAssembliesContainDifferentVersionOfSameAssembly() { var assembly1a = new SourceAssembly( QualifiedName("1"), version: new Version(1, 0, 0), ImmutableArray <IAssembly> .Empty, ImmutableArray <IDocument> .Empty, new MockAssemblyCompiler()); var assembly1b = new SourceAssembly( QualifiedName("1"), version: new Version(1, 0, 1), ImmutableArray <IAssembly> .Empty, ImmutableArray <IDocument> .Empty, new MockAssemblyCompiler()); new SourceAssembly( QualifiedName("TestAssembly"), version: new Version(1, 0, 0), ImmutableArray.Create <IAssembly>(assembly1a, assembly1b), ImmutableArray <IDocument> .Empty, new MockAssemblyCompiler()).VerifyDiagnostics( new Diagnostic(new Location(new TextToken(@"")), ErrorCode.MultipleVersionsOfSameAssembly)); }
/// <summary> /// Assigns the fields and properties of aSource to this instance. /// </summary> /// <param name="aSource">A source TransactionStatus.</param> public void AssignFromSource(TransactionStatus aSource) { if (aSource == null) { return; } _transactionResult = aSource._transactionResult; _sourceAssembly = aSource._sourceAssembly; _targetUrl = aSource._targetUrl; _message = aSource._message; _innerMessage = aSource._innerMessage; aSource._messagePairList.ForEach(vSourceMessagePair => { var vTargetMessagePair = new MessagePair(vSourceMessagePair.Message, vSourceMessagePair.Subject); _messagePairList.Add(vTargetMessagePair); }); }
/// <summary> /// Initializes a new instance of the <see cref="ZpCodedException"/> class. /// </summary> /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param> /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is null. </exception> /// <exception cref="T:System.Runtime.Serialization.SerializationException">The class name is null or <see cref="P:System.Exception.HResult"/> is zero (0). </exception> protected ZpCodedException(SerializationInfo info, StreamingContext context) : base(info, context) { if (info == null) return; _sourceAssembly = (SourceAssembly)info.GetInt32("_sourceAssembly"); _messageCode = info.GetString("_messageCode"); _methodCode = info.GetString("_methodCode"); _objectCode = info.GetString("_objectCode"); _messagePairList = (List<MessagePair>)info.GetValue("_messagePairList", typeof(List<MessagePair>)); }