/// <summary> /// This function will check to see if there are any service instances for the given /// BizTalk application. If so, it will throw an exception. /// </summary> public override bool Execute() { this.Log.LogMessage("Checking for existing service instances associated with application '{0}'...", _applicationName); using (BizTalkOperations _operations = new BizTalkOperations()) { // Get all service instances in the message box. foreach (Instance instance in _operations.GetServiceInstances()) { // We will only deal with instances that we can determine // which application it belongs to. MessageBoxServiceInstance mbsi = instance as MessageBoxServiceInstance; if (mbsi != null) { if (mbsi.Application == Application) { this.Log.LogError( "There is at least one service instance associated with the '{0}' application [Instance Status = {1}]. An application be removed only when there are no associated service instances.", _applicationName, Enum.GetName(typeof(InstanceStatus), mbsi.InstanceStatus)); return(false); } } } } this.Log.LogMessage("Done checking for existing service instances associated with application '{0}'.", _applicationName); return(true); }
public MessageBoxServiceInstanceWrapper(MessageBoxServiceInstance messageBoxServiceInstance) { if (messageBoxServiceInstance == null) { throw new ArgumentNullException("messageBoxServiceInstance"); } _messageBoxServiceInstance = messageBoxServiceInstance; }
public override bool Execute() { if (string.IsNullOrEmpty(_applicationName)) { base.Log.LogError("Application property must be set"); return(false); } int resumedServiceCount = 0; bool success = true; bool resumeAll = (_applicationName.Trim() == "*"); base.Log.LogMessage( MessageImportance.Normal, "Attempting to resume all service instances for BizTalk app '{0}'...", resumeAll ? "[ALL APPS]" : _applicationName); using (BizTalkOperations operations = new BizTalkOperations()) { // Get all service instances in the message box. // This is terribly inefficient -- BizTalkOperations has a way to directly query and filter by app, but the classes are Internal. // Could use reflection to call it anyway, but risks compatibility across BizTalk releases. foreach (Instance instance in operations.GetServiceInstances()) { MessageBoxServiceInstance mbsi = instance as MessageBoxServiceInstance; if (mbsi != null) { // Only resume if the application matches the one we are interested in. "*" will match all apps. bool resumeThisInstance = (resumeAll || (string.Compare(mbsi.Application, _applicationName, true) == 0)); bool suspended = ((mbsi.InstanceStatus & InstanceStatus.SuspendedAll) != InstanceStatus.None); if (resumeThisInstance && suspended) { CompletionStatus status = operations.ResumeInstance(mbsi.ID); if (status != CompletionStatus.Succeeded) { this.Log.LogWarning("Could not resume instance {0}. Status is {1}.", mbsi.ID, status.ToString()); success = false; } else { resumedServiceCount++; } if (resumedServiceCount % 5000 == 0) { base.Log.LogMessage( MessageImportance.Normal, "Resumed {0} service instances for BizTalk app '{1}'.", resumedServiceCount, resumeAll ? "[ALL APPS]" : _applicationName); } } } } } base.Log.LogMessage( MessageImportance.Normal, "Finished resuming {0} service instances for BizTalk app '{1}'.", resumedServiceCount, resumeAll ? "[ALL APPS]" : _applicationName); return(success); }
public MessageBoxServiceInstanceWrapper(MessageBoxServiceInstance messageBoxServiceInstance) { _messageBoxServiceInstance = messageBoxServiceInstance ?? throw new ArgumentNullException(nameof(messageBoxServiceInstance)); }
public override bool Execute() { if (string.IsNullOrEmpty(_applicationName)) { base.Log.LogError("Application property must be set"); return(false); } const int MaxRetries = 3; bool success = true; int terminatedServiceCount = 0; bool removeAll = (_applicationName.Trim() == "*"); base.Log.LogMessage( MessageImportance.Normal, "Attempting to terminate all service instances for BizTalk app '{0}'...", removeAll ? "[ALL APPS]" : _applicationName); for (int retryCount = 0; retryCount < MaxRetries; retryCount++) { success = true; // Create a new BizTalkOperations instance each time to avoid potential caching issues using (BizTalkOperations operations = new BizTalkOperations()) { // Get all service instances in the message box. // This is terribly inefficient -- BizTalkOperations has a way to directly query and filter by app, but the classes are Internal. // Could use reflection to call it anyway, but risks compatibility across BizTalk releases. foreach (Instance instance in operations.GetServiceInstances()) { MessageBoxServiceInstance mbsi = instance as MessageBoxServiceInstance; if (mbsi == null) { continue; } // Only terminate if the application matches the one we are interested in. "*" will match all apps. bool removeThisInstance = (removeAll || (string.Compare(mbsi.Application, _applicationName, true) == 0)); bool running = ((mbsi.InstanceStatus & InstanceStatus.RunningAll) != InstanceStatus.None); bool suspended = ((mbsi.InstanceStatus & InstanceStatus.SuspendedAll) != InstanceStatus.None); if (removeThisInstance && (running || suspended)) { CompletionStatus status = operations.TerminateInstance(mbsi.ID); if (status != CompletionStatus.Succeeded) { if (instance.Class == ServiceClass.RoutingFailure) { this.Log.LogMessage(MessageImportance.Low, "Could not terminate routing failure {0}. It was probably terminated by a linked instance.", mbsi.ID); } else { if (retryCount == MaxRetries - 1) { this.Log.LogError("Could not terminate instance {0}. Status is {1}.", mbsi.ID, status.ToString()); } success = false; } } else { terminatedServiceCount++; } } } } if (success) { break; } } base.Log.LogMessage( MessageImportance.Normal, "Terminated {0} service instances for BizTalk app '{1}'.", terminatedServiceCount, removeAll ? "[ALL APPS]" : _applicationName); return(success); }