private void CheckGetByImmediateParentSupport()
 {
     if (this.FluentMethodGroup.Level > 0)
     {
         foreach (MethodJvaf innerMethod in FluentMethodGroup.InnerMethods.Where(method => method.HttpMethod == HttpMethod.Get))
         {
             ISegmentFluentMethodGroup parentMethodGroup = this.FluentMethodGroup.ParentFluentMethodGroup;
             if (parentMethodGroup != null)
             {
                 bool isResponseCompositeType = innerMethod.ReturnTypeJva.BodyClientType is CompositeTypeJv;
                 if (!isResponseCompositeType)
                 {
                     // In order to be able to map response to standard model T where T is class/interface type
                     // it need to be composite type. If the return type is primitive type (e.g. void), sequence type
                     // dict type then mapping cannot be done. Skip get methods returning such types they will be appear
                     // as other methods
                     continue;
                 }
                 else
                 {
                     var     armUri      = new ARMUri(innerMethod);
                     Segment lastSegment = armUri.LastOrDefault();
                     if (lastSegment != null && lastSegment is ParentSegment)
                     {
                         ParentSegment resourceSegment = (ParentSegment)lastSegment;
                         if (resourceSegment.Name.EqualsIgnoreCase(FluentMethodGroup.LocalNameInPascalCase))
                         {
                             Segment secondLastSegment = armUri.SkipLast(1).LastOrDefault();
                             if (secondLastSegment != null && secondLastSegment is ParentSegment)
                             {
                                 ParentSegment parentSegment = (ParentSegment)secondLastSegment;
                                 if (parentSegment.Name.EqualsIgnoreCase(parentMethodGroup.LocalNameInPascalCase))
                                 {
                                     if (StandardFluentMethod.CanWrap(innerMethod))
                                     {
                                         this.supportsGet = true;
                                         this.getMethod   = new StandardFluentMethod(innerMethod, this.FluentMethodGroup);
                                         break;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     else
     {
         this.supportsGet = false;
         this.getMethod   = null;
     }
 }
 public bool IsCompatibleWith(FluentModelMemberVariables other)
 {
     if (other.FluentMethod == null || this.FluentMethod == null)
     {
         return(true);
     }
     else
     {
         var thisArmUri  = new ARMUri(this.FluentMethod.InnerMethod);
         var otherArmUri = new ARMUri(other.FluentMethod.InnerMethod);
         return(thisArmUri.IsSame(otherArmUri));
     }
 }
 private void CheckGetByResourceGroupSupport()
 {
     if (this.FluentMethodGroup.Level == 0)
     {
         foreach (MethodJvaf innerMethod in FluentMethodGroup.InnerMethods.Where(method => method.HttpMethod == HttpMethod.Get))
         {
             bool isResponseCompositeType = innerMethod.ReturnTypeJva.BodyClientType is CompositeTypeJv;
             if (!isResponseCompositeType)
             {
                 // In order to be able to implement SupportsGetByResourceGroup<T> where T is class/interface type,
                 // we should be able to map respone resource of get to T. If the return type is primitive type
                 // (e.g. void), sequence type, dict type then mapping cannot be done. Skip get methods returning
                 // such types they will be appear as "OtherMethod"s.
                 continue;
             }
             else
             {
                 var     armUri      = new ARMUri(innerMethod);
                 Segment lastSegment = armUri.LastOrDefault();
                 if (lastSegment != null && lastSegment is ParentSegment)
                 {
                     ParentSegment resourceSegment    = (ParentSegment)lastSegment;
                     var           requiredParameters = Utils.RequiredParametersOfMethod(innerMethod);
                     if (resourceSegment.Name.EqualsIgnoreCase(FluentMethodGroup.LocalNameInPascalCase) && requiredParameters.Count() == 2)
                     {
                         var resourceGroupSegment = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("resourceGroups"));
                         if (resourceGroupSegment != null)
                         {
                             bool hasResourceGroupParam = requiredParameters.Any(p => p.SerializedName.EqualsIgnoreCase(resourceGroupSegment.Parameter.SerializedName));
                             bool hasResourceParm       = requiredParameters.Any(p => p.SerializedName.EqualsIgnoreCase(resourceSegment.Parameter.SerializedName));
                             if (hasResourceGroupParam && hasResourceParm)
                             {
                                 if (StandardFluentMethod.CanWrap(innerMethod))
                                 {
                                     this.supportsGet = true;
                                     this.getMethod   = new StandardFluentMethod(innerMethod, this.FluentMethodGroup);
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     else
     {
         this.supportsGet = false;
         this.getMethod   = null;
     }
 }
        private StandardFluentMethod TryGetCreateAsNestedChildMethod()
        {
            foreach (MethodJvaf innerMethod in FluentMethodGroup.InnerMethods)
            {
                string innerMethodName = innerMethod.Name.ToLowerInvariant();
                if (innerMethodName.Contains("update") && !innerMethodName.Contains("create"))
                {
                    // There are resources that does not support create, but support update through PUT
                    // here using method name pattern as heuristics to skip such methods to be considered
                    // as create method.
                    //
                    continue;
                }

                if (innerMethod.HttpMethod == HttpMethod.Put)
                {
                    bool isResponseCompositeType = innerMethod.ReturnTypeJva.BodyClientType is CompositeTypeJv;
                    if (!isResponseCompositeType)
                    {
                        // In order to be able to implement SupportsCreating<T> where T is class/interface type, we should be
                        // able to map response resource of create to T. if the return type is primitive type (e.g. void),
                        // sequence type, dict type then mapping cannot be done. Skip create methods returning such types
                        // they will be appear as other methods
                        continue;
                    }
                    else if (!Utils.HasProperty(innerMethod.ReturnTypeJva.BodyClientType, "name"))
                    {
                        // A model that is creatable has to be derive from CreatableUpdatableImpl which requires name
                        // property to present.
                        continue;
                    }
                    else
                    {
                        var     armUri      = new ARMUri(innerMethod);
                        Segment lastSegment = armUri.LastOrDefault();
                        if (lastSegment != null && lastSegment is ParentSegment)
                        {
                            ParentSegment resourceSegment = (ParentSegment)lastSegment;
                            if (resourceSegment.Name.EqualsIgnoreCase(FluentMethodGroup.LocalNameInPascalCase))
                            {
                                if (this.FluentMethodGroup.Level > 0 && StandardFluentMethod.CanWrap(innerMethod))
                                {
                                    return(new StandardFluentMethod(innerMethod, this.FluentMethodGroup));
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }
 private FluentMethod TryGetCreateInSubscriptionMethod()
 {
     foreach (MethodJvaf innerMethod in fluentMethodGroup.InnerMethods)
     {
         string innerMethodName = innerMethod.Name.ToLowerInvariant();
         if (innerMethodName.Contains("update") && !innerMethodName.Contains("create"))
         {
             // There are resources that does not support create, but support update through PUT
             // here using method name pattern as heuristics to skip such methods to be considered
             // as create method.
             //
             continue;
         }
         if (innerMethod.HttpMethod == HttpMethod.Put)
         {
             if (innerMethod.ReturnTypeJva.BodyClientType is PrimaryTypeJv)
             {
                 // In order to be able to implement SupportsCreating<T>, we should be able to map resource of create to T
                 // if the return type is primitive type (e.g. void) then mapping cannot be done. Skip create methods
                 // returning such primitve they will be appear as other methods
                 continue;
             }
             else
             {
                 var     armUri      = new ARMUri(innerMethod);
                 Segment lastSegment = armUri.LastOrDefault();
                 if (lastSegment != null && lastSegment is ParentSegment)
                 {
                     ParentSegment resourceSegment = (ParentSegment)lastSegment;
                     if (resourceSegment.Name.EqualsIgnoreCase(fluentMethodGroup.LocalNameInPascalCase))
                     {
                         if (this.fluentMethodGroup.Level == 0)
                         {
                             var subscriptionSegment = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("subscriptions"));
                             if (subscriptionSegment != null)
                             {
                                 var resourceGroupSegment = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("resourceGroups"));
                                 if (resourceGroupSegment == null)
                                 {
                                     return(new FluentMethod(true, innerMethod, this.fluentMethodGroup));
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return(null);
 }
예제 #6
0
        private void CheckGetByParameterizedParentSupport()
        {
            if (this.FluentMethodGroup.Level == 0)
            {
                foreach (MethodJvaf innerMethod in FluentMethodGroup.InnerMethods.Where(method => method.HttpMethod == HttpMethod.Get))
                {
                    bool isResponseCompositeType = innerMethod.ReturnTypeJva.BodyClientType is CompositeTypeJv;
                    if (!isResponseCompositeType)
                    {
                        // In order to be able to map response to standard model T where T is class/interface type
                        // it need to be composite type. If the return type is primitive type (e.g. void), sequence type
                        // dict type then mapping cannot be done. Skip get methods returning such types they will be appear
                        // as "OtherMethod"s
                        continue;
                    }
                    else
                    {
                        var     armUri      = new ARMUri(innerMethod);
                        Segment lastSegment = armUri.LastOrDefault();
                        if (lastSegment != null && lastSegment is ParentSegment)
                        {
                            ParentSegment resourceSegment    = (ParentSegment)lastSegment;
                            var           requiredParameters = Utils.RequiredParametersOfMethod(innerMethod);
                            if (resourceSegment.Name.EqualsIgnoreCase(FluentMethodGroup.LocalNameInPascalCase))
                            {
                                var subscriptionSegment  = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("subscriptions"));
                                var resourceGroupSegment = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("resourceGroups"));

                                if (subscriptionSegment == null && resourceGroupSegment == null)
                                {
                                    if (StandardFluentMethod.CanWrap(innerMethod))
                                    {
                                        this.supportsGet = true;
                                        this.getMethod   = new StandardFluentMethod(innerMethod, this.FluentMethodGroup);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                this.supportsGet = false;
                this.getMethod   = null;
            }
        }
 /// <summary>
 /// Check can support list by immediate parent.
 /// </summary>
 private void CheckListByImmediateParentSupport()
 {
     if (this.FluentMethodGroup.Level > 0)
     {
         foreach (MethodJvaf innerMethod in FluentMethodGroup.InnerMethods.Where(method => method.HttpMethod == HttpMethod.Get))
         {
             IFluentMethodGroup parentMethodGroup = this.FluentMethodGroup.ParentFluentMethodGroup;
             if (parentMethodGroup != null)
             {
                 var     armUri      = new ARMUri(innerMethod);
                 Segment lastSegment = armUri.LastOrDefault();
                 if (lastSegment != null && lastSegment is TerminalSegment)
                 {
                     TerminalSegment terminalSegment = (TerminalSegment)lastSegment;
                     if (terminalSegment.Name.EqualsIgnoreCase(FluentMethodGroup.LocalNameInPascalCase))
                     {
                         Segment secondLastSegment = armUri.SkipLast(1).LastOrDefault();
                         if (secondLastSegment != null && secondLastSegment is ParentSegment)
                         {
                             ParentSegment parentSegment = (ParentSegment)secondLastSegment;
                             if (parentSegment.Name.EqualsIgnoreCase(parentMethodGroup.LocalNameInPascalCase))
                             {
                                 if (innerMethod.ReturnTypeResponseName.StartsWith("PagedList<") ||
                                     innerMethod.ReturnTypeResponseName.StartsWith("List<"))
                                 {
                                     if (StandardFluentMethod.CanWrap(innerMethod))
                                     {
                                         this.supportsListing = true;
                                         this.listMethod      = new StandardFluentMethod(innerMethod, this.FluentMethodGroup);
                                         break;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     else
     {
         this.supportsListing = false;
         this.listMethod      = null;
     }
 }
        private void Init()
        {
            ARMUri armUri = new ARMUri(this.FluentMethod.InnerMethod);

            //
            foreach (ParameterJv parameter in this.MethodParameters.Where(p => !p.IsConstant && !p.IsClientProperty))
            {
                FluentModelMemberVariable memberVariable = null;
                if (parameter.Location == ParameterLocation.Path)
                {
                    var parentSegment = armUri.OfType <ParentSegment>()
                                        .Where(segment => segment.Parameter.Name.Equals(parameter.Name))
                                        .FirstOrDefault();
                    if (parentSegment != null)
                    {
                        memberVariable = new FluentModelParentRefMemberVariable(parentSegment);
                    }
                    else
                    {
                        var positionalSegment = armUri.OfType <PositionalSegment>()
                                                .Where(segment => segment.Parameter.Name.Equals(parameter.Name))
                                                .FirstOrDefault();
                        if (positionalSegment != null)
                        {
                            memberVariable = new FluentModelPositionalPathMemberVariable(positionalSegment);
                        }
                    }
                    //
                    if (memberVariable == null)
                    {
                        throw new InvalidOperationException($"Unable to locate a parameter segment with name '{parameter.Name}' in the ARM Uri '{this.FluentMethod.InnerMethod.Url}'.");
                    }
                }
                else
                {
                    memberVariable = new FluentModelMemberVariable(variableName: parameter.Name, fromParameter: parameter);
                }
                memberVariable.Index = GetParameterIndex(parameter);
                //
                //
                this.Add(memberVariable.VariableName, memberVariable);
            }
        }
 /// <summary>
 /// Checks can support "SupportsListByResourceGroup" interface
 /// </summary>
 private void CheckListByResourceGroupSupport()
 {
     if (this.FluentMethodGroup.Level == 0)
     {
         foreach (MethodJvaf innerMethod in FluentMethodGroup.InnerMethods.Where(method => method.HttpMethod == HttpMethod.Get))
         {
             var     armUri      = new ARMUri(innerMethod);
             Segment lastSegment = armUri.LastOrDefault();
             if (lastSegment != null && lastSegment is TerminalSegment)
             {
                 TerminalSegment terminalSegment    = (TerminalSegment)lastSegment;
                 var             requiredParameters = Utils.RequiredParametersOfMethod(innerMethod);
                 if (terminalSegment.Name.EqualsIgnoreCase(FluentMethodGroup.LocalNameInPascalCase) && requiredParameters.Count() == 1)
                 {
                     var subscriptionSegment  = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("subscriptions"));
                     var resourceGroupSegment = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("resourceGroups"));
                     if (subscriptionSegment != null && resourceGroupSegment != null)
                     {
                         var singleParameter = requiredParameters.First();
                         if (resourceGroupSegment.Parameter.SerializedName.EqualsIgnoreCase(singleParameter.SerializedName))
                         {
                             if (innerMethod.ReturnTypeResponseName.StartsWith("PagedList<") ||
                                 innerMethod.ReturnTypeResponseName.StartsWith("List<"))
                             {
                                 if (StandardFluentMethod.CanWrap(innerMethod))
                                 {
                                     this.supportsListing = true;
                                     this.listMethod      = new StandardFluentMethod(innerMethod, this.FluentMethodGroup);
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     else
     {
         this.supportsListing = false;
         this.listMethod      = null;
     }
 }
 private FluentMethod TryGetUpdateInSubscriptionMethod()
 {
     foreach (MethodJvaf innerMethod in fluentMethodGroup.InnerMethods)
     {
         if (innerMethod.HttpMethod == HttpMethod.Patch)
         {
             if (innerMethod.ReturnTypeJva.BodyClientType is PrimaryTypeJv)
             {
                 // In order to be able to implement SupportUpdating<T>, we should be able to map resource of update to T
                 // if the return type is primitive type (e.g. void) then mapping cannot be done. Skip update methods
                 // returning such primitve they will be appear as other methods
                 continue;
             }
             else
             {
                 var     armUri      = new ARMUri(innerMethod);
                 Segment lastSegment = armUri.LastOrDefault();
                 if (lastSegment != null && lastSegment is ParentSegment)
                 {
                     ParentSegment resourceSegment = (ParentSegment)lastSegment;
                     if (resourceSegment.Name.EqualsIgnoreCase(fluentMethodGroup.LocalNameInPascalCase))
                     {
                         if (this.fluentMethodGroup.Level == 0)
                         {
                             var subscriptionSegment = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("subscriptions"));
                             if (subscriptionSegment != null)
                             {
                                 var resourceGroupSegment = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("resourceGroups"));
                                 if (resourceGroupSegment == null)
                                 {
                                     return(new FluentMethod(true, innerMethod, this.fluentMethodGroup));
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return(null);
 }
 private void CheckGetByImmediateParentSupport()
 {
     if (this.fluentMethodGroup.Level > 0)
     {
         foreach (MethodJvaf innerMethod in fluentMethodGroup.InnerMethods.Where(method => method.HttpMethod == HttpMethod.Get))
         {
             FluentMethodGroup parentMethodGroup = this.fluentMethodGroup.ParentFluentMethodGroup;
             if (parentMethodGroup != null)
             {
                 var     armUri      = new ARMUri(innerMethod);
                 Segment lastSegment = armUri.LastOrDefault();
                 if (lastSegment != null && lastSegment is ParentSegment)
                 {
                     ParentSegment resourceSegment = (ParentSegment)lastSegment;
                     if (resourceSegment.Name.EqualsIgnoreCase(fluentMethodGroup.LocalNameInPascalCase))
                     {
                         Segment secondLastSegment = armUri.SkipLast(1).LastOrDefault();
                         if (secondLastSegment != null && secondLastSegment is ParentSegment)
                         {
                             ParentSegment parentSegment = (ParentSegment)secondLastSegment;
                             if (parentSegment.Name.EqualsIgnoreCase(parentMethodGroup.LocalNameInPascalCase))
                             {
                                 this.supportsGetByImmediateParent = true;
                                 this.getByImmediateParentMethod   = new FluentMethod(true, innerMethod, this.fluentMethodGroup);
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
     else
     {
         this.supportsGetByImmediateParent = false;
         this.getByImmediateParentMethod   = null;
     }
 }
예제 #12
0
        /// <summary>
        /// Checks this Uri matches with the provided Uri.
        /// </summary>
        /// <param name="other">the other uri</param>
        /// <returns>true if matches, false otherwise</returns>
        public bool IsSame(ARMUri other)
        {
            var thisUriItr  = this.GetEnumerator();
            var otherUriItr = other.GetEnumerator();

            //
            while (thisUriItr.MoveNext() && otherUriItr.MoveNext())
            {
                if (thisUriItr.Current is PositionalSegment)
                {
                    if (otherUriItr.Current is PositionalSegment)
                    {
                        continue;
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (thisUriItr.Current is ParentSegment)
                {
                    if (otherUriItr.Current is ParentSegment)
                    {
                        if (thisUriItr.Current.Name.EqualsIgnoreCase(otherUriItr.Current.Name))
                        {
                            continue;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (thisUriItr.Current is ReferenceSegment)
                {
                    if (otherUriItr.Current is ReferenceSegment)
                    {
                        if (thisUriItr.Current.Name.EqualsIgnoreCase(otherUriItr.Current.Name))
                        {
                            continue;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (thisUriItr.Current is TerminalSegment)
                {
                    if (otherUriItr.Current is TerminalSegment)
                    {
                        if (thisUriItr.Current.Name.EqualsIgnoreCase(otherUriItr.Current.Name))
                        {
                            continue;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            return(thisUriItr.MoveNext() == false &&
                   otherUriItr.MoveNext() == false);
        }
예제 #13
0
        private StandardFluentMethod TryGetUpdateInParameterizedParentMethod(bool findPatchUpdate)
        {
            bool findPutUpdate = !findPatchUpdate;

            //
            foreach (MethodJvaf innerMethod in fluentMethodGroup.InnerMethods)
            {
                if ((findPatchUpdate && innerMethod.HttpMethod == HttpMethod.Patch) || (findPutUpdate && innerMethod.HttpMethod == HttpMethod.Put))
                {
                    bool isResponseCompositeType = innerMethod.ReturnTypeJva.BodyClientType is CompositeTypeJv;
                    if (!isResponseCompositeType)
                    {
                        // In order to be able to implement SupportUpdating<T>, we should be able to map resource of update to T
                        // if the return type is primitive type (e.g. void) then mapping cannot be done. Skip update methods
                        // returning such primitve they will be appear as other methods
                        continue;
                    }
                    else if (!Utils.HasProperty(innerMethod.ReturnTypeJva.BodyClientType, "name"))
                    {
                        // A model that is creatable has to be derive from CreatableUpdatableImpl which requires name
                        // property to present.
                        continue;
                    }
                    else
                    {
                        if (findPutUpdate)
                        {
                            string innerMethodName = innerMethod.Name.ToLowerInvariant();
                            if (innerMethodName.Contains("create") && !innerMethodName.Contains("update"))
                            {
                                // There are resources that does not support update, but support create through PUT
                                // here using method name pattern as heuristics to skip such methods to be considered
                                // as update method.
                                //
                                continue;
                            }
                        }
                        //
                        var     armUri      = new ARMUri(innerMethod);
                        Segment lastSegment = armUri.LastOrDefault();
                        if (lastSegment != null && lastSegment is ParentSegment)
                        {
                            ParentSegment resourceSegment = (ParentSegment)lastSegment;
                            if (resourceSegment.Name.EqualsIgnoreCase(fluentMethodGroup.LocalNameInPascalCase))
                            {
                                if (this.fluentMethodGroup.Level == 0)
                                {
                                    var subscriptionSegment  = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("subscriptions"));
                                    var resourceGroupSegment = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("resourceGroups"));

                                    if (subscriptionSegment == null && resourceGroupSegment == null && StandardFluentMethod.CanWrap(innerMethod))
                                    {
                                        return(new StandardFluentMethod(innerMethod, this.fluentMethodGroup));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }
예제 #14
0
        public static FluentMethodGroups InnerMethodGroupToFluentMethodGroups(CodeModelJvaf codeModel)
        {
            FluentMethodGroups innerMethodGroupToFluentMethodGroups = new FluentMethodGroups(codeModel);

            foreach (MethodGroupJvaf innerMethodGroup in codeModel.AllOperations)
            {
                List <FluentMethodGroup> fluentMGroupsInCurrentInnerMGroup = new List <FluentMethodGroup>();
                innerMethodGroupToFluentMethodGroups.Add(innerMethodGroup.Name, fluentMGroupsInCurrentInnerMGroup);

                foreach (MethodJvaf innerMethod in innerMethodGroup.Methods)
                {
                    var uri = new ARMUri(innerMethod);

                    if (String.IsNullOrEmpty(innerMethod.FluentUrl()))
                    {
                        // Skip empty Url e.g. listNextPage
                        //
                        continue;
                    }
                    else if (innerMethod.Name.ToLowerInvariant().StartsWith("begin"))
                    {
                        // Skip LRO begin methods
                        //
                        continue;
                    }
                    else
                    {
                        List <String> urlParts = GetPartsAfterProvider(innerMethod.FluentUrl());
                        if (urlParts.Any())
                        {
                            string providerNamespace = urlParts[0];
                            // skip provider namespace.
                            urlParts = urlParts.Skip(1).ToList();

                            FluentMethodGroup fluentMGroup = null;
                            if (urlParts.Count() == 1)
                            {
                                string possibleFMGName = urlParts[0];
                                //
                                fluentMGroup = new FluentMethodGroup(innerMethodGroupToFluentMethodGroups)
                                {
                                    LocalNameInPascalCase = $"{DeferFMGResolution}{possibleFMGName}"
                                };
                            }
                            else
                            {
                                fluentMGroup = FluentMethodGroup.ResolveFluentMethodGroup(innerMethodGroupToFluentMethodGroups, urlParts, innerMethod.HttpMethod);
                            }

                            Debug.Assert(fluentMGroup != null);
                            // Checks whether we already derived a method group with same name in the current "Operation group" (inner method group)
                            //
                            FluentMethodGroup matchedFluentMethodGroup = fluentMGroupsInCurrentInnerMGroup.FirstOrDefault(fmg => fmg.LocalNameInPascalCase.EqualsIgnoreCase(fluentMGroup.LocalNameInPascalCase));

                            if (matchedFluentMethodGroup != null)
                            {
                                matchedFluentMethodGroup.InnerMethods.Add(innerMethod);
                            }
                            else
                            {
                                fluentMGroup.InnerMethods.Add(innerMethod);
                                fluentMGroup.InnerMethodGroup = innerMethodGroup;
                                fluentMGroupsInCurrentInnerMGroup.Add(fluentMGroup);
                            }
                        }
                    }
                }
            }
            innerMethodGroupToFluentMethodGroups.ResolveDeferedFluentMethodGroups(codeModel);
            innerMethodGroupToFluentMethodGroups.LinkFluentMethodGroups();
            innerMethodGroupToFluentMethodGroups.InjectPlaceHolderFluentMethodGroups();
            innerMethodGroupToFluentMethodGroups.EnsureUniqueJavaInterfaceNameForFluentMethodGroup();
            innerMethodGroupToFluentMethodGroups.DeriveStandardFluentModelForMethodGroups();
            innerMethodGroupToFluentMethodGroups.EnsureUniqueJvaModelInterfaceName();
            innerMethodGroupToFluentMethodGroups.SpecializeFluentModels();

            return(innerMethodGroupToFluentMethodGroups);
        }
예제 #15
0
        public static FluentMethodGroups InnerMethodGroupToFluentMethodGroups(CodeModelJvaf codeModel)
        {
            IEnumerable <MethodGroupJv> allInnerMethodGroups = codeModel.AllOperations;
            //
            FluentMethodGroups fluentMethodGroups = new FluentMethodGroups(codeModel);

            //
            foreach (MethodGroupJvaf currentInnerMethodGroup in allInnerMethodGroups)
            {
                FluentMethodGroupList fluentMethodGroupsInCurrentInnerMethodGroup = new FluentMethodGroupList(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())
                            {
                                FluentMethodGroup 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 FluentMethodGroup(fluentMethodGroups: fluentMethodGroups,
                                                                              localName: DeferredFluentMethodGroupNamePrefix.AddPrefix(name));
                                }
                                else
                                {
                                    string methodGroupDefaultName = Utils.TrimInnerSuffix(currentInnerMethodGroup.Name.ToString());
                                    fluentMethodGroup = FluentMethodGroup.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"
                                //
                                FluentMethodGroup matchedFluentMethodGroup = fluentMethodGroupsInCurrentInnerMethodGroup.FindFluentMethodGroup(fluentMethodGroup.LocalNameInPascalCase);
                                if (matchedFluentMethodGroup != null)
                                {
                                    matchedFluentMethodGroup.AddInnerMethod(innerMethod);
                                }
                                else
                                {
                                    fluentMethodGroup.AddInnerMethod(innerMethod);
                                    fluentMethodGroupsInCurrentInnerMethodGroup.AddFluentMethodGroup(fluentMethodGroup);
                                }
                            }
                        }
                    }
                }
            }
            //
            fluentMethodGroups.ResolveDeferredFluentMethodGroups(codeModel);
            fluentMethodGroups.LinkFluentMethodGroups();
            fluentMethodGroups.InjectPlaceHolderFluentMethodGroups();
            fluentMethodGroups.DeriveStandardInnerModelForMethodGroups();
            fluentMethodGroups.PruneMethodGroups();
            fluentMethodGroups.Select(m => m.Value).SelectMany(fluentMethodGroupList => fluentMethodGroupList)
            .ForEach(fluentMethodGroup =>
            {
                fluentMethodGroup.JavaInterfaceName = fluentMethodGroup.LocalNameInPascalCase;
            });
            fluentMethodGroups.EnsureUniqueJvaModelInterfaceName();
            fluentMethodGroups.SpecializeFluentModels();
            //
            return(fluentMethodGroups);
        }