public SegmentFluentMethodGroup(SegmentFluentMethodGroups fluentMethodGroups, string localName)
 {
     this.FluentMethodGroups = fluentMethodGroups ?? throw new ArgumentNullException(nameof(fluentMethodGroups));
     //
     if (localName == null)
     {
         throw new ArgumentNullException(nameof(localName));
     }
     this.LocalNameInPascalCase = $"{localName.First().ToString().ToUpper()}{localName.Substring(1)}";
     //
     this.ParentMethodGroupNames = new List <string>();
     this.Level                   = -1;
     this.innerMethods            = new List <MethodJvaf>();
     this.childFluentMethodGroups = new List <ISegmentFluentMethodGroup>();
     this.otherMethods            = null;
 }
 public SegmentFluentMethodGroup(SegmentFluentMethodGroups fluentMethodGroups, string localName, List <string> parentMethodGroupNames)
 {
     this.FluentMethodGroups = fluentMethodGroups ?? throw new ArgumentNullException(nameof(fluentMethodGroups));
     //
     if (localName == null)
     {
         throw new ArgumentNullException(nameof(localName));
     }
     this.LocalNameInPascalCase  = $"{localName.First().ToString().ToUpper()}{localName.Substring(1)}";
     this.ParentMethodGroupNames = parentMethodGroupNames ?? throw new ArgumentNullException(nameof(parentMethodGroupNames));
     //
     this.Level = this.ParentMethodGroupNames.Count(); // Level is zero indexed (level of this group/collection in ARM Uri)
     //
     this.innerMethods            = new List <MethodJvaf>();
     this.childFluentMethodGroups = new List <ISegmentFluentMethodGroup>();
     this.otherMethods            = null;
 }
Example #3
0
 public ServiceManagerModel(CodeModelJvaf codeModel, SegmentFluentMethodGroups fluentMethodGroups)
 {
     this.codeModel          = codeModel;
     this.fluentMethodGroups = fluentMethodGroups;
     this.ns = Settings.Instance.Namespace.ToLower();
 }
