示例#1
0
        /*--------------------------------------------------------------------------------------------*/
        private static FabSpecService BuildTraversalService(FabService pSvc,
                                                            Func <string, ApiEntry> pGetEntry)
        {
            IList <ITravRule> rules = TraversalUtil.GetTravRules();
            var map = new Dictionary <SpecStepAttribute, IList <ITravRule> >();

            foreach (ITravRule rule in rules)
            {
                SpecStepAttribute ssa = GetAttribute <SpecStepAttribute>(rule.Step.GetType());

                if (!map.ContainsKey(ssa))
                {
                    map.Add(ssa, new List <ITravRule>());
                }

                map[ssa].Add(rule);
            }

            ////

            FabSpecService svc = BuildService(pSvc, pGetEntry);

            svc.Steps = new List <FabSpecServiceStep>();

            foreach (SpecStepAttribute ssa in map.Keys)
            {
                if (ssa.IsRoot)
                {
                    continue;
                }

                svc.Steps.Add(BuildTraversalServiceStep(ssa, map[ssa]));
            }

            return(svc);
        }
示例#2
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);
        }