/// <summary> /// Attempt to find a registered part and then asks it to create a service action with the given initial serviceName parameter value. /// If the desired part cannot be found then the method returns null (if throwOnNotFound is false) or it throws a PartIDNotFoundException (if the throwOnNotFound is true). /// </summary> /// <param name="partID">Gives the part ID on which to create a service action.</param> /// <param name="serviceName">Gives the initial value of the service name to be performed, or null, or string.Empty if the name is not already known.</param> /// <param name="namedParamValues">Gives the initial value that the created action's NamedParamValues will be set to.</param> /// <param name="throwOnNotFound">When true this method will throw a PartIDNotFoundException if the given partID is not found. When false the method will return null when the given partID is not found.</param> /// <exception cref="PartIDNotFoundException">Thrown when the partID is not found and throwOnNotFound is given as true.</exception> public IStringParamAction CreateServiceAction(string partID, string serviceName, INamedValueSet namedParamValues, bool throwOnNotFound) { IActivePartBase part = FindPart(partID, throwOnNotFound); if (part == null) { return(null); } IStringParamAction action = part.CreateServiceAction(serviceName); action.NamedParamValues = namedParamValues; return(action); }
/// <summary> /// Attempts to register the given <paramref name="part"/> in this IPartsInterconnection table. /// If there is already a part that has been registered with the given PartID then this method uses the <paramref name="howToHandleDuplicates"/> parameter to select the desired behavior. /// </summary> /// <exception cref="DuplicatePartIDException">will be thrown if there is already a part registered with the partID registered and the <paramref name="howToHandleDuplicates"/> has been set to DuplicatePartBehavior.Throw</exception> public IActivePartBase RegisterPart(IActivePartBase part, DuplicatePartIDRegistrationBehavior howToHandleDuplicates = DuplicatePartIDRegistrationBehavior.Replace) { string mesg = null; if (part == null) { mesg = "{0} failed: given part parameter is null".CheckedFormat(Fcns.CurrentMethodName); } else { string sanitizedPartID = part.PartID.Sanitize(); lock (mutex) { IActivePartBase existingPart = partIDDictionary.SafeTryGetValue(sanitizedPartID); if (existingPart == null) { partIDDictionary[sanitizedPartID] = part; } else { switch (howToHandleDuplicates) { case DuplicatePartIDRegistrationBehavior.None: mesg = "Registration of PartID '{0}' did not replace previously registered part of the same name [by request, {1}]".CheckedFormat(sanitizedPartID, existingPart.GetType()); break; case DuplicatePartIDRegistrationBehavior.Replace: partIDDictionary[sanitizedPartID] = part; mesg = "Registration of PartID '{0}' replaced previously registered part of the same name [by request, {1}]".CheckedFormat(sanitizedPartID, existingPart.GetType()); break; case DuplicatePartIDRegistrationBehavior.Throw: throw new DuplicatePartIDException("Registration of PartID '{0}' failed: by request cannot replace previously registered part with the same name [{1} {2}]".CheckedFormat(sanitizedPartID, Name, existingPart.GetType())); } } } } if (!mesg.IsNullOrEmpty()) { Logger.Debug.Emit(mesg); } return(part); }
/// <summary> /// Attempt to find a registered part and return it. /// If the desired part cannot be found then the method returns null (if throwOnNotFound is false) or it throws a PartIDNotFoundException (if the throwOnNotFound is true). /// </summary> /// <param name="partID">Gives the part ID on which to create a service action.</param> /// <param name="throwOnNotFound">When true this method will throw a PartIDNotFoundException if the given partID is not found. When false the method will return null when the given partID is not found.</param> /// <exception cref="PartIDNotFoundException">Thrown when the partID is not found and throwOnNotFound is given as true.</exception> public IActivePartBase FindPart(string partID, bool throwOnNotFound) { IActivePartBase part = null; if (partID != null) { lock (mutex) { partIDDictionary.TryGetValue(partID, out part); } } if (part == null && throwOnNotFound) { throw new PartIDNotFoundException("PartID '{0}' was not found in Action Interconnection '{1}'".CheckedFormat(partID, Name)); } return(part); }
/// <summary> /// Attempts to register the given part as an available target for creation of Interconnected Actions /// </summary> public void RegisterPart(IActivePartBase part) { IActivePartBase replacedPart = null; if (part != null && !part.PartID.IsNullOrEmpty()) { string partID = part.PartID; lock (mutex) { partIDDictionary.TryGetValue(partID, out replacedPart); partIDDictionary[partID] = part; } } if (replacedPart != null) { if (!object.ReferenceEquals(part, replacedPart)) Logger.Debug.Emit("Registration of PartID '{0}' replaced a previously registered part of the same name", part.PartID); else Logger.Debug.Emit("Redundant registration encountered for PartID '{0}'", part.PartID); } }