@ -116,36 +116,36 @@ namespace DevicesService.Common
{
try
{
if ( text . Contains ( "http:" ) )
{
DateTime dateTime = DateTime . Now ;
string time = DateTime . Now . ToString (
"yyyyMMddHHmmss" , DateTimeFormatInfo . InvariantInfo ) ;
var dirpath = Path . Combine ( Environment . CurrentDirectory , "wwwroot" , "TempFile" ) ;
FileExt . MakeSureDirExist ( dirpath ) ;
var filepath = Path . Combine ( dirpath , time ) ;
string path = dirpath + "\\" + time + ".txt" ;
WebRequest request = WebRequest . Create ( text ) ;
WebResponse response = request . GetResponse ( ) ;
using ( Stream stream = response . GetResponseStream ( ) )
{
using ( FileStream fileStream = new FileStream ( path , FileMode . Create ) )
{
stream . CopyTo ( fileStream ) ;
}
}
response . Close ( ) ;
using ( StreamReader sr = new StreamReader ( path ) )
{
text = string . Empty ;
string line ;
while ( ( line = sr . ReadLine ( ) ) ! = null )
{
// 处理每一行数据
text = text + line ;
}
}
}
//if (text.Contains("http:") )
// {
// DateTime dateTime = DateTime.Now ;
// string time = DateTime.Now.ToString (
// "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo) ;
// var dirpath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "TempFile") ;
// FileExt.MakeSureDirExist(dirpath) ;
// var filepath = Path.Combine(dirpath, time) ;
// string path = dirpath + "\\" + time + ".txt" ;
// WebRequest request = WebRequest.Create(text) ;
// WebResponse response = request.GetResponse() ;
// using (Stream stream = response.GetResponseStream() )
// {
// using (FileStream fileStream = new FileStream(path, FileMode.Create) )
// {
// stream.CopyTo(fileStream) ;
// }
// }
// response.Close() ;
// using (StreamReader sr = new StreamReader(path) )
// {
// text = string.Empty ;
// string line ;
// while ((line = sr.ReadLine()) != null )
// {
// // 处理每一行数据
// text = text + line ;
// }
// }
// }
Task . Run ( ( ) = >
{
text = text . Replace ( "(" , "" ) . Replace ( ")" , "、" ) ;
@ -201,45 +201,47 @@ namespace DevicesService.Common
string data = hScamera . openCamera2 ( ) ;
if ( ! string . IsNullOrEmpty ( data ) )
{
//string base64 = Util.ImgToBase64String(data) ;
Task . Run ( async ( ) = >
{
UploadInfoByFile ( url , data ) ;
} ) ;
@event5 . WaitOne ( ) ;
Regex re = new Regex ( @"(((?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:ww w.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#? (?:[\w]*))?)" ) ;
MatchCollection mc = re . Matches ( url ) ; //获取的是一个数组
string imgurl = mc [ 0 ] . ToString ( ) + "://" + mc [ 1 ] . ToString ( ) + urlP ;
return "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"bmp\",\"data\":\"" + imgurl + "\"}" ;
FileInfo fileInfo = new FileInfo ( data ) ;
string newdata = Util . CompressPictures ( fileInfo ) ;
string base64 = Util . ImgToBase64String ( data ) ;
//Task.Run(async () = >
// {
// UploadInfoByFile(url, data) ;
//}) ;
//@event5.WaitOne() ;
//Regex re = new Regex( @"(((?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:ww w.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#? (?:[\w]*))?)");
//MatchCollection mc = re.Matches(url); //获取的是一个数组
//string imgurl = mc[0].ToString() + "://" + mc[1].ToString() + urlP ;
return base64 ;
}
else
{
data = hScamera . openCamera2 ( ) ;
if ( ! string . IsNullOrEmpty ( data ) )
{
// string base64 = Util.ImgToBase64String(data);
Task . Run ( async ( ) = >
{
UploadInfoByFile ( url , data ) ;
} ) ;
@event5 . WaitOne ( ) ;
Regex re = new Regex ( @"(((?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:ww w.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#? (?:[\w]*))?)" ) ;
MatchCollection mc = re . Matches ( url ) ; //获取的是一个数组
string imgurl = mc [ 0 ] . ToString ( ) + "://" + mc [ 1 ] . ToString ( ) + urlP ;
return "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"bmp\",\"data\":\"" + imgurl + "\"}" ;
string base64 = Util . ImgToBase64String ( data ) ;
//Task.Run(async () =>
//{
// UploadInfoByFile(url, data);
//});
//@event5.WaitOne();
//Regex re = new Regex(@"(((?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:ww w.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#? (?:[\w]*))?)");
//MatchCollection mc = re.Matches(url);//获取的是一个数组
//string imgurl = mc[0].ToString() + "://" + mc[1].ToString() + urlP;
return base64 ;
}
else
{
return "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "扫描失败" + "\"}" ;
return Util . str2Base64 ( "400" ) ;
}
}
}
catch ( Exception ex )
{
return "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex . Message + "\"}" ;
Log . Info ( "扫描仪异常:" + ex . Message ) ;
return Util . str2Base64 ( "400" ) ;
}
}
@ -385,24 +387,24 @@ namespace DevicesService.Common
}
Task . Run ( async ( ) = >
{
DateTime dateTime = DateTime . Now ;
string time = DateTime . Now . ToString (
"yyyyMMddHHmmss" , DateTimeFormatInfo . InvariantInfo ) ;
var dirpath = Path . Combine ( Environment . CurrentDirectory , "wwwroot" , "PrintFile" ) ;
FileExt . MakeSureDirExist ( dirpath ) ;
var filepath = Path . Combine ( dirpath , time ) ;
string path = dirpath + "\\" + time + "." + ext ;
WebRequest request = WebRequest . Create ( url ) ;
WebResponse response = request . GetResponse ( ) ;
using ( Stream stream = response . GetResponseStream ( ) )
{
using ( FileStream fileStream = new FileStream ( path , FileMode . Create ) )
{
stream . CopyTo ( fileStream ) ;
}
}
response . Close ( ) ;
Util . Print2 ( path , fPrintDocument . PrinterSettings . PrinterName ) ;
//DateTime dateTime = DateTime.Now ;
//string time = DateTime.Now.ToString (
// "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo) ;
//var dirpath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "PrintFile") ;
//FileExt.MakeSureDirExist(dirpath) ;
//var filepath = Path.Combine(dirpath, time) ;
//string path = dirpath + "\\" + time + "." + ext ;
//WebRequest request = WebRequest.Create(url) ;
//WebResponse response = request.GetResponse() ;
//using (Stream stream = response.GetResponseStream() )
// {
// using (FileStream fileStream = new FileStream(path, FileMode.Create) )
// {
// stream.CopyTo(fileStream) ;
// }
// }
//response.Close() ;
Util . Print2 ( url , fPrintDocument . PrinterSettings . PrinterName ) ;
} ) ;
return "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "打印成功" + "\"}" ;
@ -485,15 +487,15 @@ namespace DevicesService.Common
//结束录音上传文件
if ( ! string . IsNullOrEmpty ( url ) & & ! isopen )
{
Task . Run ( async ( ) = >
{
UploadInfo ( url ) ;
} ) ;
@event2 . WaitOne ( ) ;
Regex re = new Regex ( @"(((?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:ww w.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#? (?:[\w]*))?)" ) ;
MatchCollection mc = re . Matches ( url ) ; //获取的是一个数组
string reurl = mc [ 0 ] . ToString ( ) + "://" + mc [ 1 ] . ToString ( ) + urlpath ;
return "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + reurl + "\"}" ;
//Task.Run(async () = >
// {
// UploadInfo(url) ;
//}) ;
//@event2.WaitOne() ;
//Regex re = new Regex( @"(((?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:ww w.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#? (?:[\w]*))?)");
//MatchCollection mc = re.Matches(url); //获取的是一个数组
//string reurl = mc[0].ToString() + "://" + mc[1].ToString() + urlpath ;
return "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + srpath + "\"}" ;
}
else if ( isopen ) //开始录音
{
@ -532,6 +534,14 @@ namespace DevicesService.Common
if ( player = = null )
{
NewMethod ( url ) ;
if ( player ! = null )
{
return "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "音频播放" + "\"}" ;
}
else
{
return "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"400\",\"status\":false,\"data\":\"" + "未发现播放文件" + "\"}" ;
}
}
else
{
@ -539,6 +549,7 @@ namespace DevicesService.Common
{
player . Play ( ) ;
Log . Info ( "恢复播放" ) ;
return "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "恢复播放" + "\"}" ;
}
else
{
@ -550,6 +561,14 @@ namespace DevicesService.Common
audioFileReader . Dispose ( ) ;
}
NewMethod ( url ) ;
if ( player ! = null )
{
return "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "音频播放" + "\"}" ;
}
else
{
return "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"400\",\"status\":false,\"data\":\"" + "未发现播放文件" + "\"}" ;
}
}
}
}
@ -557,18 +576,29 @@ namespace DevicesService.Common
{
if ( player ! = null )
{
player . Pause ( ) ;
Log . Info ( "暂停播放" ) ;
if ( string . IsNullOrEmpty ( url ) )
{
player . Pause ( ) ;
Log . Info ( "暂停播放" ) ;
return "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "暂停播放" + "\"}" ;
}
else
{
player . Stop ( ) ;
// 释放资源
player . Dispose ( ) ;
audioFileReader . Dispose ( ) ;
player = null ;
File . Delete ( WaveOutPath ) ;
Log . Info ( "停止播放" ) ;
return "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "停止播放" + "\"}" ;
}
}
else
{
return "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"400\",\"status\":false,\"data\":\"" + "未发现播放文件" + "\"}" ;
}
}
if ( player ! = null )
{
return "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "音频播放" + "\"}" ;
}
else
{
return "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"400\",\"status\":false,\"data\":\"" + "未发现播放文件" + "\"}" ;
}
}
catch ( Exception ex )
{
@ -582,28 +612,30 @@ namespace DevicesService.Common
/// <param name="url"></param>
private void NewMethod ( string url )
{
Uri uri = new Uri ( url ) ;
//返回 123.xlsx
var filename = HttpUtility . UrlDecode ( uri . Segments . Last ( ) ) ;
//获取文件后缀
string ext = Path . GetExtension ( filename ) ;
DateTime dateTime = DateTime . Now ;
string time = DateTime . Now . ToString (
"yyyyMMddHHmmss" , DateTimeFormatInfo . InvariantInfo ) ;
var dirpath = Path . Combine ( Environment . CurrentDirectory , "wwwroot" , "WaveOutFile" ) ;
FileExt . MakeSureDirExist ( dirpath ) ;
var filepath = Path . Combine ( dirpath , time ) ;
WaveOutPath = dirpath + "\\" + time + ext ;
WebRequest request = WebRequest . Create ( url ) ;
WebResponse response = request . GetResponse ( ) ;
using ( Stream stream = response . GetResponseStream ( ) )
{
using ( FileStream fileStream = new FileStream ( WaveOutPath , FileMode . Create ) )
{
stream . CopyTo ( fileStream ) ;
}
}
response . Close ( ) ;
//Uri uri = new Uri(url);
////返回 123.xlsx
//var filename = HttpUtility.UrlDecode(uri.Segments.Last());
////获取文件后缀
//string ext = Path.GetExtension(filename);
//DateTime dateTime = DateTime.Now;
//string time = DateTime.Now.ToString(
// "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
//var dirpath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "WaveOutFile");
//FileExt.MakeSureDirExist(dirpath);
//var filepath = Path.Combine(dirpath, time);
//WebRequest request = WebRequest.Create(url);
//WebResponse response = request.GetResponse();
//using (Stream stream = response.GetResponseStream())
//{
// using (FileStream fileStream = new FileStream(WaveOutPath, FileMode.Create))
// {
// stream.CopyTo(fileStream);
// }
//}
//response.Close();
WaveOutPath = url ;
using ( player = new WaveOutEvent ( ) )
{
player . PlaybackStopped + = waveOut_PlaybackStopped ;