/// <summary> /// Cancels the operation. /// </summary> public void Cancel() { if (LogInformation) { Platform.Log(LogLevel.Info, "Canceling..."); } Status = ScuOperationStatus.Canceled; ProgressEvent.Set(); }
/// <summary> /// Stops the running operation, by setting the Status to NotRunning, stopping the timer, and setting /// the Progress Wait Event so execution can continue. /// </summary> protected void StopRunningOperation() { //If it's anything else, then the client code may want to inspect the value. if (Status == ScuOperationStatus.Running) { Status = ScuOperationStatus.NotRunning; } ProgressEvent.Set(); }
/// <summary> /// Cancels the operation. /// </summary> public virtual void Cancel() { if (LogInformation) { LogAdapter.Logger.InfoWithFormat("Canceling Scu connected from {0} to {1}:{2}:{3}...", ClientAETitle, RemoteAE, RemoteHost, RemotePort); } Status = ScuOperationStatus.Canceled; ProgressEvent.Set(); }
/// <summary> /// Cancels the operation. /// </summary> public virtual void Cancel() { if (LogInformation) { Platform.Log(LogLevel.Info, "Canceling Scu connected from {0} to {1}:{2}:{3}...", ClientAETitle, RemoteAE, RemoteHost, RemotePort); } Status = ScuOperationStatus.Canceled; ProgressEvent.Set(); }
public void Abort() { if (_dicomClient != null) { // Force a 2.5 second timeout _dicomClient.Abort(2500); _dicomClient.Dispose(); _dicomClient = null; Status = ScuOperationStatus.NetworkError; ProgressEvent.Set(); } }
private void OnExportCompleted(object sender, ExportCompletedEventArgs e) { GlymaExportUserState userState = e.UserState as GlymaExportUserState; if (userState != null) { try { ProgressRecord progressRecord = new ProgressRecord(0, "Exporting Glyma Map", string.Format("Creating output file: {0}", Output)); progressRecord.SecondsRemaining = -1; progressRecord.PercentComplete = 100; lock (pr_lock) { this.ProgressRecord = progressRecord; ProgressEvent.Set(); //notify of change to progress } //Delete the file if it already exists before the move operation if (File.Exists(Output)) { File.Delete(Output); } File.Move(e.FileLocation, Output); progressRecord = new ProgressRecord(0, "Exporting Glyma Map", "Export completed"); progressRecord.SecondsRemaining = -1; progressRecord.PercentComplete = 100; progressRecord.RecordType = ProgressRecordType.Completed; lock (pr_lock) { this.ProgressRecord = progressRecord; ProgressEvent.Set(); //notify of change to progress } } catch (Exception ex) { lock (msg_lock) { this.Message = string.Format("Failed to move the temporary file '{0}' to the output file location.\r\n\r\nException: {1}", e.FileLocation, ex); LogMessageEvent.Set(); } } finally { userState.Completed.Set(); //signal that the export has completed Completed.Set(); //signal that the Cmdlet has completed } } }
private void OnProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) { //ensure that the completed percentage only goes up if (e.ProgressPercentage > ProgressRecord.PercentComplete) { ProgressRecord progressRecord = new ProgressRecord(0, "Exporting Glyma Map", string.Format("Export Progress: {0}%", e.ProgressPercentage)); progressRecord.SecondsRemaining = -1; progressRecord.PercentComplete = e.ProgressPercentage; lock (pr_lock) { this.ProgressRecord = progressRecord; ProgressEvent.Set(); //notify of change to progress } } }
/// <summary> /// Called when a timeout occurs waiting for the next message, as specified by <see cref="AssociationParameters.ReadTimeout"/>. /// </summary> /// <param name="client">The client.</param> /// <param name="association">The association.</param> public override void OnDimseTimeout(DicomClient client, ClientAssociationParameters association) { Status = ScuOperationStatus.TimeoutExpired; FailureDescription = String.Format("Timeout Expired ({0} seconds) for remote AE {1} when processing C-MOVE-RQ, aborting connection", association.ReadTimeout / 1000, RemoteAE); Platform.Log(LogLevel.Error, FailureDescription); try { client.SendAssociateAbort(DicomAbortSource.ServiceUser, DicomAbortReason.NotSpecified); } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Error aborting association"); } Platform.Log(LogLevel.Warn, "Completed aborting connection (after DIMSE timeout) from {0} to {1}", association.CallingAE, association.CalledAE); ProgressEvent.Set(); }
/// <summary> /// Called when [dimse timeout]. /// </summary> /// <param name="client">The client.</param> /// <param name="association">The association.</param> public virtual void OnDimseTimeout(DicomClient client, ClientAssociationParameters association) { Status = ScuOperationStatus.TimeoutExpired; ResultStatus = DicomState.Failure; FailureDescription = String.Format("Timeout Expired for remote host {0}, aborting connection", RemoteAE); if (LogInformation) { LogAdapter.Logger.Info(FailureDescription); } try { client.SendAssociateAbort(DicomAbortSource.ServiceUser, DicomAbortReason.NotSpecified); } catch (Exception ex) { LogAdapter.Logger.TraceException(ex); } LogAdapter.Logger.WarnWithFormat("Completed aborting connection (after DIMSE timeout) from {0} to {1}", association.CallingAE, association.CalledAE); ProgressEvent.Set(); }
private void InitMapManager() { ProgressRecord progressRecord = new ProgressRecord(0, "Exporting Glyma Map", "Initialising web service client"); progressRecord.SecondsRemaining = -1; progressRecord.PercentComplete = 0; progressRecord.RecordType = ProgressRecordType.Processing; lock (pr_lock) { this.ProgressRecord = progressRecord; ProgressEvent.Set(); //notify of change to progress } var binding = new BasicHttpBinding(); binding.ReaderQuotas.MaxStringContentLength = 2147483647; binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm; binding.MaxReceivedMessageSize = 2147483647; var address = new EndpointAddress(new Uri(ServiceUrl)); CallingUrl.Url = Identity; var client = new TransactionalMappingToolServiceClient(binding, address); System.Net.NetworkCredential credential = new System.Net.NetworkCredential(SharePointUsername, SharePointPassword); client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; client.ClientCredentials.Windows.ClientCredential = credential; MapManager = new SoapMapManager(client, true); MapManager.InitialiseMapManagerCompleted += OnInitialiseMapManagerCompleted; MapManager.InitialiseMapManagerAsync(); }
protected void StopRunningOperation(ScuOperationStatus status) { Status = status; ProgressEvent.Set(); }
/// <summary> /// Called when received response message. Sets the <see cref="Results"/> property as appropriate. /// </summary> /// <param name="client">The client.</param> /// <param name="association">The association.</param> /// <param name="presentationID">The presentation ID.</param> /// <param name="message">The message.</param> public override void OnReceiveResponseMessage(DicomClient client, ClientAssociationParameters association, byte presentationID, DicomMessage message) { if (message.Status.Status == DicomState.Pending) { // one result sent back, add to result list _results.Add(message.DataSet); if (_maxResults != -1 && !_cancelSent && _results.Count > _maxResults) { client.SendCFindCancelRequest(presentationID, message.MessageIdBeingRespondedTo); _cancelSent = true; } } else { _cancelSent = false; DicomState status = message.Status.Status; if (message.Status.Status != DicomState.Success) { if (status == DicomState.Cancel) { if (LogInformation) { Platform.Log(LogLevel.Info, "Cancel status received in Find Scu: {0}", message.Status); } Status = ScuOperationStatus.Canceled; } else if (status == DicomState.Failure) { string msg = String.Format("Failure status received in Find Scu: {0}", message.Status); Platform.Log(LogLevel.Error, msg); Status = ScuOperationStatus.Failed; FailureDescription = msg; } else if (status == DicomState.Warning) { Platform.Log(LogLevel.Warn, "Warning status received in Find Scu: {0}", message.Status); } else if (Status == ScuOperationStatus.Canceled) { if (LogInformation) { Platform.Log(LogLevel.Info, "Client cancelled Find Scu operation."); } } } else { if (LogInformation) { Platform.Log(LogLevel.Info, "Success status received in Find Scu!"); } } if (!ReuseAssociation) { client.SendReleaseRequest(); StopRunningOperation(); } else { ProgressEvent.Set(); } } }
private void OnInitialiseMapManagerCompleted(object sender, InitialiseMapManagerEventArgs e) { if (e.IsInitialised) { ProgressRecord progressRecord = new ProgressRecord(0, "Exporting Glyma Map", string.Format("Initialising {0} export processor", ExportFormat.ToString())); progressRecord.SecondsRemaining = -1; progressRecord.PercentComplete = 5; progressRecord.RecordType = ProgressRecordType.Processing; lock (pr_lock) { this.ProgressRecord = progressRecord; ProgressEvent.Set(); //notify of change to progress } ExportUtilityFactory exportFactory = new ExportUtilityFactory(MapManager); IExportUtility exportUtil = null; switch (MapSchema) { case "IBIS": switch (ExportFormat) { case "Compendium": exportUtil = exportFactory.CreateExportUtility(MapType.IBIS, ExportType.Compendium); break; case "Word": exportUtil = exportFactory.CreateExportUtility(MapType.IBIS, ExportType.Word); break; case "PDF": exportUtil = exportFactory.CreateExportUtility(MapType.IBIS, ExportType.PDF); break; case "GlymaXML": //exportUtil = exportFactory.CreateExportUtility(MapType.IBIS, ExportType.GlymaXml); lock (msg_lock) { Message = "Exporting to GlymaXML format is currently not supported"; LogMessageEvent.Set(); } break; } break; } exportUtil.ExportCompleted += OnExportCompleted; exportUtil.ProgressChanged += OnProgressChanged; ExportPropertiesDictionary exportProps = CreateExportProperties(); GlymaExportUserState userState = new GlymaExportUserState(Output); progressRecord = new ProgressRecord(0, "Exporting Glyma Map", "Export Progress: 0%"); progressRecord.SecondsRemaining = -1; progressRecord.PercentComplete = 10; progressRecord.RecordType = ProgressRecordType.Processing; lock (pr_lock) { this.ProgressRecord = progressRecord; ProgressEvent.Set(); //notify of change to progress } exportUtil.ExportMap(Domain, Map, exportProps, null, userState); bool signalled = userState.Completed.WaitOne(Timeout.Infinite); //wait for the export to completed if (!signalled) { Completed.Set(); //since it's inifinite timeout this shouldn't happen } } else { lock (msg_lock) { this.Message = string.Format("Failed to initialise the web service client: {0}", e.ErrorMessage); LogMessageEvent.Set(); } Completed.Set(); } }
/// <summary> /// Called when received response message. Sets the <see cref="Results"/> property as appropriate. /// </summary> /// <param name="client">The client.</param> /// <param name="association">The association.</param> /// <param name="presentationID">The presentation ID.</param> /// <param name="message">The message.</param> public override void OnReceiveResponseMessage(DicomClient client, ClientAssociationParameters association, byte presentationID, DicomMessage message) { if (message.Status.Status == DicomState.Pending) { // one result sent back, add to result list _results.Add(message.DataSet); if (_maxResults != -1 && !_cancelSent && _results.Count > _maxResults) { client.SendCFindCancelRequest(presentationID, message.MessageIdBeingRespondedTo); _cancelSent = true; } } else { _cancelSent = false; DicomStatus status = DicomStatuses.LookupQueryRetrieve(message.Status.Code); if (status.Status != DicomState.Success) { if (status.Status == DicomState.Cancel) { if (LogInformation) { LogAdapter.Logger.Info("Cancel status received in Find Scu: {0}", status); } Status = ScuOperationStatus.Canceled; } else if (status.Status == DicomState.Failure) { LogAdapter.Logger.Error("Failure status received in Find Scu: {0}", status); Status = ScuOperationStatus.Failed; FailureDescription = status.ToString(); } else if (status.Status == DicomState.Warning) { LogAdapter.Logger.Warn("Warning status received in Find Scu: {0}", status); } else if (Status == ScuOperationStatus.Canceled) { if (LogInformation) { LogAdapter.Logger.Info("Client cancelled Find Scu operation."); } } } else { if (LogInformation) { LogAdapter.Logger.Info("Success status received in Find Scu!"); } } if (!ReuseAssociation) { client.SendReleaseRequest(); StopRunningOperation(); } else { ProgressEvent.Set(); } } }