Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Activities / Rules / RuleSetCollection.cs / 1305376 / RuleSetCollection.cs
using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Globalization; using System.Text; using System.Workflow.ComponentModel; namespace System.Workflow.Activities.Rules { #region class RuleSetCollection public sealed class RuleSetCollection : KeyedCollection, IWorkflowChangeDiff { #region members and constructors private bool _runtimeInitialized; [NonSerialized] private object syncLock = new object(); public RuleSetCollection() { } #endregion #region keyed collection members protected override string GetKeyForItem(RuleSet item) { return item.Name; } protected override void InsertItem(int index, RuleSet item) { if (this._runtimeInitialized) throw new InvalidOperationException(SR.GetString(SR.Error_CanNotChangeAtRuntime)); if (item.Name != null && item.Name.Length >= 0 && this.Contains(item.Name)) { string message = string.Format(CultureInfo.CurrentCulture, Messages.RuleSetExists, item.Name); throw new ArgumentException(message); } base.InsertItem(index, item); } protected override void RemoveItem(int index) { if (this._runtimeInitialized) throw new InvalidOperationException(SR.GetString(SR.Error_CanNotChangeAtRuntime)); base.RemoveItem(index); } protected override void SetItem(int index, RuleSet item) { if (this._runtimeInitialized) throw new InvalidOperationException(SR.GetString(SR.Error_CanNotChangeAtRuntime)); base.SetItem(index, item); } new public void Add(RuleSet item) { if (this._runtimeInitialized) throw new InvalidOperationException(SR.GetString(SR.Error_CanNotChangeAtRuntime)); if (null == item) { throw new ArgumentNullException("item"); } if (null == item.Name) { string message = string.Format(CultureInfo.CurrentCulture, Messages.InvalidRuleSetName, "item.Name"); throw new ArgumentException(message); } base.Add(item); } #endregion #region runtime initializing internal void OnRuntimeInitialized() { lock (this.syncLock) { if (this._runtimeInitialized) return; foreach (RuleSet ruleSet in this) { ruleSet.OnRuntimeInitialized(); } _runtimeInitialized = true; } } internal bool RuntimeMode { set { this._runtimeInitialized = value; } get { return this._runtimeInitialized; } } internal string GenerateRuleSetName() { string nameBase = Messages.NewRuleSetName; string newName; int i = 1; do { newName = nameBase + i.ToString(CultureInfo.InvariantCulture); i++; } while(this.Contains(newName)); return newName; } #endregion #region IWorkflowChangeDiff Members public IList Diff(object originalDefinition, object changedDefinition) { List listChanges = new List (); RuleSetCollection originalRuleSets = (RuleSetCollection)originalDefinition; RuleSetCollection changedRuleSets = (RuleSetCollection)changedDefinition; if (null != changedRuleSets) { foreach (RuleSet changedRuleSet in changedRuleSets) { if ((originalRuleSets != null) && (originalRuleSets.Contains(changedRuleSet.Name))) { RuleSet originalRuleSet = originalRuleSets[changedRuleSet.Name]; if (!originalRuleSet.Equals(changedRuleSet)) { listChanges.Add(new UpdatedRuleSetAction(originalRuleSet, changedRuleSet)); } } else { listChanges.Add(new AddedRuleSetAction(changedRuleSet)); } } } if (null != originalRuleSets) { foreach (RuleSet originalRuleSet in originalRuleSets) { if ((changedRuleSets == null) || (!changedRuleSets.Contains(originalRuleSet.Name))) { listChanges.Add(new RemovedRuleSetAction(originalRuleSet)); } } } return listChanges; } #endregion } #endregion } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Globalization; using System.Text; using System.Workflow.ComponentModel; namespace System.Workflow.Activities.Rules { #region class RuleSetCollection public sealed class RuleSetCollection : KeyedCollection , IWorkflowChangeDiff { #region members and constructors private bool _runtimeInitialized; [NonSerialized] private object syncLock = new object(); public RuleSetCollection() { } #endregion #region keyed collection members protected override string GetKeyForItem(RuleSet item) { return item.Name; } protected override void InsertItem(int index, RuleSet item) { if (this._runtimeInitialized) throw new InvalidOperationException(SR.GetString(SR.Error_CanNotChangeAtRuntime)); if (item.Name != null && item.Name.Length >= 0 && this.Contains(item.Name)) { string message = string.Format(CultureInfo.CurrentCulture, Messages.RuleSetExists, item.Name); throw new ArgumentException(message); } base.InsertItem(index, item); } protected override void RemoveItem(int index) { if (this._runtimeInitialized) throw new InvalidOperationException(SR.GetString(SR.Error_CanNotChangeAtRuntime)); base.RemoveItem(index); } protected override void SetItem(int index, RuleSet item) { if (this._runtimeInitialized) throw new InvalidOperationException(SR.GetString(SR.Error_CanNotChangeAtRuntime)); base.SetItem(index, item); } new public void Add(RuleSet item) { if (this._runtimeInitialized) throw new InvalidOperationException(SR.GetString(SR.Error_CanNotChangeAtRuntime)); if (null == item) { throw new ArgumentNullException("item"); } if (null == item.Name) { string message = string.Format(CultureInfo.CurrentCulture, Messages.InvalidRuleSetName, "item.Name"); throw new ArgumentException(message); } base.Add(item); } #endregion #region runtime initializing internal void OnRuntimeInitialized() { lock (this.syncLock) { if (this._runtimeInitialized) return; foreach (RuleSet ruleSet in this) { ruleSet.OnRuntimeInitialized(); } _runtimeInitialized = true; } } internal bool RuntimeMode { set { this._runtimeInitialized = value; } get { return this._runtimeInitialized; } } internal string GenerateRuleSetName() { string nameBase = Messages.NewRuleSetName; string newName; int i = 1; do { newName = nameBase + i.ToString(CultureInfo.InvariantCulture); i++; } while(this.Contains(newName)); return newName; } #endregion #region IWorkflowChangeDiff Members public IList Diff(object originalDefinition, object changedDefinition) { List listChanges = new List (); RuleSetCollection originalRuleSets = (RuleSetCollection)originalDefinition; RuleSetCollection changedRuleSets = (RuleSetCollection)changedDefinition; if (null != changedRuleSets) { foreach (RuleSet changedRuleSet in changedRuleSets) { if ((originalRuleSets != null) && (originalRuleSets.Contains(changedRuleSet.Name))) { RuleSet originalRuleSet = originalRuleSets[changedRuleSet.Name]; if (!originalRuleSet.Equals(changedRuleSet)) { listChanges.Add(new UpdatedRuleSetAction(originalRuleSet, changedRuleSet)); } } else { listChanges.Add(new AddedRuleSetAction(changedRuleSet)); } } } if (null != originalRuleSets) { foreach (RuleSet originalRuleSet in originalRuleSets) { if ((changedRuleSets == null) || (!changedRuleSets.Contains(originalRuleSet.Name))) { listChanges.Add(new RemovedRuleSetAction(originalRuleSet)); } } } return listChanges; } #endregion } #endregion } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlArrayItemAttribute.cs
- LinqDataSourceDeleteEventArgs.cs
- CustomValidator.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- CodeMethodReturnStatement.cs
- ConfigUtil.cs
- MultiDataTrigger.cs
- XPathMultyIterator.cs
- XmlDocumentFragment.cs
- HwndHost.cs
- SqlVisitor.cs
- PropertyItem.cs
- UrlRoutingModule.cs
- FindCompletedEventArgs.cs
- WpfSharedXamlSchemaContext.cs
- DiscriminatorMap.cs
- MatrixValueSerializer.cs
- TerminatorSinks.cs
- GridErrorDlg.cs
- DeflateEmulationStream.cs
- DataBindingCollectionConverter.cs
- HasCopySemanticsAttribute.cs
- CommandLibraryHelper.cs
- ClientFormsAuthenticationCredentials.cs
- GridPattern.cs
- ValidatorCompatibilityHelper.cs
- SqlWebEventProvider.cs
- datacache.cs
- SelfIssuedAuthAsymmetricKey.cs
- Converter.cs
- AbstractExpressions.cs
- SystemGatewayIPAddressInformation.cs
- BamlLocalizableResourceKey.cs
- ButtonField.cs
- Trigger.cs
- Sentence.cs
- GridViewRowPresenterBase.cs
- KeyValueInternalCollection.cs
- ConfigurationProperty.cs
- CompensationExtension.cs
- WebPartEventArgs.cs
- ListParagraph.cs
- filewebresponse.cs
- XhtmlConformanceSection.cs
- Schema.cs
- HealthMonitoringSectionHelper.cs
- TextElement.cs
- ContextProperty.cs
- LinearGradientBrush.cs
- AdRotator.cs
- XsltCompileContext.cs
- TableCell.cs
- StoreItemCollection.Loader.cs
- SystemIcmpV6Statistics.cs
- TypeInfo.cs
- XMLUtil.cs
- mansign.cs
- DockPatternIdentifiers.cs
- _ShellExpression.cs
- SettingsSavedEventArgs.cs
- ReachDocumentPageSerializer.cs
- _KerberosClient.cs
- ToolStripButton.cs
- PrintDialogException.cs
- SendingRequestEventArgs.cs
- BaseTemplateBuildProvider.cs
- TemplateFactory.cs
- Rect.cs
- DashStyle.cs
- SqlRemoveConstantOrderBy.cs
- Operator.cs
- ConsoleKeyInfo.cs
- CharacterBufferReference.cs
- MdImport.cs
- Size.cs
- PlatformNotSupportedException.cs
- Documentation.cs
- _NestedMultipleAsyncResult.cs
- CheckBoxRenderer.cs
- FieldBuilder.cs
- FreezableOperations.cs
- EncoderFallback.cs
- PixelShader.cs
- ListView.cs
- embossbitmapeffect.cs
- RuntimeIdentifierPropertyAttribute.cs
- ComPlusInstanceProvider.cs
- BitmapCodecInfo.cs
- GeneratedCodeAttribute.cs
- MailAddressCollection.cs
- SchemaConstraints.cs
- XmlAttributes.cs
- SmtpDateTime.cs
- ErrorInfoXmlDocument.cs
- SqlTriggerAttribute.cs
- VarRemapper.cs
- TrackingWorkflowEventArgs.cs
- TabControl.cs
- TimeEnumHelper.cs
- ProjectionRewriter.cs