/// <summary> /// Loads configuration property for component. /// </summary> /// <param name="propertyBag">The configuration property bag.</param> /// <param name="errorLog">Error status (not in use).</param> void IPersistPropertyBag.Load(IPropertyBag propertyBag, int errorLog) { // The outer try/catch block is intended to catch an exception related of incorrect tracing configuration or missing tracing component assembly. try { var callToken = PipelineTraceManager.TraceIn(); try { IDictionary <string, object> props = GetConfigurableProperties(); if (props != null && props.Count > 0) { using (DisposableObjectWrapper dispObjects = new DisposableObjectWrapper(propertyBag, props)) { ICollection <string> propertyNameList = new List <string>(props.Keys); foreach (string propName in propertyNameList) { // Read the component property value from property bag provided. object value = PropertyHelper.ReadPropertyBag(propertyBag, propName); // Only change the value if it was returned from the property bag to prevent detaults from being wiped out. if (value != null) { props[propName] = value; } } // Update the instance properties which are marked with a Browsable attribute. ApplyConfigurableProperties(props); // Invoke the user implementation of the Load method in case there are any custom properties require loading. Load(propertyBag, errorLog); } } PipelineTraceManager.TraceOut(callToken); } catch (Exception e) { // Put component name as a source in this exception so that the error message could reflect this. e.Source = this.Name; // Trace the exception details. PipelineTraceManager.TraceError(e, EnableDetailedExceptions, callToken); // Re-throw the exception so that it can be handled by the caller. throw; } } catch (Exception ex) { Trace.WriteLine(ExceptionTextFormatter.Format(ex)); } }
/// <summary> /// Saves properties to the property bag. /// </summary> /// <param name="propertyBag">The property bag to manipulate.</param> /// <param name="clearDirty">Indicates if we should reset the IsDirty flag.</param> /// <param name="saveAllProperties">Indicates whether all properties should be saved.</param> void IPersistPropertyBag.Save(IPropertyBag propertyBag, bool clearDirty, bool saveAllProperties) { var callToken = PipelineTraceManager.TraceIn(); try { IDictionary <string, object> props = GetConfigurableProperties(); if (props != null && props.Count > 0) { using (DisposableObjectWrapper dispObjectWrapper = new DisposableObjectWrapper(propertyBag, props)) { foreach (KeyValuePair <string, object> prop in props) { // Write the configuration property values into a property bag provided. PropertyHelper.WritePropertyBag(propertyBag, prop.Key, prop.Value); } // Invoke the user implementation of the Save method in case there are any custom properties require storing. Save(propertyBag, clearDirty, saveAllProperties); } } PipelineTraceManager.TraceOut(callToken); } catch (Exception e) { // Put component name as a source in this exception so that the error message could reflect this. e.Source = this.Name; // Trace the exception details. PipelineTraceManager.TraceError(e, EnableDetailedExceptions, callToken); // Re-throw the exception so that it can be handled by the caller. throw; } }