public Task OnNotificationAsync(Notification notification) { if (AuditingNotificationSubscriber.log.get_IsDebugEnabled()) { AuditingNotificationSubscriber.log.DebugFormat("OnNotification type: {0} SubscriptionId: {1}", (object)notification.get_IndicationType(), (object)notification.get_SubscriptionId()); } PropertyBag propertyBag1 = new PropertyBag(notification.get_SourceInstanceProperties()); PropertyBag propertyBag2 = new PropertyBag(notification.get_IndicationProperties()); if (this.checkAuditingSetting) { try { object obj; if (IndicationHelper.GetIndicationType((IndicationType)2) == notification.get_IndicationType() && propertyBag1 != null && ((string)propertyBag1.TryGet <string>("SettingsID") == "SWNetPerfMon-AuditingTrails" && (string)propertyBag1.TryGet <string>("InstanceType") == "Orion.Settings") && ((Dictionary <string, object>)propertyBag1).TryGetValue("CurrentValue", out obj)) { this.AuditingTrailsEnabled = Convert.ToBoolean(obj); } else if (!this.AuditingTrailsEnabled) { return(Task.CompletedTask); } } catch (Exception ex) { AuditingNotificationSubscriber.log.FatalFormat("Auditing check error - will be forciby enabled. {0}", (object)ex); this.AuditingTrailsEnabled = true; this.checkAuditingSetting = false; } } AuditNotificationContainer auditNotificationContainer = new AuditNotificationContainer(notification.get_IndicationType(), propertyBag2, propertyBag1); IEnumerable <IAuditing2> iauditing2s; if (this.subscriptionIdToAuditingInstances.TryGetValue(notification.get_SubscriptionId().ToString(), out iauditing2s)) { using (IEnumerator <IAuditing2> enumerator1 = iauditing2s.GetEnumerator()) { while (((IEnumerator)enumerator1).MoveNext()) { IAuditing2 current1 = enumerator1.Current; try { if (AuditingNotificationSubscriber.log.get_IsTraceEnabled()) { AuditingNotificationSubscriber.log.TraceFormat("Trying plugin {0}", new object[1] { (object)current1 }); } IEnumerable <AuditDataContainer> source = ((IAuditing)current1).ComposeDataContainers(auditNotificationContainer); if (source != null) { if (AuditingNotificationSubscriber.log.get_IsTraceEnabled()) { AuditingNotificationSubscriber.log.Trace((object)"Storing notification."); } CultureInfo currentUiCulture = Thread.CurrentThread.CurrentUICulture; try { Thread.CurrentThread.CurrentUICulture = LocaleConfiguration.GetNonNeutralLocale(LocaleConfiguration.get_PrimaryLocale()); } catch (Exception ex) { AuditingNotificationSubscriber.log.Warn((object)"Unable set CurrentUICulture to PrimaryLocale.", ex); } using (IEnumerator <AuditDataContainer> enumerator2 = source.Select <AuditDataContainer, AuditDataContainer>((Func <AuditDataContainer, AuditDataContainer>)(composedDataContainer => new AuditDataContainer(composedDataContainer, auditNotificationContainer.get_AccountId()))).GetEnumerator()) { while (((IEnumerator)enumerator2).MoveNext()) { AuditDataContainer current2 = enumerator2.Current; AuditDatabaseDecoratedContainer decoratedContainer = new AuditDatabaseDecoratedContainer(current2, auditNotificationContainer, ((IAuditing)current1).GetMessage(current2)); int insertedId = this.auditingDAL.StoreNotification(decoratedContainer); this.PublishModificationOfAuditingEvents(decoratedContainer, insertedId); } } try { Thread.CurrentThread.CurrentUICulture = currentUiCulture; } catch (Exception ex) { AuditingNotificationSubscriber.log.Warn((object)"Unable set CurrentUICulture back to original locale.", ex); } } else if (AuditingNotificationSubscriber.log.get_IsTraceEnabled()) { AuditingNotificationSubscriber.log.Trace((object)"ComposeDataContainers returned null."); } } catch (Exception ex) { string seed = string.Empty; if (propertyBag2 != null) { seed = ((IEnumerable <KeyValuePair <string, object> >)propertyBag2).Aggregate <KeyValuePair <string, object>, string>(Environment.NewLine, (Func <string, KeyValuePair <string, object>, string>)((current, item) => current + this.FormatPropertyData("Indication Property: ", item.Key, item.Value))); } if (propertyBag1 != null) { seed = ((IEnumerable <KeyValuePair <string, object> >)propertyBag1).Aggregate <KeyValuePair <string, object>, string>(seed, (Func <string, KeyValuePair <string, object>, string>)((current, item) => current + this.FormatPropertyData("SourceInstance Property: ", item.Key, item.Value))); } AuditingNotificationSubscriber.log.ErrorFormat("Auditing translation failed. IndicationType: {0}, {1} PluginName: {2}, subscriptionId: {3} Exception: {4}", new object[5] { (object)notification.get_IndicationType(), (object)seed, (object)((IAuditing)current1).get_PluginName(), (object)notification.get_SubscriptionId(), (object)ex }); } } } } else if (AuditingNotificationSubscriber.log.get_IsDebugEnabled()) { AuditingNotificationSubscriber.log.DebugFormat("No auditing instances has been registered yet for subscriptionId '{0}'", (object)notification.get_SubscriptionId().ToString()); } return(Task.CompletedTask); }
/// <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; } }
/// <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); } }
private static bool ProbeViaLoadedAssemblies( ICollection <Assembly> loadedAssemblies, AssemblyName resolve, string resolveFileName, Assembly requesting, string sourceName, bool isLog, out Assembly resolvedAssembly) { bool first = AssemblySatelliteResolver.EntryCount.GetOrAdd(resolve.Name, (Func <string, AssemblySatelliteResolver.IntRef>)(_ => new AssemblySatelliteResolver.IntRef(0))).Increment() == 1; List <Uri> uriList = new List <Uri>(loadedAssemblies.Count); foreach (Assembly loadedAssembly in (IEnumerable <Assembly>)loadedAssemblies) { AssemblyName name = loadedAssembly.GetName(); if (!(requesting != (Assembly)null) || requesting.Equals((object)loadedAssembly) || name.Name.Equals(sourceName, StringComparison.OrdinalIgnoreCase)) { uriList.AddRange(AssemblySatelliteResolver.GetAssemblyBaseUris(loadedAssembly)); } } List <string> list = AssemblySatelliteResolver.ExpandCulture(resolve.CultureInfo).ToList <string>(); Assembly resolvedAssembly1; if (AssemblySatelliteResolver.ProbeForAssemblySatellite((IEnumerable <Uri>)uriList, list, resolve, resolveFileName, isLog, first, out resolvedAssembly1)) { resolvedAssembly = resolvedAssembly1; return(true); } if (isLog) { string str = string.Format("Cannot resolve \"{0}\".{1}", (object)resolve, AssemblySatelliteResolver.GetDebugStackTrace()); if (resolve.Name.StartsWith("SolarWinds", StringComparison.OrdinalIgnoreCase) && ((IEnumerable <string>)LocaleConfiguration.get_InstalledLocales()).Intersect <string>((IEnumerable <string>)list, (IEqualityComparer <string>)StringComparer.OrdinalIgnoreCase).Any <string>()) { AssemblySatelliteResolver.log.Warn((object)str); } else { AssemblySatelliteResolver.log.Debug((object)str); } } resolvedAssembly = (Assembly)null; return(false); }
// Token: 0x06000027 RID: 39 RVA: 0x000027E0 File Offset: 0x000009E0 public void OnIndication(string subscriptionId, string indicationType, PropertyBag indicationProperties, PropertyBag sourceInstanceProperties) { if (AuditingNotificationSubscriber.log.IsDebugEnabled) { AuditingNotificationSubscriber.log.DebugFormat("OnIndication type: {0} SubscriptionId: {1}", indicationType, subscriptionId); } if (this.checkAuditingSetting) { try { object value; if (IndicationHelper.GetIndicationType(2) == indicationType && sourceInstanceProperties != null && sourceInstanceProperties.TryGet <string>("SettingsID") == "SWNetPerfMon-AuditingTrails" && sourceInstanceProperties.TryGet <string>("InstanceType") == "Orion.Settings" && sourceInstanceProperties.TryGetValue("CurrentValue", out value)) { this.AuditingTrailsEnabled = Convert.ToBoolean(value); } else if (!this.AuditingTrailsEnabled) { return; } } catch (Exception ex) { AuditingNotificationSubscriber.log.FatalFormat("Auditing check error - will be forciby enabled. {0}", ex); this.AuditingTrailsEnabled = true; this.checkAuditingSetting = false; } } AuditNotificationContainer auditNotificationContainer = new AuditNotificationContainer(indicationType, indicationProperties, sourceInstanceProperties); Func <AuditDataContainer, AuditDataContainer> < > 9__0; Func <string, KeyValuePair <string, object>, string> < > 9__1; Func <string, KeyValuePair <string, object>, string> < > 9__2; foreach (IAuditing2 auditing in this.subscriptionIdToAuditingInstances[subscriptionId]) { try { if (AuditingNotificationSubscriber.log.IsTraceEnabled) { AuditingNotificationSubscriber.log.TraceFormat("Trying plugin {0}", new object[] { auditing }); } IEnumerable <AuditDataContainer> enumerable = auditing.ComposeDataContainers(auditNotificationContainer); if (enumerable != null) { if (AuditingNotificationSubscriber.log.IsTraceEnabled) { AuditingNotificationSubscriber.log.Trace("Storing notification."); } CultureInfo currentUICulture = Thread.CurrentThread.CurrentUICulture; try { Thread.CurrentThread.CurrentUICulture = LocaleConfiguration.GetNonNeutralLocale(LocaleConfiguration.PrimaryLocale); } catch (Exception ex2) { AuditingNotificationSubscriber.log.Warn("Unable set CurrentUICulture to PrimaryLocale.", ex2); } IEnumerable <AuditDataContainer> source = enumerable; Func <AuditDataContainer, AuditDataContainer> selector; if ((selector = < > 9__0) == null) { selector = (< > 9__0 = ((AuditDataContainer composedDataContainer) => new AuditDataContainer(composedDataContainer, auditNotificationContainer.AccountId))); } foreach (AuditDataContainer auditDataContainer in source.Select(selector)) { AuditDatabaseDecoratedContainer auditDatabaseDecoratedContainer = new AuditDatabaseDecoratedContainer(auditDataContainer, auditNotificationContainer, auditing.GetMessage(auditDataContainer)); int insertedId = this.auditingDAL.StoreNotification(auditDatabaseDecoratedContainer); this.PublishModificationOfAuditingEvents(auditDatabaseDecoratedContainer, insertedId); } try { Thread.CurrentThread.CurrentUICulture = currentUICulture; continue; } catch (Exception ex3) { AuditingNotificationSubscriber.log.Warn("Unable set CurrentUICulture back to original locale.", ex3); continue; } } if (AuditingNotificationSubscriber.log.IsTraceEnabled) { AuditingNotificationSubscriber.log.Trace("ComposeDataContainers returned null."); } } catch (Exception ex4) { string text = string.Empty; if (indicationProperties != null) { string newLine = Environment.NewLine; Func <string, KeyValuePair <string, object>, string> func; if ((func = < > 9__1) == null) { func = (< > 9__1 = ((string current, KeyValuePair <string, object> item) => current + this.FormatPropertyData("Indication Property: ", item.Key, item.Value))); } text = indicationProperties.Aggregate(newLine, func); } if (sourceInstanceProperties != null) { string seed = text; Func <string, KeyValuePair <string, object>, string> func2; if ((func2 = < > 9__2) == null) { func2 = (< > 9__2 = ((string current, KeyValuePair <string, object> item) => current + this.FormatPropertyData("SourceInstance Property: ", item.Key, item.Value))); } text = sourceInstanceProperties.Aggregate(seed, func2); } AuditingNotificationSubscriber.log.ErrorFormat("Auditing translation failed. IndicationType: {0}, {1} PluginName: {2}, subscriptionId: {3} Exception: {4}", new object[] { indicationType, text, auditing.PluginName, subscriptionId, ex4 }); } } }