本文整理汇总了C#中CodeProcessor.DefinePublic方法的典型用法代码示例。如果您正苦于以下问题:C# CodeProcessor.DefinePublic方法的具体用法?C# CodeProcessor.DefinePublic怎么用?C# CodeProcessor.DefinePublic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeProcessor
的用法示例。
在下文中一共展示了CodeProcessor.DefinePublic方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildUPnPResponse
private void BuildUPnPResponse(CodeProcessor cs, UPnPDevice device, Hashtable serviceNames)
{
foreach (UPnPService service in device.Services)
{
ServiceGenerator.ServiceConfiguration SConf = (ServiceGenerator.ServiceConfiguration)service.User;
foreach (UPnPAction action in service.Actions)
{
StringBuilder SB = new StringBuilder();
SB.Append(pc_methodPrefixDef + "Response_" + serviceNames[service] + "_" + action.Name + "(const UPnPSessionToken UPnPToken");
int argcount = 0;
foreach (UPnPArgument arg in action.Arguments)
{
if (arg.Direction == "out")
{
if (arg.RelatedStateVar.ComplexType == null)
{
// Primitive
SB.Append(", const " + ToCType(arg.RelatedStateVar.GetNetType().ToString()) + " ");
if (arg.RelatedStateVar.GetNetType() == typeof(string) && !SConf.Actions_ManualEscape.Contains(action))
{
SB.Append("unescaped_" + arg.Name);
}
else
{
SB.Append(arg.Name);
}
if (arg.RelatedStateVar.GetNetType().FullName == "System.Byte[]")
{
SB.Append(", const int _" + arg.Name + "Length");
}
}
else
{
// Complex
SB.Append(", struct " + arg.RelatedStateVar.ComplexType.Name_LOCAL + " *_" + arg.Name);
}
argcount++;
}
}
SB.Append(")");
cs.Append("/*! \\fn " + SB.ToString() + cl);
cs.Append(" \\brief Response Method for " + serviceNames[service] + " >> " + service.ServiceURN + " >> " + action.Name + cl);
cs.Append(" \\param UPnPToken MicroStack token" + cl);
foreach (UPnPArgument arg in action.Arguments)
{
if (arg.Direction == "out")
{
cs.Append(" \\param ");
if (arg.RelatedStateVar.ComplexType == null)
{
// Primitive
if (arg.RelatedStateVar.GetNetType() == typeof(string) && !SConf.Actions_ManualEscape.Contains(action))
{
cs.Append("unescaped_" + arg.Name + " Value of argument " + arg.Name + " \\b Note: Automatically Escaped" + cl);
}
else
{
cs.Append(arg.Name + " Value of argument " + arg.Name);
if (arg.RelatedStateVar.GetNetType() == typeof(string))
{
cs.Append(" \\b Note: Must be escaped" + cl);
}
else
{
cs.Append(cl);
}
}
if (arg.RelatedStateVar.GetNetType().FullName == "System.Byte[]")
{
cs.Append(" \\param " + arg.Name + "Length Length of \\a " + arg.Name + cl);
}
}
else
{
// Complex
cs.Append(" _" + arg.Name + " Value of argument " + arg.Name + cl);
}
}
}
cs.Append("*/" + cl);
cs.DefinePublic("void " + SB.ToString());
cs.Append("{" + cl);
if (argcount == 0)
{
cs.Append(pc_methodPrefixDef + "ResponseGeneric(UPnPToken,\"" + service.ServiceURN + "\",\"" + action.Name + "\",\"\");" + cl);
cs.Append("}" + cl);
cs.Append(cl);
continue;
}
foreach (UPnPArgument arg in action.Arguments)
{
if (arg.RelatedStateVar.ComplexType != null)
{
cs.Append(" char *tempString;" + cl);
break;
//.........这里部分代码省略.........
示例2: BuildMulticastSoapEvents
private void BuildMulticastSoapEvents(CodeProcessor cs, UPnPDevice device, Hashtable serviceNames)
{
foreach (UPnPService service in device.Services)
{
foreach (UPnPStateVariable statevar in service.GetStateVariables())
{
if (statevar.MulticastEvent)
{
#region Initialize
string eventname = "UPnPObject->" + serviceNames[service] + "_" + statevar.Name;
string binaryextra = "";
if (statevar.GetNetType().ToString() == "System.Byte[]") binaryextra = ",int vallen";
#endregion
cs.DefinePublic("void " + pc_methodPrefixDef + "SetMulticastState_" + serviceNames[service] + "_" + statevar.Name + "(UPnPMicroStackToken upnptoken, enum MULTICAST_EVENT_TYPE eventType, " + ToCType(statevar.GetNetType().ToString()) + " val" + binaryextra + ")");
cs.Append("{" + cl);
cs.Append(" struct " + pc_methodPrefix + "DataObject *UPnPObject = (struct " + pc_methodPrefix + "DataObject*)upnptoken;" + cl);
cs.Append(" char *b;" + cl);
cs.Append(" int bLength;" + cl);
cs.Append(" void *response_socket;" + cl);
cs.Append(" void *subChain;" + cl);
cs.Append(" int *addrList;" + cl);
cs.Append(" int addrListLength;" + cl);
cs.Append(" int i;" + cl);
cs.Append(" char newVal[32];" + cl); //ToDo: Magic Value
cs.Append(" if ((b = (char*)malloc(5000)) == NULL) ILIBCRITICALEXIT(254);" + cl); //ToDo: Magic Value
cs.Append(cl);
cs.Append(" subChain = ILibCreateChain();" + cl);
cs.Append(" response_socket = ILibAsyncUDPSocket_Create(" + cl);
cs.Append(" subChain," + cl);
cs.Append(" UPNP_MAX_SSDP_HEADER_SIZE," + cl);
cs.Append(" 0," + cl);
cs.Append(" 0," + cl);
cs.Append(" ILibAsyncUDPSocket_Reuse_SHARED," + cl);
cs.Append(" NULL," + cl);
cs.Append(" NULL," + cl);
cs.Append(" subChain);" + cl);
cs.Append(cl);
cs.Append(" ++" + pc_methodPrefix + "Object->" + serviceNames[service] + "_" + statevar.Name + "_SEQ;" + cl);
cs.Append(cl);
cs.Append(" snprintf(newVal, 32, \"%d\", val);" + cl);
cs.Append(" bLength = snprintf(b, 5000, UPnPMulticastPacketTemplate," + cl); //ToDo: Magic Value
cs.Append(" UPNP_GROUP," + cl);
cs.Append(" UPNP_MULTICASTEVENT_PORT," + cl);
cs.Append(" UPnPObject->UDN," + cl);
cs.Append(" \"" + service.ServiceURN + "\"," + cl);
cs.Append(" UPnPObject->" + serviceNames[service] + "_" + statevar.Name + "_SEQ," + cl);
cs.Append(" MULTICAST_EVENT_TYPE_DESCRIPTION[(int)eventType]," + cl);
cs.Append(" UPnPObject->InitialNotify," + cl);
cs.Append(" \"" + statevar.Name + "\"," + cl);
cs.Append(" newVal," + cl);
cs.Append(" \"" + statevar.Name + "\");" + cl);
cs.Append(" addrListLength = ILibGetLocalIPAddressList(&addrList);" + cl);
cs.Append(" ILibAsyncUDPSocket_JoinMulticastGroup(response_socket, 0, inet_addr(UPNP_GROUP));" + cl);
cs.Append(" for(i = 0; i < addrListLength; ++i)" + cl);
cs.Append(" {" + cl);
cs.Append(" ILibAsyncUDPSocket_SetMulticastInterface(response_socket, addrList[i]);" + cl);
cs.Append(" ILibAsyncUDPSocket_SendTo(response_socket, inet_addr(UPNP_GROUP), UPNP_MULTICASTEVENT_PORT, b, bLength, ILibAsyncSocket_MemoryOwnership_USER);" + cl);
cs.Append(" }" + cl);
cs.Append(" free(addrList);" + cl);
cs.Append(" ILibChain_DestroyEx(subChain);" + cl);
cs.Append("}" + cl);
}
}
}
foreach (UPnPDevice d in device.EmbeddedDevices)
{
this.BuildMulticastSoapEvents(cs, d, serviceNames);
}
}
示例3: BuildSoapEvents
private void BuildSoapEvents(CodeProcessor cs, UPnPDevice device, Hashtable serviceNames)
{
//string soap_eventblock = "<?xml version=\"1.0\" encoding=\"utf-8\"?><e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\"><e:property><%s>%s</%s></e:property></e:propertyset>";
string soap_eventblock = "%s>%s</%s";
foreach (UPnPService service in device.Services)
{
#region Calculate number of evented variables
int eventedStateVariables = 0;
foreach (UPnPStateVariable statevar in service.GetStateVariables())
{
if (statevar.SendEvent == true) eventedStateVariables++;
}
#endregion
foreach (UPnPStateVariable statevar in service.GetStateVariables())
{
if (statevar.SendEvent == true)
{
#region Initialize
string eventname = "UPnPObject->" + serviceNames[service] + "_" + statevar.Name;
string binaryextra = "";
if (statevar.GetNetType().ToString() == "System.Byte[]") binaryextra = ",int vallen";
#endregion
#region SetState
cs.Append("/*! \\fn " + pc_methodPrefixDef + "SetState_" + serviceNames[service] + "_" + statevar.Name + "(UPnPMicroStackToken upnptoken, " + ToCType(statevar.GetNetType().ToString()) + " val" + binaryextra + ")" + cl);
cs.Append(" \\brief Sets the state of " + statevar.Name + " << " + statevar.OwningService.ServiceURN + " << " + serviceNames[service] + " \\par" + cl);
cs.Append(" \\b Note: Must be called at least once prior to start" + cl);
cs.Append(" \\param upnptoken The MicroStack token" + cl);
cs.Append(" \\param val The new value of the state variable" + cl);
if (binaryextra != "")
{
cs.Append(" \\param vallen Length of \\a val" + cl);
}
cs.Append("*/" + cl);
cs.DefinePublic("void " + pc_methodPrefixDef + "SetState_" + serviceNames[service] + "_" + statevar.Name + "(UPnPMicroStackToken upnptoken, " + ToCType(statevar.GetNetType().ToString()) + " val" + binaryextra + ")");
cs.Append("{" + cl);
cs.Append(" struct " + pc_methodPrefix + "DataObject *UPnPObject = (struct " + pc_methodPrefix + "DataObject*)upnptoken;" + cl);
cs.Append(" char* body;" + cl);
cs.Append(" int bodylength;" + cl);
if (statevar.GetNetType().ToString() == "System.Byte[]")
{
cs.Append(" unsigned char* valstr;" + cl);
}
else
{
cs.Append(" char* valstr;" + cl);
}
#region Data Handling
// Data Type Handling Code
switch (statevar.GetNetType().ToString())
{
case "System.Boolean":
cs.Append(" if (val != 0) valstr = \"true\"; else valstr = \"false\";" + cl);
break;
case "System.Byte[]":
cs.Append(" " + pc_methodLibPrefix + "Base64Encode(val, vallen, &valstr);" + cl);
break;
case "System.Uri":
case "System.String":
cs.Append(" if ((valstr = (char*)malloc(" + pc_methodLibPrefix + "XmlEscapeLength(val) + 1)) == NULL) ILIBCRITICALEXIT(254);" + cl);
cs.Append(" " + this.pc_methodLibPrefix + "XmlEscape(valstr, val);" + cl);
break;
case "System.Byte":
case "System.Int16":
case "System.Int32":
cs.Append(" if ((valstr = (char*)malloc(10)) == NULL) ILIBCRITICALEXIT(254);" + cl);
cs.Append(" snprintf(valstr, 10, \"%d\", val);" + cl);
break;
case "System.Char":
case "System.SByte":
case "System.UInt16":
case "System.UInt32":
cs.Append(" if ((valstr = (char*)malloc(10)) == NULL) ILIBCRITICALEXIT(254);" + cl);
cs.Append(" snprintf(valstr, 10, \"%u\", val);" + cl);
break;
case "System.Single":
case "System.Double":
cs.Append(" if ((valstr = (char*)malloc(30)) == NULL) ILIBCRITICALEXIT(254);" + cl);
cs.Append(" snprintf(valstr, 30, \"%f\", val);" + cl);
break;
case "System.DateTime":
cs.Append(" valstr = " + this.pc_methodLibPrefix + "Time_Serialize(val);" + cl);
break;
default:
cs.Append(" char* valuestr = NULL;" + cl);
break;
}
#endregion
#region Memory Handling
// Data Type Handling Code
switch (statevar.GetNetType().ToString())
{
case "System.Uri":
case "System.String":
case "System.Byte[]":
case "System.Byte":
case "System.Int16":
case "System.Int32":
//.........这里部分代码省略.........
示例4: BuildSoapEvents
private void BuildSoapEvents(CodeProcessor cs, UPnPDevice device, Hashtable serviceNames)
{
string soap_eventblock = "<?xml version=\"1.0\" encoding=\"utf-8\"?><e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\"><e:property><%s>%s</%s></e:property></e:propertyset>";
foreach (UPnPService service in device.Services)
{
int eventedStateVariables = 0;
foreach (UPnPStateVariable statevar in service.GetStateVariables())
{
if (statevar.SendEvent == true) eventedStateVariables++;
}
foreach (UPnPStateVariable statevar in service.GetStateVariables())
{
if (statevar.SendEvent == true)
{
string eventname = serviceNames[service] + "_" + statevar.Name;
cs.DefinePublic("void "+pc_methodPrefixDef+"SetState_" + serviceNames[service] + "_" + statevar.Name + "(" + ToCType(statevar.GetNetType().ToString()) + " val)");
cs.Append("{" + cl);
cs.Append(" char* valstr;" + cl);
cs.Append(" char* body;" + cl);
cs.Append(" int bodylength;" + cl);
// Data Type Handling Code
switch (statevar.GetNetType().ToString())
{
case "System.Boolean":
cs.Append(" if (val != 0) valstr = \"true\"; else valstr = \"false\";" + cl);
break;
case "System.Byte[]":
case "System.Uri":
case "System.String":
cs.Append(" if ((valstr = (char*)malloc((int)strlen(val) + 1)) == NULL) ILIBCRITICALEXIT(254);" + cl);
cs.Append(" strcpy(valstr, val);" + cl);
break;
case "System.Byte":
case "System.Int16":
case "System.Int32":
cs.Append(" if ((valstr = (char*)malloc(10)) == NULL) ILIBCRITICALEXIT(254);" + cl);
cs.Append(" sprintf(valstr, \"%d\", val);" + cl);
break;
case "System.Char":
case "System.SByte":
case "System.UInt16":
case "System.UInt32":
cs.Append(" if ((valstr = (char*)malloc(10)) == NULL) ILIBCRITICALEXIT(254);" + cl);
cs.Append(" sprintf(valstr, \"%u\", val);" + cl);
break;
case "System.Single":
case "System.Double":
cs.Append(" if ((valstr = (char*)malloc(30)) == NULL) ILIBCRITICALEXIT(254);" + cl);
cs.Append(" sprintf(valstr, \"%f\", val);" + cl);
break;
default:
cs.Append(" char* valuestr = NULL;" + cl);
break;
}
if (statevar.GetNetType().ToString() != "System.Boolean")
{
cs.Append(" if (" + eventname + " != NULL) free("+eventname+");" + cl);
}
cs.Append(" " + eventname + " = valstr;" + cl);
cs.Append(" if ((body = (char*)malloc(" + (soap_eventblock.Length + (statevar.Name.Length * 2) + 1) + " + (int)strlen(valstr))) == NULL) ILIBCRITICALEXIT(254);" + cl);
cs.Append(" bodylength = sprintf(body, \"" + PrintfTransform(soap_eventblock) + "\", \"" + statevar.Name + "\", valstr, \"" + statevar.Name + "\");" + cl);
cs.Append(" "+pc_methodPrefix+"SendEvent(body, bodylength, \""+(string)serviceNames[service]+"\");" + cl);
//cs.Append(" free(body);" + cl);
cs.Append("}" + cl);
cs.Append(cl);
}
}
}
foreach(UPnPDevice d in device.EmbeddedDevices)
{
this.BuildSoapEvents(cs,d,serviceNames);
}
}