public bool AddNurseryItem(string pathName) { /* * NurseryMenu.DropDownItems ---------> ToolStripItemCollection<ToolStripItem> * ↑ * ToolStripItem ---> ToolStripSeparator -----------------------------| * ↓ | * ToolStripDropDownItem ----------------------------------------------| */ bool hasThisPS = false; foreach (ToolStripItem item in NurseryMenu.DropDownItems) { if (item.ToolTipText != null && item.ToolTipText.Equals(pathName)) { hasThisPS = true; } } if (!hasThisPS) { var newItem = ActionManager.GetItem(pathName); BeginInvoke(new CrossThreadDelegate(() => { NurseryMenu.DropDownItems.Add(newItem); })); LogClerk.Info($"Added {pathName}"); } return(!hasThisPS); }
private static void OnProcessExit(object sender, EventArgs e) { Process ps = sender as Process; string pathName = ps.StartInfo.FileName; ProcessStruct pst = Processes[pathName]; pst.isRunning = false; Processes[pathName] = pst; OperationClerk.OnProcessStopped(pathName, FPName[pathName]); LogClerk.Info($"Process {FPName[pathName]} exited"); }
private static void PipeServerThread() { server = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous, 1024, 1024, null, HandleInheritability.None, PipeAccessRights.ChangePermissions); PipeSecurity ps = server.GetAccessControl(); PipeAccessRule clientRule = new PipeAccessRule( new SecurityIdentifier("S-1-15-2-1"), PipeAccessRights.ReadWrite, AccessControlType.Allow); PipeAccessRule ownerRule = new PipeAccessRule( WindowsIdentity.GetCurrent().Owner, PipeAccessRights.FullControl, AccessControlType.Allow); ps.AddAccessRule(clientRule); ps.AddAccessRule(ownerRule); server.SetAccessControl(ps); LogClerk.Info("Waiting for connection."); server.WaitForConnection(); reader = new StreamReader(server); writer = new StreamWriter(server); LogClerk.Info($"Connection established: {pipeName}"); while (serverRun) { //if (!server.IsConnected) //{ // server.Disconnect(); // LogClerk.Info("Disconnected from FancyToys, waiting for its reconnection."); // server.WaitForConnection(); // LogClerk.Info("FancyToys reconnected"); //} if (server.IsConnected) { string message = reader.ReadLine(); if (!string.IsNullOrEmpty(message)) { MessageManager.Deal(message); } } else { break; } } }
private static void PipeConnectionDetector() { while (true) { if (!server.IsConnected) { server.Disconnect(); LogClerk.Info("Disconnected from FancyToys, waiting for its reconnection."); server.WaitForConnection(); LogClerk.Info("FancyToys reconnected"); } } }
public bool SetNurseryItemCheckState(string pathName, CheckState checkState) { foreach (ToolStripItem item in NurseryMenu.DropDownItems) { if (item.ToolTipText != null && item.ToolTipText.Equals(pathName)) { BeginInvoke(new CrossThreadDelegate(() => { (item as ToolStripMenuItem).CheckState = checkState; })); LogClerk.Info($"Set {item.Text} {checkState}"); return(true); } } return(false); }
private static void DealWithConfig(string content) { bool success = JsonUtil.ParseStruct <ConfigStruct>(content, out ConfigStruct cs); if (success) { switch (cs.type) { case ConfigType.FlushTime: InformationClerk.ThreadSleepSpan = cs.flushTime; Console.WriteLine($"Set flush time {InformationClerk.ThreadSleepSpan}"); LogClerk.Info($"Set flush time {InformationClerk.ThreadSleepSpan}"); break; } } }
public bool RemoveNurseryItem(string pathName) { foreach (ToolStripItem item in NurseryMenu.DropDownItems) { if (item.ToolTipText != null && item.ToolTipText.Equals(pathName)) { BeginInvoke(new CrossThreadDelegate(() => { NurseryMenu.DropDownItems.Remove(item); })); LogClerk.Info($"Removed {pathName}"); return(true); } } LogClerk.Warn($"Menu item not exit while removing it: {pathName}"); return(false); }
private static Process AddProcess(string pathName) { Process child = new Process(); child.StartInfo.RedirectStandardOutput = true; child.StartInfo.RedirectStandardError = true; child.StartInfo.FileName = pathName; child.StartInfo.CreateNoWindow = true; child.StartInfo.UseShellExecute = false; child.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(pathName); child.EnableRaisingEvents = true; // 这样才会引发 Process.Exited child.Exited += OnProcessExit; child.OutputDataReceived += (s, e) => { if (!string.IsNullOrEmpty(e.Data)) { StdClerk.StdOutput((s as Process).ProcessName, e.Data); } }; child.ErrorDataReceived += (s, e) => { if (!string.IsNullOrEmpty(e.Data)) { StdClerk.StdError((s as Process).ProcessName, e.Data); } }; Processes[pathName] = new ProcessStruct { process = child, isRunning = false }; FPName[pathName] = null; LogClerk.Info($"Added {pathName} to local process table."); return(child); }