/// <summary> /// Derive and return optional definition stages from the create member variables. /// </summary> protected List <FluentDefinitionOrUpdateStage> OptionalDefinitionStages(List <FluentDefinitionOrUpdateStage> initialStages) { if (this.optDefStages != null) { return(this.optDefStages); } this.optDefStages = new List <FluentDefinitionOrUpdateStage>(); if (!this.SupportsCreating) { return(this.optDefStages); } var dmvs = this.disambiguatedMemberVariables ?? throw new ArgumentNullException("dMemberVariables"); var payloadInnerModelVariable = this.CompositePayloadVariable; // Stages for setting optional properties of "create body payload" // if (payloadInnerModelVariable != null) { string payloadInnerModelVariableName = payloadInnerModelVariable.VariableName; CompositeTypeJvaf payloadType = (CompositeTypeJvaf)payloadInnerModelVariable.FromParameter.ClientType; var payloadOptinalProperties = payloadType .ComposedProperties .Where(p => !p.IsReadOnly && !p.IsRequired) .Where(p => !propertiesOfPayloadToSkip.Contains(p.Name.ToString(), StringComparer.OrdinalIgnoreCase)) .OrderBy(p => p.Name.ToLowerInvariant()); FluentDefinitionOrUpdateStage creatableStage = new FluentDefinitionOrUpdateStage(this.resourceName, "WithCreate"); foreach (Property pro in payloadOptinalProperties) { string methodName = $"with{pro.Name.ToPascalCase()}"; string parameterName = pro.Name; string methodParameterDecl = $"{pro.ModelTypeName} {parameterName}"; FluentDefinitionOrUpdateStageMethod method = new FluentDefinitionOrUpdateStageMethod(methodName, methodParameterDecl, pro.ModelType as IModelTypeJv) { CommentFor = new Dictionary <string, string> { { parameterName, pro.Documentation } }, Body = $"{(dmvs.MemeberVariablesForCreate[payloadInnerModelVariableName]).VariableAccessor}.{methodName}({parameterName});" }; string interfaceName = $"With{pro.Name.ToPascalCase()}"; FluentDefinitionOrUpdateStage stage = new FluentDefinitionOrUpdateStage(this.resourceName, interfaceName); this.optDefStages.Add(stage); stage.Methods.Add(method); stage.Methods.ForEach(m => { m.NextStage = creatableStage; }); } } return(this.optDefStages); }
/// <summary> /// Prepare and return the initial defintion stages that exposes methods to specify the ancestors of the 'Non-Groupable TopLevel Resource'. /// </summary> /// <param name="parentRefMemberVariables">the member vaiables that corrosonds to ancestors of the resource</param> /// <returns></returns> private List <FluentDefinitionOrUpdateStage> FirstDefintionStages(IOrderedEnumerable <FluentModelParentRefMemberVariable> parentRefMemberVariables) { var dmvs = this.DisambiguatedMemberVariables ?? throw new ArgumentNullException("dMemberVariables"); List <FluentDefinitionOrUpdateStage> initalStages = new List <FluentDefinitionOrUpdateStage>(); FluentDefinitionOrUpdateStage currentStage = null; foreach (FluentModelParentRefMemberVariable memberVariable in parentRefMemberVariables) { if (memberVariable.ParentRefName.EqualsIgnoreCase(this.FluentMethodGroup.LocalNameInPascalCase)) { // Exclude self from parent ref member variables continue; } else { string methodName = $"with{memberVariable.FromParameter.Name.ToPascalCase()}"; string parameterName = memberVariable.VariableName; string methodParameterDecl = $"{memberVariable.VariableTypeName} {parameterName}"; FluentDefinitionOrUpdateStageMethod method = new FluentDefinitionOrUpdateStageMethod(methodName, methodParameterDecl, memberVariable.VariableType) { CommentFor = new Dictionary <string, string> { { parameterName, memberVariable.FromParameter.Documentation } }, Body = $"{(dmvs.MemeberVariablesForCreate[memberVariable.VariableName]).VariableAccessor} = {parameterName};" }; string interfaceName = $"With{memberVariable.FromParameter.Name.ToPascalCase()}"; FluentDefinitionOrUpdateStage nextStage = new FluentDefinitionOrUpdateStage(this.resourceName, interfaceName); // initalStages.Add(nextStage); // nextStage.Methods.Add(method); // if (currentStage != null) { currentStage.Methods.ForEach(m => { m.NextStage = nextStage; }); } currentStage = nextStage; } } return(initalStages); }
/// <summary> /// Derive and return required definition stages from the create member variables. /// </summary> protected List <FluentDefinitionOrUpdateStage> RequiredDefinitionStages(List <FluentDefinitionOrUpdateStage> initialStages) { if (this.reqDefStages != null) { return(this.reqDefStages); } this.reqDefStages = new List <FluentDefinitionOrUpdateStage>(); if (!this.SupportsCreating) { return(this.reqDefStages); } var dmvs = this.disambiguatedMemberVariables ?? throw new ArgumentNullException("dMemberVariables"); FluentDefinitionOrUpdateStage currentStage = null; if (initialStages != null) { this.reqDefStages.AddRange(initialStages); currentStage = this.reqDefStages.LastOrDefault(); } // 1. stages for setting create arguments except "create body payload" // foreach (var memberVariable in this.NotParentRefNotCompositePayloadButPositionalAndOtherMemberVariables) { string methodName = $"with{memberVariable.FromParameter.Name.ToPascalCase()}"; string parameterName = memberVariable.VariableName; string methodParameterDecl = $"{memberVariable.VariableTypeName} {parameterName}"; FluentDefinitionOrUpdateStageMethod method = new FluentDefinitionOrUpdateStageMethod(methodName, methodParameterDecl, memberVariable.VariableType) { CommentFor = new Dictionary <string, string> { { parameterName, memberVariable.FromParameter.Documentation } }, Body = $"{(dmvs.MemeberVariablesForCreate[memberVariable.VariableName]).VariableAccessor} = {parameterName};" }; string interfaceName = $"With{memberVariable.FromParameter.Name.ToPascalCase()}"; FluentDefinitionOrUpdateStage nextStage = new FluentDefinitionOrUpdateStage(this.resourceName, interfaceName); this.reqDefStages.Add(nextStage); nextStage.Methods.Add(method); // if (currentStage != null) { currentStage.Methods.ForEach(m => { m.NextStage = nextStage; }); } currentStage = nextStage; } // 2. stages for setting required properties of "create body composite payload" // var compositePayloadVariable = this.CompositePayloadVariable; if (compositePayloadVariable != null) { string payloadInnerModelVariableName = compositePayloadVariable.VariableName; CompositeTypeJvaf payloadType = (CompositeTypeJvaf)compositePayloadVariable.FromParameter.ClientType; var payloadRequiredProperties = payloadType.ComposedProperties .Where(p => !p.IsReadOnly && p.IsRequired) .Where(p => !propertiesOfPayloadToSkip.Contains(p.Name.ToString(), StringComparer.OrdinalIgnoreCase)) .OrderBy(p => p.Name.ToLowerInvariant()); foreach (Property pro in payloadRequiredProperties) { string methodName = $"with{pro.Name.ToPascalCase()}"; string parameterName = pro.Name; string methodParameterDecl = $"{pro.ModelTypeName} {parameterName}"; FluentDefinitionOrUpdateStageMethod method = new FluentDefinitionOrUpdateStageMethod(methodName, methodParameterDecl, pro.ModelType as IModelTypeJv) { CommentFor = new Dictionary <string, string> { { parameterName, pro.Documentation } }, Body = $"{(dmvs.MemeberVariablesForCreate[payloadInnerModelVariableName]).VariableAccessor}.{methodName}({parameterName});" }; string interfaceName = $"With{pro.Name.ToPascalCase()}"; FluentDefinitionOrUpdateStage nextStage = new FluentDefinitionOrUpdateStage(this.resourceName, interfaceName); this.reqDefStages.Add(nextStage); nextStage.Methods.Add(method); if (currentStage != null) { currentStage.Methods.ForEach(m => { m.NextStage = nextStage; }); } currentStage = nextStage; } } FluentDefinitionOrUpdateStage creatableStage = new FluentDefinitionOrUpdateStage(this.resourceName, "WithCreate"); if (currentStage != null) { currentStage.Methods.ForEach(m => { m.NextStage = creatableStage; }); } return(this.reqDefStages); }
/// <summary> /// Create and return "Update Stages" from the member variables. /// </summary> public virtual List <FluentDefinitionOrUpdateStage> UpdateStages() { if (this.updateStages != null) { return(this.updateStages); } this.updateStages = new List <FluentDefinitionOrUpdateStage>(); if (!this.SupportsUpdating) { return(this.updateStages); } var dmvs = this.disambiguatedMemberVariables ?? throw new ArgumentNullException("dMemberVariables"); FluentDefinitionOrUpdateStage updateGrouping = new FluentDefinitionOrUpdateStage(this.resourceName, "Update"); // During resource update changing parent ref properties and other path properties are not allowed // IEnumerable <FluentModelMemberVariable> nonExpandableUpdatableMemberVariables = this.NotParentRefNotPositionalPathAndNotCompositePayloadMemberVariables; foreach (var memberVariable in nonExpandableUpdatableMemberVariables) { string methodName = $"with{memberVariable.FromParameter.Name.ToPascalCase()}"; string parameterName = memberVariable.VariableName; string methodParameterDecl = $"{memberVariable.VariableTypeName} {parameterName}"; FluentDefinitionOrUpdateStageMethod method = new FluentDefinitionOrUpdateStageMethod(methodName, methodParameterDecl, memberVariable.VariableType) { CommentFor = new Dictionary <string, string> { { parameterName, memberVariable.FromParameter.Documentation } }, Body = $"{(dmvs.MemeberVariablesForUpdate[memberVariable.VariableName]).VariableAccessor} = {parameterName};" }; string interfaceName = $"With{memberVariable.FromParameter.Name.ToPascalCase()}"; FluentDefinitionOrUpdateStage stage = new FluentDefinitionOrUpdateStage(this.resourceName, interfaceName); this.updateStages.Add(stage); stage.Methods.Add(method); stage.Methods.ForEach(m => { m.NextStage = updateGrouping; }); } var payloadInnerModelVariable = this.CompositePayloadVariable; if (payloadInnerModelVariable != null) { string payloadInnerModelVariableName = payloadInnerModelVariable.VariableName; CompositeTypeJvaf payloadType = (CompositeTypeJvaf)payloadInnerModelVariable.FromParameter.ClientType; var payloadOptionalProperties = payloadType .ComposedProperties .Where(p => !p.IsReadOnly && !p.IsRequired) .Where(p => !propertiesOfPayloadToSkip.Contains(p.Name.ToString(), StringComparer.OrdinalIgnoreCase)) .OrderBy(p => p.Name.ToLowerInvariant()); foreach (Property pro in payloadOptionalProperties) { string methodName = $"with{pro.Name.ToPascalCase()}"; string parameterName = pro.Name; string methodParameterDecl = $"{pro.ModelTypeName} {parameterName}"; FluentDefinitionOrUpdateStageMethod method = new FluentDefinitionOrUpdateStageMethod(methodName, methodParameterDecl, pro.ModelType as IModelTypeJv) { CommentFor = new Dictionary <string, string> { { parameterName, pro.Documentation } }, Body = $"{(dmvs.MemeberVariablesForUpdate[payloadInnerModelVariableName]).VariableAccessor}.{methodName}({parameterName});" }; string interfaceName = $"With{pro.Name.ToPascalCase()}"; FluentDefinitionOrUpdateStage stage = new FluentDefinitionOrUpdateStage(this.resourceName, interfaceName); this.updateStages.Add(stage); stage.Methods.Add(method); stage.Methods.ForEach(m => { m.NextStage = updateGrouping; }); } } return(this.updateStages); }