/// <summary> /// Execution /// </summary> /// <param name="executionData"></param> /// <returns></returns> public PluginExecutionResult Execute(PluginExecutionData executionData) { if (!_setupDone) { TelnetLibrary.EnableTelnetFeature(); _setupDone = true; } _activityData = executionData.GetMetadata <SecurityConfigurationActivityData>(); var printer = (PrintDeviceInfo)executionData.Assets.First(); try { _strAuthorization = ConvertToBase64Encoding($"admin:{ (object)printer.AdminPassword}"); switch (_activityData.SecurityType) { case SecurityConfigurationType.Basic: { BasicEnhancedSecurityConfig(printer, SecurityConfigurationType.Basic); } break; case SecurityConfigurationType.Enhanced: { BasicEnhancedSecurityConfig(printer, SecurityConfigurationType.Enhanced); } break; case SecurityConfigurationType.Custom: { CustomSecurityConfiguration(printer, SecurityConfigurationType.Custom); } break; } } catch (Exception exception) { return(new PluginExecutionResult(PluginResult.Failed, $"Failed for {printer.Address}: {exception.Message}")); } return(new PluginExecutionResult(PluginResult.Passed)); }
/// <summary> /// Performs Power Cycle of the Device /// </summary> /// <param name="address">Address</param> private void PowerCyclePrinter(string address) { const int telnetPort = 223; using (TelnetLibrary telnetConnection = new TelnetLibrary(address, telnetPort)) { ExecutionServices.SystemTrace.LogDebug("Telnet Status:" + telnetConnection.Read()); if (telnetConnection.IsConnected) { System.Threading.Thread.Sleep(TimeSpan.FromMinutes(1)); ExecutionServices.SystemTrace.LogDebug("Power Cycle Started"); telnetConnection.WriteLine("reboot"); ExecutionServices.SystemTrace.LogDebug("Telnet Status:" + telnetConnection.Read()); System.Threading.Thread.Sleep(TimeSpan.FromMinutes(5)); Retry.UntilTrue(() => IsPrinterAwake(address), 10, TimeSpan.FromMinutes(1)); } else { ExecutionServices.SystemTrace.LogDebug("Error while connecting through Telnet."); } } }