private void CheckGetByParameterizedParentSupport()
        {
            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 ParentSegment)
                    {
                        ParentSegment resourceSegment    = (ParentSegment)lastSegment;
                        var           requiredParameters = 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)
                            {
                                this.supportsGetByParameterizedParent = true;
                                this.getByParameterizedParentMethod   = new FluentMethod(true, innerMethod, this.fluentMethodGroup);
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                this.supportsGetByParameterizedParent = false;
                this.getByParameterizedParentMethod   = null;
            }
        }
 private StandardFluentMethod 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)
         {
             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)
                         {
                             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 && 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);
 }
Пример #4
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;
            }
        }
 private void CheckGetByResourceGroupSupport()
 {
     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 ParentSegment)
             {
                 ParentSegment resourceSegment    = (ParentSegment)lastSegment;
                 var           requiredParameters = 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)
                         {
                             this.supportsGetByResourceGroup = true;
                             this.getByResourceGroupMethod   = new FluentMethod(true, innerMethod, this.fluentMethodGroup);
                         }
                     }
                 }
             }
         }
     }
     else
     {
         this.supportsGetByResourceGroup = false;
         this.getByResourceGroupMethod   = null;
     }
 }
Пример #6
0
 private void CheckDeleteBySubscriptionSupport()
 {
     if (this.fluentMethodGroup.Level == 0)
     {
         foreach (MethodJvaf innerMethod in fluentMethodGroup.InnerMethods.Where(method => method.HttpMethod == HttpMethod.Delete))
         {
             var     armUri      = new ARMUri(innerMethod);
             Segment lastSegment = armUri.LastOrDefault();
             if (lastSegment != null && lastSegment is ParentSegment)
             {
                 ParentSegment resourceSegment    = (ParentSegment)lastSegment;
                 var           requiredParameters = RequiredParametersOfMethod(innerMethod);
                 if (resourceSegment.Name.EqualsIgnoreCase(fluentMethodGroup.LocalNameInPascalCase) && requiredParameters.Count() == 1)
                 {
                     var subscriptionSegment = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("subscriptions"));
                     if (subscriptionSegment != null)
                     {
                         bool hasResourceParm = requiredParameters.Any(p => p.SerializedName.EqualsIgnoreCase(resourceSegment.Parameter.SerializedName));
                         if (hasResourceParm)
                         {
                             this.supportsDeleteBySubscription = true;
                             this.deleteBySubscriptionMethod   = new StandardFluentMethod(innerMethod, this.fluentMethodGroup);
                         }
                     }
                 }
             }
         }
     }
     else
     {
         this.supportsDeleteBySubscription = false;
         this.deleteBySubscriptionMethod   = null;
     }
 }
Пример #7
0
 /// <summary>
 /// Checks can support "SupportsListBySubscription" interface
 /// </summary>
 private void CheckListBySubscriptionSupport()
 {
     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 = RequiredParametersOfMethod(innerMethod);
                 if (terminalSegment.Name.EqualsIgnoreCase(fluentMethodGroup.LocalNameInPascalCase) && requiredParameters.Count() == 0)
                 {
                     var subscriptionSegment = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("subscriptions"));
                     if (subscriptionSegment != null)
                     {
                         if (innerMethod.ReturnTypeResponseName.StartsWith("PagedList") ||
                             innerMethod.ReturnTypeResponseName.StartsWith("List"))
                         {
                             this.supportsListBySubscription = true;
                             this.listBySubscriptionMethod   = new FluentMethod(true, innerMethod, this.fluentMethodGroup);
                             break;
                         }
                     }
                 }
             }
         }
     }
     else
     {
         this.supportsListBySubscription = false;
         this.listBySubscriptionMethod   = 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 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;
     }
 }