Ejemplo n.º 1
0
        public Stream GetPhotoContent(int id)
        {
            WebOperationContext context = WebOperationContext.Current;

            StreamingServicePhoto photo = StreamingServiceContext.GetPhoto(id);

            if (photo == null)
            {
                context.OutgoingResponse.SetStatusAsNotFound();
                return(new MemoryStream());
            }

            if (context.IncomingRequest.Headers[HttpRequestHeader.Accept] == "test/ReplyWithHeaders")
            {
                XDocument doc = StreamingServiceHelpers.SerializeRequestHeaders(context.IncomingRequest.Headers);

                context.OutgoingResponse.Headers[HttpResponseHeader.ContentEncoding] = "UTF-8";
                MemoryStream      s  = new MemoryStream();
                XmlWriterSettings ws = new XmlWriterSettings()
                {
                    OmitXmlDeclaration = true,
                    Encoding           = Encoding.UTF8
                };

                using (XmlWriter w = XmlWriter.Create(s, ws))
                {
                    doc.Save(w);
                }

                context.OutgoingResponse.ContentLength = s.Length;
                s.Seek(0, SeekOrigin.Begin);
                return(s);
            }

            if (context.IncomingRequest.Headers[HttpRequestHeader.Accept] == "test/AddTestHeaders")
            {
                context.OutgoingResponse.Headers.Add("test-single", "value1");
                context.OutgoingResponse.Headers.Add("test-multi", "value2");
                context.OutgoingResponse.Headers.Add("test-multi", "value3");
            }

            if (context.IncomingRequest.Headers[HttpRequestHeader.Accept] == "test/AddContentPropertyHeaders")
            {
                context.OutgoingResponse.Headers.Add(HttpResponseHeader.ContentType, "test/ContentType");
                context.OutgoingResponse.Headers.Add("Content-Disposition", "test-content-disposition");
            }

            if (context.OutgoingResponse.ContentType == null)
            {
                if (photo.ContentType != "no-content-type")
                {
                    context.OutgoingResponse.ContentType = photo.ContentType;
                }
            }

            context.OutgoingResponse.ContentLength = photo.Content.Length;
            return(new MemoryStream(photo.Content));
        }
Ejemplo n.º 2
0
        public object CreateResource(string containerName, string fullTypeName)
        {
            StreamingServiceObjectBase resource = null;

            if (containerName == "Photos")
            {
                if (fullTypeName == (typeof(StreamingServicePhoto).Namespace + "." + typeof(StreamingServicePhoto).Name))
                {
                    resource    = new StreamingServicePhoto();
                    resource.ID = _id++;
                    this.pendingChanges.Add(new PendingChange()
                    {
                        ChangeType = ChangeType.Add, List = _photos, Resource = resource
                    });
                }
            }
            else if (containerName == "V1Photos")
            {
                if (fullTypeName == (typeof(StreamingServiceV1Photo).Namespace + "." + typeof(StreamingServiceV1Photo).Name))
                {
                    resource    = new StreamingServiceV1Photo();
                    resource.ID = _id++;
                    this.pendingChanges.Add(new PendingChange()
                    {
                        ChangeType = ChangeType.Add, List = _v1photos, Resource = resource
                    });
                }
            }
            else if (containerName == "EntitiesWithoutStream")
            {
                if (fullTypeName == (typeof(StreamingServiceEntityWithoutStream).Namespace + "." + typeof(StreamingServiceEntityWithoutStream).Name))
                {
                    resource    = new StreamingServiceEntityWithoutStream();
                    resource.ID = _id++;
                    this.pendingChanges.Add(new PendingChange()
                    {
                        ChangeType = ChangeType.Add, List = _entitiesWithoutStream, Resource = resource
                    });
                }
            }

            if (resource == null)
            {
                throw new Exception("Unknown resource to be created: " + containerName + ", " + fullTypeName);
            }
            return(resource);
        }
Ejemplo n.º 3
0
        public Uri GetReadStreamUri(object entity, DataServiceOperationContext operationContext)
        {
            StreamingServiceRequestHeaders headers = entity as StreamingServiceRequestHeaders;

            if (headers == null)
            {
                StreamingServicePhotoBase photo = entity as StreamingServicePhotoBase;
                if (photo == null)
                {
                    throw new ArgumentException("The specified entity is not a photo entity.", "entity");
                }

                StreamingServicePhoto photoV2 = photo as StreamingServicePhoto;
                if (photoV2 != null && photoV2.AlternativeUri && contentServiceUri != null)
                {
                    return(new Uri(contentServiceUri.ToString() + "PhotoContent?id=" + photoV2.ID.ToString(), UriKind.Absolute));
                }
            }

            return(null);
        }