- Joined
- Apr 17, 2018
- Messages
- 331
- Reaction score
- 15
- Points
- 18
Здравствуйте!
Помогите разобраться, в чем ошибка?
Проблема в том, что в многопотоке бывает так, что из Таблицы "Asins" берется одновременно одна и та же строка с одинаковыми значениями в разных потоках. Хотя вроде все залочино и строка удаляется.
ВОТ САМ СНИППЕТ
lock(SyncObject)
{
//var isDebug = Global.Variables.IsDebugMode;
Boolean isDebug = false;
try
{
instance.ClearCookie();
instance.ClearCache();
project.Variables["userAgent"].Value = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36";
var accounts = project.Tables["accounts"];
var asins = project.Tables["asins"];
lock(SyncObjects.TableSyncer)
{
if(accounts.RowCount == 0)
{
project.SendWarningToLog("Список accounts пустой", true);
return null;
}
if(asins.RowCount == 0)
{
project.SendWarningToLog("Список asins пустой", true);
return null;
}
//---
var row = accounts.GetRow(0).ToList();
//if(!isDebug) accounts.DeleteRow(0);
string parent_path = System.IO.Directory.GetParent(project.Directory).ToString();
//project.SendInfoToLog(parent_path, true);
project.Variables["ebayLogin"].Value = row[0];
project.Variables["ebayPass"].Value = row[1];
project.Variables["proxy"].Value = row.Count > 2 ? row[2] : "";
//---
string bad_asins = File.ReadAllText(parent_path + "\\badASINs.txt");
string work_asins = File.ReadAllText(project.Directory + "\\EbayLister\\workASINs.txt");
//string stop_words = File.ReadAllText(parent_path + "\\stopWords.txt");
var stop_words = project.Lists["stop_words"];
int index = 0;
string stop_word = "";
string stop_title = "";
while (true) {
int value = ++index;
row = asins.GetRow(0).ToList();
if(!isDebug) asins.DeleteRow(0);
if (!bad_asins.Contains(row[0]) && !work_asins.Contains(row[0])) {
string title = row.Count > 1 ? row[1] : "";
if (title == "") {
project.Variables["asin"].Value = row[0];
project.Variables["title"].Value = "";
break;
} else {
string low_title = title.ToLower();
Boolean isFind = false;
string word = "";
string [] words = null;
string str = "";
for (int i = 0; i < stop_words.Count; i++) {
word = stop_words;
words = word.Split(' ');
if (words.Length > 1) {
if (low_title.Contains(word)) {
stop_word = word;
stop_title = title;
isFind = true;
break;
}
} else {
str = "\\b" + word + "\\b";
if (Regex.IsMatch(title, @str, RegexOptions.IgnoreCase)) {
stop_word = word;
stop_title = title;
isFind = true;
break;
}
}
}
if (!isFind) {
project.Variables["asin"].Value = row[0];
project.Variables["goodsSellPrice"].Value = row[1];
break;
} else {
project.SendInfoToLog(row[0] + " - удаляем, т. к. Title - " + stop_title + " имеет запрещенное слово " + stop_word, true);
lock(SyncObjects.TableSyncer) {
var row1 = new List<string>() {
row[0], stop_title
};
project.Tables["asinsBad"].AddRow(row1);
}
}
}
} else {
project.SendInfoToLog(row[0] + " - удаляем, т. к. этот ASIN в черном списке или в рабочем списке" , true);
}
if (value > 10) {
throw new Exception("Бесконечный цикл");
}
}
project.SendInfoToLog(project.Variables["asin"].Value + " - " + project.Variables["goodsSellPrice"].Value, true);
}
var path = project.Directory + "\\EbayLister\\Profiles\\" + project.Variables["ebayLogin"].Value.Split('@')[0] + ".zpprofile";
if(File.Exists(path))
{
project.Profile.Load(path);
}
//instance.SetProxy(project.Variables["proxy"].Value);
}
catch(Exception e)
{
project.SendErrorToLog(e.ToString(), true);
return null;
}
}
Помогите разобраться, в чем ошибка?
Проблема в том, что в многопотоке бывает так, что из Таблицы "Asins" берется одновременно одна и та же строка с одинаковыми значениями в разных потоках. Хотя вроде все залочино и строка удаляется.
ВОТ САМ СНИППЕТ
lock(SyncObject)
{
//var isDebug = Global.Variables.IsDebugMode;
Boolean isDebug = false;
try
{
instance.ClearCookie();
instance.ClearCache();
project.Variables["userAgent"].Value = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36";
var accounts = project.Tables["accounts"];
var asins = project.Tables["asins"];
lock(SyncObjects.TableSyncer)
{
if(accounts.RowCount == 0)
{
project.SendWarningToLog("Список accounts пустой", true);
return null;
}
if(asins.RowCount == 0)
{
project.SendWarningToLog("Список asins пустой", true);
return null;
}
//---
var row = accounts.GetRow(0).ToList();
//if(!isDebug) accounts.DeleteRow(0);
string parent_path = System.IO.Directory.GetParent(project.Directory).ToString();
//project.SendInfoToLog(parent_path, true);
project.Variables["ebayLogin"].Value = row[0];
project.Variables["ebayPass"].Value = row[1];
project.Variables["proxy"].Value = row.Count > 2 ? row[2] : "";
//---
string bad_asins = File.ReadAllText(parent_path + "\\badASINs.txt");
string work_asins = File.ReadAllText(project.Directory + "\\EbayLister\\workASINs.txt");
//string stop_words = File.ReadAllText(parent_path + "\\stopWords.txt");
var stop_words = project.Lists["stop_words"];
int index = 0;
string stop_word = "";
string stop_title = "";
while (true) {
int value = ++index;
row = asins.GetRow(0).ToList();
if(!isDebug) asins.DeleteRow(0);
if (!bad_asins.Contains(row[0]) && !work_asins.Contains(row[0])) {
string title = row.Count > 1 ? row[1] : "";
if (title == "") {
project.Variables["asin"].Value = row[0];
project.Variables["title"].Value = "";
break;
} else {
string low_title = title.ToLower();
Boolean isFind = false;
string word = "";
string [] words = null;
string str = "";
for (int i = 0; i < stop_words.Count; i++) {
word = stop_words;
words = word.Split(' ');
if (words.Length > 1) {
if (low_title.Contains(word)) {
stop_word = word;
stop_title = title;
isFind = true;
break;
}
} else {
str = "\\b" + word + "\\b";
if (Regex.IsMatch(title, @str, RegexOptions.IgnoreCase)) {
stop_word = word;
stop_title = title;
isFind = true;
break;
}
}
}
if (!isFind) {
project.Variables["asin"].Value = row[0];
project.Variables["goodsSellPrice"].Value = row[1];
break;
} else {
project.SendInfoToLog(row[0] + " - удаляем, т. к. Title - " + stop_title + " имеет запрещенное слово " + stop_word, true);
lock(SyncObjects.TableSyncer) {
var row1 = new List<string>() {
row[0], stop_title
};
project.Tables["asinsBad"].AddRow(row1);
}
}
}
} else {
project.SendInfoToLog(row[0] + " - удаляем, т. к. этот ASIN в черном списке или в рабочем списке" , true);
}
if (value > 10) {
throw new Exception("Бесконечный цикл");
}
}
project.SendInfoToLog(project.Variables["asin"].Value + " - " + project.Variables["goodsSellPrice"].Value, true);
}
var path = project.Directory + "\\EbayLister\\Profiles\\" + project.Variables["ebayLogin"].Value.Split('@')[0] + ".zpprofile";
if(File.Exists(path))
{
project.Profile.Load(path);
}
//instance.SetProxy(project.Variables["proxy"].Value);
}
catch(Exception e)
{
project.SendErrorToLog(e.ToString(), true);
return null;
}
}