コード例 #1
0
        public Stream GetReadStream(object entity, string etag, bool?
                                    checkETagForEquality, DataServiceOperationContext operationContext)
        {
            if (checkETagForEquality != null)
            {
                // This stream provider implementation does not support
                // ETag headers for media resources. This means that we do not track
                // concurrency for a media resource and last-in wins on updates.
                throw new DataServiceException(400,
                                               "This sample service does not support the ETag header for a media resource.");
            }

            PhotoInfo image = entity as PhotoInfo;

            if (image == null)
            {
                throw new DataServiceException(500, "Internal Server Error.");
            }

            // Build the full path to the stored image file, which includes the entity key.
            string fullImageFilePath = imageFilePath + "image" + image.PhotoId;

            if (!File.Exists(fullImageFilePath))
            {
                throw new DataServiceException(500, "The image could not be found.");
            }

            // Return a stream that contains the requested file.
            return(new FileStream(fullImageFilePath, FileMode.Open));
        }
コード例 #2
0
        public string GetStreamContentType(object entity, DataServiceOperationContext operationContext)
        {
            // Get the PhotoInfo entity instance.
            PhotoInfo image = entity as PhotoInfo;

            if (image == null)
            {
                throw new DataServiceException(500, "Internal Server Error.");
            }

            return(image.ContentType);
        }
コード例 #3
0
ファイル: photodata.designer.cs プロジェクト: wzchua/docs
        /// <summary>
        /// Create a new PhotoInfo object.
        /// </summary>
        /// <param name="photoId">Initial value of the PhotoId property.</param>
        /// <param name="fileName">Initial value of the FileName property.</param>
        /// <param name="dateAdded">Initial value of the DateAdded property.</param>
        /// <param name="exposure">Initial value of the Exposure property.</param>
        /// <param name="dimensions">Initial value of the Dimensions property.</param>
        /// <param name="dateModified">Initial value of the DateModified property.</param>
        public static PhotoInfo CreatePhotoInfo(global::System.Int32 photoId, global::System.String fileName, global::System.DateTime dateAdded, Exposure exposure, Dimensions dimensions, global::System.DateTime dateModified)
        {
            PhotoInfo photoInfo = new PhotoInfo();

            photoInfo.PhotoId      = photoId;
            photoInfo.FileName     = fileName;
            photoInfo.DateAdded    = dateAdded;
            photoInfo.Exposure     = StructuralObject.VerifyComplexObjectIsNotNull(exposure, "Exposure");
            photoInfo.Dimensions   = StructuralObject.VerifyComplexObjectIsNotNull(dimensions, "Dimensions");
            photoInfo.DateModified = dateModified;
            return(photoInfo);
        }
コード例 #4
0
        public Stream GetWriteStream(object entity, string etag, bool?
                                     checkETagForEquality, DataServiceOperationContext operationContext)
        {
            if (checkETagForEquality != null)
            {
                // This stream provider implementation does not support ETags associated with BLOBs.
                // This means that we do not track concurrency for a media resource
                // and last-in wins on updates.
                throw new DataServiceException(400,
                                               "This demo does not support ETags associated with BLOBs");
            }

            PhotoInfo image = entity as PhotoInfo;

            if (image == null)
            {
                throw new DataServiceException(500, "Internal Server Error: "
                                               + "the Media Link Entry could not be determined.");
            }

            // Handle the POST request.
            if (operationContext.RequestMethod == "POST")
            {
                // Set the file name from the Slug header; if we don't have a
                // Slug header, just set a temporary name which is overwritten
                // by the subsequent MERGE request from the client.
                image.FileName = operationContext.RequestHeaders["Slug"] ?? "newFile";

                // Set the required DateTime values.
                image.DateModified = DateTime.Today;
                image.DateAdded    = DateTime.Today;

                // Set the content type, which cannot be null.
                image.ContentType = operationContext.RequestHeaders["Content-Type"];

                // Cache the current entity to enable us to both create a key based storage file name
                // and to maintain transactional integrity in the disposer; we do this only for a POST request.
                cachedEntity = image;

                return(new FileStream(tempFile, FileMode.Open));
            }
            // Handle the PUT request
            else
            {
                // Return a stream to write to an existing file.
                return(new FileStream(imageFilePath + "image" + image.PhotoId.ToString(),
                                      FileMode.Open, FileAccess.Write));
            }
        }
コード例 #5
0
        public void DeleteStream(object entity, DataServiceOperationContext operationContext)
        {
            PhotoInfo image = entity as PhotoInfo;

            if (image == null)
            {
                throw new DataServiceException(500, "Internal Server Error.");
            }

            try
            {
                // Delete the requested file by using the key value.
                File.Delete(imageFilePath + "image" + image.PhotoId.ToString());
            }
            catch (IOException ex)
            {
                throw new DataServiceException("The image could not be found.", ex);
            }
        }
コード例 #6
0
ファイル: photodata.designer.cs プロジェクト: wzchua/docs
 /// <summary>
 /// Deprecated Method for adding a new object to the PhotoInfo EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPhotoInfo(PhotoInfo photoInfo)
 {
     base.AddObject("PhotoInfo", photoInfo);
 }