public void Successful_Scenario_Test(QueryCommand.QueryCommandFlag flag, byte[] guidingValues, byte[] frameInfoValues, bool expectedAutoGuiderActive, byte frameIndex, int positionX, int positionY, short distanceRA, short distanceDec) { var expectedFrameInfo = frameIndex != 0 ? new FrameInfo(frameIndex, positionX, positionY, distanceRA, distanceDec) : null; SetupWrite(ftdiMock, new byte[] { 0xca }, new byte[] { 0x10 }, new byte[] { (byte)flag }); if (guidingValues != null && frameInfoValues != null) { SetupRead(ftdiMock, new byte[] { 0xca }, new byte[] { 0x00 }, guidingValues, frameInfoValues); } else if (guidingValues != null) { SetupRead(ftdiMock, new byte[] { 0xca }, new byte[] { 0x00 }, guidingValues); } else if (frameInfoValues != null) { SetupRead(ftdiMock, new byte[] { 0xca }, new byte[] { 0x00 }, frameInfoValues); } else { SetupRead(ftdiMock, new byte[] { 0xca }, new byte[] { 0x00 }); } var sut = new QueryCommand(flag); var result = sut.Execute(ftdiMock.Object); result.Success.Should().BeTrue(); result.AutoGuiderActive.Should().Be(expectedAutoGuiderActive); result.FrameInfo.Should().BeEquivalentTo(expectedFrameInfo); }
public string Dispatch(string[] data) { var command = data[0].ToLower(); data = data.Skip(1).ToArray(); var result = string.Empty; switch (command) { case "query": var queryCommand = new QueryCommand(data); result = queryCommand.Execute(); break; case "clear": case "cls": Console.Clear(); break; case "exit": new ExitCommand().Execute(); break; default: throw new ArgumentException("Invalid command!"); } return(result); }
public PageControlCmd() { InitializeComponent(); this.Loaded += delegate { //上一页 this.btnPrev.Click += new RoutedEventHandler(btnPrev_Click); //下一页 this.btnNext.Click += new RoutedEventHandler(btnNext_Click); //跳转 this.btnGo.Click += new RoutedEventHandler(btnGo_Click); QueryCommand.Execute(1); }; if (Pagination == null) { Pagination = new Pagination(); } //监听Pagination DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(PaginationProperty, typeof(PageControlCmd)); dpd?.AddValueChanged(this, delegate { if (Pagination != null) { ShowPages(Pagination.Total, Pagination.Current, Pagination.Size); } }); }
public void Exception_Test(byte errorCode, Type ex) { SetupWrite(ftdiMock, new byte[] { 0xca }, new byte[] { 0x10 }); SetupRead(ftdiMock, new byte[] { 0xca }, new byte[] { errorCode }); var sut = new QueryCommand(QueryCommand.QueryCommandFlag.None); Action act = () => sut.Execute(ftdiMock.Object); TestDelegate test = new TestDelegate(act); MethodInfo method = typeof(Assert).GetMethod("Throws", new[] { typeof(TestDelegate) }); MethodInfo generic = method.MakeGenericMethod(ex); generic.Invoke(this, new object[] { test }); }
private void ParseCommand(string line) { if (string.IsNullOrEmpty(line)) { return; } //NOTE: Parse in ascending length order! if (line.Substring(0, 1).Equals("#")) { return; } if (line.Length < 4) { Warn("invalid command: {0}", line); return; } if (line.Substring(0, 4).ToLower().Equals("quit") || line.Substring(0, 4).ToLower().Equals("exit")) { return; } var idx = line.IndexOf(' '); string cmd; if (idx < 0) { idx = 0; cmd = line; } else { cmd = line.Substring(0, idx).ToLower(); } var args = idx == 0 ? string.Empty : line.Substring(idx + 1).Trim(); if (CR.abort.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new AbortCommand(); c.Execute(context); StopTimer(CR.abort + " " + args); return; } if (CR.addalias.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new AddAliasCommand(); c.Execute(context, args); StopTimer(CR.addalias + " " + args); return; } if (CR.addindex.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new AddIndexCommand(); c.Execute(context, args); StopTimer(CR.addindex + " " + args); return; } if (CR.close.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new CloseCommand(); c.Execute(context, args); StopTimer(CR.close + " " + args); return; } if (CR.commit.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new CommitCommand(); c.Execute(context, args); StopTimer(CR.commit + " " + args); return; } if (CR.compactcontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new CompactContainerCommand(); c.Execute(context, args); StopTimer(CR.compactcontainer + " " + args); return; } if (CR.contextquery.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new ContextQueryCommand(); c.Execute(context, args); StopTimer(CR.contextquery + " " + args); return; } if (CR.cquery.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new CQueryCommand(); c.Execute(context, args); StopTimer(CR.cquery + " " + args); return; } if (CR.createcontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new CreateContainerCommand(); c.Execute(context, args); StopTimer(CR.createcontainer + " " + args); return; } if (CR.delindex.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new DeleteIndexCommand(); c.Execute(context, args); StopTimer(CR.delindex + " " + args); return; } if (CR.echo.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { Msg(args); return; } if (CR.getdocuments.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new GetDocumentsCommand(); c.Execute(context, args); StopTimer(CR.getdocuments + " " + args); return; } if (CR.getmetadata.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new GetMetadataCommand(); c.Execute(context, args); StopTimer(CR.getmetadata + " " + args); return; } if (CR.help.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { var c = new HelpCommand(); c.Execute(args); return; } if (CR.info.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new InfoCommand(); c.Execute(context, args); StopTimer(CR.info + " " + args); return; } if (CR.listindexes.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new ListIndexesCommand(); c.Execute(context, args); StopTimer(CR.listindexes + " " + args); return; } if (CR.lookupedgeindex.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new LookupEdgeIndexCommand(); c.Execute(context, args); StopTimer(CR.lookupedgeindex + " " + args); return; } if (CR.lookupindex.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new LookupIndexCommand(); c.Execute(context, args); StopTimer(CR.lookupindex + " " + args); return; } if (CR.lookupstats.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new LookupStatisticsCommand(); c.Execute(context, args); StopTimer(CR.lookupstats + " " + args); return; } if (CR.opencontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new OpenContainerCommand(); c.Execute(context, args); StopTimer(CR.opencontainer + " " + args); return; } if (CR.preload.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new PreloadCommand(); c.Execute(context, args); StopTimer(CR.preload + " " + args); return; } if (CR.prepare.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new PrepareCommand(); c.Execute(context, args); StopTimer(CR.prepare + " " + args); return; } if (CR.print.IndexOf(cmd, 0, StringComparison.Ordinal) == 0 || cmd.ToLower().Equals("printnames")) { StartTimer(); var c = new PrintCommand(); c.Execute(context, cmd.Equals("printnames") ? "printnames " + args : args); StopTimer(cmd.Equals("printnames") ? "printNames" : CR.print); return; } if (CR.putdocuments.Equals(cmd)) { StartTimer(); var c = new PutDocumentsCommand(); c.Execute(context, args); StopTimer(CR.putdocuments + " " + args); return; } if (CR.putdocument.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new PutDocumentCommand(); c.Execute(context, args); StopTimer(CR.putdocument + " " + args); return; } if (CR.query.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new QueryCommand(); c.Execute(context, args); StopTimer(CR.query + " " + args); return; } if (CR.queryplan.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new QueryPlanCommand(); c.Execute(context, args); StopTimer(CR.queryplan + " " + args); return; } if (CR.reindexcontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new ReindexContainerCommand(); c.Execute(context, args); StopTimer(CR.reindexcontainer + " " + args); return; } if (CR.removealias.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new RemoveAliasCommand(); c.Execute(context, args); StopTimer(CR.removealias + " " + args); return; } if (CR.removecontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new RemoveContainerCommand(); c.Execute(context, args); StopTimer(CR.removecontainer + " " + args); return; } if (CR.removedocument.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new RemoveDocumentCommand(); c.Execute(context, args); StopTimer(CR.removedocument + " " + args); return; } if (CR.run.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { var c = new RunCommand(); c.Execute(context, args); var l2 = new List <string>(originalArgs) { "-s", c.Script }; StartTimer(); Main(l2.ToArray()); StopTimer(CR.run + " " + args); return; } if (CR.setautoindexing.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new SetAutoIndexingCommand(); c.Execute(context, args); StopTimer(CR.setautoindexing + " " + args); return; } if (CR.setbaseuri.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new SetBaseUriCommand(); c.Execute(context, args); StopTimer(CR.setbaseuri + " " + args); return; } if (CR.setignore.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { var c = new SetIgnoreCommand(); c.Execute(context, args); ignoreErrors = c.Ignore; return; } if (CR.setlazy.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new SetLazyCommand(); c.Execute(context, args); StopTimer(CR.setlazy + " " + args); return; } if (CR.setmetadata.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new SetMetadataCommand(); c.Execute(context, args); StopTimer(CR.setmetadata + " " + args); return; } if (CR.setnamespace.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new SetNamespaceCommand(); c.Execute(context, args); StopTimer(CR.setnamespace + " " + args); return; } if (CR.setprojection.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new SetProjectionCommand(); c.Execute(context, args); StopTimer(CR.setprojection + " " + args); return; } if (CR.setquerytimeout.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new SetQueryTimeoutCommand(); c.Execute(context, args); StopTimer(CR.setquerytimeout + " " + args); return; } if (CR.setvariable.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new SetVariableCommand(); c.Execute(context, args); StopTimer(CR.setvariable + " " + args); return; } if (CR.setverbose.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new SetVerboseCommand(); c.Execute(context, args); StopTimer(CR.setverbose + " " + args); return; } if (CR.sync.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); context.Sync(); StopTimer(CR.sync + " " + args); return; } if (CR.time.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { time = true; ParseCommand(args); return; } if (CR.transaction.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new TransactionCommand(); c.Execute(context, args); StopTimer(CR.transaction + " " + args); return; } if (CR.upgradecontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0) { StartTimer(); var c = new UpgradeContainerCommand(); c.Execute(context, args); StopTimer(CR.upgradecontainer + " " + args); return; } Warn("Command not recognized: {0}", cmd); }
private void InitCommand() { PrintConfigurationSaveBaseCommand = new DelegateCommand((obj) => { string msg = PrintHelper.VerifyPrintConfiguration(PrintConfiguration); if (string.IsNullOrEmpty(msg)) { int id = CommonService.SaveBarTenderPrintConfigXX(PrintConfiguration); if (id > 0) { PrintConfiguration.Id = id; MessageBox.Show("保存成功"); } else { MessageBox.Show("保存失败,请联系管理员"); } } else { MessageBox.Show(msg); } }); TemplateSelectBaseCommand = new DelegateCommand((obj) => { System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog(); if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { PirntTemplates = PrintHelper.GetTenderPrintA4Templates(fbd.SelectedPath); } }); DirectorySelectBaseCommand = new DelegateCommand((obj) => { // 导出目录选择 System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog(); if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { HostConfig.HostValue = fbd.SelectedPath; var result = CommonService.SaveHostConfig(HostConfig); if (result) { HostConfig = CommonService.GetHostConfig(DataGridId, HostName, User.ID); } } }); ExportBaseCommand = new DelegateCommand((obj) => { if (Directory.Exists(HostConfig.HostValue)) { ExportView view = new ExportView(DataGridId, 1); (view.DataContext as ExportViewModel).Export((type, outputEntity, checkBoxValue, orderedColumns) => { view.Close(); if (type == 1) { DataTable datatable = new DataTable(); if (outputEntity == 1) { datatable = _service.GetExportData1("DGPrintA4", User.ID, CommonService.GetSqlWhereString(QueryParameter)); ExportHelper.ExportDataTableToExcel(datatable, HostConfig.HostValue, HostConfig.TypeDesciption + CommonService.GetQueryParameterValueString(QueryParameter)); MessageBox.Show("导出成功"); } //else if (outputEntity == 2) //{ // datatable = _shippingService.GetShippingBillExprotDataTable2(UserDataId); // new Helper.DataTableImportExportHelper().ExportDataTableToExcel(datatable, HostConfig.HostValue, HostConfig.TypeDesciption); // MessageBox.Show("导出成功"); //} //else if (outputEntity == 3) //{ // datatable = _shippingService.GetShippingBillExprotDataTable3(UserDataId, string.Join(",", orderedColumns)); // new Helper.DataTableImportExportHelper().ExportDataTableToExcel(datatable, HostConfig.HostValue, HostConfig.TypeDesciption, checkBoxValue, 1, orderedColumns); // MessageBox.Show("导出成功"); //} } }); view.ShowDialog(); } else { MessageBox.Show("目录不存在,请先选择导出的目录"); DirectorySelectBaseCommand.Execute(null); } CommonService.WriteActionLog(new ActionOperationLogModel { ActionName = "ExportBaseCommand", ActionDesc = HostConfig.TypeDesciption + HostConfig.TypeId.ToString(), UserId = User.ID, MainMenuId = Menu.ID, PKId = -1, HostName = HostName }); }); DataGridSaveCommand = new DelegateCommand((obj) => { DataGridManagementService.SaveColumnConfigurationInUserInterface(obj as DataGrid, User.ID); MessageBox.Show("参数保存成功"); }); PrintBaseCommand = new DelegateCommand((obj) => { string msg = PrintHelper.VerifyPrintConfiguration(PrintConfiguration); if (string.IsNullOrEmpty(msg)) { var selectedLists = ((obj as DataGrid).SelectedItems).Cast <LabelPrintHistoryModel>().ToList(); if (selectedLists.Count > 0) { string result = _print.BarTenderPrintA4(selectedLists, PrintConfiguration, selectedLists.Sum(x => x.PrintCount)); MessageBox.Show(result); QueryCommand.Execute(null); } else { MessageBox.Show("先选择行数据,【CTRL】或【SHFIT】 多选行"); } } else { MessageBox.Show(msg); } }); QueryCommand = new DelegateCommand((obj) => { PrintHistoryLists.Clear(); _service.GetHistoryLists(CommonService.GetSqlWhereString(QueryParameter)).ForEach(x => PrintHistoryLists.Add(x)); }); DataGridManageCommand = new DelegateCommand((obj) => { var grid = obj as DataGrid; UserDataGridFormatConfigurationView view = new UserDataGridFormatConfigurationView("DGPrintA4"); (view.DataContext as UserDataGridFormatConfigurationViewModel).WithParam(null, (type, outputEntity) => { view.Close(); if (type == 1) { // 重新加载DataGrid格式 grid.Columns.Clear(); CommonService.GetUserDataGridColumn(User.ID, grid, 0); } }); view.ShowDialog(); }); }
private void InitCommand() { SaveCommand = new DelegateCommand((obj) => { CommonService.LoadIEnumerableToDatabase(DataGridLists, "SJDataGridColumnHeaderTemplate"); // 修改后台数据 if (_service.BatchUpdate()) { QueryCommand.Execute(null); } }); NewCommand = new DelegateCommand((obj) => { DataGridColumnHeaderModel inputEntity = DataGridSelectedItem == null? new DataGridColumnHeaderModel { MainMenuId = Menu.ID, ColumnOrder = 1000, ColumnWidth = 120 } : ObjectDeepCopyHelper <DataGridColumnHeaderModel, DataGridColumnHeaderModel> .Trans(DataGridSelectedItem); inputEntity.ColumnOrder++; DataGridColumnAddWindow view = new DataGridColumnAddWindow(); (view.DataContext as DataGridColumnAddViewModel).WithParam(inputEntity, (type, outputEntity) => { view.Close(); if (type == 1) { if (_service.Insert(outputEntity)) { QueryCommand.Execute(null); } } }); view.ShowDialog(); }); MoveUpCommand = new DelegateCommand((obj) => { var cloneData = ObjectDeepCopyHelper <DataGridColumnHeaderModel, DataGridColumnHeaderModel> .Trans(DataGridSelectedItem); int index = DataGridLists.IndexOf(DataGridSelectedItem); if (index == 0) { return; } int upOrder = DataGridLists.ElementAt(index - 1).ColumnOrder; int currentOrder = DataGridSelectedItem.ColumnOrder; cloneData.ColumnOrder = upOrder; DataGridLists.ElementAt(index - 1).ColumnOrder = currentOrder; DataGridLists.RemoveAt(index); index--; DataGridLists.Insert(index, cloneData); DataGridSelectedItem = cloneData; }); MoveDownCommand = new DelegateCommand((obj) => { var cloneData = ObjectDeepCopyHelper <DataGridColumnHeaderModel, DataGridColumnHeaderModel> .Trans(DataGridSelectedItem); int index = DataGridLists.IndexOf(DataGridSelectedItem); if (index == DataGridLists.Count - 1) { return; } int downOrder = DataGridLists.ElementAt(index + 1).ColumnOrder; int currentOrder = DataGridSelectedItem.ColumnOrder; cloneData.ColumnOrder = downOrder; DataGridLists.ElementAt(index + 1).ColumnOrder = currentOrder; DataGridLists.RemoveAt(index); index++; DataGridLists.Insert(index, cloneData); DataGridSelectedItem = cloneData; }); QueryCommand = new DelegateCommand((obj) => { DataGridLists.Clear(); _service.GetDataGridLists(CommonService.GetSqlWhereString(QueryParameter)).ForEach(x => DataGridLists.Add(x)); }); }