public static ReservationBase CreateReservation(Guid mailboxGuid, TenantPartitionHint partitionHint, Guid resourceId, ReservationFlags flags, string clientName) { ReservationBase result; using (DisposeGuard disposeGuard = default(DisposeGuard)) { SettingsContextBase settingsContextBase = new MailboxSettingsContext(mailboxGuid, null); if (partitionHint != null) { settingsContextBase = new OrganizationSettingsContext(OrganizationId.FromExternalDirectoryOrganizationId(partitionHint.GetExternalDirectoryOrganizationId()), settingsContextBase); } ReservationBase reservationBase; if (resourceId == MRSResource.Id.ObjectGuid) { reservationBase = new MRSReservation(); } else { if (flags.HasFlag(ReservationFlags.Read)) { reservationBase = new ReadReservation(); } else { reservationBase = new WriteReservation(); } settingsContextBase = new DatabaseSettingsContext(resourceId, settingsContextBase); } disposeGuard.Add <ReservationBase>(reservationBase); settingsContextBase = new GenericSettingsContext("WorkloadType", reservationBase.WorkloadType.ToString(), settingsContextBase); reservationBase.MailboxGuid = mailboxGuid; reservationBase.PartitionHint = partitionHint; reservationBase.ResourceId = resourceId; reservationBase.Flags = flags; reservationBase.ClientName = clientName; using (settingsContextBase.Activate()) { reservationBase.ReserveResources(); } disposeGuard.Success(); result = reservationBase; } return(result); }
private static void WriteInternal(Guid requestGuid, Exception failure, bool isFatal, RequestState requestState, SyncStage syncStage, string folderName, string operationType, Guid failureGuid, int failureLevel) { FailureData objectToLog = default(FailureData); objectToLog.FailureGuid = failureGuid; objectToLog.RequestGuid = requestGuid; objectToLog.Failure = failure; objectToLog.FailureLevel = failureLevel; objectToLog.IsFatal = isFatal; objectToLog.RequestState = requestState; objectToLog.SyncStage = syncStage; objectToLog.FolderName = folderName; objectToLog.OperationType = operationType; if (objectToLog.OperationType == null && objectToLog.Failure != null) { string dataContext = ExecutionContext.GetDataContext(failure); objectToLog.OperationType = FailureLog.GetDataContextToPersist(dataContext); } GenericSettingsContext genericSettingsContext = new GenericSettingsContext("FailureType", CommonUtils.GetFailureType(failure), null); using (genericSettingsContext.Activate()) { if (ConfigBase <MRSConfigSchema> .GetConfig <bool>("SendGenericWatson")) { string watsonHash; CommonUtils.SendGenericWatson(failure, CommonUtils.FullFailureMessageWithCallStack(failure, 5), out watsonHash); objectToLog.WatsonHash = watsonHash; } else { objectToLog.WatsonHash = CommonUtils.ComputeCallStackHash(failure, 5); } } FailureLog.instance.LogObject(objectToLog); if (failure.InnerException != null) { FailureLog.WriteInternal(requestGuid, failure.InnerException, isFatal, requestState, syncStage, folderName, operationType, failureGuid, failureLevel + 1); } }
public void ProcessLogs() { if (!this.LogIsNeeded()) { return; } MRSSettingsLogCollection config = ConfigBase <MRSConfigSchema> .GetConfig <MRSSettingsLogCollection>("MRSSettingsLogList"); if (config == null) { MRSSettingsLog.PublishPeriodicExceptionNotification(string.Format("The value for {0} setting is corrupt. Check and correct setting value", "MRSSettingsLogList")); return; } foreach (MRSSettingsLogCollection.MRSSettingsLogElement mrssettingsLogElement in config.SettingsLogCollection) { try { MRSSettingsData loggingStatsData; if (StringComparer.OrdinalIgnoreCase.Equals(mrssettingsLogElement.SettingName, "IsJobPickupEnabled")) { using (IEnumerator enumerator2 = Enum.GetValues(typeof(RequestWorkloadType)).GetEnumerator()) { while (enumerator2.MoveNext()) { object obj = enumerator2.Current; RequestWorkloadType requestWorkloadType = (RequestWorkloadType)obj; if (requestWorkloadType != RequestWorkloadType.None) { SettingsContextBase settingsContextBase = new GenericSettingsContext("RequestWorkloadType", requestWorkloadType.ToString(), null); using (settingsContextBase.Activate()) { bool config2 = ConfigBase <MRSConfigSchema> .GetConfig <bool>(mrssettingsLogElement.SettingName); loggingStatsData = new MRSSettingsData { Context = string.Format("{0}={1}", "RequestWorkloadType", requestWorkloadType.ToString()), SettingName = "IsJobPickupEnabled", SettingValue = Convert.ToInt32(config2).ToString() }; } this.Write(loggingStatsData); } } continue; } } if (StringComparer.OrdinalIgnoreCase.Equals(mrssettingsLogElement.SettingName, "IgnoreHealthMonitor")) { List <ResourceKey> list = new List <ResourceKey> { ADResourceKey.Key, ProcessorResourceKey.Local }; using (List <ResourceKey> .Enumerator enumerator3 = list.GetEnumerator()) { while (enumerator3.MoveNext()) { ResourceKey resourceKey = enumerator3.Current; SettingsContextBase settingsContextBase2 = new GenericSettingsContext("WlmHealthMonitor", resourceKey.ToString(), null); using (settingsContextBase2.Activate()) { bool config3 = ConfigBase <MRSConfigSchema> .GetConfig <bool>(mrssettingsLogElement.SettingName); loggingStatsData = new MRSSettingsData { Context = string.Format("{0}={1}", "WlmHealthMonitor", resourceKey.ToString()), SettingName = "IgnoreHealthMonitor", SettingValue = Convert.ToInt32(config3).ToString() }; } this.Write(loggingStatsData); } continue; } } ConfigurationProperty configurationProperty; if (!ConfigBase <MRSConfigSchema> .Schema.TryGetConfigurationProperty(mrssettingsLogElement.SettingName, out configurationProperty)) { throw new MRSSettingsLog.BadConfigSettingException(string.Format("Can not find corresponding name of MRS config setting specified by string {0}. Check if the setting name and correct it if needed", mrssettingsLogElement.SettingName)); } string settingValue = string.Empty; if (configurationProperty.Type == typeof(bool)) { settingValue = ConfigBase <MRSConfigSchema> .GetConfig <bool>(configurationProperty.Name).ToString(); } else if (configurationProperty.Type == typeof(int)) { settingValue = ConfigBase <MRSConfigSchema> .GetConfig <int>(configurationProperty.Name).ToString(); } else if (configurationProperty.Type == typeof(long)) { settingValue = ConfigBase <MRSConfigSchema> .GetConfig <long>(configurationProperty.Name).ToString(); } else if (configurationProperty.Type == typeof(string)) { settingValue = ConfigBase <MRSConfigSchema> .GetConfig <string>(configurationProperty.Name); } else { if (!(configurationProperty.Type == typeof(TimeSpan))) { throw new MRSSettingsLog.BadConfigSettingException(string.Format("Type {0} of a provided setting {1} is not supported by logging functionality. Check and correct list of the settings to be logged", configurationProperty.Type, mrssettingsLogElement.SettingName)); } settingValue = ConfigBase <MRSConfigSchema> .GetConfig <TimeSpan>(configurationProperty.Name).ToString(); } loggingStatsData = new MRSSettingsData { Context = "Server", SettingName = configurationProperty.Name, SettingValue = settingValue }; this.Write(loggingStatsData); } catch (MRSSettingsLog.BadConfigSettingException ex) { MRSSettingsLog.PublishPeriodicExceptionNotification(ex.Message); } } }
private void ProcessDiagnostic(ExchangeSettings settings, ConfigDiagnosticArgument argument, IConfigSchema schema) { XElement xelement = new XElement("config"); SettingsContextBase context = new DiagnosticSettingsContext(schema, argument); Server server = null; if (this.Server != null) { server = (Server)base.GetDataObject <Server>(this.Server, base.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorServerNotFound(this.Server.ToString())), new LocalizedString?(Strings.ErrorServerNotUnique(this.Server.ToString()))); } if (server != null || !string.IsNullOrEmpty(this.Process)) { context = new ServerSettingsContext(server, this.Process, context); } if (this.Database != null) { Database database = (Database)base.GetDataObject <Database>(this.Database, base.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorDatabaseNotFound(this.Database.ToString())), new LocalizedString?(Strings.ErrorDatabaseNotUnique(this.Database.ToString()))); context = new DatabaseSettingsContext(database.Guid, context); } if (this.Organization != null) { ExchangeConfigurationUnit org = (ExchangeConfigurationUnit)base.GetDataObject <ExchangeConfigurationUnit>(this.Organization, base.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorOrganizationNotFound(this.Organization.ToString())), new LocalizedString?(Strings.ErrorOrganizationNotUnique(this.Organization.ToString()))); context = new OrganizationSettingsContext(org, context); } if (this.User != Guid.Empty) { context = new MailboxSettingsContext(this.User, context); } if (this.GenericScopeName != null) { if (schema != null) { schema.ParseAndValidateScopeValue(this.GenericScopeName, this.GenericScopeValue); } context = new GenericSettingsContext(this.GenericScopeName, this.GenericScopeValue, context); } if (this.GenericScopes != null) { foreach (string text in this.GenericScopes) { string text2 = null; string text3 = null; if (text != null) { int num = (text != null) ? text.IndexOf('=') : -1; if (num > 0) { text2 = text.Substring(0, num); text3 = text.Substring(num + 1); } } if (string.IsNullOrWhiteSpace(text2)) { base.WriteError(new ExchangeSettingsBadFormatOfConfigPairException(text), ExchangeErrorCategory.Client, this.GenericScopes); } if (schema != null) { schema.ParseAndValidateScopeValue(text2, text3); } context = new GenericSettingsContext(text2, text3, context); } } if (this.Diagnostic) { xelement.Add(argument.RunDiagnosticOperation(() => context.GetDiagnosticInfo(this.DiagnosticArgument))); if (schema != null) { xelement.Add(argument.RunDiagnosticOperation(() => schema.GetDiagnosticInfo(this.DiagnosticArgument))); } xelement.Add(argument.RunDiagnosticOperation(delegate { XElement xelement2 = new XElement("scopes"); SettingsScopeFilterSchema schemaInstance = SettingsScopeFilterSchema.GetSchemaInstance(schema); foreach (PropertyDefinition propertyDefinition in schemaInstance.AllProperties) { xelement2.Add(new XElement(propertyDefinition.Name, new XAttribute("type", propertyDefinition.Type))); } return(xelement2); })); } if (!string.IsNullOrEmpty(this.ConfigName)) { string serializedValue = null; ConfigurationProperty pdef = null; xelement.Add(argument.RunDiagnosticOperation(delegate { using (context.Activate()) { if (!settings.TryGetConfig(schema, SettingsContextBase.EffectiveContext, this.ConfigName, out serializedValue) && schema != null && schema.TryGetConfigurationProperty(this.ConfigName, out pdef)) { object defaultConfigValue = schema.GetDefaultConfigValue(pdef); serializedValue = ((defaultConfigValue != null) ? defaultConfigValue.ToString() : null); } } return(new XElement("EffectiveValue", new object[] { new XAttribute("name", this.ConfigName ?? "null"), new XAttribute("value", serializedValue ?? "null") })); })); settings.EffectiveSetting = new KeyValuePair <string, object>(this.ConfigName, serializedValue); if (serializedValue != null && schema != null) { settings.EffectiveSetting = new KeyValuePair <string, object>(this.ConfigName, schema.ParseAndValidateConfigValue(this.ConfigName, serializedValue, null)); } if (this.Diagnostic) { xelement.Add(argument.RunDiagnosticOperation(() => settings.GetDiagnosticInfo(this.DiagnosticArgument))); } } if (this.Diagnostic) { settings.DiagnosticInfo = xelement.ToString(); } }
XElement IDiagnosable.GetDiagnosticInfo(DiagnosableParameters parameters) { XElement xelement = new XElement(MRSService.DiagnosticsComponentName); MRSDiagnosticArgument arguments; try { arguments = new MRSDiagnosticArgument(parameters.Argument); } catch (DiagnosticArgumentException ex) { xelement.Add(new XElement("Error", "Encountered exception: " + ex.Message)); return(xelement); } xelement.Add(new object[] { new XElement("ServiceStartTime", MRSService.serviceStartTime), new XElement("LastScanDuration", MRSService.lastFullScanDuration), new XElement("LastScanTime", MRSService.lastFullScanTime.ToString()), new XElement("DurationSinceLastScan", (long)(DateTime.UtcNow - MRSService.lastFullScanTime).TotalMilliseconds), new XElement("NextFullScanTime", MRSService.NextFullScanTime.ToString()), new XElement("NextLightJobsFullScanTime", MRSService.nextLightJobsFullScanTime.ToString()) }); if (arguments.ArgumentCount == 0) { xelement.Add(new XElement("Help", "Supported arguments: " + arguments.GetSupportedArguments())); } if (arguments.HasArgument("binaryversions")) { string assemblyNamePattern = arguments.GetArgument <string>("binaryversions"); xelement.Add(arguments.RunDiagnosticOperation(() => CommonUtils.GetBinaryVersions(assemblyNamePattern))); } if (arguments.HasArgument("job")) { xelement.Add(arguments.RunDiagnosticOperation(() => MailboxSyncerJobs.GetJobsDiagnosticInfo(arguments))); } if (arguments.HasArgument("reservations")) { xelement.Add(arguments.RunDiagnosticOperation(() => ReservationManager.GetReservationsDiagnosticInfo(arguments))); } if (arguments.HasArgument("resources")) { xelement.Add(arguments.RunDiagnosticOperation(() => ReservationManager.GetResourcesDiagnosticInfo(arguments))); } if (arguments.HasArgument("queues")) { xelement.Add(arguments.RunDiagnosticOperation(() => MRSQueue.GetDiagnosticInfo(arguments))); } if (arguments.HasArgument("workloads")) { XElement xelement2 = new XElement("Workloads"); foreach (object obj in Enum.GetValues(typeof(RequestWorkloadType))) { RequestWorkloadType requestWorkloadType = (RequestWorkloadType)obj; if (requestWorkloadType != RequestWorkloadType.None) { GenericSettingsContext genericSettingsContext = new GenericSettingsContext("RequestWorkloadType", requestWorkloadType.ToString(), null); using (genericSettingsContext.Activate()) { bool config = ConfigBase <MRSConfigSchema> .GetConfig <bool>("IsJobPickupEnabled"); xelement2.Add(new XElement("Workload", new object[] { new XAttribute("Name", requestWorkloadType.ToString()), new XAttribute("IsJobPickupEnabled", config) })); } } } xelement.Add(xelement2); } return(xelement); }