当前位置: 首页>>代码示例>>C#>>正文


C# CodeProcessor.Define方法代码示例

本文整理汇总了C#中CodeProcessor.Define方法的典型用法代码示例。如果您正苦于以下问题:C# CodeProcessor.Define方法的具体用法?C# CodeProcessor.Define怎么用?C# CodeProcessor.Define使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CodeProcessor的用法示例。


在下文中一共展示了CodeProcessor.Define方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Build_TypeCheckUnsignedIntegral

 private void Build_TypeCheckUnsignedIntegral(CodeProcessor cs)
 {
     cs.Define("int " + pc_methodPrefixDef + "TypeCheckUnsignedIntegral(char* inVar, int inVarLength, unsigned long MinVal, unsigned long MaxVal, void *outVar, char *varName,struct HTTPReaderObject *ReaderObject)");
     cs.Append("{" + cl);
     cs.Append("	unsigned long TempULong;" + cl);
     cs.Append("	int OK = 0;" + cl);
     cs.Append("	char *msg;" + cl);
     cs.Append("	if (" + pc_methodLibPrefix + "GetULong(inVar, inVarLength, &TempULong)!=0)" + cl);
     cs.Append("	{" + cl);
     cs.Append("		OK=-1;" + cl);
     cs.Append("	}" + cl);
     cs.Append("	if (!(TempULong >= MinVal && TempULong <= MaxVal))" + cl);
     cs.Append("	{" + cl);
     cs.Append("		OK=-2;" + cl);
     cs.Append("	}" + cl);
     cs.Append("	if (OK==-1)" + cl);
     cs.Append("	{" + cl);
     if (Configuration.ExplicitErrorEncoding == true)
     {
         cs.Append("		if ((msg = (char*)malloc(25 + (int)strlen(varName))) == NULL) ILIBCRITICALEXIT(254);" + cl);
         cs.Append("		snprintf(msg, 25 + (int)strlen(varName), \"Argument[%s] illegal value\", varName);" + cl);
         cs.Append("		" + pc_methodPrefix + "Response_Error(ReaderObject, 402, msg);" + cl);
         cs.Append("		free(msg);" + cl);
     }
     else
     {
         cs.Append("		" + pc_methodPrefix + "Response_Error(ReaderObject,402,\"Illegal value\");" + cl);
     }
     cs.Append("		return(-1);" + cl);
     cs.Append("	}" + cl);
     cs.Append("	if (OK==-2)" + cl);
     cs.Append("	{" + cl);
     if (Configuration.ExplicitErrorEncoding == true)
     {
         cs.Append("		if ((msg = (char*)malloc(25 + (int)strlen(varName))) == NULL) ILIBCRITICALEXIT(254);" + cl);
         cs.Append("		snprintf(msg, 25 + (int)strlen(varName), \"Argument[%s] out of range\", varName);" + cl);
         cs.Append("		" + pc_methodPrefix + "Response_Error(ReaderObject, 402, msg);" + cl);
         cs.Append("		free(msg);" + cl);
     }
     else
     {
         cs.Append("		" + pc_methodPrefix + "Response_Error(ReaderObject, 402, \"Illegal value\");" + cl);
     }
     cs.Append("		return(-1);" + cl);
     cs.Append("	}" + cl);
     cs.Append("	*((unsigned long*)outVar) = TempULong;" + cl);
     cs.Append("	return(0);" + cl);
     cs.Append("}" + cl);
 }
开发者ID:evolution124,项目名称:Developer-Tools-for-UPnP-Technologies,代码行数:49,代码来源:EmbeddedCGenerator.cs

