Beispiel #1
0
        public void Delete(string key, Guid?etag, TransactionInformation transactionInformation)
        {
            TransactionalStorage.Batch(actions =>
            {
                if (transactionInformation == null)
                {
                    AssertDeleteOperationNotVetoed(key, transactionInformation);

                    DeleteTriggers.Apply(trigger => trigger.OnDelete(key, transactionInformation));

                    JObject metadata;
                    if (actions.Documents.DeleteDocument(key, etag, out metadata))
                    {
                        AddIndexingTask(actions, metadata, () => new RemoveFromIndexTask {
                            Keys = new[] { key }
                        });
                        DeleteTriggers.Apply(trigger => trigger.AfterDelete(key, transactionInformation));
                    }
                }
                else
                {
                    actions.Transactions.DeleteDocumentInTransaction(transactionInformation, key, etag);
                }
                workContext.ShouldNotifyAboutWork();
            });
            TransactionalStorage
            .ExecuteImmediatelyOrRegisterForSyncronization(() => DeleteTriggers.Apply(trigger => trigger.AfterCommit(key)));
        }
Beispiel #2
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)));
        }
Beispiel #3
0
        public Guid Enqueue(IncomingMessage incomingMessage)
        {
            AssertValidQueuePath(incomingMessage.Queue);

            Guid result = Guid.Empty;

            transactionalStorage.Batch(actions =>
            {
                MessageEnqueuedTriggers.Apply(trigger => trigger.BeforeMessageEnqueued(incomingMessage));

                var bytes = incomingMessage.Metadata.ToBytes();
                var ms    = new MemoryStream(bytes.Length + incomingMessage.Data.Length);
                ms.Write(bytes, 0, bytes.Length);
                ms.Write(incomingMessage.Data, 0, incomingMessage.Data.Length);


                actions.Queues.IncrementMessageCount(incomingMessage.Queue);
                result = actions.Messages.Enqueue(incomingMessage.Queue, DateTime.UtcNow.Add(incomingMessage.TimeToLive),
                                                  ms.ToArray());
            });
            MessageEnqueuedTriggers.Apply(
                enqueuedTrigger => transactionalStorage.ExecuteImmediatelyOrRegisterForSyncronization(
                    enqueuedTrigger,
                    incomingMessage,
                    msgs => MessageEnqueuedTriggers.Apply(x => x.AfterCommit(msgs.Cast <IncomingMessage>()))
                    ));
            return(result);
        }
