Pages

Showing posts with label Miscellaneous. Show all posts
Showing posts with label Miscellaneous. Show all posts

How To: Copy all Filenames in a Directory to a Text File

Friday, September 14, 2012

How To: Copy all Filenames

Got to know this last week! This works great if you want to save all the filenames in a directory to a text file.1. Open up your command prompt by typing cmd in the run dialog box and hitting Enter.
2. Navigate to the directory which has the files and type the following command -
DIR /B /O:N > filenames.txt
This will save all the filenames in the current directory to a text file. The text file will be saved in the same directory.
3. To save file names from any sub-directories in the current folder, just add /S like -
DIR /B /O:N /S > filenames.txt
Read more ...

Biz talk Deployment & Build Automation - Biz Talk 2009 TFS 2008

Tuesday, September 11, 2012

BizTalk Server 2009 comes with support for MSBuild. The question is, how can we use it, and how does it help us? The obvious advantage is of course, that this enables Visual Studio BizTalk projects to be deployed to the production environment without the pain of exporting/importing MSI packages. This is particular troublesome when dealing with large BizTalk implementations, with lots of assemblies, where you need to select and deselect assemblies to be included in the package.
It is possible to automate deployment using BizTalk Server 2006 R*, but not without installing Visual Studio on the production environment. This is because MSBuild can’t build BizTalk 2006 projects, and you need to use DevEnv to do the work. But since BizTalk 2009 projects are C# project, and C# projects is nothing less then MSBuild scripts, BizTalk 2009 projects can be built on environments without the need of Visual Studio.
But there is  a catch… –It can build, but there is no support for deployment :(
To manage Deployment, we need to do some customization.
image










When you create a new Build Type in Team Explorer and execute the build, the default build will execute a set of Build Tasks such as GetSources, Compile, Execute Tests etc. The result of the build will give you a folder with the output of the Build. That is a folder with a bunch of assemblies. To deploy these assemblies, we need to figure out where they should deployed to. The obvious place to find this information would be in the bindings files.
So to make use of the new MSBuild support, we need to create three custom tasks:
  • Undeploy Bindings - Since we are going to redeploy the solution, we need to remove all previous assemblies and artifacts.
  • Deploy Assemblies - This Task can optionally be disabled, in case you just want to undeploy. The bindings files will tell us to which BizTalk Application an assembly should get deployed to. if your build results in assemblies that should not get deployed to BizTalk, then these won’t get deployed since they are not included in the bindings files.
  • Import Bindings - This is the last custom task to be executed, and will create all the port bindings. Similar to the Deploy Assembly task, this one is optional is case you just want to undeploy.
Next we need to include these tasks in our build. We do this by adding a single row to our already created Build Type:
<Project DefaultTargets="DesktopBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">

  <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets" />
  <Import Project="$(SolutionRoot)/TeamBuildTypes/Blogical.BizTalk.CustomTasks.targets"/>
  <ProjectExtensions>
The Blogical.BizTalk.CustomTasks.targets file includes all necessary targets, and will execute the Undeploy-, Deploy- and Import Bindings tasks after the Compilation Task has been successfully executed.
That’s it!
image

There are some architectural constraints and considerations you need to be aware of:

Isolated Solutions
The Visual Studio solution is central in this process, and it’s important that projects within this solution should not be part of, or referenced from within any other solution that is going to be used in any Build Type. The reason for this is that the solution might not be possible to undeploy if it’s referenced by any other assemblies.
Bindingsfile location
In order for the Custom Tasks to find the Bindings files, the Bindings files need to be checked in to a folder named Bindings which needs to be located in the same folder as the Visual Studio solution file. Also the Bindings files need to be named [Some Name].[Target Environment].xml. Where the Target Environment could be something like TEST, STAGE, PRODUCTION etc. Eg Navision.OrderConfirmation.STAGE.xml
Shared Components
Global artifacts, such as generic schemas and pipelines, needs to be handled separately from this Build Process, as these are referenced by any number of assemblies, ports and filters.
BizTalk Applications
This Build Process does not create BizTalk Applications. Nor does it manage its references. Therefore you need to create them manually before deploying. As Applications are normally not created on a daily basis, this should not be a big issue.
Utilizing undocumented BizTalk assemblies
The Custom Tasks does not use BtsTask.exe, as it’s difficult to handle exceptions using for example Process.Start. Instead it uses Microsoft.BizTalk.ApplicationDeployment.Engine (also used by BTSTask, ExplorerOM and Visual Studio). This is working very well, but this is not a documented library. I would really like to see Microsoft ship BizTalk with a better supported Deployment API similar to ExplorerOM.
Installation
The Zip file includes the Custom Tasks library and the CustomTask.target file.
  1. Save the Blogical.Shared.Tools.BizTalkBuildTasks.dll file to preferred directory on each server running the Build Agent. You can use a network share.
  2. Edit the Blogical.BizTalk.CustomTasks.targets file (line 44). Set the <Blogical_CustomTasks> to the directory where you saved the Blogical.Shared.Tools.BizTalkBuildTasks.dll.
  3. Check in the Blogical.BizTalk.CustomTasks.targets file to the TeamBuildTypes folder in you TFS project.
Read more ...

Advanced Users Biztalk WIKI : Useful How to Links Part - 5

Tuesday, June 12, 2012
 Useful How to Links Part - 5

Bre Static Support Key

Calling Data Access from Ado.Net

Sso Configuration Storing Values

Xml Document XPath Sample

ESB Dynamic Routing using Itineraries


Read more ...

Solved : MSMQ Error Rcv Pipeline No Disassemble stage components can recognize the data & A message received by adapter "MSMQ" on receive location is suspended.

Friday, September 30, 2011
Q:

When I try process a file, I receive the following two errors - 
There was a failure executing the receive pipeline:  Receive Port: : No Disassemble stage components can recognize the data.

and 


A message received by adapter "MSMQ" on receive location  is suspended.

Error details: There was a failure executing the receive pipeline: Source: "Flat file disassembler" Receive Port:  URI: "FORMATNAME: DIRECT=OS: " Reason: No Disassemble stage components can recognize the data.
MessageId: {77F9D67C-3575-4993-926E-BDD24B020C89}
InstanceID: {B72BA496-9194-4003-84FF-83070DB5941B}

Input file is Flat file and the receive pipeline has a Flatfile disassembler. Also configured the flat file disassembler with the Document schema.

Any help appreciated?

sol:
This problem frequently occurs because of header or extra format information that is added to an MSMQ message. If you open up the MSMQ service uinder Administrative Tools \ Computer Management \ Services, you can see the MSMQ messages that are in the queue. I would stop your BizTalk application and then send in a message. You can see the body value of the message and determine whether extra characters are being added to the message before BizTalk receives it and tries to parse it
Also check the MSMQ.BodyType context property which will determine how the Biztalk will handle the message.
References:
and




Read more ...

BizTalk custom pipeline DECODE component to REPLACE a Special Character inside the Message

Friday, September 30, 2011
Q:

Hello Friends,

I am new to create a custom pipeline DECODE component but stuck at the logic which modifies the message (replacing some prespecified character with some default character).
What i know is what to REPLACE and with WHAT along with the format of file type which is Flat File.

For eg.
10ç0ç6140314101  02368A794 004 01000081224081223AAAPA    000000011270000000A000000024340000A         
2000000024340000A000000024340000A000000000000000A000000000000000A000000000000000A000000000000000A    
3000000000000000A000000000000000A00000023858A00000023858A00000000000A00000000000A00000A 2AçAAVLAA    
4AAEAACAA AEACOA     AAAL EAUAAY AAVEAAOA                                                            
5                    000000000000000A000000000000000A000000000000000A                                
6             00000033917C00000033917CH06        AEAAE       000000000000000000000A0000000274311A    
7000ç000000A000000000000000000A0000000000        A00000000                                           
As you can see, there is one special character (ç : Cedilla), which i want to replace with "x"

Below is the code i was banging my head with

public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
{
    if (inmsg.BodyPart != null)
    {
    	IBaseMessagePart bodyPart = inmsg.BodyPart;
        Stream sOriginalStream = bodyPart.GetOriginalDataStream();
        if (sOriginalStream != null)
        {
            MemoryStream memStream = new MemoryStream();
            try
            {
                Regex reReplaceChar = new Regex("ç", RegexOptions.None);
                StreamReader sReader = new StreamReader(sOriginalStream);
                StringBuilder sBuilder = null;
                byte[] byteArray = new byte[sOriginalStream.Length];
                while (sReader.Peek() != -1)
                {
                    sBuilder = new StringBuilder(sReader.ReadLine());
                    sBuilder = new StringBuilder(reReplaceChar.Replace(sReader.ReadLine().ToString(), "x"));
                    byteArray = System.Text.Encoding.ASCII.GetBytes(sBuilder.ToString());
                    memStream.Write(byteArray, 0, byteArray.Length);
                }
                bodyPart.Data = memStream;
                memStream.Position = 0;
                inmsg.BodyPart.Data = bodyPart.Data;
                pc.ResourceTracker.AddResource(memStream);
            }
            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry("ReplaceCharacter", "Exception Occurred : " + ex.Message, EventLogEntryType.Error, iEventID, 5);
            }
            finally
            {
            	sBuilder = null;
            	sReader.Close();
            	sReader.Dispose();
            	memStream.Close();
            	memStream.Dispose();
            }
        }
    }
    return inmsg;
}
Problem area for me is:
1. How to loop throu the message?
2. Replace doesn't work, so i created another function which find out the position of the character, remove it and insert "x" (the Replacement Character) at the same position.
3. Not getting the proper message in output.

