Ejemplo n.º 1
0
 public void OnChangeCustomer(ClrNamespace.Customer c, UpdateOperations operation)
 {
     if (CustomerChangeInterceptorOverride != null)
     {
         CustomerChangeInterceptorOverride(c, operation);
     }
 }
Ejemplo n.º 2
0
        internal static string GetStoragePath(object entity)
        {
            if (entity.GetType() == typeof(Photo))
            {
                Photo  p         = (Photo)entity;
                string extension = GetContentType(entity).Split('/')[1];

                return(Path.Combine(RootPhotosStoragePath, p.ID + "." + extension));
            }
            else if (entity.GetType() == typeof(ClrNamespace.CustomerBlob) || entity.GetType() == typeof(ClrNamespace.CustomerBlobWithBirthday))
            {
                ClrNamespace.Customer c = (ClrNamespace.Customer)entity;
                return(Path.Combine(RootCustomerBlobStoragePath, c.ID + ".blob"));
            }

            throw new NotSupportedException("Unsupported entity type: " + entity.GetType());
        }
Ejemplo n.º 3
0
        public Stream GetWriteStream(object entity, string etag, bool?checkETagForEquality, DataServiceOperationContext operationContext)
        {
            this.ThrowIfDisposed();
            int entityId = 0;

            if (entity.GetType() == typeof(Photo))
            {
                Photo p = (Photo)entity;
                p.LastUpdated = DateTime.Now;

                if (operationContext.RequestMethod.Equals("POST", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(operationContext.RequestHeaders["Slug"]))
                {
                    string slug = operationContext.RequestHeaders["Slug"];
                    int    id;
                    if (int.TryParse(slug, out id))
                    {
                        p.ID = id;
                    }
                    else
                    {
                        p.Description = slug;
                    }
                }

                entityId = p.ID;
            }
            else if (entity.GetType() == typeof(ClrNamespace.CustomerBlob) || entity.GetType() == typeof(ClrNamespace.CustomerBlobWithBirthday))
            {
                ClrNamespace.Customer c = (ClrNamespace.Customer)entity;

                if (operationContext.RequestMethod.Equals("POST", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(operationContext.RequestHeaders["Slug"]))
                {
                    string slug = operationContext.RequestHeaders["Slug"];
                    c.Concurrency = slug;
                    int id;
                    if (int.TryParse(slug, out id))
                    {
                        c.ID   = id;
                        c.Name = "Customer " + slug;
                    }
                    else
                    {
                        throw new InvalidOperationException(string.Format("Invalid Slug header value '{0}'.", slug));
                    }
                }

                entityId = c.ID;
            }

            ValidateArguments(entity, operationContext);

            if (checkETagForEquality == true)
            {
                if (etag != "\"MediaResourceETag" + entityId + "\"")
                {
                    throw new InvalidOperationException("ETag for media resource did not match.");
                }
            }

            FileStream fs = File.Open(GetStoragePath(entity), FileMode.Create, FileAccess.Write);

            return(fs);
        }