Beispiel #1
0
        public void Check(ICheckNotifier notifier)
        {
            var catalogues = _loadMetadata.GetAllCatalogues().ToArray();

            //if there are no logging tasks defined on any Catalogues
            if (catalogues.Any() && catalogues.All(c => string.IsNullOrWhiteSpace(c.LoggingDataTask)))
            {
                string proposedName;

                bool fix;

                if (catalogues.Length == 1)
                {
                    proposedName = "Loading '" + catalogues[0] + "'";
                    fix          = notifier.OnCheckPerformed(
                        new CheckEventArgs(
                            "Catalogue " + catalogues[0] + " does not have a logging task specified",
                            CheckResult.Fail, null, "Create a new Logging Task called '" + proposedName + "'?"));
                }
                else
                {
                    proposedName = _loadMetadata.Name;

                    fix =
                        notifier.OnCheckPerformed(
                            new CheckEventArgs(
                                "Catalogues " + string.Join(",", catalogues.Select(c => c.Name)) + " do not have a logging task specified",
                                CheckResult.Fail, null, "Create a new Logging Task called '" + proposedName + "'?"));
                }

                if (fix)
                {
                    CreateNewLoggingTaskFor(notifier, catalogues, proposedName);
                }
                else
                {
                    return;
                }
            }

            #region Fix missing LoggingDataTask
            var missingTasks   = catalogues.Where(c => string.IsNullOrWhiteSpace(c.LoggingDataTask)).ToArray();
            var potentialTasks = catalogues.Except(missingTasks).Select(c => c.LoggingDataTask).Distinct().ToArray();

            //If any Catalogues are missing tasks
            if (missingTasks.Any())
            {
                //but there is consensus for those that are not missing tasks
                if (potentialTasks.Length == 1)
                {
                    var fix = notifier.OnCheckPerformed(new CheckEventArgs("Some catalogues have NULL LoggingDataTasks", CheckResult.Fail, null, $"Set task to {potentialTasks.Single()}"));

                    if (fix)
                    {
                        foreach (var cata in missingTasks)
                        {
                            cata.LoggingDataTask = potentialTasks.Single();
                            cata.SaveToDatabase();
                        }
                    }
                }
            }
            #endregion

            #region Fix missing LiveLoggingServer_ID
            var missingServer   = catalogues.Where(c => c.LiveLoggingServer_ID == null).ToArray();
            var potentialServer = catalogues.Except(missingServer).Select(c => c.LiveLoggingServer_ID).Distinct().ToArray();

            if (missingServer.Any())
            {
                if (potentialServer.Length == 1)
                {
                    var fix = notifier.OnCheckPerformed(new CheckEventArgs("Some catalogues have NULL LiveLoggingServer_ID", CheckResult.Fail, null, $"Set LiveLoggingServer_ID to {potentialServer.Single()}"));

                    if (fix)
                    {
                        foreach (var cata in missingServer)
                        {
                            cata.LiveLoggingServer_ID = potentialServer.Single();
                            cata.SaveToDatabase();
                        }
                    }
                }
                else
                {
                    var defaults             = _loadMetadata.CatalogueRepository.GetServerDefaults();
                    var defaultLoggingServer = defaults.GetDefaultFor(PermissableDefaults.LiveLoggingServer_ID);

                    if (defaultLoggingServer != null)
                    {
                        var fix = notifier.OnCheckPerformed(new CheckEventArgs("Some catalogues have NULL LiveLoggingServer_ID", CheckResult.Fail, null, $"Set LiveLoggingServer_ID to '{defaultLoggingServer}' (the default)"));

                        if (fix)
                        {
                            foreach (var cata in missingServer)
                            {
                                cata.LiveLoggingServer_ID = defaultLoggingServer.ID;
                                cata.SaveToDatabase();
                            }
                        }
                    }
                }
            }
            #endregion

            string distinctLoggingTask = null;
            try
            {
                distinctLoggingTask = _loadMetadata.GetDistinctLoggingTask();
                notifier.OnCheckPerformed(new CheckEventArgs("All Catalogues agreed on a single Logging Task:" + distinctLoggingTask, CheckResult.Success, null));
            }
            catch (Exception e)
            {
                notifier.OnCheckPerformed(new CheckEventArgs("Catalogues could not agreed on a single Logging Task", CheckResult.Fail, e));
            }


            try
            {
                var settings = _loadMetadata.GetDistinctLoggingDatabase();
                settings.TestConnection();
                notifier.OnCheckPerformed(new CheckEventArgs("Connected to logging architecture successfully", CheckResult.Success, null));


                if (distinctLoggingTask != null)
                {
                    LogManager lm        = new LogManager(settings);
                    string[]   dataTasks = lm.ListDataTasks();

                    if (dataTasks.Contains(distinctLoggingTask))
                    {
                        notifier.OnCheckPerformed(new CheckEventArgs("Found Logging Task " + distinctLoggingTask + " in Logging database", CheckResult.Success, null));
                    }
                    else
                    {
                        var fix = notifier.OnCheckPerformed(new CheckEventArgs("Could not find Logging Task " + distinctLoggingTask + " in Logging database", CheckResult.Fail, null, "Create Logging Task '" + distinctLoggingTask + "'"));
                        if (fix)
                        {
                            lm.CreateNewLoggingTaskIfNotExists(distinctLoggingTask);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                notifier.OnCheckPerformed(new CheckEventArgs("Could reach default logging server", CheckResult.Fail, e));
            }
        }
Beispiel #2
0
        public void Check(ICheckNotifier notifier)
        {
            var catalogues = _loadMetadata.GetAllCatalogues().ToArray();

            //if there are no logging tasks defined on any Catalogues
            if (catalogues.Any() && catalogues.All(c => string.IsNullOrWhiteSpace(c.LoggingDataTask)))
            {
                string proposedName;

                bool fix;

                if (catalogues.Length == 1)
                {
                    proposedName = "Loading '" + catalogues[0] + "'";
                    fix          = notifier.OnCheckPerformed(
                        new CheckEventArgs(
                            "Catalogue " + catalogues[0] + " does not have a logging task specified",
                            CheckResult.Fail, null, "Create a new Logging Task called '" + proposedName + "'?"));
                }
                else
                {
                    proposedName = _loadMetadata.Name;

                    fix =
                        notifier.OnCheckPerformed(
                            new CheckEventArgs(
                                "Catalogues " + string.Join(",", catalogues.Select(c => c.Name)) + " do not have a logging task specified",
                                CheckResult.Fail, null, "Create a new Logging Task called '" + proposedName + "'?"));
                }

                if (fix)
                {
                    CreateNewLoggingTaskFor(notifier, catalogues, proposedName);
                }
                else
                {
                    return;
                }
            }

            string distinctLoggingTask = null;

            try
            {
                distinctLoggingTask = _loadMetadata.GetDistinctLoggingTask();
                notifier.OnCheckPerformed(new CheckEventArgs("All Catalogues agreed on a single Logging Task:" + distinctLoggingTask, CheckResult.Success, null));
            }
            catch (Exception e)
            {
                notifier.OnCheckPerformed(new CheckEventArgs("Catalogues could not agreed on a single Logging Task", CheckResult.Fail, e));
            }

            try
            {
                var settings = _loadMetadata.GetDistinctLoggingDatabase();
                settings.TestConnection();
                notifier.OnCheckPerformed(new CheckEventArgs("Connected to logging architecture successfully", CheckResult.Success, null));


                if (distinctLoggingTask != null)
                {
                    LogManager lm        = new LogManager(settings);
                    string[]   dataTasks = lm.ListDataTasks();

                    if (dataTasks.Contains(distinctLoggingTask))
                    {
                        notifier.OnCheckPerformed(new CheckEventArgs("Found Logging Task " + distinctLoggingTask + " in Logging database", CheckResult.Success, null));
                    }
                    else
                    {
                        var fix = notifier.OnCheckPerformed(new CheckEventArgs("Could not find Logging Task " + distinctLoggingTask + " in Logging database", CheckResult.Fail, null, "Create Logging Task '" + distinctLoggingTask + "'"));
                        if (fix)
                        {
                            lm.CreateNewLoggingTaskIfNotExists(distinctLoggingTask);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                notifier.OnCheckPerformed(new CheckEventArgs("Could reach default logging server", CheckResult.Fail, e));
            }
        }