本文整理汇总了C#中ParseStack类的典型用法代码示例。如果您正苦于以下问题:C# ParseStack类的具体用法?C# ParseStack怎么用?C# ParseStack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParseStack类属于命名空间,在下文中一共展示了ParseStack类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: StackDump
string StackDump(ParseStack parseStack)
{
StringBuilder sb = new StringBuilder();
foreach (string elem in parseStack)
{
sb.Insert(0, elem);
sb.Insert(0, " : ");
}
sb.Insert(0, parseStack.ParseType);
sb.Insert(0, "[");
sb.Append("]");
return sb.ToString();
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:13,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例2: DeserializeRequest
public XmlRpcRequest DeserializeRequest(XmlDocument xdoc, Type svcType)
{
XmlRpcRequest request = new XmlRpcRequest();
XmlNode callNode = xdoc.SelectSingleNode("./methodCall");
if (callNode == null)
{
throw new XmlRpcInvalidXmlRpcException(
"Request XML not valid XML-RPC - missing methodCall element.");
}
XmlNode methodNode = callNode.SelectSingleNode("./methodName");
if (methodNode == null)
{
throw new XmlRpcInvalidXmlRpcException(
"Request XML not valid XML-RPC - missing methodName element.");
}
request.method = methodNode.FirstChild.Value;
if (request.method == "")
{
throw new XmlRpcInvalidXmlRpcException(
"Request XML not valid XML-RPC - empty methodName.");
}
request.mi = null;
ParameterInfo[] pis = new ParameterInfo[0];
if (svcType != null)
{
// retrieve info for the method which handles this XML-RPC method
XmlRpcServiceInfo svcInfo
= XmlRpcServiceInfo.CreateServiceInfo(svcType);
request.mi = svcInfo.GetMethodInfo(request.method);
// if a service type has been specified and we cannot find the requested
// method then we must throw an exception
if (request.mi == null)
{
string msg = String.Format("unsupported method called: {0}",
request.method);
throw new XmlRpcUnsupportedMethodException(msg);
}
// 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,
//.........这里部分代码省略.........
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:101,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例3: ParseValue
Object ParseValue(
XmlNode node,
Type ValueType,
ParseStack parseStack,
MappingAction mappingAction)
{
Type parsedType;
Type parsedArrayType;
return ParseValue(node, ValueType, parseStack, mappingAction,
out parsedType, out parsedArrayType);
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:11,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例4: ReportMissingMembers
void ReportMissingMembers(
Type valueType,
Hashtable names,
ParseStack parseStack)
{
StringBuilder sb = new StringBuilder();
int errorCount = 0;
string sep = "";
foreach (string s in names.Keys)
{
MappingAction memberAction = MemberMappingAction(valueType, s,
MappingAction.Error);
if (memberAction == MappingAction.Error)
{
sb.Append(sep);
sb.Append(s);
sep = " ";
errorCount++;
}
}
if (errorCount > 0)
{
string plural = "";
if (errorCount > 1)
plural = "s";
throw new XmlRpcTypeMismatchException(parseStack.ParseType
+ " contains struct value with missing non-optional member"
+ plural + ": " + sb.ToString() + " " + StackDump(parseStack));
}
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:30,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例5: 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
示例6: 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;
}
开发者ID:jbrunken,项目名称:ActiveForumsTapatalkXmlRpc,代码行数:101,代码来源:XmlRpcSerializer.cs
示例7: ParseMultiDimArray
Object ParseMultiDimArray(XmlNode node, Type ValueType,
ParseStack parseStack, MappingAction mappingAction)
{
// parse the type name to get element type and array rank
#if (!COMPACT_FRAMEWORK)
Type elemType = ValueType.GetElementType();
int rank = ValueType.GetArrayRank();
#else
string[] checkMultiDim = Regex.Split(ValueType.FullName,
"\\[,[,]*\\]$");
Type elemType = Type.GetType(checkMultiDim[0]);
string commas = ValueType.FullName.Substring(checkMultiDim[0].Length+1,
ValueType.FullName.Length-checkMultiDim[0].Length-2);
int rank = commas.Length+1;
#endif
// elements will be stored sequentially as nested arrays are parsed
ArrayList elements = new ArrayList();
// create array to store length of each dimension - initialize to
// all zeroes so that when parsing we can determine if an array for
// that dimension has been parsed already
int[] dimLengths = new int[rank];
dimLengths.Initialize();
ParseMultiDimElements(node, rank, 0, elemType, elements, dimLengths,
parseStack, mappingAction);
// build arguments to define array dimensions and create the array
Object[] args = new Object[dimLengths.Length];
for (int argi=0; argi<dimLengths.Length; argi++)
{
args[argi] = dimLengths[argi];
}
Array ret = (Array)CreateArrayInstance(ValueType, args);
// copy elements into new multi-dim array
//!! make more efficient
int length = ret.Length;
for (int e=0; e<length; e++)
{
int[] indices = new int[dimLengths.Length];
int div = 1;
for (int f=(indices.Length-1); f>=0; f--)
{
indices[f] = (e/div)%dimLengths[f];
div*=dimLengths[f];
}
ret.SetValue(elements[e], indices);
}
return ret;
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:47,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例8: 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
示例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: 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
示例11: ParseFault
XmlRpcFaultException ParseFault(
XmlNode faultNode,
ParseStack parseStack,
MappingAction mappingAction)
{
XmlNode valueNode = faultNode.SelectSingleNode("./value");
XmlNode structNode = valueNode.SelectSingleNode("./struct");
if (structNode == null)
{
throw new XmlRpcInvalidXmlRpcException(
"struct element missing from fault response.");
}
Fault fault;
try
{
fault = (Fault)ParseValue(structNode, typeof(Fault), parseStack,
mappingAction);
}
catch(Exception ex)
{
// some servers incorrectly return fault code in a string
if (AllowStringFaultCode)
throw;
else
{
FaultStructStringCode faultStrCode;
try
{
faultStrCode = (FaultStructStringCode)ParseValue(structNode,
typeof(FaultStructStringCode), parseStack, mappingAction);
fault.faultCode = Convert.ToInt32(faultStrCode.faultCode);
fault.faultString = faultStrCode.faultString;
}
catch (Exception)
{
// use exception from when attempting to parse code as integer
throw ex;
}
}
}
return new XmlRpcFaultException(fault.faultCode, fault.faultString);
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:42,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例12: 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
示例13: 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;
}
开发者ID:nevasion,项目名称:gandi-desktop,代码行数:59,代码来源:XmlRpcSerializer.cs
示例14: DeserializeResponse
public XmlRpcResponse DeserializeResponse(XmlDocument xdoc, Type returnType)
{
XmlRpcResponse response = new XmlRpcResponse();
Object retObj = null;
XmlNode methodResponseNode = xdoc.SelectSingleNode("./methodResponse");
if (methodResponseNode == null)
{
throw new XmlRpcInvalidXmlRpcException(
"Response XML not valid XML-RPC - missing methodResponse element.");
}
// check for fault response
XmlNode faultNode = methodResponseNode.SelectSingleNode("./fault");
if (faultNode != null)
{
ParseStack parseStack = new ParseStack("fault response");
// TODO: use global action setting
MappingAction mappingAction = MappingAction.Error;
XmlRpcFaultException faultEx = ParseFault(faultNode, parseStack,
mappingAction);
throw faultEx;
}
XmlNode paramsNode = methodResponseNode.SelectSingleNode("./params");
if (paramsNode == null && returnType != null)
{
if (returnType == typeof(void))
return null;
else
throw new XmlRpcInvalidXmlRpcException(
"Response XML not valid XML-RPC - missing params element.");
}
XmlNode paramNode = paramsNode.SelectSingleNode("./param");
if (paramNode == null && returnType != null)
{
if (returnType == typeof(void))
return null;
else
throw new XmlRpcInvalidXmlRpcException(
"Response XML not valid XML-RPC - missing params element.");
}
XmlNode valueNode = paramNode.SelectSingleNode("./value");
if (valueNode == null)
{
throw new XmlRpcInvalidXmlRpcException(
"Response XML not valid XML-RPC - missing value element.");
}
if (returnType == typeof(void))
{
retObj = null;
}
else
{
ParseStack parseStack = new ParseStack("response");
// TODO: use global action setting
MappingAction mappingAction = MappingAction.Error;
XmlNode node = valueNode.SelectSingleNode("./*");
if (node == null)
node = valueNode.FirstChild;
retObj = ParseValue(node, returnType, parseStack, mappingAction);
}
response.retVal = retObj;
return response;
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:62,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例15: ParseMultiDimElements
void ParseMultiDimElements(XmlNode node, int Rank, int CurRank,
Type elemType, ArrayList elements, int[] dimLengths,
ParseStack parseStack, MappingAction mappingAction)
{
if (node.Name != "array")
{
throw new XmlRpcTypeMismatchException(
"param element does not contain array element.");
}
XmlNode dataNode = node.SelectSingleNode("./data");
XmlNodeList childNodes = dataNode.SelectNodes("./value");
int nodeCount = childNodes.Count;
//!! check that multi dim array is not jagged
if (dimLengths[CurRank] != 0 && nodeCount != dimLengths[CurRank])
{
throw new XmlRpcNonRegularArrayException(
"Multi-dimensional array must not be jagged.");
}
dimLengths[CurRank] = nodeCount; // in case first array at this rank
if (CurRank < (Rank-1))
{
foreach (XmlNode vNode in childNodes)
{
XmlNode arrayNode = vNode.SelectSingleNode("./array");
ParseMultiDimElements(arrayNode, Rank, CurRank+1, elemType,
elements, dimLengths, parseStack, mappingAction);
}
}
else
{
foreach (XmlNode vNode in childNodes)
{
XmlNode vvNode = vNode.SelectSingleNode("./*");
if (node == null)
node = vNode.FirstChild;
elements.Add(ParseValue(vvNode, elemType, parseStack,
mappingAction));
}
}
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:40,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例16: 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
示例17: 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
示例18: ParseStruct
Object ParseStruct(
XmlNode node,
Type valueType,
ParseStack parseStack,
MappingAction mappingAction)
{
if (valueType.IsPrimitive)
{
throw new XmlRpcTypeMismatchException(parseStack.ParseType
+ " contains struct value where "
+ XmlRpcServiceInfo.GetXmlRpcTypeString(valueType)
+ " expected " + StackDump(parseStack));
}
#if !FX1_0
if (valueType.IsGenericType
&& valueType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
valueType = valueType.GetGenericArguments()[0];
}
#endif
object retObj;
try
{
retObj = Activator.CreateInstance(valueType);
}
catch (Exception ex)
{
throw new XmlRpcTypeMismatchException(parseStack.ParseType
+ " contains struct value where "
+ XmlRpcServiceInfo.GetXmlRpcTypeString(valueType)
+ " expected (as type " + valueType.Name + ") "
+ StackDump(parseStack));
}
// Note: mapping action on a struct is only applied locally - it
// does not override the global mapping action when members of the
// struct are parsed
MappingAction localAction = mappingAction;
if (valueType != null)
{
parseStack.Push("struct mapped to type " + valueType.Name);
localAction = StructMappingAction(valueType, mappingAction);
}
else
{
parseStack.Push("struct");
}
// create map of field names and remove each name from it as
// processed so we can determine which fields are missing
// TODO: replace HashTable with lighter collection
Hashtable names = new Hashtable();
foreach (FieldInfo fi in valueType.GetFields())
{
names.Add(fi.Name, fi.Name);
}
foreach (PropertyInfo pi in valueType.GetProperties())
{
names.Add(pi.Name, pi.Name);
}
XmlNodeList members = node.SelectNodes("./member");
int fieldCount = 0;
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 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));
//.........这里部分代码省略.........
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:101,代码来源:Copy+of+XmlRpcSerializer+-+preservewhitepace.cs
示例19: 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
|
请发表评论