Example #1
0
 protected abstract void processItem(QueueItem queueItem);
Example #2
0
        public static void SaveDicomToFile(DicomDataset dataset, string storagePath, 
            DicomFile dicomFile, ServerOptions serverOptions)
        {
            var pacientName = dataset.GetPacientName(serverOptions);
            var pacientDate = dataset.Get<DateTime>(DicomTag.PatientBirthDate);
            var imageDateTime = dataset.GetImageDateTime();

            var path = Path.GetFullPath(storagePath);
            path = Path.Combine(path, imageDateTime.Year.ToString("D4"));
            path = Path.Combine(path, imageDateTime.Month.ToString("D2"));
            path = Path.Combine(path, imageDateTime.ToShortDateString());

            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);

            string fileName = pacientName + " " + pacientDate.ToShortDateString() + " " + imageDateTime.ToLongTimeString() + ".dcm";
            fileName = Path.GetInvalidFileNameChars().Aggregate(fileName, (current, invalidChar) => current.Replace(invalidChar, '_'));
            fileName = Path.Combine(path, fileName);

            using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                dicomFile.Save(fileStream);
                fileStream.Flush();
            }

            var item = new QueueItem { FileName = fileName, Options = serverOptions };


            lock (BackgroundService.Services)
            {
                foreach (var queueService in BackgroundService.Services.OfType<QueueService>())
                    queueService.Enqueue(item);
            }

            try
            {
                if(Settings.Default.QueueNameList.Count > 0)
                {
                    foreach (var queueName in Settings.Default.QueueNameList)
                    {
                        if (!string.IsNullOrEmpty(queueName))
                        {
                            var name = queueName;
                            if (!name.Contains(@"\"))
                                name = @".\Private$\" + name;

                            System.Messaging.MessageQueue messageQueue;
                            if (System.Messaging.MessageQueue.Exists(name))
                                messageQueue = new System.Messaging.MessageQueue(name);
                            else
                                messageQueue = System.Messaging.MessageQueue.Create(name);

                            try
                            {
                                messageQueue.Send(item);
                            }
                            finally
                            {
                                messageQueue.Dispose();
                            }
                        }
                    }
                }
            }
            catch
            {
            }

        }
Example #3
0
 public void Enqueue(QueueItem item)
 {
     Queue.Enqueue(item);
 }