Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / System.Runtime.DurableInstancing / System / Runtime / DurableInstancing / InstancePersistence.cs / 1305376 / InstancePersistence.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Runtime.DurableInstancing { using System; using System.Collections.Generic; using System.Runtime; using System.Xml.Linq; static class InstancePersistence { static readonly XNamespace activitiesCommandNamespace = XNamespace.Get("urn:schemas-microsoft-com:System.Activities.Persistence/command"); static readonly XNamespace activitiesEventNamespace = XNamespace.Get("urn:schemas-microsoft-com:System.Activities.Persistence/event"); internal static XNamespace ActivitiesCommandNamespace { get { return InstancePersistence.activitiesCommandNamespace; } } internal static XNamespace ActivitiesEventNamespace { get { return InstancePersistence.activitiesEventNamespace; } } public static void ValidatePropertyBag(this IDictionarybag) { bag.ValidatePropertyBag(false); } public static void ValidatePropertyBag(this IDictionary bag, bool allowDelete) { if (bag != null) { foreach (KeyValuePair property in bag) { property.ValidateProperty(allowDelete); } } } public static void ValidateProperty(this KeyValuePair property) { property.ValidateProperty(false); } public static void ValidateProperty(this KeyValuePair property, bool allowDelete) { if (property.Key == null) { throw Fx.Exception.AsError(new InvalidOperationException(SRCore.MetadataCannotContainNullKey)); } if (property.Value == null) { throw Fx.Exception.AsError(new InvalidOperationException(SRCore.MetadataCannotContainNullValue(property.Key))); } if (!allowDelete && property.Value.IsDeletedValue) { throw Fx.Exception.AsError(new InvalidOperationException(SRCore.InitialMetadataCannotBeDeleted(property.Key))); } } public static bool IsOptional(this InstanceValue value) { return (value.Options & InstanceValueOptions.Optional) != 0; } public static bool IsWriteOnly(this InstanceValue value) { return (value.Options & InstanceValueOptions.WriteOnly) != 0; } public static ReadOnlyDictionary ReadOnlyCopy(this IDictionary bag, bool allowWriteOnly) { if (bag != null && bag.Count > 0) { Dictionary copy = new Dictionary (bag.Count); foreach (KeyValuePair value in bag) { value.ValidateProperty(); if (!value.Value.IsWriteOnly()) { copy.Add(value.Key, value.Value); } else if (!allowWriteOnly) { throw Fx.Exception.AsError(new InvalidOperationException(SRCore.LoadedWriteOnlyValue)); } } return new ReadOnlyDictionary (copy, false); } else { return null; } } public static ReadOnlyDictionary ReadOnlyMergeInto(this IDictionary bag, IDictionary existing, bool allowWriteOnly) { Fx.Assert(existing == null || existing is ReadOnlyDictionary , "Should only be merging into other read-only dictionaries."); if (bag != null && bag.Count > 0) { Dictionary copy = existing == null ? new Dictionary (bag.Count) : new Dictionary (existing); foreach (KeyValuePair value in bag) { value.ValidateProperty(true); if (value.Value.IsDeletedValue) { copy.Remove(value.Key); } else if (!value.Value.IsWriteOnly()) { copy[value.Key] = value.Value; } else if (!allowWriteOnly) { throw Fx.Exception.AsError(new InvalidOperationException(SRCore.LoadedWriteOnlyValue)); } else { copy.Remove(value.Key); } } return new ReadOnlyDictionary (copy, false); } else { return (ReadOnlyDictionary ) existing; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Runtime.DurableInstancing { using System; using System.Collections.Generic; using System.Runtime; using System.Xml.Linq; static class InstancePersistence { static readonly XNamespace activitiesCommandNamespace = XNamespace.Get("urn:schemas-microsoft-com:System.Activities.Persistence/command"); static readonly XNamespace activitiesEventNamespace = XNamespace.Get("urn:schemas-microsoft-com:System.Activities.Persistence/event"); internal static XNamespace ActivitiesCommandNamespace { get { return InstancePersistence.activitiesCommandNamespace; } } internal static XNamespace ActivitiesEventNamespace { get { return InstancePersistence.activitiesEventNamespace; } } public static void ValidatePropertyBag(this IDictionary bag) { bag.ValidatePropertyBag(false); } public static void ValidatePropertyBag(this IDictionary bag, bool allowDelete) { if (bag != null) { foreach (KeyValuePair property in bag) { property.ValidateProperty(allowDelete); } } } public static void ValidateProperty(this KeyValuePair property) { property.ValidateProperty(false); } public static void ValidateProperty(this KeyValuePair property, bool allowDelete) { if (property.Key == null) { throw Fx.Exception.AsError(new InvalidOperationException(SRCore.MetadataCannotContainNullKey)); } if (property.Value == null) { throw Fx.Exception.AsError(new InvalidOperationException(SRCore.MetadataCannotContainNullValue(property.Key))); } if (!allowDelete && property.Value.IsDeletedValue) { throw Fx.Exception.AsError(new InvalidOperationException(SRCore.InitialMetadataCannotBeDeleted(property.Key))); } } public static bool IsOptional(this InstanceValue value) { return (value.Options & InstanceValueOptions.Optional) != 0; } public static bool IsWriteOnly(this InstanceValue value) { return (value.Options & InstanceValueOptions.WriteOnly) != 0; } public static ReadOnlyDictionary ReadOnlyCopy(this IDictionary bag, bool allowWriteOnly) { if (bag != null && bag.Count > 0) { Dictionary copy = new Dictionary (bag.Count); foreach (KeyValuePair value in bag) { value.ValidateProperty(); if (!value.Value.IsWriteOnly()) { copy.Add(value.Key, value.Value); } else if (!allowWriteOnly) { throw Fx.Exception.AsError(new InvalidOperationException(SRCore.LoadedWriteOnlyValue)); } } return new ReadOnlyDictionary (copy, false); } else { return null; } } public static ReadOnlyDictionary ReadOnlyMergeInto(this IDictionary bag, IDictionary existing, bool allowWriteOnly) { Fx.Assert(existing == null || existing is ReadOnlyDictionary , "Should only be merging into other read-only dictionaries."); if (bag != null && bag.Count > 0) { Dictionary copy = existing == null ? new Dictionary (bag.Count) : new Dictionary (existing); foreach (KeyValuePair value in bag) { value.ValidateProperty(true); if (value.Value.IsDeletedValue) { copy.Remove(value.Key); } else if (!value.Value.IsWriteOnly()) { copy[value.Key] = value.Value; } else if (!allowWriteOnly) { throw Fx.Exception.AsError(new InvalidOperationException(SRCore.LoadedWriteOnlyValue)); } else { copy.Remove(value.Key); } } return new ReadOnlyDictionary (copy, false); } else { return (ReadOnlyDictionary ) existing; } } } } // 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
- XmlSerializerNamespaces.cs
- Fault.cs
- ConfigurationPermission.cs
- AliasedSlot.cs
- Point3DConverter.cs
- JsonClassDataContract.cs
- ReadOnlyDataSource.cs
- ObjectViewFactory.cs
- _AutoWebProxyScriptEngine.cs
- WebServiceMethodData.cs
- DataMisalignedException.cs
- SuppressMessageAttribute.cs
- securitycriticaldata.cs
- OutputCacheProfile.cs
- GenericIdentity.cs
- ProtocolsSection.cs
- DataBindingsDialog.cs
- SendMessageChannelCache.cs
- BoolExpressionVisitors.cs
- TextServicesContext.cs
- NotSupportedException.cs
- ToolTipAutomationPeer.cs
- ReadOnlyCollection.cs
- XmlConverter.cs
- PEFileReader.cs
- ComponentResourceManager.cs
- ProtocolsSection.cs
- ManagedWndProcTracker.cs
- PathSegmentCollection.cs
- FragmentNavigationEventArgs.cs
- TemplateBaseAction.cs
- RolePrincipal.cs
- ArraySortHelper.cs
- StringTraceRecord.cs
- Base64Decoder.cs
- RootBrowserWindow.cs
- FixedTextPointer.cs
- HatchBrush.cs
- XmlIlGenerator.cs
- ItemChangedEventArgs.cs
- ZoneIdentityPermission.cs
- ApplicationGesture.cs
- Pipe.cs
- CollectionCodeDomSerializer.cs
- Model3DGroup.cs
- Int64Storage.cs
- MultiPropertyDescriptorGridEntry.cs
- BeginEvent.cs
- Matrix.cs
- XmlSchemaParticle.cs
- SqlDataReaderSmi.cs
- SessionEndingEventArgs.cs
- ElementInit.cs
- ResizeGrip.cs
- ProtectedUri.cs
- AsymmetricAlgorithm.cs
- MediaTimeline.cs
- TransformConverter.cs
- XPathAxisIterator.cs
- TreeNodeCollection.cs
- ThemeDirectoryCompiler.cs
- ContractHandle.cs
- RequestTimeoutManager.cs
- UnsignedPublishLicense.cs
- CodeMemberMethod.cs
- InvalidCastException.cs
- KoreanCalendar.cs
- StrokeCollection.cs
- XmlSchemaSimpleContent.cs
- MLangCodePageEncoding.cs
- SystemWebSectionGroup.cs
- Ticks.cs
- XmlDocumentFragment.cs
- VirtualDirectoryMapping.cs
- ConnectionManagementSection.cs
- DebuggerService.cs
- SizeAnimation.cs
- MemberRestriction.cs
- SQLRoleProvider.cs
- PngBitmapDecoder.cs
- NamespaceEmitter.cs
- FunctionMappingTranslator.cs
- ResourceDictionary.cs
- ThemeInfoAttribute.cs
- StrokeNodeOperations2.cs
- BindingWorker.cs
- ComponentConverter.cs
- MouseEventArgs.cs
- TextAutomationPeer.cs
- ValidationErrorCollection.cs
- WrapPanel.cs
- WebControl.cs
- BypassElementCollection.cs
- HybridDictionary.cs
- Image.cs
- ProtocolsConfiguration.cs
- DesignerCatalogPartChrome.cs
- SqlGenerator.cs
- TemplateBindingExtension.cs
- SecurityManager.cs