Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new instance of <see cref="EntityToSerialize"/>.
        /// </summary>
        /// <param name="entity">The entity itself.</param>
        /// <param name="resourceType">The type of the entity.</param>
        /// <param name="resourceSetWrapper">The resource set the entity belongs to.</param>
        /// <param name="provider">The wrapper for the current service provider.</param>
        /// <param name="absoluteServiceUri">The absolute service URI.</param>
        /// <returns>The new instance of <see cref="EntityToSerialize"/></returns>
        internal static EntityToSerialize Create(object entity, ResourceType resourceType, ResourceSetWrapper resourceSetWrapper, DataServiceProviderWrapper provider, Uri absoluteServiceUri)
        {
            Debug.Assert(provider != null, "provider != null");
            Debug.Assert(provider.DataService != null, "provider.DataService != null");
            Debug.Assert(provider.DataService.Configuration != null, "provider.DataService.Configuration != null");
            Debug.Assert(provider.DataService.Configuration.DataServiceBehavior != null,
                         "provider.DataService.Configuration.DataServiceBehavior != null");

            KeySerializer keySerializer = KeySerializer.Create(provider.DataService.Configuration.DataServiceBehavior.GenerateKeyAsSegment);

            Func <ResourceProperty, object> getPropertyValue = p =>
            {
                object keyValue = WebUtil.GetPropertyValue(provider, entity, resourceType, p, null);
                if (keyValue == null)
                {
                    throw new InvalidOperationException(Service.Strings.Serializer_NullKeysAreNotSupported(p.Name));
                }

                return(keyValue);
            };

            bool includeTypeSegment = resourceSetWrapper.ResourceType != resourceType;

            return(Create(entity, resourceType, resourceSetWrapper.Name, includeTypeSegment, getPropertyValue, keySerializer, absoluteServiceUri));
        }
Ejemplo n.º 2
0
        public void Init()
        {
            this.keyProperty1 = new ResourceProperty("Key1", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(string)));
            this.keyProperty2 = new ResourceProperty("Key2", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int)));

            this.defaultSerializer = KeySerializer.Create(false);
            this.segmentSerializer = KeySerializer.Create(true);

            this.singleKeyProperty = new[] { this.keyProperty1 };
            this.compositeKey      = new[] { this.keyProperty1, this.keyProperty2 };
        }
Ejemplo n.º 3
0
        private static EntityToSerialize CreateEntityToSerialize(bool shouldIncludeTypeSegment)
        {
            ResourceType baseType = new ResourceType(typeof(MyType), ResourceTypeKind.EntityType, null, "TestNamespace", "BaseType", /*isAbstract*/ false);

            baseType.AddProperty(new ResourceProperty("ID", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, new ResourceType(typeof(int), ResourceTypeKind.Primitive, null, "int")));

            baseType.SetReadOnly();

            Uri serviceUri = new Uri("http://dummy");

            KeySerializer keySerializer = KeySerializer.Create(false);

            Func <ResourceProperty, object> getPropertyValue = p => "fakePropertyValue";

            return(EntityToSerialize.Create(new MyType {
                ID = 42
            }, baseType, "MySet", shouldIncludeTypeSegment, getPropertyValue, keySerializer, serviceUri));
        }
 /// <summary>
 /// Private constructor since the singleton instance is sufficient.
 /// </summary>
 /// <param name="keyAsSegment">Whether use key as segment</param>
 private PathSegmentToContextUrlPathTranslator(bool keyAsSegment)
 {
     this.KeySerializer = KeySerializer.Create(keyAsSegment);
 }
 /// <summary>
 /// Private constructor since the singleton instance is sufficient.
 /// </summary>
 /// <param name="keyAsSegment">Whether use key as segment</param>
 private PathSegmentToContextUrlPathTranslator(bool keyAsSegment)
 {
     KeySerializer = KeySerializer.Create(UrlConvention.CreateWithExplicitValue(keyAsSegment));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Prevents a default instance of the <see cref="DataServiceUrlConventions"/> class from being created.
 /// </summary>
 /// <param name="urlConvention">The url convention to use.</param>
 private DataServiceUrlConventions(UrlConvention urlConvention)
 {
     Debug.Assert(urlConvention != null, "urlConvention != null");
     this.urlConvention = urlConvention;
     this.keySerializer = KeySerializer.Create(urlConvention);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Prevents a default instance of the <see cref="DataServiceUrlKeyDelimiter"/> class from being created.
 /// </summary>
 /// <param name="enableKeyAsSegment">Whether enable key as segment</param>
 private DataServiceUrlKeyDelimiter(bool enableKeyAsSegment)
 {
     this.keySerializer = KeySerializer.Create(enableKeyAsSegment);
 }
 /// <summary>
 /// Private constructor since the singleton instance is sufficient.
 /// </summary>
 /// <param name="urlConventions">Whether use key as segment</param>
 public PathSegmentToResourcePathTranslator(UrlConvention urlConventions)
 {
     KeySerializer = KeySerializer.Create(urlConventions);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Private constructor since the singleton instance is sufficient.
 /// </summary>
 /// <param name="odataUrlKeyDelimiter">Key delimiter used in url.</param>
 public PathSegmentToResourcePathTranslator(ODataUrlKeyDelimiter odataUrlKeyDelimiter)
 {
     Debug.Assert(odataUrlKeyDelimiter != null, "odataUrlKeyDelimiter != null");
     this.KeySerializer = KeySerializer.Create(odataUrlKeyDelimiter.EnableKeyAsSegment);
 }