示例2: Build_TypeCheckString

        private void Build_TypeCheckString(CodeProcessor cs, Hashtable serviceNames)
        {
            SortedList SL = new SortedList();
            IDictionaryEnumerator en = serviceNames.GetEnumerator();

            while (en.MoveNext())
            {
                SL[en.Value] = en.Key;
            }
            en = SL.GetEnumerator();

            cs.Define("int " + pc_methodPrefixDef + "TypeCheckString(char* inVar, int inVarLength, char* ServiceName, char* StateVariable, char** outVar, int* outVarLength, char* varName, struct HTTPReaderObject *ReaderObject)");
            cs.Append("{" + cl);
            cs.Append("	int OK = 0;" + cl);
            cs.Append("	char* msg;" + cl);
            while (en.MoveNext())
            {
                UPnPService S = (UPnPService)en.Value;
                string key = (string)en.Key;

                bool Needed = false;
                foreach (UPnPStateVariable V in S.GetStateVariables())
                {
                    if (V.AllowedStringValues != null)
                    {
                        Needed = true;
                        break;
                    }
                }

                if (Needed)
                {
                    cs.Append("	if (strncmp(ServiceName,\"" + key + "\"," + key.Length.ToString() + ") == 0)" + cl);
                    cs.Append("	{" + cl);
                    foreach (UPnPStateVariable V in S.GetStateVariables())
                    {
                        if (V.AllowedStringValues != null)
                        {
                            cs.Append("		if (strncmp(StateVariable,\"" + V.Name + "\"," + V.Name.Length.ToString() + ") == 0)" + cl);
                            cs.Append("		{" + cl);
                            cs.Append("			OK = -1;" + cl);
                            bool first = true;
                            foreach (string AllowedString in V.AllowedStringValues)
                            {
                                if (first == false) cs.Append("else ");
                                first = false;
                                cs.Append("			if (inVarLengt h== " + AllowedString.Length.ToString() + ")" + cl);
                                cs.Append("			{" + cl);
                                cs.Append("				if (memcmp(inVar,\"" + AllowedString + "\"," + AllowedString.Length.ToString() + ") == 0) {OK = 0;}" + cl);
                                cs.Append("			}" + cl);
                            }
                            cs.Append("			if (OK != 0)" + cl);
                            cs.Append("			{" + cl);
                            if (Configuration.ExplicitErrorEncoding == true)
                            {
                                cs.Append("				if ((msg = (char*)malloc(65)) == NULL) ILIBCRITICALEXIT(254);" + cl);
                                cs.Append("				snprintf(msg, 65, \"Argument[%s] contains a value that is not in AllowedValueList\", varName);" + cl);
                                cs.Append("				" + pc_methodPrefix + "Response_Error(ReaderObject, 402, msg);" + cl);
                                cs.Append("				free(msg);" + cl);
                            }
                            else
                            {
                                cs.Append("				" + pc_methodPrefix + "Response_Error(ReaderObject, 402, \"Illegal value\");" + cl);
                            }
                            cs.Append("				return -1;" + cl);
                            cs.Append("			}" + cl);
                            cs.Append("			*outVar = inVar;" + cl);
                            cs.Append("			*outVarLength = inVarLength;" + cl);
                            cs.Append("			return(0);" + cl);
                            cs.Append("		}" + cl);
                        }
                    }
                    cs.Append("	}" + cl);
                }
            }
            cs.Append("}" + cl);
        }
开发者ID:evolution124,项目名称:Developer-Tools-for-UPnP-Technologies,代码行数:77,代码来源:EmbeddedCGenerator.cs

