Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / Model / CollectionChange.cs / 1305376 / CollectionChange.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.Model { using System.Runtime; class CollectionChange : ModelChange { public ModelItemCollection Collection { get; set; } public int Index { get; set; } public ModelItem Item { get; set; } public OperationType Operation { get; set; } public ModelTreeManager ModelTreeManager { get; set; } public override string Description { get { return this.Operation == OperationType.Insert ? SR.CollectionAddEditingScopeDescription : SR.CollectionRemoveEditingScopeDescription; } } public override bool Apply() { switch (this.Operation) { case OperationType.Insert: ApplyInsert(); break; case OperationType.Delete: ApplyDelete(); break; default: Fx.Assert("Operation should be Insert or Delete"); break; } return true; } private void ApplyDelete() { Fx.Assert(this.ModelTreeManager != null, "ModelTreeManager cannot be null."); Fx.Assert(this.Collection != null, "this.Collection cannot be null."); if (this.Index >= 0) { ((ModelItemCollectionImpl)this.Collection).RemoveAtCore(this.Index); } else { Fx.Assert(this.Index == -1, "-1 must be used to indicate Remove(item)"); this.Index = this.Collection.IndexOf(this.Item); ((ModelItemCollectionImpl)this.Collection).RemoveCore(this.Item); } // if no more this.Item exists in this.Collection, then this.Item should be released from the ModelTree. if (this.Collection.IndexOf(this.Item) == -1) { ((IModelTreeItem)this.Item).RemoveParent(this.Collection); this.ModelTreeManager.ReleaseModelItem(this.Item, this.Collection); } this.ModelTreeManager.NotifyCollectionRemove(this.Item); } private void ApplyInsert() { Fx.Assert(this.ModelTreeManager != null, "ModelTreeManager cannot be null."); Fx.Assert(this.Collection != null, "this.Collection cannot be null."); this.ModelTreeManager.ReAddModelItemToModelTree(this.Item); if (this.Index >= 0) { ((ModelItemCollectionImpl)this.Collection).InsertCore(this.Index, this.Item); } else { Fx.Assert(this.Index == -1, "-1 must be used to indicate Add(item)"); this.Index = this.Collection.Count; ((ModelItemCollectionImpl)this.Collection).AddCore(this.Item); } this.ModelTreeManager.NotifyCollectionInsert(this.Item); } public override Change GetInverse() { OperationType reverseOperation = this.Operation == OperationType.Insert ? OperationType.Delete : OperationType.Insert; return new CollectionChange() { Collection = this.Collection, Operation = reverseOperation, Item = this.Item, ModelTreeManager = this.ModelTreeManager, Index = this.Index }; } public enum OperationType { Insert, Delete } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.Model { using System.Runtime; class CollectionChange : ModelChange { public ModelItemCollection Collection { get; set; } public int Index { get; set; } public ModelItem Item { get; set; } public OperationType Operation { get; set; } public ModelTreeManager ModelTreeManager { get; set; } public override string Description { get { return this.Operation == OperationType.Insert ? SR.CollectionAddEditingScopeDescription : SR.CollectionRemoveEditingScopeDescription; } } public override bool Apply() { switch (this.Operation) { case OperationType.Insert: ApplyInsert(); break; case OperationType.Delete: ApplyDelete(); break; default: Fx.Assert("Operation should be Insert or Delete"); break; } return true; } private void ApplyDelete() { Fx.Assert(this.ModelTreeManager != null, "ModelTreeManager cannot be null."); Fx.Assert(this.Collection != null, "this.Collection cannot be null."); if (this.Index >= 0) { ((ModelItemCollectionImpl)this.Collection).RemoveAtCore(this.Index); } else { Fx.Assert(this.Index == -1, "-1 must be used to indicate Remove(item)"); this.Index = this.Collection.IndexOf(this.Item); ((ModelItemCollectionImpl)this.Collection).RemoveCore(this.Item); } // if no more this.Item exists in this.Collection, then this.Item should be released from the ModelTree. if (this.Collection.IndexOf(this.Item) == -1) { ((IModelTreeItem)this.Item).RemoveParent(this.Collection); this.ModelTreeManager.ReleaseModelItem(this.Item, this.Collection); } this.ModelTreeManager.NotifyCollectionRemove(this.Item); } private void ApplyInsert() { Fx.Assert(this.ModelTreeManager != null, "ModelTreeManager cannot be null."); Fx.Assert(this.Collection != null, "this.Collection cannot be null."); this.ModelTreeManager.ReAddModelItemToModelTree(this.Item); if (this.Index >= 0) { ((ModelItemCollectionImpl)this.Collection).InsertCore(this.Index, this.Item); } else { Fx.Assert(this.Index == -1, "-1 must be used to indicate Add(item)"); this.Index = this.Collection.Count; ((ModelItemCollectionImpl)this.Collection).AddCore(this.Item); } this.ModelTreeManager.NotifyCollectionInsert(this.Item); } public override Change GetInverse() { OperationType reverseOperation = this.Operation == OperationType.Insert ? OperationType.Delete : OperationType.Insert; return new CollectionChange() { Collection = this.Collection, Operation = reverseOperation, Item = this.Item, ModelTreeManager = this.ModelTreeManager, Index = this.Index }; } public enum OperationType { Insert, Delete } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- LightweightCodeGenerator.cs
- NavigateEvent.cs
- TrustManager.cs
- AnimationException.cs
- CharEntityEncoderFallback.cs
- ControlAdapter.cs
- OracleEncoding.cs
- CollectionViewSource.cs
- InvalidDataContractException.cs
- SelectionItemPattern.cs
- RegionInfo.cs
- Propagator.ExtentPlaceholderCreator.cs
- AvTraceFormat.cs
- SafeSystemMetrics.cs
- Size.cs
- XamlContextStack.cs
- BamlLocalizer.cs
- Translator.cs
- WorkflowServiceHost.cs
- SamlAudienceRestrictionCondition.cs
- CompilationUnit.cs
- ToolStripSystemRenderer.cs
- TimelineGroup.cs
- DbExpressionVisitor_TResultType.cs
- SelectionRange.cs
- CompressedStack.cs
- InlineUIContainer.cs
- DesignTimeType.cs
- EntityViewGenerationAttribute.cs
- CompositeScriptReference.cs
- XmlAnyElementAttributes.cs
- WebServiceReceive.cs
- WebScriptMetadataFormatter.cs
- MailDefinition.cs
- KeyEventArgs.cs
- WrappedReader.cs
- IOThreadTimer.cs
- BuildProvider.cs
- TextTreeInsertUndoUnit.cs
- HostingEnvironmentException.cs
- DatatypeImplementation.cs
- RequestCachePolicyConverter.cs
- XmlSchemaCollection.cs
- RemoteX509Token.cs
- Partitioner.cs
- ComponentResourceManager.cs
- DbBuffer.cs
- bindurihelper.cs
- QuaternionValueSerializer.cs
- Visitor.cs
- EvidenceTypeDescriptor.cs
- WebUtil.cs
- DiagnosticsConfiguration.cs
- _SslState.cs
- ZipIOLocalFileHeader.cs
- ParsedAttributeCollection.cs
- GestureRecognizer.cs
- AnonymousIdentificationModule.cs
- BamlTreeNode.cs
- ControlTemplate.cs
- DbMetaDataFactory.cs
- PathSegmentCollection.cs
- DataSetSchema.cs
- RawMouseInputReport.cs
- HttpRequestBase.cs
- SystemShuttingDownException.cs
- ListCollectionView.cs
- XmlHierarchyData.cs
- AnnouncementClient.cs
- SemaphoreSecurity.cs
- AttachInfo.cs
- ControlOperationInvoker.cs
- KeyFrames.cs
- nulltextcontainer.cs
- LineProperties.cs
- MobileListItemCollection.cs
- Command.cs
- ISFTagAndGuidCache.cs
- ServiceManager.cs
- WsatServiceAddress.cs
- CroppedBitmap.cs
- HtmlTableRow.cs
- altserialization.cs
- ParameterCollectionEditorForm.cs
- UnaryExpression.cs
- BindToObject.cs
- ping.cs
- PixelFormat.cs
- DrawingGroup.cs
- XsltSettings.cs
- EngineSite.cs
- DbDataReader.cs
- Query.cs
- AxisAngleRotation3D.cs
- SafeViewOfFileHandle.cs
- XpsSerializerWriter.cs
- RegionData.cs
- ConfigErrorGlyph.cs
- HttpPostedFile.cs
- PolicyDesigner.cs