private int CheckPrinterStatus(DatDeviceReboot ddr, DateTime startDt) { int exe; int rebootTime = 0; string state = string.Empty; DateTime dt = DateTime.Now.AddSeconds(240); while (state != "Ready" && (dt > DateTime.Now)) { state = ddr.GetSNMPData(out exe, _deviceStatus); TimeSpan span = DateTime.Now.Subtract(startDt); rebootTime = (span.Minutes * 60) + span.Seconds; if (state.Equals("04 00")) { state = "Still in the process of rebooting: " + rebootTime + " seconds passed."; } else if (string.IsNullOrWhiteSpace(state)) { state = "Still in the process of rebooting:" + rebootTime + " seconds passed."; } else if (state.ToLower().Contains("error:") && state.ToLower().Contains("did not respond to snmp")) { state = "Beginning of power cycle process. Printer is unable to respond."; } RlblRebootMessage.Text = state; RlblRebootMessage.Update(); this.Refresh(); } return(rebootTime); }
private void CheckPrinterIPAddress(DatDeviceReboot ddr) { if (!ddr.ValidIPAddress(RtxtIpAddress.Text)) { ErrorMessage = ddr.GetLastError + ", " + RtxtIpAddress.Text; MessageBox.Show(ErrorMessage, "Printer IP Address", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void RebootDevice(DatDeviceReboot ddr, ref int exeTime, ref int rebootTime) { ddr.RebootDevice(_rebootOid, out exeTime); if (exeTime > 0) { RlblRebootMessage.Text = "Starting the power cycle process"; RlblRebootMessage.Update(); DateTime startDt = DateTime.Now; Thread.Sleep(5000); rebootTime = CheckPrinterStatus(ddr, startDt); } }
private void RbtnReboot_Click(object sender, EventArgs e) { ErrorMessage = string.Empty; DatDeviceReboot ddr = new DatDeviceReboot(RtxtIpAddress.Text, string.Empty); CheckPrinterIPAddress(ddr); int rebootTime = 0; int exeTime; if (!IsError) { GetDeviceName(ddr); string status = ddr.GetSNMPData(out exeTime, _deviceStatus); SetLabel(); if (status.ToLower().Equals("sleep mode on")) { WakeDevice(ddr); } RebootDevice(ddr, ref exeTime, ref rebootTime); if (!ddr.IsError) { RlblRebootMessage.Text += " - Rebooted in " + rebootTime + " seconds."; } else { MessageBox.Show(ddr.GetLastError, "Printer IP Address", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { ErrorMessage = string.Empty; } }
private void WakeDevice(DatDeviceReboot ddr) { int exeTime = 0; string status = ddr.SetDeviceValue(_wakeDevice, 1, out exeTime); if (!ddr.IsError) { status = ddr.GetSNMPData(out exeTime, _deviceStatus); while (status.ToLower().Contains("sleep") || status.ToLower().Contains("initializing")) { RlblRebootMessage.Text = status + "...Waking device " + RtxtIpAddress.Text; RlblRebootMessage.Update(); exeTime = 0; Thread.Sleep(5000); status = ddr.GetSNMPData(out exeTime, _deviceStatus); } } else { RlblRebootMessage.Text = "Issue waking device. Reboot may still work. " + ddr.GetLastError; } }
private void GetDeviceName(DatDeviceReboot ddr) { int iTime = 0; PrinterName = ddr.GetSNMPData(out iTime, _printerNameOid); }