The Context Accessor functoid, part II

The Context Accessor functoid, part II

Hi all

I had a post about one of the context
accessor functoids
which can be seen here: http://blog.eliasen.dk/2009/04/01/TheContextAccessorFunctoidPartI.aspx

This post is about the other one – the one that can only be used in a map that is
used in a receive port.

Basically, the functoid takes in three inputs:

GetReceivedFilename

The first is the name of the property and the second parameter is the namespace of
the property schema this property belongs to. The third parameter is an optional string
that is returned in case the promoted property could not be read.

This functoid only works in a map that is called in a receive port
and only if the receive location uses a pipeline that uses the ContextAccessorProvider
pipeline component that is included in he same DLL as the functoids.

What the pipeline component does is, that it takes the context of the incoming message
and saves it in a public static member. This way, the functoid can access this static
member of the pipeline component and read the promoted properties this way.

Good luck using it.



eliasen

Managing Concurrency over Service Boundaries

[Source: http://geekswithblogs.net/EltonStoneman]

Managing concurrency within an application boundary can be straightforward where you own the database schema and the application’s data representation. By adding an incrementing lock sequence to tables and holding the current sequence in entity objects, you can implement optimistic locking at the database level without a significant performance hit. At the service level, the situation is more complicated. Even where the database schema can be extended, you wouldn’t want the internals of concurrency management to be exposed in service contracts, so the lock sequence approach isn’t suitable.

An alternative pattern is to compute a data signature representing the retrieved state of an entity at the service level, and flow the signature alongside the entity in Get services. On Update calls, the original data signature is passed back and compared to the current signature of the data; if they differ then there’s been a concurrency violation and the update fails. The signature can be passed as a SOAP header across the wire so it’s not part of the contract and the optimistic locking strategy is transparent to consumers.

The level of transparency will depend on the consumer, as it needs to retrieve the signature from the Get call, retain it, and pass it back on the Update call. In WCF the DataContract versioning mechanism can be used to extract the signature from the header and retain it in the ExtensionData property of IExtensibleDataObject. The contents of the ExtensionData property are not directly accessible, so if the same DataContract is used on the Get and the Update, and the signature management is done through WCF extension points, then concurrency control is transparent to users.

I’ve worked through a WCF implementation for this pattern on MSDN Code Gallery here: Optimistic Locking over WCF. The sample uses a WCF behavior on the server side to compute a data signature (as a hash of the serializable object – generating a deterministic GUID from the XML string) and adds it to outgoing message headers for all services which return a DataContract object. On the consumer side, a parallel behaviour extracts the data signature from the header and adds it to ExtensionData, by appending it to the XML payload and using the standard DataContractSerializer to extract it.

The update service checks the data signature passed in the call with the current signature of the object and throws a known FaultException if there’s been a concurrency violation, which the WCF client can catch and react to:

Sixeyed.OptimisticLockingSample

The sample solution consists of four projects providing a SQL database for Customer entities, WCF Get and Update services, a WCF client and the ServiceModel library which contains the data signature behaviors. DataSignatureServiceBehavior adds a dispatch message formatter to each service operation, which computes the hash for any DataContract objects being returned, and adds it to the message headers. DataSignatureEndpointBehavior on the client adds a client message formatter to each endpoint operation, which extracts the hash from incoming calls, stores it in ExtensionData and adds it back to the header on outgoing calls.

Concurrency checking is done on the server side in the Update call, by comparing the given data signature to the signature from the current object state:

Guid dataSignature = DataSignature.Current;

if (dataSignature == Guid.Empty)

{

//this is an update method, so no data signature to

//compare against is an exception:

throw new FaultException<NoDataSignature>(new NoDataSignature());

}

Customer currentState = CustomerEntityService.Load(customer);

Guid currentDataSignature = DataSignature.Sign(currentState);

//if the data signatures match then update:

if (currentDataSignature == dataSignature)

{

CustomerEntityService.Update(customer);

}

else

{

//otherwise, throw concurrency violation exception:

throw new FaultException<ConcurrencyViolation>(new ConcurrencyViolation());

}

A limitation of the sample is the use of IExtensibleDataObject to store the data signature at the client side. Although this is fully functional and allows a completely generic solution, it relies on reflection to extract the data signature and add it to the message headers for the update call, which is a brittle option. Where you have greater control over the client, you can use a custom solution which will be more suitable – e.g. creating and implementing an IDataSignedEntity interface, or if consuming the services in BizTalk, by using context properties.

Making Logging Cheaper with Lambda Expressions

[Source: http://geekswithblogs.net/EltonStoneman]

The venerable log4net library enables cheap instrumentation with configured logging levels, so logs are only written if the log call is on or above the active level. However, the evaluation of the log message always takes place, so there is some performance hit even if the log is not actually written. You can get over this by using delegates for the log message, which are only evaluated based on the active log level:

public static void Log(LogLevel level, Func<string> fMessage)

{

if (IsLogLevelEnabled(level))

{

LogInternal(level, fMessage.Invoke());

}

}

Making the delegate call with a lambda expression makes the code easy to read, as well as giving a performance saving:

Logger.Log(LogLevel.Debug,

() => string.Format(“Time: {0}, Config setting: {1}”,

DateTime.Now.TimeOfDay,

ConfigurationManager.AppSettings[“configValue”]));

For simple log messages, the saving may be minimal, but if the log involves walking the current stack to retrieve parameter values, it may be worth having. The sample above writes the current time and a configuration value to the log, if set to Debug. With the log level set to Warn, the log isn’t written. Executing the call 1,000,000 times at Warn level consistently takes over 3.7 seconds if the logger call is made directly, and less than 0.08 seconds if the Lambda delegate is used:

With a Warn call, the log is active and the direct and Lambda variants run 5,000 calls in 8.6 seconds, writing to a rolling log file appender:

I’ve added the logger and test code to the MSDN Code Gallery sample: Lambda log4net Sample, if you’re interested in checking it out.

BizTalk PGP Pipeline Component with Encrypt, Decrypt, and Sign and Encrypt functionality

I’ve added some functionality to the PGP Pipeline component to enable it to Sign and Encrypt files.

Properties Explained:

ASCIIArmorFlag – Writes out file in ASCII or Binary

Extension – Final File’s extension

Operation – Decrypt, Encrypt, and now Sign and Encrypt

Passphrase – Private Key’s password for decrypting and signing

PrivateKeyFile – Absolute path to private key file

PublicKeyFile – Absolute path to public key file.

TempDirectory – Temporary directory used for file processing.

Email me if you could use this.

BizTalk FTP/FTPS Adapter

I was having some problems transferring files from a very old SUN Unix server using the FTP adapter. I decided to create a new BizTalk FTP/FTPS adapter that would be robust and allow me to connect to FTPS servers.

Here are the Receive Location Properties.

Explanation of properties:

CRLF Mode – The CRLF Mode property applies when downloading files in ASCII mode. If CRLF Mode is set to No Alteration the transfer happens normally without alteration. A value of CRLF converts all line endings to CR+ LF. A value of LF Only converts all line endings to LF-only. A value of CR Only converts all line endings to CR-only.

FTP Trace Mode – Send a trace of the FTP session and any errors to either a File, designated by the FTP Trace path and FileName, Event Log, or None.

Transfer Mode – Binary or ASCII

Use Passive Host Address – Some FTP servers need this option for passive data transfers. In passive mode, the data connection is initiated by the client sending a PASV command to the FTP server, and the FTP server responds with the IP address and port number where it is listening for the client’s connection request. When the Use Passive Host Address property is set to Yes, the IP address in the PASV response is discarded and the IP address of the remote endpoint of the existing control connection is used instead.

Authentication Mode – By setting the Authentication Mode Property to AuthTls , a secure FTP connection can be established using either SSL 3.0 or TLS 1.0. The FTP_FTPS Adapter will automatically choose whichever is supported by the FTP server during the secure channel establishment. The FTP control port remains at the default (21). Upon connection, the channel is converted to a secure channel automatically. All control messages and data transfers are encrypted. By choosing Implicit SSL, the FTP_FTPS Adapter connects using SSL on port 990, which is the de-facto standard FTP SSL port.

Client Certificate – The FTP_FTPS Adapter provides the ability to use a client certificate with secure FTP (implicit or explicit SSL/TLS).

Private Key File – The FTP_FTPS Adapter provides the ability to use a client certificate with secure FTP (implicit or explicit SSL/TLS). You may load a certificate from separate .crt (or .cer) and .pvk files and use it as the client-side SSL cert. The .pvk contains the private key. The .crt/.cer file contains the PEM or DER encoded digital certificate. Note: Client-side certificates are only needed in situations where the server demands one.

Invoice VAN FTP/SSL – By choosing yes, the FTP_FTPS Adapter will sets all the properties correctly to connect to an Inovis VAN FTP/SSL.

Tumbleweed Secure Transport FTPS Server – The FTP_FTPS Server can connect, authenticate, transfer files to a Tumbleweed Secure Transport SSL FTP Server. Instead of providing a login name and password, you pass the string “site-auth” for the username, and an empty string for the password. You must also provide a client-side digital certificate — as the certificate’s credentials and validity are used to authenticate.

Please email me if you could use this adapter.

ugMix event in Minneapolis May 8th

ugMix event in Minneapolis May 8th

If you are in the local area, there is a pretty cool event coming to town on May 8th.  From Jeff Brand:

Join us for a special event co-sponsored by the .NET User Group & Silverlight User Group. This month we’re bringing highlights from the MIX09 conference to you!! You’ll get detailed information and in-depth demonstrations on the upcoming release of Silverlight 3 and Expression Blend 3 as well as see some of the great new technologies that were introduced at MIX09.

So, if you didn’t make it to Mix and you want to learn all about the cool technologies first hand, get registered soon.  Don’t think this will fill up fast? Think again.  In addition to the MIX content, Microsoft is doing a screening of the new Star Trek movie after the event.  That’s right, run don’t want to that website and register and find your old communicator and Spock ears! 

BizTalk Server 2009 RTM on MSDN

BizTalk Server 2009 RTM on MSDN

This news is a few days late, but couldn’t let it pass: the 2009 version of BizTalk is out on MSDN for download. This is another evolutionary release, containing a large set of improvements ont he previous 2006 R2 version, including .Net 3.5 SP1/VS2008 SP2 support and much more. You can check everything that’s new on the deck of the presentation I delivered at DevDays 2009 (in Portuguese).

Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it!

MBVQueryBuilder Quick Help

MBVQueryBuilder Quick Help

This doc below  provide some documentation on MBVQueryBuilder tool , explaining what is this tool  and why it exists and what it allow to do.


 


1)   Presenting MBVQueryBuilder and its concepts


 


What is MBVQueryBuilder ?


This tool allow to create quickly and easily additional queries for MBV tool
This tool can create and update a Query Repository XML file with the all queries you will create and allow also to generate the queries you want in an XML MBV Extension file starting with name “MBVEXT”.


 


Why MBVQueryBuilder  ? 


MBV use a custom Health Check engine I developed (“MyHC” Engine) which is easily extensible in tem of queries and rules.
This extensibility is made possible via any XML file starting with name “MBVEXT” and located in same folder than MBV.


These MBV Extension File contain additional custom queries (with their rules if exist) which will appear in additional Queries tabs in MBV gui interface.


To generate easily and quickly such MBV Extension XML files, it became obvious to create a tool to do it.


 


What is a MBV Query  and what it contains ?


An MBV query is an object containing following information :


Main Query information :


– Internal ID: guid
– Category : category of the query
– Caption: visible caption of the query, ex: “List of Send Ports”
– Comment : Description of the query
– Source and Versions : Information about the source and version of this Query
– Type: SQL, WMI, .BAT, .CMD,.VBS, Other
– Target Type: server or Db to target executing the queries
– Target Name: Visible target name in MBV tool gui
– Body: Text of the query (ex: “Select @@Servername”)
– Different attributes: selected by default in MBV gui interface, log a report, etc…


Rules:


A query can contain 0 to N Rules containing themselves 0 to N Conditions and each rule if validated can execute some actions.


A rule is so a set of conditions checking some values in each row of a report of a query, which is just in fact a table where you have columns as SQL fields for example and rows as records.

Each condition containing some references to a column is evaluated per row in the report.
Each condition containing no references to columns like “%ROWCOUNT% > 100” will be evaluated first and only once of course.


So a Rule object is composed of :


– Internal ID: guid
– Caption: Rule caption visible in MBV tool
– 0 to N Conditions
– Actions


A Condition is composed  of predicates :


– A value to check, which can be either a reference to a report value in a specific column, or any other value (like %ROWCOUNT%)
– A value to trigger an action
– A Boolean specifying if comparison will be case sensitive or not


Possible Actions are :


– Write an entry in the Summary Report section with 0 to N link and 3 possible level of warning
– Write an entry in the Topology Report section
– Call a custom .NET function in a custom dll
– Assign a value to a global property (see below for “Properties”)


Properties:


Each query can have 0 to N custom properties (i.e variables) identified by an ID, a caption, one value, and some attributes.

When specify in a body, caption, Summary Report entry, etc.. with syntax “‘%<Property ID>%”, MyHC engine will replace at runtime this “macro” by its  corresponding value.


You can also decide to have a query property visible in MBV gui. In this case, the property caption and its current value will appear in MBV interface (right pane) when selecting the query in the Queries list, allowing you to enter a new value.


 


Custom processing Functions


Each query can (it is completely optional) to have custom .NET functions  implemented in custom dll and called automatically by MyHC engine at different stages:


– before the query will be proceeded by MyHC engine
– to execute the query
– before each query report is populated
– after each query report is populated
– After the query processing is finished


These functions are interesting  mainly when you have type of queries noty supported by MyHC engine or if you want to add your own logic at different stages of the query processing


A sample of a C# project implementing such custom DLL and functions is provided with MBVQueryBuilder 


 


Which type of queries we can create in MBVQueryBuilder ?


MyHC engine that MBV uses provides implementation to execute automatically SQL, WMI, BAT.CMD and VBS queries.


By “automatically” I mean that by providing just the body of a SQL queries, the HC engine  can execute them without having  to provide any code or logic implementation. It is the same for WMI, BAT.CMD and VBS queries.


For .BAT,.CMD and VBS queries, they can be executed only locally on the machine  where MBV is running, as opposed to SQL or WMI queries where you can target remote servers.

To execute automatically .BAT, .CMD and VBS queries, MyHC engine just create on the fly a temporary file and paste the body inside before to execute a CMD.exe or CSCRIPT.exe process and intercept the console output.


 


MBVQueryBuilder and queries Targets


Each Query has a corresponding Target Type and Target Name :

– The  Type allow MyHC engine to know which server to target executing the queries, ex: MsgBox Servers, MsgBox Dbs, DTA Db, Mgmt Db,ALL Servers of the BizTalk group, SQL servers of the BizTalk group, etc…


– The Name  is visible in the Queries List in MBV gui interface in the last column


If you select Target Type ending  with “Server” or “Servers” for SQL queries,  you can enter a specific Database name (ex: “Master”)  or if you let it empty, MBV engine will use automatically the corresponding BizTalk Database name, ex: “BizTalkMsgboxDb” for a MsgBox server


 


Queries Columns:


For querie which are not SQL or WMI, like .VBS, .BAT, .CMD, or OTHER you can specify the columns name the query report will have and also specify the delimiters of query output to use to identify the columns.This fetaure is interesting mainly for .BAt, .CMD, or .VBS to display the console output in a table formated way. 


 


Global Properties:


In the same way you can define properties for Queries, you can also define in MBVQueryBuilder from 0 to N custom Global properties identified by an ID, a caption, a default value, and other attributes.

When specify in rule conditions,  query body, query caption, Summary Report entry, etc.. with syntax “‘%<Global Property ID>%”, MyHC engine will replace at runtime this “macro” by its corresponding current value.


You can also decide to have a global property visible in MBV gui. In this case, the global property caption and its current value will appear in the Global Properties tab of MBV interface (left pane) allowing you to enter a new value.


These global properties are some sort of global variables that you can create and reuse everywhere in queries or rules allowing you to customize your queries.


MyHC engine provide by default some internal  global properties that you cannot remove in MBVQueryBuilder but you can change their default values for some of them. Some of these internal global properties have their value changed dynamically by MyHC engine and will contain for example  :


– the current physical targeted server name
– the current targeted DataSource name
– the current targeted database name
– the current type of targeted server (is it BizTalk Server, a SQL Server)
– etc ..


 


Query Categories:


Important: This feature  is implemented in MBV only since version 10.13


A Query category allow to  better sort and group queries.


When you want to create a query in MBVQueryBuilder, you can specify its category, whatever it is an existing one or a new one


Each Query Category is composed of  :


– an Internal guid
– a Name
– a Type: “Important”, Optional”, “’Custom”
– 1 to N queries (see above for Query description)


At startup, MBV will load the categories of each query either from its embedded Queries Repository XML or from external XML Extension Files and it wil create a many tabs as it find categories.


Each Important category  will have it name shown in bold in MBV, and for each categories found in a custom MBVEXTxxxx.XML file, MBV will create the corresponding tab in blue color to specify that it is a custom category


Once created in MBVQueryBuilder, a category will appear in the Categories List in the tab “Categories”.
You can there change its name and sort them. The order will be so preserved in MBV tool when it will create corresponding Queries tabs.


Each category name will be present in the HTML report before the list of its queries? with also its category type;


 


 



2)   Using MBVQueryBuilder :


 


