//Called from editor's CommandLine. Almost same as _Run. Does not throw. internal static int RunCL_(wnd w, int mode, string script, string[] args, Action <string> resultA) { bool wait = 0 != (mode & 1), needResult = 0 != (mode & 2); using var tr = new _TaskResults(); if (needResult && !tr.Init()) { return((int)RunResult_.cannotGetResult); } var data = Serializer_.Serialize(script, args, tr.pipeName); int pid = (int)WndCopyData.Send <byte>(w, 101, data, mode); if (pid == 0) { pid--; //RunResult_.failed } switch ((RunResult_)pid) { case RunResult_.failed: case RunResult_.notFound: return(pid); case RunResult_.deferred: //possible only if !wait case RunResult_.editorThread: //the script ran sync and already returned. Ignore needResult, as it it auto-detected, not explicitly specified. return(0); } if (wait) { using var hProcess = WaitHandle_.FromProcessId(pid, Api.SYNCHRONIZE | Api.PROCESS_QUERY_LIMITED_INFORMATION); if (hProcess == null) { return((int)RunResult_.cannotWait); } if (!needResult) { hProcess.WaitOne(-1); } else if (!tr.WaitAndRead(hProcess, resultA)) { return((int)RunResult_.cannotWaitGetResult); } if (!Api.GetExitCodeProcess(hProcess.SafeWaitHandle.DangerousGetHandle(), out pid)) { pid = int.MinValue; } } return(pid); }
private void SystemMenuLoginItem_Click(object sender, EventArgs e) { if (AppManager.GetInstance().UserLoginState == AppManager.UserState.LOGIN) { return; } RbacServiceClient rbacService = new RbacServiceClient(AppManager.GetInstance().ApiUrl + "rbacservices/"); FrmUserLogin frmUserLogin = new FrmUserLogin(rbacService); var loginResult = frmUserLogin.ShowDialog(); if (loginResult == DialogResult.OK) { //设置导航菜单可用 NavigatoButton.Enabled = true; //系统管理员才能操作菜单设置对话框 if (AppManager.GetInstance().User.id == -1) { MenuMgrButton.Enabled = true; } //设置菜单栏里登录按钮不可用 SystemMenuLoginItem.Enabled = false; //从API获取用户权限及菜单 MenuServiceClient menuService_ = new MenuServiceClient(AppManager.GetInstance().ApiUrl + "menuservices/"); ResponseModel response; if (AppManager.GetInstance().User.id != -1) { //一般操作员默认根据用户ID获取菜单 response = menuService_.GetMenu(int.Parse(AppManager.GetInstance().User.user_id)); } else { //系统内置管理员默认获取所有菜单 response = menuService_.GetMenus(); } if (response.Code == 1) { List <Menus> menus = Serializer_.Deserialize <List <Menus> >(Serializer_.Serialize(response.Data)); InitMenus(menus); } else { MessageBox.Show($"获取权限异常:{response.Message}"); } } }
private void InitDepartmentTree() { ResponseModel response = DepartmentService_.GetDepartments(); if (response.Code == 1) { if (response.DataCount >= 1) { List <Department> departments = Serializer_.Deserialize <List <Department> >(Serializer_.Serialize(response.Data)); BindToTreeView(departments); } else { MessageBox.Show("尚未有任何部门被创建"); } } else { MessageBox.Show(response.Message); } }
public void UserLogin() { string userName = txtUserName.Text.Trim(); string password = txtPassword.Text.Trim(); if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password)) { MessageBox.Show("user name/password cannot be empty."); return; } ResponseModel response = RbacService_.UserLogin(userName, password); if (response.Code == 1) { AppManager.GetInstance().User = Serializer_.Deserialize <Users>(Serializer_.Serialize(response.Data)); AppManager.GetInstance().UserLoginState = AppManager.UserState.LOGIN; DialogResult = DialogResult.OK; } else { MessageBox.Show($"login fail,{response?.Message}"); DialogResult = DialogResult.Abort; } }
#pragma warning restore CS1573 // Parameter has no matching param tag in the XML comment (but other parameters do) static int _Run(int mode, string script, string[] args, out string resultS, Action <string> resultA = null) { resultS = null; var w = WndMsg_; if (w.Is0) { throw new AuException("Editor process not found."); //CONSIDER: run editor program, if installed } bool wait = 0 != (mode & 1), needResult = 0 != (mode & 2); using var tr = new _TaskResults(); if (needResult && !tr.Init()) { throw new AuException("*get task results"); } var data = Serializer_.Serialize(script, args, tr.pipeName); int pid = (int)WndCopyData.Send <byte>(w, 100, data, mode); if (pid == 0) { pid--; //RunResult_.failed } switch ((RunResult_)pid) { case RunResult_.failed: return(!wait ? -1 : throw new AuException("*start task")); case RunResult_.notFound: throw new FileNotFoundException($"Script '{script}' not found."); case RunResult_.deferred: //possible only if !wait case RunResult_.editorThread: //the script ran sync and already returned return(0); } if (wait) { using var hProcess = WaitHandle_.FromProcessId(pid, Api.SYNCHRONIZE | Api.PROCESS_QUERY_LIMITED_INFORMATION); if (hProcess == null) { throw new AuException("*wait for task"); } if (!needResult) { hProcess.WaitOne(-1); } else if (!tr.WaitAndRead(hProcess, resultA)) { throw new AuException("*get task result"); } else if (resultA == null) { resultS = tr.ResultString; } if (!Api.GetExitCodeProcess(hProcess.SafeWaitHandle.DangerousGetHandle(), out pid)) { pid = int.MinValue; } } return(pid); }
int _DragEvent(int event_, byte[] b) { if (!_isDragMode) { return(0); } DDEvent ev = (DDEvent)event_; if (ev == DDEvent.Leave) { if (!_wTargetControl.Is0) { _InvokeDT(_wTargetControl, ev, 0, 0, default); _wTargetControl = default; } return(0); } var a = Serializer_.Deserialize(b); int effect = a[0], keyState = a[1]; POINT pt = new(a[2], a[3]); if (ev == DDEvent.Enter) { _data = new System.Windows.DataObject(); var t = new DDData { files = a[4], shell = a[5], text = a[6], linkName = a[7] }; if (t.files != null) { _data.SetData("FileDrop", t.files); } if (t.shell != null) { _SetDataBytes("Shell IDList Array", t.shell); } if (t.text != null) { _data.SetData("UnicodeText", t.text); } if (t.linkName != null) { _SetDataBytes("FileGroupDescriptorW", t.linkName); } //workaround for: SetData writes byte[] in wrong format, probably serialized void _SetDataBytes(string name, byte[] a) => _data.SetData(name, new MemoryStream(a), false); } int ef = 0; var w = _wWindow.ChildFromXY(pt, WXYCFlags.ScreenXY); if (w.Is0) { w = _wWindow; } if (w != _wTargetControl && !_wTargetControl.Is0) { _InvokeDT(_wTargetControl, DDEvent.Leave, 0, 0, default); _wTargetControl = default; } if (!w.Is0 && w.IsOfThisProcess && w.IsEnabled(true)) { if (ev != 0 && _wTargetControl.Is0) { if (ev == DDEvent.Over) { ev = 0; } else { _InvokeDT(w, DDEvent.Enter, effect, keyState, pt); } } ef = _InvokeDT(_wTargetControl = w, ev, effect, keyState, pt); } if (ev == DDEvent.Drop) { _wTargetControl = default; } int _InvokeDT(wnd w, DDEvent ev, int effect, int keyState, POINT pt) { if (w.IsOfThisThread) { return(_InvokeDropTarget(w, ev, effect, keyState, pt)); } var d = HwndSource.FromHwnd(w.Window.Handle)?.Dispatcher; return(d?.Invoke(() => _InvokeDropTarget(w, ev, effect, keyState, pt)) ?? 0); } return(ef); }