Esempio n. 1
0
 public override void AddToWriteQueue(SeriesMessage message, IMessageHeader header, ulong deliveryTag)
 {
     ToProcess.Enqueue(new Tuple <BsonDocument, ulong>(new BsonDocument {
         { "hello", "world" }
     }, deliveryTag));
 }
Esempio n. 2
0
        public override void AddToWriteQueue(SeriesMessage message, IMessageHeader header, ulong deliveryTag)
        {
            // Only time we are not processing is if we are shutting down anyway
            if (IsStopping)
            {
                return;
            }

            if (Model == null)
            {
                throw new ApplicationException("Model needs to be set before messages can be processed");
            }

            DicomDataset dataset;

            try
            {
                dataset = DicomTypeTranslater.DeserializeJsonToDataset(message.DicomDataset);
            }
            catch (Exception e)
            {
                throw new ApplicationException("Could not deserialize json to dataset", e);
            }

            BsonDocument datasetDoc;

            try
            {
                datasetDoc = DicomTypeTranslaterReader.BuildBsonDocument(dataset);
            }
            catch (Exception e)
            {
                throw new ApplicationException("Exception converting dataset to BsonDocument", e);
            }

            BsonDocument bsonHeader = MongoDocumentHeaders.SeriesDocumentHeader(message);

            BsonDocument document = new BsonDocument()
                                    .Add("header", bsonHeader)
                                    .AddRange(datasetDoc);

            int docByteLength = document.ToBson().Length;

            if (docByteLength > MaxDocumentSize)
            {
                throw new ApplicationException($"BsonDocument was larger than the max allowed size (have {docByteLength}, max is {MaxDocumentSize})");
            }

            var forceProcess = false;

            lock (LockObj)
            {
                ToProcess.Enqueue(new Tuple <BsonDocument, ulong>(document, deliveryTag));

                if (ToProcess.Count >= MaxQueueSize)
                {
                    forceProcess = true;
                }
            }

            if (!forceProcess)
            {
                return;
            }

            Logger.Debug("SeriesMessageProcessor: Max queue size reached, calling ProcessQueue");
            ProcessQueue();
        }