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);
        }
예제 #2
0
        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);
            }
        }