private T ValidateParameterAndReturnValue <T>(string paramName, string value)
 {
     try
     {
         return((T)Convert.ChangeType(value, typeof(T)));
     }
     catch
     {
         string errorMessage = string.Format("Value: {0} of Parameter : {1} is invalid", value, paramName);
         HealthManagerHelper.PostServiceHealthReport(this.fabricClient, this.Context, SettingsValidationProperty, errorMessage, HealthState.Error);
         ServiceEventSource.Current.ErrorMessage(errorMessage);
         throw new ArgumentException(errorMessage);
     }
 }
Esempio n. 2
0
 private static void ValidateParameter <T> (string paramName, string value, FabricClient fabricClient, ServiceContext serviceContext)
 {
     try
     {
         var outValue = (T)Convert.ChangeType(value, typeof(T));
     }
     catch
     {
         string errorMessage = string.Format("Value: {0} of Parameter : {1} is invalid", value, paramName);
         HealthManagerHelper.PostServiceHealthReport(fabricClient, serviceContext, SettingsValidationProperty, errorMessage, HealthState.Error);
         ServiceEventSource.Current.ErrorMessage(errorMessage);
         throw new ArgumentException(errorMessage);
     }
 }
        private void InitializeConfiguration(ConfigurationPackage package)
        {
            string settingsDestinationPath = this.GetLocalPathForApplication(package.Path) + NtServicePath + "Settings.xml";

            try
            {
                NtServiceConfigurationUtility.CreateConfigurationForNtService(package, settingsDestinationPath, this.fabricClient, this.Context);
                if (package.Settings != null && package.Settings.Sections.Contains(settingsSectionName))
                {
                    this.ModifySettings(package.Settings.Sections[settingsSectionName]);
                }
                string healthMessage = "Settings validation was successful.";
                HealthManagerHelper.PostServiceHealthReport(this.fabricClient, this.Context, SettingsValidationProperty, healthMessage, HealthState.Ok, 1);
            }
            catch (Exception ex)
            {
                ServiceEventSource.Current.ErrorMessage("InitializeConfiguration failed with exception: {0}", ex);
                this.Partition.ReportFault(FaultType.Permanent);
            }
        }
 /// <summary>
 /// Sets health alert for current stateless service instance
 /// Typically called when there is a problem in service instance or its sub-components(NT service).
 /// </summary>
 /// <param name="description">description of the health report</param>
 private void SetHealthAlert(string description)
 {
     HealthManagerHelper.PostServiceInstanceHealthReport(this.fabricClient, this.context, HealthManagerHelper.SourceId, this.healthProperty, description, HealthState.Warning);
 }
 /// <summary>
 /// Reset the Health Alert for current stateless service instance
 /// Typically called when condition causing health alert is remedied
 /// </summary>
 /// <param name="description">description of the health report</param>
 private void ResetHealthAlert(string description)
 {
     HealthManagerHelper.PostServiceInstanceHealthReport(this.fabricClient, this.context, HealthManagerHelper.SourceId, this.healthProperty, description, HealthState.Ok,
                                                         HealthManagerHelper.HealthyEventTtlInMinutes);
 }