IdeaBlade DevForce 2010 Help Reference
EntityServerSaveInterceptor Class
Members  Example  See Also  Send Feedback
IdeaBlade.EntityModel.Server Assembly > IdeaBlade.EntityModel.Server Namespace : EntityServerSaveInterceptor Class



Provides server-side interception of save processing.

Object Model

EntityServerSaveInterceptor ClassEntityManager ClassSaveOptions ClassVerifierEngine Class

Syntax

Visual Basic (Declaration) 
<DefaultExportAttribute(IsDefault=True, 
   ContractName="", 
   ContractType=IdeaBlade.EntityModel.Server.EntityServerSaveInterceptor)>
Public Class EntityServerSaveInterceptor 
Visual Basic (Usage)Copy Code
Dim instance As EntityServerSaveInterceptor
C# 
[DefaultExportAttribute(IsDefault=true, 
   ContractName="", 
   ContractType=IdeaBlade.EntityModel.Server.EntityServerSaveInterceptor)]
public class EntityServerSaveInterceptor 
C++/CLI 
[DefaultExportAttribute(IsDefault=true, 
   ContractName="", 
   ContractType=IdeaBlade.EntityModel.Server.EntityServerSaveInterceptor)]
public ref class EntityServerSaveInterceptor 

Example

C#Copy Code
// Server-side implementation of EntityServerSaveInterceptor          
public class EntityServerSaveManager : EntityServerSaveInterceptor  {

  // Always require explicit authorization attributes on entities.
  protected override bool DefaultAuthorization {
    get { return false; }
  }

  // Log errors to any listening loggers.
  protected override void OnError(Exception e, PersistenceFailure failureType) {
    TraceFns.WriteLine("Save error: " + e.Message);  
  }

  // Customized save logic.
  protected override bool ExecuteSave() {

    // Pre-save logic.
    var em = EntityManager;
    var addedEmps = em.FindEntities(EntityState.Added).OfType<Employee>();

    // Mark any added emps with "Added at".
    addedEmps.ForEach(emp => emp.Notes = "Added at" + DateTime.Now);

    // Execute the save.
    var ok = base.ExecuteSave();

    // After save logic.  
    if (ok) {
      // Log any type of saved to an Employee.
      var emps = EntityManager.FindEntities(EntityState.Added | EntityState.Deleted | EntityState.Modified).OfType<Employee>();
      TraceFns.WriteLine("Emps saved: " + emps.Count());
    }

    return ok;
  }
}

Remarks

You may intercept and customize save processing at several points during the save lifecycle. The save request is first authorized before any further actions are taken: see DefaultAuthorization, AuthorizeSave and ClientCanSave for information. Next validation can be performed on the entities: see ValidateSave. Finally the save is executed: see ExecuteSave. Save processing can be cancelled at any point in the lifecycle.

At all times during the lifecycle you have access to the Principal for the user issuing the save.

A new instance of your EntityServerSaveInterceptor is created for each save request.

Inheritance Hierarchy

System.Object
   IdeaBlade.EntityModel.Server.EntityServerSaveInterceptor

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2013 All Rights Reserved.