Click here to Skip to main content
15,886,059 members
Articles / Programming Languages / C#

Fax Adapter

Rate me:
Please Sign up or sign in to vote.
3.62/5 (13 votes)
28 Sep 2006CPOL4 min read 63.5K   994   31  
Fax Adapter for BizTalk Server 2006
//---------------------------------------------------------------------
// File: Batch.cs
// 
// Summary: Implementation of an adapter framework sample adapter. 
// This class constitutes one of the BaseAdapter classes, which, are
// a set of generic re-usable set of classes to help adapter writers.
//
// Sample: Base Adapter Class Library v1.0.2
//
// Description: Helper functions to deal with Configuration XML DOM
//
//---------------------------------------------------------------------
// This file is part of the Microsoft BizTalk Server 2006 SDK
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// This source code is intended only as a supplement to Microsoft BizTalk
// Server 2006 release and/or on-line documentation. See these other
// materials for detailed information regarding Microsoft code samples.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
// PURPOSE.
//---------------------------------------------------------------------

using System;
using System.Xml;
using Microsoft.BizTalk.Component.Interop;

namespace Microsoft.Samples.BizTalk.Adapter.Common
{
    /// <summary>
	/// Summary description for ConfigProperties.
    /// </summary>
    public class ConfigProperties
    {
        // Various useful helper functions
        public static XmlDocument ExtractConfigDomImpl (IPropertyBag pConfig, bool required)
        {
            object obj = null;
            pConfig.Read("AdapterConfig", out obj, 0);
            if (!required && null == obj)
                return null;
            if (null == obj)
                throw new NoAdapterConfig();

            XmlDocument configDom = new XmlDocument();

            string adapterConfig = (string)obj;
            configDom.LoadXml(adapterConfig);

            return configDom;
        }

        public static XmlDocument ExtractConfigDom (IPropertyBag pConfig)
        {
            return ExtractConfigDomImpl(pConfig, true);
        }

        public static XmlDocument IfExistsExtractConfigDom (IPropertyBag pConfig)
        {
            return ExtractConfigDomImpl(pConfig, false);
        }

        public static string ExtractImpl (XmlDocument document, string path, bool required, string alt)
        {
            XmlNode node = document.SelectSingleNode(path);
            if (!required && null == node)
                return alt;
            if (null == node)
                throw new NoSuchProperty(path);
            return node.InnerText;
        }

        public static string IfNotEmptyExtract(XmlDocument document, string path, bool required, string alt)
        {
            XmlNode node = document.SelectSingleNode(path);
            if (!required && (null == node || 0 == node.InnerText.Length) )
                return alt;
            if (null == node)
                throw new NoSuchProperty(path);
            return node.InnerText;
        }

        public static string Extract (XmlDocument document, string path, string alt)
        {
            return ExtractImpl(document, path, true, alt);
        }
        
        public static string IfExistsExtract (XmlDocument document, string path, string alt)
        {
            return ExtractImpl(document, path, false, alt);
        }

        public static int ExtractInt (XmlDocument document, string path)
        {
            string s = Extract(document, path, String.Empty);
            return int.Parse(s);
        }

        public static int IfExistsExtractInt (XmlDocument document, string path, int alt)
        {
            string s = IfExistsExtract(document, path, String.Empty);
            if (0 == s.Length)
                return alt;
            return int.Parse(s);
        }

        public static long ExtractLong (XmlDocument document, string path)
        {
            string s = Extract(document, path, String.Empty);
            return long.Parse(s);
        }

        public static long IfExistsExtractLong (XmlDocument document, string path, long alt)
        {
            string s = IfExistsExtract(document, path, String.Empty);
            if (0 == s.Length)
                return alt;
            return long.Parse(s);
        }

		public static bool ExtractBool(XmlDocument document, string path)
		{
			string s = Extract(document, path, String.Empty);
			return Boolean.Parse(s);
		}

        public static bool IfExistsExtractBool(XmlDocument document, string path, bool alt)
        {
            string s = IfExistsExtract(document, path, String.Empty);
            if (0 == s.Length)
                return alt;
            return Boolean.Parse(s);
        }

        public static long ExtractPollingInterval (XmlDocument document)
        {
            long pollingInterval = ExtractInt(document, "/Config/pollingInterval");
            string pollingUnitOfMeasureStr = Extract(document, "/Config/pollingUnitOfMeasure", "Seconds");

            switch (pollingUnitOfMeasureStr)
            {
                case "Seconds": //  do nothing: seconds is the default
                    break;
                case "Minutes": pollingInterval *= 60;
                    break;
                case "Hours":   pollingInterval *= (60 * 60);
                    break;
                case "Days":    pollingInterval *= (60 * 60 * 24);
                    break;
            }
            return pollingInterval;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
India India
Anil is from Hyderabad, Andhra Pradesh. He is Currently Working with VisualSoft Technologies Ltd., As a Software Engineer.

Anil has more than 4 yrs of experience in the IT industry working on Microsoft Technologies. He is involved in various project activities like System Architecture, Design, and Development. Technical experience most specifically ASP.NET , Javascript, Biztalk 2004/2006, Webservices, C# and .NET framework. He has have worked on various language and platforms. He is Microsoft Certified professional.

The author has won several programming awards within the organizations worked and is well-recognized.


--

Comments and Discussions