private void ReadConfigurationSettings() { // Read sql database connectionstring setting sqlDatabaseConnectionString = CloudConfigurationHelper.GetSetting(SqlDatabaseConnectionStringSetting); TraceEventSource.Log.TraceInfo(string.Format(RoleEnvironmentSettingFormat, SqlDatabaseConnectionStringSetting, sqlDatabaseConnectionString)); // Read insert stored procedure setting insertStoredProcedure = CloudConfigurationHelper.GetSetting(InsertStoredProcedureSetting); TraceEventSource.Log.TraceInfo(string.Format(RoleEnvironmentSettingFormat, InsertStoredProcedureSetting, insertStoredProcedure)); // Read storage account connectionstring setting storageAccountConnectionString = CloudConfigurationHelper.GetSetting(StorageAccountConnectionStringSetting); TraceEventSource.Log.TraceInfo(string.Format(RoleEnvironmentSettingFormat, StorageAccountConnectionStringSetting, storageAccountConnectionString)); // Read service bus connectionstring setting serviceBusConnectionString = CloudConfigurationHelper.GetSetting(ServiceBusConnectionStringSetting); TraceEventSource.Log.TraceInfo(string.Format(RoleEnvironmentSettingFormat, ServiceBusConnectionStringSetting, serviceBusConnectionString)); // Read event hub name setting eventHubName = CloudConfigurationHelper.GetSetting(EventHubNameSetting); TraceEventSource.Log.TraceInfo(string.Format(RoleEnvironmentSettingFormat, ServiceBusConnectionStringSetting, serviceBusConnectionString)); // Read event consumer group name setting consumerGroupName = CloudConfigurationHelper.GetSetting(ConsumerGroupNameSetting); TraceEventSource.Log.TraceInfo(string.Format(RoleEnvironmentSettingFormat, ServiceBusConnectionStringSetting, serviceBusConnectionString)); }
/// <summary> /// Occurs before a change to the service configuration is applied to the running instances of a role. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">presents the arguments for the Changing event, which occurs before a configuration change is applied to a role instance. </param> private static void RoleEnvironment_Changing(object sender, RoleEnvironmentChangingEventArgs e) { try { // TraceIn TraceEventSource.Log.TraceIn(); // Get the list of configuration setting changes var settingChanges = e.Changes.OfType <RoleEnvironmentConfigurationSettingChange>(); foreach (var settingChange in settingChanges) { var value = CloudConfigurationHelper.GetSetting(settingChange.ConfigurationSettingName); TraceEventSource.Log.TraceInfo(string.Format(RoleEnvironmentConfigurationSettingChangingFormat, settingChange.ConfigurationSettingName, string.IsNullOrEmpty(value) ? string.Empty : value)); } // Get the list of configuration changes var topologyChanges = e.Changes.OfType <RoleEnvironmentTopologyChange>(); foreach (var roleName in topologyChanges.Select(topologyChange => topologyChange.RoleName)) { TraceEventSource.Log.TraceInfo(string.Format(RoleEnvironmentTopologyChangingFormat, string.IsNullOrEmpty(roleName) ? Unknown : roleName)); if (string.IsNullOrEmpty(roleName)) { continue; } var role = RoleEnvironment.Roles[roleName]; if (role == null) { continue; } TraceEventSource.Log.TraceInfo(string.Format(RoleInstanceCountFormat, roleName, role.Instances.Count)); foreach (var roleInstance in role.Instances) { TraceEventSource.Log.TraceInfo(string.Format(RoleInstanceIdFormat, roleName, roleInstance.Id)); TraceEventSource.Log.TraceInfo(string.Format(RoleInstanceEndpointCountFormat, roleName, roleInstance.InstanceEndpoints.Count)); foreach (var instanceEndpoint in roleInstance.InstanceEndpoints) { TraceEventSource.Log.TraceInfo(string.Format(RoleInstanceEndpointFormat, roleName, instanceEndpoint.Key, instanceEndpoint.Value.Protocol, instanceEndpoint.Value.IPEndpoint.Address, instanceEndpoint.Value.IPEndpoint.Port)); } } } } catch (Exception ex) { // Trace Exception TraceEventSource.Log.TraceError(ex.Message, ex.InnerException?.Message ?? string.Empty); } finally { // TraceOut TraceEventSource.Log.TraceOut(); } }