Customize the CSLA server side initialization - initialization

I have next problem. We have a huge client-server system and use CSLA to operate with DB data. There are a set of WinForms-based clients and one WCF-based AppServer. We have custom logging subsystem and settings for this subsystem are stored in DB. So on initialization of each side of our system (client application or application server) we need to configure logging subsystem with settings from DB. In the client application it is easy to do. But how can we extend CSLA WCF Portal to init logging after init of CSLA WCF Portal??
So, how to customize the initialization of CSLA?
Thanks a lot!!

Rockford Lhotka answered this question on his forum http://forums.lhotka.net/forums/p/9224/43785.aspx#43785
In CSLA 3.8 and higher there's one hook that exists on the server before anything else occurs. It is designed to enable authorization on every single server call, but it can be used to perform server-side initialization as well.
You need to implement Csla.Server.IAuthorizeDataPortal and add a config entry so the data portal knows the assembly qualified type name of your class that implements the interface.

Related

How to know an application is available?

when I use the cloudify(2.7) to deploy an application(e.g. an application app includes two services A and B ),I try to use the Admin.addEventListener() to add some eventListener,but it does't work !
I try to add the ProcessingUnitStatusChangedEventListener ,when I debug the code,the value of (ProcessingUnitStatusChangedEvent)event.getNewStatus() changes from SCHEDULED to INTACT,then SCHEDULED,then INTACT again,
I also try to add the ProcessingUnitInstanceLifecycleEventListener,when I debug the code,the status is intact,but the service is not available!
Is there any other listener or method to know the application(not the services) is available,or I use the listener in the wrong way?
First, the Admin API is internal - use it at your own risk. And you should not be using it the way you are - Cloudify adds a lot of logic on top of the internal Admin API.
Second, it is not exactly clear where you are executing your code from.
You can always use the rest client to get an accurate state of the application. Look at https://github.com/CloudifySource/cloudify/blob/master/rest-client/src/main/java/org/cloudifysource/restclient/RestClient.java#L388
In addition, if you are running this code in a service lifecycle event handler, the easiest way to implement this is to have your 'top' level service, the one that should be available last, write an application entry to the shared attributes store in its 'postStart' event. Everyone else can just periodically poll on this entry. The polling itself is very fast, all in-memory operations.
If you do not have a top-level service, or your logic is more complicated then that, you would need to use the Service Context API to scan each service and its instances to see if they are up. An explanation on getting service instance state is available here:
cloudify service dependsOn other service

Set a SQL trigger and have asp.net subscribe to it?

Is it possible to set a SQL trigger, where if it gets fired, do something in an asp.net application?
Theoretically YES (via SQL CLR Stored Proc calling a web service in
that asp.net app)
Psychologically NO
You'd be better using a queue or log table, write to that and have a service or task subscribe to it.
EDIT: Excuse me... taht technology is deprecated, and now you should use:
SQL Dependency class
DEPRECATED:
You can use SQL Server Notification Service.
Look at this article:
Understanding SQL Server 2005 Notification Services with ASP.NET 2.0
It uses right the same technology that SqlCacheDependency Class which could also help you, depending on what exactly you want to achieve.

Running VBA functions in a server side Access database from a WCF service

I've been researching for days and I've gotten to the point where my WCF service creates an Access object via com/interop. I've ran the OpenCurrentDatabase call for the Access object without an error but Application.CurrentDB is still nothing/null. If the CurrentDB is nothing then I surely can't call Application.Run "myFunction" I realize WCF services aren't meant to be user interactive, but it's a long story why I'm trying to go this route. Basically I need to have a proof of concept ready sooner rather than later and the alternative (correct) route involves the complete re-writing of a large complex access VBA application. It's not a permissions issue, I have the IIS user names added to the security tab. What I really need is a way to set Environment.UserInteractive to true so my WCF service can create an instance of Access on my server machine, run the VBA functions, close out, return true. I'm using VS 2010 for the WCF, IIS 7 for my server, Access 2010 for the VBA application. Please help!
The answer is to have the WCF service write the access macro name to a database and have a desktop application on the server machine monitor the database. The desktop application loads access, performs the actions, and writes back to the database upon completion. The WCF service monitors the database waiting for an "operation complete" status and returns the result.