MBVQueryBuilder Dialog Box is composed mainly of 3 parts :


       The tab pages part consisting of 7 top tab pages divided  in 5 for settings of the current query, and 2 for Categories and Global properties settings.


       The queries List View part contain the list of queries that you created with their information summary


       The bottom control buttons  allow to :


o    add a query


o    remove a query


o    Load another  query repository file


o    Test the queries which are checked in the List View


o    Export into an Extension  XML file the queries which are checked in the List View


 



How to create a fresh new Query  ?


       Select the Query Type you want in the corresponding ComboBox at bottom of the tool Dialog box


       Select the Query Category you want in the corresponding ComboBox at bottom of the tool Dialog box


       Click on the button “Add:”.


       A File Dialog Box will be opened inviting you to chose the name of XML file representing your queries repository.


       A new query will be then added in the Queries List View with its summary of information and its main information will be visible in the “Query Main Info” tab  page where you can there change lot of its information like its caption, comment, Target type, etc…

A default query body will be filled as sample so you will have to change it


Once you finished all your changes on this page, remember to click on “Commit Changes” red button to commit these changes in the query and update the Repository file..


 


How to sort created Queries  ?


The two arrows on the right side of the queries List View allow you to sort the queries in a same category.

Sorting a query allow to change its order of presentation in MBV queries List but also its execution in its category : It can be important for example to execute first a query before another one.


