/*--------------------------------------------------------------------------------------------*/ private static FabSpecServiceOperation BuildServiceOp(string pSvcName, FabServiceOperation pSvcOp, ApiEntry pEntry) { var so = new FabSpecServiceOperation(); so.Name = pSvcOp.Name; so.Uri = pSvcOp.Uri; so.Method = pSvcOp.Method; so.Return = ApiLang.TypeName(pEntry.ResponseType); so.Description = ApiLang.Text <ServiceOpText>(pSvcName + "_" + so.Name + "_" + so.Method); so.Auth = (pEntry.MemberAuth ? "Member" : "None"); so.Parameters = new List <FabSpecServiceParam>(); for (int i = 0; i < pEntry.Params.Count; i++) { ApiEntryParam aep = pEntry.Params[i]; var sop = new FabSpecServiceParam(); sop.Index = i; sop.Name = aep.Name; sop.Type = ApiLang.TypeName(aep.ParamType); so.Parameters.Add(sop); string langKey = (aep.LangKey ?? pSvcName + "_" + so.Name + "_" + sop.Name); sop.Description = ApiLang.Text <ServiceOpParamText>(langKey); } return(so); }
/*--------------------------------------------------------------------------------------------*/ private static FabServiceOperation NewOperation(string pName, Type pRespType, ApiEntry.Method pMethod = ApiEntry.Method.Get) { var op = new FabServiceOperation(); op.Name = pName; op.Uri = "/" + pName.Replace(" ", ""); op.Method = (pMethod + "").ToUpper(); op.Return = ApiLang.TypeName(pRespType); return(op); }
/*--------------------------------------------------------------------------------------------*/ private static List <FabSpecObjectProp> BuildEnumProps(string pEnumName, EnumItem pItem) { var enumProps = new List <FabSpecObjectProp>(); if (pItem == null) { pItem = new EnumItem(); } PropertyInfo[] props = pItem.GetType().GetProperties( BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); foreach (PropertyInfo pi in props) { var p = new FabSpecObjectProp(); p.Name = pi.Name; p.Description = ApiLang.Text <EnumPropText>(pEnumName + "_" + p.Name); p.Type = ApiLang.TypeName(pi.PropertyType); enumProps.Add(p); } return(enumProps); }
/*--------------------------------------------------------------------------------------------*/ private static FabSpecObjectProp BuildObjectProp( string pObjName, PropertyInfo pProp, bool pSkipText) { DataMemberAttribute dataMem = GetAttribute <DataMemberAttribute>(pProp); var p = new FabSpecObjectProp(); p.Name = (dataMem == null ? pProp.Name : dataMem.Name); p.Type = ApiLang.TypeName(pProp.PropertyType); if (!pSkipText) { string key = pObjName.Substring(3) + "_" + pProp.Name; if (pObjName.IndexOf("CreateFab") == 0) { key = pObjName.Replace("CreateFab", "Create") + "_" + pProp.Name; } p.Description = ApiLang.Text <DtoPropText>(key); } //// SpecLenAttribute specLen = GetAttribute <SpecLenAttribute>(pProp); SpecRangeAttribute specRange = GetAttribute <SpecRangeAttribute>(pProp); SpecRegexAttribute specReg = GetAttribute <SpecRegexAttribute>(pProp); SpecUniqueAttribute specUni = GetAttribute <SpecUniqueAttribute>(pProp); SpecToLowerCaseAttribute specLow = GetAttribute <SpecToLowerCaseAttribute>(pProp); SpecFromEnumAttribute specEnum = GetAttribute <SpecFromEnumAttribute>(pProp); if (HasAttribute <SpecOptionalAttribute>(pProp)) { p.IsOptional = true; } if (specLen != null) { p.LenMin = specLen.Min; p.LenMax = specLen.Max; } if (specRange != null) { p.Min = specRange.Min; p.Max = specRange.Max; } if (specReg != null) { p.ValidRegex = specReg.Pattern; } if (specUni != null) { p.IsUnique = true; } if (specLow != null) { p.ToLowerCase = true; } if (specEnum != null) { p.Enum = specEnum.Name; } return(p); }
/*--------------------------------------------------------------------------------------------*/ private static FabSpecServiceStep BuildTraversalServiceStep(SpecStepAttribute pStepAttr, IList <ITravRule> pRules) { var s = new FabSpecServiceStep(); s.Name = pStepAttr.Name; s.Description = ApiLang.Text <StepText>(s.Name); s.Parameters = new List <FabSpecServiceParam>(); s.Rules = new List <FabSpecServiceStepRule>(); ITravStep ts0 = pRules[0].Step; foreach (ITravStepParam tsp in ts0.Params) { var p = new FabSpecServiceParam(); p.Index = tsp.ParamIndex; p.Name = tsp.Name; p.Description = ApiLang.Text <StepParamText>(s.Name + "_" + p.Name); p.Type = ApiLang.TypeName(tsp.DataType); p.Min = tsp.Min; p.Max = tsp.Max; p.LenMax = tsp.LenMax; p.ValidRegex = tsp.ValidRegex; s.Parameters.Add(p); if (tsp.IsGenericDataType) { p.Type = "T"; } if (tsp.AcceptedStrings != null) { p.AcceptedStrings = tsp.AcceptedStrings.ToArray(); } } foreach (ITravRule rule in pRules) { ITravStep ts = rule.Step; var r = new FabSpecServiceStepRule(); r.Name = ts.Command; r.Uri = "/" + ts.Command; r.Entry = ApiLang.TypeName(rule.FromType); s.Rules.Add(r); if (rule.ToType != null) { r.Return = ApiLang.TypeName(rule.ToType); } if (ts.ToAliasType) { r.ReturnsAliasType = true; } if (ts.ParamValueType != null) { r.T = ApiLang.TypeName(ts.ParamValueType); } } return(s); }