public ResourceGetDescription(IFluentMethodGroup fluentMethodGroup) { this.FluentMethodGroup = fluentMethodGroup; this.getByResourceGroup = new GetByResourceGroupDescription(fluentMethodGroup, this.GetInnerAsyncFuncFactory); this.getBySubscription = new GetBySubscriptionDescription(fluentMethodGroup, this.GetInnerAsyncFuncFactory); this.getByImmediateParent = new GetByImmediateParentDescription(fluentMethodGroup, this.GetInnerAsyncFuncFactory); this.getByParameterizedParent = new GetByParameterizedParentDescription(fluentMethodGroup, this.GetInnerAsyncFuncFactory); }
public StandardFluentMethod(MethodJvaf innerMethod, IFluentMethodGroup methodGroup) { if (!CanWrap(innerMethod)) { throw new ArgumentException($"StandardFluentMethod can wrap only inner methods that return wrappable return type, received inner method '{innerMethod.ReturnTypeResponseName} {innerMethod.Name}(..)'"); } // this.InnerMethod = innerMethod; this.FluentMethodGroup = methodGroup; }
/// <summary> /// Creates a proxy Fluent Method Group. /// </summary> /// <param name="subjectFluentMethodGroup">the first group that become either subject or gets generalized depending on the generalizeSubject parameter</param> /// <param name="secondaryFluentMethodGroup">the second group which is always gets generalized</param> /// <param name="generalizeSubject">decides whether the subject fluent method group also needs to be generalized</param> /// <returns>proxy fluent method group</returns> public static ProxyFluentMethodGroup Create(IFluentMethodGroup subjectFluentMethodGroup, IFluentMethodGroup secondaryFluentMethodGroup, bool generalizeSubject) { ProxyFluentMethodGroup proxy = Init(subjectFluentMethodGroup); // if (generalizeSubject) { proxy.subjectFluentMethodGroup = null; // No subject, means use nullObjects // -- Generalize the subject Fluent Method Group -- GeneralizedOutput subjectGeneralized = GeneralizedOutput.Generalize(subjectFluentMethodGroup); // if (!subjectGeneralized.IsEmpty) { proxy.generalizedOutputs.Add(subjectGeneralized); } foreach (var output in subjectGeneralized.GeneralizedOutputs.Where(gop => !gop.IsEmpty)) { proxy.generalizedOutputs.Add(output); } // proxy.innerMethods.AddRange(subjectFluentMethodGroup.InnerMethods); proxy.childFluentMethodGroups.AddRange(subjectFluentMethodGroup.ChildFluentMethodGroups); } else { proxy.subjectFluentMethodGroup = subjectFluentMethodGroup; // foreach (var output in subjectFluentMethodGroup.GeneralizedOutputs.Where(gop => !gop.IsEmpty)) { proxy.generalizedOutputs.Add(output); } proxy.innerMethods.AddRange(subjectFluentMethodGroup.InnerMethods); proxy.childFluentMethodGroups.AddRange(subjectFluentMethodGroup.ChildFluentMethodGroups); } // // -- Generalize the secondary Fluent Method Group -- GeneralizedOutput secondaryGeneralized = GeneralizedOutput.Generalize(secondaryFluentMethodGroup); // if (!secondaryGeneralized.IsEmpty) { proxy.generalizedOutputs.Add(secondaryGeneralized); } foreach (var output in secondaryGeneralized.GeneralizedOutputs.Where(gop => !gop.IsEmpty)) { proxy.generalizedOutputs.Add(output); } // proxy.innerMethods.AddRange(secondaryFluentMethodGroup.InnerMethods); // proxy.childFluentMethodGroups.AddRange(secondaryFluentMethodGroup.ChildFluentMethodGroups); // return(proxy); }
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; } }
/// <summary> /// Creates a proxy fluent method group for the given fluent method group. /// </summary> /// <param name="subjectFluentMethodGroup">the subject for which proxy needs to be created</param> /// <returns>proxy fluent method group</returns> public static ProxyFluentMethodGroup Create(IFluentMethodGroup subjectFluentMethodGroup) { ProxyFluentMethodGroup proxy = Init(subjectFluentMethodGroup); // proxy.subjectFluentMethodGroup = subjectFluentMethodGroup; // foreach (var output in subjectFluentMethodGroup.GeneralizedOutputs.Where(gop => !gop.IsEmpty)) { proxy.generalizedOutputs.Add(output); } return(proxy); }
private static ProxyFluentMethodGroup Init(IFluentMethodGroup fluentMethodGroup) { return(new ProxyFluentMethodGroup { // The "FluentMethodGroups" and "ManagerName" are golbals, same across all fluent method groups. FluentMethodGroups = fluentMethodGroup.FluentMethodGroups, ManagerName = fluentMethodGroup.ManagerName, // The "InnerMethodGroup" is same across all fluent method groups belongs to the same inner method group // an instance of proxy always works with fluent method groups in the same inner method group. InnerMethodGroup = fluentMethodGroup.InnerMethodGroup, // generalizedOutputs = new List <GeneralizedOutput>(), }); }
protected ClientFluentMethodGroupImpl(IFluentMethodGroup fluentMethodGroup) { if (fluentMethodGroup.Type != MethodGroupType.ActionsOnly) { if (fluentMethodGroup.StandardFluentModel == null) { throw new ArgumentNullException($"Fluent method group type is '{fluentMethodGroup.Type}' but standard model is null."); } this.model = fluentMethodGroup.StandardFluentModel; } else { this.model = null; // i.e. FMG exposes only actions and child accessors & does not wrap a model } this.Interface = fluentMethodGroup; }
/// <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 CheckDeleteByImmediateParentSupport() { if (this.fluentMethodGroup.Level > 0) { foreach (MethodJvaf innerMethod in fluentMethodGroup.InnerMethods.Where(method => method.HttpMethod == HttpMethod.Delete)) { IFluentMethodGroup 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.supportsDeleteByImmediateParent = true; this.deleteByImmediateParentMethod = new StandardFluentMethod(innerMethod, this.fluentMethodGroup); break; } } } } } } } else { this.supportsDeleteByImmediateParent = false; this.deleteByImmediateParentMethod = null; } }
public static StandardMethodsInfo StandardMethodsInfo(this IFluentMethodGroup fluentMethodGroup) { StandardMethodsInfo standardMethods = new StandardMethodsInfo(); // HashSet <string> knownMethodNames = new HashSet <string>(); if (fluentMethodGroup.ResourceCreateDescription.SupportsCreating) { standardMethods.InnerMethodNames.Add(fluentMethodGroup.ResourceCreateDescription.CreateMethod.Name.ToLowerInvariant()); } if (fluentMethodGroup.ResourceUpdateDescription.SupportsUpdating) { standardMethods.InnerMethodNames.Add(fluentMethodGroup.ResourceUpdateDescription.UpdateMethod.Name.ToLowerInvariant()); // StandardFluentMethod updateMethod = fluentMethodGroup.ResourceUpdateDescription.UpdateMethod; if (updateMethod.InnerMethod.HttpMethod == HttpMethod.Put) { // If PUT based update is supported then skip any PATCH based update method // being treated as "Other methods". // var patchUpdateMethod = fluentMethodGroup.InnerMethods .Where(m => m.HttpMethod == HttpMethod.Patch) .Where(m => m.Url.EqualsIgnoreCase(updateMethod.InnerMethod.Url)) .FirstOrDefault(); if (patchUpdateMethod != null) { standardMethods.InnerMethodNames.Add(patchUpdateMethod.Name.ToLowerInvariant()); } } } if (fluentMethodGroup.ResourceListingDescription.SupportsListByImmediateParent) { standardMethods.InnerMethodNames.Add(fluentMethodGroup.ResourceListingDescription.ListByImmediateParentMethod.Name.ToLowerInvariant()); } if (fluentMethodGroup.ResourceListingDescription.SupportsListByResourceGroup) { standardMethods.InnerMethodNames.Add(fluentMethodGroup.ResourceListingDescription.ListByResourceGroupMethod.Name.ToLowerInvariant()); standardMethods.FluentMethodNames.Add("listByResourceGroup".ToLowerInvariant()); } if (fluentMethodGroup.ResourceListingDescription.SupportsListBySubscription) { standardMethods.InnerMethodNames.Add(fluentMethodGroup.ResourceListingDescription.ListBySubscriptionMethod.Name.ToLowerInvariant()); standardMethods.FluentMethodNames.Add("list".ToLowerInvariant()); } if (fluentMethodGroup.ResourceGetDescription.SupportsGetByImmediateParent) { standardMethods.InnerMethodNames.Add(fluentMethodGroup.ResourceGetDescription.GetByImmediateParentMethod.Name.ToLowerInvariant()); } if (fluentMethodGroup.ResourceGetDescription.SupportsGetByResourceGroup) { standardMethods.InnerMethodNames.Add(fluentMethodGroup.ResourceGetDescription.GetByResourceGroupMethod.Name.ToLowerInvariant()); standardMethods.FluentMethodNames.Add("getByResourceGroup".ToLowerInvariant()); } if (fluentMethodGroup.ResourceDeleteDescription.SupportsDeleteByImmediateParent) { standardMethods.InnerMethodNames.Add(fluentMethodGroup.ResourceDeleteDescription.DeleteByImmediateParentMethod.Name.ToLowerInvariant()); } if (fluentMethodGroup.ResourceDeleteDescription.SupportsDeleteByResourceGroup) { standardMethods.InnerMethodNames.Add(fluentMethodGroup.ResourceDeleteDescription.DeleteByResourceGroupMethod.Name.ToLowerInvariant()); standardMethods.FluentMethodNames.Add("deleteByResourceGroup".ToLowerInvariant()); standardMethods.FluentMethodNames.Add("deleteByIds".ToLowerInvariant()); } // return(standardMethods); }
public GetByParameterizedParentDescription(IFluentMethodGroup fluentMethodGroup, IGetInnerAsyncFuncFactory getInnerAsyncFuncFactory) { this.FluentMethodGroup = fluentMethodGroup; this.getInnerAsyncFuncFactory = getInnerAsyncFuncFactory; }
public GetByResourceGroupDescription(IFluentMethodGroup fluentMethodGroup, IGetInnerAsyncFuncFactory getInnerAsyncFuncFactory) { this.FluentMethodGroup = fluentMethodGroup; this.getInnerAsyncFuncFactory = getInnerAsyncFuncFactory; }
private GeneralizedOutput(IFluentMethodGroup fluentMethodGroup) { this.fluentMethodGroup = fluentMethodGroup; }
public GetByImmediateParentDescription(IFluentMethodGroup fluentMethodGroup, IGetInnerAsyncFuncFactory getInnerAsyncFuncFactory) { this.FluentMethodGroup = fluentMethodGroup; this.getInnerAsyncFuncFactory = getInnerAsyncFuncFactory; }
public ClientFluentNonGroupableTopLevelMethodGroupImpl(IFluentMethodGroup methodGroup) : base(methodGroup) { }
public ClientFluentMethodGroupInterface(IFluentMethodGroup fluentMethodGroup) { this.fluentMethodGroup = fluentMethodGroup; }
public ClientFluentActionsOnlyMethodGroupImpl(IFluentMethodGroup fluentMethodGroup) : base(fluentMethodGroup) { }
public FluentMethodGroupInterfaceModel(IFluentMethodGroup fluentMethodGroup) { this.fluentMethodGroup = fluentMethodGroup; }
public NestedFluentMethodGroupImpl(IFluentMethodGroup methodGroup) : base(methodGroup) { }
public void AddToChildFluentMethodGroup(IFluentMethodGroup fluentMethodGroup) { this.childFluentMethodGroups.Add(fluentMethodGroup); }
public void SetParentFluentMethodGroup(IFluentMethodGroup fluentMethodGroup) { this.ParentFluentMethodGroup = fluentMethodGroup; }
public OtherMethod(MethodJvaf innerMethod, IFluentMethodGroup methodGroup) { this.InnerMethod = innerMethod; this.FluentMethodGroup = methodGroup; }
public static GeneralizedOutput Generalize(IFluentMethodGroup fluentMethodGroup) { GeneralizedOutput generalizedOutput = new GeneralizedOutput(fluentMethodGroup); return(generalizedOutput); }
// TODO: anuchan: expand type to have details of primtive type it represents. public DictionaryModel(DictionaryTypeJv rawModel, IFluentMethodGroup fluentMethodGroup) { this.RawModel = rawModel; this.fluentMethodGroup = fluentMethodGroup; }
public ActionOrChildAccessorOnlyMethodGroupImpl(IFluentMethodGroup fluentMethodGroup) : base(fluentMethodGroup) { }
/// <summary> /// Prune the "Segment Fluent Method Group" in this list to produce a "Fluent Method Group". /// </summary> /// <returns>Fluent Method Group</returns> public IFluentMethodGroup Prune() { var localGroups = this; if (localGroups.Count == 0) { return(null); } else { IFluentMethodGroup prunedGroup = ProxyFluentMethodGroup.Create(localGroups.First()); foreach (ISegmentFluentMethodGroup currentGroup in localGroups.Skip(1)) { if (prunedGroup.StandardFluentModel == null) { if (currentGroup.StandardFluentModel == null) { // If both doesn't have standard model then create a proxy by generalizing both // prunedGroup = ProxyFluentMethodGroup.Create(prunedGroup, currentGroup, true); } else { if (prunedGroup.GeneralizedOutputs.Select(go => go.DefineFunc).Any(d => d.IsDefineSupported)) { prunedGroup = ProxyFluentMethodGroup.Create(prunedGroup, currentGroup, true); } else { // If the current one have a standard model then make it the subject and generalize the pruned one // prunedGroup = ProxyFluentMethodGroup.Create(currentGroup, prunedGroup, false); } } } else { if (prunedGroup.LocalNameInPascalCase.Equals(this.InnerMethodGroupName, StringComparison.OrdinalIgnoreCase) && currentGroup.LocalNameInPascalCase.Equals(this.InnerMethodGroupName, StringComparison.OrdinalIgnoreCase)) { // If both has standard model and both local names matches with the inner method group name then // create a proxy by generalizing both. // prunedGroup = ProxyFluentMethodGroup.Create(prunedGroup, currentGroup, true); } else if (!prunedGroup.LocalNameInPascalCase.Equals(this.InnerMethodGroupName, StringComparison.OrdinalIgnoreCase) && !currentGroup.LocalNameInPascalCase.Equals(this.InnerMethodGroupName, StringComparison.OrdinalIgnoreCase)) { // If both has standard model and both local names doesn't matches with the inner method group name then // create a proxy by generalizing both. // prunedGroup = ProxyFluentMethodGroup.Create(prunedGroup, currentGroup, true); } else if (prunedGroup.LocalNameInPascalCase.Equals(this.InnerMethodGroupName, StringComparison.OrdinalIgnoreCase)) { // If both has standard models but only the local name of pruned matches with the inner method // group name then create a proxy with pruned as subject and current one generalized. // prunedGroup = ProxyFluentMethodGroup.Create(prunedGroup, currentGroup, false); } else { // If both has standard models but only the local name of current matches with the inner method // group name then create a proxy with current as subject and pruned one generalized. // prunedGroup = ProxyFluentMethodGroup.Create(currentGroup, prunedGroup, false); } } } this.PrunedMethodGroup = prunedGroup; return(prunedGroup); } }
public ClientFluentNestedMethodGroupImpl(IFluentMethodGroup methodGroup) : base(methodGroup) { }
public GroupableFluentMethodGroupImpl(IFluentMethodGroup methodGroup) : base(methodGroup) { }
public ClientFluentGroupableMethodGroupImpl(IFluentMethodGroup methodGroup) : base(methodGroup) { }