private void reconvertFileBtn_Click(object sender, EventArgs e) { if (showHistoryList.SelectedItems.Count == 0) { return; } if (MessageBox.Show(Localise.GetPhrase("Are you sure you want to reconvert the selected files?"), Localise.GetPhrase("Reconvert files"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes) { foreach (ListViewItem item in showHistoryList.SelectedItems) { try { _pipeProxy.DeleteHistoryItem(item.Text); } catch (Exception e1) { MessageBox.Show(Localise.GetPhrase("Unable to communicate with engine."), Localise.GetPhrase("Communication Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); Log.WriteSystemEventLog(Localise.GetPhrase("MCEBuddy GUI: Unable to clear History File"), EventLogEntryType.Warning); Log.WriteSystemEventLog(e1.ToString(), EventLogEntryType.Warning); } } // Reload form GetAndDisplayHistoryLog(); } }
static int Main(string[] args) { Log.AppLog = new Log(Log.LogDestination.Console); // Redirect to console all output Log.LogLevel = Log.LogEntryType.Debug; // Print all messages ICore _pipeProxy = null; CLIOptions cliOptions = new CLIOptions(); string currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); Log.AppLog.WriteEntry("", "\r\nMCEBuddy.UserCLI is a Command Line Interface for users to interact with the MCEBuddy engine", Log.LogEntryType.Debug); Log.AppLog.WriteEntry("", "Copyright (c) Ramit Bhalla, Build Version : " + currentVersion, Log.LogEntryType.Debug); Log.AppLog.WriteEntry("", "Build Date : " + System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString(System.Globalization.CultureInfo.InvariantCulture), Log.LogEntryType.Debug); Log.AppLog.WriteEntry("", "", Log.LogEntryType.Debug); if (args.Length < 2) // Atleast 2 arguments are required { Usage(); return(-1); } try { CommandLineParser parser = new CommandLineParser(); if (!parser.ParseArguments(args, cliOptions)) { throw new Exception("Invalid Options"); } } catch (Exception e) { Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI Invalid Input Error -> " + e.ToString() + "\r\n", Log.LogEntryType.Error); Usage(); return(-1); // Bad usage } Log.AppLog.WriteEntry("", "\r\nMCEBuddy.UserCLI trying to connect to Engine " + cliOptions.Server + " on Port " + cliOptions.Port + "\r\n", Log.LogEntryType.Debug); // Connect to the engine try // Try to reconnect { string remoteServerName = cliOptions.Server; int remoteServerPort = cliOptions.Port; _pipeProxy = MCEBuddyEngineConnect.ConnectToRemoteEngine(remoteServerName, remoteServerPort); _pipeProxy.EngineRunning(); // Test to check if we are really connected Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI successfully connected to MCEBuddy engine", Log.LogEntryType.Debug); // Pass the command to the engine switch (cliOptions.Command) { // Engine commands case "engine": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI processing command engine", Log.LogEntryType.Debug); // Engine actions switch (cliOptions.Action) { case "start": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI starting engine", Log.LogEntryType.Debug); _pipeProxy.Start(); break; case "stop": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI stopping engine", Log.LogEntryType.Debug); _pipeProxy.Stop(true); break; case "pause": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI pausing engine", Log.LogEntryType.Debug); _pipeProxy.SuspendConversion(true); break; case "resume": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI resuming engine", Log.LogEntryType.Debug); _pipeProxy.SuspendConversion(false); break; case "rescan": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI rescanning monitor locations and logs", Log.LogEntryType.Debug); _pipeProxy.Rescan(); break; default: Log.AppLog.WriteEntry("", "Invalid action " + cliOptions.Action, Log.LogEntryType.Error); Usage(); return(-1); } break; // Adding a file to the queue case "addfile": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI processing command addfile", Log.LogEntryType.Debug); if (String.IsNullOrWhiteSpace(cliOptions.Action)) { Log.AppLog.WriteEntry("", "Invalid filename " + cliOptions.Action, Log.LogEntryType.Error); Usage(); return(-1); } Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI adding file " + cliOptions.Action + " to the conversion queue", Log.LogEntryType.Debug); if (Util.Net.IsUNCPath(Util.Net.GetUNCPath(cliOptions.Action))) // check if the files are on a remote computer { Log.AppLog.WriteEntry("", "Networked files will be accessed using the logon credentials of the MCEBuddy Service, not the currently logged on user. You can manually specify the network credentials from the Settings -> Expert Settings page in MCEBuddy.", Log.LogEntryType.Warning); } _pipeProxy.AddManualJob(cliOptions.Action); break; // Removing a job from the queue case "removejob": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI processing command removejob", Log.LogEntryType.Debug); int fileNo; if (String.IsNullOrWhiteSpace(cliOptions.Action) || (!int.TryParse(cliOptions.Action, out fileNo)) || (fileNo < 1)) // job starts at 1 for users { Log.AppLog.WriteEntry("", "Invalid job number " + cliOptions.Action, Log.LogEntryType.Error); Usage(); return(-1); } Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI removing job " + fileNo + " from the conversion queue", Log.LogEntryType.Debug); _pipeProxy.CancelJob(new int[] { --fileNo }); // MCEBuddy start jobs at 0 break; // Change priority case "priority": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI processing command change priority", Log.LogEntryType.Debug); switch (cliOptions.Action) { case "low": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI setting priority to low", Log.LogEntryType.Debug); _pipeProxy.ChangePriority("Low"); break; case "normal": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI setting priority to normal", Log.LogEntryType.Debug); _pipeProxy.ChangePriority("Normal"); break; case "high": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI setting priority to high", Log.LogEntryType.Debug); _pipeProxy.ChangePriority("High"); break; default: Log.AppLog.WriteEntry("", "Invalid priority " + cliOptions.Action, Log.LogEntryType.Error); Usage(); return(-1); } break; // Remove file from History case "deletehistoryitem": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI processing command deleting file entry from history", Log.LogEntryType.Debug); if (String.IsNullOrWhiteSpace(cliOptions.Action)) { Log.AppLog.WriteEntry("", "Invalid filename " + cliOptions.Action, Log.LogEntryType.Error); Usage(); return(-1); } Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI deleting item " + cliOptions.Action + " from History", Log.LogEntryType.Debug); _pipeProxy.DeleteHistoryItem(cliOptions.Action); break; // UPnP case "upnp": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI processing command UPnP", Log.LogEntryType.Debug); switch (cliOptions.Action) { case "enable": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI enabling UPnP access port fowarding", Log.LogEntryType.Debug); _pipeProxy.SetUPnPState(true); break; case "disable": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI disabling UPnP access port fowarding", Log.LogEntryType.Debug); _pipeProxy.SetUPnPState(false); break; default: Log.AppLog.WriteEntry("", "Invalid UPnP state " + cliOptions.Action, Log.LogEntryType.Error); Usage(); return(-1); } break; // Firewall case "firewall": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI processing command Firewall", Log.LogEntryType.Debug); switch (cliOptions.Action) { case "enable": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI enabling Firewall exception for MCEBuddy remote access", Log.LogEntryType.Debug); _pipeProxy.SetFirewallException(true); break; case "disable": Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI disabling Firewall exception for MCEBuddy remote access", Log.LogEntryType.Debug); _pipeProxy.SetFirewallException(false); break; default: Log.AppLog.WriteEntry("", "Invalid Firewall exception state " + cliOptions.Action, Log.LogEntryType.Error); Usage(); return(-1); } break; default: Log.AppLog.WriteEntry("", "Invalid command " + cliOptions.Command, Log.LogEntryType.Error); Usage(); return(-1); } // Successful Log.AppLog.WriteEntry("", "\r\nMCEBuddy.UserCLI Successful!!", Log.LogEntryType.Debug); return(0); // we good here } catch (Exception e) { Log.AppLog.WriteEntry("", "MCEBuddy.UserCLI Error -> " + e.ToString() + "\r\n", Log.LogEntryType.Error); Log.AppLog.WriteEntry("", "\r\nMCEBuddy.UserCLI Failed!!", Log.LogEntryType.Debug); return(-2); // too bad } }