Example #4
0
 /// <summary>
 /// Find or create a level 0 "Segment Fluent Method Group".
 /// </summary>
 /// <param name="groups">a dictionary of all "Segment Fluent Method Group List" indexed by "Inner Client" name</param>
 /// <returns>level 0 "Segment Fluent Method Group"</returns>
 public SegmentFluentMethodGroup FindBestMatchingLevel0FluentMethodGroupOrCreateOne(SegmentFluentMethodGroups groups)
 {
     if (this.defaultLevel0FluentMethodGroup == null)
     {
         // First look for a level 0 "Segment Fluent Method Group" with name same as the "Inner Method Group" name.
         //
         this.defaultLevel0FluentMethodGroup = this.Where(group => group.Level == 0)
                                               .Where(group => this.InnerMethodGroupName.StartsWith(group.LocalNameInPascalCase, StringComparison.OrdinalIgnoreCase))
                                               .FirstOrDefault();
         //
         if (this.defaultLevel0FluentMethodGroup == null)
         {
             // If no such group then pick the first one in level 0 sorted by the name
             //
             this.defaultLevel0FluentMethodGroup = this.OrderBy(group => group.LocalNameInPascalCase).Where(group => group.Level == 0).FirstOrDefault();
             // if there no level 0 then create one
             //
             if (this.defaultLevel0FluentMethodGroup == null)
             {
                 this.defaultLevel0FluentMethodGroup = new SegmentFluentMethodGroup(fluentMethodGroups: groups,
                                                                                    localName: this.InnerMethodGroupName,
                                                                                    parentMethodGroupNames: new List <string>());
                 //
                 this.AddFluentMethodGroup(this.defaultLevel0FluentMethodGroup);
             }
         }
     }
     return(this.defaultLevel0FluentMethodGroup);
 }
        /// <summary>
        /// Given an ARM operation endpoint Uri, derive a "Segment Fluent Method Group" that the operation can possibly belongs to.
        /// </summary>
        /// <param name="fluentMethodGroups">the map holding all "Segment Fluent Method Group"s</param>
        /// <param name="innerMethod">inner Swagger method</param>
        /// <param name="segments">the ARM operation endpoint uri segments those appear after Provider name</param>
        /// <returns>The segment fluent method group</returns>
        public static SegmentFluentMethodGroup ResolveFluentMethodGroup(SegmentFluentMethodGroups fluentMethodGroups,
                                                                        MethodJvaf innerMethod,
                                                                        IEnumerable <Segment> segments,
                                                                        string defaultMethodGroupName)
        {
            List <string> fluentMethodGroupNamesInSegments = new List <string>();
            Pluralizer    pluralizer = new Pluralizer();
            HttpMethod    httpMethod = innerMethod.HttpMethod;

            segments
            .Where(segment => !(segment is PositionalSegment) && Utils.IsPlural(segment.Name, fluentMethodGroups.FluentConfig))
            .ForEach(segment =>
            {
                fluentMethodGroupNamesInSegments.Add(segment.Name);
            });
            //
            if (fluentMethodGroupNamesInSegments.Count() == 0)
            {
                // Level 0 "Fluent Method Group"
                return(new SegmentFluentMethodGroup(fluentMethodGroups: fluentMethodGroups,
                                                    localName: defaultMethodGroupName,
                                                    parentMethodGroupNames: new List <string>()));
            }
            if (fluentMethodGroupNamesInSegments.Count() == 1)
            {
                // Level 0 "Fluent Method Group"
                return(new SegmentFluentMethodGroup(fluentMethodGroups: fluentMethodGroups,
                                                    localName: fluentMethodGroupNamesInSegments[0],
                                                    parentMethodGroupNames: new List <string>()));
            }
            else if (httpMethod == HttpMethod.Post)
            {
                if (segments.Last() is TerminalSegment &&
                    segments.Last().Name.EqualsIgnoreCase(fluentMethodGroupNamesInSegments.Last()))
                {
                    //POST /providers/Microsoft.EventHub/namespaces/{nsname}/authorizationRules/{ruleName}/listKeys
                    //
                    return(new SegmentFluentMethodGroup(fluentMethodGroups: fluentMethodGroups,
                                                        localName: fluentMethodGroupNamesInSegments.SkipLast(1).Last(),
                                                        parentMethodGroupNames: fluentMethodGroupNamesInSegments.SkipLast(2).ToList()));
                }
                else
                {
                    return(new SegmentFluentMethodGroup(fluentMethodGroups: fluentMethodGroups,
                                                        localName: fluentMethodGroupNamesInSegments.Last(),
                                                        parentMethodGroupNames: fluentMethodGroupNamesInSegments.SkipLast(1).ToList()));
                }
            }
            else
            {
                IModelTypeJv retType = innerMethod.ReturnTypeJva.BodyClientType;
                if ((httpMethod == HttpMethod.Get || httpMethod == HttpMethod.Put) &&
                    (retType is PrimaryType || (retType as SequenceType)?.ElementType is PrimaryType))
                {
                    return(new SegmentFluentMethodGroup(fluentMethodGroups: fluentMethodGroups,
                                                        localName: fluentMethodGroupNamesInSegments.SkipLast(1).Last(),
                                                        parentMethodGroupNames: fluentMethodGroupNamesInSegments.SkipLast(2).ToList()));
                }
                else
                {
                    return(new SegmentFluentMethodGroup(fluentMethodGroups: fluentMethodGroups,
                                                        localName: fluentMethodGroupNamesInSegments.Last(),
                                                        parentMethodGroupNames: fluentMethodGroupNamesInSegments.SkipLast(1).ToList()));
                }
            }
        }
Example #6
0
 public ModelLocalProperties(IEnumerable <Property> innerProperties, SegmentFluentMethodGroups methodGroups, bool wrapReturnInner)
 {
     this.innerProperties = innerProperties;
     this.methodGroups    = methodGroups;
     this.wrapReturnInner = wrapReturnInner;
 }
