1 //Copyright 2010 Microsoft Corporation 2 // 3 //Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 4 //You may obtain a copy of the License at 5 // 6 //http://www.apache.org/licenses/LICENSE-2.0 7 // 8 //Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an 9 //"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 //See the License for the specific language governing permissions and limitations under the License. 11 12 13 namespace System.Data.Services.Client 14 { 15 #region Namespaces. 16 17 using System; 18 using System.Collections; 19 using System.Collections.Generic; 20 using System.Diagnostics; 21 using System.Linq; 22 using System.Reflection; 23 using System.Xml; 24 using System.Xml.Linq; 25 using System.Text; 26 27 #endregion Namespaces. 28 29 [DebuggerDisplay("AtomEntry {ResolvedObject} @ {Identity}")] 30 internal class AtomEntry 31 { 32 #region Private fields. 33 34 private EntryFlags flags; 35 36 [Flags] 37 private enum EntryFlags 38 { 39 ShouldUpdateFromPayload = 0x01, 40 41 CreatedByMaterializer = 0x02, 42 43 EntityHasBeenResolved = 0x04, 44 45 MediaLinkEntryValue = 0x08, 46 47 MediaLinkEntryAssigned = 0x10, 48 49 EntityPropertyMappingsApplied = 0x20, 50 51 IsNull = 0x40 52 } 53 54 #endregion Private fields. 55 56 #region Public properties. 57 58 public bool? MediaLinkEntry 59 { 60 get 61 { 62 return this.GetFlagValue(EntryFlags.MediaLinkEntryAssigned) ? (bool?)this.GetFlagValue(EntryFlags.MediaLinkEntryValue) : null; 63 } 64 65 set 66 { 67 Debug.Assert(value.HasValue, "value.HasValue -- callers shouldn't set the value to unknown"); 68 this.SetFlagValue(EntryFlags.MediaLinkEntryAssigned, true); 69 this.SetFlagValue(EntryFlags.MediaLinkEntryValue, value.Value); 70 } 71 } 72 73 public Uri MediaContentUri 74 { 75 get; 76 set; 77 } 78 79 public Uri MediaEditUri 80 { 81 get; 82 set; 83 } 84 85 public string TypeName 86 { 87 get; 88 set; 89 } 90 91 public ClientType ActualType 92 { 93 get; 94 set; 95 } 96 97 public Uri EditLink 98 { 99 get; 100 set; 101 } 102 103 public Uri QueryLink 104 { 105 get; 106 set; 107 } 108 109 public string Identity 110 { 111 get; 112 set; 113 } 114 115 public bool IsNull 116 { 117 get { return this.GetFlagValue(EntryFlags.IsNull); } 118 set { this.SetFlagValue(EntryFlags.IsNull, value); } 119 } 120 121 public List<AtomContentProperty> DataValues 122 { 123 get; 124 set; 125 } 126 127 public object ResolvedObject 128 { 129 get; 130 set; 131 } 132 133 public object Tag 134 { 135 get; 136 set; 137 } 138 139 public string ETagText 140 { 141 get; 142 set; 143 } 144 145 public string StreamETagText 146 { 147 get; 148 set; 149 } 150 151 public bool ShouldUpdateFromPayload 152 { 153 get { return this.GetFlagValue(EntryFlags.ShouldUpdateFromPayload); } 154 set { this.SetFlagValue(EntryFlags.ShouldUpdateFromPayload, value); } 155 } 156 157 public bool CreatedByMaterializer 158 { 159 get { return this.GetFlagValue(EntryFlags.CreatedByMaterializer); } 160 set { this.SetFlagValue(EntryFlags.CreatedByMaterializer, value); } 161 } 162 163 public bool EntityHasBeenResolved 164 { 165 get { return this.GetFlagValue(EntryFlags.EntityHasBeenResolved); } 166 set { this.SetFlagValue(EntryFlags.EntityHasBeenResolved, value); } 167 } 168 169 public bool EntityPropertyMappingsApplied 170 { 171 get { return this.GetFlagValue(EntryFlags.EntityPropertyMappingsApplied); } 172 set { this.SetFlagValue(EntryFlags.EntityPropertyMappingsApplied, value); } 173 } 174 175 #endregion Public properties. 176 177 #region Private methods. 178 GetFlagValue(EntryFlags mask)179 private bool GetFlagValue(EntryFlags mask) 180 { 181 return (this.flags & mask) != 0; 182 } 183 SetFlagValue(EntryFlags mask, bool value)184 private void SetFlagValue(EntryFlags mask, bool value) 185 { 186 if (value) 187 { 188 this.flags |= mask; 189 } 190 else 191 { 192 this.flags &= (~mask); 193 } 194 } 195 196 #endregion Private methods. 197 } 198 } 199