Beispiel #1
0
        private void SendUpdate(AutoUpdateItem item)
        {
            AeInfo[] aes = _AccessAgent.GetRelatedAeTitles(item.SourceAE, UPDATE_RELATION);
            DicomScp scp = null;

            if (aes == null || aes.Length == 0)
            {
                return;
            }

            foreach (AeInfo ae in aes)
            {
                using (UpdateProcessor processor = new UpdateProcessor(Module.Options.UseCustomAE ? Module.Options.AutoUpdateAE : item.ClientAE))
                {
                    try
                    {
                        DicomCommandStatusType status = DicomCommandStatusType.Reserved4;

                        if (processor.Scu.IsConnected())
                        {
                            processor.Scu.CloseForced(true);
                        }
                        scp    = new DicomScp(IPAddress.Parse(ae.Address), ae.AETitle, ae.Port);
                        status = processor.SendUpdate(scp, item.Dicom, item.Action);
                        if (status != DicomCommandStatusType.Success)
                        {
                            if (status != DicomCommandStatusType.MissingAttribute && status != DicomCommandStatusType.AttributeOutOfRange)
                            {
                                AddRetry(scp, item, ae.Address);
                            }
                        }
                    }
                    catch (ClientAssociationException ce)
                    {
                        string message = string.Format("[Auto Update] Failed to establish association with server: {0}.  Adding {1} action to update retry queue.", ce.Reason,
                                                       AutoRetryProcessor.Actions[item.Action]);

                        UpdateProcessor.LogEvent(LogType.Error, MessageDirection.None, message, DicomCommandType.Undefined, null, processor.Scu, null);
                        AddRetry(scp, item, ae.Address);
                    }
                    catch (DicomException de)
                    {
                        string message = string.Format("[Auto Update] Error: {0}. Adding {1} action to update retry queue.", de.Message, AutoRetryProcessor.Actions[item.Action]);

                        UpdateProcessor.LogEvent(LogType.Error, MessageDirection.Input, message, DicomCommandType.Undefined, null, processor.Scu, null);
                        AddRetry(scp, item, ae.Address);
                    }
                    catch (Exception e)
                    {
                        string message = "[Auto Update] " + e.Message;

                        Logger.Global.Log(string.Empty, string.Empty, -1, string.Empty, string.Empty, -1, DicomCommandType.Undefined,
                                          DateTime.Now, LogType.Error, MessageDirection.None, message, null, null);
                    }
                    finally
                    {
                    }
                }
            }
        }
Beispiel #2
0
        private void RetryAutoUpdate(object state)
        {
            _RetryTimer.Change(Timeout.Infinite, Timeout.Infinite);
            try
            {
                foreach (FileInfo fi in FileSearcher.GetFiles(_RetryDir, "*.xml", SearchOption.AllDirectories))
                {
                    string    xml = File.ReadAllText(fi.FullName);
                    RetryInfo ri  = xml.FromXml <RetryInfo>(_UpdateTypes);


                    if (ri != null)
                    {
                        string dicomPath = Path.Combine(_DicomDir, fi.Name);

                        dicomPath = Path.ChangeExtension(dicomPath, ".ds");
                        if (DateTime.Now > ri.Expires)
                        {
                            //
                            // Retry period has expired.  Delete File
                            //
                            Logger.Global.Log(string.Empty, string.Empty, -1, string.Empty, string.Empty, -1, DicomCommandType.Undefined,
                                              DateTime.Now, LogType.Information, MessageDirection.None,
                                              "[Auto Update] NAction retry has passed expiration.  Item removed from update retry queue.", null,
                                              new SerializableDictionary <string, object>()
                            {
                                { "Filename", dicomPath }
                            });
                            DeleteRetry(fi, dicomPath);
                            continue;
                        }

                        if (!File.Exists(dicomPath))
                        {
                            Logger.Global.Log(string.Empty, string.Empty, -1, string.Empty, string.Empty, -1, DicomCommandType.Undefined,
                                              DateTime.Now, LogType.Information, MessageDirection.None,
                                              "[Auto Update] File for retry action doesn't exit.  Item removed from update retry queue.", null,
                                              new SerializableDictionary <string, object>()
                            {
                                { "Filename", dicomPath }
                            });
                            DeleteRetry(fi, dicomPath);
                        }

                        using (UpdateProcessor processor = new UpdateProcessor(Module.Options.UseCustomAE ? Module.Options.AutoUpdateAE : ri.Item.ClientAE))
                        {
                            DicomCommandStatusType status = DicomCommandStatusType.Reserved4;
                            bool failed = false;

                            try
                            {
                                string message = string.Empty;

                                using (DicomDataSet ds = new DicomDataSet(PatientUpdaterAddIn.TemporaryDirectory))
                                {
                                    ds.Load(dicomPath, DicomDataSetLoadFlags.None);
                                    ri.Scp.PeerAddress = IPAddress.Parse(ri.Address);
                                    status             = processor.SendUpdate(ri.Scp, ds, ri.Item.Action);
                                    if (status != DicomCommandStatusType.Success)
                                    {
                                        if (status == DicomCommandStatusType.MissingAttribute || status == DicomCommandStatusType.AttributeOutOfRange)
                                        {
                                            message = string.Format("[Auto Update] {0} failed. Item not found at destination [{1}].  Item will be removed from update retry queue.", AutoRetryProcessor.Actions[ri.Item.Action], ri.Item.SourceAE);
                                            UpdateProcessor.LogEvent(LogType.Warning, MessageDirection.None, message, DicomCommandType.Undefined, null, processor.Scu, null);
                                        }
                                        else
                                        {
                                            failed = true;
                                        }
                                    }
                                }
                            }
                            catch (DicomException de)
                            {
                                string message = string.Format("[Auto Update] Error: {0}. Leaving {1} action to update retry queue.", de.Message, AutoRetryProcessor.Actions[ri.Item.Action]);

                                UpdateProcessor.LogEvent(LogType.Error, MessageDirection.Input, message, DicomCommandType.Undefined, null, processor.Scu, null);
                                failed = true;
                            }
                            catch (Exception e)
                            {
                                string message = "[Auto Update] " + e.Message;

                                Logger.Global.Log(string.Empty, string.Empty, -1, string.Empty, string.Empty, -1, DicomCommandType.Undefined,
                                                  DateTime.Now, LogType.Error, MessageDirection.None, message, null, null);
                                failed = true;
                            }

                            if (!failed)
                            {
                                DeleteRetry(fi, dicomPath);
                            }
                        }
                    }
                }
            }
            finally
            {
                _RetryTimer.Change(1000 * _Seconds, Timeout.Infinite);
            }
        }