Ejemplo n.º 1
0
 public static Skill find_by_name(string name)
 {
     try
     {
         return(new Skill(SkillConfigurations.First(item => item.ConfigurationId.DisplayName == name)));
     }
     catch (InvalidOperationException)
     {
         throw new KeyNotFoundException(string.Format("Unable to find a {0} with key {1}", MethodInfo.GetCurrentMethod().DeclaringType.Name, name));
     }
 }
Ejemplo n.º 2
0
        public static void upload(string filepath)
        {
            var data = Helpers.LoadCSV(filepath);

            // Map columns
            var mapper = new CSVMapper {
                DataTable = data
            };

            if (mapper.map("name", new[] { "NAME", "ID", "DISPLAYNAME", "SKILL" }) == -1)
            {
                throw new ArgumentException("Name column not found", "name");
            }
            mapper.map("workgroups", new[] { "WORKGROUP", "WORKGROUPS", "GROUP", "GROUPS" });
            mapper.map("users", new[] { "USER", "USERS", "AGENT", "AGENTS" });

            var configurations = new SkillConfigurationList(ConfigurationManager.GetInstance(Application.ICSession));

            foreach (DataRow row in data.Rows)
            {
                SkillConfiguration skill = null;
                var name = row.Field <string>(mapper["name"]);

                if (string.IsNullOrWhiteSpace(name))
                {
                    continue;
                }
                if (!SkillConfigurations.Any(item => item.ConfigurationId.DisplayName == name))
                {
                    skill = configurations.CreateObject();
                    skill.SetConfigurationId(name);
                    skill.SetDisplayName(name);
                }
                else
                {
                    skill = SkillConfigurations.First(item => item.ConfigurationId.DisplayName == name);
                    skill.PrepareForEdit();
                }
                if (mapper["workgroups"] > -1)
                {
                    skill.WorkgroupAssignments.Value.Clear();
                    Helpers.ParseManySkillSettings(row.Field <string>(mapper["workgroups"])).ForEach(x => skill.WorkgroupAssignments.Value.Add(x));
                }
                if (mapper["users"] > -1)
                {
                    skill.UserAssignments.Value.Clear();
                    Helpers.ParseManySkillSettings(row.Field <string>(mapper["users"])).ForEach(x => skill.UserAssignments.Value.Add(x));
                }
                skill.Commit();
            }
            _SkillConfigurations = null; // So the list is fetched again
        }
 public void Start()
 {
     _logging = Logging.GetInstance();
     _workgroupConfigurations    = new WorkgroupConfigurations();
     _skillConfigurations        = new SkillConfigurations();
     _agentConfigurations        = new AgentConfigurations();
     _agentLicenseConfigurations = new AgentLicenseConfigurations();
     _scheduleConfigurations     = new ScheduleConfigurations();
     _workgroupPeople            = new WorkgroupPeople();
     _workgroupInteractions      = new WorkgroupInteractions();
     _agentAvailability          = new AgentAvailability();
     //use ipaddress.tryparse and use dns lookup if it fails
     _server1         = System.Configuration.ConfigurationManager.AppSettings["PrimaryServer"];
     _server2         = System.Configuration.ConfigurationManager.AppSettings["SecondaryServer"];
     _user            = System.Configuration.ConfigurationManager.AppSettings["CicUser"];
     _password        = System.Configuration.ConfigurationManager.AppSettings["CicPassword"];
     _connectAttempts = 0;
     Connect();
 }
Ejemplo n.º 4
0
        public void InitSkills()
        {
            // Add Fake Skill registration
            const string fakeSkillName       = "FakeSkill";
            var          fakeSkillDefinition = new SkillDefinition();
            var          fakeSkillType       = typeof(FakeSkill.FakeSkill);

            fakeSkillDefinition.Assembly = fakeSkillType.AssemblyQualifiedName;
            fakeSkillDefinition.Id       = fakeSkillName;
            fakeSkillDefinition.Name     = fakeSkillName;

            SkillConfigurations.Add(fakeSkillDefinition.Id, Services);

            // Options are passed to the SkillDialog
            SkillDialogOptions = new SkillDialogOptions();
            SkillDialogOptions.SkillDefinition = fakeSkillDefinition;

            // Add the SkillDialog to the available dialogs passing the initialized FakeSkill
            Dialogs.Add(new SkillDialog(fakeSkillDefinition, Services, null, TelemetryClient));
        }