Clicking one of this arrow will so move up or down the query in its category (only !)


 



How to add Rules to a Query  ?


– Select the Query in the queries List View


– Select the “Query Rules tab page
A new rule is created with a default caption that you can change  


– Select the “Rules Conditions” tab page and add your conditions (see Conditions above).


– Select the “Rule Action Types” tab page to specify type of actions  to trigger if the rule is evaluated^


– Select then the other Rule tab pages to fill the actions  information. They are quite explicit themselves.


In each predicates of a condition or fields of action tabs, you can enter any query custom properties or global properties in the form “%<prodID>%


– When you finished to fill all rules settings, remember to click on “Commit Changes” red button at bottom of the  Rule page


Notes:


To fill correctly conditions and actions and have a detailed idea of the type of information and rule you can create, I suggest strongly  to select some any native queries in MBV tool itself and display their rules details (right pane when a query is selected)


 


How to add Query Custom Properties ?


– Select the “Query Custom Properties” tab page


– Click on button “Add Prop” to add a new property
A default prop ID, caption and value will be filled that you can by double-clicking on each item.


– if you want to make a property visible in MBV tool gui then set to “True” the attribute “Visible in HC tool”


– The two arrows on the right side of the  List View allow you to sort the properties. It can be important to specify an order if they are flagged  to be visible in MBV

