This commit is contained in:
2018-10-03 20:44:22 +00:00
parent 5a235dc77c
commit fbf05d9bac
3 changed files with 39 additions and 32 deletions

View File

@@ -415,45 +415,52 @@ namespace AyaNova.Biz
List<MatchingDictionaryEntry> MatchingKeywordIdList = new List<MatchingDictionaryEntry>();
//######### FROM HERE NEEDS TO LOCK SEARCHDICTIONARY FROM HERE TO ADDING NEW WORDS
using (var transaction = ct.Database.BeginTransaction())
//ITERATE ALL THE KEYWORDS, SEARCH IN THE SEARCHDICTIONARY TABLE AND COLLECT ID'S OF ANY PRE-EXISTING IN DB KEYWORDS
var ExistingKeywordMatches = ct.SearchDictionary.Where(m => KeyWordList.Contains(m.Word)).ToDictionary(m => m.Id, m => m.Word);
//Put the matching keyword ID's into the list
foreach (KeyValuePair<long, string> K in ExistingKeywordMatches)
{
//ITERATE ALL THE KEYWORDS, SEARCH IN THE SEARCHDICTIONARY TABLE AND COLLECT ID'S OF ANY PRE-EXISTING IN DB KEYWORDS
var ExistingKeywordMatches = ct.SearchDictionary.Where(m => KeyWordList.Contains(m.Word)).ToDictionary(m => m.Id, m => m.Word);
//Put the matching keyword ID's into the list
foreach (KeyValuePair<long, string> K in ExistingKeywordMatches)
{
bool IsName = false;
if (NameKeyWordList.Contains(K.Value))
IsName = true;
MatchingKeywordIdList.Add(new MatchingDictionaryEntry() { DictionaryId = K.Key, InName = IsName });
}
bool IsName = false;
if (NameKeyWordList.Contains(K.Value))
IsName = true;
MatchingKeywordIdList.Add(new MatchingDictionaryEntry() { DictionaryId = K.Key, InName = IsName });
}
//ITERATE THROUGH THE KEYWORDS THAT DO *NOT* HAVE MATCHES IN THE SEARCHDICTIONARY AND ADD THEM TO THE SEARCH DICTIONARY, COLLECTING THEIR ID'S
bool NewWordsAdded = false;
var NewSearchDictionaryWordsList = new List<SearchDictionary>();
foreach (string KeyWord in KeyWordList)
//ITERATE THROUGH THE KEYWORDS THAT DO *NOT* HAVE MATCHES IN THE SEARCHDICTIONARY AND ADD THEM TO THE SEARCH DICTIONARY, COLLECTING THEIR ID'S
bool NewWordsAdded = false;
var NewSearchDictionaryWordsList = new List<SearchDictionary>();
foreach (string KeyWord in KeyWordList)
{
if (!ExistingKeywordMatches.ContainsValue(KeyWord))
{
if (!ExistingKeywordMatches.ContainsValue(KeyWord))
{
NewSearchDictionaryWordsList.Add(new SearchDictionary() { Word = KeyWord });
NewWordsAdded = true;
}
NewSearchDictionaryWordsList.Add(new SearchDictionary() { Word = KeyWord });
NewWordsAdded = true;
}
}
//Save the context in order to get the id's of the new words added
if (NewWordsAdded)
//Save the context in order to get the id's of the new words added
if (NewWordsAdded)
{
//adding in a range sped this up noticeably
ct.SearchDictionary.AddRange(NewSearchDictionaryWordsList);
try
{
//adding in a range sped this up noticeably
ct.SearchDictionary.AddRange(NewSearchDictionaryWordsList);
ct.SaveChanges();
}
catch (Exception ex)
{
//In integration testing hit duplicate values of widget names
//adjusted uniquify code in test util class to use milliseconds instead of seconds (duh) and didn't hit this again,
//however just in case I'm leaving it here as a potential debug break point if it arises again
//Outside of a test situation I can't imagine this will be an issue in actual production use
//as it seems unlikely that two separate manual users inputting data are going to generate the same word at the same exact moment
//in time
throw ex;
}
}
transaction.Commit();
}//end transaction
//#########################
//-----
//Now add the id's of the newly created words to the matching keyword id list for this object

View File

@@ -112,7 +112,7 @@ namespace raven_integration
uint OriginalConcurrencyToken = a.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
//Now TechFullAuthToken attempt to modify it via patch
var newName = Util.Uniquify("ServerShouldDisAllowOwnerOnlyRightsUserToPatchNonOwned - UPDATED TEST WIDGET");
var newName = Util.Uniquify("ServerShouldDisAllowOwnerOnlyRightsUserToPatchNonOwned - UPDATED TEST WIDGETB");
string patchJson = "[{\"value\": \"" + newName + "\",\"path\": \"/name\",\"op\": \"replace\"}]";
a = await Util.PatchAsync("Widget/" + Id.ToString() + "/" + OriginalConcurrencyToken.ToString(), await Util.GetTokenAsync( "TechFull"), patchJson);
//2004 unauthorized expected

View File

@@ -22,7 +22,7 @@ namespace raven_integration
public static string Uniquify(string s)
{
return s + ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds();
return s + ((DateTimeOffset)DateTime.Now).ToUnixTimeMilliseconds().ToString();
}
public async static Task<string> GetTokenAsync(string login, string password = null)