public List <string> SendFile() { var filelst = System.IO.Directory.GetFiles(Properties.Settings.Default.SendDirectoryPath); var sendlst = new List <string>(); foreach (var filename in filelst) { try { var file = new System.IO.FileInfo(filename); var filedata = System.IO.File.ReadAllBytes(filename); this.WriteArchiveFile("send", filename); System.IO.File.Delete(filename); var send = new BluetoothApplicationTransferData(file.Name, filedata); this.SendFileQueue.Enqueue(send); sendlst.Add(file.Name); } catch (Exception ex) { this.Logger.Error(ex, "送信ファイル読み込み失敗。{0}", filename); } } return(sendlst); }
private void RunReceive() { this.Logger.Info("データ受信処理開始"); while (this.AcceptingFlag) { try { //受信データ長 var loadop = SocketReader.LoadAsync(sizeof(uint)); while (loadop.Status != Windows.Foundation.AsyncStatus.Completed) { System.Threading.Thread.Sleep(500); if (!this.AcceptingFlag) { break; } } if (!this.AcceptingFlag) { break; } uint size = loadop.GetResults(); if (size < sizeof(uint)) { break; } uint recvsize = SocketReader.ReadUInt32(); //ファイル名のデータ loadop = SocketReader.LoadAsync(recvsize); while (loadop.Status != Windows.Foundation.AsyncStatus.Completed) { System.Threading.Thread.Sleep(500); if (!this.AcceptingFlag) { break; } } if (!this.AcceptingFlag) { break; } size = loadop.GetResults(); if (size != recvsize) { break; } byte[] recvdata = new byte[recvsize]; SocketReader.ReadBytes(recvdata); var recv = new BluetoothApplicationTransferData(recvdata); this.Logger.Info("データ受信結果:{0},{1}", recv.Name, recv.Data.Length); this.ReceiveFileQueue.Enqueue(recv); } catch (Exception ex) { this.Logger.Error(ex, "データ通信中にエラー発生!"); break; } } this.AcceptingFlag = false; this.ConnectStatusChanged?.Invoke(this, new AsyncCompletedEventArgs(null, false, BluetoothApplicationConnectStatus.Disconnect)); }