Gokul's Blog


Leave a comment

BizTalk Mapping from .Net Code

I came across a few articles sometime back on how to access BizTalk maps or use the XSLT generated from the maps in .net Code.

Here are a few links:


Leave a comment

BizTalk Jobs and BizTalk Databases

MessageBox_DeadProcesses_Cleanup_BizTalkMsgBoxDb
MessageBox_Message_Cleanup_BizTalkMsgBoxDb
MessageBox_Parts_Cleanup_BizTalkMsgBoxDb
PurgeSubscriptionsJob_BizTalkMsgBoxDb

 

Handling the growing size of BizTalk database’s log db

http://social.msdn.microsoft.com/forums/en-US/sqldisasterrecovery/thread/d3db3a47-3a4f-4ddb-b2e8-4d5a643d8476/

BizTalk Message Viewer


Leave a comment

BizUnit

Some reference sites related to BizUnit

  1. BizUnit overview: http://blogs.msdn.com/kevinsmi/archive/2005/07/17/439728.aspx
  2. Walk through of how to use the BizUnit: http://biztalkia.blogspot.com/2007/03/getting-started-with-nunit-and-bizunit.html
  3. I suggest that you go through the URL above and actually implement the sample code.
  4. Other useful tools (they will make sense once you do the walk through)


Leave a comment

Get value from Registry settings in C#

The below method is used to get the connection string from Registry or BizTalk Config file

public static string GetConnectionString()
        {
//            RegistryKey reg = Registry.LocalMachine.OpenSubKey(@"Software\MYcompany\Connstring");
//            String sConn = (String)reg.GetValue("ConnStr", "Integrated Security=SSPI;Data Source=.;Initial Catalog=BizTalkMsgBoxDb");
//            reg.Close();
            string sConn;
            // Read from the BTSNTSvc.exe.config
            sConn = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"].ToString();
            if (sConn.Length <= 0)
            {
                  throw;
            }
            return sConn;
        }


Leave a comment

Code Snippet to get the size of an Xlang Message in Bytes

One of my colleague was working on to find out is there a way to find the message size of an xlang message. Based on his request I am adding his Code snippet to get the size of an Xlang Message in bytes.

 //Returns the sum of the size of the message parts public static int GetMessageSize(Microsoft.XLANGs.BaseTypes.XLANGMessage msg)
            {
                int msgSize = 0;
                try
                {
                    foreach (Microsoft.XLANGs.BaseTypes.XLANGPart xp in msg)
                    {
                        msgSize += Convert.ToInt32(xp.GetPartProperty(typeof(Microsoft.XLANGs.BaseTypes.Size)));
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.EventLog.WriteEntry("XMLUtils GetMessageSize", ex.Message, System.Diagnostics.EventLogEntryType.Error);
                }

                return msgSize;
            }
Original Source: Link

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }


Leave a comment

POP3 and BizTalk

(original Publish date: April 16, 2008)
Abstract : Receive an email from an POP3 server and write the attachments in to a folder.

Solution 1: Use the BizTalk 2006 R2 POP3 adapter and an orchestration to achieve it.

The receive location has to be configured as follows.

[Image] of POP3 receive location

I was able to get the filename by getting the message partname while I was using Gmail POP3 as my POP3 server, when we switched to Windows POP3 server I was unable to get the Filename. The algorithm used by BizTalk POP3 adapter to get the filename is as follows

1. Take it from the Content-Description header.
2. If not found, then the part name is based on the Content-ID header.
3. If still not found, then generate a GUID for the part name.

Receive the email as a Multipart message and then loop through the parts. While looping through check whether the MIME.FileName property exists if not then its the body part :).

Please find the attached zip file containing the orchestration code. This orchestration sample will read an email and write the attachments one by one to a folder.

Solution 2: While I was exploring through various options to overcome the issue. I came across an interesting scenario. If you just need a file which contain the email with all the contents in a folder. .eml comes to the rescue. Read the email using a receive port and write the message using a send port with an  .eml extension. When a user double-click on this file it opens in outlook express and its very simple solution(15 minutes we can achieve this). This solution suits for environments where outlook express is allowed.

Solution 3: Use the Raw Message send it to a helper method there are a lot of third party .Net based MIME encoding tools. Manipulate the message as needed. A google search on .Net mime encoding returns a lot of tools. An excellent article from Roy Ashbrook explains how to use Regex to parse .eml files.

Here is the code for reference taken from the above blog.

using System;
using System.IO;
using System.Text.RegularExpressions;
 
namespace parse.eml
{
    class Email
    {
        string _path,_to,_from,_subject,_urls;
 
        public Email(string path)
            {
                _path = path;
                string fc = new StreamReader(path).ReadToEnd();
                _from = Regex.Matches(fc, "From: (.+)")[0].ToString();
                _to = Regex.Matches(fc, "To: (.+)")[0].ToString();
                _subject = Regex.Matches(fc, "Subject: (.+)")[0].ToString();
                _urls = string.Empty;
                foreach (Match m in Regex.Matches(fc,@"https?://([a-zA-Z\.]+)/"))
                {
                _urls += m.ToString() + ' ';
                }
            }
            
            public void show()
            {
                Console.WriteLine("{0}\n\t{1}\n\t{2}\n\t{3}\n\t{4}",_path, _to, _from, _subject, _urls);
            }
     }
        
    class Program
    {
        static void Main(string[] args)
        {
            foreach (string f in Directory.GetFiles(".", "*.eml"))
            {
            Email e = new Email(f);
            e.show();
            }
        }
    }
} //namespace
      
 
Reference articles:

http://www.biztalkgurus.com/forums/p/2217/4455.aspx#4455

http://www.biztalkgurus.com/files/folders/biztalk_2006_samples/entry15562.aspx

And also I would like to thank my friends/ Mandi(MS-support) for their guidance, in getting "solution 1" possible.

Solution 2 coming soon!

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }