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 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; } }
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; } }
private FluentMethod TryGetUpdateAsNestedChildMethod() { 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) { return(new FluentMethod(true, innerMethod, this.fluentMethodGroup)); } } } } } } return(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 StandardFluentMethod TryGetUpdateAsNestedChildMethod(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 updatable 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 && StandardFluentMethod.CanWrap(innerMethod)) { return(new StandardFluentMethod(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)) { IFluentMethodGroup 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; } }
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 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); }
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 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; } }
private void Init() { if (string.IsNullOrEmpty(this.rawUrl)) { return; } IEnumerable <string> parts = this.rawUrl.Split("/").Where(part => !string.IsNullOrEmpty(part)); // IEnumerator <string> itr = parts.GetEnumerator(); if (!itr.MoveNext()) { return; } // int pos = 0; // First Segment // if (itr.Current.StartsWith("{")) { string name = itr.Current.Trim(new char[] { '{', '}' }); this.Add(new PositionalSegment(name: name, position: pos) { Parameter = this.method.Parameters .OfType <ParameterJv>() .First(p => p.Location == Core.Model.ParameterLocation.Path && p.SerializedName.EqualsIgnoreCase(name)) }); } else { this.Add(new ParentSegment(name: itr.Current, position: pos)); } // // Intermediate segments // while (itr.MoveNext()) { pos++; // if (itr.Current.StartsWith("{")) { string name = itr.Current.Trim(new char[] { '{', '}' }); if (this.Last() is ParentSegment && ((ParentSegment)this.Last()).Parameter == null) { ParentSegment parentSegment = (ParentSegment)this.Last(); parentSegment.Parameter = this.method.Parameters .OfType <ParameterJv>() .First(p => p.Location == Core.Model.ParameterLocation.Path && p.SerializedName.EqualsIgnoreCase(name)); } else { this.Add(new PositionalSegment(name: name, position: pos) { Parameter = this.method.Parameters .OfType <ParameterJv>() .First(p => p.Location == Core.Model.ParameterLocation.Path && p.SerializedName.EqualsIgnoreCase(name)) }); } } else { if (this.Last() is ParentSegment) { ParentSegment parentSegment = (ParentSegment)this.Last(); if (parentSegment.Parameter == null) { this.RemoveAt(this.Count - 1); this.Add(new ReferenceSegment(name: parentSegment.Name, position: parentSegment.Position, refName: itr.Current)); } } this.Add(new ParentSegment(name: itr.Current, position: pos)); } } // Last segment special handling // if (this.Last() is ParentSegment) { ParentSegment parentSegment = (ParentSegment)this.Last(); if (parentSegment.Parameter == null) { this.RemoveAt(this.Count - 1); this.Add(new TerminalSegment(name: parentSegment.Name, position: parentSegment.Position)); } } }
public FluentModelParentRefMemberVariable(ParentSegment parentSegment) : base(variableName: parentSegment.Parameter.Name, fromParameter: parentSegment.Parameter) { this.ParentRefName = parentSegment.Name; }