private static void RunRegisterCompositionListener(CompositionCommandInfo info, XmlProcessingContext xmlProcessingContext) { if (!(info is RegisterCompositionListenerInfo registerCompositionListenerInfo)) { throw new ArgumentException("Invalid runner input type: error in static setup."); } var listener = XmlValueParser.ParseValue(registerCompositionListenerInfo.XElements, registerCompositionListenerInfo.XAttributes, xmlProcessingContext); if (listener == null) { xmlProcessingContext.ReportError("Provided value is null for registering composition listeners."); return; } if (!(listener is ICompositionListener compositionListener)) { xmlProcessingContext.ReportError( "Registering composition listeners are only allowed for ICompositionListener implementations. Provided type: " + listener.GetType().FullName); return; } xmlProcessingContext.ComponentContext.RegisterCompositionListener(registerCompositionListenerInfo.Name, compositionListener); }
private static void RunUnregisterFamily(CompositionCommandInfo info, XmlProcessingContext xmlProcessingContext) { if (!(info is UnregisterFamilyInfo unregisterFamilyInfo)) { throw new ArgumentException("Invalid runner input type: error in static setup."); } var contractType = SimpleTypeParserUtil.ParseType(unregisterFamilyInfo.ContractType, xmlProcessingContext); if (contractType == null) { xmlProcessingContext.ReportError($"Type '{unregisterFamilyInfo.ContractType}' could not be loaded."); return; } xmlProcessingContext.ComponentContext.UnregisterFamily(contractType); }
public static void ApplyCompositionInfo(CompositionInfo info, XmlProcessingContext xmlProcessingContext) { if (info.CommandInfos == null) { return; } foreach (var commandInfo in info.CommandInfos) { if (!Runners.ContainsKey(commandInfo.GetType())) { throw new CompositionException("Provided type is not supported for applying to a component context: " + commandInfo.GetType().FullName); } var runner = Runners[commandInfo.GetType()]; try { xmlProcessingContext.EnterRunningLocation("Processing '" + commandInfo + "'"); runner(commandInfo, xmlProcessingContext); xmlProcessingContext.LeaveRunningLocation(); } catch (Exception e) { // Ignore the exception if the "IgnoreOnError" property is set. // If not, just report the exception (in case it happened in an // include command) and let it bubble up. if (!commandInfo.IgnoreOnError) { // TODO: Fix logging / tracing mechanism xmlProcessingContext.ReportError("Exception: " + e.Message); throw; } // If exception has occured, then the "LeaveRunningLocation" // method is not executed in the "try" block, so call it here. xmlProcessingContext.LeaveRunningLocation(); } } }
private static void RunUnregister(CompositionCommandInfo info, XmlProcessingContext xmlProcessingContext) { var unregisterInfo = info as UnregisterInfo; if (unregisterInfo == null) { throw new ArgumentException("Invalid runner input type: error in static setup."); } var contractType = SimpleTypeParserUtil.ParseType(unregisterInfo.ContractType, xmlProcessingContext); if (contractType == null) { xmlProcessingContext.ReportError(string.Format("Type '{0}' could not be loaded.", unregisterInfo.ContractType)); return; } var contractIdentity = new ContractIdentity(contractType, unregisterInfo.ContractName); xmlProcessingContext.ComponentContext.Unregister(contractIdentity); }
private static void RunRemoteComponent(CompositionCommandInfo info, XmlProcessingContext xmlProcessingContext) { if (!(info is RemoteComponentInfo remoteComponentInfo)) { throw new ArgumentException("Invalid runner input type: error in static setup."); } // Extract and load contract type var contractType = SimpleTypeParserUtil.ParseType(remoteComponentInfo.ContractType, xmlProcessingContext); if (contractType == null) { xmlProcessingContext.ReportError( $"Type '{remoteComponentInfo.ContractType}' could not be loaded."); return; } // Get contract name var contractName = remoteComponentInfo.ContractName; // Create end point address var serverAddress = remoteComponentInfo.ServerAddress ?? (string) xmlProcessingContext.ComponentContext.GetVariable(remoteComponentInfo.ServerAddressVariableName); var spnIdentity = remoteComponentInfo.SpnIdentity ?? contractType.Name; var endpointAddress = new EndpointAddress( new Uri(serverAddress), EndpointIdentity.CreateSpnIdentity(spnIdentity)); // Create binding var securityMode = (SecurityMode)Enum.Parse( typeof(SecurityMode), remoteComponentInfo.SecurityMode ?? "None", true); var binding = new NetTcpBinding(securityMode) { MaxBufferSize = (remoteComponentInfo.MaxBufferSizeNullable.HasValue ? remoteComponentInfo.MaxBufferSize : 16777216), MaxReceivedMessageSize = (remoteComponentInfo.MaxReceivedMessageSizeNullable.HasValue ? remoteComponentInfo.MaxReceivedMessageSize : 16777216) }; // Extract list of known types List <Type> knownTypes = null; if (!string.IsNullOrEmpty(remoteComponentInfo.KnownTypesVariableName)) { knownTypes = xmlProcessingContext.ComponentContext.GetVariable(remoteComponentInfo.KnownTypesVariableName) as List <Type>; } // Build ComponentConfiguration var componentFactory = new RemoteComponentFactory { Address = endpointAddress, Binding = binding, ContractType = contractType, KnownTypes = knownTypes }; // Register the component into the component context. xmlProcessingContext.ComponentContext.Register(contractType, contractName, componentFactory); }
private static void RunRegisterComponent(CompositionCommandInfo info, XmlProcessingContext xmlProcessingContext) { if (!(info is RegisterComponentInfo registerComponentInfo)) { throw new ArgumentException("Invalid runner input type: error in static setup."); } // Extract and load contract type Type contractType = null; if (registerComponentInfo.ContractType != null) { contractType = SimpleTypeParserUtil.ParseType(registerComponentInfo.ContractType, xmlProcessingContext); if (contractType == null) { xmlProcessingContext.ReportError( $"Type '{registerComponentInfo.ContractType}' could not be loaded."); return; } } // Get contract name var contractName = registerComponentInfo.ContractName; // Build ComponentConfiguration var componentType = SimpleTypeParserUtil.ParseType(registerComponentInfo.Type, xmlProcessingContext); if (componentType == null) { xmlProcessingContext.ReportError($"Type '{registerComponentInfo.Type}' could not be loaded."); return; } IComponentFactory componentFactory; List <InitializationPointSpecification> initializationPoints; if ((componentType.IsGenericType) && (componentType.ContainsGenericParameters)) { var genericLocalComponentFactory = new GenericLocalComponentFactory(componentType); componentFactory = genericLocalComponentFactory; initializationPoints = genericLocalComponentFactory.InitializationPoints; } else { var localComponentFactory = new LocalComponentFactory(componentType); componentFactory = localComponentFactory; initializationPoints = localComponentFactory.InitializationPoints; } // Add each configured plug, into the InitializationPoints // in the component configuration. foreach (var plugInfo in registerComponentInfo.Plugs) { xmlProcessingContext.EnterRunningLocation($"Plug '{plugInfo.Name}'"); var plugRefType = SimpleTypeParserUtil.ParseType(plugInfo.RefType, xmlProcessingContext); if (plugRefType == null) { xmlProcessingContext.ReportError($"Type '{plugInfo.RefType}' could not be loaded."); xmlProcessingContext.LeaveRunningLocation(); return; } var plugRefName = plugInfo.RefName; initializationPoints.Add(new InitializationPointSpecification( plugInfo.Name, MemberTypes.All, true, new ComponentQuery(plugRefType, plugRefName))); // TODO: Add support for optional plugs in Composition XML xmlProcessingContext.LeaveRunningLocation(); } // Add each configuration point, into the InitializationPoints // in the component configuration. foreach (var configurationPointInfo in registerComponentInfo.ConfigurationPoints) { xmlProcessingContext.EnterRunningLocation($"ConfigurationPoint '{configurationPointInfo.Name}'"); var value = CreateLazyXmlValue(configurationPointInfo.XElements, configurationPointInfo.XAttributes, xmlProcessingContext); initializationPoints.Add(new InitializationPointSpecification( configurationPointInfo.Name, MemberTypes.All, true, new LazyValueQuery(value))); xmlProcessingContext.LeaveRunningLocation(); } // Register the component into the component context. if (contractType == null) { xmlProcessingContext.ComponentContext.Register(contractName, componentFactory); } else { xmlProcessingContext.ComponentContext.Register(contractType, contractName, componentFactory); } }