Browse Source

优化获取内存共享key的流程

master
С·æ 4 years ago
parent
commit
31a13baea3
  1. 32
      JdShopListener/JdShopListener/MainWindowViewModel.cs
  2. 25
      JdShopListener/JdShopListener/MemoryHelper.cs
  3. 2
      JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml.user

32
JdShopListener/JdShopListener/MainWindowViewModel.cs

@ -128,7 +128,6 @@ namespace JdShopListener
webClient.DownloadFileCompleted += WebClient_DownloadFileCompleted;
webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
webClient.DownloadFileTaskAsync("https://qymds.oss-cn-hangzhou.aliyuncs.com/chromium/.local-chromium.zip", System.Environment.CurrentDirectory+"\\tempZip.zip").Wait();
}
private void WebClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
@ -163,7 +162,10 @@ namespace JdShopListener
IsInitLoding = true;
var result = ApiHelper.GetLabelByItemIds();
result.datas.ForEach(item => {
AddLog($"检测到{result.datas.Count}个慧眼竞品添加!");
result.datas.ForEach(item =>
{
var last = skuList.FirstOrDefault(c => c.SkuId == item.GoodsId);
if (last != null)
@ -175,17 +177,24 @@ namespace JdShopListener
}
}
//新增
else {
Application.Current.Dispatcher.Invoke(() => {
else
{
Application.Current.Dispatcher.Invoke(() =>
{
InitText = $"正在添加【{item.GoodsId}】...";
});
AddSku(item.GoodsId);
AddSku(item.GoodsId, "慧眼竞品添加");
}
//
});
}
finally {
catch(Exception ex)
{
AddLog($"慧眼添加异常{ex.Message}\r\n{ex.StackTrace}!");
}
finally
{
IsInitLoding = false;
}
});
@ -417,7 +426,7 @@ namespace JdShopListener
}
private void AddSku(string newSku)
private void AddSku(string newSku,string desc=null)
{
if (string.IsNullOrEmpty(JDCookie))
{
@ -446,7 +455,7 @@ namespace JdShopListener
{
SkuModel model = new SkuModel()
{
Desc = Desc,
Desc = desc??Desc,
SkuId = sku["skuId"].ToString(),
SpuId = spuId
};
@ -1225,6 +1234,8 @@ namespace JdShopListener
//Args = new string[] { "--no-sandbox" }
}).Result;
try
{
// 打开一个页面
var page = browser.NewPageAsync().Result;
@ -1240,6 +1251,11 @@ namespace JdShopListener
{
JDCookie += $"{c.Name}={c.Value};";
});
}
catch (Exception ex)
{
WpfNoticeMsg.NoticeMessage.Show("初始化内核失败,请尝试关闭跟屁虫重新启动!", "错误");
}
AddLog("获取到Cookie" + JDCookie);
}

25
JdShopListener/JdShopListener/MemoryHelper.cs

@ -2,11 +2,15 @@
using System.Collections.Generic;
using System.IO.MemoryMappedFiles;
using System.Text;
using System.Threading;
namespace Utils
{
public class MemoryHelper
{
static int getTokentCount = 0;
public static string GetMemoryToken()
{
string memoryName = string.Empty;
@ -23,15 +27,30 @@ namespace Utils
if (result.isOk)
{
if (string.IsNullOrEmpty(result.content))
{
getTokentCount = getTokentCount + 1;
if (getTokentCount <= 3)
{
Thread.Sleep(300);
return GetMemoryToken();
}
}
return result.content;
}
else
{
getTokentCount = getTokentCount + 1;
if (getTokentCount <= 3)
{
Thread.Sleep(300);
return GetMemoryToken();
}
System.Environment.Exit(0);
return string.Empty;
}
}
/// <summary>
/// 写入映射文件
/// </summary>
@ -66,12 +85,12 @@ namespace Utils
MemoryMappedFile mmf = MemoryMappedFile.OpenExisting(mapname);
using (var mmfStream = mmf.CreateViewStream(0, 1000, MemoryMappedFileAccess.ReadWrite))
{
byte[] buffer = new byte[128];
byte[] buffer = new byte[1000];
int nLength = 0;
StringBuilder sb = new StringBuilder();
do
{
nLength = mmfStream.Read(buffer, 0, 128);
nLength = mmfStream.Read(buffer, 0, 1000);
sb.AppendLine(System.Text.ASCIIEncoding.Default.GetString(buffer));
} while (nLength > 0);

2
JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml.user

@ -4,6 +4,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<History>True|2021-11-12T07:27:50.0418057Z;True|2021-11-12T15:06:23.1220477+08:00;True|2021-11-11T18:06:38.5161322+08:00;True|2021-11-11T17:53:13.2835443+08:00;True|2021-11-11T17:52:00.9170918+08:00;True|2021-11-11T17:51:37.4852682+08:00;True|2021-11-11T17:49:30.9386192+08:00;True|2021-11-11T17:44:28.5146341+08:00;True|2021-11-11T17:42:26.8480671+08:00;True|2021-11-11T17:37:14.4108790+08:00;True|2021-11-11T17:30:25.4460722+08:00;</History>
<History>True|2021-11-13T02:44:44.3567647Z;True|2021-11-13T10:42:01.8636514+08:00;True|2021-11-13T10:38:36.0623458+08:00;True|2021-11-13T10:20:29.4761762+08:00;True|2021-11-13T10:08:51.4924474+08:00;True|2021-11-12T15:27:50.0418057+08:00;True|2021-11-12T15:06:23.1220477+08:00;True|2021-11-11T18:06:38.5161322+08:00;True|2021-11-11T17:53:13.2835443+08:00;True|2021-11-11T17:52:00.9170918+08:00;True|2021-11-11T17:51:37.4852682+08:00;True|2021-11-11T17:49:30.9386192+08:00;True|2021-11-11T17:44:28.5146341+08:00;True|2021-11-11T17:42:26.8480671+08:00;True|2021-11-11T17:37:14.4108790+08:00;True|2021-11-11T17:30:25.4460722+08:00;</History>
</PropertyGroup>
</Project>
Loading…
Cancel
Save