PureConnect

 View Only
Discussion Thread View
  • 1.  iceLib : Roles & Workgroups lists assigned to a user always empty

    Posted 03-27-2019 17:24
    Hi,

    I am trying to manage Roles and Workgroups associated to users with iceLib. I am able to assign Roles and Workgroups but I am not able to get currently assigned Roles and Workgroups for a user. The list is always empty when I read a user.

    Here is the code:
    using ININ.IceLib.Configuration;
    using ININ.IceLib.Connection;
    using System;
    using System.Collections.Generic;
    
    namespace TestIceLib
    {
        class Program
        {
            Session session;
    
            void connect()
            {
                session = new Session();
    
                SessionSettings sessionSettings = new SessionSettings();
                sessionSettings.ClassOfService = ClassOfService.General;
                sessionSettings.IsoLanguage = "en-US";
                sessionSettings.ApplicationName = "testApplication";
    
                HostSettings hostSettings = new HostSettings();
                hostSettings.HostEndpoint = new HostEndpoint("localhost", HostEndpoint.DefaultPort);
                var UserName = "";
                var Password = "";
    
                AuthSettings authSettings;
                if (String.IsNullOrEmpty(UserName) || Password == null)
                {
                    authSettings = new WindowsAuthSettings();
                }
                else
                {
                    authSettings = new ICAuthSettings(UserName, Password);
                }
    
                StationSettings stationSettings = new StationlessSettings();
    
                session.Connect(sessionSettings, hostSettings, authSettings, stationSettings);
            }
            UserConfiguration getUser(string id)
            {
                ConfigurationManager manager = ConfigurationManager.GetInstance(session);
                UserConfigurationList userConfigurationList = new UserConfigurationList(manager);
    
                List<FilterDefinition<UserConfiguration, UserConfiguration.Property>> filterDefinitions =
                        new List<FilterDefinition<UserConfiguration, UserConfiguration.Property>>();
    
                if (id != null)
                {
                    filterDefinitions.Add(
                            new BasicFilterDefinition<UserConfiguration, UserConfiguration.Property>(
                                    UserConfiguration.Property.Id, id, FilterMatchType.Exact));
                }
    
    
                QuerySettings<UserConfiguration, UserConfiguration.Property> watchSettings = userConfigurationList.CreateQuerySettings();
    
                watchSettings.SetFilterDefinition(
                    new GroupFilterDefinition<UserConfiguration, UserConfiguration.Property>(filterDefinitions));
    
                userConfigurationList.StartCaching(watchSettings);
    
                foreach (UserConfiguration user in userConfigurationList.GetConfigurationList())
                {
                    return user;
                }
                return null;
            }
    
            void disconnect()
            {
                session.Disconnect();
            }
            static void Main(string[] args)
            {
                var app = new Program();
                app.connect();
    
                var user = app.getUser("donald.hamel");
                if (user != null)
                {
                    Console.WriteLine("nb workgroup: " + user.Workgroups.Value.Count);
                }
    
                app.disconnect();
            }
        }
    }
    Does anyone knows what is my issue?

    Thanks,
    #Unsure/Other

    ------------------------------
    Donald

    ------------------------------


  • 2.  RE: iceLib : Roles & Workgroups lists assigned to a user always empty
    Best Answer

    Posted 03-28-2019 08:59
    I don't currently have an environment to run this against, but at first glance it does not appear that your watch settings are actually watching the role or workgroup properties for the user.

    ------------------------------
    Sean Walls
    ------------------------------



  • 3.  RE: iceLib : Roles & Workgroups lists assigned to a user always empty

    Posted 03-28-2019 09:42
    Thanks for the hint! Adding this line of code fixed it:

    watchSettings.SetPropertiesToRetrieveToAll();



    ------------------------------
    Donald Hamel
    Bell Canada
    ------------------------------



  • 4.  RE: iceLib : Roles & Workgroups lists assigned to a user always empty

    Posted 03-28-2019 10:58
    Hey Donald!

    Glad you got a solution to your question.

    Please make sure to mark Sean's answer as the one that helped - it adds to his "reputation" and allows others to see this question has been answerdd :-)


  • 5.  RE: iceLib : Roles & Workgroups lists assigned to a user always empty

    Posted 03-28-2019 12:36

    Also, don't forget to stop your watches:


    try
    {
        ...
        userConfigurationList.StartCaching(watchSettings);
        ...
    }
    catch
    {
        ...
    }
    finally
    {
        if (userConfigurationList.IsWatching())
        {
            userConfigurationList.StopWatching();
        }
    }



    ------------------------------
    Ivan Sazonov
    UMA Education, Inc.
    ------------------------------



  • 6.  RE: iceLib : Roles & Workgroups lists assigned to a user always empty

    Posted 03-28-2019 13:59
    Do you think it is an issue if the application terminates without calling StopWatching() ?

    ------------------------------
    Donald Hamel
    Bell Canada
    ------------------------------



  • 7.  RE: iceLib : Roles & Workgroups lists assigned to a user always empty

    Posted 03-28-2019 14:08
    Edited by Ivan Sazonov 03-28-2019 14:08
    As far as I understand, calling StartWatching() creates a watch on the server side so that it can notify the watcher on the client side of any changes. If the application terminates without calling StopWatching(), it'll keep sending messages to the application, even though it's not there anymore, thus the resources on the server are still allocated. We've ran into this with hundreds of client applications each starting a watch for a custom notification very frequently and never stopping it, which then started to considerably reduce resources on the server.

    ------------------------------
    Ivan Sazonov
    UMA Education, Inc.
    ------------------------------



  • 8.  RE: iceLib : Roles & Workgroups lists assigned to a user always empty

    Posted 03-28-2019 15:16
    Edited by Paul Simpson 03-28-2019 15:16
    In theory, the system should eventually "realize" and clean up. But it won't be quick and, depending on how many of these are running, the resulting "orphaned" watches could put significant drain on Server resources.

    As I always tell my students in a situation like this... "Don't behave like a teenager and expect your parents to pick up after you. Put your own laundry in the basket..." Since the time taken and coding effort needed to tidy up and release resources correctly is negligable, the real question is "why wouldn't you"?

    Just my 10 cents

    ------------------------------
    Paul Simpson
    Senior Technical Instructor
    ------------------------------



  • 9.  RE: iceLib : Roles & Workgroups lists assigned to a user always empty

    Posted 03-28-2019 15:37
    It is a good question. In my case, I have developed cmdlets for all configuration objects available in iceLib. I have cmdlets like Get-User, Get-Role... The PowerShell script will get a user and then may need to edit it so Get-User cannot call StopCaching right away. I will probably call StopCaching when cmdlet Close-Session is called. I think it will work.

    Thanks for all your answers.

    ------------------------------
    Donald Hamel
    Bell Canada
    ------------------------------



Need Help finding something?

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