public void PutStatic(string name, Guid?etag, byte[] data, JObject metadata) { if (name == null) { throw new ArgumentNullException("name"); } if (Encoding.Unicode.GetByteCount(name) >= 255) { throw new ArgumentException("The key must be a maximum of 255 bytes in unicode, 127 characters", "name"); } Guid newEtag = Guid.Empty; TransactionalStorage.Batch(actions => { AssertAttachmentPutOperationNotVetoed(name, metadata, data); AttachmentPutTriggers.Apply(trigger => trigger.OnPut(name, data, metadata)); newEtag = actions.Attachments.AddAttachment(name, etag, data, metadata); AttachmentPutTriggers.Apply(trigger => trigger.AfterPut(name, data, metadata, newEtag)); workContext.ShouldNotifyAboutWork(); }); TransactionalStorage .ExecuteImmediatelyOrRegisterForSyncronization(() => AttachmentPutTriggers.Apply(trigger => trigger.AfterCommit(name, data, metadata, newEtag))); }
private void InitializeTriggers() { PutTriggers .Init(disableAllTriggers) .OfType <IRequiresDocumentDatabaseInitialization>().Apply(initialization => initialization.Initialize(this)); DeleteTriggers .Init(disableAllTriggers) .OfType <IRequiresDocumentDatabaseInitialization>().Apply(initialization => initialization.Initialize(this)); ReadTriggers .Init(disableAllTriggers) .OfType <IRequiresDocumentDatabaseInitialization>().Apply(initialization => initialization.Initialize(this)); AttachmentPutTriggers .Init(disableAllTriggers) .OfType <IRequiresDocumentDatabaseInitialization>().Apply(initialization => initialization.Initialize(this)); AttachmentDeleteTriggers .Init(disableAllTriggers) .OfType <IRequiresDocumentDatabaseInitialization>().Apply(initialization => initialization.Initialize(this)); AttachmentReadTriggers .Init(disableAllTriggers) .OfType <IRequiresDocumentDatabaseInitialization>().Apply(initialization => initialization.Initialize(this)); IndexUpdateTriggers .Init(disableAllTriggers) .OfType <IRequiresDocumentDatabaseInitialization>().Apply(initialization => initialization.Initialize(this)); }
private void AssertAttachmentPutOperationNotVetoed(string key, JObject metadata, byte[] data) { var vetoResult = AttachmentPutTriggers .Select(trigger => new { Trigger = trigger, VetoResult = trigger.AllowPut(key, data, metadata) }) .FirstOrDefault(x => x.VetoResult.IsAllowed == false); if (vetoResult != null) { throw new OperationVetoedException("PUT vetoed by " + vetoResult.Trigger + " because: " + vetoResult.VetoResult.Reason); } }
private void SecondStageInitialization() { DocumentCodecs .OfType <IRequiresDocumentDatabaseInitialization>() .Concat(PutTriggers.OfType <IRequiresDocumentDatabaseInitialization>()) .Concat(DeleteTriggers.OfType <IRequiresDocumentDatabaseInitialization>()) .Concat(IndexCodecs.OfType <IRequiresDocumentDatabaseInitialization>()) .Concat(IndexQueryTriggers.OfType <IRequiresDocumentDatabaseInitialization>()) .Concat(AttachmentPutTriggers.OfType <IRequiresDocumentDatabaseInitialization>()) .Concat(AttachmentDeleteTriggers.OfType <IRequiresDocumentDatabaseInitialization>()) .Concat(AttachmentReadTriggers.OfType <IRequiresDocumentDatabaseInitialization>()) .Concat(IndexUpdateTriggers.OfType <IRequiresDocumentDatabaseInitialization>()) .Apply(initialization => initialization.SecondStageInit()); }
public void PutStatic(string name, Guid?etag, byte[] data, JObject metadata) { Guid newEtag = Guid.Empty; TransactionalStorage.Batch(actions => { AssertAttachmentPutOperationNotVetoed(name, metadata, data); AttachmentPutTriggers.Apply(trigger => trigger.OnPut(name, data, metadata)); newEtag = actions.Attachments.AddAttachment(name, etag, data, metadata); AttachmentPutTriggers.Apply(trigger => trigger.AfterPut(name, data, metadata, newEtag)); workContext.ShouldNotifyAboutWork(); }); TransactionalStorage .ExecuteImmediatelyOrRegisterForSyncronization(() => AttachmentPutTriggers.Apply(trigger => trigger.AfterCommit(name, data, metadata, newEtag))); }
private void InitializeTriggersExceptIndexCodecs() { DocumentCodecs // .Init(disableAllTriggers) // Document codecs should always be activated (RavenDB-576) .OfType <IRequiresDocumentDatabaseInitialization>().Apply(initialization => initialization.Initialize(this)); PutTriggers.Init(disableAllTriggers).OfType <IRequiresDocumentDatabaseInitialization>().Apply(initialization => initialization.Initialize(this)); DeleteTriggers.Init(disableAllTriggers).OfType <IRequiresDocumentDatabaseInitialization>().Apply(initialization => initialization.Initialize(this)); ReadTriggers.Init(disableAllTriggers).OfType <IRequiresDocumentDatabaseInitialization>().Apply(initialization => initialization.Initialize(this)); IndexQueryTriggers.Init(disableAllTriggers).OfType <IRequiresDocumentDatabaseInitialization>().Apply(initialization => initialization.Initialize(this)); AttachmentPutTriggers.Init(disableAllTriggers).OfType <IRequiresDocumentDatabaseInitialization>().Apply(initialization => initialization.Initialize(this)); AttachmentDeleteTriggers.Init(disableAllTriggers).OfType <IRequiresDocumentDatabaseInitialization>().Apply(initialization => initialization.Initialize(this)); AttachmentReadTriggers.Init(disableAllTriggers).OfType <IRequiresDocumentDatabaseInitialization>().Apply(initialization => initialization.Initialize(this)); IndexUpdateTriggers.Init(disableAllTriggers).OfType <IRequiresDocumentDatabaseInitialization>().Apply(initialization => initialization.Initialize(this)); }