/// <summary> /// Connect and disconnect command execute. /// </summary> /// <param name="obj">The obj.</param> private void ConnectDisconnectCommandExecute(object obj) { if (!IsConnected) { try { _hartCommunication.Initialize(_settingsViewModel.SettingsDataModel.ComPort); OpenResult result = _hartCommunication.Open(); switch (result) { case OpenResult.UnknownComPortError: _messageBoxService.ShowError("Unknown COM port error while connecting to device.", "Error"); return; case OpenResult.ComPortNotExisting: _messageBoxService.ShowError("Selected COM port does not exists.", "Error"); return; case OpenResult.ComPortIsOpenAlreadyOpen: _messageBoxService.ShowError("COM port is already opened.", "Error"); return; } _hartCommunication.PreambleLength = Convert.ToInt32(_settingsViewModel.SettingsDataModel.Preamble); _hartCommunication.Receive += ReceiveValueHandle; _hartCommunication.SendingCommand += SendingValueHandle; IsConnected = true; } catch (Exception e) { _messageBoxService.ShowError("Error on connecting to device.\n\n" + e, "Error"); } } else { try { CloseResult result = _hartCommunication.Close(); switch (result) { case CloseResult.PortIsNotOpen: _messageBoxService.ShowError("The port is not open.", "Error"); return; } IsConnected = false; _hartCommunication.Receive -= ReceiveValueHandle; _hartCommunication.SendingCommand -= SendingValueHandle; } catch (Exception e) { _messageBoxService.ShowError("Error on disconnecting from device.\n\n" + e, "Error"); } } }
/// <summary> /// 判断当前期在数据库是否已经存在 /// </summary> /// <param name="issueNo"></param> /// <returns></returns> private static bool Exists(long issueNo, string lotteryCode, string dataSource) { string sql = $"select * from open_result where issue_number = {issueNo} and lottery_code = '{lotteryCode}' and data_source = '{dataSource}'"; OpenResult o = MysqlHelper.GetOne <OpenResult>(sql); return(o != null && o.id > 0); }
public OpenResult Open(GameBoard gameBoard) { OpenResult result = OpenResult.None; if (UserType == CellType.Hesitate || UserType == CellType.Flag) { SetUserType(CellType.Floor); result = OpenResult.OpenMark; } if (UserType == CellType.Floor) { if (BackgroundType != CellType.Mine) { if (RiskLevel > 0) { result = OpenResult.OpenRisk; } else { result = OpenResult.OpenSafe; } SetUserType(BackgroundType); } else { SetBackgroundType(CellType.Bomb); result = OpenResult.Bomb; } } UpdateUserInterface(); return(result); }
private async Task Open(bool selectionOnly) { try { if (this.Actor == null || this.Skeleton == null) { return; } OpenResult result = await FileService.Open <PoseFile, LegacyPoseFile>(); if (result.File == null) { return; } if (result.File is LegacyPoseFile legacyFile) { result.File = legacyFile.Upgrade(this.Actor.Customize?.Race ?? Appearance.Races.Hyur); } if (result.File is PoseFile poseFile) { await poseFile.Apply(this.Actor, this.Skeleton, FileConfig, selectionOnly); } } catch (Exception ex) { Log.Error(ex, "Failed to load pose file"); } }
private async void OnLoadClicked(object sender, RoutedEventArgs e) { try { OpenResult result = await FileService.Open <SceneFile>("Scene"); if (result.File == null) { return; } SceneFile.Configuration config = new SceneFile.Configuration(); ////if (result.UseAdvancedLoad) //// config = await ViewService.ShowDialog<BoneGroupsSelectorDialog, PoseFile.Configuration>("Load Scene..."); if (config == null) { return; } if (result.File is SceneFile sceneFile) { await sceneFile.Apply(config); } } catch (Exception ex) { Log.Write(Severity.Error, ex); } }
public void Usage() { HartCommunicationLite communication = new HartCommunicationLite("COM1") { AutomaticZeroCommand = false }; CommandResult receivedCommandResult = null; AutoResetEvent resetEvent = new AutoResetEvent(false); communication.Receive += (sender, args) => { receivedCommandResult = args; resetEvent.Set(); }; OpenResult openResult = communication.Open(); Assert.That(openResult, Is.EqualTo(OpenResult.Opened)); CommandResult commandResult = communication.SendZeroCommand(); Assert.That(commandResult, Is.Not.Null); Assert.That(commandResult.CommandNumber, Is.EqualTo(0)); Assert.That(commandResult.ResponseCode.FirstByte, Is.EqualTo(0)); Assert.That(resetEvent.WaitOne(TimeSpan.FromSeconds(2)), Is.True); Assert.That(commandResult.Address, Is.EqualTo(receivedCommandResult.Address)); Assert.That(commandResult.CommandNumber, Is.EqualTo(receivedCommandResult.CommandNumber)); Assert.That(commandResult.PreambleLength, Is.EqualTo(receivedCommandResult.PreambleLength)); Assert.That(commandResult.ResponseCode.FirstByte, Is.EqualTo(receivedCommandResult.ResponseCode.FirstByte)); Assert.That(commandResult.ResponseCode.SecondByte, Is.EqualTo(receivedCommandResult.ResponseCode.SecondByte)); communication.Close(); }
private async Task Load() { if (this.Actor == null) { return; } CharacterFileOptions.Result = lastLoadMode; OpenResult result = await FileService.Open <LegacyCharacterFile, DatCharacterFile, CharacterFile>(); if (result.File == null) { return; } lastLoadMode = CharacterFileOptions.Result; if (result.File is LegacyCharacterFile legacyFile) { result.File = legacyFile.Upgrade(); } if (result.File is DatCharacterFile datFile) { result.File = datFile.Upgrade(); } if (result.File is CharacterFile apFile) { await apFile.Apply(this.Actor, lastLoadMode); } }
public void Usage() { HartCommunicationLite communication = new HartCommunicationLite("COM1"); List <CommandResult> commandResults = new List <CommandResult>(); AutoResetEvent resetEvent = new AutoResetEvent(false); communication.Receive += (sender, args) => { commandResults.Add(args); if (args.CommandNumber == 12) { resetEvent.Set(); } }; OpenResult openResult = communication.Open(); Assert.That(openResult, Is.EqualTo(OpenResult.Opened)); communication.SendAsync(12); Assert.That(resetEvent.WaitOne(TimeSpan.FromSeconds(20)), Is.True); Assert.That(commandResults.Count, Is.EqualTo(2)); Assert.That(commandResults[0].CommandNumber, Is.EqualTo(0)); Assert.That(commandResults[0].ResponseCode.FirstByte, Is.EqualTo(0)); Assert.That(commandResults[1].CommandNumber, Is.EqualTo(12)); Assert.That(commandResults[1].ResponseCode.FirstByte, Is.EqualTo(0)); communication.Close(); }
public Open_Business_Customer_Search() { InitializeComponent(); OpenWait.Hide(); OpenResult.Hide(); SetConnectionString(); }
public static OpenResult Open(string path) { TypeWrapper tw; switch (Path.GetExtension(path).ToLower()) { case ".webp": tw = new WebpWrapper(); break; case ".svg": tw = new SvgWrapper(); break; case ".psd": tw = new PsdWrapper(); break; case ".ico": tw = new IcoWrapper(); break; case ".cr2": tw = new Cr2Wrapper(); break; case ".dds": case ".tga": tw = new DdsTgaWrapper(); break; default: tw = new BitmapWrapper(); break; } OpenResult res = tw.Open(path); if (string.IsNullOrEmpty(res.ErrorMessage)) { return new OpenResult { ErrorMessage = null, TypeName = tw.TypeName, Bmp = res.Bmp, ShowTypeOps = tw.ShowTypeOps } } ; else { return new OpenResult { ErrorMessage = res.ErrorMessage, TypeName = tw.TypeName, Bmp = null, ShowTypeOps = false } }; }
public void ConnectResponseResultShouldBeComPortNotExisting() { HartCommunicationLite communication = new HartCommunicationLite("notExisting"); OpenResult openResult = communication.Open(); Assert.That(openResult, Is.EqualTo(OpenResult.ComPortNotExisting)); }
public void TestConnectionOpenAutoCreate() { CreateDatabase(); OpenResult openResult = _database.Open(); Assert.AreEqual(OpenResult.Open, openResult); }
private void CheckExport(BaseScreen model) { Bind(model); Assert.IsTrue(model.CanExport.Value); result = (OpenResult)model.Export(); Assert.That(File.Exists(result.Filename), result.Filename); }
public async void ShouldReturnOpenResultErrorIfPortCannotOpened(OpenResult openResult) { var mock = new Mock <IHartCommunication>(); mock.Setup(item => item.Open()).Returns(openResult); var service = new HartCommunicationService(mock.Object); (await service.OpenAsync()).Should().Be(openResult); }
/// <summary> /// 执行抓取 /// </summary> /// <returns></returns> public List <OpenResult> Pick() { HttpRequestParam param = new HttpRequestParam { Url = this._url }; string errorInfo = string.Empty; string html = HttpHelper.GetHtml(param, ref errorInfo); if (!string.IsNullOrEmpty(errorInfo)) { throw new Exception($"从彩世界采集{this._lotteryType}出错。错误信息:{errorInfo},抓取地址:{this._url}"); } Regex regex = new Regex(@"<table[^><]*class=""history|tbHistory|dataContainer""[^><]*>(?<html>[\S\s]*?</table>", RegexOptions.IgnoreCase); Match match = regex.Match(html); if (!match.Success) { throw new Exception($"从彩世界采集{this._lotteryType}出错。抓取地址:{this._url},源代码:{html}"); } html = match.Groups["html"].Value; regex = new Regex(@"<tr>\s*<td>\s*<i[^><]*class=""font_gray666"">(?<issueNo>[^><]+)</i>\s*<i[^><]*class=""font_gray999"">(?<time>[^><]+)</i>\s*</td>\s*<td>\s*<div[^><]*>(?<num>[\s\S]*?)</div>", RegexOptions.IgnoreCase); MatchCollection matches = regex.Matches(html); if (matches.Count == 0) { throw new Exception($"从彩世界采集{this._lotteryType}出错。抓取地址:{this._url},源代码:{html}"); } List <OpenResult> resultList = new List <OpenResult>(); foreach (Match m in matches) { OpenResult result = new OpenResult { create_time = DateTime.Now, lottery_code = this._lotteryType, data_source = DataSourceEnum.CSJ }; result.issue_number = Convert.ToInt64(m.Groups["issueNo"].Value.Replace("-", "")); result.open_time = Convert.ToDateTime(m.Groups["time"].Value); result.open_data = this.GetOpenData(m.Groups["num"].Value); if (string.IsNullOrEmpty(result.open_data)) { continue; } resultList.Add(result); } return(resultList); }
public void TestConnectionOpen() { CreateResult result = SQLiteDatabase.Create(Constants.databaseFilePath); Assert.AreEqual(CreateResult.Create, result); _database = new SQLiteDatabase(Constants.databaseFilePath); OpenResult openResult = _database.Open(); Assert.AreEqual(OpenResult.Open, openResult); }
public void Usage() { const string PORT_NAME = "COM1"; HartCommunicationLite communication = new HartCommunicationLite(PORT_NAME); OpenResult openResult = communication.Open(); Assert.That(openResult, Is.EqualTo(OpenResult.Opened)); communication.Close(); }
private static OpenAndXResponse CreateResponseForNamedPipe(ushort fileID, OpenResult openResult) { OpenAndXResponse response = new OpenAndXResponse(); response.FID = fileID; response.AccessRights = AccessRights.SMB_DA_ACCESS_READ_WRITE; response.ResourceType = ResourceType.FileTypeMessageModePipe; response.NMPipeStatus.ICount = 255; response.NMPipeStatus.ReadMode = ReadMode.MessageMode; response.NMPipeStatus.NamedPipeType = NamedPipeType.MessageModePipe; response.OpenResults.OpenResult = openResult; return(response); }
private IEnumerable <IResult> ActivateItem(IConductor parent, TItem item) { if (OpenResult.BeforeActivation != null) { yield return(new SequentialResult(OpenResult.BeforeActivation(item).GetEnumerator())); } yield return(new DelegateResult(() => parent.ActivateItem(item))); if (OpenResult.AfterActivation != null) { yield return(new SequentialResult(OpenResult.AfterActivation(item).GetEnumerator())); } }
private async Task Load(bool advanced) { if (this.Actor == null) { return; } OpenResult result = await FileService.Open <LegacyEquipmentSetFile, LegacyCharacterFile, DatCharacterFile, CharacterFile>(); if (result.File == null) { return; } if (result.File is LegacyCharacterFile legacyAllFile) { result.File = legacyAllFile.Upgrade(); } if (result.File is LegacyEquipmentSetFile legacyEquipmentFile) { result.File = legacyEquipmentFile.Upgrade(); } if (result.File is DatCharacterFile datFile) { result.File = datFile.Upgrade(); } if (result.File is CharacterFile apFile) { CharacterFile.SaveModes mode = CharacterFile.SaveModes.All; if (advanced) { CharacterFile.SaveModes newmode = await ViewService.ShowDialog <AppearanceModeSelectorDialog, CharacterFile.SaveModes>("Load Character...", lastLoadMode); if (newmode == CharacterFile.SaveModes.None) { return; } lastLoadMode = newmode; mode = lastLoadMode; } await apFile.Apply(this.Actor, mode); } }
private void Search_Click_1(object sender, EventArgs e) { SetConnectionString(); CountryName = Country.Text; CurrencyCode = Currency.Text; if (CountryName == "") { MessageBox.Show("Please Select Country"); } else if (CurrencyCode == "") { MessageBox.Show("Please Select Currency"); } else { OpenWait.Show(); OpenSearch.Enabled = false; using (SqlConnection conn = new SqlConnection(ConnectionString)) { string CunCode = GetCunCode(CountryName); SqlCommand cmd = new SqlCommand(String.Format(@"select CustomerNumber,S.SalesLocationName,CustomerTypeCode,C.CurrencyCode, CustomerStatusCode,CustomerName, * from customer C join Saleslocation S on C.Saleslocationcode = S.saleslocationcode where C.CustomerStatusCode = 'ACT' and S.SalesLocationCode = '{0}' and C.CustomerNumber like '0005%'", CunCode), conn); conn.Open(); DataTable dt = new DataTable(); SqlDataAdapter adapter = new SqlDataAdapter(cmd); adapter.Fill(dt); OpenWait.Hide(); conn.Close(); OpenResult.Show(); OpenSearch.Enabled = true; OpenResult.DataSource = dt; } } }
public void ConnectResponseResultShouldBeComPortIsAlreadyOpened() { const string PORT_NAME = "COM1"; System.IO.Ports.SerialPort serialPort = new System.IO.Ports.SerialPort(PORT_NAME); serialPort.Open(); HartCommunicationLite communication = new HartCommunicationLite(PORT_NAME); OpenResult openResult = communication.Open(); Assert.That(openResult, Is.EqualTo(OpenResult.ComPortIsOpenAlreadyOpen)); serialPort.Close(); }
public void Export() { var catalog = session.Query <Catalog>().First(c => c.HaveOffers); var model = new CatalogOfferViewModel(catalog); WpfTestHelper.WithWindow2(async w => { var view = Bind(model); w.Content = view; await view.WaitLoaded(); Assert.IsTrue(model.CanExport.Value); result = (OpenResult)model.Export(); Assert.That(File.Exists(result.Filename), result.Filename); }); }
public JsonResult OnPostLoadDirectory([FromBody] OpenAction openAction) { using (SqlConnection connection = new SqlConnection(_connectionString)) { connection.Open(); DataTable dt = new DataTable(); using (SqlCommand command = new SqlCommand("[dbo].[GetDirectoryItems]", connection)) { command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = 300; command.Parameters.Add("@IdDirectory", SqlDbType.Int); command.Parameters["@IdDirectory"].Value = openAction.IdDirectory ?? Convert.DBNull; command.Parameters.Add("@IsSortByName", SqlDbType.Bit); command.Parameters["@IsSortByName"].Value = openAction.IsSortByName; using (SqlDataReader dataReader = command.ExecuteReader()) { dt.Load(dataReader); } } connection.Close(); OpenResult result = new OpenResult(); for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i].Field <int?>("Id_Directory").HasValue) { Directory dir = new Directory(dt.Rows[i].Field <int>("Id_Directory")); dir.Name = dt.Rows[i].Field <string>("Name"); dir.HasSubItems = dt.Rows[i].Field <bool>("HasSubItems"); result.Directories.Add(dir); } else { File file = new File(dt.Rows[i].Field <int>("Id_File")); file.Name = dt.Rows[i].Field <string>("Name"); file.Size = dt.Rows[i].Field <long>("Size"); result.Files.Add(file); } } return(new JsonResult(JsonConvert.SerializeObject(result))); } }
static void Main(string[] args) { UnRAR.RAROpenArchiveDataEx openData = new UnRAR.RAROpenArchiveDataEx { ArcName = null, ArcNameW = @"C:\Users\shoa\Desktop\nopassword.rar", OpenMode = (uint)OpenMode.RAR_OM_EXTRACT, Callback = CrackPassword, UserData = Marshal.StringToHGlobalUni("123") }; var handle = RAROpenArchiveEx(ref openData); OpenResult result = (OpenResult)RARProcessFileW(handle, (int)Operation.RAR_EXTRACT, null, null); Console.ReadKey(); }
private void createNewFile_Click(object sender, EventArgs e) { FolderBrowserDialog folder = new FolderBrowserDialog(); folder.Description = "Please locate the directory where the database file should go."; //folder.RootFolder = Directory.(Application.ExecutablePath); folder.ShowNewFolderButton = true; if (folder.ShowDialog() == DialogResult.Cancel) { return; } Result = OpenResult.Create; FileDir = folder.SelectedPath; this.Close(); }
public void WriteAssemblyNumber() { HartCommunicationLite communication = new HartCommunicationLite("COM1"); OpenResult openResult = communication.Open(); Assert.That(openResult, Is.EqualTo(OpenResult.Opened)); CommandResult commandResult = communication.Send(19, new byte[] { 1, 2, 3 }); Assert.That(commandResult, Is.Not.Null); Assert.That(commandResult.CommandNumber, Is.EqualTo(19)); Assert.That(commandResult.Data, Is.EqualTo(new byte[] { 1, 2, 3 })); Assert.That(commandResult.ResponseCode.FirstByte, Is.EqualTo(0)); communication.Close(); }
public async void ShouldShowMessageIfNotOpenedIsReceived(OpenResult openResult) { var messageBoxService = new TestMessageBoxService(); var hartCommunicationService = new TestHartCommunicationService(); hartCommunicationService.OpenAsyncResponders.Enqueue(() => openResult); var viewModel = new RibbonViewModel(new ApplicationServices { HartCommunicationService = hartCommunicationService }, new CommonServices { MessageBoxService = messageBoxService }); await viewModel.ConnectionCommand.Execute(null); messageBoxService.ShowInformationRequests.Count.Should().Be(1); messageBoxService.ShowInformationRequests[0].Message.Should().NotBeNullOrEmpty(); }
public void ShouldReturnNullIfNoZeroCommandSend() { HartCommunicationLite communication = new HartCommunicationLite("COM1") { AutomaticZeroCommand = false }; OpenResult openResult = communication.Open(); Assert.That(openResult, Is.EqualTo(OpenResult.Opened)); CommandResult commandResult = communication.Send(12); Assert.That(commandResult, Is.Null); communication.Close(); }
public void Usage() { HartCommunicationLite communication = new HartCommunicationLite("COM1") { AutomaticZeroCommand = false }; OpenResult openResult = communication.Open(); Assert.That(openResult, Is.EqualTo(OpenResult.Opened)); CommandResult command = communication.SendZeroCommand(); Assert.That(command, Is.Not.Null); Assert.That(command.CommandNumber, Is.EqualTo(0)); Assert.That(command.ResponseCode.FirstByte, Is.EqualTo(0)); communication.Close(); }