本文整理汇总了C#中CodeProcessor.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# CodeProcessor.ToString方法的具体用法?C# CodeProcessor.ToString怎么用?C# CodeProcessor.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeProcessor
的用法示例。
在下文中一共展示了CodeProcessor.ToString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build_UPnPHTTPClient
public bool Build_UPnPHTTPClient(DirectoryInfo outputDirectory)
{
StreamWriter writer;
if (this.Platform == PLATFORMS.POSIX)
{
pc_SockType = "int";
// pc_TimeType = "struct timeval";
pc_SockClose = "close";
// pc_stricmp = "strncasecmp";
}
if (this.Platform == PLATFORMS.WINDOWS)
{
pc_SockType = "SOCKET";
// pc_TimeType = "unsigned int";
pc_SockClose = "closesocket";
// pc_stricmp = "_strnicmp";
}
if (this.Language == LANGUAGES.C)
{
pc_methodPrefix = CallPrefix;
pc_methodLibPrefix = CallLibPrefix;
pc_methodPrefixDef = CallingConvention + CallPrefix;
}
CodeProcessor cs = new CodeProcessor(new StringBuilder(),this.Language == LANGUAGES.CPP);
/* Build UPnPHTTPClient.h */
AddLicense(cs,pc_methodPrefix+"HTTPClient.h");
cs.Append(cl);
cs.Append("#ifndef __"+pc_methodPrefix+"HTTPClient__"+cl);
cs.Append("#define __"+pc_methodPrefix+"HTTPClient__"+cl);
cs.Append(cl);
cs.Append("#define HTTP_SESSION_INTERRUPT_CHAIN 1"+cl);
cs.Append("#define HTTP_SESSION_INTERRUPT_PEERRESET 2"+cl);
cs.Append("#define HTTP_INTERRUPT_CHAIN 3"+cl);
cs.Append("#define HTTP_DELETEREQUEST_INTERRUPT 4"+cl);
cs.Append("#define "+pc_methodPrefix+"AddRequest_Direct(ClientModule, buffer, bufferlength,Destination, CallbackPtr, user, user2) "+pc_methodPrefix+"AddRequest_DirectEx(ClientModule, buffer, bufferlength,NULL,0,Destination, CallbackPtr, user, user2)"+cl);
cs.Append(cl);
cs.Comment("Forward Declaration");
cs.Append("struct packetheader;"+cl+cl);
cs.Append("void* "+pc_methodPrefix+"CreateHTTPClientModule(void *Chain, int MaxSockets);"+cl);
cs.Append("void "+pc_methodPrefix+"DestroyHTTPClientModule(void *ClientModule);"+cl);
cs.Append(cl);
cs.Append("char* "+pc_methodPrefix+"GetReceivingInterface(void* ReaderObject);"+cl);
cs.Append("void "+pc_methodPrefix+"AddRequest(void *ClientModule, struct packetheader *packet,struct sockaddr_in *Destination, void (*CallbackPtr)(void *reader, struct packetheader *header, int IsInterrupt,char* buffer, int *p_BeginPointer, int EndPointer, int done, void* user, void* user2), void* user, void* user2);"+cl);
cs.Append("void "+pc_methodPrefix+"AddRequest_DirectEx(void *ClientModule, char *buffer, int bufferlength,char *buffer2, int buffer2length,struct sockaddr_in *Destination, void (*CallbackPtr)(void *reader, struct packetheader *header, int IsInterrupt, char* buffer, int *p_BeginPointer, int EndPointer, int done, void* user, void* user2), void* user, void* user2);"+cl);
cs.Append("void "+pc_methodPrefix+"CloseRequest(void* ReaderObject);"+cl);
cs.Append("void "+pc_methodPrefix+"DeleteRequests(void *ClientModule, void *user1);"+cl);
cs.Append(cl);
cs.Append("#endif"+cl);
writer = File.CreateText(outputDirectory.FullName + "\\"+pc_methodPrefix+"HTTPClient.h");
writer.Write(cs.ToString());
writer.Close();
/* Build UPnPHTTPClient.c */
cs = new CodeProcessor(new StringBuilder(),this.Language == LANGUAGES.CPP);
if (this.Language == LANGUAGES.CPP)
{
AddLicense(cs,pc_methodPrefix+"HTTPClient.cpp");
}
else
{
AddLicense(cs,pc_methodPrefix+"HTTPClient.c");
}
cs.Append(cl);
if (this.Platform==PLATFORMS.WINDOWS)
{
cs.Append("#ifndef MICROSTACK_NO_STDAFX"+cl);
cs.Append("#include \"stdafx.h\""+cl);
cs.Append("#endif"+cl);
cs.Append("#define _CRTDBG_MAP_ALLOC"+cl);
cs.Append("#include <math.h>"+cl);
cs.Append("#include <winerror.h>"+cl);
cs.Append("#include <stdlib.h>"+cl);
cs.Append("#include <stdio.h>"+cl);
cs.Append("#include <stddef.h>"+cl);
cs.Append("#include <string.h>"+cl);
if (this.WinSock == 1)
{
cs.Append("#include <winsock.h>"+cl);
cs.Append("#include <wininet.h>"+cl);
}
if (this.WinSock == 2)
{
cs.Append("#include <winsock2.h>"+cl);
cs.Append("#include <ws2tcpip.h>"+cl);
}
if (this.SubTarget != SUBTARGETS.PPC2003)
{
// cs.Append("#include <errno.h>"+cl);
}
//.........这里部分代码省略.........
示例2: GenerateEx
//.........这里部分代码省略.........
cs.Append(" }" + cl);
cs.Append(cl);
cs.Append(" public void UnicastSearch(IPAddress address)" + cl);
cs.Append(" {" + cl);
cs.Append(" scp.UnicastSearch(address);" + cl);
cs.Append(" }" + cl);
cs.Append(cl);
cs.Append(" public void ForceDisposeDevice(UPnPDevice dev)" + cl);
cs.Append(" {" + cl);
cs.Append(" if (dev.ParentDevice != null)" + cl);
cs.Append(" {" + cl);
cs.Append(" ForceDisposeDevice(dev.ParentDevice);" + cl);
cs.Append(" }" + cl);
cs.Append(" else" + cl);
cs.Append(" {" + cl);
cs.Append(" scp.ForceDisposeDevice(dev);" + cl);
cs.Append(" }" + cl);
cs.Append(" }" + cl);
cs.Append(cl);
cs.Append(" private void OnAddSink(UPnPSmartControlPoint sender, UPnPDevice d)" + cl);
cs.Append(" {" + cl);
cs.Append(" AddEvent.Fire(this, d);" + cl);
cs.Append(" }" + cl);
cs.Append(cl);
cs.Append(" private void OnRemoveSink(UPnPSmartControlPoint sender, UPnPDevice d)" + cl);
cs.Append(" {" + cl);
cs.Append(" RemoveEvent.Fire(this, d);" + cl);
cs.Append(" }" + cl);
cs.Append(" }" + cl);
cs.Append("}" + cl);
cs.Append(cl);
writer = File.CreateText(outputDirectory.FullName + "\\" + dt[4] + "Discovery.cs");
writer.Write(cs.ToString());
writer.Close();
cs = new CodeProcessor(new StringBuilder(), true);
cs.Comment("UPnP .NET Framework Control Point Stack, Core Module");
cs.Comment(VersionString);
cs.Append(cl);
cs.Append("using System;" + cl);
cs.Append("using OpenSource.UPnP;" + cl);
cs.Append("using " + nspace + ";" + cl);
cs.Append(cl);
cs.Append("namespace " + nspace + cl);
cs.Append("{" + cl);
cs.Append(" /// <summary>" + cl);
cs.Append(" /// Summary description for Main." + cl);
cs.Append(" /// </summary>" + cl);
cs.Append(" class SampleDeviceMain" + cl);
cs.Append(" {" + cl);
cs.Append(" /// <summary>" + cl);
cs.Append(" /// The main entry point for the application." + cl);
cs.Append(" /// </summary>" + cl);
cs.Append(" [STAThread]" + cl);
cs.Append(" static void Main(string[] args)" + cl);
cs.Append(" {" + cl);
cs.Append(" System.Console.WriteLine(\"UPnP .NET Framework Stack\");" + cl);
cs.Append(" System.Console.WriteLine(\"StackBuilder Build#" + this.VersionString + "\");" + cl);
cs.Append(" " + cl);
cs.Append(" " + dt[4] + "Discovery disco = new " + dt[4] + "Discovery();" + cl);
cs.Append(" disco.OnAddedDevice += new " + dt[4] + "Discovery.DiscoveryHandler(AddSink);" + cl);
cs.Append(" disco.OnRemovedDevice += new " + dt[4] + "Discovery.DiscoveryHandler(RemoveSink);" + cl);
cs.Append(" " + cl);
cs.Append(" System.Console.WriteLine(\"Press return to stop CP.\");" + cl);
cs.Append(" disco.Start();" + cl);
示例3: GetCPlusPlusAbstraction_CPP
public static string GetCPlusPlusAbstraction_CPP(UPnPDevice[] devices)
{
string WC = SourceCodeRepository.GetCPlusPlus_Template_CPP("UPnP");
string WC2;
CodeProcessor sb = new CodeProcessor(new StringBuilder(),false);
bool ok = false;
bool cpok = false;
foreach(UPnPDevice d in devices)
{
if (((ServiceGenerator.Configuration)d.User).ConfigType==ServiceGenerator.ConfigurationType.DEVICE)
{
WC2 = SourceCodeRepository.GetTextBetweenTags(WC,"//{{{MicroStackInclude_Begin}}}","//{{{MicroStackInclude_End}}}");
WC2 = WC2.Replace("{{{PREFIX}}}",((ServiceGenerator.Configuration)d.User).Prefix);
WC = SourceCodeRepository.InsertTextBeforeTag(WC,"//{{{MicroStackInclude_Begin}}}",WC2);
WC2 = SourceCodeRepository.GetTextBetweenTags(WC,"//{{{Manager_Constructor_Begin}}}","//{{{Manager_Constructor_End}}}");
WC2 = WC2.Replace("{{{DEVICE}}}","UPnP_Device_"+d.User2.ToString());
WC = SourceCodeRepository.InsertTextBeforeTag(WC,"//{{{Manager_Constructor_Begin}}}",WC2);
WC2 = SourceCodeRepository.GetTextBetweenTags(WC,"//{{{Manager_GetDevice_Begin}}}","//{{{Manager_GetDevice_End}}}");
WC2 = WC2.Replace("{{{DEVICE}}}","UPnP_Device_"+d.User2.ToString());
WC = SourceCodeRepository.InsertTextBeforeTag(WC,"//{{{Manager_GetDevice_Begin}}}",WC2);
WC2 = SourceCodeRepository.GetTextBetweenTags(WC,"//{{{Manager_Destructor_Begin}}}","//{{{Manager_Destructor_End}}}");
WC2 = WC2.Replace("{{{DEVICE}}}","UPnP_Device_"+d.User2.ToString());
WC = SourceCodeRepository.InsertTextBeforeTag(WC,"//{{{Manager_Destructor_Begin}}}",WC2);
WC2 = SourceCodeRepository.GetTextBetweenTags(WC,"//{{{IPADDRESS_HANDLER_BEGIN}}}","//{{{IPADDRESS_HANDLER_END}}}");
WC2 = WC2.Replace("{{{PREFIX}}}",((ServiceGenerator.Configuration)d.User).Prefix);
WC2 = WC2.Replace("{{{DEVICE}}}","UPnP_Device_"+d.User2.ToString());
WC = SourceCodeRepository.InsertTextBeforeTag(WC,"//{{{IPADDRESS_HANDLER_BEGIN}}}",WC2);
WC2 = GetCPlusPlusAbstraction_CPP_Device(WC,d);
WC = SourceCodeRepository.InsertTextBeforeTag(WC,"//{{{Device_Begin}}}",WC2);
ok = true;
}
else
{
// Includes
WC2 = SourceCodeRepository.GetTextBetweenTags(WC,"//{{{CPMicroStackInclude_Begin}}}","//{{{CPMicroStackInclude_End}}}");
WC2 = WC2.Replace("{{{PREFIX}}}",((ServiceGenerator.Configuration)d.User).Prefix);
WC = SourceCodeRepository.InsertTextBeforeTag(WC,"//{{{CPMicroStackInclude_Begin}}}",WC2);
// Constructor
WC2 = SourceCodeRepository.GetTextBetweenTags(WC,"//{{{Manager_CPConstructor_Begin}}}","//{{{Manager_CPConstructor_End}}}");
WC2 = WC2.Replace("{{{DEVICE}}}",d.User2.ToString());
WC2 = WC2.Replace("{{{PREFIX}}}",((ServiceGenerator.Configuration)d.User).Prefix);
WC2 = WC2.Replace("{{{DEVICEID}}}",d.GetHashCode().ToString());
WC = SourceCodeRepository.InsertTextBeforeTag(WC,"//{{{Manager_CPConstructor_Begin}}}",WC2);
// Discover/Remove Sinks
WC2 = SourceCodeRepository.GetTextBetweenTags(WC,"//{{{BEGIN_CPDiscoverSink}}}","//{{{END_CPDiscoverSink}}}");
WC2 = WC2.Replace("{{{PREFIX}}}",((ServiceGenerator.Configuration)d.User).Prefix);
WC2 = WC2.Replace("{{{DEVICE}}}",d.User2.ToString());
WC2 = WC2.Replace("{{{DEVICEID}}}",d.GetHashCode().ToString());
WC = SourceCodeRepository.InsertTextBeforeTag(WC,"//{{{BEGIN_CPDiscoverSink}}}",WC2);
// SetControlPoint
WC2 = SourceCodeRepository.GetTextBetweenTags(WC,"//{{{BEGIN_SetControlPoint}}}","//{{{END_SetControlPoint}}}");
WC2 = WC2.Replace("{{{DEVICE}}}",d.User2.ToString());
WC2 = WC2.Replace("{{{DEVICEID}}}",d.GetHashCode().ToString());
WC = SourceCodeRepository.InsertTextBeforeTag(WC,"//{{{BEGIN_SetControlPoint}}}",WC2);
// Device/Service Specific Stuff
WC = AddCPlusPlusAbstraction_CPP_ControlPoint(WC,d);
cpok = true;
ok = true;
}
}
if (!cpok)
{
WC = SourceCodeRepository.RemoveAndClearTag("//{{{CP_BEGIN}}}","//{{{CP_END}}}",WC);
}
else
{
WC = SourceCodeRepository.RemoveTag("//{{{CP_BEGIN}}}","//{{{CP_END}}}",WC);
}
if (ok)
{
WC = SourceCodeRepository.RemoveAndClearTag("//{{{Manager_Destructor_Begin}}}","//{{{Manager_Destructor_End}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{Manager_Constructor_Begin}}}","//{{{Manager_Constructor_End}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{Manager_GetDevice_Begin}}}","//{{{Manager_GetDevice_End}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{Device_Begin}}}","//{{{Device_End}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{Service_Begin}}}","//{{{Service_End}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{SERVICE_VIRTUAL_METHOD_BASE_IMPLEMENTATION_BEGIN}}}","//{{{SERVICE_VIRTUAL_METHOD_BASE_IMPLEMENTATION_END}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{Service_Instantiation_Begin}}}","//{{{Service_Instantiation_End}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{Device_Instantiation_Begin}}}","//{{{Device_Instantiation_End}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{SinkList_Begin}}}","//{{{SinkList_End}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{Destructor_Begin}}}","//{{{Destructor_End}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{Dispatch_Begin}}}","//{{{Dispatch_End}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{MicroStackInclude_Begin}}}","//{{{MicroStackInclude_End}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{IPADDRESS_HANDLER_BEGIN}}}","//{{{IPADDRESS_HANDLER_END}}}",WC);
// Control Point Specific
WC = SourceCodeRepository.RemoveAndClearTag("//{{{CPMicroStackInclude_Begin}}}","//{{{CPMicroStackInclude_End}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{Manager_CPConstructor_Begin}}}","//{{{Manager_CPConstructor_End}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{BEGIN_CPDiscoverSink}}}","//{{{END_CPDiscoverSink}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{BEGIN_ServiceCheck}}}","//{{{END_ServiceCheck}}}",WC);
//.........这里部分代码省略.........
示例4: Build_UPnPMiniWebServer
public bool Build_UPnPMiniWebServer(DirectoryInfo outputDirectory)
{
StreamWriter writer;
if (this.Platform == PLATFORMS.POSIX)
{
if (this.SubTarget == SUBTARGETS.NUCLEUS)
{
pc_SockType = "int";
// pc_TimeType = "Timeval";
pc_SockClose = "NU_Close_Socket";
// pc_stricmp = "strncasecmp";
}
else
{
pc_SockType = "int";
// pc_TimeType = "struct timeval";
pc_SockClose = "close";
// pc_stricmp = "strncasecmp";
}
}
if (this.Platform == PLATFORMS.WINDOWS)
{
pc_SockType = "SOCKET";
// pc_TimeType = "unsigned int";
pc_SockClose = "closesocket";
// pc_stricmp = "_strnicmp";
}
if (this.Language == LANGUAGES.C)
{
pc_methodPrefix = CallPrefix;
pc_methodLibPrefix = CallLibPrefix;
pc_methodPrefixDef = CallingConvention + CallPrefix;
}
CodeProcessor cs = new CodeProcessor(new StringBuilder(),this.Language == LANGUAGES.CPP);
/* Build UPnPMiniWebServer.h */
AddLicense(cs,pc_methodPrefix+"MiniWebServer.h");
cs.Append(cl);
cs.Append("#ifndef __"+pc_methodPrefix+"MiniWebServer__"+cl);
cs.Append("#define __"+pc_methodPrefix+"MiniWebServer__"+cl);
cs.Append(cl);
cs.Comment("Forward Declaration");
cs.Append("struct packetheader;"+cl+cl);
cs.Append("void* "+pc_methodPrefix+"CreateMiniWebServer(void *chain,int MaxSockets,void (*OnReceive) (void *ReaderObject, struct packetheader *header, char* buffer, int *BeginPointer, int BufferSize, int done, void* user),void *user);"+cl);
cs.Append("void "+pc_methodPrefix+"DestroyMiniWebServer(void *WebServerModule);"+cl);
cs.Append("void "+pc_methodPrefix+"StartMiniWebServerModule(void *WebServerModule);"+cl);
cs.Append("void "+pc_methodPrefix+"StopMiniWebServerModule(void *WebServerModule);"+cl);
cs.Append(cl);
cs.Append("void "+pc_methodPrefix+"MiniWebServer_SetReserved(void *MWS, void *object);"+cl);
cs.Append("void *"+pc_methodPrefix+"MiniWebServer_GetReserved(void *MWS);"+cl);
cs.Append("void *"+pc_methodPrefix+"MiniWebServer_GetMiniWebServerFromReader(void *Reader);"+cl);
cs.Append(cl);
cs.Append("int "+pc_methodPrefix+"GetMiniWebServerPortNumber(void *WebServerModule);"+cl);
cs.Append("void "+pc_methodPrefix+"MiniWebServerSend(void *ReaderObject, struct packetheader *packet);"+cl);
cs.Append("void "+pc_methodPrefix+"MiniWebServerCloseSession(void *ReaderObject);"+cl);
cs.Append(cl);
cs.Append("char* "+pc_methodPrefix+"GetReceivingInterface(void* ReaderObject);"+cl);
cs.Append("void "+pc_methodPrefix+"CloseRequest(void* ReaderObject); "+cl);
cs.Append(cl);
cs.Append("#endif"+cl);
writer = File.CreateText(outputDirectory.FullName + "\\"+pc_methodPrefix+"MiniWebServer.h");
writer.Write(cs.ToString());
writer.Close();
/* Build UPnPMiniWebServer.c */
cs = new CodeProcessor(new StringBuilder(),this.Language == LANGUAGES.CPP);
if (this.Language == LANGUAGES.CPP)
{
AddLicense(cs,pc_methodPrefix+"MiniWebServer.cpp");
}
else
{
AddLicense(cs,pc_methodPrefix+"MiniWebServer.c");
}
cs.Append(cl);
if (this.Platform==PLATFORMS.WINDOWS)
{
cs.Append("#ifndef MICROSTACK_NO_STDAFX"+cl);
cs.Append("#include \"stdafx.h\""+cl);
cs.Append("#endif"+cl);
cs.Append("#define _CRTDBG_MAP_ALLOC"+cl);
cs.Append("#include <math.h>"+cl);
cs.Append("#include <winerror.h>"+cl);
cs.Append("#include <stdlib.h>"+cl);
cs.Append("#include <stdio.h>"+cl);
cs.Append("#include <stddef.h>"+cl);
cs.Append("#include <string.h>"+cl);
if (this.WinSock == 1)
{
//.........这里部分代码省略.........
示例5: GetPopulatedDeviceObjectsString
public static string GetPopulatedDeviceObjectsString(UPnPDevice d)
{
Hashtable VarTable = new Hashtable();
Hashtable ActionTable = new Hashtable();
CodeProcessor cs = new CodeProcessor(new StringBuilder(),false);
cs.NewLine = "\r\n";
DeviceObjectGenerator.GenerateStateVariableLookupTable(d,VarTable);
DeviceObjectGenerator.GenerateActionLookupTable(d,ActionTable);
PopulateStateVariableStructs(cs,d,VarTable);
PopulateActionStructs(cs,d,ActionTable);
PopulateServiceStructs(cs,d);
PopulateDeviceStructs(cs,d);
return(cs.ToString());
}
示例6: InjectBytes
public static void InjectBytes(out string byteString, byte[] inVal, string newLine, bool withTypeCast)
{
CodeProcessor cs = new CodeProcessor(new StringBuilder(),false);
cs.NewLine = newLine;
cs.Append("{"+cs.NewLine);
bool _first = true;
int _ctr=0;
foreach(byte b in inVal)
{
if (_first==false)
{
cs.Append(",");
}
else
{
_first = false;
}
string hx = b.ToString("X");
if (withTypeCast)
{
cs.Append("(char)");
}
cs.Append("0x");
if (hx.Length==1){cs.Append("0");}
cs.Append(hx);
++_ctr;
if (_ctr%(withTypeCast?10:20)==0)
{
cs.Append(cs.NewLine);
}
}
cs.Append(cs.NewLine+"}");
byteString = cs.ToString();
}
示例7: GetCPlusPlusAbstraction_H
public static string GetCPlusPlusAbstraction_H(UPnPDevice[] devices)
{
string WC = SourceCodeRepository.GetCPlusPlus_Template_H("UPnP");
string WC2;
CodeProcessor sb = new CodeProcessor(new StringBuilder(),false);
bool ok = false;
bool CPok = false;
foreach(UPnPDevice d in devices)
{
if (((ServiceGenerator.Configuration)d.User).ConfigType==ServiceGenerator.ConfigurationType.DEVICE)
{
WC2 = GetCPlusPlusAbstraction_H_FriendDevice(WC,d);
WC = SourceCodeRepository.InsertTextBeforeTag(WC,"//{{{Manager_Friends_BEGIN}}}",WC2);
WC2 = SourceCodeRepository.GetTextBetweenTags(WC,"//{{{Manager_GetDevice_BEGIN}}}","//{{{Manager_GetDevice_END}}}");
WC2 = WC2.Replace("{{{DEVICE}}}","UPnP_Device_"+d.User2.ToString());
WC = SourceCodeRepository.InsertTextBeforeTag(WC,"//{{{Manager_GetDevice_BEGIN}}}",WC2);
WC2 = SourceCodeRepository.GetTextBetweenTags(WC,"//{{{Manager_Device_BEGIN}}}","//{{{Manager_Device_END}}}");
WC2 = WC2.Replace("{{{DEVICE}}}","UPnP_Device_"+d.User2.ToString());
WC = SourceCodeRepository.InsertTextBeforeTag(WC,"//{{{Manager_Device_BEGIN}}}",WC2);
WC = GetCPlusPlusAbstraction_H_Device(WC,d);
ok = true;
}
else
{
WC2 = SourceCodeRepository.GetTextBetweenTags(WC,"//{{{Manager_SetControlPoint_BEGIN}}}","//{{{Manager_SetControlPoint_END}}}");
WC2 = WC2.Replace("{{{DEVICE}}}",d.User2.ToString());
WC = SourceCodeRepository.InsertTextBeforeTag(WC,"//{{{Manager_SetControlPoint_BEGIN}}}",WC2);
WC2 = SourceCodeRepository.GetTextBetweenTags(WC,"//{{{Manager_ProtectedCP_Stuff_BEGIN}}}","//{{{Manager_ProtectedCP_Stuff_END}}}");
WC2 = WC2.Replace("{{{DEVICE}}}",d.User2.ToString());
WC2 = WC2.Replace("{{{DEVICE_ID}}}",d.GetHashCode().ToString());
WC = SourceCodeRepository.InsertTextBeforeTag(WC,"//{{{Manager_ProtectedCP_Stuff_BEGIN}}}",WC2);
WC2 = GetCPlusPlusAbstraction_H_Device_CP(WC,d);
WC = SourceCodeRepository.InsertTextBeforeTag(WC,"//{{{BEGIN_CP_SERVICE}}}",WC2);
CPok = true;
ok = true;
}
}
WC = SourceCodeRepository.RemoveAndClearTag("//{{{Manager_SetControlPoint_BEGIN}}}","//{{{Manager_SetControlPoint_END}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{Manager_ProtectedCP_Stuff_BEGIN}}}","//{{{Manager_ProtectedCP_Stuff_END}}}",WC);
if (!CPok)
{
WC = SourceCodeRepository.RemoveAndClearTag("//{{{ControlPoint_Begin}}}","//{{{ControlPoint_End}}}",WC);
}
else
{
WC = SourceCodeRepository.RemoveTag("//{{{ControlPoint_Begin}}}","//{{{ControlPoint_End}}}",WC);
}
if (ok)
{
WC = SourceCodeRepository.RemoveAndClearTag("//{{{Device_Begin}}}","//{{{Device_End}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{Service_Begin}}}","//{{{Service_End}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{Manager_Friends_BEGIN}}}","//{{{Manager_Friends_END}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{Manager_GetDevice_BEGIN}}}","{{{Manager_GetDevice_END}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{Manager_Device_BEGIN}}}","//{{{Manager_Device_END}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{BEGIN_CP_SERVICE}}}","//{{{END_CP_SERVICE}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{BEGIN_EVENT_TYPEDEF}}}","//{{{END_EVENT_TYPEDEF}}}",WC);
WC = SourceCodeRepository.RemoveAndClearTag("//{{{BEGIN_EVENT}}}","//{{{END_EVENT}}}",WC);
sb.Append(WC);
}
return(sb.ToString());
}
示例8: GetDeviceObjectsString
public static string GetDeviceObjectsString(UPnPDevice d)
{
CodeProcessor cs = new CodeProcessor(new StringBuilder(),false);
cs.NewLine = "\r\n";
//
// Calculate the size to initialize "UPnP_StateVariable_AllowedValues_MAX"
//
int max = CalculateMaxAllowedValues(d,0);
if (max!=0)
{
++max;
cs.Append("#define UPnP_StateVariable_AllowedValues_MAX "+max+cs.NewLine);
}
BuildStateVariableStructs(cs,d);
BuildActionStructs(cs,d);
BuildServiceStructs(cs,d);
BuildDeviceStructs(cs,d);
return(cs.ToString());
}
示例9: GenerateEx
protected bool GenerateEx(UPnPDevice device, DirectoryInfo outputDirectory, Hashtable serviceNames, ref string SampleApp)
{
bool BuildSampleApp = SampleApp == null ? false : true;
ServiceGenerator.Configuration DeviceConf = (ServiceGenerator.Configuration)device.User;
#region Initialize
string WS;
StreamWriter W;
Hashtable ChoTable = new Hashtable();
Hashtable SeqTable = new Hashtable();
int SequenceCounter = 0;
int ChoiceCounter = 0;
string first = "";
RootDevice = device;
SortedList SL = new SortedList();
IDictionaryEnumerator en = serviceNames.GetEnumerator();
while (en.MoveNext())
{
SL[en.Value] = en.Key;
}
en = SL.GetEnumerator();
if (this.SubTarget == SUBTARGETS.NONE)
{
UseSystem = this.Platform.ToString();
}
else
{
UseSystem = this.SubTarget.ToString();
}
pc_methodPrefix = ((ServiceGenerator.Configuration)device.User).Prefix;
pc_methodLibPrefix = Configuration.prefixlib;
if (this.Language == LANGUAGES.C)
{
pc_methodPrefixDef = CallingConvention + pc_methodPrefix;
pc_classPrefix = "";
}
if (this.Language == LANGUAGES.CPP)
{
pc_methodPrefixDef = CallingConvention + ClassName + "::" + pc_methodPrefix;
pc_classPrefix = ClassName + "::";
}
AllServices.Clear();
AddAllServices(device);
FriendlyNameTable.Clear();
Fix(device, 0, serviceNames);
PrivateClassDeclarations = new CodeProcessor(new StringBuilder(), this.Language == LANGUAGES.CPP);
PublicClassDeclarations = new CodeProcessor(new StringBuilder(), this.Language == LANGUAGES.CPP);
CodeProcessor cs = new CodeProcessor(new StringBuilder(), this.Language == LANGUAGES.CPP);
cs.NewLine = this.CodeNewLine;
cs.ClassDefinitions = PrivateClassDeclarations;
cs.PublicClassDefinitions = PublicClassDeclarations;
PrivateClassDeclarations.CodeTab = Indent;
PublicClassDeclarations.CodeTab = Indent;
cs.CodeTab = Indent;
#endregion
#region New Style UPnPMicroStack.h
WS = SourceCodeRepository.GetMicroStack_H_Template(pc_methodPrefix);
#region UPnP/1.1 Complex Types
cs = new CodeProcessor(new StringBuilder(), this.Language == LANGUAGES.CPP);
BuildComplexTypeDefinitionsAndHeaders(SL, cs, SeqTable, ChoTable, ref SequenceCounter, ref ChoiceCounter, this.pc_methodPrefix, this.pc_methodLibPrefix);
WS = WS.Replace("//{{{ComplexTypeCode}}}", cs.ToString());
#endregion
#region Function Callbacks
cs = new CodeProcessor(new StringBuilder(), this.Language == LANGUAGES.CPP);
en.Reset();
while (en.MoveNext())
{
UPnPService service = (UPnPService)en.Value;
foreach (UPnPAction action in service.Actions)
{
cs.Append(" typedef void(*UPnP_ActionHandler_" + serviceNames[service] + "_" + action.Name + ") (void* upnptoken");
foreach (UPnPArgument args in action.Arguments)
{
if (args.Direction == "in")
{
if (args.RelatedStateVar.ComplexType == null)
{
cs.Append("," + ToCType(args.RelatedStateVar.GetNetType().FullName) + " " + args.Name);
if (args.RelatedStateVar.GetNetType().FullName == "System.Byte[]")
{
cs.Append(",int _" + args.Name + "Length");
}
}
else
{
//.........这里部分代码省略.........
示例10: GenerateEx
protected bool GenerateEx(UPnPDevice device,DirectoryInfo outputDirectory, Hashtable serviceNames)
{
AllServices.Clear();
AddAllServices(device);
StreamWriter writer;
ServiceNames = serviceNames;
// *** Generate Main Code
Log("Writing main stack module...");
foreach (UPnPService service in AllServices)
{
string servicename = (string)serviceNames[service];
string servicexml = new UTF8Encoding().GetString(service.GetSCPDXml());
Log("Generating service class for " + servicename);
OpenSource.UPnP.ServiceGenerator.Generate("Dv"+servicename,nspace,outputDirectory.FullName + "\\Dv" + servicename + ".cs",service.ServiceID,service.ServiceURN,servicexml);
}
CodeProcessor cs = new CodeProcessor(new StringBuilder(),true);
StringBuilder cs2;
cs.Comment("UPnP .NET Framework Device Stack, Device Module");
cs.Comment(VersionString);
cs.Append(cl);
cs.Append("using System;" + cl);
cs.Append("using OpenSource.UPnP;" + cl);
cs.Append("using "+nspace+";" + cl);
cs.Append(cl);
cs.Append("namespace "+nspace+cl);
cs.Append("{"+cl);
cs.Append(" /// <summary>"+cl);
cs.Append(" /// Summary description for SampleDevice."+cl);
cs.Append(" /// </summary>"+cl);
cs.Append(" class SampleDevice"+cl);
cs.Append(" {"+cl);
cs.Append(" private UPnPDevice device;" + cl);
cs.Append(cl);
cs.Append(" public SampleDevice()"+cl);
cs.Append(" {"+cl);
gendevnumber = 0;
GenerateAddDevice(cs,device);
cs.Comment("Setting the initial value of evented variables");
foreach (UPnPService service in AllServices)
{
string servicename = (string)ServiceNames[service];
foreach (UPnPStateVariable variable in service.GetStateVariables())
{
if (variable.SendEvent == true)
{
cs.Append(servicename + ".Evented_" + variable.Name + " = " + this.ToSampleValue(variable.GetNetType().ToString()) + ";" + cl);
}
}
}
cs.Append(" }"+cl);
cs.Append(cl);
cs.Append(" public void Start()"+cl);
cs.Append(" {"+cl);
cs.Append(" device.StartDevice();"+cl);
cs.Append(" }"+cl);
cs.Append(cl);
cs.Append(" public void Stop()"+cl);
cs.Append(" {"+cl);
cs.Append(" device.StopDevice();"+cl);
cs.Append(" }"+cl);
cs.Append(cl);
foreach (UPnPService service in AllServices)
{
string servicename = (string)serviceNames[service];
// Build MethodDelegates
foreach(UPnPAction action in service.Actions)
{
cs.Append("public ");
if (action.HasReturnValue==false)
{
cs.Append("void ");
}
else
{
cs.Append(action.GetRetArg().RelatedStateVar.GetNetType().FullName + " ");
}
cs.Append(servicename + "_" + action.Name + "(");
UPnPArgument[] Args = action.ArgumentList;
for(int i=0;i<Args.Length;++i)
{
UPnPArgument arg = Args[i];
if (arg.IsReturnValue==false)
{
if (arg.Direction=="out")
{
cs.Append("out ");
}
if (arg.RelatedStateVar.AllowedStringValues==null)
{
cs.Append(arg.RelatedStateVar.GetNetType().FullName + " ");
//.........这里部分代码省略.........
示例11: CP_GenerateHeaderFile
//.........这里部分代码省略.........
cs.Append(cl);
IDictionaryEnumerator en2 = SL.GetEnumerator();
while(en2.MoveNext())
{
UPnPService s = (UPnPService)en2.Value;
string name = (string)en2.Key;
foreach(UPnPStateVariable variable in s.GetStateVariables())
{
if (variable.SendEvent == true)
{
cs.Append("extern void (*"+pc_methodPrefix+"EventCallback_"+name+"_"+variable.Name+")(struct UPnPService* Service,");
cs.Append(ToCType(variable.GetNetType().FullName)+" "+variable.Name);
if (variable.GetNetType()==typeof(byte[]))
{
cs.Append(", int " + variable.Name+"Length");
}
cs.Append(");"+cl);
}
}
}
cs.Append(cl);
en.Reset();
while(en.MoveNext())
{
UPnPService s = (UPnPService)en.Value;
string name = (string)en.Key;
foreach(UPnPAction A in s.Actions)
{
cs.Append(" void "+pc_methodPrefix+"Invoke_"+name+"_"+A.Name+"(struct UPnPService *service, void (*CallbackPtr)(struct UPnPService*,int ErrorCode,void *user");
if (A.HasReturnValue)
{
if (A.GetRetArg().RelatedStateVar.ComplexType==null)
{
// NonComplex
cs.Append(","+ToCType(A.GetRetArg().RelatedStateVar.GetNetType().FullName)+" "+A.GetRetArg().Name);
if (A.GetRetArg().RelatedStateVar.GetNetType()==typeof(byte[]))
{
cs.Append(", int " + A.GetRetArg().Name+"Length");
}
}
else
{
// Complex
cs.Append(", struct " + A.GetRetArg().RelatedStateVar.ComplexType.Name_LOCAL+" *"+A.GetRetArg().Name);
}
}
foreach(UPnPArgument Arg in A.Arguments)
{
if (!Arg.IsReturnValue && Arg.Direction=="out")
{
if (Arg.RelatedStateVar.ComplexType==null)
{
//NonComplex
cs.Append(","+ToCType(Arg.RelatedStateVar.GetNetType().FullName)+" "+Arg.Name);
if (Arg.RelatedStateVar.GetNetType()==typeof(byte[]))
{
cs.Append(", int " + Arg.Name+"Length");
}
}
else
{
//Complex
cs.Append(", struct "+Arg.RelatedStateVar.ComplexType.Name_LOCAL+" *"+Arg.Name);
}
}
}
cs.Append(")");
cs.Append(",void* _user");
foreach(UPnPArgument Arg in A.Arguments)
{
if (Arg.Direction=="in")
{
if (Arg.RelatedStateVar.ComplexType==null)
{
//NonComplex
cs.Append(", "+ToCType(Arg.RelatedStateVar.GetNetType().FullName)+" "+Arg.Name);
if (Arg.RelatedStateVar.GetNetType()==typeof(byte[]))
{
cs.Append(", int " + Arg.Name+"Length");
}
}
else
{
//Complex
cs.Append(", struct "+Arg.RelatedStateVar.ComplexType.Name_LOCAL+" *"+Arg.Name);
}
}
}
cs.Append(");"+cl);
}
}
cs.Append(cl);
cs.Append("#endif"+cl);
StreamWriter writer5 = File.CreateText(outputDirectory.FullName + "\\"+pc_methodPrefix+"ControlPoint.h");
writer5.Write(cs.ToString());
writer5.Close();
}
示例12: GenerateEx
protected bool GenerateEx(UPnPDevice device,DirectoryInfo outputDirectory, Hashtable serviceNames, ref string SampleApp)
{
#region Initialization
//StreamWriter W;
DText PP = new DText();
PP.ATTRMARK = ":";
bool OkToDo=false;
string WS,tmp;
StreamWriter writer;
SequenceTable.Clear();
ChoiceTable.Clear();
SequenceCounter=0;
ChoiceCounter=0;
if (this.SubTarget==SUBTARGETS.NONE)
{
UseSystem = this.Platform.ToString();
}
else
{
UseSystem = this.SubTarget.ToString();
}
UseInfoString = UseSystem + ", UPnP/1.0, MicroStack/" + UseVersion;
if (this.Language == LANGUAGES.C)
{
pc_methodPrefix = ((ServiceGenerator.Configuration)device.User).Prefix;
pc_methodLibPrefix = Configuration.prefixlib;
pc_methodPrefixDef = CallingConvention + pc_methodPrefix;
}
AllServices.Clear();
AddAllServices(device);
Fix(device,0, serviceNames);
SortedList SL = new SortedList();
IDictionaryEnumerator en = serviceNames.GetEnumerator();
DText Parser = new DText();
Parser.ATTRMARK = ":";
Parser[0] = device.DeviceURN;
string DeviceName = Parser[4];
// *** Generate Main Code
Log("Writing main stack module...");
while(en.MoveNext())
{
SL[en.Value] = en.Key;
}
en = SL.GetEnumerator();
PrivateClassDeclarations = new CodeProcessor(new StringBuilder(),this.Language == LANGUAGES.CPP);
PublicClassDeclarations = new CodeProcessor(new StringBuilder(),this.Language == LANGUAGES.CPP);
CodeProcessor cs = new CodeProcessor(new StringBuilder(), this.Language == LANGUAGES.CPP);
cs.NewLine = this.CodeNewLine;
cs.ClassDefinitions = PrivateClassDeclarations;
cs.PublicClassDefinitions = PublicClassDeclarations;
PrivateClassDeclarations.CodeTab = Indent;
PublicClassDeclarations.CodeTab = Indent;
cs.CodeTab = Indent;
if (this.Language == LANGUAGES.CPP)
{
AddLicense(cs,pc_methodPrefix + "ControlPoint.cpp");
}
else
{
AddLicense(cs,pc_methodPrefix + "ControlPoint.c");
}
cs.Append(cl);
#endregion
#region UPnPControlPoint.h
WS = SourceCodeRepository.GetControlPoint_H_Template(this.pc_methodPrefix);
#region GetService
cs = new CodeProcessor(new StringBuilder(),this.Language == LANGUAGES.CPP);
en.Reset();
while(en.MoveNext())
{
string name = (string)en.Key;
cs.Append(" struct UPnPService *"+pc_methodPrefixDef+"GetService_"+name+"(struct UPnPDevice *device);"+cl);
}
WS = WS.Replace("//{{{UPnPGetService}}}",cs.ToString());
#endregion
#region Event Callbacks
cs = new CodeProcessor(new StringBuilder(),this.Language == LANGUAGES.CPP);
en.Reset();
while(en.MoveNext())
{
UPnPService s = (UPnPService)en.Value;
string name = (string)en.Key;
foreach(UPnPStateVariable variable in s.GetStateVariables())
{
if (variable.SendEvent == true)
{
cs.Append("extern void (*"+pc_methodPrefix+"EventCallback_"+name+"_"+variable.Name+")(struct UPnPService* Service,");
cs.Append(ToCType(variable.GetNetType().FullName)+" "+variable.Name);
//.........这里部分代码省略.........
示例13: GenerateEx
//.........这里部分代码省略.........
cs.Append(" " + action.Name + "(");
bool firstArg = true;
foreach (UPnPArgument arg in action.Arguments)
{
if (!arg.IsReturnValue)
{
if (!firstArg)
{
cs.Append(", ");
}
firstArg = false;
if (arg.Direction == "in")
{
cs.Append(GetJavaType(arg.RelatedStateVar));
}
else
{
cs.Append("RefParameter<");
cs.Append(GetJavaType(arg.RelatedStateVar, true));
cs.Append(">");
}
cs.Append(" ");
cs.Append(arg.Name);
}
}
cs.Append(");" + cl);
}
cs.Append("}" + cl);
//writer = File.CreateText(srcDir.FullName + "\\" + servicename + "_InvokeHandler.java");
//writer.Write(cs.ToString());
//writer.Close();
serviceInvocationHandlers = cs.ToString();
}
#endregion
#region Build Named Inner Classes for Invocation Processing
StringBuilder nic = new StringBuilder();
foreach (UPnPService service in AllServices)
{
string servicename = (string)ServiceNames[service];
foreach (UPnPAction action in service.Actions)
{
nic.Append(" private class " + servicename + "_" + action.Name + "_Dispatcher implements GenericRemoteInvokeHandler" + cl);
nic.Append(" {" + cl);
nic.Append(" public " + servicename + "_" + action.Name + "_Dispatcher()"+cl);
nic.Append(" {" + cl);
nic.Append(" }" + cl);
nic.Append(cl);
nic.Append(" @Override" + cl);
nic.Append(" public void OnGenericRemoteInvoke(UPnPAction sender, Attributes inParams, List<BasicNameValuePair> outParams)" + cl);
nic.Append(" throws UPnPInvokeException" + cl);
nic.Append(" {" + cl);
nic.Append(" if(" + servicename + "_InvokeCallback != null)" + cl);
nic.Append(" {" + cl);
//Input Argument Conversion
foreach (UPnPArgument arg in action.Arguments)
{
if (arg.Direction == "in")
{
nic.Append(" " + GetJavaType(arg.RelatedStateVar) + " " + arg.Name + " = ");
nic.Append(DeSerializeVariable(arg.RelatedStateVar, "inParams.getValue(\"" + arg.Name + "\")"));
nic.Append(";" + cl);
}