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
- MultiPropertyDescriptorGridEntry.cs
- DbSource.cs
- RequestTimeoutManager.cs
- AssemblyInfo.cs
- OleDbRowUpdatingEvent.cs
- HiddenField.cs
- XmlIterators.cs
- AssertHelper.cs
- Config.cs
- ObjectDataSourceFilteringEventArgs.cs
- SHA384.cs
- RawStylusInputCustomData.cs
- TrustDriver.cs
- MSHTMLHostUtil.cs
- ContractListAdapter.cs
- WebPartConnectionsDisconnectVerb.cs
- CommandCollectionEditor.cs
- VirtualPathUtility.cs
- ValidationEventArgs.cs
- RetrieveVirtualItemEventArgs.cs
- EventLogPermissionEntryCollection.cs
- DataExpression.cs
- GraphicsContext.cs
- DetailsViewPageEventArgs.cs
- XmlNamespaceManager.cs
- DataTableReader.cs
- InputLanguage.cs
- PartitionResolver.cs
- ToolStripOverflow.cs
- WindowsSecurityToken.cs
- ToolStripSplitStackLayout.cs
- SqlCommand.cs
- ContractsBCL.cs
- GridLength.cs
- IconEditor.cs
- LinqToSqlWrapper.cs
- safelink.cs
- DataGridViewUtilities.cs
- MsmqIntegrationInputChannel.cs
- UnsafeNativeMethods.cs
- KeyValueConfigurationCollection.cs
- JournalNavigationScope.cs
- EntityAdapter.cs
- ColumnMap.cs
- TextPattern.cs
- FontCollection.cs
- entityreference_tresulttype.cs
- Calendar.cs
- CollectionView.cs
- TreeIterator.cs
- Propagator.JoinPropagator.SubstitutingCloneVisitor.cs
- IdentifierCollection.cs
- InputManager.cs
- OleDbCommandBuilder.cs
- XmlWrappingWriter.cs
- LogLogRecordEnumerator.cs
- WebPartCollection.cs
- BaseDataBoundControl.cs
- OAVariantLib.cs
- Rss20FeedFormatter.cs
- StrokeDescriptor.cs
- ClientData.cs
- TreeViewHitTestInfo.cs
- CriticalFinalizerObject.cs
- DispatcherSynchronizationContext.cs
- RIPEMD160.cs
- RouteItem.cs
- DataFormat.cs
- PrimitiveSchema.cs
- ArrayExtension.cs
- WindowsAltTab.cs
- RealProxy.cs
- ToolStripComboBox.cs
- RoutedEventValueSerializer.cs
- Duration.cs
- CookieProtection.cs
- AssemblyAttributes.cs
- x509utils.cs
- BevelBitmapEffect.cs
- CssStyleCollection.cs
- DataColumnCollection.cs
- HostedHttpRequestAsyncResult.cs
- ZipPackagePart.cs
- PackWebRequest.cs
- Vector3DCollectionConverter.cs
- DataGridViewCellStateChangedEventArgs.cs
- ExpanderAutomationPeer.cs
- MembershipAdapter.cs
- QueryPageSettingsEventArgs.cs
- DefinitionBase.cs
- AmbientProperties.cs
- ToolStripContentPanelRenderEventArgs.cs
- GridViewSortEventArgs.cs
- QueryStack.cs
- Int32Collection.cs
- EventToken.cs
- VoiceSynthesis.cs
- WinCategoryAttribute.cs
- HandlerWithFactory.cs
- GetPageCompletedEventArgs.cs