/// <summary> /// Creates the CodeDOM for a method to insert a record into a table using transacted logic. /// </summary> /// <param name="tableSchema">A description of the table.</param> public UpdateExMethod(TableSchema tableSchema) { // This shreds the list of parameters up into a metadata stucture that is helpful in extracting ordinary parameters // from those that need to be found in other tables using external identifiers. UpdateExParameterMatrix updateParameterMatrix = new UpdateExParameterMatrix(tableSchema); // [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] // public void UpdateObjectEx(string configurationId, object description, object externalId, object name, global::System.Guid objectId, object typeCode) // { this.CustomAttributes.AddRange(new CodeCustomAttributesForMethods()); this.Attributes = MemberAttributes.Public | MemberAttributes.Final; this.Name = string.Format("Update{0}Ex", tableSchema.Name); foreach (KeyValuePair <string, ExternalParameterItem> parameterPair in updateParameterMatrix.ExternalParameterItems) { this.Parameters.Add(parameterPair.Value.CodeParameterDeclarationExpression); } // base.Channel.UpdateObjectEx(configurationId, description, externalId, name, objectId, typeCode); List <CodeExpression> arguments = new List <CodeExpression>(); foreach (KeyValuePair <string, ExternalParameterItem> parameterPair in updateParameterMatrix.ExternalParameterItems) { arguments.Add(new CodeArgumentReferenceExpression(parameterPair.Value.Name)); } this.Statements.Add(new CodeMethodInvokeExpression(new CodePropertyReferenceExpression(new CodeBaseReferenceExpression(), "Channel"), this.Name, arguments.ToArray())); // } }
/// <summary> /// Creates a method that loads records into the database from an external source. /// </summary> /// <param name="tableSchema">The schema used to describe the table.</param> public UpdateMethod(TableSchema tableSchema) { // This shreds the list of parameters up into a metadata stucture that is helpful in extracting ordinary parameters // from those that need to be found in other tables using external identifiers. UpdateExParameterMatrix updateParameterMatrix = new UpdateExParameterMatrix(tableSchema); // This collects a distinct list of data types that are added to the contract. SortedList <string, Type> knownTypes = new SortedList <string, Type>(); foreach (KeyValuePair <string, ExternalParameterItem> externalParameterPair in updateParameterMatrix.ExternalParameterItems) { if (externalParameterPair.Value.DeclaredDataType == typeof(Object)) { if (!knownTypes.ContainsKey(typeof(DBNull).Name)) { knownTypes.Add(typeof(DBNull).Name, typeof(DBNull)); } } if (externalParameterPair.Value.ActualDataType != externalParameterPair.Value.DeclaredDataType) { if (!externalParameterPair.Value.ActualDataType.IsPrimitive) { if (!knownTypes.ContainsKey(externalParameterPair.Value.ActualDataType.Name)) { knownTypes.Add(externalParameterPair.Value.ActualDataType.Name, externalParameterPair.Value.ActualDataType); } } } } // public void CreateEmployee(int age, string configurationId, string departmentId, string employeeId, string marriageCode) { // { string actionUri = String.Format("http://tempuri.org/I{0}/Update{1}", tableSchema.DataModel.Name, tableSchema.Name); string actionReplyUri = String.Format("http://tempuri.org/I{0}/Update{1}Response", tableSchema.DataModel.Name, tableSchema.Name); this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(OperationContractAttribute)), new CodeAttributeArgument("Action", new CodePrimitiveExpression(actionUri)), new CodeAttributeArgument("ReplyAction", new CodePrimitiveExpression(actionReplyUri)))); this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(TransactionFlowAttribute)), new CodeAttributeArgument(new CodePropertyReferenceExpression(new CodeGlobalTypeReferenceExpression(typeof(TransactionFlowOption)), "Allowed")))); foreach (KeyValuePair <string, Type> knownTypePair in knownTypes) { this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(ServiceKnownTypeAttribute)), new CodeAttributeArgument(new CodeTypeOfExpression(new CodeGlobalTypeReference(knownTypePair.Value))))); } this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(FaultContractAttribute)), new CodeAttributeArgument(new CodeTypeOfExpression(new CodeGlobalTypeReference(typeof(RecordNotFoundFault)))))); this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(FaultContractAttribute)), new CodeAttributeArgument(new CodeTypeOfExpression(new CodeGlobalTypeReference(typeof(IndexNotFoundFault)))))); this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(FaultContractAttribute)), new CodeAttributeArgument(new CodeTypeOfExpression(new CodeGlobalTypeReference(typeof(ArgumentFault)))))); this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(FaultContractAttribute)), new CodeAttributeArgument(new CodeTypeOfExpression(new CodeGlobalTypeReference(typeof(FormatFault)))))); this.CustomAttributes.Add( new CodeAttributeDeclaration( new CodeGlobalTypeReference(typeof(FaultContractAttribute)), new CodeAttributeArgument(new CodeTypeOfExpression(new CodeGlobalTypeReference(typeof(TenantNotLoadedFault)))))); this.Attributes = MemberAttributes.Public | MemberAttributes.Abstract; this.Attributes = MemberAttributes.Public | MemberAttributes.Abstract; this.Attributes = MemberAttributes.Public | MemberAttributes.Final; this.Name = String.Format("Update{0}", tableSchema.Name); foreach (KeyValuePair <string, ExternalParameterItem> parameterPair in updateParameterMatrix.ExternalParameterItems) { this.Parameters.Add(parameterPair.Value.CodeParameterDeclarationExpression); } }
/// <summary> /// Creates a method that loads records into the database from an external source. /// </summary> /// <param name="tableSchema">The schema used to describe the table.</param> public UpdateExMethod(TableSchema tableSchema) { // This shreds the list of parameters up into a metadata stucture that is helpful in extracting ordinary parameters // from those that need to be found in other tables using external identifiers. UpdateExParameterMatrix updateParameterMatrix = new UpdateExParameterMatrix(tableSchema); // /// <summary> // /// Loads a record into the Department table from an external source. // /// </summary> // /// <param name="configurationId">Selects a configuration of unique indices used to resolve external identifiers.</param> // /// <param name="employeeKey">An optional unique key for the parent Employee record.</param> // /// <param name="managerKey">An optional unique key for the parent Manager record.</param> this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement(string.Format("Loads a record into the Department table from an external source.", tableSchema.Name), true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); foreach (KeyValuePair <string, ExternalParameterItem> parameterPair in updateParameterMatrix.ExternalParameterItems) { this.Comments.Add(new CodeCommentStatement(string.Format("<param name=\"{0}\">{1}</param>", parameterPair.Value.Name, parameterPair.Value.Description), true)); } // This collects a distinct list of data types that are added to the contract. SortedList <string, Type> knownTypes = new SortedList <string, Type>(); foreach (KeyValuePair <string, ExternalParameterItem> externalParameterPair in updateParameterMatrix.ExternalParameterItems) { if (externalParameterPair.Value.DeclaredDataType == typeof(System.Object)) { if (!knownTypes.ContainsKey(typeof(System.DBNull).Name)) { knownTypes.Add(typeof(System.DBNull).Name, typeof(System.DBNull)); } } if (externalParameterPair.Value.ActualDataType != externalParameterPair.Value.DeclaredDataType) { if (!externalParameterPair.Value.ActualDataType.IsPrimitive) { if (!knownTypes.ContainsKey(externalParameterPair.Value.ActualDataType.Name)) { knownTypes.Add(externalParameterPair.Value.ActualDataType.Name, externalParameterPair.Value.ActualDataType); } } } } // public void CreateEmployee(int age, string configurationId, string departmentId, string employeeId, string marriageCode) { // { string actionUri = string.Format("http://tempuri.org/I{0}/Update{1}Ex", tableSchema.DataModel.Name, tableSchema.Name); string actionReplyUri = string.Format("http://tempuri.org/I{0}/Update{1}ExResponse", tableSchema.DataModel.Name, tableSchema.Name); this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(System.ServiceModel.OperationContractAttribute)), new CodeAttributeArgument("Action", new CodePrimitiveExpression(actionUri)), new CodeAttributeArgument("ReplyAction", new CodePrimitiveExpression(actionReplyUri)))); this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(System.ServiceModel.TransactionFlowAttribute)), new CodeAttributeArgument(new CodePropertyReferenceExpression(new CodeGlobalTypeReferenceExpression(typeof(System.ServiceModel.TransactionFlowOption)), "Allowed")))); foreach (KeyValuePair <string, Type> knownTypePair in knownTypes) { this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(System.ServiceModel.ServiceKnownTypeAttribute)), new CodeAttributeArgument(new CodeTypeOfExpression(new CodeGlobalTypeReference(knownTypePair.Value))))); } this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(System.ServiceModel.FaultContractAttribute)), new CodeAttributeArgument(new CodeTypeOfExpression(new CodeGlobalTypeReference(typeof(RecordNotFoundFault)))))); this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(System.ServiceModel.FaultContractAttribute)), new CodeAttributeArgument(new CodeTypeOfExpression(new CodeGlobalTypeReference(typeof(IndexNotFoundFault)))))); this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(System.ServiceModel.FaultContractAttribute)), new CodeAttributeArgument(new CodeTypeOfExpression(new CodeGlobalTypeReference(typeof(ArgumentFault)))))); this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(System.ServiceModel.FaultContractAttribute)), new CodeAttributeArgument(new CodeTypeOfExpression(new CodeGlobalTypeReference(typeof(FormatFault)))))); this.Attributes = MemberAttributes.Public | MemberAttributes.Abstract; this.Attributes = MemberAttributes.Public | MemberAttributes.Final; this.Name = string.Format("Update{0}Ex", tableSchema.Name); foreach (KeyValuePair <string, ExternalParameterItem> parameterPair in updateParameterMatrix.ExternalParameterItems) { this.Parameters.Add(parameterPair.Value.CodeParameterDeclarationExpression); } }
/// <summary> /// Creates a method that loads records into the database from an external source. /// </summary> /// <param name="tableSchema">The schema used to describe the table.</param> public UpdateExMethod(TableSchema tableSchema) { // This shreds the list of parameters up into a metadata stucture that is helpful in extracting ordinary parameters // from those that need to be found in other tables using external identifiers. UpdateExParameterMatrix updateParameterMatrix = new UpdateExParameterMatrix(tableSchema); // /// <summary> // /// Loads a record into the Department table from an external source. // /// </summary> // /// <param name="configurationId">Selects a configuration of unique indices used to resolve external identifiers.</param> // /// <param name="employeeKey">An optional unique key for the parent Employee record.</param> // /// <param name="managerKey">An optional unique key for the parent Manager record.</param> // [global::System.ServiceModel.OperationBehaviorAttribute(TransactionScopeRequired=true)] // [global::FluidTrade.Core.ClaimsPrincipalPermission(global::System.Security.Permissions.SecurityAction.Demand, ClaimType=global::FluidTrade.Core.ClaimTypes.Create, Resource=global::FluidTrade.Core.Resources.Application)] // public void UpdateEngineerEx(string configurationId, object[] employeeKey, object[] managerKey) { this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement(string.Format("Loads a record into the Department table from an external source.", tableSchema.Name), true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(System.ServiceModel.OperationBehaviorAttribute)), new CodeAttributeArgument("TransactionScopeRequired", new CodePrimitiveExpression(true)))); //AR FB 408 - Remove Claims requirement //this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(ClaimsPrincipalPermission)), new CodeAttributeArgument(new CodePropertyReferenceExpression(new CodeGlobalTypeReferenceExpression(typeof(System.Security.Permissions.SecurityAction)), "Demand")), // new CodeAttributeArgument("ClaimType", new CodePropertyReferenceExpression(new CodeGlobalTypeReferenceExpression(typeof(ClaimTypes)), "Create")), // new CodeAttributeArgument("Resource", new CodePropertyReferenceExpression(new CodeGlobalTypeReferenceExpression(typeof(Resources)), "Application")))); foreach (KeyValuePair <string, ExternalParameterItem> parameterPair in updateParameterMatrix.ExternalParameterItems) { this.Comments.Add(new CodeCommentStatement(string.Format("<param name=\"{0}\">{1}</param>", parameterPair.Value.Name, parameterPair.Value.Description), true)); } this.Attributes = MemberAttributes.Public | MemberAttributes.Final; this.Name = string.Format("Update{0}Ex", tableSchema.Name); foreach (KeyValuePair <string, ExternalParameterItem> parameterPair in updateParameterMatrix.ExternalParameterItems) { this.Parameters.Add(parameterPair.Value.CodeParameterDeclarationExpression); } // // This provides a context for the middle tier transactions. // global::FluidTrade.Core.MiddleTierContext middleTierTransaction = global::FluidTrade.Core.MiddleTierContext.Current; CodeVariableReferenceExpression transactionExpression = new CodeRandomVariableReferenceExpression(); this.Statements.Add(new CodeCreateMiddleTierContextStatement(tableSchema.DataModel, transactionExpression)); // This will resolve the external identifiers and the build the primary key for the target record. The main idea is to // map elements from foreign rows into parameters that can be used to call the internal methods. foreach (KeyValuePair <string, ExternalParameterItem> parameterPair in updateParameterMatrix.ExternalParameterItems) { // This will recurse into the foreign key relations that use external identifiers and create code to resolve the // variables using the external record. if (parameterPair.Value is ForeignKeyConstraintParameterItem) { this.Statements.AddRange(new CodeResolveExternalVariableStatements(tableSchema, transactionExpression, parameterPair.Value as ForeignKeyConstraintParameterItem)); } // Every internal update method requires a primary key. The external methods do not have this requirement and can // use any unique key. The translation between the external unique key and the internal primary key is created // here. if (parameterPair.Value is UniqueConstraintParameterItem) { this.Statements.AddRange(new CodeResolvePrimaryKeyStatements(tableSchema, transactionExpression, parameterPair.Value as UniqueConstraintParameterItem)); } } // At this point, all the external variables have been resolved and the primary index of the target row has been // calculated in the parameter matrix. This will perform the update with the internal method. this.Statements.Add(new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), string.Format("Update{0}", tableSchema.Name), updateParameterMatrix.UpdateParameters)); }
/// <summary> /// Creates a method that loads records into the database from an external source. /// </summary> /// <param name="tableSchema">The schema used to describe the table.</param> public UpdateMethod(TableSchema tableSchema) { // This shreds the list of parameters up into a metadata stucture that is helpful in extracting ordinary parameters // from those that need to be found in other tables using external identifiers. UpdateExParameterMatrix updateParameterMatrix = new UpdateExParameterMatrix(tableSchema); // /// <summary> // /// Loads a record into the Department table from an external source. // /// </summary> // /// <param name="configurationId">Selects a configuration of unique indices used to resolve external identifiers.</param> // /// <param name="employeeKey">An optional unique key for the parent Employee record.</param> // /// <param name="managerKey">An optional unique key for the parent Manager record.</param> // [global::System.ServiceModel.OperationBehaviorAttribute(TransactionScopeRequired=true)] // [global::Teraque.ClaimsPrincipalPermission(global::System.Security.Permissions.SecurityAction.Demand, ClaimType=global::Teraque.ClaimTypes.Create, Resource=global::Teraque.Resources.Application)] // public void UpdateEngineerEx(string configurationId, object[] employeeKey, object[] managerKey) { this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement(String.Format("Loads a record into the Department table from an external source.", tableSchema.Name), true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(OperationBehaviorAttribute)), new CodeAttributeArgument("TransactionScopeRequired", new CodePrimitiveExpression(true)))); this.CustomAttributes.Add( new CodeAttributeDeclaration( new CodeGlobalTypeReference(typeof(ClaimsPermission)), new CodeAttributeArgument(new CodePropertyReferenceExpression(new CodeGlobalTypeReferenceExpression(typeof(SecurityAction)), "Demand")), new CodeAttributeArgument("ClaimType", new CodePropertyReferenceExpression(new CodeGlobalTypeReferenceExpression(typeof(ClaimTypes)), "Create")), new CodeAttributeArgument("Resource", new CodePropertyReferenceExpression(new CodeGlobalTypeReferenceExpression(typeof(Resources)), "Application")))); foreach (KeyValuePair <string, ExternalParameterItem> parameterPair in updateParameterMatrix.ExternalParameterItems) { this.Comments.Add(new CodeCommentStatement(String.Format("<param name=\"{0}\">{1}</param>", parameterPair.Value.Name, parameterPair.Value.Description), true)); } this.Attributes = MemberAttributes.Public | MemberAttributes.Final; this.Name = String.Format("Update{0}", tableSchema.Name); foreach (KeyValuePair <string, ExternalParameterItem> parameterPair in updateParameterMatrix.ExternalParameterItems) { this.Parameters.Add(parameterPair.Value.CodeParameterDeclarationExpression); } // global::Teraque.OrganizationPrincipal c226 = ((Teraque.OrganizationPrincipal)(global::System.Threading.Thread.CurrentPrincipal)); CodeVariableReferenceExpression organizationPrincipal = new CodeRandomVariableReferenceExpression(); this.Statements.Add(new CodeOrganizationPrincipalExpression(organizationPrincipal)); // if ((DataModel.tenantMap.ContainsKey(q3953.Organization) == false)) // { // throw new global::System.ServiceModel.FaultException<Teraque.TenantNotLoadedFault>(new global::Teraque.TenantNotLoadedFault(q3953.Organization)); // } this.Statements.Add( new CodeConditionStatement( new CodeBinaryOperatorExpression( new CodeMethodInvokeExpression( new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(tableSchema.DataModelSchema.Name), "tenantMap"), "ContainsKey", new CodePropertyReferenceExpression(organizationPrincipal, "Organization")), CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(false)), new CodeStatement[] { new CodeThrowTenantNotLoadedExceptionStatement(new CodePropertyReferenceExpression(organizationPrincipal, "Organization")) })); // DataModelTransaction o1881 = DataModel.CurrentTransaction; // TenantTarget d1882 = o1881.tenantDataSet; CodeVariableReferenceExpression transactionExpression = new CodeRandomVariableReferenceExpression(); this.Statements.Add(new CodeCreateTransactionStatement(tableSchema.DataModel, transactionExpression)); CodeVariableReferenceExpression targetDataSet = new CodeRandomVariableReferenceExpression(); this.Statements.Add( new CodeVariableDeclarationStatement( new CodeTypeReference(String.Format("Tenant{0}", tableSchema.DataModelSchema.Name)), targetDataSet.VariableName, new CodeFieldReferenceExpression(transactionExpression, "tenantDataSet"))); // This will resolve the external identifiers and the build the primary key for the target record. The main idea is to // map elements from foreign rows into parameters that can be used to call the internal methods. foreach (KeyValuePair <string, ExternalParameterItem> parameterPair in updateParameterMatrix.ExternalParameterItems) { // This will recurse into the foreign key relations that use external identifiers and create code to resolve the // variables using the external record. if (parameterPair.Value is ForeignKeyConstraintParameterItem) { this.Statements.AddRange(new CodeResolveExternalVariableStatements(tableSchema, transactionExpression, parameterPair.Value as ForeignKeyConstraintParameterItem, targetDataSet)); } // Every internal update method requires a primary key. The external methods do not have this requirement and can // use any unique key. The translation between the external unique key and the internal primary key is created // here. if (parameterPair.Value is UniqueConstraintParameterItem) { this.Statements.AddRange(new CodeResolvePrimaryKeyStatements(tableSchema, transactionExpression, parameterPair.Value as UniqueConstraintParameterItem, targetDataSet)); } } // At this point, all the external variables have been resolved and the primary index of the target row has been // calculated in the parameter matrix. This will perform the update with the internal method. this.Statements.Add( new CodeMethodInvokeExpression(targetDataSet, String.Format("Update{0}", tableSchema.Name), updateParameterMatrix.UpdateParameters)); }