Beispiel #4
0
        public PutResult Put(string key, Guid?etag, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
        {
            if (key != null && Encoding.Unicode.GetByteCount(key) >= 255)
            {
                throw new ArgumentException("The key must be a maximum of 255 bytes in unicode, 127 characters", "key");
            }

            log.DebugFormat("Putting a document with key: {0} and etag {1}", key, etag);

            if (string.IsNullOrEmpty(key))
            {
                // we no longer sort by the key, so it doesn't matter
                // that the key is no longer sequential
                key = Guid.NewGuid().ToString();
            }
            RemoveReservedProperties(document);
            RemoveReservedProperties(metadata);
            Guid newEtag = Guid.Empty;

            lock (this)
            {
                TransactionalStorage.Batch(actions =>
                {
                    if (key.EndsWith("/"))
                    {
                        key += actions.General.GetNextIdentityValue(key);
                    }
                    if (transactionInformation == null)
                    {
                        AssertPutOperationNotVetoed(key, metadata, document, transactionInformation);
                        PutTriggers.Apply(trigger => trigger.OnPut(key, document, metadata, transactionInformation));

                        newEtag = actions.Documents.AddDocument(key, etag, document, metadata);
                        // We detect this by using the etags
                        // AddIndexingTask(actions, metadata, () => new IndexDocumentsTask { Keys = new[] { key } });
                        PutTriggers.Apply(trigger => trigger.AfterPut(key, document, metadata, newEtag, transactionInformation));
                    }
                    else
                    {
                        newEtag = actions.Transactions.AddDocumentInTransaction(key, etag,
                                                                                document, metadata, transactionInformation);
                    }
                    workContext.ShouldNotifyAboutWork();
                });
            }
            TransactionalStorage
            .ExecuteImmediatelyOrRegisterForSyncronization(() => PutTriggers.Apply(trigger => trigger.AfterCommit(key, document, metadata, newEtag)));

            return(new PutResult
            {
                Key = key,
                ETag = newEtag
            });
        }
Beispiel #5
0
        public PutResult Put(string key, Guid?etag, JObject document, JObject metadata, TransactionInformation transactionInformation)
        {
            if (string.IsNullOrEmpty(key))
            {
                // we no longer sort by the key, so it doesn't matter
                // that the key is no longer sequential
                key = Guid.NewGuid().ToString();
            }
            RemoveReservedProperties(document);
            RemoveReservedProperties(metadata);
            Guid newEtag = Guid.Empty;

            lock (this)
            {
                TransactionalStorage.Batch(actions =>
                {
                    if (key.EndsWith("/"))
                    {
                        key += actions.General.GetNextIdentityValue(key);
                    }
                    if (transactionInformation == null)
                    {
                        AssertPutOperationNotVetoed(key, metadata, document, transactionInformation);
                        PutTriggers.Apply(trigger => trigger.OnPut(key, document, metadata, transactionInformation));

                        newEtag = actions.Documents.AddDocument(key, etag, document, metadata);
                        // We detect this by using the etags
                        // AddIndexingTask(actions, metadata, () => new IndexDocumentsTask { Keys = new[] { key } });
                        PutTriggers.Apply(trigger => trigger.AfterPut(key, document, metadata, newEtag, transactionInformation));
                    }
                    else
                    {
                        newEtag = actions.Transactions.AddDocumentInTransaction(key, etag,
                                                                                document, metadata, transactionInformation);
                    }
                    workContext.ShouldNotifyAboutWork();
                });
            }
            TransactionalStorage
            .ExecuteImmediatelyOrRegisterForSyncronization(() => PutTriggers.Apply(trigger => trigger.AfterCommit(key, document, metadata, newEtag)));

            return(new PutResult
            {
                Key = key,
                ETag = newEtag
            });
        }
        public PutResult Put(string key, Guid?etag, JObject document, JObject metadata, TransactionInformation transactionInformation)
        {
            if (string.IsNullOrEmpty(key))
            {
                Guid value;
                UuidCreateSequential(out value);
                key = value.ToString();
            }
            RemoveReservedProperties(document);
            RemoveReservedProperties(metadata);
            TransactionalStorage.Batch(actions =>
            {
                metadata["Last-Modified"] = JToken.FromObject(DateTime.UtcNow.ToString("r"));
                if (key.EndsWith("/"))
                {
                    key += actions.General.GetNextIdentityValue(key);
                }
                metadata.Add("@id", new JValue(key));
                if (transactionInformation == null)
                {
                    AssertPutOperationNotVetoed(key, metadata, document, transactionInformation);
                    PutTriggers.Apply(trigger => trigger.OnPut(key, document, metadata, transactionInformation));

                    etag = actions.Documents.AddDocument(key, etag, document, metadata);
                    AddIndexingTask(actions, metadata, () => new IndexDocumentsTask {
                        Keys = new[] { key }
                    });
                    PutTriggers.Apply(trigger => trigger.AfterPut(key, document, metadata, etag.Value, transactionInformation));
                }
                else
                {
                    etag = actions.Transactions.AddDocumentInTransaction(key, etag,
                                                                         document, metadata, transactionInformation);
                }
                workContext.ShouldNotifyAboutWork();
            });

            TransactionalStorage
            .ExecuteImmediatelyOrRegisterForSyncronization(() => PutTriggers.Apply(trigger => trigger.AfterCommit(key, document, metadata, etag.Value)));

            return(new PutResult
            {
                Key = key,
                ETag = etag.Value
            });
        }
Beispiel #7
0
        public void DeleteStatic(string name, Guid?etag)
        {
            TransactionalStorage.Batch(actions =>
            {
                AssertAttachmentDeleteOperationNotVetoed(name);

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

                actions.Attachments.DeleteAttachment(name, etag);

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

                workContext.ShouldNotifyAboutWork();
            });

            TransactionalStorage
            .ExecuteImmediatelyOrRegisterForSyncronization(
                () => AttachmentDeleteTriggers.Apply(trigger => trigger.AfterCommit(name)));
        }
Beispiel #8
0
        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)));
        }