Esempio n. 1
0
 //Ex from Typescript: [RestInPeacePost("ECaminhao GetByID(segment number id, mandatory number age, optional string bla, body string oi)")]
 static private bool WriteFunction(EFunctionFile eFile, EFunction eFunction)
 {
     try {
         StringBuilder result = new StringBuilder();
         StringBuilder argsStringBuilder = new StringBuilder();
         List <EArg>   segmentsList, mandatoryList, optionalList, formArgList, allArgsList;
         EArg          bodyArg;
         Logger.LogInfo("\tFunction " + eFunction.functionName);
         string functionName = Char.ToLowerInvariant(eFunction.functionName[0]) + eFunction.functionName.Substring(1);
         string operation = Helper.GetRESTOperation(eFile, eFunction);
         if (string.IsNullOrEmpty(operation))
         {
             return(false);
         }
         if (!GetFunctionArgs(eFunction, ref argsStringBuilder, out allArgsList, out segmentsList, out mandatoryList, out optionalList, out formArgList, out bodyArg))
         {
             Logger.LogError("unable to get funcion parameters to write file " + eFile.frontendFileName + ": " + eFunction.functionName);
             return(false);
         }
         result.Append("\tasync ");
         result.Append(functionName);
         result.Append("(");
         result.Append(argsStringBuilder.ToString());
         result.Append("):Promise<");
         result.Append(AngularWatcher.ConvertToAngularTypeName(eFunction.returnTypeName));
         result.Append(">{\n");
         string functionBody = GetFunctionBody(eFile, eFunction, operation, segmentsList, mandatoryList, optionalList, formArgList, bodyArg);
         result.Append(functionBody);
         eFunction.frontendFunctionContent = result.ToString();
         return(true);
     } catch (Exception e) {
         Logger.LogError(e);
     }
     return(false);
 }
Esempio n. 2
0
 static private bool GetFunctionArgs(EFunction eFunction, ref StringBuilder argsStringBuilder, out List <EArg> allArgsList, out List <EArg> segmentsList, out List <EArg> mandatoryList, out List <EArg> optionalList, out List <EArg> formArgList, out EArg bodyArg)
 {
     segmentsList  = null;
     mandatoryList = null;
     optionalList  = null;
     formArgList   = null;
     allArgsList   = new List <EArg>();
     bodyArg       = null;
     try {
         //orderby then to linq nao funciona  para mesmo campo
         bodyArg       = Helper.GetBodyArg(eFunction.argsList);
         segmentsList  = Helper.GetSegmentsArgs(eFunction.argsList);
         mandatoryList = Helper.GetMandatoryArgs(eFunction.argsList);
         optionalList  = Helper.GetOptionalArgs(eFunction.argsList);
         formArgList   = Helper.GetFormArgs(eFunction.argsList);
         if (bodyArg != null)
         {
             allArgsList.Add(bodyArg);
         }
         if (segmentsList.Any())
         {
             allArgsList.AddRange(segmentsList);
         }
         if (mandatoryList.Any())
         {
             allArgsList.AddRange(mandatoryList);
         }
         if (optionalList.Any())
         {
             allArgsList.AddRange(optionalList);
         }
         if (formArgList.Any())
         {
             allArgsList.AddRange(formArgList);
         }
         for (int i = 0; i < allArgsList.Count; i++)
         {
             EArg eArg = allArgsList.ElementAt(i);
             argsStringBuilder.Append(eArg.name);
             argsStringBuilder.Append(":");
             argsStringBuilder.Append(AngularWatcher.ConvertToAngularTypeName(eArg.typeName));
             if (!string.IsNullOrEmpty(eArg.defaultValue))
             {
                 argsStringBuilder.Append("=" + eArg.defaultValue);
             }
             if (i < (allArgsList.Count - 1))
             {
                 argsStringBuilder.Append(", ");
             }
         }
         if (argsStringBuilder.Length > 0)
         {
             argsStringBuilder.Append(", timeoutSeconds:number=20000");
         }
         else
         {
             argsStringBuilder.Append("timeoutSeconds:number=20000");
         }
         return(true);
     } catch (Exception e) {
         Logger.LogError(e);
     }
     return(false);
 }