// Server端用來定時到指定資料夾去辨識是否有指定名稱的文件(經藍牙傳輸的檔案), 並檢查檔案的正確性 private void BluetoothOBEXTimer_Tick(object sender, EventArgs e) { string path = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal); // 回傳系統預設的"我的文件"資料夾路徑 string filename = "WinmateBluetoothTest.txt"; string sourceFile = path + Path.DirectorySeparatorChar + filename; if (File.Exists(sourceFile) == true) { BluetoothOBEXTimer.Stop(); Boolean fileChecksum = CompareFile(sourceFile); if (fileChecksum) { txtCompareFileResult.ForeColor = Color.Green; txtCompareFileResult.Text = "Pass!"; DialogResult fileTransferResult = MessageBox.Show("Bluetooth file transfer the same content, Pass.", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Information); if (fileTransferResult == DialogResult.OK) { BluetoothOBEXTimer.Start(); } } else { txtCompareFileResult.ForeColor = Color.Red; txtCompareFileResult.Text = "Fail!"; DialogResult fileTransferResult = MessageBox.Show("Bluetooth file content is not the same, Fail.", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Error); if (fileTransferResult == DialogResult.OK) { BluetoothOBEXTimer.Start(); } } System.IO.File.Delete(sourceFile); } else { txtCompareFileResult.ForeColor = Color.Blue; txtCompareFileResult.Text = "Not Result"; } }
private void bluetooth_Load(object sender, EventArgs e) { result["result"] = "FAIL"; var jsonconfig = GetFullPath("config.json"); if (!File.Exists(jsonconfig)) { MessageBox.Show("config.json not founded"); Exit(); } dynamic jobject = JObject.Parse(File.ReadAllText(jsonconfig)); ShowWindow = (bool)jobject.ShowWindow; if (ShowWindow) { this.Opacity = 100; this.ShowInTaskbar = true; } if (IsDebugMode) { Trace.WriteLine("BT_Load"); } #region Prepare Bluetooth ComboBoxServices.Items.AddRange(new object[] { "SerialPort", "Handsfree", "HumanInterfaceDevice", "SDP Protocol", "DialupNetworking" }); // 藍芽連線用以配對的Service類型 ComboBoxServices.SelectedIndex = 1; // Service類型預設為SerialPort TextBoxPin.Enabled = CheckBoxUsePin.Checked; // 如果UsePin被勾選就要讓試用者能輸入PinCode txtBTDeviceDetails.Text = ""; // 用以顯示藍芽連線時的各種資訊 mBackgroundWorker_FindDevice = new BackgroundWorker(); mBackgroundWorker_FindDevice.WorkerSupportsCancellation = true; mBackgroundWorker_FindDevice.WorkerReportsProgress = true; mBackgroundWorker_FindDevice.DoWork += new DoWorkEventHandler(FindBluetoothDevice_DoWork); mBackgroundWorker_FindDevice.RunWorkerCompleted += new RunWorkerCompletedEventHandler(FindBluetoothDevice_RunWorkerCompleted); #endregion #region 可選測試清單(檔案傳輸/音樂播放) // 當要進行藍牙音樂播放測試的時候, 才會將音樂播放測試清單顯示 if (EnablePlayAudio) { groupBoxBluetoothPair.Visible = true; } else if (EnableFileTransfer) // 當要進行藍牙檔案測試的時候, 才會將藍牙檔案測試清單顯示 { groupBTDeviceConnection.Visible = true; // 這個Timer主要提供給測試Server作為分辨藍牙傳輸後檔案的正確性(因為不知道何時會有藍牙傳輸, 所以必須定時檢查指定資料夾有沒有檔案進來) BluetoothOBEXTimer.Interval = 3000; BluetoothOBEXTimer.Start(); } #endregion if (!mBackgroundWorker_FindDevice.IsBusy) { buttonFindBluetoothDevice.PerformClick(); // mBackgroundWorker_FindDevice.RunWorkerAsync(); } else { MessageBox.Show("Searching for Bluetooth devices...Please Wait", "Attention"); } }