– once you finished your changes, remember to click on “Commit Changes” red button in this page to update the Repository file.


 


How to add Query Custom Processing functions ?


Important Note:

Filling these function names is optional if the query type and body is supported natively by MyHC and if the rules you want to implement can be implemented completely using conditions in Rules tab  page.


– Select the “Query Custom Processing” tab page


– Fill the name of the dll implementing the custom functions (can have or not .DLL)


– Fill the name of the different .NET functions implementing your logic.
These functions will be called automatically by MyHC engine when it will be the time to execute this query.
These  functions do not accept arguments and return value.

The main important functions is the one called to process the query. Indeed, if it is filled, MyHC engine will not try to automatically execute your query body and will depend only of this custom functions to do the query job.


If you need to create such DLL,  I recommend strongly you to look at the sample of C# project “SampleExtDLL” implementing a such DLL and functions, provided with MBQueryBuilder


 


How to add Custom Global Properties ?


– Select the “Global Properties” tab page


– Click on button “Add Prop” to add a new property
A default prop ID, caption and value will be filled that you can by double-clicking on each item.


– If you want to make a global property visible in MBV tool gui then set to “True” or “True – in bold”  the attribute “Visible in HC tool”


– The two arrows on the right side of the  List View allow you to sort the global properties. It can be important to specify an order if they are flagged  to be visible in MBV in the Global properties list

