PureConnect

 View Only
Discussion Thread View
  • 1.  How to use ICWS C# Library to retrieve configuration data?

    Posted 04-30-2020 17:19
    I'm trying to get some config data (ie, workstations, users, skills, etc) using a C# app and the #ICWS C# DLLs.  However, the provided example is not very helpful and there seems to be zero other documentation.  Can anyone provide some guidance on simple retrieval of data using this library, rather than using it for managing calls?  I'd really appreciate it!
    #Handlers
    #Integrations
    #Unsure/Other

    ------------------------------
    Tyler Style
    Interactive Intelligence Engineer, WellCare Health Plans
    ------------------------------


  • 2.  RE: How to use ICWS C# Library to retrieve configuration data?

    Posted 05-01-2020 09:39
    For the record, I gave up on trying to puzzle this out and just wrote my own using RestSharp.  Took about an hour.  I'd still like to know if anyone can shed light on it, though!

    ------------------------------
    Tyler Style
    Interactive Intelligence Engineer, WellCare Health Plans
    ------------------------------



  • 3.  RE: How to use ICWS C# Library to retrieve configuration data?

    Posted 05-01-2020 12:18
    Tyler,

    Have you looked at ICELib? This is the .Net API for doing this kind of thing.

    If you could describe what you are trying to achieve, we migth be able to offer some advice.

    For example,
    Are you looking for a "snapshot" or do you need data that gets updated in real time?
    Are you trying to get information on all objects of a particular type (say all Users) or specific ones?

    We'll do our best to assist!


  • 4.  RE: How to use ICWS C# Library to retrieve configuration data?

    Posted 06-09-2020 15:14
    Thanks Paul - sorry for the super late follow up.

    My understanding from when I was at CX17 was that ICELib wasn't being actively developed anymore, and that devs should be switching to ICWS?

    What I'm mostly trying to do is provide a tool to sync our dev, uat and prod environments so that they don't get so far out of whack that they're useless.  I've also got an eye towards automating some of our change management - ie, using tools to push changes instead of manual updates across instances, as we wind up with ridiculous copy/paste and character encoding irregularities (eg, em-dash instead of two dashes, smart quotes, white space issues, etc.)

    ------------------------------
    Tyler Style
    Interactive Intelligence Engineer, WellCare Health Plans
    ------------------------------



  • 5.  RE: How to use ICWS C# Library to retrieve configuration data?

    Posted 05-01-2020 15:04
    Edited by Douglas Suyemoto 05-01-2020 15:28
    Hi Tyler,

    Here is some code I use to make the initial connection, referencing "ININ.ICWS.Managed.dll" and "ININ.Webservices.Core.dll":

    using ININ.ICWS;
    using ININ.ICWS.Common;
    using ININ.ICWS.Connection;
    using ININ.WebServices.Core;
    using System;
    using System.Collections.Generic;
    using static ININ.ICWS.Connection.ConnectionResource;
    
    namespace PureConnect
    {
        public class ININService : IININService
        {
            private WebServiceUtility _webServiceUtility;
            private CreateConnectionRequestParameters _createConnectionRequestParameters;
            private IcAuthConnectionRequestSettingsDataContract _icAuthConnectionRequestSettingsDataContract;
            private List<string> _connectAlternateHosts = new List<string>();
            private bool _tryingBackupServer = false;
    
            public bool IsConnected { get; private set; } = false;
    
            public ININService()
            {
                _createConnectionRequestParameters = new CreateConnectionRequestParameters()
                {
                    Accept_Language = "en-us",
                    Include = "features"
                };
                _icAuthConnectionRequestSettingsDataContract = new IcAuthConnectionRequestSettingsDataContract()
                {
                    ApplicationName = "PureConnectService",
                };
            }
    
            public WebServiceUtility Connect(ININServerCredentials ininServerCredentials)
            {
                return Connect(ininServerCredentials.Server, ininServerCredentials.Username, ininServerCredentials.Password);
            }
    
            public WebServiceUtility Connect(string server, string username, string password, int maxTries=3)
            {
                _icAuthConnectionRequestSettingsDataContract.UserID = username;
                _icAuthConnectionRequestSettingsDataContract.Password = password;
    
                ConnectServer(server);
    
                return _webServiceUtility;
            }
    
            private void ConnectServer(string server)
            {
                IsConnected = false;
                _webServiceUtility = new WebServiceUtility()
                {
                    Port = 8018,
                    IsHttps = false,
                    Server = server
                };
    
                var result = new ConnectionResource(_webServiceUtility)
                    .CreateConnection(
                        _createConnectionRequestParameters,
                        _icAuthConnectionRequestSettingsDataContract).Result;
                
                result.PerformIfResponseIs201(response => HandleConnection201(response, result.Set_Cookie));
                result.PerformIfResponseIs400(response => HandleConnectionError(response));
                result.PerformIfResponseIs410(response => HandleConnectionError(response));
                result.PerformIfResponseIs503(response => HandleConnection503(response));
            }
    
            private void HandleConnection201(ConnectionResponseDataContract response, string cookie)
            {
                _webServiceUtility.SessionParameters =
                    new AuthenticationParameters
                    {
                        SessionId = response.SessionId,
                        Cookie = cookie,
                        ININ_ICWS_CSRF_Token = response.CsrfToken
                    };
    
                IsConnected = true;
                _connectAlternateHosts.Clear();
                _tryingBackupServer = false;
            }
    
            private void HandleConnectionError(ErrorDataContract errorDataContract)
            {
                throw new Exception(errorDataContract.Message);
            }
    
            private void HandleConnection503(AlternateHostsDataContract response)
            {
                if (response.AlternateHostListHasValue && !_tryingBackupServer)
                {
                    _connectAlternateHosts = response.AlternateHostList;
                    _tryingBackupServer = true;
                }
                if (!IsConnected && _connectAlternateHosts.Count > 0)
                {
                    var alternateHost = _connectAlternateHosts[0];
                    _connectAlternateHosts.Remove(alternateHost);
                    ConnectServer(alternateHost);
                }
            }
        }
    }

     This essentially uses callbacks to capture the responses and adds it back to the webservice so that you can use the connection to make further calls to resources. For example, to get information about an interaction, you would use the following code:

    using ININ.ICWS.Interactions;
    using System.Threading.Tasks;
    using static ININ.ICWS.Interactions.InteractionsResource;
    
    namespace PureConnect
    {
        public class ININInteractionsResource : IININInteractionsResource
        {
            IININService _ininService;
            InteractionsResource _interactionsResource;
    
            public ININInteractionsResource(IININService ininService)
            {
                _ininService = ininService;
            }
    
            public void Connect(string server, string username, string password)
            {
                _interactionsResource = new InteractionsResource(_ininService.Connect(server, username, password));
            }
    
            public async Task<ININGetInteractionAttributesResponse> GetInteractionAttributesAsync(
                ININGetInteractionAttributesRequestParameters ininGetInteractionAttributesRequestParameters
                )
            {
                return new ININGetInteractionAttributesResponse(
                    await _interactionsResource.GetInteractionAttributes(
                        new GetInteractionAttributesRequestParameters()
                        {
                            InteractionId = ininGetInteractionAttributesRequestParameters.InteractionId,
                            Select = ininGetInteractionAttributesRequestParameters.Select
                        }));
            }
        }
    }
    

    Here is sample code to initialize and get attribute info from an interaction:

    var ininInteractionsResource = new ININInteractionsResource(new ININService());
    
    ininInteractionsResource.Connect("serverName", "username", "password");
    
    var interactionId = "12345678";
    var attributeNames = new string[]{ "Eic_Note" };
    
    var responses = ininInteractionsResource.GetInteractionAttributesAsync(
                        new ININGetInteractionAttributesRequestParameters()
                        {
                            InteractionId = interactionId,
                            Select = string.Join(",", attributeNames)
                        }
                        ).Result;

    Keep in mind I've created wrappers around the ININ classes, so they are referenced here with ININ in the class names so they won't resolve if you just copy and paste in VS, but hopefully this should clarify how to create the code.  If you need all the wrapper classes, let me know and I think I can upload them. Also, you don't need to defer the connection until the method call like I am doing, you can simply initialize the web service using the credentials, make the connection, then inject them into the resource.

    Essentially, you need to find out which resource you need, initialize that resource, inject the webservice and use it to retrieve the resources data.  For example, if you need to retrieve user info, use the following class: 

    ININ.ICWS.Configuration.People.UsersResource


    Which contains all the CRUD operations for the user class/resource.  You can look at the object browser in VS for ININ.ICWS.Managed.dll or you can even look in the ICWS reference library on the Genesys website, since they're essentially the same to find out which resource you need to use.



    ------------------------------
    Douglas Suyemoto
    Latham & Watkins LLP
    ------------------------------



  • 6.  RE: How to use ICWS C# Library to retrieve configuration data?

    Posted 06-09-2020 16:07
    Thanks Douglas - and sorry for the very late reply, life kept on happening to me...

    I really appreciate the examples, but since they're abstracted away from the actual ICWS code and the resultant wrappers are missing - coupled with my inexperience with C# and my unfamiliarity with the referenced assemblies - makes them almost unintelligible to me. I'm just missing too many key assumptions and understandings.  I'm sure with an actual bare bones example of a simple fetch for something like a Schedule or User I could make headway from that but as it is it's all just a huge wall of thousands of classes with nothing really showing how they work together to produce results.

    ------------------------------
    Tyler Style
    Interactive Intelligence Engineer, WellCare Health Plans
    ------------------------------



  • 7.  RE: How to use ICWS C# Library to retrieve configuration data?

    Posted 06-12-2020 03:50
    Edited by Douglas Suyemoto 06-12-2020 03:52
    Here is a simpler example in C# to retrieve user properties.

            public void Execute()
            {
                // Configures web service utility
                WebServiceUtility webServiceUtility = new WebServiceUtility()
                {
                    Port = 8018,
                    IsHttps = false,
                    Server = "name_of_server"
                };
                Console.WriteLine(webServiceUtility.Port);
    
                //Initializes/authenticates web service utility with CIC server
                var result = new ConnectionResource(webServiceUtility).CreateConnection(
                        new CreateConnectionRequestParameters()
                        {
                            Accept_Language = "en-us",
                            Include = "features"
                        },
                        new IcAuthConnectionRequestSettingsDataContract()
                        {
                            UserID = "cic_user_id",
                            Password = "cic_user_password",
                            ApplicationName = "PureConnectService",
                        }).Result;
                Console.WriteLine(result.ININ_ICWS_Session_ID);
    
                //Retrieves response from CIC server and caches token/cookie for web service utility
                result.PerformIfResponseIs201(response => {
                    webServiceUtility.SessionParameters =
                    new AuthenticationParameters
                    {
                        SessionId = response.SessionId,
                        Cookie = result.Set_Cookie,
                        ININ_ICWS_CSRF_Token = response.CsrfToken
                    };
                });
                Console.WriteLine(result.StatusCode);
    
                //Retrieves user using user ID and writes out skills of user
                UsersResource usersResource = new UsersResource(webServiceUtility);
                UsersResource.GetUserResponses userResult = usersResource.GetUser(new UsersResource.GetUserRequestParameters()
                {
                    Id = "cic_user_id"
                }).Result;
                Console.WriteLine(userResult.StatusCode);
    
                userResult.PerformIfResponseIs200(u => {
                    if (u.SkillsHasValue)
                        Console.WriteLine(u.Skills);
                });
            }

    To sum up, you need to create the WebServiceUtility which will be used to pass to the resource you wish to retrieve, then use a callback to retrieve the response from the web service.  Keep in mind, this example leaves out the ability to try a second server if you are running a server as backup, so you should always use the active server in the server name.

    ------------------------------
    Douglas Suyemoto
    Latham & Watkins LLP
    ------------------------------



  • 8.  RE: How to use ICWS C# Library to retrieve configuration data?

    Posted 06-12-2020 09:04
    Thank you @Douglas Suyemoto, that looks like exactly the kind of hint I need!  I shall give it a whirl ASAP.​​

    ------------------------------
    Tyler Style
    Interactive Intelligence Engineer, WellCare Health Plans
    ------------------------------



Need Help finding something?

Check out the Genesys Knowledge Network - your all-in-one access point for Genesys resources