Ejemplo n.º 1
0
        public async Task <HttpResponseMessage> FileSystemPut(string id, bool update = false)
        {
            MessageWithStatusCode fileSystemNameFormat = CheckNameFormat(id, Database.Configuration.FileSystem.DataDirectory);

            if (fileSystemNameFormat.Message != null)
            {
                return(GetMessageWithObject(new
                {
                    Error = fileSystemNameFormat.Message
                }, fileSystemNameFormat.ErrorCode));
            }

            if (FileSystemsLandlord.IsNotLicensed())
            {
                return(GetMessageWithObject(new
                {
                    Error = "Your license does not allow the use of RavenFS!"
                }, HttpStatusCode.BadRequest));
            }

            var docKey = "Raven/FileSystems/" + id;

            // There are 2 possible ways to call this put. We either want to update a filesystem configuration or we want to create a new one.
            if (!update)
            {
                // As we are not updating, we should fail when the filesystem already exists.
                var existingFilesystem = Database.Documents.Get(docKey, null);
                if (existingFilesystem != null)
                {
                    return(GetEmptyMessage(HttpStatusCode.Conflict));
                }
            }

            var fsDoc = await ReadJsonObjectAsync <DatabaseDocument>();

            FileSystemsLandlord.Protect(fsDoc);
            var json = RavenJObject.FromObject(fsDoc);

            json.Remove("Id");

            Database.Documents.Put(docKey, null, json, new RavenJObject(), null);

            return(GetEmptyMessage(HttpStatusCode.Created));
        }