– once you finished your changes, remember to click on “Commit Changes” red button in this page to update the Repository file.


 


How to Test immediately the queries you created?


– Check the queries in the List View you want to test


– Select the targeted BizTalk Mgmt Server and  BizTalk Mgmt Db


– Click on the button “Test Checked Queries” which will be enabled


– you will see some activity in the status bar in yellow and Internet Explorer will be started to display the temporary HTML report created showing the report output.


 


How to Export some queries from your repository into an Extension File usable by MBV tool ?


– Check the queries in the List View you want to Export


– Click on the button “Export to Query Extension File” which will be enabled


– A File Dialog box will be opened to invite you  to select the targeted folder for this Extension XML file.


– If you have SQL queries to export, a Warning message will be displayed  alerting that creating SQL queries targeting BizTalk Dbs can be dangerous in term of performances or integrity.


– Then if the file is correctly saved, a message will be displayed to confirm it


Important Note:

You need to be sure the Extension File will begin with “MBVEXT“ to be seen as Extension file by MBV tool



If you copy then this produced file in the same folder than MBV, then MBV will load your queries at next startup and will add them in their corresponding  blue category tab !


 


How to load an existing queries Repository ?


– Click on the control button “Load/import other Repository” and browse for the XML repository file


– A message box will be then displayed asking you to replace your working repository by the new one, or to append in your working repository all the queries of the selected repository (Append mode).


– once choice is made, your working repository will contain the new queries loaded


 

MOSS 2007 SP2 will be out soon

MOSS 2007 SP2 will be out soon

Hi All,
Microsoft has recently announced Microsoft Office System Service Pack 2 (includes MOSS 2007 SP2) which is due to be released on 28th April 2009.
You can get more information on the new features and updates available in MOSS 2007 SP2 from here:
http://blogs.technet.com/office_sustained_engineering/archive/2008/10/22/announcing-service-pack-2-sp2-for-the-2007-microsoft-office-system.aspx
and here:
http://blogs.msdn.com/dmahugh/archive/2008/05/21/office-support-for-document-format-standards.aspx
Keep watching this space for more…