Siebel Analytics Web Administration Guide > Working with Data and Managing the Web Catalog Using Siebel Analytics Web SOAP API >

Code Example for Writing Web Catalog Information To XML Files Using the Siebel Analytics Web SOAP API


This section provides an example of C# code that uses the Siebel Analytics Web SOAP API. The code extracts Web Catalog information and writes it to XML files.

NOTE:  Some code that appears on a single line in an application development environment may appear on more than one line when the code is printed or viewed online because of page or window size limitations.

using System;
using System.IO;
using System.Web;

using CatalogExport.SAWServices;

namespace CatalogExport
{
   /// <summary>
   /// Summary description for Class1.
   /// </summary>
   class CatalogExport
   {
      static private System.Net.CookieContainer cookies = new System.Net.CookieContainer ();
      static private SAWSessionService m_session = new SAWSessionService ();
      static private WebCatalogService m_WebCatalogService = new WebCatalogService();
      static int m_nCurFileIndex=0;
      static StreamWriter m_curFile = null;
      static int m_nFileMaxlen=1024*1024*5;
      static String m_strExportDir=null;
      static String m_strFilePrefix="catalog";

      static void openFile()
      {
         if (m_curFile== null || m_curFile.BaseStream.Length > m_nFileMaxlen)
         {
            if (m_curFile != null )
            {
               m_curFile.WriteLine("</CatalogRoot>");
               m_curFile.Close();
            }
            String strNewPath = m_strExportDir + "\\" + m_strFilePrefix + (++m_nCurFileIndex) + ".xml";
            m_curFile = new StreamWriter(strNewPath);
            m_curFile.WriteLine("<CatalogRoot>");
         }
      }
      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main(string[] args)
      {
         String strURL="http://localhost/analytics/saw.dll";
         String strUser="Administrator";

         String strPWD="";

         for (int i=0;i<args.Length;++i)
         {
            if (args[i].Equals("/URL"))
               strURL = args[++i];
            else if (args[i].Equals("/USER"))
               strUser = args[++i];
            else if (args[i].Equals("/PWD"))
               strPWD = args[++i];
            else if (args[i].Equals("/DIR"))
               m_strExportDir = args[++i];
            else if (args[i].Equals("/?"))
            {
               printUsage();
               return;
            }
         }

         if (m_strExportDir == null)
         {
            printUsage();
            return;
         }
         Directory.CreateDirectory(m_strExportDir);
         //let all services use the same cookie container - so all of them
         //would have access to Session cookie
         m_WebCatalogService.CookieContainer = cookies;
         m_session.CookieContainer = cookies;
         m_session.Url = strURL + "?SoapImpl=nQSessionService";
         m_WebCatalogService.Url = strURL + "?SoapImpl=webCatalogService";
         String sessionID = m_session.logon(strUser,strPWD);
         try
         {
            processCatalogFolder("/",sessionID);
         }
         finally
         {
            if (m_curFile != null )
            {
               m_curFile.WriteLine("</CatalogRoot>");
               m_curFile.Close();
            }
         }
         
      }

      static void processCatalogFolder(string path,string sessionID)
      {
         ItemInfo[] arrChilds = m_WebCatalogService.getSubItems(path,"*",false,null,sessionID);
         foreach (ItemInfo info in arrChilds)
         {
            switch (info.type)
            {
               case ItemInfoType.Folder:
                  try
                  {
                     processCatalogFolder(info.path,sessionID);
                  }
                  catch (Exception e)
                  {
                     Console.WriteLine(e.Message);
                  }

                  continue;
               case ItemInfoType.Object:
               {
                  if (!isKnownSignature(info.signature))
                     continue;
                  openFile();
                  CatalogObject co = m_WebCatalogService.readObject(info.path,true,sessionID);
                  m_curFile.WriteLine("<CatalogObj path=\"" + HttpUtility.HtmlEncode(info.path) + "\" signature=\"" + info.signature +"\">");
                  m_curFile.WriteLine(co.catalogObject.ToString());
                  m_curFile.WriteLine("</CatalogObj>");
                  break;
               }
            }
         }

      }

      static bool isKnownSignature(string strSignature)
      {
         return strSignature=="dashboardpageitem1" ||
               strSignature=="dashboarditem1" ||
               strSignature=="queryitem1" ||
               strSignature=="dashboarditem1" ||
         strSignature=="globalfilteritem1" ||
         strSignature=="filteritem1" ||
         strSignature=="COXmlDocument1";
      }
      static void printUsage()
      {
         Console.WriteLine("CatalogExport /DIR exportdir [/USER usename] [/PWD password] [/URL serverurl]");
      }
   }
}

Siebel Analytics Web Administration Guide