GlowCommand ConvertCommand(XElement xml) { var glow = new GlowCommand(XmlConvert.ToInt32(xml.Attribute("number").Value)); xml.Element("dirFieldMask").Do(value => glow.DirFieldMask = XmlConvert.ToInt32(value)); var invocationXml = xml.Element("invocation"); if (invocationXml != null) { var glowInvocation = new GlowInvocation(GlowTags.Command.Invocation); invocationXml.Element("invocationId").Do(value => glowInvocation.InvocationId = XmlConvert.ToInt32(value)); var argumentsXml = invocationXml.Element("arguments"); if (argumentsXml != null) { glowInvocation.ArgumentValues = from valueXml in argumentsXml.Elements("Value") let glowValue = ConvertValue(valueXml) where glowValue != null select glowValue; } glow.Invocation = glowInvocation; } return(glow); }
public GlowInvocationResult Invoke(GlowInvocation invocation) { GlowValue[] arguments; int? invocationId; if (invocation == null) { if (Arguments != null) { throw new ArgumentException("Function with parameters called without arguments!"); } arguments = null; invocationId = null; } else { var argumentValues = invocation.ArgumentValues; arguments = argumentValues != null ? argumentValues.ToArray() : null; invocationId = invocation.InvocationId; AssertValueTypes(arguments, Arguments); } if (invocationId == null && HasResult) { throw new ArgumentException("Function with result called without invocation id!"); } var result = _coreFunc(arguments); AssertValueTypes(result, Result); if (invocationId != null) { var invocationResult = GlowInvocationResult.CreateRoot(invocationId.Value); if (result != null) { invocationResult.ResultValues = result; } return(invocationResult); } return(null); }
GlowCommand ConvertCommand(XElement xml) { var glow = new GlowCommand(XmlConvert.ToInt32(xml.Attribute("number").Value)); xml.Element("dirFieldMask").Do(value => glow.DirFieldMask = XmlConvert.ToInt32(value)); var invocationXml = xml.Element("invocation"); if(invocationXml != null) { var glowInvocation = new GlowInvocation(GlowTags.Command.Invocation); invocationXml.Element("invocationId").Do(value => glowInvocation.InvocationId = XmlConvert.ToInt32(value)); var argumentsXml = invocationXml.Element("arguments"); if(argumentsXml != null) { glowInvocation.ArgumentValues = from valueXml in argumentsXml.Elements("Value") let glowValue = ConvertValue(valueXml) where glowValue != null select glowValue; } glow.Invocation = glowInvocation; } return glow; }
public async Task <GlowInvocationResult> Invoke(GlowInvocation invocation) { GlowValue[] arguments; int? invocationId; if (invocation == null) { if (Arguments != null) { throw new ArgumentException("Function with parameters called without arguments!"); } arguments = null; invocationId = null; } else { var argumentValues = invocation.ArgumentValues; arguments = argumentValues != null ? argumentValues.ToArray() : null; // ********************************************** // Added code // Functions without parameters can be defined in two (2) ways. Either 'args=null' or 'args=empty list' // - EmberViewer v1.6.2 sends args=null when function parameter is missing // - EmberViewer v2.4.0 sends args=empty list when function parameter is missing // So that both models will work, we create an empty list if args=null // and we create args=null if args=empty list if (Arguments != null && Arguments.Length == 0 && arguments == null) { arguments = new GlowValue[0]; } if (Arguments == null && arguments != null && arguments.Length == 0) { arguments = null; } // ************************************************ invocationId = invocation.InvocationId; AssertValueTypes(arguments, Arguments); } if (invocationId == null && HasResult) { throw new ArgumentException("Function with result called without invocation id!"); } Debug.WriteLine($"Invoking function {IdentifierPath}"); var result = await _coreFunc(arguments); AssertValueTypes(result, Result); if (invocationId != null) { var invocationResult = GlowInvocationResult.CreateRoot(invocationId.Value); if (result != null) { invocationResult.ResultValues = result; } return(invocationResult); } return(null); }
public async Task <GlowInvocationResult> Invoke(GlowInvocation invocation) { GlowValue[] arguments; int? invocationId; if (invocation == null) { if (Arguments != null) { throw new ArgumentException("Function with parameters called without arguments!"); } arguments = null; invocationId = null; } else { var argumentValues = invocation.ArgumentValues; arguments = argumentValues != null ? argumentValues.ToArray() : null; // ******* Tillagd kod **************************** // Funktioner utan parametrar kan definieras på två sätt. Antingen args=null eller args=tom lista. // Men EmberViewer v1.6.2 skickar args=null då funktionsparametrar saknas // och EmberViewer v2.4.0 skickar args=tom lista då funktionsparametrar saknas // För att båda modellerna ska fungera skapar vi tom lista om arg=null men förväntas vara tom lista // och argumenten sätts till null om argumenten förväntas vara null men är tom lista. if (Arguments != null && Arguments.Length == 0 && arguments == null) { arguments = new GlowValue[0]; } if (Arguments == null && arguments != null && arguments.Length == 0) { arguments = null; } // ************************************************ invocationId = invocation.InvocationId; AssertValueTypes(arguments, Arguments); } if (invocationId == null && HasResult) { throw new ArgumentException("Function with result called without invocation id!"); } Log.Debug($"Invoking function {IdentifierPath}"); var result = await _coreFunc(arguments); AssertValueTypes(result, Result); if (invocationId != null) { var invocationResult = GlowInvocationResult.CreateRoot(invocationId.Value); if (result != null) { invocationResult.ResultValues = result; } return(invocationResult); } return(null); }