Skip to content

Commit

Permalink
Addded try catch block for mutex exception
Browse files Browse the repository at this point in the history
  • Loading branch information
amanpras committed Aug 30, 2024
1 parent 5f2c893 commit 0e5a666
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)
//{

Check warning on line 88 in Ginger/GingerCoreNET/LiteDBFolder/LiteDbConnector.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Ginger/GingerCoreNET/LiteDBFolder/LiteDbConnector.cs#L88

Remove this commented out code.
// 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 0e5a666

Please sign in to comment.