private string InvokeMethod(string path, int argumentsCount, Func <string, WoopsaValueType, WoopsaValue> getArgumentByName) { IWoopsaElement item = FindByPath(path); if (item is IWoopsaMethod) { IWoopsaMethod method = item as IWoopsaMethod; if (argumentsCount == method.ArgumentInfos.Count()) { List <WoopsaValue> woopsaArguments = new List <WoopsaValue>(); foreach (var argInfo in method.ArgumentInfos) { WoopsaValue argumentValue = getArgumentByName(argInfo.Name, argInfo.Type); if (argumentValue == null) { string message = String.Format("Missing argument {0} for method {1}", argInfo.Name, item.Name); OnLog(WoopsaVerb.Invoke, path, NoArguments, message, false); throw new WoopsaInvalidOperationException(message); } else { woopsaArguments.Add(argumentValue); } } WoopsaValue[] argumentsArray = woopsaArguments.ToArray(); IWoopsaValue methodResult = method.Invoke(argumentsArray); string result = methodResult != null?methodResult.Serialize() : WoopsaConst.WoopsaNull; OnLog(WoopsaVerb.Invoke, path, argumentsArray, result, true); return(result); } else { string message = String.Format("Wrong argument count for method {0}", item.Name); OnLog(WoopsaVerb.Invoke, path, NoArguments, message, false); throw new WoopsaInvalidOperationException(message); } } else { string message = String.Format("Cannot invoke a {0}", item.GetType()); OnLog(WoopsaVerb.Invoke, path, NoArguments, message, false); throw new WoopsaInvalidOperationException(message); } }
internal string InvokeMethod(string path, NameValueCollection arguments) { IWoopsaElement item = FindByPath(path); if (item is IWoopsaMethod) { int argumentsCount = arguments != null ? arguments.Count : 0; IWoopsaMethod method = item as IWoopsaMethod; if (argumentsCount == method.ArgumentInfos.Count()) { List <WoopsaValue> woopsaArguments = new List <WoopsaValue>(); foreach (var argInfo in method.ArgumentInfos) { string argumentValue = arguments[argInfo.Name]; if (argumentValue == null) { throw new WoopsaInvalidOperationException(String.Format( "Missing argument {0} for method {1}", argInfo.Name, item.Name)); } woopsaArguments.Add(WoopsaValue.CreateChecked(argumentValue, argInfo.Type)); } IWoopsaValue result = method.Invoke(woopsaArguments.ToArray()); return(result != null?result.Serialize() : WoopsaConst.WoopsaNull); } else { throw new WoopsaInvalidOperationException(String.Format( "Wrong argument count for method {0}", item.Name)); } } else { throw new WoopsaInvalidOperationException(String.Format( "Cannot invoke a {0}", item.GetType())); } }
internal string GetMetadata(string path) { IWoopsaElement item = FindByPath(path); if (item is IWoopsaObject) { return((item as IWoopsaObject).SerializeMetadata()); } else if (item is IWoopsaContainer) { return((item as IWoopsaContainer).SerializeMetadata()); } else { throw new WoopsaInvalidOperationException(String.Format("Cannot get metadata for a WoopsaElement of type {0}", item.GetType())); } }
internal string GetMetadata(string path) { IWoopsaElement item = FindByPath(path); if (item is IWoopsaContainer) { string result; if (item is IWoopsaObject) { result = (item as IWoopsaObject).SerializeMetadata(); } else { result = (item as IWoopsaContainer).SerializeMetadata(); } OnLog(WoopsaVerb.Meta, path, NoArguments, result, true); return(result); } else { string message = String.Format("Cannot get metadata for a WoopsaElement of type {0}", item.GetType()); OnLog(WoopsaVerb.Meta, path, NoArguments, message, false); throw new WoopsaInvalidOperationException(message); } }