コード例 #1
0
        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)));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
 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());
 }
コード例 #5
0
ファイル: DocumentDatabase.cs プロジェクト: creamdog/ravendb
        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)));
        }
コード例 #6
0
        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));
        }