Csla CommandBase Question

Csla CommandBase Question

Old forum URL: forums.lhotka.net/forums/t/2691.aspx


glenntoy posted on Friday, April 13, 2007

Would it be possible to know when to use/implement these methods private methods BeforeServer() and AfterSever()? Is there anybody here using these methods?

Thanks.

LiamGrossmann replied on Thursday, August 23, 2007

I'm using CommandBase to call a DTS (i.e. SSIS package). I pass in the jobname to the Execute method and take it from there ...

 

using System;

using System.Collections.Generic;

using System.Text;

using Csla;

using Csla.Data;

using Microsoft.SqlServer.Dts.Runtime;

namespace BarclaysCapital.ADF.Batch

{

/// <summary>

///

/// </summary>

[Serializable()]

public class SystemJobCommand : CommandBase

{

#region Authorization

public static bool CanExecuteCommand()

{

// TODO: Customize to check user roles

// return ApplicationContext.User.IsInRole("Intranet\\Group1");

return true;

}

#endregion

#region Client-side code

bool _Result = false;

string _JobName = String.Empty;

public bool Result

{

get { return _Result; }

}

public string JobName

{

get { return _JobName; }

set { _JobName = value; }

}

private void BeforeServer(string jobName)

{

//_JobName = jobName;

}

private void AfterServer()

{

// TODO: Implement code to run on client after server is called

}

#endregion

#region Factory Methods

public static bool Execute(string jobName)

{

SystemJobCommand cmd = new SystemJobCommand();

cmd.BeforeServer(jobName);

cmd = DataPortal.Execute<SystemJobCommand>(cmd);

cmd.AfterServer();

return cmd.Result;

}

private SystemJobCommand()

{ /* require use of factory methods */ }

#endregion

#region Server-side code

protected override void DataPortal_Execute()

{

Microsoft.SqlServer.Dts.Runtime.Application application = new Microsoft.SqlServer.Dts.Runtime.Application();

Package package = application.LoadPackage(@"C:\Perforce\CreditRiskReporting\depot\CreditRiskIT\CreditRiskReporting\_main.br\IntegrationServices\CRRETL\" + _JobName, null);

package.ImportConfigurationFile(@"C:\Perforce\CreditRiskReporting\depot\CreditRiskIT\CreditRiskReporting\_main.br\IntegrationServices\CRRETL\CRRETL.dtsConfig");

//Variables vars = package.Variables;

//vars["XYZ"].Value = "hELLO";

DTSExecResult rc = package.Execute();

}

#endregion

}

}

 

 

RockfordLhotka replied on Thursday, August 23, 2007

glenntoy:
Would it be possible to know when to use/implement these methods private methods BeforeServer() and AfterSever()? Is there anybody here using these methods?

Thanks.

The idea is that a command object can run code at three points in its lifecycle:

  1. On the client before the execute
  2. During the execute on the app server (logically at least)
  3. On the client after the execute

In many cases step 1 is just to initialize some fields so step 2 can run, and there is no step 3.

But it really depends on what your command needs to do. If you need to do something in any of those steps then you can do it, otherwise you don't.

Copyright (c) Marimer LLC