You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

115 lines
3.7 KiB

using PCScreenSavers.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WebSocket4Net;
namespace PCScreenSavers.Win
{
/// <summary>
/// RichAD.xaml 的交互逻辑
/// </summary>
public partial class RichAD : UserControl
{
Class_Log log = new Class_Log();
App app = ((App)Application.Current);
private string shopCode = string.Empty;
public RichAD(double width, int height, string logo, string name, string floor, double angle,string code)
{
InitializeComponent();
try
{
//this.Width = width;
//WinRect.Rect = new Rect(0, 0, width - 80, 170);
this.TxtName.Text = name;
//if (!string.IsNullOrEmpty(floor))
//{
// TxtDistance.Text = floor;
// TxtDistance.Visibility = Visibility.Visible;
// TxtPoint.Visibility = Visibility.Visible;
// imgPoint.Visibility = Visibility.Hidden;
// ImgRotate.Angle = 0;
//}
//else {
// TxtDistance.Visibility = Visibility.Hidden;
// TxtPoint.Visibility = Visibility.Hidden;
// imgPoint.Visibility = Visibility.Visible;
// ImgRotate.Angle = angle;
//}
logo = string.Format("http://{0}{1}", app.HttpUrl, logo);
logo=logo.Replace("\\","/").Replace(@"\",@"/");
Uri uri = new Uri(logo, UriKind.Absolute);
this.ImgLogo.Source = BitmapFrame.Create(uri);
shopCode = code;
}
catch (Exception e)
{
log.WriteLogFile(e.ToString(), "RichAD");
}
}
public static byte[] GetImageFromResponse(string url, string cookie = null)
{
redo:
try
{
System.Net.WebRequest request = System.Net.WebRequest.Create(url);
if (!string.IsNullOrWhiteSpace(cookie))
{
request.Headers[System.Net.HttpRequestHeader.Cookie] = cookie;
}
System.Net.WebResponse response = request.GetResponse();
using (Stream stream = response.GetResponseStream())
{
using (MemoryStream ms = new MemoryStream())
{
Byte[] buffer = new Byte[1024];
int current = 0;
do
{
ms.Write(buffer, 0, current);
} while ((current = stream.Read(buffer, 0, buffer.Length)) != 0);
return ms.ToArray();
}
}
}
catch (System.Net.WebException ex)
{
if (ex.Message == "基础连接已经关闭: 发送时发生错误。")
{
goto redo;
}
else
{
throw;
}
}
}
private void Image_MouseDown(object sender, MouseButtonEventArgs e)
{
if (app.websocket != null && app.websocket.State == WebSocketState.Open) {
app.websocket.Send("导航"+shopCode);
}
}
}
}