/// <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 DestroyMethod(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. DestroyExParameterMatrix destroyExParameterMatrix = new DestroyExParameterMatrix(tableSchema); // public void CreateEmployee(int age, string configurationId, string departmentId, string employeeId, string marriageCode) { // { string actionUri = String.Format("http://tempuri.org/I{0}/Destroy{1}", tableSchema.DataModel.Name, tableSchema.Name); string actionReplyUri = String.Format("http://tempuri.org/I{0}/Destroy{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")))); this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(ServiceKnownTypeAttribute)), new CodeAttributeArgument(new CodeTypeOfExpression(new CodeGlobalTypeReference(typeof(DBNull)))))); 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("Destroy{0}", tableSchema.Name); foreach (KeyValuePair <string, ExternalParameterItem> parameterPair in destroyExParameterMatrix.ExternalParameterItems) { this.Parameters.Add(parameterPair.Value.CodeParameterDeclarationExpression); } }
/// <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 DestroyExMethod(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. DestroyExParameterMatrix destroyParameterMatrix = new DestroyExParameterMatrix(tableSchema); // [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] // public void DestroyObjectEx(string configurationId, object externalId, global::System.Guid objectId) // { this.CustomAttributes.AddRange(new CodeCustomAttributesForMethods()); this.Attributes = MemberAttributes.Public | MemberAttributes.Final; this.Name = string.Format("Destroy{0}Ex", tableSchema.Name); foreach (KeyValuePair <string, ExternalParameterItem> parameterPair in destroyParameterMatrix.ExternalParameterItems) { this.Parameters.Add(parameterPair.Value.CodeParameterDeclarationExpression); } // base.Channel.DestroyObjectEx(configurationId, externalId, objectId); List <CodeExpression> arguments = new List <CodeExpression>(); foreach (KeyValuePair <string, ExternalParameterItem> parameterPair in destroyParameterMatrix.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 DestroyExMethod(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. DestroyExParameterMatrix destroyParameterMatrix = new DestroyExParameterMatrix(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 DestroyEngineerEx(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 destroyParameterMatrix.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("Destroy{0}Ex", tableSchema.Name); foreach (KeyValuePair <string, ExternalParameterItem> parameterPair in destroyParameterMatrix.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 destroyParameterMatrix.ExternalParameterItems) { // 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 destroy with the internal method. this.Statements.Add(new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), string.Format("Destroy{0}", tableSchema.Name), destroyParameterMatrix.DestroyParameters)); }
/// <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 DestroyExMethod(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. DestroyExParameterMatrix destroyExParameterMatrix = new DestroyExParameterMatrix(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 DestroyEngineerEx(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)); foreach (KeyValuePair <string, ExternalParameterItem> parameterPair in destroyExParameterMatrix.ExternalParameterItems) { this.Comments.Add(new CodeCommentStatement(string.Format("<param name=\"{0}\">{1}</param>", parameterPair.Value.Name, parameterPair.Value.Description), true)); } // public void CreateEmployee(int age, string configurationId, string departmentId, string employeeId, string marriageCode) { // { string actionUri = string.Format("http://tempuri.org/I{0}/Destroy{1}Ex", tableSchema.DataModel.Name, tableSchema.Name); string actionReplyUri = string.Format("http://tempuri.org/I{0}/Destroy{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")))); this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(System.ServiceModel.ServiceKnownTypeAttribute)), new CodeAttributeArgument(new CodeTypeOfExpression(new CodeGlobalTypeReference(typeof(System.DBNull)))))); 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("Destroy{0}Ex", tableSchema.Name); foreach (KeyValuePair <string, ExternalParameterItem> parameterPair in destroyExParameterMatrix.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 DestroyMethod(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. DestroyExParameterMatrix destroyParameterMatrix = new DestroyExParameterMatrix(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 DestroyEngineerEx(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 destroyParameterMatrix.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("Destroy{0}", tableSchema.Name); foreach (KeyValuePair <string, ExternalParameterItem> parameterPair in destroyParameterMatrix.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 destroyParameterMatrix.ExternalParameterItems) { // 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 destroy with the internal method. this.Statements.Add( new CodeMethodInvokeExpression(targetDataSet, String.Format("Destroy{0}", tableSchema.Name), destroyParameterMatrix.DestroyParameters)); }