public String ResolveAttributeExpression(String expression, IHandlerContext handlerContext) { String text = expression; int leftMarkerIndex = text.IndexOf(LEFT_MARKER); int rightMarkerIndex = text.IndexOf(RIGHT_MARKER, leftMarkerIndex + LEFT_MARKER.Length); while ((leftMarkerIndex != - 1) && (rightMarkerIndex != - 1)) { String attributeName = text.Substring(leftMarkerIndex + LEFT_MARKER.Length, (rightMarkerIndex) - (leftMarkerIndex + LEFT_MARKER.Length)).Trim(); try { Object attribute = handlerContext.GetAttribute(attributeName); if (attribute != null) { String attributeString = attribute.ToString(); text = text.Substring(0, leftMarkerIndex) + attributeString + text.Substring(rightMarkerIndex + RIGHT_MARKER.Length); rightMarkerIndex = rightMarkerIndex + attributeString.Length - attributeName.Length - LEFT_MARKER.Length - RIGHT_MARKER.Length; } } catch (Exception e) { log.Debug("attribute '" + attributeName + "' could not be resolved in attribute expression '" + expression + "'. Exception: " + e.Message); } leftMarkerIndex = text.IndexOf(LEFT_MARKER, rightMarkerIndex + RIGHT_MARKER.Length); rightMarkerIndex = text.IndexOf(RIGHT_MARKER, leftMarkerIndex + LEFT_MARKER.Length); } return text; }
public String ResolveAttributeExpression(String expression, IHandlerContext handlerContext) { String text = expression; int leftMarkerIndex = text.IndexOf(LEFT_MARKER); int rightMarkerIndex = text.IndexOf(RIGHT_MARKER, leftMarkerIndex + LEFT_MARKER.Length); while ((leftMarkerIndex != -1) && (rightMarkerIndex != -1)) { String attributeName = text.Substring(leftMarkerIndex + LEFT_MARKER.Length, (rightMarkerIndex) - (leftMarkerIndex + LEFT_MARKER.Length)).Trim(); try { Object attribute = handlerContext.GetAttribute(attributeName); if (attribute != null) { String attributeString = attribute.ToString(); text = text.Substring(0, leftMarkerIndex) + attributeString + text.Substring(rightMarkerIndex + RIGHT_MARKER.Length); rightMarkerIndex = rightMarkerIndex + attributeString.Length - attributeName.Length - LEFT_MARKER.Length - RIGHT_MARKER.Length; } } catch (Exception e) { log.Debug("attribute '" + attributeName + "' could not be resolved in attribute expression '" + expression + "'. Exception: " + e.Message); } leftMarkerIndex = text.IndexOf(LEFT_MARKER, rightMarkerIndex + RIGHT_MARKER.Length); rightMarkerIndex = text.IndexOf(RIGHT_MARKER, leftMarkerIndex + LEFT_MARKER.Length); } return(text); }
public IActor ResolveArgumentRole(IActor resolvedActor, string[] parameters, IHandlerContext handlerContext) { if (parameters.Length != 1) { throw new SystemException("argument role expects exactly one parameter (role-name) instead of " + parameters.Length); } IActor actor = null; if (resolvedActor == null) { try { actor = (IActor)handlerContext.GetAttribute(parameters[0]); } catch (InvalidCastException e) { throw new SystemException("argument attribute(" + parameters[0] + ") does not contain an actor : " + handlerContext.GetAttribute(parameters[0]).GetType().FullName, e); } } else { string roleName = parameters[0].Trim(); try { IList <IUser> users = organizationApplication.FindUsersByGroupAndRole(resolvedActor.UniqueName, roleName); if (users.Count < 1) { throw new SystemException("no users have role " + roleName + " for group " + resolvedActor.UniqueName); } actor = users[0]; // TODO : create a new group if more then one user is returned on the query... } catch (InvalidCastException e) { throw new SystemException("can't resolve role-argument : a role must be calculated from a Group, not a " + resolvedActor.GetType().FullName, e); } catch { //throw new SystemException("can't resolve role-argument : can't find the users that perform role " + roleName + " for group " + resolvedActor.Id + " : " + e.Message); } } return(actor); }