Created
July 26, 2013 18:52
-
-
Save markdstafford/6091320 to your computer and use it in GitHub Desktop.
Examples for http://blogs.msdn.com/b/astoriateam/archive/2013/07/26/using-the-new-client-hooks-in-wcf-data-services-client.aspx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context.Configurations.ResponsePipeline.OnEntryEnded((a => | |
{ | |
Type entityType = dataServiceContext.ResolveType(a.Entry.TypeName); | |
if (typeof(Product).IsAssignableFrom(entityType)) | |
{ | |
var properties = a.Entry.Properties as List<ODataProperty>; | |
if (properties == null) | |
{ | |
properties = new List<ODataProperty>(a.Entry.Properties); | |
} | |
var odataPropertyToRemove = properties.Single(p => p.Name == "Description"); | |
properties.Remove(odataPropertyToRemove); | |
a.Entry.Properties = properties; | |
} | |
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void RemoveProperties(this ODataEntry entry, params string[] propertyNames) | |
{ | |
var properties = entry.Properties as List<ODataProperty>; | |
if (properties == null) | |
{ | |
properties = new List<ODataProperty>(entry.Properties); | |
} | |
var propertiesToRemove = properties.Where(p => propertyNames.Any(rp => rp == p.Name)); | |
foreach (var propertyToRemove in propertiesToRemove.ToArray()) | |
{ | |
properties.Remove(propertyToRemove); | |
} | |
entry.Properties = properties; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static DataServiceClientResponsePipelineConfiguration RemoveProperties<T>( | |
this DataServiceClientResponsePipelineConfiguration responsePipeline, | |
Func<string, Type> resolveType, | |
params string[] propertiesToRemove) | |
{ | |
return responsePipeline.OnEntryEnded((args) => | |
{ | |
Type resolvedType = resolveType(args.Entry.TypeName); | |
if (resolvedType != null && typeof(T).IsAssignableFrom(resolvedType)) | |
{ | |
args.Entry.RemoveProperties(propertiesToRemove); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context.Configurations.ResponsePipeline.RemoveProperties<Product>(context.ResolveType, "Description"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DataServiceClientResponsePipelineConfiguration | |
{ | |
public DataServiceClientResponsePipelineConfiguration OnEntityMaterialized(Action<MaterializedEntityArgs> action); | |
public DataServiceClientResponsePipelineConfiguration OnEntryEnded(Action<ReadingEntryArgs> action); | |
public DataServiceClientResponsePipelineConfiguration OnEntryStarted(Action<ReadingEntryArgs> action); | |
public DataServiceClientResponsePipelineConfiguration OnFeedEnded(Action<ReadingFeedArgs> action); | |
public DataServiceClientResponsePipelineConfiguration OnFeedStarted(Action<ReadingFeedArgs> action); | |
public DataServiceClientResponsePipelineConfiguration OnMessageReaderSettingsCreated( | |
Action<MessageReaderSettingsArgs> messageReaderSettingsAction); | |
public DataServiceClientResponsePipelineConfiguration OnNavigationLinkEnded(Action<ReadingNavigationLinkArgs> action); | |
public DataServiceClientResponsePipelineConfiguration OnNavigationLinkStarted(Action<ReadingNavigationLinkArgs> action); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static DataServiceClientRequestPipelineConfiguration RemoveProperties<T>( | |
this DataServiceClientRequestPipelineConfiguration requestPipeline, | |
params string[] propertiesToRemove) | |
{ | |
return requestPipeline.OnEntryEnding((args) => | |
{ | |
if (typeof(T).IsAssignableFrom(args.Entity.GetType())) | |
{ | |
args.Entry.RemoveProperties(propertiesToRemove); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DataServiceClientRequestPipelineConfiguration | |
{ | |
public DataServiceClientRequestPipelineConfiguration OnEntityReferenceLink( | |
Action<WritingEntityReferenceLinkArgs> action); | |
public DataServiceClientRequestPipelineConfiguration OnEntryEnding(Action<WritingEntryArgs> action); | |
public DataServiceClientRequestPipelineConfiguration OnEntryStarting(Action<WritingEntryArgs> action); | |
public DataServiceClientRequestPipelineConfiguration OnMessageWriterSettingsCreated( | |
Action<MessageWriterSettingsArgs> args); | |
public DataServiceClientRequestPipelineConfiguration OnNavigationLinkEnding(Action<WritingNavigationLinkArgs> action); | |
public DataServiceClientRequestPipelineConfiguration OnNavigationLinkStarting(Action<WritingNavigationLinkArgs> action); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment