Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Activities / Rules / RuleDefinitions.cs / 1305376 / RuleDefinitions.cs
// ---------------------------------------------------------------------------- // Copyright (C) 2006 Microsoft Corporation All Rights Reserved // --------------------------------------------------------------------------- #define CODE_ANALYSIS using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Workflow.ComponentModel; namespace System.Workflow.Activities.Rules { #region class RuleDefinitions public sealed class RuleDefinitions : IWorkflowChangeDiff { [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")] public static readonly DependencyProperty RuleDefinitionsProperty = DependencyProperty.RegisterAttached("RuleDefinitions", typeof(RuleDefinitions), typeof(RuleDefinitions), new PropertyMetadata(null, DependencyPropertyOptions.Metadata, new GetValueOverride(OnGetRuleConditions), null, new Attribute[] { new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden) })); private RuleConditionCollection conditions; private RuleSetCollection ruleSets; private bool runtimeInitialized; [NonSerialized] private object syncLock = new object(); [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public RuleConditionCollection Conditions { get { if (this.conditions == null) this.conditions = new RuleConditionCollection(); return conditions; } } [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public RuleSetCollection RuleSets { get { if (this.ruleSets == null) this.ruleSets = new RuleSetCollection(); return this.ruleSets; } } internal static object OnGetRuleConditions(DependencyObject dependencyObject) { if (dependencyObject == null) throw new ArgumentNullException("dependencyObject"); RuleDefinitions rules = dependencyObject.GetValueBase(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions; if (rules != null) return rules; Activity rootActivity = dependencyObject as Activity; if (rootActivity.Parent == null) { rules = ConditionHelper.GetRuleDefinitionsFromManifest(rootActivity.GetType()); if (rules != null) dependencyObject.SetValue(RuleDefinitions.RuleDefinitionsProperty, rules); } return rules; } internal void OnRuntimeInitialized() { lock (syncLock) { if (runtimeInitialized) return; Conditions.OnRuntimeInitialized(); RuleSets.OnRuntimeInitialized(); runtimeInitialized = true; } } #region IWorkflowChangeDiff Members public IListDiff(object originalDefinition, object changedDefinition) { RuleDefinitions originalRules = originalDefinition as RuleDefinitions; RuleDefinitions changedRules = changedDefinition as RuleDefinitions; if ((originalRules == null) || (changedRules == null)) return new List (); IList cdiff = Conditions.Diff(originalRules.Conditions, changedRules.Conditions); IList rdiff = RuleSets.Diff(originalRules.RuleSets, changedRules.RuleSets); // quick optimization -- if no condition changes, simply return the ruleset changes if (cdiff.Count == 0) return rdiff; // merge ruleset changes into condition changes for (int i = 0; i < rdiff.Count; ++i) { cdiff.Add(rdiff[i]); } return cdiff; } #endregion internal RuleDefinitions Clone() { RuleDefinitions newRuleDefinitions = new RuleDefinitions(); if (this.ruleSets != null) { newRuleDefinitions.ruleSets = new RuleSetCollection(); foreach (RuleSet r in this.ruleSets) newRuleDefinitions.ruleSets.Add(r.Clone()); } if (this.conditions != null) { newRuleDefinitions.conditions = new RuleConditionCollection(); foreach (RuleCondition r in this.conditions) newRuleDefinitions.conditions.Add(r.Clone()); } return newRuleDefinitions; } } #endregion } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. // ---------------------------------------------------------------------------- // Copyright (C) 2006 Microsoft Corporation All Rights Reserved // --------------------------------------------------------------------------- #define CODE_ANALYSIS using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Workflow.ComponentModel; namespace System.Workflow.Activities.Rules { #region class RuleDefinitions public sealed class RuleDefinitions : IWorkflowChangeDiff { [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")] public static readonly DependencyProperty RuleDefinitionsProperty = DependencyProperty.RegisterAttached("RuleDefinitions", typeof(RuleDefinitions), typeof(RuleDefinitions), new PropertyMetadata(null, DependencyPropertyOptions.Metadata, new GetValueOverride(OnGetRuleConditions), null, new Attribute[] { new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden) })); private RuleConditionCollection conditions; private RuleSetCollection ruleSets; private bool runtimeInitialized; [NonSerialized] private object syncLock = new object(); [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public RuleConditionCollection Conditions { get { if (this.conditions == null) this.conditions = new RuleConditionCollection(); return conditions; } } [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public RuleSetCollection RuleSets { get { if (this.ruleSets == null) this.ruleSets = new RuleSetCollection(); return this.ruleSets; } } internal static object OnGetRuleConditions(DependencyObject dependencyObject) { if (dependencyObject == null) throw new ArgumentNullException("dependencyObject"); RuleDefinitions rules = dependencyObject.GetValueBase(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions; if (rules != null) return rules; Activity rootActivity = dependencyObject as Activity; if (rootActivity.Parent == null) { rules = ConditionHelper.GetRuleDefinitionsFromManifest(rootActivity.GetType()); if (rules != null) dependencyObject.SetValue(RuleDefinitions.RuleDefinitionsProperty, rules); } return rules; } internal void OnRuntimeInitialized() { lock (syncLock) { if (runtimeInitialized) return; Conditions.OnRuntimeInitialized(); RuleSets.OnRuntimeInitialized(); runtimeInitialized = true; } } #region IWorkflowChangeDiff Members public IList Diff(object originalDefinition, object changedDefinition) { RuleDefinitions originalRules = originalDefinition as RuleDefinitions; RuleDefinitions changedRules = changedDefinition as RuleDefinitions; if ((originalRules == null) || (changedRules == null)) return new List (); IList cdiff = Conditions.Diff(originalRules.Conditions, changedRules.Conditions); IList rdiff = RuleSets.Diff(originalRules.RuleSets, changedRules.RuleSets); // quick optimization -- if no condition changes, simply return the ruleset changes if (cdiff.Count == 0) return rdiff; // merge ruleset changes into condition changes for (int i = 0; i < rdiff.Count; ++i) { cdiff.Add(rdiff[i]); } return cdiff; } #endregion internal RuleDefinitions Clone() { RuleDefinitions newRuleDefinitions = new RuleDefinitions(); if (this.ruleSets != null) { newRuleDefinitions.ruleSets = new RuleSetCollection(); foreach (RuleSet r in this.ruleSets) newRuleDefinitions.ruleSets.Add(r.Clone()); } if (this.conditions != null) { newRuleDefinitions.conditions = new RuleConditionCollection(); foreach (RuleCondition r in this.conditions) newRuleDefinitions.conditions.Add(r.Clone()); } return newRuleDefinitions; } } #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
- NullableDecimalAverageAggregationOperator.cs
- HttpSessionStateWrapper.cs
- TdsRecordBufferSetter.cs
- TextRangeBase.cs
- SqlDataSourceSelectingEventArgs.cs
- HijriCalendar.cs
- SymmetricCryptoHandle.cs
- _LazyAsyncResult.cs
- ReferencedAssembly.cs
- EntityWithKeyStrategy.cs
- ProtocolElementCollection.cs
- EncoderBestFitFallback.cs
- GeometryConverter.cs
- RuleSetDialog.Designer.cs
- WindowsListViewItem.cs
- XmlSchemaAppInfo.cs
- EntityCommandCompilationException.cs
- DispatcherSynchronizationContext.cs
- ValidatingReaderNodeData.cs
- ToolStripItemTextRenderEventArgs.cs
- WebHttpBindingCollectionElement.cs
- DataKey.cs
- InvalidPrinterException.cs
- FormViewInsertedEventArgs.cs
- TextEndOfLine.cs
- MSAAWinEventWrap.cs
- RectangleGeometry.cs
- DefaultWorkflowTransactionService.cs
- AspCompat.cs
- DocumentScope.cs
- WinInetCache.cs
- HierarchicalDataSourceControl.cs
- SymmetricKeyWrap.cs
- TraceContextEventArgs.cs
- SmtpSection.cs
- Triangle.cs
- AttachedPropertyBrowsableWhenAttributePresentAttribute.cs
- RuntimeCompatibilityAttribute.cs
- WebPartConnectionsCancelEventArgs.cs
- XmlSchemaAnyAttribute.cs
- AstTree.cs
- UrlAuthorizationModule.cs
- EntityDataSourceMemberPath.cs
- SqlBulkCopy.cs
- SelectingProviderEventArgs.cs
- FontDifferentiator.cs
- XmlAttributeCollection.cs
- OdbcEnvironment.cs
- OrderedDictionaryStateHelper.cs
- RandomDelayQueuedSendsAsyncResult.cs
- SessionStateSection.cs
- DataServices.cs
- DataGridHeaderBorder.cs
- JsonDeserializer.cs
- UrlMappingsSection.cs
- CqlLexerHelpers.cs
- TransformPattern.cs
- LinkedResourceCollection.cs
- RuntimeResourceSet.cs
- ComponentCodeDomSerializer.cs
- MsmqMessage.cs
- DesignerSerializationVisibilityAttribute.cs
- DynamicHyperLink.cs
- DigestTraceRecordHelper.cs
- XmlSchemaSimpleType.cs
- OleServicesContext.cs
- XmlSchemaInferenceException.cs
- SqlInternalConnectionTds.cs
- SoapExtension.cs
- IdleTimeoutMonitor.cs
- ImageIndexEditor.cs
- DataServiceClientException.cs
- TabPage.cs
- DataGridViewCellMouseEventArgs.cs
- RSAProtectedConfigurationProvider.cs
- DtrList.cs
- HasCopySemanticsAttribute.cs
- securitycriticaldata.cs
- Cursors.cs
- TextTreeExtractElementUndoUnit.cs
- dbenumerator.cs
- KnownTypeHelper.cs
- TextSpanModifier.cs
- CompilationSection.cs
- SafeNativeMethods.cs
- XmlAggregates.cs
- HtmlInputRadioButton.cs
- CustomError.cs
- wmiprovider.cs
- BamlStream.cs
- StylusPointPropertyInfoDefaults.cs
- ArgumentOutOfRangeException.cs
- BamlWriter.cs
- CompatibleComparer.cs
- DesignerAdRotatorAdapter.cs
- SqlDataAdapter.cs
- HighlightVisual.cs
- SortExpressionBuilder.cs
- DataSourceXmlElementAttribute.cs
- AutoScrollHelper.cs