Avoiding having to map WCF's generated complex types

I have an ASP.NET MVC web app whose controllers use WCF to call into the domain model on a different server. The domain code needs to talk to a database and access to the database server isn't always possible from web servers (depends on the customer site) hence the use of WCF to get to a place where my code is allowed to connect to the database server.
This is configurable so if the controllers are able to access the database server directly then I use local instances of the domain objects rather than use WCF.
Lets say I have a page asking for person details like age, name etc. This is a complex type that is a parameter on my WCF operation like this :
[OperationContract]
string SayHello( Person oPerson);
When I generate the client code (eg; by adding a service reference in my client) I get a separate Person class that fulfills the wcf contract. The client, an MVC web app, can use this client Person class as the view model and all is well. I pass that straight into the WCF client methods and it all works brilliantly.
If my mvc client app is configured to NOT use WCF I have a problem. If I am calling my domain objects directly from the controller (assume I have a domain access factory/provider setup) then I need the original Person class and not the wcf generated Person class. This results in my problem which is that I will have to perform mapping from one object to another if I don't use WCF
The main problem with this is that there are many domain objects that will need to be mapped and errors may be introduced such as new properties forgotten about in future changes
I'm learning and experimenting with WCF and MVC can you help me know what my options are in this scenario? I'm sure there will be an easy way out of this given the extensibility of WCF and MVC
Thanks
It appears that you are not actually trying to use a service-oriented architecture. In this case, you can place the domain objects into a single assembly, and share it between the WCF service and the clients. When creating the clients, use "Add Service Reference", and on the "Advanced" tab, choose "Share Types". Either choose to share all types, or choose the list of assemblies whose types you want to share.
Sound service-oriented-architecture dictates that you use message based communication regardless of whether your service is on another machine, in another process, in another appdomain, or in your appdomain. You can use different endpoints with different bindings to take advantage of the speed of the link (http, tcp, named pipes) based on the location of your service, but the code using that service would remain the same.
This may not be the easiest or least time-consuming answer, but one thing you can do is avoid using the "add service reference" option, and then copy your contract interfaces to your MVC application and initiate the connection to WCF manually without automatically creating a service proxy. This will allow you to use one set of classes for your model objects and you can control explicitly when to use WCF or not.
There's a good series of webcasts on WCF by Michele Leroux Bustamante, and I think in episode 2, she explains how to do exactly this. Check it out here: http://www.dasblonde.net/WCFWebcastSeries.aspx
Hope this helps!
One sound option is that you always use WCF, even if client and server are in the same process, as Aviad points out.
Another option is to define the service contracts on interfaces, and to put these, together with the data contracts into an assembly that is shared between client and server. In the client, don't use svcutil or a service reference; instead, use ClientFactory<T>.
This way, your client code will use the same interfaces and classes as the server.

What's the best practice for ASP.NET MVC app to check for dependencies at startup?

Like any other ASP.NET application, the web app I'm developing depends on a plethora of services and settings. Examples of services include third-party web services and examples of settings include SMTP server settings. It is fairly typical for a Java application to do some self checking at startup and if any of the required dependencies are not present or in the right state, the application will not start up. What is the best practice for implementing something similar in ASP.NET (MVC)?
See this:
Use Bootstrapper in Your ASP.NET MVC Application and Reduce Code Smell
Note that you can extend the main interface there:
public interface IBootstrapperTask
{
void Execute();
bool IsEnabled(); // <--
}
and then only boot it if it says so.
Each service has its own way of checking for availability, and some services do not need to be checked at all unless there is a request for them. It really depends on the requirements of the application and the needs of the users.
if you have some depemdencies, you can do it at Application_Start and Session_Start to make such a check, both methods in Global.asax. If any severe error detected, you can redirect the page to an error message page and send an email to admin or log the error.

Resources