Feedback

  • Contents
  • Index
 

Sample code

The following code sample uses ININ.Reporting.InteractionDetailsAPI.dll. You can find this, along with ININ.Reporting.Historical.InteractionDetailsAPI.dll and QiHistoryInterfaceLib.dll, in your IC Business Manager Apps directory. This directory is typically C:\Program Files (x86)\Interactive Intelligence\BusinessManagerApps.

  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Data;
  using System.Data.SqlClient;
  using ININ.Reporting.Historical.InteractionDetailsAPI;
  using QiHistoryInterfaceLib;
  namespace InteractionDetailExample
  {
      class Program
      {
          public static readonly string RAW_DATA_SOURCE = @"Data Source=YourSQLServerHere;Initial Catalog=YourDatabaseHere;User Id=YourUserIdHere;password=YourPasswordHere;timeout=600";
         
          static void Main(string[] args)
          {
              DataSet dsRawInteractionDetailRecords = GetInteractionsDataSet();
             
              //Example 1:
              // This method will result in all the data queried from InteractionSegmentDetail be put into memory; be cautious of this method if you're
              // quering a large quantity of data
              DataSet ds = ConvertSegmentDetailToDataSet(dsRawInteractionDetailRecords);
              //continue here with using the resulting tables as necessary...
              //Example 2:
              // This method will return an IDataReader, which means that you can iteate through it, as in the example code, without
              // loading the entire DataSet into memory at once.
              // Note the call to QiHistory.MultipleEventsToXML; this converts the string you see in InteractionSegmentDetail.SegmentLog to XML.
              // The call to InteractionDetailsAPI.AddXMLData converts the XML to an array of 4 .Net System.Data.DataTable objects.
              IDataReader dr = ConvertSegmentDetailToDataReader(dsRawInteractionDetailRecords);
              while (dr.Read())
              {
                  string EventLogXML = QiHistory.MultipleEventsToXML(dr["SegmentLog"].ToString(), false, false, QiHistory.eSchemaType.Localized);
                  DataTable[] dtDetails = InteractionDetailsAPI.AddXMLData(dr["interactionidkey"].ToString(), EventLogXML);
                  //continue here with using the resulting tables as necessary...
              }
              dr.Close();
          }
          static DataSet ConvertSegmentDetailToDataSet(DataSet dsDetailRecords)
          {
              InteractionDetailsAPI.ReportProgress += new EventHandler<IntEventArgs>(InteractionDetailsAPI_ReportProgress);
              DataSet dsConvertedDetailRecords = InteractionDetailsAPI.GetAsDataSet(dsDetailRecords.Tables[0], QiHistory.eSchemaType.Localized);
              return dsConvertedDetailRecords;
          }
          static void InteractionDetailsAPI_ReportProgress(object sender, IntEventArgs e)
          {
              //report progress here if required
          }
          static IDataReader ConvertSegmentDetailToDataReader(DataSet dsDetailRecords)
          {
              IDataReader drSource = GetInteractionsDataReader();
              return drSource;
          }
          #region Utilities
          /// <summary>
          /// Gets some data from InteractionSegmentDetail
          /// </summary>
          /// <returns>A complete DataSet</returns>
          static DataSet GetInteractionsDataSet()
          {
              DataSet dsRet = new DataSet();
              using (SqlConnection dbConnection = new SqlConnection(RAW_DATA_SOURCE))
              {
                  string SQL = "SELECT top 10 InteractionIDKey, SegmentLog FROM InteractionSegmentDetail WHERE ((StartDateTimeUTC >= cast('2014-05-27 04:00:00.000' as DateTime)) AND (StartDateTimeUTC <= cast('2014-05-27 13:59:59.000' as DateTime)))";
                  using (SqlCommand dbCommand = new SqlCommand(SQL, dbConnection))
                  {
                      using (SqlDataAdapter dbAdapter = new SqlDataAdapter(dbCommand))
                      {
                          dbAdapter.Fill(dsRet, "Test");
                          return dsRet;
                      }
                  }
              }
          }
          /// <summary>
          /// Gets some data from InteractionSegmentDetail
          /// </summary>
          /// <returns>an IDataReader for less memory intense processing</returns>
          static IDataReader GetInteractionsDataReader()
          {
              string SQL = "SELECT top 10 InteractionIDKey, SegmentLog FROM InteractionSegmentDetail WHERE ((StartDateTimeUTC >= cast('2014-05-27 05:00:00.000' as DateTime)) AND (StartDateTimeUTC <= cast('2014-05-27 13:59:59.000' as DateTime)))";
              SqlConnection conn = new SqlConnection(RAW_DATA_SOURCE);
              SqlCommand cmd = new SqlCommand(SQL, conn);
              conn.Open();
              SqlDataReader dr = cmd.ExecuteReader();
              return dr;
          }
          #endregion
      }
  }