//----------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.DynamicUpdate { using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Runtime.Serialization; using System.Text; using System.Security; using System.Runtime; [Serializable] public class InstanceUpdateException : Exception { private ReadOnlyCollection blockingActivities; public InstanceUpdateException() : base() { } public InstanceUpdateException(string message) : base(message) { } public InstanceUpdateException(string message, Exception innerException) : base(message, innerException) { } public InstanceUpdateException(IList blockingActivities) : this(BuildMessage(blockingActivities), blockingActivities) { } public InstanceUpdateException(string message, IList blockingActivities) : base(message) { if (blockingActivities != null) { this.blockingActivities = new ReadOnlyCollection(blockingActivities); } } public InstanceUpdateException(string message, IList blockingActivities, Exception innerException) : base(message, innerException) { if (blockingActivities != null) { this.blockingActivities = new ReadOnlyCollection(blockingActivities); } } protected InstanceUpdateException(SerializationInfo info, StreamingContext context) : base(info, context) { this.blockingActivities = (ReadOnlyCollection)info.GetValue( "blockingActivities", typeof(ReadOnlyCollection)); } public IList BlockingActivities { get { if (this.blockingActivities == null) { this.blockingActivities = new ReadOnlyCollection(new ActivityBlockingUpdate[0]); } return this.blockingActivities; } } [Fx.Tag.SecurityNote(Critical = "Critical because we are overriding a critical method in the base class.")] [SecurityCritical] public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); info.AddValue("blockingActivities", this.blockingActivities); } private static string BuildMessage(IList blockingActivities) { if (blockingActivities != null && blockingActivities.Count > 0) { StringBuilder errorMsgs = new StringBuilder(); for (int i = 0; i < blockingActivities.Count - 1; i++) { errorMsgs.AppendLine(GetMessage(blockingActivities[i])); } errorMsgs.Append(GetMessage(blockingActivities[blockingActivities.Count - 1])); return errorMsgs.ToString(); } return null; } private static string GetMessage(ActivityBlockingUpdate blockingActivity) { object activity = (object)blockingActivity.Activity ?? blockingActivity.UpdatedActivityId; if (activity != null) { return SR.ActivityBlockingUpdate(activity, blockingActivity.Reason); } else { return blockingActivity.Reason; } } } }