public void SetReference(string propertyName, IUpdateInstance instance) { Func <ResourceProperty, bool> func = null; if (instance != null) { Dictionary <string, object> keyValues = instance.GetKeyValues(); if (keyValues.Count <= 1) { foreach (KeyValuePair <string, object> keyValue in keyValues) { this.propertyUpdates[propertyName] = keyValue.Value; } return; } else { throw new NotImplementedException(); } } else { SortedDictionary <string, object> defaultValue = this.propertyUpdates; string str = propertyName; ReadOnlyCollection <ResourceProperty> properties = this.resourceType.Properties; if (func == null) { func = (ResourceProperty p) => p.Name == propertyName; } defaultValue[str] = properties.Single <ResourceProperty>(func).GetCustomState().DefaultValue; return; } }
public void SetValue(object resource, string propertyName, object propertyValue) { string str; string str1; Tracer current = TraceHelper.Current; string str2 = "DataServiceUpdateProvider"; string str3 = "SetValue"; if (resource == null) { str = "null"; } else { str = resource.ToString(); } string str4 = propertyName; if (propertyValue == null) { str1 = "null"; } else { str1 = propertyValue.ToString(); } current.MethodCall3(str2, str3, str, str4, str1); IUpdateInstance instanceFromHandle = this.GetInstanceFromHandle(resource); instanceFromHandle.SetValue(propertyName, propertyValue); }
internal IUpdateInstance GetInstanceFromHandle(object resource) { object str; IUpdateInstance updateInstance = resource as IUpdateInstance; string str1 = "resource"; bool flag = updateInstance == null; string invalidUpdateHandle = Resources.InvalidUpdateHandle; object[] objArray = new object[1]; object[] objArray1 = objArray; int num = 0; if (resource != null) { str = resource.ToString(); } else { str = string.Empty; } objArray1[num] = str; ExceptionHelpers.ThrowArgumentExceptionIf(str1, flag, invalidUpdateHandle, objArray); ExceptionHelpers.ThrowArgumentExceptionIf("resource", !this.instances.Contains(updateInstance), Resources.NoLongerValidUpdateHandle, new object[0]); return(updateInstance); }
public void AddReferenceToCollection(object targetResource, string propertyName, object resourceToBeAdded) { TraceHelper.Current.MethodCall0("DataServiceUpdateProvider", "AddReferenceToCollection"); IUpdateInstance instanceFromHandle = this.GetInstanceFromHandle(targetResource); IUpdateInstance updateInstance = this.GetInstanceFromHandle(resourceToBeAdded); (instanceFromHandle as EntityUpdate).AddReference(propertyName, updateInstance); this.entityInstance = instanceFromHandle; }
public object GetResource(IQueryable query, string fullTypeName) { object obj; TraceHelper.Current.MethodCall2("DataServiceUpdateProvider", "GetResource", query.ToString(), fullTypeName); try { DSLinqQueryProvider provider = query.Provider as DSLinqQueryProvider; ExceptionHelpers.ThrowArgumentExceptionIf("query", provider == null, Resources.QueryDoesNotIncludePswsProvider, new object[0]); if (!provider.IsFilterOverResourceRoot(query.Expression)) { ReferredResourceExtractor referredResourceExtractor = new ReferredResourceExtractor(); DSResource current = null; if (!referredResourceExtractor.Extract(query.Expression, provider.GetInitialQueryable(), provider.GetInitialResourceType(), provider.GetEntityMetadata(provider.GetInitialResourceType()))) { IEnumerator <DSResource> enumerator = (query.GetEnumerator() as IEnumerable <DSResource>).GetEnumerator(); if (enumerator.MoveNext()) { current = enumerator.Current; if (enumerator.MoveNext()) { throw new ArgumentException("multiple instances"); } } else { throw new ArgumentException("no instances"); } } else { current = referredResourceExtractor.ReferredResource; } ResourceType resourceType = current.ResourceType; EntityMetadata entityMetadata = provider.GetEntityMetadata(resourceType); IUpdateInstance referredEntityInstance = new ReferredEntityInstance(current, this.dataContext.UserContext, resourceType, entityMetadata, this.dataContext.MembershipId); this.instances.Add(referredEntityInstance); obj = referredEntityInstance; } else { ResourceType initialResourceType = provider.GetInitialResourceType(); EntityMetadata entityMetadatum = provider.GetEntityMetadata(initialResourceType); this.entityInstance = new EntityUpdate(CommandType.Update, this.dataContext.UserContext, initialResourceType, entityMetadatum, query, this.dataContext.MembershipId); this.instances.Add(this.entityInstance); obj = this.entityInstance; } } catch (ArgumentException argumentException1) { ArgumentException argumentException = argumentException1; TraceHelper.Current.InvalidUpdateQuery(fullTypeName, query.ToString(), argumentException.GetType().ToString(), argumentException.Message); obj = null; } return(obj); }
public void SetConcurrencyValues(object resourceCookie, bool?checkForEquality, IEnumerable <KeyValuePair <string, object> > concurrencyValues) { string str; string str1; bool hasValue; Tracer current = TraceHelper.Current; string str2 = "DataServiceUpdateProvider"; string str3 = "SetConcurrencyValues"; if (!checkForEquality.HasValue) { str = "null"; } else { str = checkForEquality.ToString(); } if (concurrencyValues == null) { str1 = "null"; } else { str1 = concurrencyValues.ToString(); } current.MethodCall2(str2, str3, str, str1); if (checkForEquality.HasValue) { bool?nullable = checkForEquality; if (nullable.GetValueOrDefault()) { hasValue = false; } else { hasValue = nullable.HasValue; } if (!hasValue) { IUpdateInstance instanceFromHandle = this.GetInstanceFromHandle(resourceCookie); instanceFromHandle.VerifyConcurrencyValues(concurrencyValues); return; } else { throw new NotImplementedException(); } } else { return; } }
internal static object ResolveUpdatableObject(object value) { IUpdateInstance updateInstance = value as IUpdateInstance; if (updateInstance == null) { return(value); } else { return(updateInstance.Resolve()); } }
public void RemoveReference(string propertyName, IUpdateInstance instance) { this.referringProperty = this.resourceType.Properties.FirstOrDefault <ResourceProperty>((ResourceProperty it) => string.Equals(propertyName, it.Name, StringComparison.Ordinal)); if (this.referringProperty != null) { this.commandType = CommandType.RemoveReference; this.referredInstance = instance; return; } else { throw new ArgumentException("not a reference property"); } }
internal static Dictionary <string, object> CreateResolvedDictionary(Dictionary <string, object> properties) { Dictionary <string, object> strs = new Dictionary <string, object>(); foreach (string key in properties.Keys) { object item = properties[key]; IUpdateInstance updateInstance = item as IUpdateInstance; if (updateInstance != null) { item = updateInstance.Resolve(); } strs.Add(key, item); } return(strs); }
public object CreateResource(string containerName, string fullTypeName) { TraceHelper.Current.MethodCall2("DataServiceUpdateProvider", "AddReferenceToCollection", containerName, fullTypeName); ResourceType resourceType = null; if (containerName != null) { ResourceSet resourceSet = null; this.dataContext.UserSchema.ResourceSets.TryGetValue(containerName, out resourceSet); object[] objArray = new object[1]; objArray[0] = containerName; ExceptionHelpers.ThrowArgumentExceptionIf("set", resourceSet == null, Resources.MissingResourceSet, objArray); if (this.entityInstance == null) { resourceType = resourceSet.ResourceType; EntityMetadata item = this.dataContext.UserSchema.EntityMetadataDictionary[resourceSet.ResourceType.FullName]; this.entityInstance = new EntityUpdate(this.dataContext.UserContext, resourceType, item, this.dataContext.MembershipId); this.instances.Add(this.entityInstance); return(this.entityInstance); } else { throw new NotImplementedException(ExceptionHelpers.GetExceptionMessage(Resources.BatchUpdatesNotSupported, new object[0])); } } else { this.dataContext.UserSchema.ResourceTypes.TryGetValue(fullTypeName, out resourceType); if (resourceType != null) { object[] objArray1 = new object[1]; objArray1[0] = fullTypeName; ExceptionHelpers.ThrowArgumentExceptionIf("fullTypeName", resourceType.ResourceTypeKind != ResourceTypeKind.ComplexType, Resources.NotAComplexType, objArray1); IUpdateInstance complexTypeInstance = new ComplexTypeInstance(resourceType); this.instances.Add(complexTypeInstance); return(complexTypeInstance); } else { TraceHelper.Current.ResourceTypeNotFound(fullTypeName); object[] objArray2 = new object[1]; objArray2[0] = fullTypeName; throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.MissingResourceType, objArray2)); } } }
public object CreateResource(string containerName, string fullTypeName) { TraceHelper.Current.MethodCall2("DataServiceUpdateProvider", "AddReferenceToCollection", containerName, fullTypeName); ResourceType resourceType = null; if (containerName != null) { ResourceSet resourceSet = null; this.dataContext.UserSchema.ResourceSets.TryGetValue(containerName, out resourceSet); object[] objArray = new object[1]; objArray[0] = containerName; ExceptionHelpers.ThrowArgumentExceptionIf("set", resourceSet == null, Resources.MissingResourceSet, objArray); if (this.entityInstance == null) { resourceType = resourceSet.ResourceType; EntityMetadata item = this.dataContext.UserSchema.EntityMetadataDictionary[resourceSet.ResourceType.FullName]; this.entityInstance = new EntityUpdate(this.dataContext.UserContext, resourceType, item, this.dataContext.MembershipId); this.instances.Add(this.entityInstance); return this.entityInstance; } else { throw new NotImplementedException(ExceptionHelpers.GetExceptionMessage(Resources.BatchUpdatesNotSupported, new object[0])); } } else { this.dataContext.UserSchema.ResourceTypes.TryGetValue(fullTypeName, out resourceType); if (resourceType != null) { object[] objArray1 = new object[1]; objArray1[0] = fullTypeName; ExceptionHelpers.ThrowArgumentExceptionIf("fullTypeName", resourceType.ResourceTypeKind != ResourceTypeKind.ComplexType, Resources.NotAComplexType, objArray1); IUpdateInstance complexTypeInstance = new ComplexTypeInstance(resourceType); this.instances.Add(complexTypeInstance); return complexTypeInstance; } else { TraceHelper.Current.ResourceTypeNotFound(fullTypeName); object[] objArray2 = new object[1]; objArray2[0] = fullTypeName; throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.MissingResourceType, objArray2)); } } }
public void DeleteResource(object resource) { string str; Tracer current = TraceHelper.Current; string str1 = "DataServiceUpdateProvider"; string str2 = "DeleteResource"; if (resource == null) { str = "null"; } else { str = resource.ToString(); } current.MethodCall1(str1, str2, str); IUpdateInstance instanceFromHandle = this.GetInstanceFromHandle(resource); instanceFromHandle.Delete(); }
public void SetReference(string propertyName, IUpdateInstance instance) { throw new NotImplementedException(); }
public void SetReference(string propertyName, IUpdateInstance instance) { Func<ResourceProperty, bool> func = null; if (instance != null) { Dictionary<string, object> keyValues = instance.GetKeyValues(); if (keyValues.Count <= 1) { foreach (KeyValuePair<string, object> keyValue in keyValues) { this.propertyUpdates[propertyName] = keyValue.Value; } return; } else { throw new NotImplementedException(); } } else { SortedDictionary<string, object> defaultValue = this.propertyUpdates; string str = propertyName; ReadOnlyCollection<ResourceProperty> properties = this.resourceType.Properties; if (func == null) { func = (ResourceProperty p) => p.Name == propertyName; } defaultValue[str] = properties.Single<ResourceProperty>(func).GetCustomState().DefaultValue; return; } }
public void RemoveReference(string propertyName, IUpdateInstance instance) { this.referringProperty = this.resourceType.Properties.FirstOrDefault<ResourceProperty>((ResourceProperty it) => string.Equals(propertyName, it.Name, StringComparison.Ordinal)); if (this.referringProperty != null) { this.commandType = CommandType.RemoveReference; this.referredInstance = instance; return; } else { throw new ArgumentException("not a reference property"); } }
public object GetResource(IQueryable query, string fullTypeName) { object obj; TraceHelper.Current.MethodCall2("DataServiceUpdateProvider", "GetResource", query.ToString(), fullTypeName); try { DSLinqQueryProvider provider = query.Provider as DSLinqQueryProvider; ExceptionHelpers.ThrowArgumentExceptionIf("query", provider == null, Resources.QueryDoesNotIncludePswsProvider, new object[0]); if (!provider.IsFilterOverResourceRoot(query.Expression)) { ReferredResourceExtractor referredResourceExtractor = new ReferredResourceExtractor(); DSResource current = null; if (!referredResourceExtractor.Extract(query.Expression, provider.GetInitialQueryable(), provider.GetInitialResourceType(), provider.GetEntityMetadata(provider.GetInitialResourceType()))) { IEnumerator<DSResource> enumerator = (query.GetEnumerator() as IEnumerable<DSResource>).GetEnumerator(); if (enumerator.MoveNext()) { current = enumerator.Current; if (enumerator.MoveNext()) { throw new ArgumentException("multiple instances"); } } else { throw new ArgumentException("no instances"); } } else { current = referredResourceExtractor.ReferredResource; } ResourceType resourceType = current.ResourceType; EntityMetadata entityMetadata = provider.GetEntityMetadata(resourceType); IUpdateInstance referredEntityInstance = new ReferredEntityInstance(current, this.dataContext.UserContext, resourceType, entityMetadata, this.dataContext.MembershipId); this.instances.Add(referredEntityInstance); obj = referredEntityInstance; } else { ResourceType initialResourceType = provider.GetInitialResourceType(); EntityMetadata entityMetadatum = provider.GetEntityMetadata(initialResourceType); this.entityInstance = new EntityUpdate(CommandType.Update, this.dataContext.UserContext, initialResourceType, entityMetadatum, query, this.dataContext.MembershipId); this.instances.Add(this.entityInstance); obj = this.entityInstance; } } catch (ArgumentException argumentException1) { ArgumentException argumentException = argumentException1; TraceHelper.Current.InvalidUpdateQuery(fullTypeName, query.ToString(), argumentException.GetType().ToString(), argumentException.Message); obj = null; } return obj; }