public async void connect() { SettingsManagement.PersistConnectionData( this.toolStripTextBoxServer.Text, this.toolStripTextBoxCertificat.Text); var uri = new Uri( string.Format( "https://{0}:{1}/", SettingsManagement.GetHostName(), SettingsManagement.GetServicePort())); formatting = new FormattingServiceWrapper(); try { // path to service certificate (located in program folder) var serverCertPath = @"C:\CERTIFICAT\Format.Service_server.cer"; var svcConfig = new FormattingServiceConfig( uri, serverCertPath, SettingsManagement.GetClientCertificate()); formatting.Initialize(svcConfig); // get version, for testing this.SwitchWaiting(true); string version = await formatting.GetVersionAsync(); this.SwitchOnline(true, version); recupFormats(); } catch (Exception ex) { this.HandleFailure(ex); } finally { this.SwitchWaiting(false); } }
private async void btnGetData_Click(object sender, EventArgs e) { switch (cBxFormats.SelectedIndex) { case 0: format = "42ff4ea439524aa28ea0e61364c2704b"; MessageBox.Show("premier format"); break; case 1: format = "a9cb28e0 - 70ed - 4b64 - b9bc - 200f45d65eb6"; break; case 2: format = "af7d107b - 4e05 - 49b3 - bb06 - d0817356bbc7"; break; case 3: format = "fcda2570 - 60db - 40fe - a7a3 - fd3b0b9f5b1d"; break; case 4: format = "acfc6fd2 - 37e3 - 41a2 - 81be - c69ffa8be1cf"; break; default: break; } this.SetProcessing(true); formatting = new FormattingServiceWrapper(); try { // try to parse UID ulong uid; if (!ulong.TryParse(this.txBxID.Text, out uid)) { this.tBxResult.Text = "Invalid UID value supplied."; return; } // try to parse FormatTypeId Guid formatTypeId; if (!Guid.TryParse(format, out formatTypeId)) { this.tBxResult.Text = "Invalid UUID value supplied for format type ID."; return; } // synchronous call: var formattedData = this.formatting.Service.GetSingleUidData(); var formattedData = await formatting.GetSingleUidDataAsync(uid, formatTypeId); StringBuilder sb = new StringBuilder(); sb.AppendLine("Formatted data:"); sb.AppendLine(); sb.Append("UID (dec): "); sb.AppendLine(formattedData.Uid.ToString()); if (formattedData.Dsf.HasValue) { sb.Append("DSF (dec): "); sb.AppendLine(formattedData.Dsf.Value.ToString()); } sb.AppendLine(); string[] BlockDataToWrite = new string[formattedData.Blocks.Length]; foreach (var blockData in formattedData.Blocks) { BlockDataToWrite[blockData.BlockNumber] = blockData.BlockValue; sb.Append("Block #"); sb.Append(blockData.BlockNumber); sb.Append(": "); sb.AppendLine(blockData.BlockValue); } this.tBxResult.Text = sb.ToString(); } catch (Exception ex) { this.tBxResult.Text = string.Format( "Error:{1}{1}{0}", ex.Message, Environment.NewLine); } this.SetProcessing(false); }