August 2003 - Posts
A week ago I started working on a new project for
PAG, this new project is a reference document and implementation for an application architecture, it's a very interesting project.... of course I can't talk too much about it here ;). One of the first tasks I was given is researching many different ways to implement COM+ transactions for .Net. code
Of course using COM+ which is very interesting and widely used technology, it's also nd a set of component services totally based in interception. In COM+
aspects are widely used (there's a lot of articles and blogs about this
here,
here, and
here ).
One of the most ugly features of COM+ is that in order to use transactions you must declare a component as "transactional", for example if the component
Customer had a method
Save and the component
Order aslo had a method
Save, in order to define an ACID transaction that calls
customer.Save and
order.Save, both operations within the same transaction, you must declare the component
Customer and
Order as "transactional". Of course this brings a lot of performance troubles if your Customer component also had, for example, a method
SelectAll, because the transaction will lock every record selected until the transaction gets Committed or Rollbacked (Aborted in COM+ terms). The problem is that "transactionability" is an
aspect for the execution context, it does not belongs to the
Customer or
Order components.
There are some solutions for this problem but many of them changes the way you have to code or develop your components.
In COM+ 1.5 (W2K3 and WXP) there's an unpopular feature which is named "COM+ Services without Components", explained in this
MSDN article and
here is the MSDN documentation, it's a COM component that allows creating a COM+ context (with the desired context feature) without using a COM component to initialize the context. The programming model allows to call a method to create a context, after the method is called, every operation issued over a transactional resource will be included in the transaction until another method is called to leave the context.
Using .NET 1.0 you can define the Interop classes or using Managed Extensions a wrapper can be created so those features can be used in a managed environment. In .NET 1.1 a class called
ServiceDomain was included as a wrapper for that feature.
The following code demonstrates how to use it:
// (A) perform any operation on any transactional resource
ServiceConfig svcc = new ServiceConfig();
svcc.Transaction = TransactionOption.Required;
ServiceDomain.Enter( svcc );
// (B) perform any operation on any transactional resource
ContextUtil.SetAbort(); //SetCommit();
ServiceDomain.Leave();
// (C) perform any operation on any transactional resource
After the execution you will notice that operation performed on A and C have been committed, but the operation performed on operation B does not. It's a great feature you can use in .NET.
Some limitations In MSDN says it's only supported on Windows 2003, in Windows XP there's a version of COM+ 1.5 but some people says it's broken.... i run a very simple code and it worked fine.... i really don't have field experience about it's behavior in WinXP. It CAN'T be used on Windows 2000.
There's also a cool feature in COM+ 1.0 called BYOT i was using, and i'm really impressed about it. This allows passing transactions between proceses... and a very simple solutions about how to marshal transactions using Remoting. I'll blog about BYOT in a couple of days.
If you may have some questions you can take a look at the EnterpriseServices FAQ in GDN.
www.microsoft.com runs Linux? Up to a point ...
Does anybody knows where we can find Browser usage statistics? I'm using Firebird, and seems many people are doing so..... it seems the browser war is back again....
Many times i have to develop applications using external providers so users can change the provider in the configuration file and change the way the application behaves. It's very helpful on some external components like Custom data access (i.e. using the PetShop approach), logging, and so on.
Usually each provider uses an interface so the application can run with any class implementing the interface. For example:
public interface ISomeProvider
{
// Custom provider methods.
}
In the application config file i place external providers in a custom section like this one (to handle this you have to code an IConfigurationSectionHandler):
<configuration>
<configSections>
<section name="MyAppConfig" type="MyApp.MyConfigSectionHandler,MyApp" />
</configSections>
<MyAppConfig>
<logprovider name="default" type="MyApp.DefaultLogProvider,MyApp" />
</MyAppConfig>
</configuration>
After implementing solutions like that in many applications i was using something like a pattern for provider configurations.
I add a method named "Init" in the interface. This will allow to initialize all the providers during application bootstrap and avoiding static constructors, or obscure flags so in the first use the provider it gets initialized.
The "Init" method receives an XmlNode. During configration load, the section handler reads the "logProvider" node and creates an instance of the type "MyApp.DefaultLogProvider,MyApp", after the instance is created, the "Init" method is called using the "logProvider" node as the first parameter. Why does the parameter is defined the "Init" Method instead using the constructor?. Because the calling application uses the "Init" method to initialize the provider, when an instance of a Type is created using Activator.CreateInstance( Type ), the parameters to the constructor must be specified as an object[], and of course, constructors can't be specified in the interface, so using a method in an interface avoids type mismatch problems.
If the provider needs some configuration it will define its config within the node that defines the provider, and aviods creating extra section handlers or loading provider data from a different file. So the xml will looks like:
<logprovider name="default" type="MyApp.DefaultLogProvider,MyApp">
<provider_specific_config />
</logprovider>
And the interface having the Init Method:
public interface ISomeProvider
{
void Init( XmlNode configNode );
// Custom provider methods.
}
Some more issues, if the Init method throws an exception (and the application needs the provider) the application does not load. This is great because you don't have to start using the application to know if all the providers have initialized correctly, if something fails you wil have an error during application load.
A variant for this we used in the
Configuration Management Application Block and
User Interface Application Block. In those blocks we don't define an XmlNode in the Init method but an IDictionary. The contents of the IDictionary are the attributes on the provider node and it's values. Of course this will only specify name=value pairs, but will not allow complex configuration schemas.
Hope it helps somebody.
A couple of days ago somebody asked me about calling WebServices using JavaScript whithin the WebBrowser. He was using XMLHTTP object within IE calling a simple WebService passing parameters in the URL. But he get into trouble when the WebService returns a hard-typed DataSet because he have to use DOM (XPath) to get the data within the DataSet's XML.
This is a simple but ugly solution because samobidy could could change a "field" from Element(default) to Attribute; all the code in C#(for example) using the DataSet generated class, will be compatible, but the XML is different.
A couple of months ago i wanted to develop a Client-Side Dataset providing similar API to use a DataSet but coded in JavaScript so it can be used inside the browser. I started coding some lines this morning but is not a simple solution, and i have a lot of work to do :).
I was thinking on the following solution:
- Creating a ServerControl with a single property named DataSetType. In design time the developer places the ServerControl in a page setting the property to a DataSet type.
- During server control rendering, it uses reflection and XSD information to generate enough JavaScript code so an XML could be readed and supporting a DataSet like programming interface.
- The script generated also creates a new instance of an empty the Dataset so the user can execute the following code in JavaScript: someDataSet.LoadXml( xmlString ); alert( someDataSet.Tables[0][0] );
Monday is a non-working day in Argentina, so i'll try to get some code working and perhaps post the code in a Workspace. Does anybody knows if someone else is working on somthing similar?
Yesterday i was speaking in a conference at Microsoft Argentina named "Application Architecture in .NET". I am really amazed on how many people is interested in this topic. They have a lot of doubts and questions about general architecture, how to use the application blocks, and how to develop their enterprise applications in .NET. I don't have all the answers for the questions, but i really like to discuss about it. There were about 120 people, i was talking about the PAG's architecture, enterprise patterns, i explain how to use the Application Blocks: UIP, CMAB, Caching, Exception Management, during 3 exciting hours.
It was a great conference.
Muchas gracias a todos los asistentes.
I really like to have some information about the workspace, for example:
- Workspace hits, or explain what the "Activity %" means :)
- Downloads count.
- Member activity
- Link to other Workspaces related os UserSamples. Many people make some changes and posts UserSamples it could be great to link them to the Workspace.
- Check-In count
- Source code change notificaton.
- Read only membership. So some users can only post messages and get the code but they should not be able to update the code in Source Control
- New Bug notification to anyone interested
Check
it out. The release is listed
here.
I was working for
Patterns & Practices group on the development of some Application Blocks (
User Interface Process,
Configuration Management,
Application Updater), after that they told me to develop a completly new version for the DAAB where every mehtod of the DAAB uses only ADO.NET interfaces. It will be available online on the following
Workspace this week... i hope.
But it have some limitations for example the SQL syntax, you can't use any ADO.NET provider using the same SQL syntax. I was wondering if it's possible to develop an abstraction over ADO.NET drivers so the client application can issue a generic SQL and then this SQL is converted to the specific SQL supported by the ADO.NET drivers. It's the same approach used by JDBC... what is needed to implement this?
- A generic SQL grammar (scanner and parser). Which receives an SQL which is ADO.NET SQL and creates an AST representation.
- A converter which takes the AST and generates an SQL statement for a specific ADO.NET provider.
.... does anybody have a sample SQL grammar for LEX/YACC or perhaps
Coco/R? I was writing my own grammar to test my idea using
Grammatica.... but my DiegoSQL grammar wont be correct. :)
On friday a new version for the Web Services Architecture document was published as a wroking draft. The document describes most of the Core concepts and the architecture models proposed, including Policy and Mangement. Very interesting reading.
Have you check the differences between the SLN and the CSPROJ files between VS2002 y VS2003? It's
incredible i've been checking the files and i find an UNSUPPORTED way to convert the project files so you can
open the solution with any VS version.
On the .sln file you will get the following text on VS.NET 2003:
Microsoft Visual Studio Solution File, Format Version 8.00
But in VS.NET 2002 the version is 7.00... very funny. On the CSPROJ file which is an XML file, you will fine the following node:
<CSHARP
ProjectType = "Local"
ProductVersion = "7.10.3077"
SchemaVersion = "2.0"
ProjectGuid = "{4B2C7E90-EE53-4887-8C5E-2F57F414E305}"
>
If you change the "SchemaVersion" attribute to "1.0" and the "ProductVersion" to "7.0.9466" this file can be readed with VS.NET 2002, you may get some warnings but it works...
I have some questions about this?
Why VS.NET team does not use XML to define the SLN files? If the schemas gets public it will be great for external tools to generate every solution file, i mean the SLN, CSPROJ, XSX, etc.
Silly solutions for a silly world.
More Posts
Next page »