Improved error handling

This commit is contained in:
2016-03-25 00:39:15 +01:00
parent 86cf01ad8c
commit fd76147eed
8 changed files with 60 additions and 27 deletions
@@ -60,17 +60,12 @@ namespace Ntp.Analyzer.Process.Description
protected override void InternalExecute()
{
// Find host in database.
Host host;
Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId);
try
{
host = DataFace.Instance.Hosts.Single(h => h.Name == config.ServerName);
}
catch (Exception e)
{
Log.WriteLine("Hostname not found in database: " + config.ServerName, Severity.Warn);
Log.WriteLine (e, Severity.Trace);
if (host == null) {
Log.WriteLine (String.Format (
"Host with ID {0} was not found in database. ", config.HostId),
Severity.Warn);
return;
}
@@ -24,6 +24,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Linq;
using Ntp.Analyzer.Config.Destination;
using Ntp.Analyzer.Config.Graph;
@@ -61,7 +62,14 @@ namespace Ntp.Analyzer.Process.Description
protected override void InternalExecute()
{
Host host = DataFace.Instance.Hosts.Single(h => h.Id == config.HostId);
Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId);
if (host == null) {
Log.WriteLine (String.Format (
"Host with ID {0} was not found in database. ", config.HostId),
Severity.Warn);
return;
}
foreach (GraphSetConfiguration graphSet in config.GraphSets)
{
@@ -24,6 +24,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Ntp.Analyzer.Config.Graph;
@@ -60,7 +61,14 @@ namespace Ntp.Analyzer.Process.Description
protected override void InternalExecute()
{
Host host = DataFace.Instance.Hosts.Single(h => h.Id == config.HostId);
Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId);
if (host == null) {
Log.WriteLine (String.Format (
"Host with ID {0} was not found in database. ", config.HostId),
Severity.Warn);
return;
}
foreach (NtpConfEntry entry in DataFace.Instance.NtpConfigCache[config.ConfigFile])
{
@@ -24,6 +24,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Ntp.Analyzer.Config.Destination;
@@ -62,7 +63,14 @@ namespace Ntp.Analyzer.Process.Description
protected override void InternalExecute()
{
Host host = DataFace.Instance.Hosts.Single(h => h.Id == config.HostId);
Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId);
if (host == null) {
Log.WriteLine (String.Format (
"Host with ID {0} was not found in database. ", config.HostId),
Severity.Warn);
return;
}
foreach (GraphSetConfiguration graphSet in config.GraphSets)
{
@@ -24,6 +24,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
@@ -67,7 +68,14 @@ namespace Ntp.Analyzer.Process.Description
protected override void InternalExecute()
{
Host host = DataFace.Instance.Hosts.Single(h => h.Id == page.HostId);
Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == page.HostId);
if (host == null) {
Log.WriteLine (String.Format (
"Host with ID {0} was not found in database. ", page.HostId),
Severity.Warn);
return;
}
foreach (NtpConfEntry entry in DataFace.Instance.NtpConfigCache[page.ConfigFile])
{
@@ -60,16 +60,12 @@ namespace Ntp.Analyzer.Process.Description
protected override void InternalExecute()
{
Host host;
Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId);
try
{
host = DataFace.Instance.Hosts.Single(h => h.Name == config.ServerName);
}
catch (Exception e)
{
Log.WriteLine("Hostname not found in database: " + config.ServerName, Severity.Warn);
Log.WriteLine (e, Severity.Trace);
if (host == null) {
Log.WriteLine (String.Format (
"Host with ID {0} was not found in database. ", config.HostId),
Severity.Warn);
return;
}
@@ -77,4 +73,4 @@ namespace Ntp.Analyzer.Process.Description
SaveStream(graph);
}
}
}
}