Ejemplo n.º 5
0
        public static Skill find_or_create(string name)
        {
            if (!SkillConfigurations.Any(item => item.ConfigurationId.DisplayName == name))
            {
                try
                {
                    var configurations = new SkillConfigurationList(ConfigurationManager.GetInstance(Application.ICSession));
                    var skill          = configurations.CreateObject();

                    skill.SetConfigurationId(name);
                    skill.SetDisplayName(name);
                    skill.Commit();
                    _SkillConfigurations = null; // So the list is fetched again
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            return(new Skill(SkillConfigurations.First(item => item.ConfigurationId.DisplayName == name)));
        }
        public void InitSkills()
        {
            // Add Fake Skill registration
            const string fakeSkillName       = "FakeSkill";
            var          fakeSkillDefinition = new SkillDefinition();
            var          fakeSkillType       = typeof(FakeSkill.FakeSkill);

            fakeSkillDefinition.Id   = fakeSkillName;
            fakeSkillDefinition.Name = fakeSkillName;

            // Set Assembly name to invalid value
            fakeSkillDefinition.Assembly = "FakeSkill.FakeSkil, Microsoft.Bot.Solutions.Tests, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null";

            SkillConfigurations.Add(fakeSkillDefinition.Id, Services);

            // Options are passed to the SkillDialog
            SkillDialogOptions = new SkillDialogOptions();
            SkillDialogOptions.SkillDefinition = fakeSkillDefinition;

            // Add the SkillDialog to the available dialogs passing the initialized FakeSkill
            Dialogs.Add(new SkillDialog(fakeSkillDefinition, Services, null, null, TelemetryClient, null));
        }
Ejemplo n.º 7
0
        public static Skill create(string name)
        {
            if (SkillConfigurations.Any(item => item.ConfigurationId.DisplayName == name))
            {
                throw new DuplicateKeyException(name, string.Format("Skill {0} already exists", name));
            }
            try
            {
                var configurations = new SkillConfigurationList(ConfigurationManager.GetInstance(Application.ICSession));
                var skill          = configurations.CreateObject();

                skill.SetConfigurationId(name);
                skill.SetDisplayName(name);
                skill.Commit();
                _SkillConfigurations = null; // So the list is fetched again
            }
            catch (Exception e)
            {
                throw e;
            }
            return(new Skill(SkillConfigurations.First(item => item.ConfigurationId.DisplayName == name)));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BotServices"/> class.
        /// </summary>
        /// <param name="botConfiguration">The <see cref="BotConfiguration"/> instance for the bot.</param>
        public BotServices(BotConfiguration botConfiguration, List <SkillDefinition> skills)
        {
            foreach (var service in botConfiguration.Services)
            {
                switch (service.Type)
                {
                case ServiceTypes.AppInsights:
                {
                    var appInsights     = service as AppInsightsService;
                    var telemetryConfig = new TelemetryConfiguration(appInsights.InstrumentationKey);
                    TelemetryClient = new TelemetryClient(telemetryConfig);
                    break;
                }

                case ServiceTypes.Dispatch:
                {
                    var dispatch    = service as DispatchService;
                    var dispatchApp = new LuisApplication(dispatch.AppId, dispatch.SubscriptionKey, dispatch.GetEndpoint());
                    DispatchRecognizer = new TelemetryLuisRecognizer(dispatchApp);
                    break;
                }

                case ServiceTypes.Luis:
                {
                    var luis    = service as LuisService;
                    var luisApp = new LuisApplication(luis.AppId, luis.SubscriptionKey, luis.GetEndpoint());
                    LuisServices.Add(service.Id, new TelemetryLuisRecognizer(luisApp));
                    break;
                }

                case ServiceTypes.QnA:
                {
                    var qna         = service as QnAMakerService;
                    var qnaEndpoint = new QnAMakerEndpoint()
                    {
                        KnowledgeBaseId = qna.KbId,
                        EndpointKey     = qna.EndpointKey,
                        Host            = qna.Hostname,
                    };
                    var qnaMaker = new TelemetryQnAMaker(qnaEndpoint);
                    QnAServices.Add(qna.Id, qnaMaker);
                    break;
                }

                case ServiceTypes.Generic:
                {
                    if (service.Name == "Authentication")
                    {
                        var authentication = service as GenericService;
                        AuthenticationConnections = authentication.Configuration;
                    }

                    break;
                }

                case ServiceTypes.CosmosDB:
                {
                    var cosmos = service as CosmosDbService;

                    CosmosDbOptions = new CosmosDbStorageOptions
                    {
                        AuthKey          = cosmos.Key,
                        CollectionId     = cosmos.Collection,
                        DatabaseId       = cosmos.Database,
                        CosmosDBEndpoint = new Uri(cosmos.Endpoint),
                    };

                    break;
                }
                }
            }

            foreach (var skill in skills)
            {
                var skillConfig = new SkillConfiguration()
                {
                    CosmosDbOptions = CosmosDbOptions,
                    TelemetryClient = TelemetryClient,
                    LuisServices    = LuisServices.Where(l => skill.LuisServiceIds.Contains(l.Key) == true).ToDictionary(l => l.Key, l => l.Value as IRecognizer),
                };

                if (skill.SupportedProviders != null)
                {
                    foreach (var provider in skill.SupportedProviders)
                    {
                        var matches = AuthenticationConnections.Where(x => x.Value == provider);

                        foreach (var match in matches)
                        {
                            skillConfig.AuthenticationConnections.Add(match.Key, match.Value);
                        }
                    }
                }

                foreach (var set in skill.Configuration)
                {
                    skillConfig.Properties.Add(set.Key, set.Value);
                }

                SkillDefinitions.Add(skill);
                SkillConfigurations.Add(skill.Id, skillConfig);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BotServices"/> class.
        /// </summary>
        /// <param name="botConfiguration">The <see cref="BotConfiguration"/> instance for the bot.</param>
        /// <param name="skills">List of <see cref="SkillDefinition"/> for loading skill configurations.</param>
        /// <param name="languageModels">The locale specifc language model configs for each supported language.</param>
        /// <param name="skillEventsConfig">The configuration for skill events.</param>
        public BotServices(BotConfiguration botConfiguration, Dictionary <string, Dictionary <string, string> > languageModels, List <SkillDefinition> skills, List <SkillEvent> skillEventsConfig)
        {
            // Create service clients for each service in the .bot file.
            foreach (var service in botConfiguration.Services)
            {
                switch (service.Type)
                {
                case ServiceTypes.AppInsights:
                {
                    var appInsights = (AppInsightsService)service;
                    if (appInsights == null)
                    {
                        throw new InvalidOperationException("The Application Insights is not configured correctly in your '.bot' file.");
                    }

                    if (string.IsNullOrWhiteSpace(appInsights.InstrumentationKey))
                    {
                        throw new InvalidOperationException("The Application Insights Instrumentation Key ('instrumentationKey') is required to run this sample.  Please update your '.bot' file.");
                    }

                    var telemetryConfig = new TelemetryConfiguration(appInsights.InstrumentationKey);
                    TelemetryClient = new TelemetryClient(telemetryConfig)
                    {
                        InstrumentationKey = appInsights.InstrumentationKey,
                    };

                    break;
                }

                case ServiceTypes.CosmosDB:
                {
                    var cosmos = service as CosmosDbService;

                    CosmosDbOptions = new CosmosDbStorageOptions
                    {
                        AuthKey          = cosmos.Key,
                        CollectionId     = cosmos.Collection,
                        DatabaseId       = cosmos.Database,
                        CosmosDBEndpoint = new Uri(cosmos.Endpoint),
                    };

                    break;
                }

                case ServiceTypes.Generic:
                {
                    if (service.Name == "Authentication")
                    {
                        var authentication = service as GenericService;
                        AuthenticationConnections = authentication.Configuration;
                    }

                    break;
                }
                }
            }

            // Create locale configuration object for each language config in appsettings.json
            foreach (var language in languageModels)
            {
                if (language.Value.TryGetValue("botFilePath", out var botFilePath) && File.Exists(botFilePath))
                {
                    var botFileSecret = language.Value["botFileSecret"];
                    var config        = BotConfiguration.Load(botFilePath, !string.IsNullOrEmpty(botFileSecret) ? botFileSecret : null);

                    var localeConfig = new LocaleConfiguration
                    {
                        Locale = language.Key
                    };

                    foreach (var service in config.Services)
                    {
                        switch (service.Type)
                        {
                        case ServiceTypes.Dispatch:
                        {
                            var dispatch = service as DispatchService;
                            if (dispatch == null)
                            {
                                throw new InvalidOperationException("The Dispatch service is not configured correctly in your '.bot' file.");
                            }

                            if (string.IsNullOrWhiteSpace(dispatch.AppId))
                            {
                                throw new InvalidOperationException("The Dispatch Luis Model Application Id ('appId') is required to run this sample.  Please update your '.bot' file.");
                            }

                            if (string.IsNullOrWhiteSpace(dispatch.SubscriptionKey))
                            {
                                throw new InvalidOperationException("The Subscription Key ('subscriptionKey') is required to run this sample.  Please update your '.bot' file.");
                            }

                            var dispatchApp = new LuisApplication(dispatch.AppId, dispatch.SubscriptionKey, dispatch.GetEndpoint());
                            localeConfig.DispatchRecognizer = new TelemetryLuisRecognizer(dispatchApp);
                            break;
                        }

                        case ServiceTypes.Luis:
                        {
                            var luis = service as LuisService;
                            if (luis == null)
                            {
                                throw new InvalidOperationException("The Luis service is not configured correctly in your '.bot' file.");
                            }

                            if (string.IsNullOrWhiteSpace(luis.AppId))
                            {
                                throw new InvalidOperationException("The Luis Model Application Id ('appId') is required to run this sample.  Please update your '.bot' file.");
                            }

                            if (string.IsNullOrWhiteSpace(luis.AuthoringKey))
                            {
                                throw new InvalidOperationException("The Luis Authoring Key ('authoringKey') is required to run this sample.  Please update your '.bot' file.");
                            }

                            if (string.IsNullOrWhiteSpace(luis.SubscriptionKey))
                            {
                                throw new InvalidOperationException("The Subscription Key ('subscriptionKey') is required to run this sample.  Please update your '.bot' file.");
                            }

                            if (string.IsNullOrWhiteSpace(luis.Region))
                            {
                                throw new InvalidOperationException("The Region ('region') is required to run this sample.  Please update your '.bot' file.");
                            }

                            var luisApp    = new LuisApplication(luis.AppId, luis.SubscriptionKey, luis.GetEndpoint());
                            var recognizer = new TelemetryLuisRecognizer(luisApp, logPersonalInformation: true);
                            localeConfig.LuisServices.Add(service.Id, recognizer);
                            break;
                        }

                        case ServiceTypes.QnA:
                        {
                            var qna         = service as QnAMakerService;
                            var qnaEndpoint = new QnAMakerEndpoint()
                            {
                                KnowledgeBaseId = qna.KbId,
                                EndpointKey     = qna.EndpointKey,
                                Host            = qna.Hostname,
                            };
                            var qnaMaker = new TelemetryQnAMaker(qnaEndpoint, logPersonalInformation: true);
                            localeConfig.QnAServices.Add(qna.Id, qnaMaker);
                            break;
                        }
                        }
                    }

                    LocaleConfigurations.Add(language.Key, localeConfig);
                }
            }

            // Create a skill configurations for each skill in appsettings.json
            foreach (var skill in skills)
            {
                var skillConfig = new SkillConfiguration()
                {
                    CosmosDbOptions = CosmosDbOptions
                };

                foreach (var localeConfig in LocaleConfigurations)
                {
                    skillConfig.LocaleConfigurations.Add(localeConfig.Key, new LocaleConfiguration
                    {
                        LuisServices = localeConfig.Value.LuisServices.Where(l => skill.LuisServiceIds.Contains(l.Key) == true).ToDictionary(l => l.Key, l => l.Value)
                    });
                }

                if (skill.SupportedProviders != null)
                {
                    foreach (var provider in skill.SupportedProviders)
                    {
                        var matches = AuthenticationConnections.Where(x => x.Value == provider);

                        foreach (var match in matches)
                        {
                            skillConfig.AuthenticationConnections.Add(match.Key, match.Value);
                        }
                    }
                }

                foreach (var set in skill.Configuration)
                {
                    skillConfig.Properties.Add(set.Key, set.Value);
                }

                SkillDefinitions.Add(skill);
                SkillConfigurations.Add(skill.Id, skillConfig);
                SkillEvents = skillEventsConfig != null?skillEventsConfig.ToDictionary(i => i.Event) : null;
            }
        }
Ejemplo n.º 10
0
 public static ICollection <Skill> find_all()
 {
     return(SkillConfigurations.Select(item => new Skill(item)).ToList());
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BotServices"/> class.
        /// </summary>
        /// <param name="botConfiguration">The <see cref="BotConfiguration"/> instance for the bot.</param>
        /// <param name="skills">List of <see cref="SkillDefinition"/> for loading skill configurations.</param>
        /// <param name="languageModels">The locale specifc language model configs for each supported language.</param>
        public BotServices(BotConfiguration botConfiguration, Dictionary <string, Dictionary <string, string> > languageModels, List <SkillDefinition> skills)
        {
            // Create service clients for each service in the .bot file.
            foreach (var service in botConfiguration.Services)
            {
                switch (service.Type)
                {
                case ServiceTypes.AppInsights:
                {
                    var appInsights     = service as AppInsightsService;
                    var telemetryConfig = new TelemetryConfiguration(appInsights.InstrumentationKey);
                    TelemetryClient = new TelemetryClient(telemetryConfig);
                    break;
                }

                case ServiceTypes.CosmosDB:
                {
                    var cosmos = service as CosmosDbService;

                    CosmosDbOptions = new CosmosDbStorageOptions
                    {
                        AuthKey          = cosmos.Key,
                        CollectionId     = cosmos.Collection,
                        DatabaseId       = cosmos.Database,
                        CosmosDBEndpoint = new Uri(cosmos.Endpoint),
                    };

                    break;
                }

                case ServiceTypes.Generic:
                {
                    if (service.Name == "Authentication")
                    {
                        var authentication = service as GenericService;
                        AuthenticationConnections = authentication.Configuration;
                    }

                    break;
                }
                }
            }

            // Create locale configuration object for each language config in appsettings.json
            foreach (var language in languageModels)
            {
                var localeConfig = new LocaleConfiguration
                {
                    Locale = language.Key
                };

                var path   = language.Value["botFilePath"];
                var secret = language.Value["botFileSecret"];
                var config = BotConfiguration.Load(path, !string.IsNullOrEmpty(secret) ? secret : null);

                foreach (var service in config.Services)
                {
                    switch (service.Type)
                    {
                    case ServiceTypes.Dispatch:
                    {
                        var dispatch    = service as DispatchService;
                        var dispatchApp = new LuisApplication(dispatch.AppId, dispatch.SubscriptionKey, dispatch.GetEndpoint());
                        localeConfig.DispatchRecognizer = new TelemetryLuisRecognizer(dispatchApp);
                        break;
                    }

                    case ServiceTypes.Luis:
                    {
                        var luis    = service as LuisService;
                        var luisApp = new LuisApplication(luis.AppId, luis.SubscriptionKey, luis.GetEndpoint());
                        localeConfig.LuisServices.Add(service.Id, new TelemetryLuisRecognizer(luisApp));
                        break;
                    }

                    case ServiceTypes.QnA:
                    {
                        var qna         = service as QnAMakerService;
                        var qnaEndpoint = new QnAMakerEndpoint()
                        {
                            KnowledgeBaseId = qna.KbId,
                            EndpointKey     = qna.EndpointKey,
                            Host            = qna.Hostname,
                        };
                        var qnaMaker = new TelemetryQnAMaker(qnaEndpoint);
                        localeConfig.QnAServices.Add(qna.Id, qnaMaker);
                        break;
                    }
                    }
                }

                LocaleConfigurations.Add(language.Key, localeConfig);
            }

            // Create a skill configurations for each skill in appsettings.json
            foreach (var skill in skills)
            {
                var skillConfig = new SkillConfiguration()
                {
                    CosmosDbOptions = CosmosDbOptions,
                    TelemetryClient = TelemetryClient,
                };

                foreach (var localeConfig in LocaleConfigurations)
                {
                    skillConfig.LocaleConfigurations.Add(localeConfig.Key, new LocaleConfiguration
                    {
                        LuisServices = localeConfig.Value.LuisServices.Where(l => skill.LuisServiceIds.Contains(l.Key) == true).ToDictionary(l => l.Key, l => l.Value)
                    });
                }

                if (skill.SupportedProviders != null)
                {
                    foreach (var provider in skill.SupportedProviders)
                    {
                        var matches = AuthenticationConnections.Where(x => x.Value == provider);

                        foreach (var match in matches)
                        {
                            skillConfig.AuthenticationConnections.Add(match.Key, match.Value);
                        }
                    }
                }

                foreach (var set in skill.Configuration)
                {
                    skillConfig.Properties.Add(set.Key, set.Value);
                }

                SkillDefinitions.Add(skill);
                SkillConfigurations.Add(skill.Id, skillConfig);
            }
        }