public void DeleteStatic(string name, Etag etag)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            name = name.Trim();
            TransactionalStorage.Batch(actions =>
            {
                AssertAttachmentDeleteOperationNotVetoed(name);

                Database.AttachmentDeleteTriggers.Apply(x => x.OnDelete(name));

                actions.Attachments.DeleteAttachment(name, etag);

                Database.AttachmentDeleteTriggers.Apply(x => x.AfterDelete(name));

                WorkContext.ShouldNotifyAboutWork(() => "DELETE ATTACHMENT " + name);
            });
            TransactionalStorage
            .ExecuteImmediatelyOrRegisterForSynchronization(
                () =>
            {
                Database.AttachmentDeleteTriggers.Apply(trigger => trigger.AfterCommit(name));
                var newAttachmentNotification = new AttachmentChangeNotification()
                {
                    Id   = name,
                    Type = AttachmentChangeTypes.Delete,
                    Etag = etag
                };
                Database.Notifications.RaiseNotifications(newAttachmentNotification, null);
            });
        }
Beispiel #2
0
        //This is not raising notification through the transport because this is intended
        //to be used internaly only (server side).
        public void RaiseNotifications(AttachmentChangeNotification obj, RavenJObject metadata)
        {
            var onDocumentChange = OnAttachmentChange;

            if (onDocumentChange != null)
            {
                onDocumentChange.Invoke(Database, obj, metadata);
            }
        }
        public Etag PutStatic(string name, Etag etag, Stream data, RavenJObject metadata)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            name = name.Trim();

            if (Encoding.Unicode.GetByteCount(name) >= 2048)
            {
                throw new ArgumentException("The key must be a maximum of 2,048 bytes in Unicode, 1,024 characters", "name");
            }

            var locker = putAttachmentSerialLock.GetOrAdd(name, s => new object());

            Monitor.Enter(locker);
            try
            {
                Etag newEtag = Etag.Empty;
                TransactionalStorage.Batch(actions =>
                {
                    AssertAttachmentPutOperationNotVetoed(name, metadata, data);

                    Database.AttachmentPutTriggers.Apply(trigger => trigger.OnPut(name, data, metadata));

                    newEtag = actions.Attachments.AddAttachment(name, etag, data, metadata);

                    Database.AttachmentPutTriggers.Apply(trigger => trigger.AfterPut(name, data, metadata, newEtag));

                    WorkContext.ShouldNotifyAboutWork(() => "PUT ATTACHMENT " + name);
                });
                TransactionalStorage
                .ExecuteImmediatelyOrRegisterForSynchronization(() =>
                {
                    Database.AttachmentPutTriggers.Apply(trigger => trigger.AfterCommit(name, data, metadata, newEtag));
                    var newAttachmentNotification = new AttachmentChangeNotification()
                    {
                        Id   = name,
                        Type = AttachmentChangeTypes.Put,
                        Etag = newEtag
                    };
                    Database.Notifications.RaiseNotifications(newAttachmentNotification, metadata);
                });
                return(newEtag);
            }
            finally
            {
                Monitor.Exit(locker);
                putAttachmentSerialLock.TryRemove(name, out locker);
            }
        }