Example #7
0
 public ClientFluentReadOnlyModelInterface(WrappableFluentModel fluentModel, SegmentFluentMethodGroups fluentMethodGroups, string managerTypeName)
 {
     this.fluentModel        = fluentModel;
     this.fluentMethodGroups = fluentMethodGroups;
     this.ManagerTypeName    = managerTypeName;
 }
        public static SegmentFluentMethodGroups InnerMethodGroupToSegmentFluentMethodGroups(CodeModelJvaf codeModel)
        {
            IEnumerable <MethodGroupJv> allInnerMethodGroups = codeModel.AllOperations;
            //
            SegmentFluentMethodGroups fluentMethodGroups = new SegmentFluentMethodGroups(codeModel);

            //
            foreach (MethodGroupJvaf currentInnerMethodGroup in allInnerMethodGroups)
            {
                SegmentFluentMethodGroupList fluentMethodGroupsInCurrentInnerMethodGroup = new SegmentFluentMethodGroupList(currentInnerMethodGroup);
                //
                fluentMethodGroups.Add(fluentMethodGroupsInCurrentInnerMethodGroup);
                //
                foreach (MethodJvaf innerMethod in currentInnerMethodGroup.Methods)
                {
                    if (innerMethod.Name.ToLowerInvariant().StartsWith("begin", StringComparison.OrdinalIgnoreCase))
                    {
                        // Skip LRO begin methods
                        continue;
                    }
                    else
                    {
                        ARMUri armUri = new ARMUri(innerMethod);
                        // Skip below two methods
                        //    1. uri can be empty for method such as 'listNext'
                        //    2. uri can be just 'nextLink' for method to retrieve next page
                        if (!armUri.IsNullOrEmpty() && !(armUri.Count == 1 && armUri.First().Name.EqualsIgnoreCase("nextLink")))
                        {
                            IEnumerable <Segment> segments = armUri.SegmentsAfterProvider;
                            segments = segments.Any() ? segments : armUri;
                            //
                            if (segments.Any())
                            {
                                SegmentFluentMethodGroup fluentMethodGroup = null;
                                if (segments.Count() == 1 && (segments.First() is TerminalSegment))
                                {
                                    // e.g. providers/Microsoft.Network/networkInterfaces
                                    // e.g. providers/Microsoft.Network/checkNameAvailability
                                    //
                                    string name = segments.First().Name;
                                    fluentMethodGroup = new SegmentFluentMethodGroup(fluentMethodGroups: fluentMethodGroups,
                                                                                     localName: DeferredFluentMethodGroupNamePrefix.AddPrefix(name));
                                }
                                else
                                {
                                    string methodGroupDefaultName = Utils.TrimInnerSuffix(currentInnerMethodGroup.Name.ToString());
                                    fluentMethodGroup = SegmentFluentMethodGroup.ResolveFluentMethodGroup(fluentMethodGroups, innerMethod, segments, methodGroupDefaultName);
                                    fluentMethodGroup = fluentMethodGroup ?? throw new ArgumentNullException(nameof(fluentMethodGroup));
                                }
                                // Checks whether we already derived a method group with same name in the current "Inner Method Group"
                                //
                                SegmentFluentMethodGroup matchedFluentMethodGroup = fluentMethodGroupsInCurrentInnerMethodGroup.FindFluentMethodGroup(fluentMethodGroup.LocalNameInPascalCase);
                                if (matchedFluentMethodGroup != null)
                                {
                                    matchedFluentMethodGroup.AddInnerMethod(innerMethod);
                                }
                                else
                                {
                                    fluentMethodGroup.AddInnerMethod(innerMethod);
                                    fluentMethodGroupsInCurrentInnerMethodGroup.AddFluentMethodGroup(fluentMethodGroup);
                                }
                            }
                        }
                    }
                }
            }
            //
            fluentMethodGroups.ResolveDeferredSegmentFluentMethodGroups(codeModel);
            fluentMethodGroups.LinkSegmentFluentMethodGroups();
            fluentMethodGroups.InjectPlaceHolderSegmentFluentMethodGroups();
            fluentMethodGroups.DeriveStandardInnerModelForMethodGroups();
            fluentMethodGroups.PruneMethodGroups();
            fluentMethodGroups.Select(m => m.Value).SelectMany(fluentMethodGroupList => fluentMethodGroupList)
            .ForEach(fluentMethodGroup =>
            {
                fluentMethodGroup.JavaInterfaceName = fluentMethodGroup.LocalNameInPascalCase;
            });
            fluentMethodGroups.EnsureUniqueJvaModelInterfaceName();
            fluentMethodGroups.SpecializeFluentModels();
            //
            return(fluentMethodGroups);
        }