Skip to content

Commit

Permalink
Merge pull request #3888 from Ginger-Automation/BugFix/LiteDBTryCatch…
Browse files Browse the repository at this point in the history
…MutexIssue

Addded try catch block for mutex exception
  • Loading branch information
Maheshkale447 authored Aug 30, 2024
2 parents 5f2c893 + 0e5a666 commit c676240
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions Ginger/GingerCoreNET/LiteDBFolder/LiteDbConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,35 +71,41 @@ public ILiteCollection<T> GetCollection<T>(string collectionName)
collection = db.GetCollection<T>(collectionName);
}
}
catch(UnauthorizedAccessException ex)
{
Reporter.ToLog(eLogLevel.ERROR, $"Access denied while trying to get collection: {collectionName}", ex);
}
catch (Exception ex)
{
Reporter.ToLog(eLogLevel.ERROR, $"Failed to Get Collection: {collectionName}", ex);
throw;
}
return collection;
}

/*
* This function is not used anywhere
* public bool DeleteCollectionItems<T>(LiteCollection<T> baseColl, Query query)

//This function is not used anywhere
//public bool DeleteCollectionItems<T>(LiteCollection<T> baseColl, Query query)
//{
// bool result = false;
// try
// {
// using (var db = new LiteDatabase(this.ConnectionString))
// {
// result = baseColl.Delete(query) > 0;
// }
// }
// catch (Exception ex)
// {
// Console.WriteLine("DeleteCollectionItems Error - " + ex.Message);
// }
// return result;
//}

public bool DeleteDocumentByLiteDbRunSet(LiteDbRunSet liteDbRunSet, eExecutedFrom executedFrom = eExecutedFrom.Run)
{
bool result = false;
bool result = true;
try
{
using (var db = new LiteDatabase(this.ConnectionString))
{
result = baseColl.Delete(query) > 0;
}
}
catch (Exception ex)
{
Console.WriteLine("DeleteCollectionItems Error - " + ex.Message);
}
return result;
}
*/ public bool DeleteDocumentByLiteDbRunSet(LiteDbRunSet liteDbRunSet, eExecutedFrom executedFrom = eExecutedFrom.Run)
{
bool result = true;
var runSetLiteColl = GetCollection<LiteDbRunSet>(NameInDb<LiteDbRunSet>());
var runnerssLiteColl = GetCollection<LiteDbRunner>(NameInDb<LiteDbRunner>());
foreach (LiteDbRunner ldbRunner in liteDbRunSet.RunnersColl)
Expand Down Expand Up @@ -133,6 +139,12 @@ public ILiteCollection<T> GetCollection<T>(string collectionName)
{
runSetLiteColl.Delete(liteDbRunSet._id);
}
}
catch (Exception ex)
{
Reporter.ToLog(eLogLevel.ERROR, $"Failed to delete document for RunSet: {liteDbRunSet._id}", ex);
result = false;
}
return result;
}
public string NameInDb<T>()
Expand Down

0 comments on commit c676240

Please sign in to comment.