I am stuck very badly, please help me. 
Thanks a tonne in advance.

Regards
harry
Sol:
Your code is very close - I haven't tried it, but from reading it I think the only problem may be that you're closing the memory stream? 
you're assigning your memory stream to the message you're returning to BizTalk, but then your'e closing the stream, which would inevidebly mean BizTalk won't be able to read the message?

You've correctly added it to the resource tracker which would allow Biztalk to dispose of it when done processing the message, so you should be ok removing the two lines from the finally block.

I would emphasie again the points I've made yesterday - your code will read the entire message to memory, which may cause issues under load, and you really ought to be createing a new message and not replace the stream on the existing one (but while I'm quite strickt on the first point I'll admit to be more 'flexible' on the second sometimes)
 Here, do this - it should work:


The line:

      sBuilder = new StringBuilder(sReader.ReadLine());

Replace with:

      sBuilder = new StringBuilder(sReader.ReadLine(), Encoding.Default);

This will allow your code to recognize your cedilla character.

Then just have ONE string replace line like this in your loop:

      sBuilder = new StringBuilder(sReader.ReadLine().Replace("ç", "x")); 

You don't need any of that Regex stuff.
Here's the test method I just wrote to validate the above.  You can use it for reference.

        private static string BizTalkHelp(string input)
        {
                StreamReader sReader = new StreamReader(@"C:\BizTalkTestDir\sample.txt", Encoding.Default);
                StringBuilder sBuilder = null;
                while (sReader.Peek() != -1)
                {
                    sBuilder = new StringBuilder(sReader.ReadLine().Replace("ç", "x"));
                }
                return sBuilder.ToString();
        }
Read more ...

Solution : Delimited Flat File Schema Misssing Fields At End

Friday, September 30, 2011
Q:
I have a Flat File Schema with records delimited by CRLF and fields delimited by a pipe symbol (|).  Occasionally we receive a record with some of the fields on the end of one record missing.  The file is not being processed correctly.  Since those fields are optional, I would like to be able to accept both type of file.
For example, a normal record might look like this:
TAG1|A1|B1|C1|D1
TAG2|A2|B2|C2|D2|E2|F2
TAG3|A3|B3|C3
But sometimes we get one like this (note that D2, E2, and F2 are missing):
TAG1|A1|B1|C1|D1
TAG2|A2|B2|C2
TAG3|A3|B3|C3
Is there any way that we can accommodate this requirement? I would like for both files to be processed.  The resulting xml should just have empty nodes for the missing fields.
Any help will be appreciated.

Sol:


Use the choice group node in your schema to achieve this. Create a choice group with option for fileds "C2|D2|E2|F2" and for "C2" only. Get more details about choice group from:
or
1) Set the "Allow Early Termination" property on the "schema" node of your flat file schema to "Yes".
2) Then set the "Min Occurs" property on all the fields which are optional to "0".
3) Validate your instance and have fun.

Regards
Read more ...