17 changed files with 691 additions and 101 deletions
@ -1,3 +1,5 @@ |
|||
/JdShopListener/JdShopListener/obj |
|||
/JdShopListener/JdShopListener/bin |
|||
/JdShopListener/.vs |
|||
/JdShopListener/WpfNoticeMsg/bin |
|||
/JdShopListener/WpfNoticeMsg/obj |
|||
|
@ -0,0 +1,126 @@ |
|||
using JdShopListener.Models; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Net.Http; |
|||
using System.Text; |
|||
using System.Threading; |
|||
using System.Windows; |
|||
|
|||
namespace Utils |
|||
{ |
|||
public class ApiHelper |
|||
{ |
|||
public static string ApiBase { get; set; } = "http://localhost:5000"; |
|||
//public static string ApiBase { get; set; } = "http://hyapi.qiyue666.com";
|
|||
|
|||
|
|||
static string jwtToken; |
|||
|
|||
public static string JwtToken |
|||
{ |
|||
get |
|||
{ |
|||
if (string.IsNullOrEmpty(jwtToken)) |
|||
{ |
|||
jwtToken = Utils.MemoryHelper.GetMemoryToken(); |
|||
} |
|||
|
|||
return jwtToken; |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 获取标签信息
|
|||
/// </summary>
|
|||
/// <param name="ids"></param>
|
|||
/// <param name="platform"></param>
|
|||
/// <returns></returns>
|
|||
public static (bool isOk,List<ItemlabelInfoDto> datas) GetLabelByItemIds(int type=1) |
|||
{ |
|||
try |
|||
{ |
|||
var result = Http($"http://hyapi.qiyue666.com/HuiYan/itemlabels/GetItemsByJpLabels?type={type}"); |
|||
|
|||
var data = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(result); |
|||
|
|||
string json = data.Data.ToString(); |
|||
|
|||
var datas = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ItemlabelInfoDto>>(json); |
|||
|
|||
bool isSuccess = data.Success; |
|||
|
|||
return (isSuccess, datas ?? new List<ItemlabelInfoDto>()); |
|||
} |
|||
catch |
|||
{ |
|||
return (false, new List<ItemlabelInfoDto>()); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// http接口调用
|
|||
/// </summary>
|
|||
/// <param name="api"></param>
|
|||
/// <param name="postData"></param>
|
|||
/// <returns></returns>
|
|||
private static string Http(string api, string postData = null, bool isAgain = false) |
|||
{ |
|||
try |
|||
{ |
|||
string url = api; |
|||
|
|||
if (!url.StartsWith("http")) |
|||
{ |
|||
url = ApiBase + api; |
|||
} |
|||
|
|||
HttpClient http = new HttpClient(); |
|||
http.Timeout = new TimeSpan(0, 0, 35); |
|||
http.DefaultRequestHeaders.Add("Authorization", "Bearer " + JwtToken); |
|||
if (postData!=null) |
|||
{ |
|||
StringContent content = new StringContent(postData); |
|||
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); |
|||
var result = http.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result; |
|||
return result; |
|||
} |
|||
|
|||
var request = new HttpRequestMessage() { Method = HttpMethod.Get, RequestUri = new Uri(url) }; |
|||
|
|||
var res = http.SendAsync(request).Result; |
|||
|
|||
if (res.StatusCode == System.Net.HttpStatusCode.Unauthorized) |
|||
{ |
|||
return string.Empty; |
|||
} |
|||
else |
|||
{ |
|||
//服务器挂掉
|
|||
if (res.StatusCode != System.Net.HttpStatusCode.OK) |
|||
{ |
|||
if (isAgain) |
|||
return null; |
|||
|
|||
Thread.Sleep(60000); |
|||
return Http(api, postData, true); |
|||
} |
|||
return res.Content.ReadAsStringAsync().Result; |
|||
} |
|||
|
|||
} |
|||
catch (HttpRequestException ex) |
|||
{ |
|||
if (isAgain) |
|||
return null; |
|||
Thread.Sleep(60000); |
|||
return Http(api, postData, true); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,88 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO.MemoryMappedFiles; |
|||
using System.Text; |
|||
|
|||
namespace Utils |
|||
{ |
|||
public class MemoryHelper |
|||
{ |
|||
public static string GetMemoryToken() |
|||
{ |
|||
string memoryName = string.Empty; |
|||
string[] args = Environment.GetCommandLineArgs(); |
|||
foreach (var arg in args) |
|||
{ |
|||
if (arg.StartsWith("uid:")) |
|||
{ |
|||
memoryName = arg; |
|||
} |
|||
} |
|||
|
|||
var result = MemoryHelper.ReadMMF(memoryName); |
|||
|
|||
if (result.isOk) |
|||
{ |
|||
return result.content; |
|||
} |
|||
else |
|||
{ |
|||
System.Environment.Exit(0); |
|||
return string.Empty; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 写入映射文件
|
|||
/// </summary>
|
|||
/// <param name="mapname"></param>
|
|||
/// <param name="content"></param>
|
|||
public static bool WriteMMF(string mapname, string content) |
|||
{ |
|||
MemoryMappedFile mmf = MemoryMappedFile.CreateOrOpen(mapname, 1000, MemoryMappedFileAccess.ReadWrite); |
|||
if (!string.IsNullOrEmpty(content)) |
|||
{ |
|||
using (var mmfStream = mmf.CreateViewStream()) |
|||
{ |
|||
using (var sw = new System.IO.StreamWriter(mmfStream)) |
|||
{ |
|||
sw.Write(content.Trim()); |
|||
} |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 读取映射文件
|
|||
/// </summary>
|
|||
/// <param name="mapname"></param>
|
|||
public static (bool isOk,string content) ReadMMF(string mapname) |
|||
{ |
|||
try |
|||
{ |
|||
MemoryMappedFile mmf = MemoryMappedFile.OpenExisting(mapname); |
|||
using (var mmfStream = mmf.CreateViewStream(0, 1000, MemoryMappedFileAccess.ReadWrite)) |
|||
{ |
|||
byte[] buffer = new byte[128]; |
|||
int nLength = 0; |
|||
StringBuilder sb = new StringBuilder(); |
|||
do |
|||
{ |
|||
nLength = mmfStream.Read(buffer, 0, 128); |
|||
sb.AppendLine(System.Text.ASCIIEncoding.Default.GetString(buffer)); |
|||
|
|||
} while (nLength > 0); |
|||
|
|||
return (true, sb.ToString().Replace("\0", null).TrimEnd()); |
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
return (false, null); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,80 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace JdShopListener.Models |
|||
{ |
|||
public class ItemlabelInfoDto: itemlabels |
|||
{ |
|||
/// <summary>
|
|||
/// 平台
|
|||
/// </summary>
|
|||
public int Platform { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否集团过滤
|
|||
/// </summary>
|
|||
public bool HasFilter { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 宝贝ID
|
|||
/// </summary>
|
|||
public string GoodsId { get; set; } |
|||
} |
|||
|
|||
public class itemlabels |
|||
{ |
|||
public String Id { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 创建时间
|
|||
/// </summary>
|
|||
public DateTime CreateTime { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 创建人Id
|
|||
/// </summary>
|
|||
public String CreatorId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 否已删除
|
|||
/// </summary>
|
|||
public Boolean Deleted { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 宝贝ID
|
|||
/// </summary>
|
|||
public String ItemsId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否筛选
|
|||
/// </summary>
|
|||
public Boolean IsScreening { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否过滤
|
|||
/// </summary>
|
|||
public Boolean IsFilter { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否竞品
|
|||
/// </summary>
|
|||
public Boolean IsCompeting { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否加入产品库
|
|||
/// </summary>
|
|||
public Boolean IsAdded { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 添加人
|
|||
/// </summary>
|
|||
public String UserId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 团队ID
|
|||
/// </summary>
|
|||
public String TeamId { get; set; } |
|||
|
|||
} |
|||
} |
@ -0,0 +1,92 @@ |
|||
<Window x:Class="WpfNoticeMsg.NoticeMessage" |
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
|||
xmlns:local="clr-namespace:WpfNoticeMsg" |
|||
mc:Ignorable="d" |
|||
AllowsTransparency="True" |
|||
WindowStyle="None" |
|||
ResizeMode="NoResize" |
|||
WindowStartupLocation="CenterOwner" |
|||
Background="Transparent" |
|||
Foreground="White" |
|||
Title="NoticeMessage" MinHeight="75" MinWidth="350"> |
|||
|
|||
|
|||
<WindowChrome.WindowChrome> |
|||
<WindowChrome GlassFrameThickness="-1" CaptionHeight="2"/> |
|||
</WindowChrome.WindowChrome> |
|||
|
|||
|
|||
<Window.Style> |
|||
<Style TargetType="{x:Type Window}"> |
|||
<Setter Property="Background" Value="Transparent"></Setter> |
|||
<Setter Property="Template"> |
|||
<Setter.Value> |
|||
<ControlTemplate TargetType="{x:Type Window}"> |
|||
<Border BorderBrush="#D7D7D7" |
|||
BorderThickness="1" |
|||
CornerRadius="6" |
|||
x:Name="WindowBorder"> |
|||
<Border.Background> |
|||
<SolidColorBrush Opacity="0.6" Color="Black"></SolidColorBrush> |
|||
</Border.Background> |
|||
|
|||
|
|||
<Grid x:Name="LayoutRoot" |
|||
Background="{TemplateBinding Background}"> |
|||
<Grid.RowDefinitions> |
|||
<RowDefinition Height="Auto" /> |
|||
<RowDefinition Height="*" /> |
|||
</Grid.RowDefinitions> |
|||
<Grid x:Name="WindowTitlePanel" |
|||
Background="{TemplateBinding BorderBrush}" |
|||
Margin="0,-1,0,0"> |
|||
|
|||
<ContentPresenter Content="{TemplateBinding Tag}"></ContentPresenter> |
|||
</Grid> |
|||
<AdornerDecorator Grid.Row="1" |
|||
KeyboardNavigation.IsTabStop="False"> |
|||
<ContentPresenter Content="{TemplateBinding Content}" |
|||
x:Name="MainContentPresenter" |
|||
KeyboardNavigation.TabNavigation="Cycle" /> |
|||
</AdornerDecorator> |
|||
|
|||
</Grid> |
|||
</Border> |
|||
</ControlTemplate> |
|||
</Setter.Value> |
|||
</Setter> |
|||
</Style> |
|||
</Window.Style> |
|||
|
|||
<Window.Tag> |
|||
<Border Padding="5"> |
|||
<Grid> |
|||
<Grid.ColumnDefinitions> |
|||
<ColumnDefinition></ColumnDefinition> |
|||
<ColumnDefinition></ColumnDefinition> |
|||
</Grid.ColumnDefinitions> |
|||
<TextBlock Text="提示" FontSize="14" Padding="20 5" x:Name="txt_Title"></TextBlock> |
|||
|
|||
<Button Padding="10" Grid.Column="1" HorizontalAlignment="Right" Name="close" Click="close_Click"> |
|||
<Button.Template> |
|||
<ControlTemplate TargetType="Button"> |
|||
<Border Padding="{TemplateBinding Padding}"> |
|||
<Border.Background> |
|||
<SolidColorBrush Color="White" Opacity="0.01"></SolidColorBrush> |
|||
</Border.Background> |
|||
<Path Data="M0 0 10 10 M5 5 10 0 M5 5 0 10" Stroke="White" ></Path> |
|||
</Border> |
|||
</ControlTemplate> |
|||
</Button.Template> |
|||
</Button> |
|||
</Grid> |
|||
</Border> |
|||
|
|||
</Window.Tag> |
|||
<Grid x:Name="grid" > |
|||
<TextBlock Margin="20 0 20 15" VerticalAlignment="Center" HorizontalAlignment="Center" x:Name="txtMsg"></TextBlock> |
|||
</Grid> |
|||
</Window> |
@ -0,0 +1,63 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using System.Threading; |
|||
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.Shapes; |
|||
|
|||
namespace WpfNoticeMsg |
|||
{ |
|||
/// <summary>
|
|||
/// NoticeMessage.xaml 的交互逻辑
|
|||
/// </summary>
|
|||
public partial class NoticeMessage : Window |
|||
{ |
|||
public NoticeMessage() |
|||
{ |
|||
InitializeComponent(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 显示消息
|
|||
/// </summary>
|
|||
/// <param name="msg"></param>
|
|||
/// <param name="title"></param>
|
|||
/// <param name="sleep"></param>
|
|||
public static void Show(string msg, string title = "提示", int sleep = 2000) |
|||
{ |
|||
Application.Current.Dispatcher.BeginInvoke(new Action(() => |
|||
{ |
|||
NoticeMessage noticeMessage = new NoticeMessage(); |
|||
noticeMessage.Owner = Application.Current.MainWindow; |
|||
noticeMessage.txt_Title.Text = title; |
|||
noticeMessage.txtMsg.Text = msg; |
|||
|
|||
noticeMessage.Height= noticeMessage.grid.ActualHeight; |
|||
noticeMessage.Width = noticeMessage.grid.ActualWidth + 30; |
|||
|
|||
noticeMessage.Show(); |
|||
|
|||
Task.Factory.StartNew(() => |
|||
{ |
|||
Thread.Sleep(sleep); |
|||
Application.Current.Dispatcher.Invoke(() => |
|||
{ |
|||
noticeMessage.Close(); |
|||
}); |
|||
}); |
|||
})); |
|||
} |
|||
|
|||
private void close_Click(object sender, RoutedEventArgs e) |
|||
{ |
|||
this.Close(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,23 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp3.1</TargetFramework> |
|||
<UseWPF>true</UseWPF> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.5" /> |
|||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.5"> |
|||
<PrivateAssets>all</PrivateAssets> |
|||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
|||
</PackageReference> |
|||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.5" /> |
|||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="5.0.5" /> |
|||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.5"> |
|||
<PrivateAssets>all</PrivateAssets> |
|||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
|||
</PackageReference> |
|||
<PackageReference Include="MvvmLightLibsStd10" Version="5.4.1.1" /> |
|||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> |
|||
</ItemGroup> |
|||
</Project> |
@ -0,0 +1,14 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<PropertyGroup /> |
|||
<ItemGroup> |
|||
<Compile Update="NoticeMessage.xaml.cs"> |
|||
<SubType>Code</SubType> |
|||
</Compile> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Page Update="NoticeMessage.xaml"> |
|||
<SubType>Designer</SubType> |
|||
</Page> |
|||
</ItemGroup> |
|||
</Project> |
Loading…
Reference in new issue