Ejemplo n.º 1
0
        /*--------------------------------------------------------------------------------------------*/
        private static FabSpecService BuildService(FabService pSvc, Func <string, ApiEntry> pGetEntry)
        {
            var s = new FabSpecService();

            s.Name        = pSvc.Name;
            s.Uri         = pSvc.Uri;
            s.Summary     = ApiLang.Text <ServiceText>(s.Name + "Summ");
            s.Description = ApiLang.Text <ServiceText>(s.Name + "Desc");
            s.Operations  = new List <FabSpecServiceOperation>();

            foreach (FabServiceOperation svcOp in pSvc.Operations)
            {
                if (svcOp == null)
                {
                    throw new Exception("Missing ServiceOperation for '" + pSvc.Name + "'.");
                }

                string   key = svcOp.Method + " " + s.Uri + svcOp.Uri;
                ApiEntry ae;

                try {
                    ae = pGetEntry(key);
                }
                catch (Exception e) {
                    throw new Exception("No ApiEntry for '" + pSvc.Name + "' with key '" + key + "'.", e);
                }

                FabSpecServiceOperation sso = BuildServiceOp(s.Name, svcOp, ae);
                s.Operations.Add(sso);
            }

            return(s);
        }
Ejemplo n.º 2
0
        /*--------------------------------------------------------------------------------------------*/
        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);
        }
Ejemplo n.º 3
0
        /*--------------------------------------------------------------------------------------------*/
        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);
        }
Ejemplo n.º 4
0
        /*--------------------------------------------------------------------------------------------*/
        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);
        }
Ejemplo n.º 5
0
        /*--------------------------------------------------------------------------------------------*/
        private static FabSpecObject BuildObject(Type pType)
        {
            var o = new FabSpecObject();

            o.Name    = pType.Name.Split(new[] { '`' })[0];
            o.Extends = pType.BaseType.Name.Split(new[] { '`' })[0];

            if (o.Name.IndexOf("CreateFab") == 0)
            {
                o.Description = ApiLang.Text <DtoText>(o.Name);
            }
            else if (o.Name.IndexOf("FabSpec") == 0)
            {
                o.Description = null;
            }
            else
            {
                o.Description = ApiLang.Text <DtoText>(o.Name.Substring(3));                //remove "Fab"
            }

            o.Properties = BuildObjectProps(o.Name, pType, (o.Description == null));
            return(o);
        }
Ejemplo n.º 6
0
        /*--------------------------------------------------------------------------------------------*/
        private static FabSpecEnum BuildEnum(Type pType)
        {
            EnumObject       obj   = (EnumObject)Activator.CreateInstance(pType);
            IList <EnumItem> items = (obj.ToList() ?? new List <EnumItem>());

            var e = new FabSpecEnum();

            e.Name        = pType.Name;
            e.Description = ApiLang.Text <EnumText>(e.Name);
            e.Properties  = BuildEnumProps(e.Name, items.FirstOrDefault());

            if (pType != typeof(EnumObject))
            {
                e.Extends = pType.BaseType.Name;
                e.Items   = new List <Dictionary <string, object> >();

                foreach (EnumItem item in items)
                {
                    e.Items.Add(BuildEnumItem(item));
                }
            }

            return(e);
        }
Ejemplo n.º 7
0
        /*--------------------------------------------------------------------------------------------*/
        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);
        }
Ejemplo n.º 8
0
        /*--------------------------------------------------------------------------------------------*/
        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);
        }