none
Party Management [EDI Props] RRS feed

Answers

All replies

  • You can do this using a btstask.exe script

     

    Monday, August 4, 2008 12:11 PM
    Moderator
  •  Ravi Sekhar - MSFT wrote:
    You can do this using a btstask.exe script

     

     

    How to do with it.

    Give us an example would be greatly appreciated

     

    Friday, August 15, 2008 2:48 PM
  • I had a similar problem and used the following dll's to get access to the Edi Parties:

    C:\Program Files\Microsoft BizTalk Server 2006\Microsoft.BizTalk.Deployment.EdiDeployment.dll
    C:\Program Files\Microsoft BizTalk Server 2006\Microsoft.BizTalk.Edi.PartnerAgreementManager.dll
    C:\Program Files\Microsoft BizTalk Server 2006\Developer Tools\Microsoft.BizTalk.ExplorerOM.dll

    ///
    /// Party Helper - Static functions for programatically handling parties in BizTalk Server 2006
    ///
    public class PartyHelper
        {
            /// <summary>
            /// Finds the party using the given party name
            /// </summary>
            /// <param name="server"></param>
            /// <param name="database"></param>
            /// <param name="partyName"></param>
            /// <returns></returns>
            public static Party FindParty(string server, string database, string partyName, bool disposeCatalog)
            {
                Party[] parties = FindPartyRegex(server, database, partyName, disposeCatalog);
                if (parties.Length == 0)
                    return null;
                return parties[0];
            }

            public static bool PartyExists(string server, string database, string partyName)
            {
                return FindParty(server, database, partyName, true) != null;
            }

            /// <summary>
            /// Finds the party using the given party Regex. Returns an array
            /// </summary>
            /// <param name="server"></param>
            /// <param name="database"></param>
            /// <param name="regex"></param>
            /// <returns>the list of parties that match the regex</returns>
            public static Party[] FindPartyRegex(string server, string database, string regexPattern, bool disposeCatalog)
            {
                // create the party list
                List<Party> parties = new List<Party>();

                // initialize the catalog, set the connection string
                BtsCatalogExplorer catalog = new BtsCatalogExplorer();
                catalog.ConnectionString =
                    string.Format("Data Source={0};Initial Catalog={1};Integrated Security=SSPI;",
                                  server,
                                  database);

                // create the regular expression filter
                Regex regex = new Regex(regexPattern, RegexOptions.IgnoreCase);

                // iterate over the parties looking for one that matches our filter
                foreach (Party party in catalog.Parties)
                {
                    if (regex.IsMatch(party.Name))
                    {
                        // add the party to the party list
                        parties.Add(party);
                    }
                }

                // if disposing, dispose the catalog
                if (disposeCatalog)
                    catalog.Dispose();

                // return the party list
                return parties.ToArray();
            }

            /// <summary>
            /// Gets the Edi Party xml for the given edi party
            /// </summary>
            /// <param name="server"></param>
            /// <param name="database"></param>
            /// <param name="partyName"></param>
            /// <returns></returns>
            public static XmlDocument GetEdiPartyXmlDocument(
                string server,
                string database,
                string partyName)
            {
                Microsoft.BizTalk.Edi.PartnerAgreementManager.EdiParty party
                = FindEdiParty(server, database, partyName, true);

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(party.Xml);
                party.Dispose();

                return doc;
            }

            /// <summary>
            ///
            /// </summary>
            /// <param name="serverName"></param>
            /// <param name="datbaseName"></param>
            /// <param name="partyName"></param>
            /// <returns></returns>
            public static string GetEdiPartyXml(
                string serverName,
                string datbaseName,
                string partyName
            )
            {
                // find the party
                Microsoft.BizTalk.Edi.PartnerAgreementManager.EdiParty party
                            = FindEdiParty(serverName, datbaseName, partyName, true);

                // fetch the xml
                string xml = party.Xml;

                // dispose the party object
                party.Dispose();

                // return the xml
                return xml;
            }

            /// <summary>
            /// Creates a new edi party, creating the party first if it does not exist.
            /// Later, changes the config xml for the edi party using xpath replacements
            /// </summary>
            /// <param name="server">The server this edi party will exists</param>
            /// <param name="database"></param>
            /// <param name="partyName"></param>
            /// <param name="xml"></param>
            public static void AddOrEditEdiParty(string server, string database, string partyName, string xml)
            {
                // create the party first
                Party party = AddOrGetParty(server, database, partyName);

                // create the edi party now
                Microsoft.BizTalk.Edi.PartnerAgreementManager.EdiParty ediParty =
                    new Microsoft.BizTalk.Edi.PartnerAgreementManager.EdiParty(party.Name, party.BtsCatalogExplorer.ConnectionString);
               
                // dispose the party catalog
                party.BtsCatalogExplorer.Dispose();
     
                // split the party name by sender / receiver (implement your own logic for party names here)
                // ex:
                //      SENDERID-RECEIVERID
                //      -------------------
                //      12345678-0987654321
                //
                // if no delim (-) is found, then the sender and receiver ids are
                // changed to the party name
                string[] saIdSplit = partyName.Split('-');
                string senderId = saIdSplit.Length > 1 ? saIdSplit[0] : partyName;
                string receiverId = saIdSplit.Length > 2 ? saIdSplit[1] : partyName;

                // Create the property change object
                // Change the Party Name using the new party name
                // Change the sender id using the party name parsed from above
                // Change the receiver id using the party name parsed from above
                EdiPropertyChanger propertyChanger = new EdiPropertyChanger(xml);
                propertyChanger.ChangePartyName(partyName);
                propertyChanger.ChangeSenderId(senderId);
                propertyChanger.ChangeReceiverId(receiverId);

                // Get the modified xml from the property change,
                // save the changes to the object
                ediParty.Xml = propertyChanger.GetResultXml();           
                ediParty.SaveChanges();
                          
                // dispose the edi party
                ediParty.Dispose();
            }

            /// <summary>
            /// first we have to create the party
            /// </summary>
            /// <param name="server"></param>
            /// <param name="database"></param>
            /// <param name="partyName"></param>
            public static Party AddOrGetParty(string server, string database, string partyName)
            {
                // attempt to find the party
                Party party = FindParty(server, database, partyName, true);

                // if the party was not found, create it
                if (party == null)
                {
                    // fetch the catalog
                    BtsCatalogExplorer catalog = CreateCatalogExplorer(server, database);

                    // add the new party, set the name
                    party = catalog.AddNewParty();
                    party.Name = partyName;

                    // commit the changes
                    catalog.SaveChanges();
                }

                // return the newly minted party
                return party;
            }

            public static Microsoft.BizTalk.Edi.PartnerAgreementManager.EdiParty FindEdiParty(
                string server,
                string database,
                string partyName,
                bool closeCatalog)
            {
                Microsoft.BizTalk.Edi.PartnerAgreementManager.EdiParty[] parties
                = FindEdiParties(server, database, partyName, closeCatalog);
                if (parties.Length == 0)
                    return null;
                return parties[0];
            }

            public static Microsoft.BizTalk.Edi.PartnerAgreementManager.EdiParty[] FindEdiParties(
                string server,
                string database,
                string regexPattern,
                bool disposeCatalog)
            {
                // create the party list
                List<Microsoft.BizTalk.Edi.PartnerAgreementManager.EdiParty> ediParties
                    = new List<Microsoft.BizTalk.Edi.PartnerAgreementManager.EdiParty>();

                // initialize the catalog, set the connection string
                BtsCatalogExplorer catalog = CreateCatalogExplorer(server, database);          

                // create the regular expression filter
                Regex regex = new Regex(regexPattern, RegexOptions.IgnoreCase);

                // iterate over the parties looking for one that matches our filter
                foreach (Party party in catalog.Parties)
                {
                    if (regex.IsMatch(party.Name))
                    {
                        try
                        {
                            Microsoft.BizTalk.Edi.PartnerAgreementManager.EdiParty ediParty
                            = new Microsoft.BizTalk.Edi.PartnerAgreementManager.EdiParty(
                                party.Name,
                                catalog.ConnectionString
                            );

                            // add the party to the party list if no errors
                            ediParties.Add(ediParty);
                        }
                        catch (Exception ex)
                        {
                            string exStr = ex.ToString();
                        }                   
                    }
                }

                // if disposing, dispose the catalog
                if (disposeCatalog)
                    catalog.Dispose();

                // return the party list
                return ediParties.ToArray();
            }

            private static BtsCatalogExplorer CreateCatalogExplorer(string server, string database)
            {
                BtsCatalogExplorer catalog = new BtsCatalogExplorer();
                catalog.ConnectionString =
                   string.Format("Data Source={0};Initial Catalog={1};Integrated Security=SSPI;",
                                 server,
                                 database);
                return catalog;
            }
    Monday, September 29, 2008 2:50 PM
  • Hi Patrick,
       I cant found the EdiPropertyChanger class, could you tell me the assembly reference missing?

    Thanks in advance
    Gustavo
    Friday, September 18, 2009 12:50 PM
  • I was hoping there would be an answer to Gustavo's post:  Can you point us to (or give us) the EdiPropertyChanger class? There is precious little information about working with the Edi Properties in code; this looks like my best bet so far.
    Monday, March 1, 2010 9:44 PM
  • I'm sorry to bump this really old thread, but as the 2 posters above mentioned, it would be really helpfull to know where to find that EdiPropertyChanger class.
    Or if someone can point me in the right direction to change the EDI properties of a party in BizTalk through code.

    Monday, August 9, 2010 9:04 AM
  • Hi,

        There is no API as such exposed for changing EDI properties. But you can achieve the same using import binding functionality.

    As you can import binding xmls for Party settings then you can write a smart xml parser and you change settings in the xmls according to your needs and then can import it in Biztalk. I know it's a dirty kinda solution but that is the only available way for changing Edi properties.

     

     

    Thanks

    Gyan


    If this answers your question, please mark it as "Answered".
    Monday, August 9, 2010 3:47 PM
  • Hello All,

    I've managed to solve the issue.
    You can access all the EDI properties you want through the Microsoft.BizTalk.Edi.PartnerAgreementManager.Partner class.

    Please check following code to have an example, it sure did the trick for me.

                Party ediParty = btsCatalog.AddNewParty();   
                ediParty.Name = "OutBoundPartyName";
                ediParty.SendPorts.Add(**BTS Sendport**);
                btsCatalog.SaveChanges();


                Partner pEDI = new Partner(ediParty.Name);
       
                pEDI.EdifactReceiver.Unb3Id = **ReceiverID**;
                pEDI.EdifactReceiver.Unb2Id = **SenderID**;
                pEDI.EdifactSender.Unb3Id = **ReceiverID**;
                pEDI.EdifactSender.Unb2Id = **SenderID**;

                pEDI.Save();

    Wednesday, September 1, 2010 9:08 AM
  • internal override void Save();
    Declaring Type: Microsoft.BizTalk.Edi.PartnerAgreementManager.Partner
    Assembly: Microsoft.BizTalk.Edi.PartnerAgreementManager, Version=3.0.1.0

     

     

     How you were able to use

     pEDI.Save();

     Also all the properties are read only.

     

    Thursday, September 2, 2010 7:57 PM
  •  public class EdiPropertyChanger
        {
            private XmlDocument xDoc;

            public EdiPropertyChanger(string xml)
            {
                this.xDoc = new XmlDocument();
                this.xDoc.LoadXml(xml);
            }

            public EdiPropertyChanger(XmlDocument xml)
            {
                this.xDoc = xml;
            }

            public void ChangePartyName(string format, params string[] parameters)
            {
                // create the new party name
                string newPartyName = string.Format(format, parameters);

                // change the party xpaths
                this.ChangeAllInXPath("//PartyName", newPartyName);
                this.ChangeAllInXPath("//AS2To", newPartyName);
            }

            public void ChangeSenderId(string newSenderId)
            {
                this.ChangeAllInXPath("//PartnerX12[IsSender='false']/Isa6", newSenderId);
            }

            public void ChangeReceiverId(string newReceiverId)
            {
                this.ChangeAllInXPath("//PartnerX12[IsSender='false']/Isa8", newReceiverId);
            }

            public void ChangeAllInXPath(string sXPath, string newValue)
            {
                XmlNodeList nodes = this.xDoc.SelectNodes(sXPath);
                foreach (XmlNode node in nodes)
                    switch (node.NodeType)
                    {
                        case XmlNodeType.Element:
                            if (node.ChildNodes.Count > 0)
                                if (node.ChildNodes[0].NodeType == XmlNodeType.Text)
                                    node.ChildNodes[0].Value = newValue;
                            break;

                        case XmlNodeType.Attribute:
                            node.Value = newValue;
                            break;
                    }
            }

            public string GetResultXml()
            {
                return this.xDoc.OuterXml;
            }
        }

    Tuesday, November 2, 2010 4:54 PM