本文整理汇总了C#中ParseStack.Pop方法的典型用法代码示例。如果您正苦于以下问题:C# ParseStack.Pop方法的具体用法?C# ParseStack.Pop怎么用?C# ParseStack.Pop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParseStack
的用法示例。
在下文中一共展示了ParseStack.Pop方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseBoolean
Object ParseBoolean(
XmlNode node,
Type ValueType,
ParseStack parseStack,
MappingAction mappingAction)
{
if (ValueType != null && ValueType != typeof(Object)
&& ValueType != typeof(System.Boolean)
#if !FX1_0
&& ValueType != typeof(bool?)
#endif
&& ValueType != typeof(XmlRpcBoolean))
{
throw new XmlRpcTypeMismatchException(parseStack.ParseType
+ " contains boolean value where "
+ XmlRpcServiceInfo.GetXmlRpcTypeString(ValueType)
+ " expected " + StackDump(parseStack));
}
bool retVal;
parseStack.Push("boolean");
try
{
string s = node.FirstChild.Value;
if (s == "1")
{
retVal = true;
}
else if (s == "0")
{
retVal = false;
}
else
{
throw new XmlRpcInvalidXmlRpcException(
"reponse contains invalid boolean value "
+ StackDump(parseStack));
}
}
finally
{
parseStack.Pop();
}
if (ValueType == typeof(XmlRpcBoolean))
return new XmlRpcBoolean(retVal);
else
return retVal;
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:47,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例2: ParseDateTime
Object ParseDateTime(
XmlNode node,
Type ValueType,
ParseStack parseStack,
MappingAction mappingAction)
{
if (ValueType != null && ValueType != typeof(Object)
&& ValueType != typeof(System.DateTime)
#if !FX1_0
&& ValueType != typeof(DateTime?)
#endif
&& ValueType != typeof(XmlRpcDateTime))
{
throw new XmlRpcTypeMismatchException(parseStack.ParseType
+ " contains dateTime.iso8601 value where "
+ XmlRpcServiceInfo.GetXmlRpcTypeString(ValueType)
+ " expected " + StackDump(parseStack));
}
DateTime retVal;
parseStack.Push("dateTime");
try
{
XmlNode child = node.FirstChild;
if (child == null)
{
if (MapEmptyDateTimeToMinValue)
return DateTime.MinValue;
else
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains empty dateTime value "
+ StackDump(parseStack));
}
string s = child.Value;
try
{
// XML-RPC spec yyyyMMddThh:mm:ss
string dateTimeFormat = "yyyyMMdd'T'HH':'mm':'ss";
if (AllowNonStandardDateTime)
{
if (s.IndexOf("T") == 8)
{
if (s.EndsWith("Z"))
{
// WordPress yyyyMMddThh:mm:ssZ
dateTimeFormat = "yyyyMMdd'T'HH':'mm':'ss'Z'";
}
else if (s.EndsWith("-00") || s.EndsWith("-0000")
|| s.EndsWith("+00") || s.EndsWith("+0000"))
{
s = s.Substring(0, 17);
}
}
else
{
if (s.EndsWith("Z"))
{
// TypePad yyyy-MM-ddThh:mm:ssZ
dateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'";
}
else
{
// other yyyy-MM-ddThh:mm:ss
dateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss";
}
}
}
if (MapZerosDateTimeToMinValue && s.StartsWith("0000")
&& (s == "00000000T00:00:00" || s == "0000-00-00T00:00:00Z"
|| s == "00000000T00:00:00Z" || s == "0000-00-00T00:00:00"))
retVal = DateTime.MinValue;
else
retVal = DateTime.ParseExact(s, dateTimeFormat,
DateTimeFormatInfo.InvariantInfo);
}
catch(Exception)
{
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains invalid dateTime value "
+ StackDump(parseStack));
}
}
finally
{
parseStack.Pop();
}
if (ValueType == typeof(XmlRpcDateTime))
return new XmlRpcDateTime(retVal);
else
return retVal;
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:90,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例3: ParseArray
Object ParseArray(
XmlNode node,
Type ValueType,
ParseStack parseStack,
MappingAction mappingAction)
{
// required type must be an array
if (ValueType != null
&& !(ValueType.IsArray == true
|| ValueType == typeof(Array)
|| ValueType == typeof(object)))
{
throw new XmlRpcTypeMismatchException(parseStack.ParseType
+ " contains array value where "
+ XmlRpcServiceInfo.GetXmlRpcTypeString(ValueType)
+ " expected " + StackDump(parseStack));
}
if (ValueType != null)
{
XmlRpcType xmlRpcType = XmlRpcServiceInfo.GetXmlRpcType(ValueType);
if (xmlRpcType == XmlRpcType.tMultiDimArray)
{
parseStack.Push("array mapped to type " + ValueType.Name);
Object ret = ParseMultiDimArray(node, ValueType, parseStack,
mappingAction);
return ret;
}
parseStack.Push("array mapped to type " + ValueType.Name);
}
else
parseStack.Push("array");
XmlNode dataNode = node.SelectSingleNode("./data");
XmlNodeList childNodes = dataNode.SelectNodes("./value");
int nodeCount = childNodes.Count;
Object[] elements = new Object[nodeCount];
// determine type of array elements
Type elemType = null;
if (ValueType != null
&& ValueType != typeof(Array)
&& ValueType != typeof(object))
{
#if (!COMPACT_FRAMEWORK)
elemType = ValueType.GetElementType();
#else
string[] checkMultiDim = Regex.Split(ValueType.FullName,
"\\[\\]$");
// determine assembly of array element type
Assembly asmbly = ValueType.Assembly;
string[] asmblyName = asmbly.FullName.Split(',');
string elemTypeName = checkMultiDim[0] + ", " + asmblyName[0];
elemType = Type.GetType(elemTypeName);
#endif
}
else
{
elemType = typeof(object);
}
bool bGotType = false;
Type useType = null;
int i = 0;
foreach (XmlNode vNode in childNodes)
{
parseStack.Push(String.Format("element {0}", i));
XmlNode vvNode = vNode.SelectSingleNode("./*");
if (vvNode == null)
vvNode = vNode.FirstChild;
Type parsedType;
Type parsedArrayType;
elements[i++] = ParseValue(vvNode, elemType, parseStack, mappingAction,
out parsedType, out parsedArrayType);
if (bGotType == false)
{
useType = parsedArrayType;
bGotType = true;
}
else
{
if (useType != parsedArrayType)
useType = null;
}
parseStack.Pop();
}
Object[] args = new Object[1]; args[0] = nodeCount;
Object retObj = null;
if (ValueType != null
&& ValueType != typeof(Array)
&& ValueType != typeof(object))
{
retObj = CreateArrayInstance(ValueType, args);
}
else
{
if (useType == null)
retObj = CreateArrayInstance(typeof(object[]), args);
else
retObj = CreateArrayInstance(useType, args);
}
for (int j=0; j < elements.Length; j++)
{
((Array)retObj).SetValue(elements[j], j);
//.........这里部分代码省略.........
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:101,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例4: ParseBase64
Object ParseBase64(
XmlNode node,
Type ValueType,
ParseStack parseStack,
MappingAction mappingAction)
{
if (ValueType != null && ValueType != typeof(byte[])
&& ValueType != typeof(Object))
{
throw new XmlRpcTypeMismatchException(parseStack.ParseType
+ " contains base64 value where "
+ XmlRpcServiceInfo.GetXmlRpcTypeString(ValueType)
+ " expected " + StackDump(parseStack));
}
byte[] ret;
parseStack.Push("base64");
try
{
if (node.FirstChild == null)
ret = new byte[0];
else
{
string s = node.FirstChild.Value;
try
{
ret = Convert.FromBase64String(s);
}
catch (Exception)
{
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains invalid base64 value "
+ StackDump(parseStack));
}
}
}
finally
{
parseStack.Pop();
}
return ret;
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:41,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例5: ParseStruct
//.........这里部分代码省略.........
bool dupValue;
SelectTwoNodes(member, "name", out nameNode, out dupName, "value",
out valueNode, out dupValue);
if (nameNode == null)
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains a member with missing name element"
+ " " + StackDump(parseStack));
if (dupName)
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains member with more than one name element"
+ " " + StackDump(parseStack));
string name = nameNode.FirstChild.Value;
if (valueNode == null)
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains struct member " + name + " with missing value "
+ " " + StackDump(parseStack));
if (dupValue)
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains member with more than one value element"
+ " " + StackDump(parseStack));
string structName = GetStructName(valueType, name);
if (structName != null)
name = structName;
if (names.Contains(name))
names.Remove(name);
else
{
if (!IgnoreDuplicateMembers
&& (valueType.GetField(name) != null || valueType.GetProperty(name) != null))
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains struct value with duplicate member "
+ nameNode.FirstChild.Value
+ " " + StackDump(parseStack));
else
continue; // ignore duplicate member
}
MemberInfo[] mis = valueType.GetMember(name);
if (mis.Length == 0)
{
continue; // allow unexpected members
}
Object valObj = null;
switch (mis[0].MemberType)
{
case MemberTypes.Field:
FieldInfo fi = (FieldInfo)mis[0];
if (valueType == null)
parseStack.Push(String.Format("member {0}", name));
else
parseStack.Push(String.Format("member {0} mapped to type {1}",
name,fi.FieldType.Name));
try
{
XmlNode vvvNode = valueNode.SelectSingleNode("./*");
if (vvvNode == null)
vvvNode = valueNode.FirstChild;
valObj = ParseValue(vvvNode, fi.FieldType,
parseStack, mappingAction);
}
catch(XmlRpcInvalidXmlRpcException)
{
if (valueType != null && localAction == MappingAction.Error)
{
MappingAction memberAction = MemberMappingAction(valueType,
name, MappingAction.Error);
if (memberAction == MappingAction.Error)
throw;
}
}
finally
{
parseStack.Pop();
}
fi.SetValue(retObj, valObj);
break ;
case MemberTypes.Property :
PropertyInfo pi = (PropertyInfo)mis[0] ;
if (valueType == null)
parseStack.Push(String.Format("member {0}", name));
else
parseStack.Push(String.Format("member {0} mapped to type {1}",
name,pi.PropertyType.Name));
XmlNode vvNode = valueNode.SelectSingleNode("./*");
if (vvNode == null)
vvNode = valueNode.FirstChild;
valObj = ParseValue(vvNode, pi.PropertyType,
parseStack, mappingAction);
parseStack.Pop();
pi.SetValue(retObj, valObj, null);
break ;
}
fieldCount++;
}
if (localAction == MappingAction.Error && names.Count > 0)
ReportMissingMembers(valueType, names, parseStack);
parseStack.Pop();
return retObj;
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:101,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例6: DeserializeRequest
//.........这里部分代码省略.........
}
// method must be marked with XmlRpcMethod attribute
Attribute attr = Attribute.GetCustomAttribute(request.mi,
typeof(XmlRpcMethodAttribute));
if (attr == null)
{
throw new XmlRpcMethodAttributeException(
"Method must be marked with the XmlRpcMethod attribute.");
}
pis = request.mi.GetParameters();
}
XmlNode paramsNode = callNode.SelectSingleNode("./params");
if (paramsNode == null)
{
if (svcType != null)
{
if (pis.Length == 0)
{
request.args = new object[0];
return request;
}
else
{
throw new XmlRpcInvalidParametersException(
"Method takes parameters and params element is missing.");
}
}
else
{
request.args = new object[0];
return request;
}
}
XmlNodeList paramNodes = paramsNode.SelectNodes("./param");
int paramsPos = GetParamsPos(pis);
if (paramNodes.Count < paramsPos)
{
throw new XmlRpcInvalidParametersException(
"Method takes parameters and there is incorrect number of param "
+ "elements.");
}
ParseStack parseStack = new ParseStack("request");
// TODO: use global action setting
MappingAction mappingAction = MappingAction.Error;
int paramObjCount = (paramsPos == -1 ?paramNodes.Count : paramsPos + 1);
Object[] paramObjs = new Object[paramObjCount];
// parse ordinary parameters
int ordinaryParams = (paramsPos == -1 ?paramNodes.Count :paramsPos);
for (int i = 0; i < ordinaryParams; i++)
{
XmlNode paramNode = paramNodes[i];
XmlNode valueNode = paramNode.SelectSingleNode("./value");
if (valueNode == null)
throw new XmlRpcInvalidXmlRpcException("Missing value element.");
XmlNode node = valueNode.SelectSingleNode("./*");
if (node == null)
node = valueNode.FirstChild;
if (svcType != null)
{
parseStack.Push(String.Format("parameter {0}", i + 1));
// TODO: why following commented out?
// parseStack.Push(String.Format("parameter {0} mapped to type {1}",
// i, pis[i].ParameterType.Name));
paramObjs[i] = ParseValue(node, pis[i].ParameterType, parseStack,
mappingAction);
}
else
{
parseStack.Push(String.Format("parameter {0}", i));
paramObjs[i] = ParseValue(node, null, parseStack, mappingAction);
}
parseStack.Pop();
}
// parse params parameters
if (paramsPos != -1)
{
Type paramsType = pis[paramsPos].ParameterType.GetElementType();
Object[] args = new Object[1];
args[0] = paramNodes.Count - paramsPos;
Array varargs = (Array)CreateArrayInstance(pis[paramsPos].ParameterType,
args);
for (int i = 0; i < varargs.Length; i++)
{
XmlNode paramNode = paramNodes[i + paramsPos];
XmlNode valueNode = paramNode.SelectSingleNode("value");
if (valueNode == null)
throw new XmlRpcInvalidXmlRpcException("Missing value element.");
XmlNode node = valueNode.SelectSingleNode("./*");
if (node == null)
node = valueNode.FirstChild;
parseStack.Push(String.Format("parameter {0}", i + 1 + paramsPos));
varargs.SetValue(ParseValue(node, paramsType, parseStack,
mappingAction), i);
parseStack.Pop();
}
paramObjs[paramsPos] = varargs;
}
request.args = paramObjs;
return request;
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:101,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例7: ParseInt
Object ParseInt(
XmlNode node,
Type ValueType,
ParseStack parseStack,
MappingAction mappingAction)
{
if (ValueType != null && ValueType != typeof(Object)
&& ValueType != typeof(System.Int32)
#if !FX1_0
&& ValueType != typeof(int?)
#endif
&& ValueType != typeof(XmlRpcInt))
{
throw new XmlRpcTypeMismatchException(parseStack.ParseType +
" contains int value where "
+ XmlRpcServiceInfo.GetXmlRpcTypeString(ValueType)
+ " expected " + StackDump(parseStack));
}
int retVal;
parseStack.Push("integer");
try
{
XmlNode valueNode = node.FirstChild;
if (valueNode == null)
{
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+" contains invalid int element " + StackDump(parseStack));
}
try
{
String strValue = valueNode.Value;
retVal = Int32.Parse(strValue);
}
catch(Exception)
{
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains invalid int value " + StackDump(parseStack));
}
}
finally
{
parseStack.Pop();
}
if (ValueType == typeof(XmlRpcInt))
return new XmlRpcInt(retVal);
else
return retVal;
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:48,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例8: ParseString
Object ParseString(
XmlNode node,
Type ValueType,
ParseStack parseStack,
MappingAction mappingAction)
{
if (ValueType != null && ValueType != typeof(System.String)
&& ValueType != typeof(Object))
{
throw new XmlRpcTypeMismatchException(parseStack.ParseType
+ " contains string value where "
+ XmlRpcServiceInfo.GetXmlRpcTypeString(ValueType)
+ " expected " + StackDump(parseStack));
}
string ret;
parseStack.Push("string");
try
{
if (node.FirstChild == null)
ret = "";
else
ret = node.FirstChild.Value;
}
finally
{
parseStack.Pop();
}
return ret;
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:29,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例9: ParseHashtable
Object ParseHashtable(
XmlNode node,
Type valueType,
ParseStack parseStack,
MappingAction mappingAction)
{
XmlRpcStruct retObj = new XmlRpcStruct();
parseStack.Push("struct mapped to XmlRpcStruct");
try
{
XmlNodeList members = node.SelectNodes("./member");
foreach (XmlNode member in members)
{
if (member.Name != "member")
continue;
XmlNode nameNode;
bool dupName;
XmlNode valueNode;
bool dupValue;
SelectTwoNodes(member, "name", out nameNode, out dupName, "value",
out valueNode, out dupValue);
if (nameNode == null)
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains a member with missing name element"
+ " " + StackDump(parseStack));
if (dupName)
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains member with more than one name element"
+ " " + StackDump(parseStack));
string rpcName = nameNode.FirstChild.Value;
if (valueNode == null)
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains struct member " + rpcName + " with missing value "
+ " " + StackDump(parseStack));
if (dupValue)
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains member with more than one value element"
+ " " + StackDump(parseStack));
if (retObj.Contains(rpcName))
{
if (!IgnoreDuplicateMembers)
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains struct value with duplicate member "
+ nameNode.FirstChild.Value
+ " " + StackDump(parseStack));
else
continue;
}
object valObj;
parseStack.Push(String.Format("member {0}", rpcName));
try
{
XmlNode vvNode = valueNode.SelectSingleNode("./*");
if (vvNode == null)
vvNode = valueNode.FirstChild;
valObj = ParseValue(vvNode, null, parseStack,
mappingAction);
}
finally
{
parseStack.Pop();
}
retObj.Add(rpcName, valObj);
}
}
finally
{
parseStack.Pop();
}
return retObj;
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:71,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例10: ParseDouble
Object ParseDouble(
XmlNode node,
Type ValueType,
ParseStack parseStack,
MappingAction mappingAction)
{
if (ValueType != null && ValueType != typeof(Object)
&& ValueType != typeof(System.Double)
#if !FX1_0
&& ValueType != typeof(double?)
#endif
&& ValueType != typeof(XmlRpcDouble))
{
throw new XmlRpcTypeMismatchException(parseStack.ParseType
+ " contains double value where "
+ XmlRpcServiceInfo.GetXmlRpcTypeString(ValueType)
+ " expected " + StackDump(parseStack));
}
Double retVal;
parseStack.Push("double");
try
{
retVal = Double.Parse(node.FirstChild.Value,
CultureInfo.InvariantCulture.NumberFormat);
}
catch(Exception)
{
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains invalid double value " + StackDump(parseStack));
}
finally
{
parseStack.Pop();
}
if (ValueType == typeof(XmlRpcDouble))
return new XmlRpcDouble(retVal);
else
return retVal;
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:39,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例11: ParseDateTime
Object ParseDateTime(
XmlNode node,
Type ValueType,
ParseStack parseStack,
MappingAction mappingAction)
{
if (ValueType != null && ValueType != typeof(Object)
&& ValueType != typeof(System.DateTime)
#if !FX1_0
&& ValueType != typeof(DateTime?)
#endif
&& ValueType != typeof(XmlRpcDateTime))
{
throw new XmlRpcTypeMismatchException(parseStack.ParseType
+ " contains dateTime.iso8601 value where "
+ XmlRpcServiceInfo.GetXmlRpcTypeString(ValueType)
+ " expected " + StackDump(parseStack));
}
DateTime retVal;
parseStack.Push("dateTime");
try
{
XmlNode child = node.FirstChild;
if (child == null)
{
if (MapEmptyDateTimeToMinValue)
return DateTime.MinValue;
else
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains empty dateTime value "
+ StackDump(parseStack));
}
string s = child.Value;
// Allow various iso8601 formats, e.g.
// XML-RPC spec yyyyMMddThh:mm:ss
// WordPress yyyyMMddThh:mm:ssZ
// TypePad yyyy-MM-ddThh:mm:ssZ
// other yyyy-MM-ddThh:mm:ss
if (!DateTime8601.TryParseDateTime8601(s, out retVal))
{
if (MapZerosDateTimeToMinValue && s.StartsWith("0000")
&& (s == "00000000T00:00:00" || s == "0000-00-00T00:00:00Z"
|| s == "00000000T00:00:00Z" || s == "0000-00-00T00:00:00"))
retVal = DateTime.MinValue;
else
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains invalid dateTime value "
+ StackDump(parseStack));
}
}
finally
{
parseStack.Pop();
}
if (ValueType == typeof(XmlRpcDateTime))
return new XmlRpcDateTime(retVal);
else
return retVal;
}
示例12: DeserializeRequest
//.........这里部分代码省略.........
}
// JB Change
// Sometimes tapatalk calls the same method with both parameters and no parameters
// This allows us to handle that by changing the no parameter case into an empty parameter array
else if(pis.Length == 1 && pis[0].ParameterType == typeof(object[]))
{
paramsNode = xdoc.CreateNode(XmlNodeType.Element, "params", "");
//var paramNode = xdoc.CreateNode(XmlNodeType.Element, "param", "");
//paramsNode.AppendChild(paramNode);
// var valueNode = xdoc.CreateNode(XmlNodeType.Element, "value", "");
//paramNode.AppendChild(valueNode);
// var arrayNode = xdoc.CreateNode(XmlNodeType.Element, "string", "");
//valueNode.AppendChild(arrayNode);
// var dataNode = xdoc.CreateNode(XmlNodeType.Element, "data", "");
//arrayNode.AppendChild(dataNode);
}
else
{
throw new XmlRpcInvalidParametersException(
"Method takes parameters and params element is missing.");
}
}
else
{
request.args = new object[0];
return request;
}
}
XmlNode[] paramNodes = SelectNodes(paramsNode, "param");
int paramsPos = GetParamsPos(pis);
int minParamCount = paramsPos == -1 ? pis.Length : paramsPos;
if (svcType != null && paramNodes.Length < minParamCount)
{
throw new XmlRpcInvalidParametersException(
"Request contains too few param elements based on method signature.");
}
if (svcType != null && paramsPos == -1 && paramNodes.Length > pis.Length)
{
throw new XmlRpcInvalidParametersException(
"Request contains too many param elements based on method signature.");
}
ParseStack parseStack = new ParseStack("request");
// TODO: use global action setting
MappingAction mappingAction = MappingAction.Error;
int paramObjCount = (paramsPos == -1 ? paramNodes.Length : paramsPos + 1);
Object[] paramObjs = new Object[paramObjCount];
// parse ordinary parameters
int ordinaryParams = (paramsPos == -1 ? paramNodes.Length : paramsPos);
for (int i = 0; i < ordinaryParams; i++)
{
XmlNode paramNode = paramNodes[i];
XmlNode valueNode = SelectSingleNode(paramNode, "value");
if (valueNode == null)
throw new XmlRpcInvalidXmlRpcException("Missing value element.");
XmlNode node = SelectValueNode(valueNode);
if (svcType != null)
{
parseStack.Push(String.Format("parameter {0}", i + 1));
// TODO: why following commented out?
// parseStack.Push(String.Format("parameter {0} mapped to type {1}",
// i, pis[i].ParameterType.Name));
paramObjs[i] = ParseValue(node, pis[i].ParameterType, parseStack,
mappingAction);
}
else
{
parseStack.Push(String.Format("parameter {0}", i));
paramObjs[i] = ParseValue(node, null, parseStack, mappingAction);
}
parseStack.Pop();
}
// parse params parameters
if (paramsPos != -1)
{
Type paramsType = pis[paramsPos].ParameterType.GetElementType();
Object[] args = new Object[1];
args[0] = paramNodes.Length - paramsPos;
Array varargs = (Array)CreateArrayInstance(pis[paramsPos].ParameterType,
args);
for (int i = 0; i < varargs.Length; i++)
{
XmlNode paramNode = paramNodes[i + paramsPos];
XmlNode valueNode = SelectSingleNode(paramNode, "value");
if (valueNode == null)
throw new XmlRpcInvalidXmlRpcException("Missing value element.");
XmlNode node = SelectValueNode(valueNode);
parseStack.Push(String.Format("parameter {0}", i + 1 + paramsPos));
varargs.SetValue(ParseValue(node, paramsType, parseStack,
mappingAction), i);
parseStack.Pop();
}
paramObjs[paramsPos] = varargs;
}
request.args = paramObjs;
return request;
}
示例13: ParseLong
Object ParseLong(
XmlNode node,
Type ValueType,
ParseStack parseStack,
MappingAction mappingAction)
{
if (ValueType != null && ValueType != typeof(Object)
&& ValueType != typeof(System.Int64)
#if !FX1_0
&& ValueType != typeof(long?))
#endif
{
throw new XmlRpcTypeMismatchException(parseStack.ParseType +
" contains i8 value where "
+ XmlRpcServiceInfo.GetXmlRpcTypeString(ValueType)
+ " expected " + StackDump(parseStack));
}
long retVal;
parseStack.Push("i8");
try
{
XmlNode valueNode = node.FirstChild;
if (valueNode == null)
{
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains invalid i8 element " + StackDump(parseStack));
}
try
{
String strValue = valueNode.Value;
retVal = Int64.Parse(strValue);
}
catch (Exception)
{
throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
+ " contains invalid i8 value " + StackDump(parseStack));
}
}
finally
{
parseStack.Pop();
}
return retVal;
}