示例3: Build_DispatchMethods

        private void Build_DispatchMethods(CodeProcessor cs, Hashtable serviceNames)
        {
            SortedList SL = new SortedList();

            IDictionaryEnumerator en = serviceNames.GetEnumerator();
            UPnPService service;
            string name;

            while (en.MoveNext())
            {
                SL[en.Value] = en.Key;
            }

            en = SL.GetEnumerator();

            while (en.MoveNext())
            {
                int numArgs = 0;
                service = (UPnPService)en.Value;
                name = (string)en.Key;
                foreach (UPnPAction action in service.Actions)
                {
                    numArgs = 0;
                    foreach (UPnPArgument args in action.ArgumentList)
                    {
                        if (args.Direction == "in") { ++numArgs; }
                    }

                    // Define a macro version
                    if (numArgs == 0)
                    {
                        cs.Define("#define " + pc_methodPrefixDef + "Dispatch_" + name + "_" + action.Name + "(buffer,offset,bufferLength, session)\\");
                        cs.Append("{\\" + cl);
                        if (name != "DeviceSecurity")
                        {
                            if (Configuration.EXTERN_Callbacks == false)
                            {
                                cs.Append("	if (" + pc_methodPrefix + "FP_" + name + "_" + action.Name + " == NULL)\\" + cl);
                                cs.Append("		" + pc_methodPrefix + "Response_Error(session,501,\"No Function Handler\");\\" + cl);
                                cs.Append("	else\\" + cl);
                                cs.Append("		" + pc_methodPrefix + "FP_" + name + "_" + action.Name + "((void*)session);\\" + cl);
                            }
                            else
                            {
                                cs.Append("	" + pc_methodPrefix + name + "_" + action.Name + "((void*)session);\\" + cl);
                            }
                        }
                        else
                        {
                            cs.Append("	" + pc_methodLibPrefix + name + "_" + action.Name + "((void*)session);\\" + cl);
                        }
                        cs.Append("}" + cl);
                        cs.Append(cl);
                    }

                    if (numArgs > 0)
                    {
                        cs.Define("void " + pc_methodPrefixDef + "Dispatch_" + name + "_" + action.Name + "(char *buffer, int offset, int bufferLength, struct " + this.pc_methodLibPrefix + "WebServer_Session *ReaderObject)");
                        cs.Append("{" + cl);

                        bool varlong = false;
                        bool varlongtemp = false;
                        bool varulong = false;
                        bool varulongtemp = false;
                        bool varuuri = false;
                        bool varok = false;
                        foreach (UPnPArgument args in action.ArgumentList)
                        {
                            if (args.Direction == "in")
                            {
                                varok = true;
                                switch (args.RelatedStateVar.GetNetType().ToString())
                                {
                                    case "System.Uri":
                                        varuuri = true;
                                        break;
                                    case "System.Byte":
                                    case "System.UInt16":
                                    case "System.UInt32":
                                        varulong = true;
                                        if (args.RelatedStateVar.Maximum != null || args.RelatedStateVar.Minimum != null)
                                        {
                                            varulongtemp = true;
                                        }
                                        break;
                                    case "System.SByte":
                                    case "System.Int16":
                                    case "System.Int32":
                                        varlong = true;
                                        if (args.RelatedStateVar.Maximum != null || args.RelatedStateVar.Minimum != null)
                                        {
                                            varlongtemp = true;
                                        }
                                        break;
                                    case "System.Boolean":
                                    case "System.Char":
                                    case "System.Single":
                                    case "System.Double":
                                    case "System.Byte[]":
                                    case "System.String":
//.........这里部分代码省略.........
开发者ID:evolution124,项目名称:Developer-Tools-for-UPnP-Technologies,代码行数:101,代码来源:EmbeddedCGenerator.cs

示例4: Build_TypeCheckBoolean

 private void Build_TypeCheckBoolean(CodeProcessor cs)
 {
     cs.Define("int " + pc_methodPrefixDef + "TypeCheckBoolean(char *inVar, int inVarLength, int* BoolValue, char* varName, struct HTTPReaderObject *ReaderObject)");
     cs.Append("{" + cl);
     cs.Append("	int OK = 0;" + cl);
     cs.Append("	char* msg;" + cl);
     cs.Append("	if (inVarLength == 4)" + cl);
     cs.Append("	{" + cl);
     cs.Append("		if (strncasecmp(inVar, \"true\", 4) == 0)" + cl);
     cs.Append("		{" + cl);
     cs.Append("			OK = 1;" + cl);
     cs.Append("			*BoolValue = 1;" + cl);
     cs.Append("		}" + cl);
     cs.Append("	}" + cl);
     cs.Append("	if (inVarLength == 5)" + cl);
     cs.Append("	{" + cl);
     cs.Append("		if (strncasecmp(inVar, \"false\", 5) == 0)" + cl);
     cs.Append("		{" + cl);
     cs.Append("			OK = 1;" + cl);
     cs.Append("			*BoolValue = 0;" + cl);
     cs.Append("		}" + cl);
     cs.Append("	}" + cl);
     cs.Append("	if (inVarLength==1)" + cl);
     cs.Append("	{" + cl);
     cs.Append("		if (memcmp(inVar, \"0\", 1) == 0)" + cl);
     cs.Append("		{" + cl);
     cs.Append("			OK = 1;" + cl);
     cs.Append("			*BoolValue = 0;" + cl);
     cs.Append("		}" + cl);
     cs.Append("		if (memcmp(inVar, \"1\", 1) == 0)" + cl);
     cs.Append("		{" + cl);
     cs.Append("			OK = 1;" + cl);
     cs.Append("			*BoolValue = 1;" + cl);
     cs.Append("		}" + cl);
     cs.Append("	}" + cl);
     cs.Append("	if (OK == 0)" + cl);
     cs.Append("	{" + cl);
     if (Configuration.ExplicitErrorEncoding == true)
     {
         cs.Append("		if ((msg = (char*)malloc(25 + (int)strlen(varName))) == NULL) ILIBCRITICALEXIT(254);" + cl);
         cs.Append("		snprintf(msg, 25 + (int)strlen(varName), \"Argument[%s] illegal value\", varName);" + cl);
         cs.Append("		" + pc_methodPrefix + "Response_Error(ReaderObject, 402, msg);" + cl);
         cs.Append("		free(msg);" + cl);
     }
     else
     {
         cs.Append("		" + pc_methodPrefix + "Response_Error(ReaderObject, 402, \"Illegal value\");" + cl);
     }
     cs.Append("		return -1;" + cl);
     cs.Append("	}" + cl);
     cs.Append("	else" + cl);
     cs.Append("	{" + cl);
     cs.Append("		return 0;" + cl);
     cs.Append("	}" + cl);
     cs.Append("}" + cl);
 }
开发者ID:evolution124,项目名称:Developer-Tools-for-UPnP-Technologies,代码行数:56,代码来源:EmbeddedCGenerator.cs

示例5: BuildEventHelpers_InitialEvent

        private void BuildEventHelpers_InitialEvent(CodeProcessor cs, Hashtable serviceNames)
        {
            //string start_block = "<?xml version=\\\"1.0\\\" encoding=\\\"utf-8\\\"?><e:propertyset xmlns:e=\\\"urn:schemas-upnp-org:event-1-0\\\">";
            //string end_block = "</e:propertyset>";
            SortedList SL = new SortedList();
            IDictionaryEnumerator en = serviceNames.GetEnumerator();
            while (en.MoveNext())
            {
                SL[en.Value] = en.Key;
            }
            en = SL.GetEnumerator();
            while (en.MoveNext())
            {
                string name = (string)en.Key;
                UPnPService service = (UPnPService)en.Value;

                // Figure out if this service as any evented state variables
                bool eventedvars = false;
                foreach (UPnPStateVariable v in service.GetStateVariables())
                {
                    if (v.SendEvent == true) { eventedvars = true; break; }
                }
                if (eventedvars == false) continue;

                // Define the initial event body method for this service
                cs.Define("void " + pc_methodPrefixDef + "GetInitialEventBody_" + name + "(struct " + pc_methodPrefix + "DataObject *UPnPObject,char ** body, int *bodylength)");
                cs.Append("{" + cl);
                cs.Append("	int TempLength;" + cl);

                StringBuilder ev = new StringBuilder();
                //ev.Append(start_block);
                foreach (UPnPStateVariable V in service.GetStateVariables())
                {
                    if (V.SendEvent)
                    {
                        ev.Append(this.BuildEventHelpers_GetLine(V));
                    }
                }
                //ev.Append(end_block);
                string eventbody = ev.ToString();
                if (eventbody.Length != 0)
                {
                    eventbody = eventbody.Substring(13, eventbody.Length - (13 + 14));
                }

                cs.Append("	TempLength = (int)(" + eventbody.Length.ToString());
                foreach (UPnPStateVariable V in service.GetStateVariables())
                {
                    if (V.SendEvent)
                    {
                        cs.Append("+(int)strlen(UPnPObject->" + name + "_" + V.Name + ")");
                    }
                }
                cs.Append(");" + cl);
                cs.Append("	if ((*body = (char*)malloc(sizeof(char) * TempLength)) == NULL) ILIBCRITICALEXIT(254);" + cl);
                cs.Append("	*bodylength = snprintf(*body, sizeof(char) * TempLength, \"" + eventbody + "\"");
                foreach (UPnPStateVariable V in service.GetStateVariables())
                {
                    if (V.SendEvent)
                    {
                        cs.Append(",UPnPObject->" + name + "_" + V.Name);
                    }
                }
                cs.Append(");" + cl);
                cs.Append("}" + cl);
            }
        }
开发者ID:evolution124,项目名称:Developer-Tools-for-UPnP-Technologies,代码行数:67,代码来源:EmbeddedCGenerator.cs


注:本文中的CodeProcessor.Define方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。