本文整理汇总了C#中IDataService.GetResource方法的典型用法代码示例。如果您正苦于以下问题:C# IDataService.GetResource方法的具体用法?C# IDataService.GetResource怎么用?C# IDataService.GetResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataService
的用法示例。
在下文中一共展示了IDataService.GetResource方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetResourceToModify
/// <summary>
/// Returns the last segment info whose target request kind is resource
/// </summary>
/// <param name="description">description about the target request</param>
/// <param name="service">data service type to which the request was made</param>
/// <param name="allowCrossReferencing">whether cross-referencing is allowed for the resource in question.</param>
/// <param name="entityResource">entity resource which is getting modified.</param>
/// <param name="entityContainer">entity container of the entity which is getting modified.</param>
/// <param name="checkETag">whether to check the etag for the entity resource that is getting modified.</param>
/// <returns>Returns the object that needs to get modified</returns>
internal static object GetResourceToModify(
RequestDescription description,
IDataService service,
bool allowCrossReferencing,
out object entityResource,
out ResourceSetWrapper entityContainer,
bool checkETag)
{
Debug.Assert(description.SegmentInfos.Length >= 2, "description.SegmentInfos.Length >= 2");
UpdatableWrapper updatable = service.Updatable;
if (!allowCrossReferencing && description.RequestEnumerable == null)
{
throw DataServiceException.CreateBadRequestError(Strings.BadRequest_ResourceCanBeCrossReferencedOnlyForBindOperation);
}
// Set the index of the modifying resource
int modifyingResourceIndex = -1;
if (
description.TargetKind == RequestTargetKind.OpenPropertyValue ||
description.TargetKind == RequestTargetKind.PrimitiveValue)
{
modifyingResourceIndex = description.SegmentInfos.Length - 3;
}
else
{
modifyingResourceIndex = description.SegmentInfos.Length - 2;
}
// Get the index of the entity resource that is getting modified
int entityResourceIndex = -1;
if (description.LinkUri)
{
entityResourceIndex = modifyingResourceIndex;
}
else
{
for (int j = modifyingResourceIndex; j >= 0; j--)
{
if (description.SegmentInfos[j].TargetKind == RequestTargetKind.Resource ||
description.SegmentInfos[j].HasKeyValues)
{
entityResourceIndex = j;
break;
}
}
}
Debug.Assert(entityResourceIndex != -1, "This method should never be called for request that doesn't have a parent resource");
entityContainer = description.SegmentInfos[entityResourceIndex].TargetContainer;
if (entityContainer != null)
{
DataServiceHostWrapper host = service.OperationContext.Host;
// Since this is the entity which is going to get modified, then we need to check for rights
if (host.AstoriaHttpVerb == AstoriaVerbs.PUT)
{
DataServiceConfiguration.CheckResourceRights(entityContainer, EntitySetRights.WriteReplace);
}
else if (host.AstoriaHttpVerb == AstoriaVerbs.MERGE)
{
DataServiceConfiguration.CheckResourceRights(entityContainer, EntitySetRights.WriteMerge);
}
else
{
Debug.Assert(
host.AstoriaHttpVerb == AstoriaVerbs.POST ||
host.AstoriaHttpVerb == AstoriaVerbs.DELETE,
"expecting POST and DELETE methods");
DataServiceConfiguration.CheckResourceRights(entityContainer, EntitySetRights.WriteMerge | EntitySetRights.WriteReplace);
}
}
entityResource = service.GetResource(description, entityResourceIndex, null);
if (entityResource == null)
{
throw DataServiceException.CreateBadRequestError(Strings.BadRequest_DereferencingNullPropertyValue(description.SegmentInfos[entityResourceIndex].Identifier));
}
// now walk from the entity resource to the resource to modify.
// for open types, as you walk, if the intermediate resource is an entity,
// update the entityResource accordingly.
object resourceToModify = entityResource;
for (int i = entityResourceIndex + 1; i <= modifyingResourceIndex; i++)
{
resourceToModify = updatable.GetValue(resourceToModify, description.SegmentInfos[i].Identifier);
}
if (entityContainer == null)
//.........这里部分代码省略.........
示例2: GetEntityResourceToModify
/// <summary>
/// Returns the entity that need to get modified
/// </summary>
/// <param name="description">description about the target request</param>
/// <param name="service">data service type to which the request was made</param>
/// <param name="allowCrossReferencing">whether cross-referencing is allowed for the resource in question.</param>
/// <param name="entityContainer">entity container of the entity which is getting modified.</param>
/// <param name="entityResourceIndex">index of the segment which refers to the entity getting modified.</param>
/// <returns>Returns the entity that needs to get modified</returns>
private static object GetEntityResourceToModify(
RequestDescription description,
IDataService service,
bool allowCrossReferencing,
out ResourceSetWrapper entityContainer,
out int entityResourceIndex)
{
Debug.Assert(description.SegmentInfos.Count >= 2, "description.SegmentInfos.Count >= 2");
if (!allowCrossReferencing && description.RequestExpression == null)
{
throw DataServiceException.CreateBadRequestError(Strings.BadRequest_ResourceCanBeCrossReferencedOnlyForBindOperation);
}
// Get the index of the entity resource that is getting modified
entityResourceIndex = Deserializer.GetIndexOfEntityResourceToModify(description);
Debug.Assert(entityResourceIndex != -1, "This method should never be called for request that doesn't have a parent resource");
entityContainer = description.SegmentInfos[entityResourceIndex].TargetResourceSet;
Debug.Assert(entityContainer != null, "Entity container cannot be null for segments whose targetkind is resource");
AstoriaRequestMessage host = service.OperationContext.RequestMessage;
// Since this is the entity which is going to get modified, then we need to check for rights
if (host.HttpVerb == HttpVerbs.PUT)
{
DataServiceConfiguration.CheckResourceRights(entityContainer, EntitySetRights.WriteReplace);
}
else if (host.HttpVerb == HttpVerbs.PATCH)
{
DataServiceConfiguration.CheckResourceRights(entityContainer, EntitySetRights.WriteMerge);
}
else
{
Debug.Assert(
host.HttpVerb == HttpVerbs.POST ||
host.HttpVerb == HttpVerbs.DELETE,
"expecting POST and DELETE methods");
DataServiceConfiguration.CheckResourceRights(entityContainer, EntitySetRights.WriteMerge | EntitySetRights.WriteReplace);
}
object entityResource = service.GetResource(description, entityResourceIndex, null);
if (entityResource == null)
{
throw DataServiceException.CreateBadRequestError(Strings.BadRequest_DereferencingNullPropertyValue(description.SegmentInfos[entityResourceIndex].Identifier));
}
return entityResource;
}
示例3: GetEntityResourceToModify
private static object GetEntityResourceToModify(System.Data.Services.RequestDescription description, IDataService service, bool allowCrossReferencing, out ResourceSetWrapper entityContainer, out int entityResourceIndex)
{
if (!allowCrossReferencing && (description.RequestExpression == null))
{
throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.BadRequest_ResourceCanBeCrossReferencedOnlyForBindOperation);
}
entityResourceIndex = GetIndexOfEntityResourceToModify(description);
entityContainer = description.SegmentInfos[entityResourceIndex].TargetContainer;
DataServiceHostWrapper host = service.OperationContext.Host;
if (host.HttpVerb == HttpVerbs.PUT)
{
DataServiceConfiguration.CheckResourceRights(entityContainer, EntitySetRights.WriteReplace);
}
else if ((host.HttpVerb == HttpVerbs.MERGE) || (host.HttpVerb == HttpVerbs.PATCH))
{
DataServiceConfiguration.CheckResourceRights(entityContainer, EntitySetRights.WriteMerge);
}
else
{
DataServiceConfiguration.CheckResourceRights(entityContainer, EntitySetRights.WriteMerge | EntitySetRights.WriteReplace);
}
object obj2 = service.GetResource(description, entityResourceIndex, null);
if (obj2 == null)
{
throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.BadRequest_DereferencingNullPropertyValue(description.SegmentInfos[entityResourceIndex].Identifier));
}
return obj2;
}