private int extractAuditLogEvents(JobConfiguration jobConfiguration, JobTarget jobTarget, ControllerApi controllerApi)
        {
            JArray listOfAuditEvents = new JArray();

            foreach (JobTimeRange jobTimeRange in jobConfiguration.Input.HourlyTimeRanges)
            {
                string auditEventsJSON = controllerApi.GetAuditEvents(jobTimeRange.From, jobTimeRange.To);
                if (auditEventsJSON != String.Empty)
                {
                    JArray listOfAuditEventsInTimeRange = JArray.Parse(auditEventsJSON);
                    if (listOfAuditEventsInTimeRange != null)
                    {
                        // Load audit log events
                        foreach (JObject auditEvent in listOfAuditEventsInTimeRange)
                        {
                            listOfAuditEvents.Add(auditEvent);
                        }
                    }
                }
            }

            if (listOfAuditEvents.Count > 0)
            {
                FileIOHelper.WriteJArrayToFile(listOfAuditEvents, FilePathMap.AuditEventsDataFilePath(jobTarget));

                logger.Info("{0} audit events from {1:o} to {2:o}", listOfAuditEvents.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To);
                loggerConsole.Info("{0} audit events", listOfAuditEvents.Count);
            }

            return(listOfAuditEvents.Count);
        }
Ejemplo n.º 2
0
        private int extractHealthRuleViolations(JobConfiguration jobConfiguration, JobTarget jobTarget, ControllerApi controllerApi)
        {
            JArray listOfHealthRuleViolations = new JArray();

            foreach (JobTimeRange jobTimeRange in jobConfiguration.Input.HourlyTimeRanges)
            {
                long fromTimeUnix = UnixTimeHelper.ConvertToUnixTimestamp(jobTimeRange.From);
                long toTimeUnix   = UnixTimeHelper.ConvertToUnixTimestamp(jobTimeRange.To);

                string healthRuleViolationsJSON = controllerApi.GetHealthRuleViolations(jobTarget.ApplicationID, fromTimeUnix, toTimeUnix);
                if (healthRuleViolationsJSON != String.Empty)
                {
                    // Load health rule violations
                    JArray healthRuleViolationsInHour = JArray.Parse(healthRuleViolationsJSON);
                    foreach (JObject healthRuleViolation in healthRuleViolationsInHour)
                    {
                        listOfHealthRuleViolations.Add(healthRuleViolation);
                    }
                }
            }

            if (listOfHealthRuleViolations.Count > 0)
            {
                FileIOHelper.WriteJArrayToFile(listOfHealthRuleViolations, FilePathMap.HealthRuleViolationsDataFilePath(jobTarget));

                logger.Info("{0} health rule violations from {1:o} to {2:o}", listOfHealthRuleViolations.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To);
                loggerConsole.Info("{0} health rule violations", listOfHealthRuleViolations.Count);
            }

            return(listOfHealthRuleViolations.Count);
        }
Ejemplo n.º 3
0
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            if (this.ShouldExecute(jobConfiguration) == false)
            {
                return(true);
            }

            try
            {
                // TODO

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
        private int extractEvents(JobConfiguration jobConfiguration, JobTarget jobTarget, ControllerApi controllerApi, string eventType)
        {
            loggerConsole.Info("Extract List of Events {0} ({1} time ranges)", eventType, jobConfiguration.Input.HourlyTimeRanges.Count);

            JArray listOfEventsArray = new JArray();

            if (File.Exists(FilePathMap.ApplicationEventsDataFilePath(jobTarget, eventType)) == false)
            {
                foreach (JobTimeRange jobTimeRange in jobConfiguration.Input.HourlyTimeRanges)
                {
                    long fromTimeUnix = UnixTimeHelper.ConvertToUnixTimestamp(jobTimeRange.From);
                    long toTimeUnix   = UnixTimeHelper.ConvertToUnixTimestamp(jobTimeRange.To);

                    try
                    {
                        string eventsJSON = controllerApi.GetApplicationEvents(jobTarget.ApplicationID, eventType, fromTimeUnix, toTimeUnix);
                        if (eventsJSON != String.Empty)
                        {
                            // Load events
                            JArray eventsInHourArray = JArray.Parse(eventsJSON);

                            foreach (JObject eventObject in eventsInHourArray)
                            {
                                listOfEventsArray.Add(eventObject);
                            }

                            Console.Write("[{0}]+", eventsInHourArray.Count);
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                        logger.Warn("Unable to parse JSON for Events Application={0}, EventType={1}, From={2}, To={3}", jobTarget.ApplicationID, eventType, fromTimeUnix, toTimeUnix);
                    }
                }

                if (listOfEventsArray.Count > 0)
                {
                    FileIOHelper.WriteJArrayToFile(listOfEventsArray, FilePathMap.ApplicationEventsDataFilePath(jobTarget, eventType));

                    logger.Info("{0} {1} events from {2:o} to {3:o}", eventType, listOfEventsArray.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To);
                    loggerConsole.Info("{0} {1} events", eventType, listOfEventsArray.Count);
                }
            }

            return(listOfEventsArray.Count);
        }
        private int extractHealthRuleViolations(JobConfiguration jobConfiguration, JobTarget jobTarget, ControllerApi controllerApi)
        {
            JArray listOfHealthRuleViolations = new JArray();

            if (File.Exists(FilePathMap.ApplicationHealthRuleViolationsDataFilePath(jobTarget)) == false)
            {
                foreach (JobTimeRange jobTimeRange in jobConfiguration.Input.HourlyTimeRanges)
                {
                    long fromTimeUnix = UnixTimeHelper.ConvertToUnixTimestamp(jobTimeRange.From);
                    long toTimeUnix   = UnixTimeHelper.ConvertToUnixTimestamp(jobTimeRange.To);

                    string healthRuleViolationsJSON = controllerApi.GetApplicationHealthRuleViolations(jobTarget.ApplicationID, fromTimeUnix, toTimeUnix);
                    if (healthRuleViolationsJSON != String.Empty)
                    {
                        try
                        {
                            // Load health rule violations
                            JArray healthRuleViolationsInHourArray = JArray.Parse(healthRuleViolationsJSON);
                            foreach (JObject healthRuleViolationObject in healthRuleViolationsInHourArray)
                            {
                                listOfHealthRuleViolations.Add(healthRuleViolationObject);
                            }
                        }
                        catch (Exception)
                        {
                            logger.Warn("Unable to parse JSON for HR Violations Application={0}, From={1}, To={2}", jobTarget.ApplicationID, fromTimeUnix, toTimeUnix);
                        }
                    }
                }

                if (listOfHealthRuleViolations.Count > 0)
                {
                    FileIOHelper.WriteJArrayToFile(listOfHealthRuleViolations, FilePathMap.ApplicationHealthRuleViolationsDataFilePath(jobTarget));

                    logger.Info("{0} health rule violations from {1:o} to {2:o}", listOfHealthRuleViolations.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To);
                    loggerConsole.Info("{0} health rule violations", listOfHealthRuleViolations.Count);
                }
            }

            return(listOfHealthRuleViolations.Count);
        }
Ejemplo n.º 6
0
        private void extractListOfMetrics(
            JobTarget jobTarget,
            JobConfiguration jobConfiguration,
            string metricPathPrefix,
            string fileNamePrefix,
            int maxDepth)
        {
            using (ControllerApi controllerApi = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword)))
            {
                DateTime startTime = jobConfiguration.Input.HourlyTimeRanges[jobConfiguration.Input.HourlyTimeRanges.Count - 1].From;
                DateTime endTime   = jobConfiguration.Input.HourlyTimeRanges[jobConfiguration.Input.HourlyTimeRanges.Count - 1].To;

                StringBuilder sbMetricPath = new StringBuilder(128);
                sbMetricPath.Append(metricPathPrefix);

                for (int currentDepth = 0; currentDepth <= maxDepth; currentDepth++)
                {
                    sbMetricPath.Append("|*");

                    string metricPath = sbMetricPath.ToString();
                    loggerConsole.Trace("Depth {0:00}/{1:00}, {2}", currentDepth, maxDepth, metricPath);
                    logger.Info("Retrieving metric lists for Application {0}({1}), Metric='{2}', From {3:o}, To {4:o}", jobTarget.Application, jobTarget.ApplicationID, metricPath, startTime, endTime);

                    string metricsJson = String.Empty;

                    string metricsDataFilePath = FilePathMap.MetricsListDataFilePath(jobTarget, fileNamePrefix, currentDepth);
                    if (File.Exists(metricsDataFilePath) == false)
                    {
                        metricsJson = controllerApi.GetMetricData(
                            jobTarget.ApplicationID,
                            metricPath,
                            UnixTimeHelper.ConvertToUnixTimestamp(startTime),
                            UnixTimeHelper.ConvertToUnixTimestamp(endTime),
                            true);

                        FileIOHelper.SaveFileToPath(metricsJson, metricsDataFilePath);
                    }
                }
            }
        }
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            try
            {
                if (this.ShouldExecute(programOptions, jobConfiguration) == false)
                {
                    return(true);
                }

                if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_APM) == 0)
                {
                    logger.Warn("No {0} targets to process", APPLICATION_TYPE_APM);
                    loggerConsole.Warn("No {0} targets to process", APPLICATION_TYPE_APM);

                    return(true);
                }

                // Process each target
                for (int i = 0; i < jobConfiguration.Target.Count; i++)
                {
                    Stopwatch stopWatchTarget = new Stopwatch();
                    stopWatchTarget.Start();

                    JobTarget jobTarget = jobConfiguration.Target[i];

                    if (jobTarget.Type != null && jobTarget.Type.Length > 0 && jobTarget.Type != APPLICATION_TYPE_APM)
                    {
                        continue;
                    }

                    StepTiming stepTimingTarget = new StepTiming();
                    stepTimingTarget.Controller      = jobTarget.Controller;
                    stepTimingTarget.ApplicationName = jobTarget.Application;
                    stepTimingTarget.ApplicationID   = jobTarget.ApplicationID;
                    stepTimingTarget.JobFileName     = programOptions.OutputJobFilePath;
                    stepTimingTarget.StepName        = jobConfiguration.Status.ToString();
                    stepTimingTarget.StepID          = (int)jobConfiguration.Status;
                    stepTimingTarget.StartTime       = DateTime.Now;

                    stepTimingTarget.NumEntities = 9;

                    try
                    {
                        this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1);

                        #region Prepare time range

                        long fromTimeUnix        = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.HourlyTimeRanges[jobConfiguration.Input.HourlyTimeRanges.Count - 1].From);
                        long toTimeUnix          = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.HourlyTimeRanges[jobConfiguration.Input.HourlyTimeRanges.Count - 1].To);
                        long differenceInMinutes = (toTimeUnix - fromTimeUnix) / (60000);

                        #endregion

                        // Set up controller access
                        using (ControllerApi controllerApi = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword)))
                        {
                            #region Application

                            loggerConsole.Info("Application Name");

                            string applicationJSON = controllerApi.GetAPMApplication(jobTarget.ApplicationID);
                            if (applicationJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(applicationJSON, FilePathMap.APMApplicationDataFilePath(jobTarget));
                            }

                            #endregion

                            #region Tiers

                            loggerConsole.Info("List of Tiers");

                            string tiersJSON = controllerApi.GetAPMTiers(jobTarget.ApplicationID);
                            if (tiersJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(tiersJSON, FilePathMap.APMTiersDataFilePath(jobTarget));
                            }

                            #endregion

                            #region Nodes

                            loggerConsole.Info("List of Nodes");

                            string nodesJSON = controllerApi.GetAPMNodes(jobTarget.ApplicationID);
                            if (nodesJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(nodesJSON, FilePathMap.APMNodesDataFilePath(jobTarget));
                            }

                            #endregion

                            #region Backends

                            loggerConsole.Info("List of Backends");

                            string backendsJSON = controllerApi.GetAPMBackends(jobTarget.ApplicationID);
                            if (backendsJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(backendsJSON, FilePathMap.APMBackendsDataFilePath(jobTarget));
                            }

                            controllerApi.PrivateApiLogin();
                            backendsJSON = controllerApi.GetAPMBackendsAdditionalDetail(jobTarget.ApplicationID);
                            if (backendsJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(backendsJSON, FilePathMap.APMBackendsDetailDataFilePath(jobTarget));
                            }

                            List <AppDRESTBackend> backendsList = FileIOHelper.LoadListOfObjectsFromFile <AppDRESTBackend>(FilePathMap.APMBackendsDataFilePath(jobTarget));
                            if (backendsList != null)
                            {
                                loggerConsole.Info("DBMon Mappings for Backends ({0} entities)", backendsList.Count);

                                int j = 0;

                                var listOfBackendsInHourChunks = backendsList.BreakListIntoChunks(ENTITIES_EXTRACT_NUMBER_OF_BACKENDS_TO_PROCESS_PER_THREAD);

                                ParallelOptions parallelOptions = new ParallelOptions();
                                if (programOptions.ProcessSequentially == true)
                                {
                                    parallelOptions.MaxDegreeOfParallelism = 1;
                                }
                                else
                                {
                                    parallelOptions.MaxDegreeOfParallelism = BACKEND_PROPERTIES_EXTRACT_NUMBER_OF_THREADS;
                                }

                                Parallel.ForEach <List <AppDRESTBackend>, int>(
                                    listOfBackendsInHourChunks,
                                    parallelOptions,
                                    () => 0,
                                    (listOfBackendsInHourChunk, loop, subtotal) =>
                                {
                                    // Set up controller access
                                    ControllerApi controllerApiParallel = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword));
                                    // Login into private API
                                    controllerApiParallel.PrivateApiLogin();

                                    foreach (AppDRESTBackend backend in listOfBackendsInHourChunk)
                                    {
                                        if (File.Exists(FilePathMap.APMBackendToDBMonMappingDataFilePath(jobTarget, backend)) == false)
                                        {
                                            string backendToDBMonMappingJSON = controllerApi.GetAPMBackendToDBMonMapping(backend.id);
                                            if (backendToDBMonMappingJSON != String.Empty)
                                            {
                                                FileIOHelper.SaveFileToPath(backendToDBMonMappingJSON, FilePathMap.APMBackendToDBMonMappingDataFilePath(jobTarget, backend));
                                            }
                                        }
                                    }

                                    return(listOfBackendsInHourChunk.Count);
                                },
                                    (finalResult) =>
                                {
                                    Interlocked.Add(ref j, finalResult);
                                    Console.Write("[{0}].", j);
                                }
                                    );

                                loggerConsole.Info("Completed {0} Backends", backendsList.Count);

                                stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + backendsList.Count;
                            }

                            #endregion

                            #region Business Transactions

                            loggerConsole.Info("List of Business Transactions");

                            string businessTransactionsJSON = controllerApi.GetAPMBusinessTransactions(jobTarget.ApplicationID);
                            if (businessTransactionsJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(businessTransactionsJSON, FilePathMap.APMBusinessTransactionsDataFilePath(jobTarget));
                            }

                            #endregion

                            #region Service Endpoints

                            loggerConsole.Info("List of Service Endpoints");

                            string serviceEndPointsJSON = controllerApi.GetAPMServiceEndpoints(jobTarget.ApplicationID);
                            if (serviceEndPointsJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(serviceEndPointsJSON, FilePathMap.APMServiceEndpointsDataFilePath(jobTarget));
                            }

                            controllerApi.PrivateApiLogin();
                            serviceEndPointsJSON = controllerApi.GetAPMServiceEndpointsAdditionalDetail(jobTarget.ApplicationID);
                            if (serviceEndPointsJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(serviceEndPointsJSON, FilePathMap.APMServiceEndpointsDetailDataFilePath(jobTarget));
                            }

                            #endregion

                            #region Errors

                            loggerConsole.Info("List of Errors");

                            string errorsJSON = controllerApi.GetAPMErrors(jobTarget.ApplicationID);
                            if (errorsJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(errorsJSON, FilePathMap.APMErrorsDataFilePath(jobTarget));
                            }

                            #endregion

                            #region Information Points

                            loggerConsole.Info("List of Information Points");

                            string informationPointsJSON = controllerApi.GetAPMInformationPoints(jobTarget.ApplicationID);
                            if (informationPointsJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(informationPointsJSON, FilePathMap.APMInformationPointsDataFilePath(jobTarget));
                            }

                            controllerApi.PrivateApiLogin();
                            string informationPointsDetailJSON = controllerApi.GetAPMInformationPointsAdditionalDetail(jobTarget.ApplicationID);
                            if (informationPointsDetailJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(informationPointsDetailJSON, FilePathMap.APMInformationPointsDetailDataFilePath(jobTarget));
                            }

                            #endregion

                            #region Node Properties

                            List <AppDRESTNode> nodesList = FileIOHelper.LoadListOfObjectsFromFile <AppDRESTNode>(FilePathMap.APMNodesDataFilePath(jobTarget));
                            if (nodesList != null)
                            {
                                loggerConsole.Info("Node Properties for Nodes ({0} entities)", nodesList.Count);

                                int j = 0;

                                var listOfNodesInHourChunks = nodesList.BreakListIntoChunks(ENTITIES_EXTRACT_NUMBER_OF_NODES_TO_PROCESS_PER_THREAD);

                                ParallelOptions parallelOptions = new ParallelOptions();
                                if (programOptions.ProcessSequentially == true)
                                {
                                    parallelOptions.MaxDegreeOfParallelism = 1;
                                }
                                else
                                {
                                    parallelOptions.MaxDegreeOfParallelism = NODE_PROPERTIES_EXTRACT_NUMBER_OF_THREADS;
                                }

                                Parallel.ForEach <List <AppDRESTNode>, int>(
                                    listOfNodesInHourChunks,
                                    parallelOptions,
                                    () => 0,
                                    (listOfNodesInHourChunk, loop, subtotal) =>
                                {
                                    // Set up controller access
                                    ControllerApi controllerApiParallel = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword));

                                    // Login into private API
                                    controllerApiParallel.PrivateApiLogin();

                                    foreach (AppDRESTNode node in listOfNodesInHourChunk)
                                    {
                                        if (File.Exists(FilePathMap.APMNodeRuntimePropertiesDataFilePath(jobTarget, node)) == false)
                                        {
                                            string nodePropertiesJSON = controllerApi.GetAPMNodeProperties(node.id);
                                            if (nodePropertiesJSON != String.Empty)
                                            {
                                                FileIOHelper.SaveFileToPath(nodePropertiesJSON, FilePathMap.APMNodeRuntimePropertiesDataFilePath(jobTarget, node));
                                            }
                                        }
                                        if (File.Exists(FilePathMap.APMNodeMetadataDataFilePath(jobTarget, node)) == false)
                                        {
                                            string nodeMetadataJSON = controllerApi.GetAPMNodeMetadata(jobTarget.ApplicationID, node.id);
                                            if (nodeMetadataJSON != String.Empty)
                                            {
                                                FileIOHelper.SaveFileToPath(nodeMetadataJSON, FilePathMap.APMNodeMetadataDataFilePath(jobTarget, node));
                                            }
                                        }
                                    }

                                    return(listOfNodesInHourChunk.Count);
                                },
                                    (finalResult) =>
                                {
                                    Interlocked.Add(ref j, finalResult);
                                    Console.Write("[{0}].", j);
                                }
                                    );

                                loggerConsole.Info("Completed {0} Nodes", nodesList.Count);

                                stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + nodesList.Count;
                            }

                            #endregion

                            #region Backend to Tier Mappings

                            List <AppDRESTTier> tiersRESTList = FileIOHelper.LoadListOfObjectsFromFile <AppDRESTTier>(FilePathMap.APMTiersDataFilePath(jobTarget));
                            if (tiersRESTList != null)
                            {
                                loggerConsole.Info("Backend to Tier Mappings ({0} entities)", tiersRESTList.Count);

                                int j = 0;

                                foreach (AppDRESTTier tier in tiersRESTList)
                                {
                                    string backendMappingsJSON = controllerApi.GetAPMBackendToTierMapping(tier.id);
                                    if (backendMappingsJSON != String.Empty && backendMappingsJSON != "[ ]")
                                    {
                                        FileIOHelper.SaveFileToPath(backendMappingsJSON, FilePathMap.APMBackendToTierMappingDataFilePath(jobTarget, tier));
                                    }

                                    if (j % 10 == 0)
                                    {
                                        Console.Write("[{0}].", j);
                                    }
                                    j++;
                                }

                                loggerConsole.Info("Completed {0} Tiers", tiersRESTList.Count);

                                stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + tiersRESTList.Count;
                            }

                            #endregion

                            #region Overflow Business Transactions

                            if (tiersRESTList != null)
                            {
                                loggerConsole.Info("Contents of Overflow Business Transaction in Tiers ({0} entities)", tiersRESTList.Count);

                                int j = 0;

                                foreach (AppDRESTTier tier in tiersRESTList)
                                {
                                    JArray droppedBTsArray          = new JArray();
                                    JArray droppedBTsDebugModeArray = new JArray();

                                    bool noMoreBTs = false;
                                    long currentFetchedEventCount = 0;
                                    long endEventID = 0;
                                    while (noMoreBTs == false)
                                    {
                                        string batchOfBTsJSON = controllerApi.GetAPMBusinessTransactionsInOverflow(tier.id, currentFetchedEventCount, endEventID, fromTimeUnix, toTimeUnix, differenceInMinutes);

                                        if (batchOfBTsJSON != String.Empty)
                                        {
                                            JObject batchOfBTsContainer = JObject.Parse(batchOfBTsJSON);
                                            if (batchOfBTsContainer != null)
                                            {
                                                // Copy out both of the containers, not sure why there are multiple
                                                if (isTokenPropertyNull(batchOfBTsContainer, "droppedTransactionItemList") == false)
                                                {
                                                    foreach (JObject btObject in batchOfBTsContainer["droppedTransactionItemList"])
                                                    {
                                                        droppedBTsArray.Add(btObject);
                                                    }
                                                }
                                                if (isTokenPropertyNull(batchOfBTsContainer, "debugModeDroppedTransactionItemList") == false)
                                                {
                                                    foreach (JObject btObject in batchOfBTsContainer["debugModeDroppedTransactionItemList"])
                                                    {
                                                        droppedBTsDebugModeArray.Add(btObject);
                                                    }
                                                }

                                                currentFetchedEventCount = getLongValueFromJToken(batchOfBTsContainer, "eventSummariesCount");
                                                endEventID = getLongValueFromJToken(batchOfBTsContainer, "endEventId");

                                                if (currentFetchedEventCount == 0 || endEventID == 0)
                                                {
                                                    // Done getting batches
                                                    noMoreBTs = true;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            noMoreBTs = true;
                                        }
                                    }

                                    if (droppedBTsArray.Count > 0)
                                    {
                                        FileIOHelper.SaveFileToPath(droppedBTsArray.ToString(), FilePathMap.APMTierOverflowBusinessTransactionRegularDataFilePath(jobTarget, tier));
                                    }
                                    if (droppedBTsDebugModeArray.Count > 0)
                                    {
                                        FileIOHelper.SaveFileToPath(droppedBTsDebugModeArray.ToString(), FilePathMap.APMTierOverflowBusinessTransactionDebugDataFilePath(jobTarget, tier));
                                    }

                                    if (j % 10 == 0)
                                    {
                                        Console.Write("[{0}].", j);
                                    }
                                    j++;
                                }

                                loggerConsole.Info("Completed {0} Tiers", tiersRESTList.Count);
                            }

                            #endregion
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                        loggerConsole.Warn(ex);

                        return(false);
                    }
                    finally
                    {
                        stopWatchTarget.Stop();

                        this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget);

                        stepTimingTarget.EndTime    = DateTime.Now;
                        stepTimingTarget.Duration   = stopWatchTarget.Elapsed;
                        stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds;

                        List <StepTiming> stepTimings = new List <StepTiming>(1);
                        stepTimings.Add(stepTimingTarget);
                        FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
Ejemplo n.º 8
0
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            try
            {
                if (this.ShouldExecute(programOptions, jobConfiguration) == false)
                {
                    return(true);
                }

                if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_MOBILE) == 0)
                {
                    logger.Warn("No {0} targets to process", APPLICATION_TYPE_MOBILE);
                    loggerConsole.Warn("No {0} targets to process", APPLICATION_TYPE_MOBILE);

                    return(true);
                }

                #region Template comparisons

                if (jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Controller == BLANK_APPLICATION_CONTROLLER &&
                    jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Application == BLANK_APPLICATION_MOBILE)
                {
                    jobConfiguration.Target.Add(jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE);
                }
                else
                {
                    // Check if there is a valid reference application
                    JobTarget jobTargetReferenceApp = jobConfiguration.Target.Where(t =>
                                                                                    t.Type == APPLICATION_TYPE_MOBILE &&
                                                                                    String.Compare(t.Controller, jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Controller, StringComparison.InvariantCultureIgnoreCase) == 0 &&
                                                                                    String.Compare(t.Application, jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Application, StringComparison.InvariantCultureIgnoreCase) == 0).FirstOrDefault();
                    if (jobTargetReferenceApp == null)
                    {
                        // No valid reference, fall back to comparing against template
                        logger.Warn("Unable to find reference target {0}, will index default template", jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE);
                        loggerConsole.Warn("Unable to find reference target {0}, will index default template", jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE);

                        jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Controller  = BLANK_APPLICATION_CONTROLLER;
                        jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Application = BLANK_APPLICATION_MOBILE;
                        jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Type        = APPLICATION_TYPE_MOBILE;

                        jobConfiguration.Target.Add(jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE);
                    }
                }

                #endregion

                bool reportFolderCleaned = false;

                // Process each target
                for (int i = 0; i < jobConfiguration.Target.Count; i++)
                {
                    Stopwatch stopWatchTarget = new Stopwatch();
                    stopWatchTarget.Start();

                    JobTarget jobTarget = jobConfiguration.Target[i];

                    if (jobTarget.Type != null && jobTarget.Type.Length > 0 && jobTarget.Type != APPLICATION_TYPE_MOBILE)
                    {
                        continue;
                    }

                    StepTiming stepTimingTarget = new StepTiming();
                    stepTimingTarget.Controller      = jobTarget.Controller;
                    stepTimingTarget.ApplicationName = jobTarget.Application;
                    stepTimingTarget.ApplicationID   = jobTarget.ApplicationID;
                    stepTimingTarget.JobFileName     = programOptions.OutputJobFilePath;
                    stepTimingTarget.StepName        = jobConfiguration.Status.ToString();
                    stepTimingTarget.StepID          = (int)jobConfiguration.Status;
                    stepTimingTarget.StartTime       = DateTime.Now;

                    try
                    {
                        this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1);

                        #region Preload list of detected entities

                        // For later cross-reference
                        List <ControllerApplication> controllerApplicationList = FileIOHelper.ReadListFromCSVFile <ControllerApplication>(FilePathMap.ControllerApplicationsIndexFilePath(jobTarget), new ControllerApplicationReportMap());

                        #endregion

                        #region Application Summary

                        MOBILEApplicationConfiguration applicationConfiguration = new MOBILEApplicationConfiguration();

                        loggerConsole.Info("Application Summary");

                        applicationConfiguration.Controller      = jobTarget.Controller;
                        applicationConfiguration.ControllerLink  = String.Format(DEEPLINK_CONTROLLER, applicationConfiguration.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES);
                        applicationConfiguration.ApplicationName = jobTarget.Application;
                        applicationConfiguration.ApplicationID   = jobTarget.ApplicationID;
                        applicationConfiguration.ApplicationLink = String.Format(DEEPLINK_APM_APPLICATION, applicationConfiguration.Controller, applicationConfiguration.ApplicationID, DEEPLINK_TIMERANGE_LAST_15_MINUTES);
                        if (controllerApplicationList != null)
                        {
                            ControllerApplication controllerApplication = controllerApplicationList.Where(a => a.Type == APPLICATION_TYPE_MOBILE && a.ApplicationID == jobTarget.ApplicationID).FirstOrDefault();
                            if (controllerApplication != null)
                            {
                                applicationConfiguration.ApplicationDescription = controllerApplication.Description;
                            }
                        }

                        // Application Key
                        JObject appKeyObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.MOBILEApplicationKeyDataFilePath(jobTarget));
                        if (appKeyObject != null)
                        {
                            applicationConfiguration.ApplicationKey = getStringValueFromJToken(appKeyObject, "appKey");
                        }

                        // Monitoring State
                        string monitoringState = FileIOHelper.ReadFileFromPath(FilePathMap.MOBILEApplicationMonitoringStateDataFilePath(jobTarget));
                        if (monitoringState != String.Empty)
                        {
                            bool parsedBool = false;
                            Boolean.TryParse(monitoringState, out parsedBool);
                            applicationConfiguration.IsEnabled = parsedBool;
                        }

                        // Configuration Settings
                        JObject configurationSettingsObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.MOBILEAgentPageSettingsRulesDataFilePath(jobTarget));
                        if (configurationSettingsObject != null)
                        {
                            if (isTokenPropertyNull(configurationSettingsObject, "thresholds") == false)
                            {
                                applicationConfiguration.SlowThresholdType = getStringValueFromJToken(configurationSettingsObject["thresholds"]["slowThreshold"], "type");
                                applicationConfiguration.SlowThreshold     = getIntValueFromJToken(configurationSettingsObject["thresholds"]["slowThreshold"], "value");

                                applicationConfiguration.VerySlowThresholdType = getStringValueFromJToken(configurationSettingsObject["thresholds"]["verySlowThreshold"], "type");
                                applicationConfiguration.VerySlowThreshold     = getIntValueFromJToken(configurationSettingsObject["thresholds"]["verySlowThreshold"], "value");

                                applicationConfiguration.StallThresholdType = getStringValueFromJToken(configurationSettingsObject["thresholds"]["stallThreshold"], "type");
                                applicationConfiguration.StallThreshold     = getIntValueFromJToken(configurationSettingsObject["thresholds"]["stallThreshold"], "value");
                            }
                            applicationConfiguration.Percentiles    = getStringValueOfObjectFromJToken(configurationSettingsObject, "percentileMetrics", true);
                            applicationConfiguration.SessionTimeout = getIntValueFromJToken(configurationSettingsObject["sessionsMonitor"], "sessionTimeoutMins");

                            applicationConfiguration.CrashThreshold = getIntValueFromJToken(configurationSettingsObject["crashAlerts"], "threshold");

                            applicationConfiguration.IsIPDisplayed    = getBoolValueFromJToken(configurationSettingsObject, "ipAddressDisplayed");
                            applicationConfiguration.EnableScreenshot = getBoolValueFromJToken(configurationSettingsObject["agentConfigData"], "enableScreenshot");
                            applicationConfiguration.AutoScreenshot   = getBoolValueFromJToken(configurationSettingsObject["agentConfigData"], "autoScreenshot");
                            applicationConfiguration.UseCellular      = getBoolValueFromJToken(configurationSettingsObject["agentConfigData"], "screenshotUseCellular");
                        }

                        #endregion

                        #region Network Requests

                        List <MOBILENetworkRequestRule> networkRequestRulesList = new List <MOBILENetworkRequestRule>(128);

                        JObject networkRequestRulesObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.MOBILEAgentNetworkRequestsRulesDataFilePath(jobTarget));
                        if (networkRequestRulesObject != null)
                        {
                            if (isTokenPropertyNull(networkRequestRulesObject, "customNamingIncludeRules") == false)
                            {
                                JArray includeRulesArray = (JArray)networkRequestRulesObject["customNamingIncludeRules"];
                                foreach (JObject includeRuleObject in includeRulesArray)
                                {
                                    MOBILENetworkRequestRule networkRequestRule = fillNetworkRequestRule(includeRuleObject, jobTarget);
                                    if (networkRequestRule != null)
                                    {
                                        networkRequestRule.DetectionType = "INCLUDE";

                                        networkRequestRulesList.Add(networkRequestRule);
                                    }
                                }
                            }

                            if (isTokenPropertyNull(networkRequestRulesObject, "customNamingExcludeRules") == false)
                            {
                                JArray excludeRulesArray = (JArray)networkRequestRulesObject["customNamingExcludeRules"];
                                foreach (JObject excludeRuleObject in excludeRulesArray)
                                {
                                    MOBILENetworkRequestRule networkRequestRule = fillNetworkRequestRule(excludeRuleObject, jobTarget);
                                    if (networkRequestRule != null)
                                    {
                                        networkRequestRule.DetectionType = "EXCLUDE";

                                        networkRequestRulesList.Add(networkRequestRule);
                                    }
                                }
                            }
                        }

                        // Sort them
                        networkRequestRulesList = networkRequestRulesList.OrderBy(o => o.DetectionType).ThenBy(o => o.Priority).ToList();
                        FileIOHelper.WriteListToCSVFile(networkRequestRulesList, new MOBILENetworkRequestRuleReportMap(), FilePathMap.MOBILENetworkRequestRulesIndexFilePath(jobTarget));

                        loggerConsole.Info("Completed {0} Rules", networkRequestRulesList.Count);


                        #endregion

                        #region Application Settings

                        if (networkRequestRulesList != null)
                        {
                            applicationConfiguration.NumNetworkRulesInclude = networkRequestRulesList.Count(r => r.DetectionType == "INCLUDE");
                            applicationConfiguration.NumNetworkRulesExclude = networkRequestRulesList.Count(r => r.DetectionType == "EXCLUDE");
                        }

                        List <MOBILEApplicationConfiguration> applicationConfigurationsList = new List <MOBILEApplicationConfiguration>(1);
                        applicationConfigurationsList.Add(applicationConfiguration);
                        FileIOHelper.WriteListToCSVFile(applicationConfigurationsList, new MOBILEApplicationConfigurationReportMap(), FilePathMap.MOBILEApplicationConfigurationIndexFilePath(jobTarget));

                        stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + applicationConfigurationsList.Count;

                        #endregion

                        #region Combine All for Report CSV

                        // If it is the first one, clear out the combined folder
                        if (reportFolderCleaned == false)
                        {
                            FileIOHelper.DeleteFolder(FilePathMap.MOBILEConfigurationReportFolderPath());
                            Thread.Sleep(1000);
                            FileIOHelper.CreateFolder(FilePathMap.WEBConfigurationReportFolderPath());
                            reportFolderCleaned = true;
                        }

                        // Append all the individual report files into one
                        if (File.Exists(FilePathMap.MOBILEApplicationConfigurationIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.MOBILEApplicationConfigurationIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.MOBILEApplicationConfigurationReportFilePath(), FilePathMap.MOBILEApplicationConfigurationIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.MOBILENetworkRequestRulesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.MOBILENetworkRequestRulesIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.MOBILENetworkRequestRulesReportFilePath(), FilePathMap.MOBILENetworkRequestRulesIndexFilePath(jobTarget));
                        }

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                        loggerConsole.Warn(ex);

                        return(false);
                    }
                    finally
                    {
                        stopWatchTarget.Stop();

                        this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget);

                        stepTimingTarget.EndTime    = DateTime.Now;
                        stepTimingTarget.Duration   = stopWatchTarget.Elapsed;
                        stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds;

                        List <StepTiming> stepTimings = new List <StepTiming>(1);
                        stepTimings.Add(stepTimingTarget);
                        FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
                    }
                }

                // Remove all templates from the list
                jobConfiguration.Target.RemoveAll(t => t.Controller == BLANK_APPLICATION_CONTROLLER);

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
        private int extractSnapshots(
            JobConfiguration jobConfiguration,
            JobTarget jobTarget,
            ControllerApi controllerApi,
            List <JToken> entityList,
            List <AppDRESTTier> tiersNodeJSList,
            bool progressToConsole)
        {
            int j = 0;

            foreach (JToken snapshot in entityList)
            {
                // Only do first in chain
                if ((bool)snapshot["firstInChain"] == true)
                {
                    logger.Info("Retrieving snapshot for Application {0}, Tier {1}, Business Transaction {2}, RequestGUID {3}", jobTarget.Application, snapshot["applicationComponentName"], snapshot["businessTransactionName"], snapshot["requestGUID"]);

                    #region Target step variables

                    DateTime snapshotTime = UnixTimeHelper.ConvertFromUnixTimestamp((long)snapshot["serverStartTime"]);

                    string snapshotFolderPath = FilePathMap.SnapshotDataFolderPath(
                        jobTarget,
                        snapshot["applicationComponentName"].ToString(), (long)snapshot["applicationComponentId"],
                        snapshot["businessTransactionName"].ToString(), (long)snapshot["businessTransactionId"],
                        snapshotTime,
                        snapshot["userExperience"].ToString(),
                        snapshot["requestGUID"].ToString());

                    // Must strip out the milliseconds, because the segment list retrieval doesn't seem to like them in the datetimes
                    DateTime snapshotTimeFrom = snapshotTime.AddMinutes(-30).AddMilliseconds(snapshotTime.Millisecond * -1);
                    DateTime snapshotTimeTo   = snapshotTime.AddMinutes(30).AddMilliseconds(snapshotTime.Millisecond * -1);

                    long fromTimeUnix        = UnixTimeHelper.ConvertToUnixTimestamp(snapshotTimeFrom);
                    long toTimeUnix          = UnixTimeHelper.ConvertToUnixTimestamp(snapshotTimeTo);
                    int  differenceInMinutes = (int)(snapshotTimeTo - snapshotTimeFrom).TotalMinutes;

                    #endregion

                    #region Get Snapshot Flowmap

                    // Get snapshot flow map
                    // Commenting this out until the time I decide to build visual representation of it, until then it is not needed
                    //string snapshotFlowmapDataFilePath = Path.Combine(snapshotFolderPath, EXTRACT_SNAPSHOT_FLOWMAP_FILE_NAME);

                    //if (File.Exists(snapshotFlowmapDataFilePath) == false)
                    //{
                    //    string snapshotFlowmapJson = controllerApi.GetFlowmapSnapshot(jobTarget.ApplicationID, (int)snapshot["businessTransactionId"], snapshot["requestGUID"].ToString(), fromTimeUnix, toTimeUnix, differenceInMinutes);
                    //    if (snapshotFlowmapJson != String.Empty) FileIOHelper.SaveFileToPath(snapshotFlowmapJson, snapshotFlowmapDataFilePath);
                    //}

                    #endregion

                    #region Get List of Segments

                    // Get list of segments
                    string snapshotSegmentsDataFilePath = FilePathMap.SnapshotSegmentsDataFilePath(snapshotFolderPath);

                    if (File.Exists(snapshotSegmentsDataFilePath) == false)
                    {
                        string snapshotSegmentsJson = controllerApi.GetSnapshotSegments(snapshot["requestGUID"].ToString(), snapshotTimeFrom, snapshotTimeTo, differenceInMinutes);
                        if (snapshotSegmentsJson != String.Empty)
                        {
                            FileIOHelper.SaveFileToPath(snapshotSegmentsJson, snapshotSegmentsDataFilePath);
                        }
                    }

                    #endregion

                    #region Get Details for Each Segment

                    JArray snapshotSegmentsList = FileIOHelper.LoadJArrayFromFile(snapshotSegmentsDataFilePath);
                    if (snapshotSegmentsList != null)
                    {
                        // Get details for segment
                        foreach (JToken snapshotSegment in snapshotSegmentsList)
                        {
                            string snapshotSegmentDataFilePath = FilePathMap.SnapshotSegmentDataFilePath(snapshotFolderPath, snapshotSegment["id"].ToString());

                            if (File.Exists(snapshotSegmentDataFilePath) == false)
                            {
                                string snapshotSegmentJson = controllerApi.GetSnapshotSegmentDetails((long)snapshotSegment["id"], fromTimeUnix, toTimeUnix, differenceInMinutes);
                                if (snapshotSegmentJson != String.Empty)
                                {
                                    FileIOHelper.SaveFileToPath(snapshotSegmentJson, snapshotSegmentDataFilePath);
                                }
                            }
                        }

                        // Get errors for segment
                        foreach (JToken snapshotSegment in snapshotSegmentsList)
                        {
                            string snapshotSegmentErrorFilePath = FilePathMap.SnapshotSegmentErrorDataFilePath(snapshotFolderPath, snapshotSegment["id"].ToString());

                            if (File.Exists(snapshotSegmentErrorFilePath) == false && (bool)snapshotSegment["errorOccurred"] == true)
                            {
                                string snapshotSegmentJson = controllerApi.GetSnapshotSegmentErrors((long)snapshotSegment["id"], fromTimeUnix, toTimeUnix, differenceInMinutes);
                                if (snapshotSegmentJson != String.Empty)
                                {
                                    // "[ ]" == empty data. Don't create the file
                                    if (snapshotSegmentJson.Length > 3)
                                    {
                                        FileIOHelper.SaveFileToPath(snapshotSegmentJson, snapshotSegmentErrorFilePath);
                                    }
                                }
                            }
                        }

                        // Get call graphs for segment
                        foreach (JToken snapshotSegment in snapshotSegmentsList)
                        {
                            string snapshotSegmentCallGraphFilePath = FilePathMap.SnapshotSegmentCallGraphDataFilePath(snapshotFolderPath, snapshotSegment["id"].ToString());

                            if (File.Exists(snapshotSegmentCallGraphFilePath) == false && ((bool)snapshotSegment["fullCallgraph"] == true || (bool)snapshotSegment["delayedCallGraph"] == true))
                            {
                                // If the tier is Node.JS, the call graphs come from Process Snapshot
                                bool   getProcessCallGraph = false;
                                string processRequestGUID  = String.Empty;
                                if (tiersNodeJSList != null && tiersNodeJSList.Count > 0)
                                {
                                    // Is this a Node.JS tier?
                                    if (tiersNodeJSList.Count(t => t.id == (long)snapshotSegment["applicationComponentId"]) > 0)
                                    {
                                        // Yes, it is

                                        // Is there a process snapshot? Check Transaction Properties for its value
                                        string  snapshotSegmentDataFilePath = FilePathMap.SnapshotSegmentDataFilePath(snapshotFolderPath, snapshotSegment["id"].ToString());
                                        JObject snapshotSegmentDetail       = FileIOHelper.LoadJObjectFromFile(snapshotSegmentDataFilePath);
                                        if (snapshotSegmentDetail != null)
                                        {
                                            if (snapshotSegmentDetail["transactionProperties"].HasValues == true)
                                            {
                                                foreach (JToken transactionPropertyToken in snapshotSegmentDetail["transactionProperties"])
                                                {
                                                    if (transactionPropertyToken["name"].ToString() == "Process Snapshot GUIDs")
                                                    {
                                                        getProcessCallGraph = true;
                                                        processRequestGUID  = transactionPropertyToken["value"].ToString();
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                // Ok, now either get call graph the usual way or process snapshot call graph
                                if (getProcessCallGraph == true && processRequestGUID.Length > 0)
                                {
                                    string snapshotSegmentJson = controllerApi.GetProcessSnapshotCallGraph(processRequestGUID, fromTimeUnix, toTimeUnix, differenceInMinutes);
                                    if (snapshotSegmentJson != String.Empty)
                                    {
                                        FileIOHelper.SaveFileToPath(snapshotSegmentJson, snapshotSegmentCallGraphFilePath);
                                    }
                                }
                                else
                                {
                                    string snapshotSegmentJson = controllerApi.GetSnapshotSegmentCallGraph((long)snapshotSegment["id"], fromTimeUnix, toTimeUnix, differenceInMinutes);
                                    if (snapshotSegmentJson != String.Empty)
                                    {
                                        FileIOHelper.SaveFileToPath(snapshotSegmentJson, snapshotSegmentCallGraphFilePath);
                                    }
                                }
                            }
                        }
                    }

                    #endregion
                }

                if (progressToConsole == true)
                {
                    j++;
                    if (j % 10 == 0)
                    {
                        Console.Write("[{0}].", j);
                    }
                }
            }

            return(entityList.Count);
        }
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            try
            {
                if (this.ShouldExecute(jobConfiguration) == false)
                {
                    return(true);
                }

                // Process each Controller once
                int i           = 0;
                var controllers = jobConfiguration.Target.GroupBy(t => t.Controller);
                foreach (var controllerGroup in controllers)
                {
                    Stopwatch stopWatchTarget = new Stopwatch();
                    stopWatchTarget.Start();

                    JobTarget jobTarget = controllerGroup.ToList()[0];

                    StepTiming stepTimingTarget = new StepTiming();
                    stepTimingTarget.Controller      = jobTarget.Controller;
                    stepTimingTarget.ApplicationName = jobTarget.Application;
                    stepTimingTarget.ApplicationID   = jobTarget.ApplicationID;
                    stepTimingTarget.JobFileName     = programOptions.OutputJobFilePath;
                    stepTimingTarget.StepName        = jobConfiguration.Status.ToString();
                    stepTimingTarget.StepID          = (int)jobConfiguration.Status;
                    stepTimingTarget.StartTime       = DateTime.Now;

                    stepTimingTarget.NumEntities = 1;

                    try
                    {
                        this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1);

                        // Set up controller access
                        using (ControllerApi controllerApi = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword)))
                        {
                            #region Controller

                            loggerConsole.Info("Controller Version");

                            string controllerVersionXML = controllerApi.GetControllerVersion();
                            if (controllerVersionXML != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(controllerVersionXML, FilePathMap.ControllerVersionDataFilePath(jobTarget));
                            }

                            #endregion

                            #region APM Applications

                            loggerConsole.Info("APM Applications");

                            string applicationsJSON = controllerApi.GetAPMApplications();
                            if (applicationsJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(applicationsJSON, FilePathMap.APMApplicationsDataFilePath(jobTarget));
                            }

                            #endregion

                            #region Applications

                            loggerConsole.Info("All Applications");

                            controllerApi.PrivateApiLogin();

                            string applicationsAllJSON = controllerApi.GetAllApplicationsAllTypes();
                            if (applicationsAllJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(applicationsAllJSON, FilePathMap.AllApplicationsDataFilePath(jobTarget));
                            }

                            #endregion

                            #region Mobile Applications

                            loggerConsole.Info("Mobile Applications");

                            string applicationsMobileJSON = controllerApi.GetMOBILEApplications();
                            if (applicationsMobileJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(applicationsMobileJSON, FilePathMap.MOBILEApplicationsDataFilePath(jobTarget));
                            }

                            #endregion
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                        loggerConsole.Warn(ex);

                        return(false);
                    }
                    finally
                    {
                        stopWatchTarget.Stop();

                        this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget);

                        stepTimingTarget.EndTime    = DateTime.Now;
                        stepTimingTarget.Duration   = stopWatchTarget.Elapsed;
                        stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds;

                        List <StepTiming> stepTimings = new List <StepTiming>(1);
                        stepTimings.Add(stepTimingTarget);
                        FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
                    }

                    i++;
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            try
            {
                if (this.ShouldExecute(programOptions, jobConfiguration) == false)
                {
                    return(true);
                }

                if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_APM) == 0)
                {
                    logger.Warn("No {0} targets to process", APPLICATION_TYPE_APM);
                    loggerConsole.Warn("No {0} targets to process", APPLICATION_TYPE_APM);

                    return(true);
                }

                // Process each target
                for (int i = 0; i < jobConfiguration.Target.Count; i++)
                {
                    Stopwatch stopWatchTarget = new Stopwatch();
                    stopWatchTarget.Start();

                    JobTarget jobTarget = jobConfiguration.Target[i];

                    if (jobTarget.Type != null && jobTarget.Type.Length > 0 && jobTarget.Type != APPLICATION_TYPE_APM)
                    {
                        continue;
                    }

                    StepTiming stepTimingTarget = new StepTiming();
                    stepTimingTarget.Controller      = jobTarget.Controller;
                    stepTimingTarget.ApplicationName = jobTarget.Application;
                    stepTimingTarget.ApplicationID   = jobTarget.ApplicationID;
                    stepTimingTarget.JobFileName     = programOptions.OutputJobFilePath;
                    stepTimingTarget.StepName        = jobConfiguration.Status.ToString();
                    stepTimingTarget.StepID          = (int)jobConfiguration.Status;
                    stepTimingTarget.StartTime       = DateTime.Now;

                    try
                    {
                        this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1);

                        #region Target step variables

                        int numEntitiesTotal = 0;

                        #endregion

                        #region Prepare time range

                        long fromTimeUnix        = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.From);
                        long toTimeUnix          = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.To);
                        long differenceInMinutes = (toTimeUnix - fromTimeUnix) / (60000);

                        #endregion

                        ParallelOptions parallelOptions = new ParallelOptions();
                        if (programOptions.ProcessSequentially == true)
                        {
                            parallelOptions.MaxDegreeOfParallelism = 1;
                        }

                        Parallel.Invoke(parallelOptions,
                                        () =>
                        {
                            #region Application

                            loggerConsole.Info("Extract Flowmap for Application");

                            using (ControllerApi controllerApi = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword)))
                            {
                                controllerApi.PrivateApiLogin();

                                if (File.Exists(FilePathMap.ApplicationFlowmapDataFilePath(jobTarget, jobConfiguration.Input.TimeRange)) == false)
                                {
                                    string flowmapJson = controllerApi.GetFlowmapApplication(jobTarget.ApplicationID, fromTimeUnix, toTimeUnix, differenceInMinutes);
                                    if (flowmapJson != String.Empty)
                                    {
                                        FileIOHelper.SaveFileToPath(flowmapJson, FilePathMap.ApplicationFlowmapDataFilePath(jobTarget, jobConfiguration.Input.TimeRange));
                                    }
                                }

                                loggerConsole.Info("Completed Application");
                            }

                            // Removing as this doesn't seem to be a helpful report
                            //JobTimeRange jobTimeRangeLast = jobConfiguration.Input.HourlyTimeRanges[jobConfiguration.Input.HourlyTimeRanges.Count - 1];

                            //int differenceInMinutesForLastTimeRange = (int)((jobTimeRangeLast.To - jobTimeRangeLast.From).TotalMinutes);

                            //loggerConsole.Info("Extract Flowmap for Application in each minute in in last timerange ({0} minutes)", differenceInMinutesForLastTimeRange);

                            //int j = 0;

                            //Parallel.For(0,
                            //    differenceInMinutesForLastTimeRange,
                            //    parallelOptions,
                            //    () => 0,
                            //    (minute, loop, subtotal) =>
                            //    {
                            //        using (ControllerApi controllerApiLocal = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword)))
                            //        {
                            //            controllerApiLocal.PrivateApiLogin();

                            //            JobTimeRange thisMinuteJobTimeRange = new JobTimeRange();
                            //            thisMinuteJobTimeRange.From = jobTimeRangeLast.From.AddMinutes(minute);
                            //            thisMinuteJobTimeRange.To = jobTimeRangeLast.From.AddMinutes(minute + 1);

                            //            long fromTimeUnixLocal = UnixTimeHelper.ConvertToUnixTimestamp(thisMinuteJobTimeRange.From);
                            //            long toTimeUnixLocal = UnixTimeHelper.ConvertToUnixTimestamp(thisMinuteJobTimeRange.To);
                            //            long differenceInMinutesLocal = 1;

                            //            if (File.Exists(FilePathMap.ApplicationFlowmapDataFilePath(jobTarget, thisMinuteJobTimeRange)) == false)
                            //            {
                            //                string flowmapJson = controllerApiLocal.GetFlowmapApplication(jobTarget.ApplicationID, fromTimeUnixLocal, toTimeUnixLocal, differenceInMinutesLocal);
                            //                if (flowmapJson != String.Empty) FileIOHelper.SaveFileToPath(flowmapJson, FilePathMap.ApplicationFlowmapDataFilePath(jobTarget, thisMinuteJobTimeRange));
                            //            }
                            //            return 1;
                            //        }
                            //    },
                            //    (finalResult) =>
                            //    {
                            //        Interlocked.Add(ref j, finalResult);
                            //        if (j % 10 == 0)
                            //        {
                            //            Console.Write("[{0}].", j);
                            //        }
                            //    }
                            //);

                            //loggerConsole.Info("Completed Application in each minute {0} minutes", differenceInMinutesForLastTimeRange);

                            Interlocked.Add(ref numEntitiesTotal, 1);

                            #endregion
                        },
                                        () =>
                        {
                            #region Tiers

                            List <AppDRESTTier> tiersList = FileIOHelper.LoadListOfObjectsFromFile <AppDRESTTier>(FilePathMap.APMTiersDataFilePath(jobTarget));
                            if (tiersList != null)
                            {
                                loggerConsole.Info("Extract Flowmaps for Tiers ({0} entities)", tiersList.Count);

                                int j = 0;

                                Parallel.ForEach(
                                    tiersList,
                                    parallelOptions,
                                    () => 0,
                                    (tier, loop, subtotal) =>
                                {
                                    using (ControllerApi controllerApiLocal = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword)))
                                    {
                                        controllerApiLocal.PrivateApiLogin();

                                        if (File.Exists(FilePathMap.TierFlowmapDataFilePath(jobTarget, jobConfiguration.Input.TimeRange, tier)) == false)
                                        {
                                            string flowmapJson = controllerApiLocal.GetFlowmapTier(tier.id, fromTimeUnix, toTimeUnix, differenceInMinutes);
                                            if (flowmapJson != String.Empty)
                                            {
                                                FileIOHelper.SaveFileToPath(flowmapJson, FilePathMap.TierFlowmapDataFilePath(jobTarget, jobConfiguration.Input.TimeRange, tier));
                                            }
                                        }
                                        return(1);
                                    }
                                },
                                    (finalResult) =>
                                {
                                    Interlocked.Add(ref j, finalResult);
                                    if (j % 10 == 0)
                                    {
                                        Console.Write("[{0}].", j);
                                    }
                                }
                                    );

                                loggerConsole.Info("Completed {0} Tiers", tiersList.Count);

                                Interlocked.Add(ref numEntitiesTotal, tiersList.Count);
                            }
                            #endregion
                        },
                                        () =>
                        {
                            #region Nodes

                            List <AppDRESTNode> nodesList = FileIOHelper.LoadListOfObjectsFromFile <AppDRESTNode>(FilePathMap.APMNodesDataFilePath(jobTarget));
                            if (nodesList != null)
                            {
                                loggerConsole.Info("Extract Flowmaps for Nodes ({0} entities)", nodesList.Count);

                                int j = 0;

                                Parallel.ForEach(
                                    nodesList,
                                    parallelOptions,
                                    () => 0,
                                    (node, loop, subtotal) =>
                                {
                                    using (ControllerApi controllerApiLocal = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword)))
                                    {
                                        controllerApiLocal.PrivateApiLogin();

                                        if (File.Exists(FilePathMap.NodeFlowmapDataFilePath(jobTarget, jobConfiguration.Input.TimeRange, node)) == false)
                                        {
                                            string flowmapJson = controllerApiLocal.GetFlowmapNode(node.id, fromTimeUnix, toTimeUnix, differenceInMinutes);
                                            if (flowmapJson != String.Empty)
                                            {
                                                FileIOHelper.SaveFileToPath(flowmapJson, FilePathMap.NodeFlowmapDataFilePath(jobTarget, jobConfiguration.Input.TimeRange, node));
                                            }
                                        }
                                        return(1);
                                    }
                                },
                                    (finalResult) =>
                                {
                                    Interlocked.Add(ref j, finalResult);
                                    if (j % 10 == 0)
                                    {
                                        Console.Write("[{0}].", j);
                                    }
                                }
                                    );

                                loggerConsole.Info("Completed {0} Nodes", nodesList.Count);

                                Interlocked.Add(ref numEntitiesTotal, nodesList.Count);
                            }

                            #endregion
                        },
                                        () =>
                        {
                            #region Backends

                            List <AppDRESTBackend> backendsList = FileIOHelper.LoadListOfObjectsFromFile <AppDRESTBackend>(FilePathMap.APMBackendsDataFilePath(jobTarget));
                            if (backendsList != null)
                            {
                                loggerConsole.Info("Extract Flowmaps for Backends ({0} entities)", backendsList.Count);

                                int j = 0;

                                Parallel.ForEach(
                                    backendsList,
                                    parallelOptions,
                                    () => 0,
                                    (backend, loop, subtotal) =>
                                {
                                    ControllerApi controllerApiLocal = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword));
                                    controllerApiLocal.PrivateApiLogin();

                                    if (File.Exists(FilePathMap.BackendFlowmapDataFilePath(jobTarget, jobConfiguration.Input.TimeRange, backend)) == false)
                                    {
                                        string flowmapJson = controllerApiLocal.GetFlowmapBackend(backend.id, fromTimeUnix, toTimeUnix, differenceInMinutes);
                                        if (flowmapJson != String.Empty)
                                        {
                                            FileIOHelper.SaveFileToPath(flowmapJson, FilePathMap.BackendFlowmapDataFilePath(jobTarget, jobConfiguration.Input.TimeRange, backend));
                                        }
                                    }
                                    return(1);
                                },
                                    (finalResult) =>
                                {
                                    Interlocked.Add(ref j, finalResult);
                                    if (j % 10 == 0)
                                    {
                                        Console.Write("[{0}].", j);
                                    }
                                }
                                    );

                                loggerConsole.Info("Completed {0} Backends", backendsList.Count);

                                Interlocked.Add(ref numEntitiesTotal, backendsList.Count);
                            }

                            #endregion
                        },
                                        () =>
                        {
                            #region Business Transactions

                            List <AppDRESTBusinessTransaction> businessTransactionsList = FileIOHelper.LoadListOfObjectsFromFile <AppDRESTBusinessTransaction>(FilePathMap.APMBusinessTransactionsDataFilePath(jobTarget));
                            if (businessTransactionsList != null)
                            {
                                loggerConsole.Info("Extract Flowmaps for Business Transactions ({0} entities)", businessTransactionsList.Count);

                                int j = 0;

                                Parallel.ForEach(
                                    businessTransactionsList,
                                    parallelOptions,
                                    () => 0,
                                    (businessTransaction, loop, subtotal) =>
                                {
                                    using (ControllerApi controllerApiLocal = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword)))
                                    {
                                        controllerApiLocal.PrivateApiLogin();

                                        if (File.Exists(FilePathMap.BusinessTransactionFlowmapDataFilePath(jobTarget, jobConfiguration.Input.TimeRange, businessTransaction)) == false)
                                        {
                                            string flowmapJson = controllerApiLocal.GetFlowmapBusinessTransaction(jobTarget.ApplicationID, businessTransaction.id, fromTimeUnix, toTimeUnix, differenceInMinutes);
                                            if (flowmapJson != String.Empty)
                                            {
                                                FileIOHelper.SaveFileToPath(flowmapJson, FilePathMap.BusinessTransactionFlowmapDataFilePath(jobTarget, jobConfiguration.Input.TimeRange, businessTransaction));
                                            }
                                        }
                                        return(1);
                                    }
                                },
                                    (finalResult) =>
                                {
                                    Interlocked.Add(ref j, finalResult);
                                    if (j % 10 == 0)
                                    {
                                        Console.Write("[{0}].", j);
                                    }
                                }
                                    );

                                loggerConsole.Info("Completed {0} Business Transactions", businessTransactionsList.Count);

                                Interlocked.Add(ref numEntitiesTotal, businessTransactionsList.Count);
                            }

                            #endregion
                        }
                                        );

                        stepTimingTarget.NumEntities = numEntitiesTotal;
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                        loggerConsole.Warn(ex);

                        return(false);
                    }
                    finally
                    {
                        stopWatchTarget.Stop();

                        this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget);

                        stepTimingTarget.EndTime    = DateTime.Now;
                        stepTimingTarget.Duration   = stopWatchTarget.Elapsed;
                        stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds;

                        List <StepTiming> stepTimings = new List <StepTiming>(1);
                        stepTimings.Add(stepTimingTarget);
                        FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
Ejemplo n.º 12
0
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            try
            {
                if (this.ShouldExecute(jobConfiguration) == false)
                {
                    return(true);
                }

                bool reportFolderCleaned = false;

                // Process each Controller once
                int i           = 0;
                var controllers = jobConfiguration.Target.GroupBy(t => t.Controller);
                foreach (var controllerGroup in controllers)
                {
                    Stopwatch stopWatchTarget = new Stopwatch();
                    stopWatchTarget.Start();

                    JobTarget jobTarget = controllerGroup.ToList()[0];

                    StepTiming stepTimingTarget = new StepTiming();
                    stepTimingTarget.Controller      = jobTarget.Controller;
                    stepTimingTarget.ApplicationName = jobTarget.Application;
                    stepTimingTarget.ApplicationID   = jobTarget.ApplicationID;
                    stepTimingTarget.JobFileName     = programOptions.OutputJobFilePath;
                    stepTimingTarget.StepName        = jobConfiguration.Status.ToString();
                    stepTimingTarget.StepID          = (int)jobConfiguration.Status;
                    stepTimingTarget.StartTime       = DateTime.Now;

                    stepTimingTarget.NumEntities = 0;

                    try
                    {
                        this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1);

                        #region Dashboards List and Widgets List

                        loggerConsole.Info("Dashboards and their widgets");

                        List <Dashboard>             dashboardsList               = new List <Dashboard>(1024);
                        List <DashboardWidget>       dashboardWidgetsAllList      = new List <DashboardWidget>(10240);
                        List <DashboardMetricSeries> dashboardMetricSeriesAllList = new List <DashboardMetricSeries>(10240);

                        JArray dashboardsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.ControllerDashboards(jobTarget));
                        if (dashboardsArray != null)
                        {
                            int j = 0;
                            foreach (JObject dashboardObject in dashboardsArray)
                            {
                                Dashboard dashboard = new Dashboard();

                                dashboard.Controller = jobTarget.Controller;

                                dashboard.DashboardName = getStringValueFromJToken(dashboardObject, "name");
                                dashboard.Description   = getStringValueFromJToken(dashboardObject, "description");

                                dashboard.CanvasType         = getStringValueFromJToken(dashboardObject, "canvasType").Replace("CANVAS_TYPE_", "");
                                dashboard.TemplateEntityType = getStringValueFromJToken(dashboardObject, "templateEntityType");
                                dashboard.SecurityToken      = getStringValueFromJToken(dashboardObject, "securityToken");
                                if (dashboard.SecurityToken.Length > 0)
                                {
                                    dashboard.IsShared = true;
                                }
                                dashboard.IsSharingRevoked = getBoolValueFromJToken(dashboardObject, "sharingRevoked");
                                dashboard.IsTemplate       = getBoolValueFromJToken(dashboardObject, "template");

                                dashboard.Height = getIntValueFromJToken(dashboardObject, "height");
                                dashboard.Width  = getIntValueFromJToken(dashboardObject, "width");

                                dashboard.BackgroundColor = getIntValueFromJToken(dashboardObject, "backgroundColor").ToString("X6");

                                dashboard.MinutesBefore   = getIntValueFromJToken(dashboardObject, "minutesBeforeAnchorTime");
                                dashboard.RefreshInterval = getIntValueFromJToken(dashboardObject, "refreshInterval") / 1000;

                                dashboard.StartTimeUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(dashboardObject, "startTime"));
                                try { dashboard.StartTime = dashboard.StartTimeUtc.ToLocalTime(); } catch { }
                                dashboard.EndTimeUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(dashboardObject, "endTime"));
                                try { dashboard.EndTime = dashboard.EndTimeUtc.ToLocalTime(); } catch { }

                                dashboard.CreatedBy    = getStringValueFromJToken(dashboardObject, "createdBy");
                                dashboard.CreatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(dashboardObject, "createdOn"));
                                try { dashboard.CreatedOn = dashboard.CreatedOnUtc.ToLocalTime(); } catch { }
                                dashboard.UpdatedBy    = getStringValueFromJToken(dashboardObject, "modifiedBy");
                                dashboard.UpdatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(dashboardObject, "modifiedOn"));
                                try { dashboard.UpdatedOn = dashboard.UpdatedOnUtc.ToLocalTime(); } catch { }

                                dashboard.DashboardID = getLongValueFromJToken(dashboardObject, "id");

                                dashboard.DashboardLink = String.Format(DEEPLINK_DASHBOARD, dashboard.Controller, dashboard.DashboardID, DEEPLINK_TIMERANGE_LAST_15_MINUTES);

                                // Now parse the Widgets
                                JObject dashboardDetailObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.ControllerDashboard(jobTarget, dashboard.DashboardName, dashboard.DashboardID));
                                if (dashboardDetailObject != null && isTokenPropertyNull(dashboardDetailObject, "widgetTemplates") == false)
                                {
                                    List <DashboardWidget> dashboardWidgetsList = new List <DashboardWidget>(dashboardDetailObject["widgetTemplates"].Count());

                                    int dashboardWidgetIndex = 0;
                                    foreach (JObject dashboardWidgetObject in dashboardDetailObject["widgetTemplates"])
                                    {
                                        DashboardWidget dashboardWidget = new DashboardWidget();

                                        dashboardWidget.Controller    = dashboard.Controller;
                                        dashboardWidget.DashboardName = dashboard.DashboardName;
                                        dashboardWidget.DashboardID   = dashboard.DashboardID;
                                        dashboardWidget.CanvasType    = dashboard.CanvasType;
                                        dashboardWidget.WidgetType    = getStringValueFromJToken(dashboardWidgetObject, "widgetType");
                                        dashboardWidget.Index         = dashboardWidgetIndex;

                                        dashboardWidget.ApplicationName     = getStringValueFromJToken(dashboardWidgetObject["applicationReference"], "applicationName");
                                        dashboardWidget.EntityType          = getStringValueFromJToken(dashboardWidgetObject, "entityType");
                                        dashboardWidget.EntitySelectionType = getStringValueFromJToken(dashboardWidgetObject, "entitySelectionType");
                                        try
                                        {
                                            if (isTokenPropertyNull(dashboardWidgetObject, "entityReferences") == false)
                                            {
                                                string[] entities      = new string[dashboardWidgetObject["entityReferences"].Count()];
                                                int      entitiesIndex = 0;
                                                foreach (JToken entityReferenceToken in dashboardWidgetObject["entityReferences"])
                                                {
                                                    string        scopingEntityName = getStringValueFromJToken(entityReferenceToken, "scopingEntityName");
                                                    string        entityName        = getStringValueFromJToken(entityReferenceToken, "entityName");
                                                    string        subType           = getStringValueFromJToken(entityReferenceToken, "subtype");
                                                    StringBuilder sb = new StringBuilder(100);
                                                    sb.Append(scopingEntityName);
                                                    if (scopingEntityName.Length > 0)
                                                    {
                                                        sb.Append("/");
                                                    }
                                                    sb.Append(entityName);
                                                    if (subType.Length > 0)
                                                    {
                                                        sb.AppendFormat(" [{0}]", subType);
                                                    }
                                                    entities[entitiesIndex] = sb.ToString();
                                                    entitiesIndex++;;
                                                }
                                                dashboardWidget.SelectedEntities    = String.Join(";", entities);
                                                dashboardWidget.NumSelectedEntities = entities.Length;
                                            }
                                        }
                                        catch { }

                                        dashboardWidget.Title       = getStringValueFromJToken(dashboardWidgetObject, "title");
                                        dashboardWidget.Description = getStringValueFromJToken(dashboardWidgetObject, "description");
                                        dashboardWidget.Label       = getStringValueFromJToken(dashboardWidgetObject, "label");
                                        dashboardWidget.Text        = getStringValueFromJToken(dashboardWidgetObject, "text");
                                        dashboardWidget.TextAlign   = getStringValueFromJToken(dashboardWidgetObject, "textAlign");

                                        dashboardWidget.Width     = getIntValueFromJToken(dashboardWidgetObject, "width");
                                        dashboardWidget.Height    = getIntValueFromJToken(dashboardWidgetObject, "height");
                                        dashboardWidget.MinWidth  = getIntValueFromJToken(dashboardWidgetObject, "minHeight");
                                        dashboardWidget.MinHeight = getIntValueFromJToken(dashboardWidgetObject, "minWidth");
                                        dashboardWidget.X         = getIntValueFromJToken(dashboardWidgetObject, "x");
                                        dashboardWidget.Y         = getIntValueFromJToken(dashboardWidgetObject, "y");

                                        dashboardWidget.ForegroundColor = getIntValueFromJToken(dashboardWidgetObject, "color").ToString("X6");
                                        dashboardWidget.BackgroundColor = getIntValueFromJToken(dashboardWidgetObject, "backgroundColor").ToString("X6");
                                        dashboardWidget.BackgroundAlpha = getDoubleValueFromJToken(dashboardWidgetObject, "backgroundAlpha");

                                        dashboardWidget.BorderColor     = getIntValueFromJToken(dashboardWidgetObject, "borderColor").ToString("X6");
                                        dashboardWidget.BorderSize      = getIntValueFromJToken(dashboardWidgetObject, "borderThickness");
                                        dashboardWidget.IsBorderEnabled = getBoolValueFromJToken(dashboardWidgetObject, "borderEnabled");

                                        dashboardWidget.Margin = getIntValueFromJToken(dashboardWidgetObject, "margin");

                                        try { dashboardWidget.NumDataSeries = dashboardWidgetObject["dataSeriesTemplates"].Count(); } catch { }

                                        dashboardWidget.FontSize = getIntValueFromJToken(dashboardWidgetObject, "fontSize");

                                        dashboardWidget.MinutesBeforeAnchor = getIntValueFromJToken(dashboardWidgetObject, "minutesBeforeAnchorTime");

                                        dashboardWidget.VerticalAxisLabel   = getStringValueFromJToken(dashboardWidgetObject, "verticalAxisLabel");
                                        dashboardWidget.HorizontalAxisLabel = getStringValueFromJToken(dashboardWidgetObject, "horizontalAxisLabel");
                                        dashboardWidget.AxisType            = getStringValueFromJToken(dashboardWidgetObject, "axisType");
                                        dashboardWidget.IsMultipleYAxis     = getBoolValueFromJToken(dashboardWidgetObject, "multipleYAxis");
                                        dashboardWidget.StackMode           = getStringValueFromJToken(dashboardWidgetObject, "stackMode");

                                        dashboardWidget.AggregationType = getStringValueFromJToken(dashboardWidgetObject, "aggregationType");

                                        dashboardWidget.DrillDownURL             = getStringValueFromJToken(dashboardWidgetObject, "drillDownUrl");
                                        dashboardWidget.IsDrillDownMetricBrowser = getBoolValueFromJToken(dashboardWidgetObject, "useMetricBrowserAsDrillDown");

                                        dashboardWidget.IsShowEvents = getBoolValueFromJToken(dashboardWidgetObject, "showEvents");
                                        dashboardWidget.EventFilter  = getStringValueOfObjectFromJToken(dashboardWidgetObject, "eventFilterTemplate", false);

                                        dashboardWidget.ImageURL = getStringValueFromJToken(dashboardWidgetObject, "imageURL");
                                        if (dashboardWidget.ImageURL.Length > 0)
                                        {
                                            if (dashboardWidget.ImageURL.StartsWith("data:") == true)
                                            {
                                                dashboardWidget.EmbeddedImageSize = dashboardWidget.ImageURL.Length;
                                                dashboardWidget.ImageURL          = "Embedded base64 image";
                                            }
                                        }

                                        dashboardWidget.SourceURL = getStringValueFromJToken(dashboardWidgetObject, "sourceURL");
                                        dashboardWidget.IsSandbox = getBoolValueFromJToken(dashboardWidgetObject, "sandbox");

                                        if (dashboardWidget.WidgetType == "AnalyticsWidget")
                                        {
                                            try
                                            {
                                                if (dashboardWidgetObject["adqlQueryList"].Count() == 0)
                                                {
                                                    dashboardWidget.AnalyticsQueries = String.Empty;
                                                }
                                                else if (dashboardWidgetObject["adqlQueryList"].Count() == 1)
                                                {
                                                    dashboardWidget.AnalyticsQueries = dashboardWidgetObject["adqlQueryList"][0].ToString();
                                                }
                                                else
                                                {
                                                    dashboardWidget.AnalyticsQueries = getStringValueOfObjectFromJToken(dashboardWidgetObject, "adqlQueryList", false);
                                                }
                                            }
                                            catch { }
                                            dashboardWidget.AnalyticsWidgetType = getStringValueFromJToken(dashboardWidgetObject, "analyticsWidgetType");
                                            dashboardWidget.AnalyticsSearchMode = getStringValueFromJToken(dashboardWidgetObject, "searchMode");
                                        }

                                        #region Maybe discern between Widget Types?

                                        //switch (dashboardWidget.WidgetType)
                                        //{
                                        //    case "HealthListWidget":
                                        //        break;

                                        //    case "ImageWidget":
                                        //        break;

                                        //    case "TextWidget":
                                        //        break;

                                        //    case "GraphWidget":
                                        //        break;

                                        //    case "MetricLabelWidget":
                                        //        break;

                                        //    case "EventListWidget":
                                        //        break;

                                        //    case "AnalyticsWidget":
                                        //        break;

                                        //    case "PieWidget":
                                        //        break;

                                        //    case "GaugeWidget":
                                        //        break;

                                        //    case "IFrameWidget":
                                        //        break;

                                        //    default:
                                        //        logger.Warn("Unknown Widget Type {0} in {1}, Widget {2}", dashboardWidget.WidgetType, dashboard, dashboardWidget.Index);
                                        //        loggerConsole.Warn("Unknown Widget Type {0} in {1}, Widget {2}", dashboardWidget.WidgetType, dashboard, dashboardWidget.Index);

                                        //        break;
                                        //}

                                        #endregion

                                        dashboardWidgetsList.Add(dashboardWidget);

                                        // Now process metric data series for widgets that support them
                                        if (dashboardWidget.NumDataSeries > 0)
                                        {
                                            List <DashboardMetricSeries> dashboardMetricSeriesList = new List <DashboardMetricSeries>(dashboardWidget.NumDataSeries);
                                            foreach (JObject dashboardMetricSeriesObject in dashboardWidgetObject["dataSeriesTemplates"])
                                            {
                                                DashboardMetricSeries dashboardMetricSeries = new DashboardMetricSeries();
                                                dashboardMetricSeries.Controller    = dashboard.Controller;
                                                dashboardMetricSeries.DashboardName = dashboard.DashboardName;
                                                dashboardMetricSeries.DashboardID   = dashboard.DashboardID;
                                                dashboardMetricSeries.CanvasType    = dashboard.CanvasType;
                                                dashboardMetricSeries.WidgetType    = dashboardWidget.WidgetType;
                                                dashboardMetricSeries.Index         = dashboardWidget.Index;

                                                dashboardMetricSeries.SeriesName = getStringValueFromJToken(dashboardMetricSeriesObject, "name");
                                                dashboardMetricSeries.SeriesType = getStringValueFromJToken(dashboardMetricSeriesObject, "seriesType");
                                                dashboardMetricSeries.MetricType = getStringValueFromJToken(dashboardMetricSeriesObject, "metricType");
                                                if (isTokenPropertyNull(dashboardMetricSeriesObject, "colorPalette") == false)
                                                {
                                                    if (isTokenPropertyNull(dashboardMetricSeriesObject["colorPalette"], "colors") == false)
                                                    {
                                                        string[] entities      = new string[dashboardMetricSeriesObject["colorPalette"]["colors"].Count()];
                                                        int      entitiesIndex = 0;
                                                        foreach (JToken entityReferenceToken in dashboardMetricSeriesObject["colorPalette"]["colors"])
                                                        {
                                                            int color = (int)entityReferenceToken;
                                                            entities[entitiesIndex] = color.ToString("X6");
                                                            entitiesIndex++;;
                                                        }
                                                        dashboardMetricSeries.Colors    = String.Join(";", entities);
                                                        dashboardMetricSeries.NumColors = entities.Length;
                                                    }
                                                }
                                                dashboardMetricSeries.Axis = getStringValueFromJToken(dashboardMetricSeriesObject, "axisPosition");

                                                if (isTokenPropertyNull(dashboardMetricSeriesObject, "metricMatchCriteriaTemplate") == false)
                                                {
                                                    JObject dashboardMetricSeriesMetricMatchCriteriaTemplateObject = (JObject)dashboardMetricSeriesObject["metricMatchCriteriaTemplate"];

                                                    dashboardMetricSeries.MaxResults = getIntValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "maxResults");

                                                    dashboardMetricSeries.ApplicationName   = getStringValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "applicationName");
                                                    dashboardMetricSeries.Expression        = getStringValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "expressionString");
                                                    dashboardMetricSeries.EvalScopeType     = getStringValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "evaluationScopeType");
                                                    dashboardMetricSeries.Baseline          = getStringValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "baselineName");
                                                    dashboardMetricSeries.DisplayStyle      = getStringValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "metricDisplayNameStyle");
                                                    dashboardMetricSeries.DisplayFormat     = getStringValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "metricDisplayNameCustomFormat");
                                                    dashboardMetricSeries.IsRollup          = getBoolValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "rollupMetricData");
                                                    dashboardMetricSeries.UseActiveBaseline = getBoolValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "useActiveBaseline");
                                                    if (getBoolValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "sortResultsAscending") == true)
                                                    {
                                                        dashboardMetricSeries.SortDirection = "Ascending";
                                                    }
                                                    else
                                                    {
                                                        dashboardMetricSeries.SortDirection = "Descending";
                                                    }

                                                    if (isTokenPropertyNull(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "entityMatchCriteria") == false)
                                                    {
                                                        JObject dashboardMetricSeriesEntityMatchCriteriaObject = (JObject)dashboardMetricSeriesMetricMatchCriteriaTemplateObject["entityMatchCriteria"];

                                                        dashboardMetricSeries.IsSummary           = getBoolValueFromJToken(dashboardMetricSeriesEntityMatchCriteriaObject, "summary");
                                                        dashboardMetricSeries.EntityType          = getStringValueFromJToken(dashboardMetricSeriesEntityMatchCriteriaObject, "entityType");
                                                        dashboardMetricSeries.EntitySelectionType = getStringValueFromJToken(dashboardMetricSeriesEntityMatchCriteriaObject, "matchCriteriaType");
                                                        dashboardMetricSeries.AgentType           = getStringValueOfObjectFromJToken(dashboardMetricSeriesEntityMatchCriteriaObject, "agentTypes", true);

                                                        if (isTokenPropertyNull(dashboardMetricSeriesEntityMatchCriteriaObject, "entityNames") == false)
                                                        {
                                                            string[] entities      = new string[dashboardMetricSeriesEntityMatchCriteriaObject["entityNames"].Count()];
                                                            int      entitiesIndex = 0;
                                                            foreach (JToken entityReferenceToken in dashboardMetricSeriesEntityMatchCriteriaObject["entityNames"])
                                                            {
                                                                string        scopingEntityName = getStringValueFromJToken(entityReferenceToken, "scopingEntityName");
                                                                string        entityName        = getStringValueFromJToken(entityReferenceToken, "entityName");
                                                                string        subType           = getStringValueFromJToken(entityReferenceToken, "subtype");
                                                                StringBuilder sb = new StringBuilder(100);
                                                                sb.Append(scopingEntityName);
                                                                if (scopingEntityName.Length > 0)
                                                                {
                                                                    sb.Append("/");
                                                                }
                                                                sb.Append(entityName);
                                                                if (subType.Length > 0)
                                                                {
                                                                    sb.AppendFormat(" [{0}]", subType);
                                                                }
                                                                entities[entitiesIndex] = sb.ToString();
                                                                entitiesIndex++;;
                                                            }
                                                            dashboardMetricSeries.SelectedEntities    = String.Join(";", entities);
                                                            dashboardMetricSeries.NumSelectedEntities = entities.Length;
                                                        }
                                                    }

                                                    if (isTokenPropertyNull(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "metricExpressionTemplate") == false)
                                                    {
                                                        JObject dashboardMetricSeriesMetricExpressionTemplateObject = (JObject)dashboardMetricSeriesMetricMatchCriteriaTemplateObject["metricExpressionTemplate"];

                                                        dashboardMetricSeries.MetricExpressionType = getStringValueFromJToken(dashboardMetricSeriesMetricExpressionTemplateObject, "metricExpressionType");
                                                        dashboardMetricSeries.MetricDisplayName    = getStringValueFromJToken(dashboardMetricSeriesMetricExpressionTemplateObject, "displayName");
                                                        if (dashboardMetricSeries.MetricDisplayName == "null")
                                                        {
                                                            // yes, sometimes that value is saved as string "null"
                                                            dashboardMetricSeries.MetricDisplayName = String.Empty;
                                                        }
                                                        dashboardMetricSeries.FunctionType = getStringValueFromJToken(dashboardMetricSeriesMetricExpressionTemplateObject, "functionType");

                                                        dashboardMetricSeries.MetricPath = getStringValueFromJToken(dashboardMetricSeriesMetricExpressionTemplateObject, "relativeMetricPath");
                                                        if (dashboardMetricSeries.MetricPath.Length == 0)
                                                        {
                                                            // Must be dashboardMetricSeries.MetricExpressionType = Absolute
                                                            dashboardMetricSeries.MetricPath = getStringValueFromJToken(dashboardMetricSeriesMetricExpressionTemplateObject, "metricPath");
                                                        }

                                                        if (dashboardMetricSeries.NumSelectedEntities == 0)
                                                        {
                                                            // Must be dashboardMetricSeries.MetricExpressionType = Absolute
                                                            if (isTokenPropertyNull(dashboardMetricSeriesMetricExpressionTemplateObject, "scopeEntity") == false)
                                                            {
                                                                JObject dashboardMetricSeriesScopeEntityObject = (JObject)dashboardMetricSeriesMetricExpressionTemplateObject["scopeEntity"];

                                                                string        scopingEntityName = getStringValueFromJToken(dashboardMetricSeriesScopeEntityObject, "scopingEntityName");
                                                                string        entityName        = getStringValueFromJToken(dashboardMetricSeriesScopeEntityObject, "entityName");
                                                                string        subType           = getStringValueFromJToken(dashboardMetricSeriesScopeEntityObject, "subtype");
                                                                StringBuilder sb = new StringBuilder(100);
                                                                sb.Append(scopingEntityName);
                                                                if (scopingEntityName.Length > 0)
                                                                {
                                                                    sb.Append("/");
                                                                }
                                                                sb.Append(entityName);
                                                                if (subType.Length > 0)
                                                                {
                                                                    sb.AppendFormat(" [{0}]", subType);
                                                                }

                                                                dashboardMetricSeries.SelectedEntities    = sb.ToString();
                                                                dashboardMetricSeries.NumSelectedEntities = 1;
                                                            }
                                                        }

                                                        if (dashboardMetricSeries.MetricExpressionType == "Boolean")
                                                        {
                                                            dashboardMetricSeries.ExpressionOperator = getStringValueFromJToken(dashboardMetricSeriesMetricExpressionTemplateObject["operator"], "type");
                                                            dashboardMetricSeries.Expression1        = getStringValueOfObjectFromJToken(dashboardMetricSeriesMetricExpressionTemplateObject, "expression1", false);
                                                            dashboardMetricSeries.Expression2        = getStringValueOfObjectFromJToken(dashboardMetricSeriesMetricExpressionTemplateObject, "expression2", false);
                                                        }
                                                    }
                                                }

                                                dashboardMetricSeriesList.Add(dashboardMetricSeries);
                                            }

                                            dashboardMetricSeriesAllList.AddRange(dashboardMetricSeriesList);
                                        }

                                        dashboardWidgetIndex++;
                                    }

                                    dashboardWidgetsAllList.AddRange(dashboardWidgetsList);

                                    dashboard.NumWidgets            = dashboardWidgetsList.Count;
                                    dashboard.NumAnalyticsWidgets   = dashboardWidgetsList.Count(d => d.WidgetType == "AnalyticsWidget");
                                    dashboard.NumEventListWidgets   = dashboardWidgetsList.Count(d => d.WidgetType == "EventListWidget");
                                    dashboard.NumGaugeWidgets       = dashboardWidgetsList.Count(d => d.WidgetType == "GaugeWidget");
                                    dashboard.NumGraphWidgets       = dashboardWidgetsList.Count(d => d.WidgetType == "GraphWidget");
                                    dashboard.NumHealthListWidgets  = dashboardWidgetsList.Count(d => d.WidgetType == "HealthListWidget");
                                    dashboard.NumIFrameWidgets      = dashboardWidgetsList.Count(d => d.WidgetType == "IFrameWidget");
                                    dashboard.NumImageWidgets       = dashboardWidgetsList.Count(d => d.WidgetType == "ImageWidget");
                                    dashboard.NumMetricLabelWidgets = dashboardWidgetsList.Count(d => d.WidgetType == "MetricLabelWidget");
                                    dashboard.NumPieWidgets         = dashboardWidgetsList.Count(d => d.WidgetType == "PieWidget");
                                    dashboard.NumTextWidgets        = dashboardWidgetsList.Count(d => d.WidgetType == "TextWidget");
                                }

                                dashboardsList.Add(dashboard);

                                j++;
                                if (j % 100 == 0)
                                {
                                    Console.Write("[{0}].", j);
                                }
                            }
                        }

                        loggerConsole.Info("{0} Dashboards", dashboardsList.Count);
                        loggerConsole.Info("{0} Dashboard Widgets", dashboardWidgetsAllList.Count);
                        loggerConsole.Info("{0} Dashboard Widget Time Series", dashboardMetricSeriesAllList.Count);

                        dashboardsList = dashboardsList.OrderBy(d => d.DashboardName).ToList();
                        FileIOHelper.WriteListToCSVFile(dashboardsList, new DashboardReportMap(), FilePathMap.DashboardsIndexFilePath(jobTarget));

                        dashboardWidgetsAllList = dashboardWidgetsAllList.OrderBy(d => d.DashboardName).ThenBy(d => d.Index).ToList();
                        FileIOHelper.WriteListToCSVFile(dashboardWidgetsAllList, new DashboardWidgetReportMap(), FilePathMap.DashboardWidgetsIndexFilePath(jobTarget));

                        dashboardMetricSeriesAllList = dashboardMetricSeriesAllList.OrderBy(d => d.DashboardName).ThenBy(d => d.Index).ThenBy(d => d.SeriesName).ToList();
                        FileIOHelper.WriteListToCSVFile(dashboardMetricSeriesAllList, new DashboardMetricSeriesReportMap(), FilePathMap.DashboardMetricSeriesIndexFilePath(jobTarget));

                        stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + dashboardsList.Count;

                        #endregion

                        #region Combine All for Report CSV

                        // If it is the first one, clear out the combined folder
                        if (reportFolderCleaned == false)
                        {
                            FileIOHelper.DeleteFolder(FilePathMap.ControllerDashboardsReportFolderPath());
                            Thread.Sleep(1000);
                            FileIOHelper.CreateFolder(FilePathMap.ControllerDashboardsReportFolderPath());
                            reportFolderCleaned = true;
                        }

                        // Append all the individual report files into one
                        if (File.Exists(FilePathMap.DashboardsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.DashboardsIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.DashboardsReportFilePath(), FilePathMap.DashboardsIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.DashboardWidgetsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.DashboardWidgetsIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.DashboardWidgetsReportFilePath(), FilePathMap.DashboardWidgetsIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.DashboardMetricSeriesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.DashboardMetricSeriesIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.DashboardMetricSeriesReportFilePath(), FilePathMap.DashboardMetricSeriesIndexFilePath(jobTarget));
                        }

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                        loggerConsole.Warn(ex);

                        return(false);
                    }
                    finally
                    {
                        stopWatchTarget.Stop();

                        this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget);

                        stepTimingTarget.EndTime    = DateTime.Now;
                        stepTimingTarget.Duration   = stopWatchTarget.Elapsed;
                        stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds;

                        List <StepTiming> stepTimings = new List <StepTiming>(1);
                        stepTimings.Add(stepTimingTarget);
                        FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
                    }

                    i++;
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
Ejemplo n.º 13
0
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            try
            {
                if (this.ShouldExecute(jobConfiguration) == false)
                {
                    return(true);
                }

                List <JobTarget> listOfTargetsAlreadyProcessed = new List <JobTarget>(jobConfiguration.Target.Count);

                bool reportFolderCleaned = false;
                bool haveProcessedAtLeastOneDBCollector = false;

                // Process each target
                for (int i = 0; i < jobConfiguration.Target.Count; i++)
                {
                    Stopwatch stopWatchTarget = new Stopwatch();
                    stopWatchTarget.Start();

                    JobTarget jobTarget = jobConfiguration.Target[i];

                    StepTiming stepTimingTarget = new StepTiming();
                    stepTimingTarget.Controller      = jobTarget.Controller;
                    stepTimingTarget.ApplicationName = jobTarget.Application;
                    stepTimingTarget.ApplicationID   = jobTarget.ApplicationID;
                    stepTimingTarget.JobFileName     = programOptions.OutputJobFilePath;
                    stepTimingTarget.StepName        = jobConfiguration.Status.ToString();
                    stepTimingTarget.StepID          = (int)jobConfiguration.Status;
                    stepTimingTarget.StartTime       = DateTime.Now;

                    try
                    {
                        this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1);

                        if (listOfTargetsAlreadyProcessed.Count(j => (j.Controller == jobTarget.Controller) && (j.ApplicationID == jobTarget.ApplicationID)) > 0)
                        {
                            // Already saw this target, like an APM and WEB pairs together
                            continue;
                        }

                        // For databases, we only process this once for the first collector we've seen
                        if (jobTarget.Type == APPLICATION_TYPE_DB)
                        {
                            if (haveProcessedAtLeastOneDBCollector == false)
                            {
                                haveProcessedAtLeastOneDBCollector = true;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        listOfTargetsAlreadyProcessed.Add(jobTarget);

                        #region Prepare time variables

                        long   fromTimeUnix            = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.From);
                        long   toTimeUnix              = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.To);
                        long   differenceInMinutes     = (toTimeUnix - fromTimeUnix) / (60000);
                        string DEEPLINK_THIS_TIMERANGE = String.Format(DEEPLINK_TIMERANGE_BETWEEN_TIMES, toTimeUnix, fromTimeUnix, differenceInMinutes);

                        #endregion

                        #region Health Rule violations

                        List <HealthRuleViolationEvent> healthRuleViolationList = new List <HealthRuleViolationEvent>();

                        loggerConsole.Info("Index Health Rule Violations");

                        JArray healthRuleViolationsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.ApplicationHealthRuleViolationsDataFilePath(jobTarget));
                        if (healthRuleViolationsArray != null)
                        {
                            foreach (JObject interestingEventObject in healthRuleViolationsArray)
                            {
                                HealthRuleViolationEvent healthRuleViolationEvent = new HealthRuleViolationEvent();
                                healthRuleViolationEvent.Controller      = jobTarget.Controller;
                                healthRuleViolationEvent.ApplicationName = jobTarget.Application;
                                healthRuleViolationEvent.ApplicationID   = jobTarget.ApplicationID;

                                healthRuleViolationEvent.EventID = getLongValueFromJToken(interestingEventObject, "id");
                                healthRuleViolationEvent.FromUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(interestingEventObject, "startTimeInMillis"));
                                healthRuleViolationEvent.From    = healthRuleViolationEvent.FromUtc.ToLocalTime();
                                if (getLongValueFromJToken(interestingEventObject, "endTimeInMillis") > 0)
                                {
                                    healthRuleViolationEvent.ToUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(interestingEventObject, "endTimeInMillis"));
                                    healthRuleViolationEvent.To    = healthRuleViolationEvent.FromUtc.ToLocalTime();
                                }
                                healthRuleViolationEvent.Status    = getStringValueFromJToken(interestingEventObject, "incidentStatus");
                                healthRuleViolationEvent.Severity  = getStringValueFromJToken(interestingEventObject, "severity");
                                healthRuleViolationEvent.EventLink = String.Format(DEEPLINK_INCIDENT, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EventID, getStringValueFromJToken(interestingEventObject, "startTimeInMillis"), DEEPLINK_THIS_TIMERANGE);;

                                healthRuleViolationEvent.Description = getStringValueFromJToken(interestingEventObject, "description");

                                if (isTokenPropertyNull(interestingEventObject, "triggeredEntityDefinition") == false)
                                {
                                    healthRuleViolationEvent.HealthRuleID   = getLongValueFromJToken(interestingEventObject["triggeredEntityDefinition"], "entityId");
                                    healthRuleViolationEvent.HealthRuleName = getStringValueFromJToken(interestingEventObject["triggeredEntityDefinition"], "name");
                                    // TODO the health rule can't be hotlinked to until platform rewrites the screen that opens from Flash
                                    healthRuleViolationEvent.HealthRuleLink = String.Format(DEEPLINK_HEALTH_RULE, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.HealthRuleID, DEEPLINK_THIS_TIMERANGE);
                                }

                                if (isTokenPropertyNull(interestingEventObject, "affectedEntityDefinition") == false)
                                {
                                    healthRuleViolationEvent.EntityID   = getIntValueFromJToken(interestingEventObject["affectedEntityDefinition"], "entityId");
                                    healthRuleViolationEvent.EntityName = getStringValueFromJToken(interestingEventObject["affectedEntityDefinition"], "name");

                                    string entityType = getStringValueFromJToken(interestingEventObject["affectedEntityDefinition"], "entityType");
                                    if (entityTypeStringMapping.ContainsKey(entityType) == true)
                                    {
                                        healthRuleViolationEvent.EntityType = entityTypeStringMapping[entityType];
                                    }
                                    else
                                    {
                                        healthRuleViolationEvent.EntityType = entityType;
                                    }

                                    // Come up with links
                                    switch (entityType)
                                    {
                                    case ENTITY_TYPE_FLOWMAP_APPLICATION:
                                        healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_APM_APPLICATION, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, DEEPLINK_THIS_TIMERANGE);
                                        break;

                                    case ENTITY_TYPE_FLOWMAP_APPLICATION_MOBILE:
                                        healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_APPLICATION_MOBILE, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE);
                                        break;

                                    case ENTITY_TYPE_FLOWMAP_TIER:
                                        healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_TIER, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE);
                                        break;

                                    case ENTITY_TYPE_FLOWMAP_NODE:
                                        healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_NODE, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE);
                                        break;

                                    case ENTITY_TYPE_FLOWMAP_BUSINESS_TRANSACTION:
                                        healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_BUSINESS_TRANSACTION, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE);
                                        break;

                                    case ENTITY_TYPE_FLOWMAP_BACKEND:
                                        healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_BACKEND, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE);
                                        break;

                                    default:
                                        logger.Warn("Unknown entity type {0} in affectedEntityDefinition in health rule violations", entityType);
                                        break;
                                    }
                                }

                                healthRuleViolationEvent.ControllerLink  = String.Format(DEEPLINK_CONTROLLER, healthRuleViolationEvent.Controller, DEEPLINK_THIS_TIMERANGE);
                                healthRuleViolationEvent.ApplicationLink = String.Format(DEEPLINK_APM_APPLICATION, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, DEEPLINK_THIS_TIMERANGE);

                                healthRuleViolationList.Add(healthRuleViolationEvent);
                            }
                        }

                        loggerConsole.Info("{0} Health Rule Violations", healthRuleViolationList.Count);

                        stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + healthRuleViolationList.Count;

                        // Sort them
                        healthRuleViolationList = healthRuleViolationList.OrderBy(o => o.HealthRuleName).ThenBy(o => o.From).ThenBy(o => o.Severity).ToList();
                        FileIOHelper.WriteListToCSVFile <HealthRuleViolationEvent>(healthRuleViolationList, new HealthRuleViolationEventReportMap(), FilePathMap.ApplicationHealthRuleViolationsIndexFilePath(jobTarget));

                        #endregion

                        #region Events

                        List <Event> eventsList = new List <Event>();

                        loggerConsole.Info("Index Events");

                        foreach (string eventType in EVENT_TYPES)
                        {
                            JArray eventsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.ApplicationEventsDataFilePath(jobTarget, eventType));
                            if (eventsArray != null)
                            {
                                loggerConsole.Info("{0} Events", eventType);

                                foreach (JObject interestingEventObject in eventsArray)
                                {
                                    Event @event = new Event();
                                    @event.Controller      = jobTarget.Controller;
                                    @event.ApplicationName = jobTarget.Application;
                                    @event.ApplicationID   = jobTarget.ApplicationID;

                                    @event.EventID     = getLongValueFromJToken(interestingEventObject, "id");
                                    @event.OccurredUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(interestingEventObject, "eventTime"));
                                    @event.Occurred    = @event.OccurredUtc.ToLocalTime();
                                    @event.Type        = getStringValueFromJToken(interestingEventObject, "type");
                                    @event.SubType     = getStringValueFromJToken(interestingEventObject, "subType");
                                    @event.Severity    = getStringValueFromJToken(interestingEventObject, "severity");
                                    @event.EventLink   = getStringValueFromJToken(interestingEventObject, "deepLinkUrl");
                                    @event.Summary     = getStringValueFromJToken(interestingEventObject, "summary");

                                    if (isTokenPropertyNull(interestingEventObject, "triggeredEntity") == false)
                                    {
                                        @event.TriggeredEntityID   = getLongValueFromJToken(interestingEventObject["triggeredEntity"], "entityId");
                                        @event.TriggeredEntityName = getStringValueFromJToken(interestingEventObject["triggeredEntity"], "name");
                                        string entityType = getStringValueFromJToken(interestingEventObject["triggeredEntity"], "entityType");
                                        if (entityTypeStringMapping.ContainsKey(entityType) == true)
                                        {
                                            @event.TriggeredEntityType = entityTypeStringMapping[entityType];
                                        }
                                        else
                                        {
                                            @event.TriggeredEntityType = entityType;
                                        }
                                    }

                                    foreach (JObject affectedEntity in interestingEventObject["affectedEntities"])
                                    {
                                        string entityType = getStringValueFromJToken(affectedEntity, "entityType");
                                        switch (entityType)
                                        {
                                        case ENTITY_TYPE_FLOWMAP_APPLICATION:
                                            // already have this data
                                            break;

                                        case ENTITY_TYPE_FLOWMAP_TIER:
                                            @event.TierID   = getIntValueFromJToken(affectedEntity, "entityId");
                                            @event.TierName = getStringValueFromJToken(affectedEntity, "name");
                                            break;

                                        case ENTITY_TYPE_FLOWMAP_NODE:
                                            @event.NodeID   = getIntValueFromJToken(affectedEntity, "entityId");
                                            @event.NodeName = getStringValueFromJToken(affectedEntity, "name");
                                            break;

                                        case ENTITY_TYPE_FLOWMAP_MACHINE:
                                            @event.MachineID   = getIntValueFromJToken(affectedEntity, "entityId");
                                            @event.MachineName = getStringValueFromJToken(affectedEntity, "name");
                                            break;

                                        case ENTITY_TYPE_FLOWMAP_BUSINESS_TRANSACTION:
                                            @event.BTID   = getIntValueFromJToken(affectedEntity, "entityId");
                                            @event.BTName = getStringValueFromJToken(affectedEntity, "name");
                                            break;

                                        case ENTITY_TYPE_FLOWMAP_HEALTH_RULE:
                                            @event.TriggeredEntityID   = getLongValueFromJToken(affectedEntity, "entityId");
                                            @event.TriggeredEntityType = entityTypeStringMapping[getStringValueFromJToken(affectedEntity, "entityType")];
                                            @event.TriggeredEntityName = getStringValueFromJToken(affectedEntity, "name");
                                            break;

                                        default:
                                            logger.Warn("Unknown entity type {0} in affectedEntities in events", entityType);
                                            break;
                                        }
                                    }

                                    @event.ControllerLink  = String.Format(DEEPLINK_CONTROLLER, @event.Controller, DEEPLINK_THIS_TIMERANGE);
                                    @event.ApplicationLink = String.Format(DEEPLINK_APM_APPLICATION, @event.Controller, @event.ApplicationID, DEEPLINK_THIS_TIMERANGE);
                                    if (@event.TierID != 0)
                                    {
                                        @event.TierLink = String.Format(DEEPLINK_TIER, @event.Controller, @event.ApplicationID, @event.TierID, DEEPLINK_THIS_TIMERANGE);
                                    }
                                    if (@event.NodeID != 0)
                                    {
                                        @event.NodeLink = String.Format(DEEPLINK_NODE, @event.Controller, @event.ApplicationID, @event.NodeID, DEEPLINK_THIS_TIMERANGE);
                                    }
                                    if (@event.BTID != 0)
                                    {
                                        @event.BTLink = String.Format(DEEPLINK_BUSINESS_TRANSACTION, @event.Controller, @event.ApplicationID, @event.BTID, DEEPLINK_THIS_TIMERANGE);
                                    }

                                    eventsList.Add(@event);
                                }
                            }
                        }

                        loggerConsole.Info("{0} Events", eventsList.Count);

                        stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + eventsList.Count;

                        // Sort them
                        eventsList = eventsList.OrderBy(o => o.Type).ThenBy(o => o.Occurred).ThenBy(o => o.Severity).ToList();
                        FileIOHelper.WriteListToCSVFile <Event>(eventsList, new EventReportMap(), FilePathMap.ApplicationEventsIndexFilePath(jobTarget));

                        #endregion

                        #region Application

                        ApplicationEventSummary application = new ApplicationEventSummary();

                        application.Controller      = jobTarget.Controller;
                        application.ApplicationName = jobTarget.Application;
                        application.ApplicationID   = jobTarget.ApplicationID;
                        application.Type            = jobTarget.Type;

                        application.NumEvents        = eventsList.Count;
                        application.NumEventsError   = eventsList.Count(e => e.Severity == "ERROR");
                        application.NumEventsWarning = eventsList.Count(e => e.Severity == "WARN");
                        application.NumEventsInfo    = eventsList.Count(e => e.Severity == "INFO");

                        application.NumHRViolations         = healthRuleViolationList.Count;
                        application.NumHRViolationsCritical = healthRuleViolationList.Count(e => e.Severity == "CRITICAL");
                        application.NumHRViolationsWarning  = healthRuleViolationList.Count(e => e.Severity == "WARNING");

                        application.Duration = (int)(jobConfiguration.Input.TimeRange.To - jobConfiguration.Input.TimeRange.From).Duration().TotalMinutes;
                        application.From     = jobConfiguration.Input.TimeRange.From.ToLocalTime();
                        application.To       = jobConfiguration.Input.TimeRange.To.ToLocalTime();
                        application.FromUtc  = jobConfiguration.Input.TimeRange.From;
                        application.ToUtc    = jobConfiguration.Input.TimeRange.To;

                        // Determine what kind of entity we are dealing with and adjust accordingly
                        application.ControllerLink  = String.Format(DEEPLINK_CONTROLLER, application.Controller, DEEPLINK_THIS_TIMERANGE);
                        application.ApplicationLink = String.Format(DEEPLINK_APM_APPLICATION, application.Controller, application.ApplicationID, DEEPLINK_THIS_TIMERANGE);

                        if (application.NumEvents > 0 || application.NumHRViolations > 0)
                        {
                            application.HasActivity = true;
                        }

                        List <ApplicationEventSummary> applicationList = new List <ApplicationEventSummary>(1);
                        applicationList.Add(application);
                        FileIOHelper.WriteListToCSVFile(applicationList, new ApplicationEventSummaryReportMap(), FilePathMap.ApplicationEventsSummaryIndexFilePath(jobTarget));

                        #endregion

                        #region Combine All for Report CSV

                        // If it is the first one, clear out the combined folder
                        if (reportFolderCleaned == false)
                        {
                            FileIOHelper.DeleteFolder(FilePathMap.ApplicationEventsReportFolderPath());
                            Thread.Sleep(1000);
                            FileIOHelper.CreateFolder(FilePathMap.ApplicationEventsReportFolderPath());
                            reportFolderCleaned = true;
                        }

                        // Append all the individual report files into one
                        if (File.Exists(FilePathMap.ApplicationHealthRuleViolationsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ApplicationHealthRuleViolationsIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.ApplicationHealthRuleViolationsReportFilePath(), FilePathMap.ApplicationHealthRuleViolationsIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.ApplicationEventsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ApplicationEventsIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.ApplicationEventsReportFilePath(), FilePathMap.ApplicationEventsIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.ApplicationEventsSummaryIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ApplicationEventsSummaryIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.ApplicationEventsSummaryReportFilePath(), FilePathMap.ApplicationEventsSummaryIndexFilePath(jobTarget));
                        }

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                        loggerConsole.Warn(ex);

                        return(false);
                    }
                    finally
                    {
                        stopWatchTarget.Stop();

                        this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget);

                        stepTimingTarget.EndTime    = DateTime.Now;
                        stepTimingTarget.Duration   = stopWatchTarget.Elapsed;
                        stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds;

                        List <StepTiming> stepTimings = new List <StepTiming>(1);
                        stepTimings.Add(stepTimingTarget);
                        FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
Ejemplo n.º 14
0
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            try
            {
                if (this.ShouldExecute(jobConfiguration) == false)
                {
                    return(true);
                }

                bool reportFolderCleaned = false;

                // Process each Controller once
                int i           = 0;
                var controllers = jobConfiguration.Target.GroupBy(t => t.Controller);
                foreach (var controllerGroup in controllers)
                {
                    Stopwatch stopWatchTarget = new Stopwatch();
                    stopWatchTarget.Start();

                    JobTarget jobTarget = controllerGroup.ToList()[0];

                    StepTiming stepTimingTarget = new StepTiming();
                    stepTimingTarget.Controller      = jobTarget.Controller;
                    stepTimingTarget.ApplicationName = jobTarget.Application;
                    stepTimingTarget.ApplicationID   = jobTarget.ApplicationID;
                    stepTimingTarget.JobFileName     = programOptions.OutputJobFilePath;
                    stepTimingTarget.StepName        = jobConfiguration.Status.ToString();
                    stepTimingTarget.StepID          = (int)jobConfiguration.Status;
                    stepTimingTarget.StartTime       = DateTime.Now;

                    stepTimingTarget.NumEntities = 0;

                    try
                    {
                        this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1);

                        #region Controller Version

                        loggerConsole.Info("Controller Version");

                        // Create this row
                        ControllerSummary controllerSummary = new ControllerSummary();
                        controllerSummary.Controller     = jobTarget.Controller;
                        controllerSummary.ControllerLink = String.Format(DEEPLINK_CONTROLLER, controllerSummary.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES);

                        // Lookup version
                        // Load the configuration.xml from the child to parse the version
                        XmlDocument configXml = FileIOHelper.LoadXmlDocumentFromFile(FilePathMap.ControllerVersionDataFilePath(jobTarget));
                        if (configXml != null)
                        {
                            //<serverstatus version="1" vendorid="">
                            //    <available>true</available>
                            //    <serverid/>
                            //    <serverinfo>
                            //        <vendorname>AppDynamics</vendorname>
                            //        <productname>AppDynamics Application Performance Management</productname>
                            //        <serverversion>004-004-001-000</serverversion>
                            //        <implementationVersion>Controller v4.4.1.0 Build 164 Commit 6e1fd94d18dc87c1ecab2da573f98cea49d31c3a</implementationVersion>
                            //    </serverinfo>
                            //    <startupTimeInSeconds>19</startupTimeInSeconds>
                            //</serverstatus>
                            string   controllerVersion         = configXml.SelectSingleNode("serverstatus/serverinfo/serverversion").InnerText;
                            string[] controllerVersionArray    = controllerVersion.Split('-');
                            int[]    controllerVersionArrayNum = new int[controllerVersionArray.Length];
                            for (int j = 0; j < controllerVersionArray.Length; j++)
                            {
                                controllerVersionArrayNum[j] = Convert.ToInt32(controllerVersionArray[j]);
                            }
                            controllerVersion               = String.Join(".", controllerVersionArrayNum);
                            controllerSummary.Version       = controllerVersion;
                            controllerSummary.VersionDetail = configXml.SelectSingleNode("serverstatus/serverinfo/implementationVersion").InnerText;
                            controllerSummary.StartupTime   = Convert.ToInt32(configXml.SelectSingleNode("serverstatus/startupTimeInSeconds").InnerText);
                        }
                        else
                        {
                            controllerSummary.Version = "No config data";
                        }

                        #endregion

                        #region All Applications

                        JObject allApplicationsContainerObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.AllApplicationsDataFilePath(jobTarget));
                        JArray  mobileApplicationsArray        = FileIOHelper.LoadJArrayFromFile(FilePathMap.MOBILEApplicationsDataFilePath(jobTarget));

                        List <ControllerApplication> controllerApplicationsList = new List <ControllerApplication>(100);

                        if (isTokenPropertyNull(allApplicationsContainerObject, "apmApplications") == false)
                        {
                            loggerConsole.Info("Index List of APM Applications");

                            foreach (JObject applicationObject in allApplicationsContainerObject["apmApplications"])
                            {
                                ControllerApplication controllerApplication = new ControllerApplication();
                                controllerApplication.Controller = jobTarget.Controller;

                                populateApplicationInfo(applicationObject, controllerApplication);

                                controllerApplication.Type = APPLICATION_TYPE_APM;

                                controllerApplicationsList.Add(controllerApplication);
                            }
                        }

                        if (isTokenPropertyNull(allApplicationsContainerObject, "eumWebApplications") == false)
                        {
                            loggerConsole.Info("Index List of WEB Applications");

                            foreach (JObject applicationObject in allApplicationsContainerObject["eumWebApplications"])
                            {
                                ControllerApplication controllerApplication = new ControllerApplication();
                                controllerApplication.Controller = jobTarget.Controller;

                                populateApplicationInfo(applicationObject, controllerApplication);

                                controllerApplication.Type = APPLICATION_TYPE_WEB;

                                controllerApplicationsList.Add(controllerApplication);
                            }
                        }

                        if (isTokenPropertyNull(allApplicationsContainerObject, "iotApplications") == false)
                        {
                            loggerConsole.Info("Index List of IOT Applications");

                            foreach (JObject applicationObject in allApplicationsContainerObject["iotApplications"])
                            {
                                ControllerApplication controllerApplication = new ControllerApplication();
                                controllerApplication.Controller = jobTarget.Controller;

                                populateApplicationInfo(applicationObject, controllerApplication);

                                controllerApplication.Type = APPLICATION_TYPE_IOT;

                                controllerApplicationsList.Add(controllerApplication);
                            }
                        }

                        if (isTokenPropertyNull(allApplicationsContainerObject, "mobileAppContainers") == false)
                        {
                            loggerConsole.Info("Index List of MOBILE Applications");

                            foreach (JObject applicationObject in allApplicationsContainerObject["mobileAppContainers"])
                            {
                                ControllerApplication controllerApplication = new ControllerApplication();
                                controllerApplication.Controller = jobTarget.Controller;

                                populateApplicationInfo(applicationObject, controllerApplication);

                                controllerApplication.Type = APPLICATION_TYPE_MOBILE;

                                if (controllerApplicationsList.Where(a => a.ApplicationID == controllerApplication.ApplicationID).Count() == 0)
                                {
                                    controllerApplicationsList.Add(controllerApplication);
                                }

                                // Now go through children
                                if (mobileApplicationsArray != null)
                                {
                                    JToken mobileApplicationContainerObject = mobileApplicationsArray.Where(a => getLongValueFromJToken(a, "applicationId") == controllerApplication.ApplicationID).FirstOrDefault();
                                    if (mobileApplicationContainerObject != null)
                                    {
                                        foreach (JObject mobileApplicationChildJSON in mobileApplicationContainerObject["children"])
                                        {
                                            ControllerApplication controllerApplicationChild = controllerApplication.Clone();
                                            controllerApplicationChild.ParentApplicationID = controllerApplicationChild.ApplicationID;

                                            controllerApplicationChild.ApplicationName = getStringValueFromJToken(mobileApplicationChildJSON, "name");
                                            controllerApplicationChild.ApplicationID   = getLongValueFromJToken(mobileApplicationChildJSON, "mobileAppId");

                                            controllerApplicationsList.Add(controllerApplicationChild);
                                        }
                                    }
                                }
                            }
                        }

                        if (isTokenPropertyNull(allApplicationsContainerObject, "dbMonApplication") == false)
                        {
                            loggerConsole.Info("Index DB Application");

                            JObject applicationObject = (JObject)allApplicationsContainerObject["dbMonApplication"];

                            ControllerApplication controllerApplication = new ControllerApplication();
                            controllerApplication.Controller = jobTarget.Controller;

                            populateApplicationInfo(applicationObject, controllerApplication);

                            controllerApplication.Type = APPLICATION_TYPE_DB;

                            controllerApplicationsList.Add(controllerApplication);
                        }

                        if (isTokenPropertyNull(allApplicationsContainerObject, "simApplication") == false)
                        {
                            loggerConsole.Info("Index SIM Application");

                            JObject applicationObject = (JObject)allApplicationsContainerObject["simApplication"];

                            ControllerApplication controllerApplication = new ControllerApplication();
                            controllerApplication.Controller = jobTarget.Controller;

                            populateApplicationInfo(applicationObject, controllerApplication);

                            controllerApplication.Type = APPLICATION_TYPE_SIM;

                            controllerApplicationsList.Add(controllerApplication);
                        }

                        if (isTokenPropertyNull(allApplicationsContainerObject, "analyticsApplication") == false)
                        {
                            loggerConsole.Info("Index BIQ Application");

                            JObject applicationObject = (JObject)allApplicationsContainerObject["analyticsApplication"];

                            ControllerApplication controllerApplication = new ControllerApplication();
                            controllerApplication.Controller = jobTarget.Controller;

                            populateApplicationInfo(applicationObject, controllerApplication);

                            controllerApplication.Type = APPLICATION_TYPE_BIQ;

                            controllerApplicationsList.Add(controllerApplication);
                        }

                        // Sort them
                        controllerApplicationsList = controllerApplicationsList.OrderBy(o => o.Type).ThenBy(o => o.ApplicationName).ToList();
                        FileIOHelper.WriteListToCSVFile(controllerApplicationsList, new ControllerApplicationReportMap(), FilePathMap.ControllerApplicationsIndexFilePath(jobTarget));

                        controllerSummary.NumApps       = controllerApplicationsList.Count;
                        controllerSummary.NumAPMApps    = controllerApplicationsList.Where(a => a.Type == APPLICATION_TYPE_APM).Count();
                        controllerSummary.NumWEBApps    = controllerApplicationsList.Where(a => a.Type == APPLICATION_TYPE_WEB).Count();
                        controllerSummary.NumMOBILEApps = controllerApplicationsList.Where(a => a.Type == APPLICATION_TYPE_MOBILE).Count();
                        controllerSummary.NumSIMApps    = controllerApplicationsList.Where(a => a.Type == APPLICATION_TYPE_SIM).Count();
                        controllerSummary.NumDBApps     = controllerApplicationsList.Where(a => a.Type == APPLICATION_TYPE_DB).Count();
                        controllerSummary.NumBIQApps    = controllerApplicationsList.Where(a => a.Type == APPLICATION_TYPE_BIQ).Count();
                        controllerSummary.NumIOTApps    = controllerApplicationsList.Where(a => a.Type == APPLICATION_TYPE_IOT).Count();

                        List <ControllerSummary> controllerList = new List <ControllerSummary>(1);
                        controllerList.Add(controllerSummary);
                        FileIOHelper.WriteListToCSVFile(controllerList, new ControllerSummaryReportMap(), FilePathMap.ControllerSummaryIndexFilePath(jobTarget));

                        stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + controllerApplicationsList.Count;

                        #endregion

                        #region Combine All for Report CSV

                        // If it is the first one, clear out the combined folder
                        if (reportFolderCleaned == false)
                        {
                            FileIOHelper.DeleteFolder(FilePathMap.ControllerEntitiesReportFolderPath());
                            Thread.Sleep(1000);
                            FileIOHelper.CreateFolder(FilePathMap.ControllerEntitiesReportFolderPath());
                            reportFolderCleaned = true;
                        }

                        // Append all the individual report files into one
                        if (File.Exists(FilePathMap.ControllerSummaryIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ControllerSummaryIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.ControllerSummaryReportFilePath(), FilePathMap.ControllerSummaryIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.ControllerApplicationsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ControllerApplicationsIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.ControllerApplicationsReportFilePath(), FilePathMap.ControllerApplicationsIndexFilePath(jobTarget));
                        }

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                        loggerConsole.Warn(ex);

                        return(false);
                    }
                    finally
                    {
                        stopWatchTarget.Stop();

                        this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget);

                        stepTimingTarget.EndTime    = DateTime.Now;
                        stepTimingTarget.Duration   = stopWatchTarget.Elapsed;
                        stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds;

                        List <StepTiming> stepTimings = new List <StepTiming>(1);
                        stepTimings.Add(stepTimingTarget);
                        FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
                    }

                    i++;
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
Ejemplo n.º 15
0
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            try
            {
                if (this.ShouldExecute(programOptions, jobConfiguration) == false)
                {
                    return(true);
                }

                bool reportFolderCleaned = false;

                // Process each Controller once
                int i           = 0;
                var controllers = jobConfiguration.Target.GroupBy(t => t.Controller);
                foreach (var controllerGroup in controllers)
                {
                    Stopwatch stopWatchTarget = new Stopwatch();
                    stopWatchTarget.Start();

                    JobTarget jobTarget = controllerGroup.ToList()[0];

                    StepTiming stepTimingTarget = new StepTiming();
                    stepTimingTarget.Controller      = jobTarget.Controller;
                    stepTimingTarget.ApplicationName = jobTarget.Application;
                    stepTimingTarget.ApplicationID   = jobTarget.ApplicationID;
                    stepTimingTarget.JobFileName     = programOptions.OutputJobFilePath;
                    stepTimingTarget.StepName        = jobConfiguration.Status.ToString();
                    stepTimingTarget.StepID          = (int)jobConfiguration.Status;
                    stepTimingTarget.StartTime       = DateTime.Now;

                    stepTimingTarget.NumEntities = 0;

                    try
                    {
                        this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1);

                        #region Prepare time range

                        long   fromTimeUnix            = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.From);
                        long   toTimeUnix              = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.To);
                        int    differenceInMinutes     = (int)(jobConfiguration.Input.TimeRange.To - jobConfiguration.Input.TimeRange.From).Duration().TotalMinutes;
                        string DEEPLINK_THIS_TIMERANGE = String.Format(DEEPLINK_TIMERANGE_BETWEEN_TIMES, toTimeUnix, fromTimeUnix, differenceInMinutes);

                        #endregion

                        #region Account Summary

                        loggerConsole.Info("Account Summary");

                        LicenseAccountSummary licenseAccountSummary = new LicenseAccountSummary();

                        JObject accountSummaryContainerObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.LicenseAccountDataFilePath(jobTarget));
                        if (accountSummaryContainerObject != null && isTokenPropertyNull(accountSummaryContainerObject, "account") == false)
                        {
                            JObject accountSummaryLicenseObject = (JObject)accountSummaryContainerObject["account"];

                            licenseAccountSummary.Controller = jobTarget.Controller;

                            licenseAccountSummary.AccountID         = getLongValueFromJToken(accountSummaryLicenseObject, "id");
                            licenseAccountSummary.AccountName       = getStringValueFromJToken(accountSummaryLicenseObject, "name");
                            licenseAccountSummary.AccountNameGlobal = getStringValueFromJToken(accountSummaryLicenseObject, "globalAccountName");
                            licenseAccountSummary.AccountNameEUM    = getStringValueFromJToken(accountSummaryLicenseObject, "eumAccountName");

                            licenseAccountSummary.AccessKey1    = getStringValueFromJToken(accountSummaryLicenseObject, "accessKey");
                            licenseAccountSummary.AccessKey2    = getStringValueFromJToken(accountSummaryLicenseObject, "key");
                            licenseAccountSummary.LicenseKeyEUM = getStringValueFromJToken(accountSummaryLicenseObject, "eumCloudLicenseKey");
                            licenseAccountSummary.ServiceKeyES  = getStringValueFromJToken(accountSummaryLicenseObject, "eumEventServiceKey");

                            licenseAccountSummary.ExpirationDate = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(accountSummaryLicenseObject, "expirationDate"));

                            licenseAccountSummary.LicenseLink = String.Format(DEEPLINK_LICENSE, licenseAccountSummary.Controller, DEEPLINK_THIS_TIMERANGE);

                            List <LicenseAccountSummary> licenseAccountSummaryList = new List <LicenseAccountSummary>(1);
                            licenseAccountSummaryList.Add(licenseAccountSummary);
                            FileIOHelper.WriteListToCSVFile(licenseAccountSummaryList, new LicenseAccountSummaryReportMap(), FilePathMap.LicenseAccountIndexFilePath(jobTarget));

                            stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + licenseAccountSummaryList.Count;
                        }

                        #endregion

                        #region Account Level License Entitlements and Usage

                        loggerConsole.Info("Account License Summary and Usage");

                        List <License> licensesList = new List <License>(24);

                        // Typically there are 12 values per hour, if we extracted every 5 minute things
                        List <LicenseValue> licenseValuesGlobalList = new List <LicenseValue>(jobConfiguration.Input.HourlyTimeRanges.Count * 12 * licensesList.Count);

                        JObject licenseModulesContainer = FileIOHelper.LoadJObjectFromFile(FilePathMap.LicenseModulesDataFilePath(jobTarget));
                        if (licenseModulesContainer != null &&
                            isTokenPropertyNull(licenseModulesContainer, "modules") == false)
                        {
                            JArray licenseModulesArray = (JArray)licenseModulesContainer["modules"];
                            foreach (JObject licenseModuleObject in licenseModulesArray)
                            {
                                string licenseModuleName = getStringValueFromJToken(licenseModuleObject, "name");

                                License license = new License();

                                license.Controller  = jobTarget.Controller;
                                license.AccountID   = licenseAccountSummary.AccountID;
                                license.AccountName = licenseAccountSummary.AccountName;

                                // Duration
                                license.Duration = (int)(jobConfiguration.Input.TimeRange.To - jobConfiguration.Input.TimeRange.From).Duration().TotalMinutes;
                                license.From     = jobConfiguration.Input.TimeRange.From.ToLocalTime();
                                license.To       = jobConfiguration.Input.TimeRange.To.ToLocalTime();
                                license.FromUtc  = jobConfiguration.Input.TimeRange.From;
                                license.ToUtc    = jobConfiguration.Input.TimeRange.To;

                                license.AgentType = licenseModuleName;

                                JObject licenseModulePropertiesContainer = FileIOHelper.LoadJObjectFromFile(FilePathMap.LicenseModulePropertiesDataFilePath(jobTarget, licenseModuleName));
                                if (licenseModulePropertiesContainer != null &&
                                    isTokenPropertyNull(licenseModulePropertiesContainer, "properties") == false)
                                {
                                    foreach (JObject licensePropertyObject in licenseModulePropertiesContainer["properties"])
                                    {
                                        string valueOfProperty = getStringValueFromJToken(licensePropertyObject, "value");
                                        switch (getStringValueFromJToken(licensePropertyObject, "name"))
                                        {
                                        case "expiry-date":
                                            long expiryDateLong = 0;
                                            if (long.TryParse(valueOfProperty, out expiryDateLong) == true)
                                            {
                                                license.ExpirationDate = UnixTimeHelper.ConvertFromUnixTimestamp(expiryDateLong);
                                            }
                                            break;

                                        case "licensing-model":
                                            license.Model = valueOfProperty;
                                            break;

                                        case "edition":
                                            license.Edition = valueOfProperty;
                                            break;

                                        case "number-of-provisioned-licenses":
                                            long numberOfLicensesLong = 0;
                                            if (long.TryParse(valueOfProperty, out numberOfLicensesLong) == true)
                                            {
                                                license.Provisioned = numberOfLicensesLong;
                                            }
                                            break;

                                        case "maximum-allowed-licenses":
                                            long maximumNumberOfLicensesLong = 0;
                                            if (long.TryParse(valueOfProperty, out maximumNumberOfLicensesLong) == true)
                                            {
                                                license.MaximumAllowed = maximumNumberOfLicensesLong;
                                            }
                                            break;

                                        case "data-retention-period":
                                            int dataRetentionPeriodInt = 0;
                                            if (int.TryParse(valueOfProperty, out dataRetentionPeriodInt) == true)
                                            {
                                                license.Retention = dataRetentionPeriodInt;
                                            }
                                            break;

                                        default:
                                            break;
                                        }
                                    }
                                }

                                List <LicenseValue> licenseValuesList = new List <LicenseValue>(jobConfiguration.Input.HourlyTimeRanges.Count * 12);

                                JObject licenseModuleUsagesContainer = FileIOHelper.LoadJObjectFromFile(FilePathMap.LicenseModuleUsagesDataFilePath(jobTarget, licenseModuleName));
                                if (licenseModuleUsagesContainer != null &&
                                    isTokenPropertyNull(licenseModuleUsagesContainer, "usages") == false)
                                {
                                    foreach (JObject licenseUsageObject in licenseModuleUsagesContainer["usages"])
                                    {
                                        LicenseValue licenseValue = new LicenseValue();

                                        licenseValue.Controller  = license.Controller;
                                        licenseValue.AccountName = license.AccountName;
                                        licenseValue.AccountID   = license.AccountID;

                                        licenseValue.AgentType = license.AgentType;

                                        licenseValue.RuleName = "Account";

                                        licenseValue.LicenseEventTimeUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(licenseUsageObject, "createdOn"));
                                        licenseValue.LicenseEventTime    = licenseValue.LicenseEventTimeUtc.ToLocalTime();

                                        licenseValue.Min     = getLongValueFromJToken(licenseUsageObject, "minUnitsUsed");
                                        licenseValue.Max     = getLongValueFromJToken(licenseUsageObject, "maxUnitsUsed");
                                        licenseValue.Average = getLongValueFromJToken(licenseUsageObject, "avgUnitsUsed");
                                        licenseValue.Total   = getLongValueFromJToken(licenseUsageObject, "totalUnitsUsed");
                                        licenseValue.Samples = getLongValueFromJToken(licenseUsageObject, "sampleCount");

                                        licenseValuesList.Add(licenseValue);
                                    }
                                }

                                // Do the counts and averages from per hour consumption to the total line
                                if (licenseValuesList.Count > 0)
                                {
                                    license.Average = (long)Math.Round((double)((double)licenseValuesList.Sum(mv => mv.Average) / (double)licenseValuesList.Count), 0);
                                    license.Min     = licenseValuesList.Min(l => l.Min);
                                    license.Max     = licenseValuesList.Max(l => l.Max);
                                }

                                licensesList.Add(license);
                                licenseValuesGlobalList.AddRange(licenseValuesList);
                            }
                        }

                        stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + licensesList.Count;

                        licensesList = licensesList.OrderBy(l => l.AgentType).ToList();
                        FileIOHelper.WriteListToCSVFile(licensesList, new LicenseReportMap(), FilePathMap.LicensesIndexFilePath(jobTarget));

                        FileIOHelper.WriteListToCSVFile(licenseValuesGlobalList, new LicenseValueReportMap(), FilePathMap.LicenseUsageAccountIndexFilePath(jobTarget));

                        #endregion

                        #region License Rules

                        loggerConsole.Info("License Rules");

                        #region Preload the application and machine mapping

                        Dictionary <string, string> applicationsUsedByRules = null;
                        Dictionary <string, string> simMachinesUsedByRules  = null;

                        JArray licenseApplicationsReferenceArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.LicenseApplicationsDataFilePath(jobTarget));
                        JArray licenseSIMMachinesReferenceArray  = FileIOHelper.LoadJArrayFromFile(FilePathMap.LicenseSIMMachinesDataFilePath(jobTarget));

                        if (licenseApplicationsReferenceArray == null)
                        {
                            applicationsUsedByRules = new Dictionary <string, string>(0);
                        }
                        else
                        {
                            applicationsUsedByRules = new Dictionary <string, string>(licenseApplicationsReferenceArray.Count);
                            foreach (JObject applicationObject in licenseApplicationsReferenceArray)
                            {
                                applicationsUsedByRules.Add(getStringValueFromJToken(applicationObject["objectReference"], "id"), getStringValueFromJToken(applicationObject, "name"));
                            }
                        }

                        if (licenseSIMMachinesReferenceArray == null)
                        {
                            simMachinesUsedByRules = new Dictionary <string, string>(0);
                        }
                        else
                        {
                            simMachinesUsedByRules = new Dictionary <string, string>(licenseSIMMachinesReferenceArray.Count);
                            foreach (JObject machineObject in licenseSIMMachinesReferenceArray)
                            {
                                simMachinesUsedByRules.Add(getStringValueFromJToken(machineObject["objectReference"], "id"), getStringValueFromJToken(machineObject, "name"));
                            }
                        }

                        List <ControllerApplication> controllerApplicationsList = FileIOHelper.ReadListFromCSVFile <ControllerApplication>(FilePathMap.ControllerApplicationsIndexFilePath(jobTarget), new ControllerApplicationReportMap());

                        #endregion

                        List <LicenseRule>      licenseRulesList      = new List <LicenseRule>(10);
                        List <LicenseRuleScope> licenseRuleScopesList = new List <LicenseRuleScope>(100);

                        JArray licenseRulesArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.LicenseRulesDataFilePath(jobTarget));
                        if (licenseRulesArray != null)
                        {
                            foreach (JObject licenseRuleObject in licenseRulesArray)
                            {
                                string ruleID   = getStringValueFromJToken(licenseRuleObject, "id");
                                string ruleName = getStringValueFromJToken(licenseRuleObject, "name");

                                JObject licenseRuleDetailsObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.LicenseRuleConfigurationDataFilePath(jobTarget, ruleName, ruleID));
                                if (licenseRuleDetailsObject != null)
                                {
                                    LicenseRule licenseRuleTemplate = new LicenseRule();

                                    licenseRuleTemplate.Controller  = jobTarget.Controller;
                                    licenseRuleTemplate.AccountID   = licenseAccountSummary.AccountID;
                                    licenseRuleTemplate.AccountName = licenseAccountSummary.AccountName;

                                    // Duration
                                    licenseRuleTemplate.Duration = (int)(jobConfiguration.Input.TimeRange.To - jobConfiguration.Input.TimeRange.From).Duration().TotalMinutes;
                                    licenseRuleTemplate.From     = jobConfiguration.Input.TimeRange.From.ToLocalTime();
                                    licenseRuleTemplate.To       = jobConfiguration.Input.TimeRange.To.ToLocalTime();
                                    licenseRuleTemplate.FromUtc  = jobConfiguration.Input.TimeRange.From;
                                    licenseRuleTemplate.ToUtc    = jobConfiguration.Input.TimeRange.To;

                                    licenseRuleTemplate.RuleName = getStringValueFromJToken(licenseRuleObject, "name");
                                    licenseRuleTemplate.RuleID   = getStringValueFromJToken(licenseRuleObject, "id");

                                    licenseRuleTemplate.AccessKey = getStringValueFromJToken(licenseRuleObject, "access_key");

                                    licenseRuleTemplate.RuleLicenses = getLongValueFromJToken(licenseRuleObject, "total_licenses");
                                    licenseRuleTemplate.RulePeak     = getLongValueFromJToken(licenseRuleObject, "peak_usage");

                                    if (isTokenPropertyNull(licenseRuleDetailsObject, "constraints") == false)
                                    {
                                        JArray licenseRuleConstraintsArray = (JArray)licenseRuleDetailsObject["constraints"];
                                        foreach (JObject licenseConstraintObject in licenseRuleConstraintsArray)
                                        {
                                            LicenseRuleScope licenseRuleScope = new LicenseRuleScope();

                                            licenseRuleScope.Controller  = licenseRuleTemplate.Controller;
                                            licenseRuleScope.AccountID   = licenseRuleTemplate.AccountID;
                                            licenseRuleScope.AccountName = licenseRuleTemplate.AccountName;

                                            licenseRuleScope.RuleName = licenseRuleTemplate.RuleName;
                                            licenseRuleScope.RuleID   = licenseRuleTemplate.RuleID;

                                            licenseRuleScope.ScopeSelector = getStringValueFromJToken(licenseConstraintObject, "constraint_type");

                                            string scopeType = getStringValueFromJToken(licenseConstraintObject, "entity_type_id");
                                            if (scopeType == "com.appdynamics.modules.apm.topology.impl.persistenceapi.model.ApplicationEntity")
                                            {
                                                licenseRuleScope.EntityType = "Application";
                                            }
                                            else if (scopeType == "com.appdynamics.modules.apm.topology.impl.persistenceapi.model.MachineEntity")
                                            {
                                                licenseRuleScope.EntityType = "Machine";
                                            }

                                            if (licenseRuleScope.ScopeSelector == "ALLOW_ALL")
                                            {
                                                licenseRuleScope.MatchType = "EQUALS";
                                                if (scopeType == "com.appdynamics.modules.apm.topology.impl.persistenceapi.model.ApplicationEntity")
                                                {
                                                    licenseRuleScope.EntityName = "[Any Application]";
                                                    licenseRuleTemplate.NumApplications++;
                                                }
                                                else if (scopeType == "com.appdynamics.modules.apm.topology.impl.persistenceapi.model.MachineEntity")
                                                {
                                                    licenseRuleScope.EntityName = "[Any Machine]";
                                                    licenseRuleTemplate.NumServers++;
                                                }
                                                licenseRuleScopesList.Add(licenseRuleScope);
                                            }
                                            else if (isTokenPropertyNull(licenseConstraintObject, "match_conditions") == false)
                                            {
                                                JArray licenseRuleMatcheConditionsArray = (JArray)licenseConstraintObject["match_conditions"];

                                                foreach (JObject licenseRuleMatchConditionObject in licenseRuleMatcheConditionsArray)
                                                {
                                                    LicenseRuleScope licenseRuleScopeMatchCondition = licenseRuleScope.Clone();

                                                    licenseRuleScopeMatchCondition.MatchType = getStringValueFromJToken(licenseRuleMatchConditionObject, "match_type");
                                                    if (licenseRuleScopeMatchCondition.MatchType == "EQUALS" &&
                                                        getStringValueFromJToken(licenseRuleMatchConditionObject, "attribute_type") == "ID")
                                                    {
                                                        string applicationID = getStringValueFromJToken(licenseRuleMatchConditionObject, "match_string");

                                                        if (scopeType == "com.appdynamics.modules.apm.topology.impl.persistenceapi.model.ApplicationEntity")
                                                        {
                                                            if (applicationsUsedByRules.ContainsKey(applicationID) == true &&
                                                                controllerApplicationsList != null)
                                                            {
                                                                ControllerApplication controllerApplication = controllerApplicationsList.Where(a => a.ApplicationName == applicationsUsedByRules[applicationID]).FirstOrDefault();
                                                                if (controllerApplication != null)
                                                                {
                                                                    licenseRuleScopeMatchCondition.EntityName = controllerApplication.ApplicationName;
                                                                    licenseRuleScopeMatchCondition.EntityType = controllerApplication.Type;
                                                                    licenseRuleScopeMatchCondition.EntityID   = controllerApplication.ApplicationID;
                                                                }
                                                            }
                                                            licenseRuleTemplate.NumApplications++;
                                                        }
                                                        else if (scopeType == "com.appdynamics.modules.apm.topology.impl.persistenceapi.model.MachineEntity")
                                                        {
                                                            if (simMachinesUsedByRules.ContainsKey(applicationID) == true)
                                                            {
                                                                licenseRuleScopeMatchCondition.EntityName = simMachinesUsedByRules[applicationID];
                                                            }
                                                            licenseRuleTemplate.NumServers++;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        licenseRuleScopeMatchCondition.EntityName = getStringValueFromJToken(licenseRuleMatchConditionObject, "match_string");
                                                        licenseRuleScopeMatchCondition.EntityID   = -1;
                                                        if (scopeType == "com.appdynamics.modules.apm.topology.impl.persistenceapi.model.ApplicationEntity")
                                                        {
                                                            licenseRuleTemplate.NumApplications++;
                                                        }
                                                        else if (scopeType == "com.appdynamics.modules.apm.topology.impl.persistenceapi.model.MachineEntity")
                                                        {
                                                            licenseRuleTemplate.NumServers++;
                                                        }
                                                    }

                                                    licenseRuleScopesList.Add(licenseRuleScopeMatchCondition);
                                                }
                                            }
                                        }
                                    }

                                    if (isTokenPropertyNull(licenseRuleDetailsObject, "entitlements") == false)
                                    {
                                        JArray licenseRuleEntitlementsArray = (JArray)licenseRuleDetailsObject["entitlements"];
                                        foreach (JObject licenseEntitlementObject in licenseRuleEntitlementsArray)
                                        {
                                            LicenseRule licenseRule = licenseRuleTemplate.Clone();

                                            licenseRule.Licenses = getLongValueFromJToken(licenseEntitlementObject, "number_of_licenses");

                                            licenseRule.AgentType = getStringValueFromJToken(licenseEntitlementObject, "license_module_type");

                                            licenseRulesList.Add(licenseRule);
                                        }
                                    }
                                }
                            }

                            licenseRulesList = licenseRulesList.OrderBy(l => l.RuleName).ThenBy(l => l.AgentType).ToList();
                            FileIOHelper.WriteListToCSVFile(licenseRulesList, new LicenseRuleReportMap(), FilePathMap.LicenseRulesIndexFilePath(jobTarget));

                            licenseRuleScopesList = licenseRuleScopesList.OrderBy(l => l.RuleName).ThenBy(l => l.ScopeSelector).ThenBy(l => l.EntityType).ThenBy(l => l.EntityName).ToList();
                            FileIOHelper.WriteListToCSVFile(licenseRuleScopesList, new LicenseRuleScopeReportMap(), FilePathMap.LicenseRuleScopesIndexFilePath(jobTarget));
                        }

                        #endregion

                        #region License Rule consumption details

                        loggerConsole.Info("Rules License Consumption");

                        // Typically there are 12 values per hour
                        // Assume there will be 16 different license types
                        List <LicenseValue> licenseValuesRulesList = new List <LicenseValue>(jobConfiguration.Input.HourlyTimeRanges.Count * 12 * 16 * licenseRulesList.Count);

                        foreach (LicenseRule licenseRule in licenseRulesList)
                        {
                            JObject licenseValuesForRuleContainerObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.LicenseRuleUsageDataFilePath(jobTarget, licenseRule.RuleName, licenseRule.RuleID));

                            if (licenseValuesForRuleContainerObject != null)
                            {
                                if (isTokenPropertyNull(licenseValuesForRuleContainerObject, "apmStackGraphViewData") == false)
                                {
                                    // Parse the APM results first
                                    JArray licenseValuesForRuleAPMContainerArray = (JArray)licenseValuesForRuleContainerObject["apmStackGraphViewData"];
                                    if (licenseValuesForRuleAPMContainerArray != null)
                                    {
                                        foreach (JObject licenseValuesContainerObject in licenseValuesForRuleAPMContainerArray)
                                        {
                                            string licenseType = getStringValueFromJToken(licenseValuesContainerObject, "licenseModuleType");

                                            // If we have the license looked up, look through the values
                                            if (licenseType != String.Empty &&
                                                isTokenPropertyNull(licenseValuesContainerObject, "graphPoints") == false)
                                            {
                                                // Looks like [[ 1555484400000, 843 ], [ 1555488000000, 843 ]]
                                                JArray licenseValuesAPMArray = (JArray)licenseValuesContainerObject["graphPoints"];

                                                List <LicenseValue> licenseValuesList = parseLicenseValuesArray(licenseValuesAPMArray, licenseRule, licenseType);
                                                if (licenseValuesList != null)
                                                {
                                                    licenseValuesRulesList.AddRange(licenseValuesList);
                                                }
                                            }
                                        }
                                    }
                                }
                                if (isTokenPropertyNull(licenseValuesForRuleContainerObject, "nonApmModuleDetailViewData") == false)
                                {
                                    // Parse the non-APM results second
                                    JArray licenseValuesForRuleNonAPMContainerArray = (JArray)licenseValuesForRuleContainerObject["nonApmModuleDetailViewData"];
                                    if (licenseValuesForRuleNonAPMContainerArray != null)
                                    {
                                        foreach (JObject licenseValuesContainerObject in licenseValuesForRuleNonAPMContainerArray)
                                        {
                                            string licenseType = getStringValueFromJToken(licenseValuesContainerObject, "licenseModuleType");

                                            // If we have the license looked up, look through the values
                                            if (licenseType != String.Empty &&
                                                isTokenPropertyNull(licenseValuesContainerObject, "graphPoints") == false)
                                            {
                                                // Looks like [[ 1555484400000, 843 ], [ 1555488000000, 843 ]]
                                                JArray licenseValuesAPMArray = (JArray)licenseValuesContainerObject["graphPoints"];

                                                List <LicenseValue> licenseValuesList = parseLicenseValuesArray(licenseValuesAPMArray, licenseRule, licenseType);
                                                if (licenseValuesList != null)
                                                {
                                                    licenseValuesRulesList.AddRange(licenseValuesList);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        FileIOHelper.WriteListToCSVFile(licenseValuesRulesList, new LicenseRuleValueReportMap(), FilePathMap.LicenseUsageRulesIndexFilePath(jobTarget));

                        #endregion

                        #region Combine All for Report CSV

                        // If it is the first one, clear out the combined folder
                        if (reportFolderCleaned == false)
                        {
                            FileIOHelper.DeleteFolder(FilePathMap.ControllerLicensesReportFolderPath());
                            Thread.Sleep(1000);
                            FileIOHelper.CreateFolder(FilePathMap.ControllerLicensesReportFolderPath());
                            reportFolderCleaned = true;
                        }

                        // Append all the individual report files into one
                        if (File.Exists(FilePathMap.LicenseAccountIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.LicenseAccountIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.LicenseAccountReportFilePath(), FilePathMap.LicenseAccountIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.LicensesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.LicensesIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.LicensesReportFilePath(), FilePathMap.LicensesIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.LicenseRulesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.LicenseRulesIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.LicenseRulesReportFilePath(), FilePathMap.LicenseRulesIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.LicenseUsageAccountIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.LicenseUsageAccountIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.LicenseUsageAccountReportFilePath(), FilePathMap.LicenseUsageAccountIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.LicenseUsageRulesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.LicenseUsageRulesIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.LicenseUsageRulesReportFilePath(), FilePathMap.LicenseUsageRulesIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.LicenseRuleScopesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.LicenseRuleScopesIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.LicenseRuleScopesReportFilePath(), FilePathMap.LicenseRuleScopesIndexFilePath(jobTarget));
                        }

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                        loggerConsole.Warn(ex);

                        return(false);
                    }
                    finally
                    {
                        stopWatchTarget.Stop();

                        this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget);

                        stepTimingTarget.EndTime    = DateTime.Now;
                        stepTimingTarget.Duration   = stopWatchTarget.Elapsed;
                        stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds;

                        List <StepTiming> stepTimings = new List <StepTiming>(1);
                        stepTimings.Add(stepTimingTarget);
                        FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
                    }

                    i++;
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
Ejemplo n.º 16
0
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            try
            {
                if (this.ShouldExecute(programOptions, jobConfiguration) == false)
                {
                    return(true);
                }

                if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_SIM) == 0)
                {
                    logger.Warn("No {0} targets to process", APPLICATION_TYPE_SIM);
                    loggerConsole.Warn("No {0} targets to process", APPLICATION_TYPE_SIM);

                    return(true);
                }

                List <MetricExtractMapping> entityMetricExtractMappingList = getMetricsExtractMappingList(jobConfiguration);

                // Process each target
                for (int i = 0; i < jobConfiguration.Target.Count; i++)
                {
                    Stopwatch stopWatchTarget = new Stopwatch();
                    stopWatchTarget.Start();

                    JobTarget jobTarget = jobConfiguration.Target[i];

                    if (jobTarget.Type != null && jobTarget.Type.Length > 0 && jobTarget.Type != APPLICATION_TYPE_SIM)
                    {
                        continue;
                    }

                    StepTiming stepTimingTarget = new StepTiming();
                    stepTimingTarget.Controller      = jobTarget.Controller;
                    stepTimingTarget.ApplicationName = jobTarget.Application;
                    stepTimingTarget.ApplicationID   = jobTarget.ApplicationID;
                    stepTimingTarget.JobFileName     = programOptions.OutputJobFilePath;
                    stepTimingTarget.StepName        = jobConfiguration.Status.ToString();
                    stepTimingTarget.StepID          = (int)jobConfiguration.Status;
                    stepTimingTarget.StartTime       = DateTime.Now;

                    try
                    {
                        this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1);

                        #region Target step variables

                        stepTimingTarget.NumEntities = entityMetricExtractMappingList.Count;

                        #endregion

                        loggerConsole.Info("Extract Metrics for All Entities ({0} time ranges)", jobConfiguration.Input.HourlyTimeRanges.Count);

                        ParallelOptions parallelOptions = new ParallelOptions();
                        if (programOptions.ProcessSequentially == true)
                        {
                            parallelOptions.MaxDegreeOfParallelism = 1;
                        }

                        Parallel.Invoke(parallelOptions,
                                        () =>
                        {
                            #region Machine

                            getMetricsForEntities(jobTarget, jobConfiguration, entityMetricExtractMappingList, SIMMachine.ENTITY_FOLDER, SIMMachine.ENTITY_TYPE);

                            #endregion
                        },
                                        () =>
                        {
                            #region Network

                            getMetricsForEntities(jobTarget, jobConfiguration, entityMetricExtractMappingList, SIMMachineNetwork.ENTITY_FOLDER, SIMMachineNetwork.ENTITY_TYPE);

                            #endregion
                        }
                                        );
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                        loggerConsole.Warn(ex);

                        return(false);
                    }
                    finally
                    {
                        stopWatchTarget.Stop();

                        this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget);

                        stepTimingTarget.EndTime    = DateTime.Now;
                        stepTimingTarget.Duration   = stopWatchTarget.Elapsed;
                        stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds;

                        List <StepTiming> stepTimings = new List <StepTiming>(1);
                        stepTimings.Add(stepTimingTarget);
                        FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
Ejemplo n.º 17
0
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            if (this.ShouldExecute(programOptions, jobConfiguration) == false)
            {
                return(true);
            }

            try
            {
                loggerConsole.Info("Prepare APM Health Check Report File");

                #region Prepare the report package

                // Prepare package
                ExcelPackage excelReport = new ExcelPackage();
                excelReport.Workbook.Properties.Author  = String.Format("AppDynamics DEXTER {0}", Assembly.GetEntryAssembly().GetName().Version);
                excelReport.Workbook.Properties.Title   = "AppDynamics DEXTER APM Health Check Report";
                excelReport.Workbook.Properties.Subject = programOptions.JobName;

                excelReport.Workbook.Properties.Comments = String.Format("Targets={0}\nFrom={1:o}\nTo={2:o}", jobConfiguration.Target.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To);

                #endregion

                #region Parameters sheet

                // Parameters sheet
                ExcelWorksheet sheet = excelReport.Workbook.Worksheets.Add(SHEET_PARAMETERS);

                var hyperLinkStyle = sheet.Workbook.Styles.CreateNamedStyle("HyperLinkStyle");
                hyperLinkStyle.Style.Font.UnderLineType = ExcelUnderLineType.Single;
                hyperLinkStyle.Style.Font.Color.SetColor(colorBlueForHyperlinks);

                var timelineStyle = sheet.Workbook.Styles.CreateNamedStyle("TimelineStyle");
                timelineStyle.Style.Font.Name = "Consolas";
                timelineStyle.Style.Font.Size = 8;

                fillReportParametersSheet(sheet, jobConfiguration, "AppDynamics DEXTER APM Health Check Report");

                #endregion

                #region TOC sheet

                // Navigation sheet with link to other sheets
                sheet = excelReport.Workbook.Worksheets.Add(SHEET_TOC);

                #endregion

                #region Entity sheets and their associated pivot

                // Entity sheets
                sheet = excelReport.Workbook.Worksheets.Add(SHEET_CONTROLLERS_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_APPLICATIONS_ALL_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_HEALTH_CHECK_RULE_RESULTS);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Rating";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_HEALTH_CHECK_RULE_RESULTS_DISPLAY);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[3, 1].Value     = "See Summary";
                sheet.Cells[3, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_HEALTH_CHECK_RULE_RESULTS_DISPLAY);
                sheet.Cells[3, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_HEALTH_CHECK_RULE_RESULTS_DESCRIPTION_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_HEALTH_CHECK_RULE_RESULTS);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT - 4 + 2, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_HEALTH_CHECK_RULE_RESULTS_DISPLAY);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_HEALTH_CHECK_RULE_RESULTS);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                #endregion

                #region Report file variables

                ExcelRangeBase range = null;
                ExcelTable     table = null;

                #endregion

                loggerConsole.Info("Fill APM Health Check Report File");

                #region Controllers

                loggerConsole.Info("List of Controllers");

                sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerSummaryReportFilePath(), 0, typeof(ControllerSummary), sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Applications

                loggerConsole.Info("List of Applications - All");

                sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ALL_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerApplicationsReportFilePath(), 0, typeof(ControllerApplication), sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Health Check Results

                loggerConsole.Info("List of Health Check Results");

                sheet = excelReport.Workbook.Worksheets[SHEET_HEALTH_CHECK_RULE_RESULTS];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.APMHealthCheckRuleResultsReportFilePath(), 0, typeof(HealthCheckRuleResult), sheet, LIST_SHEET_START_TABLE_AT, 1);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerHealthCheckRuleResultsReportFilePath(), 1, typeof(HealthCheckRuleResult), sheet, sheet.Dimension.Rows + 1, 1);
                }
                else
                {
                    EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerHealthCheckRuleResultsReportFilePath(), 0, typeof(HealthCheckRuleResult), sheet, LIST_SHEET_START_TABLE_AT, 1);
                }

                #endregion

                loggerConsole.Info("Finalize APM Health Check Report File");

                #region Controllers sheet

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_CONTROLLERS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width = 25;
                    sheet.Column(table.Columns["Version"].Position + 1).Width    = 15;
                }

                #endregion

                #region Applications

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ALL_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_APPLICATIONS_ALL);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["Description"].Position + 1).Width     = 15;

                    sheet.Column(table.Columns["CreatedBy"].Position + 1).Width = 15;
                    sheet.Column(table.Columns["UpdatedBy"].Position + 1).Width = 15;

                    sheet.Column(table.Columns["CreatedOn"].Position + 1).Width    = 20;
                    sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width    = 20;
                    sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width = 20;
                }

                #endregion

                #region Health Check Results

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_HEALTH_CHECK_RULE_RESULTS];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_HEALTH_CHECK_RULE_RESULTS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width  = 15;
                    sheet.Column(table.Columns["Application"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["EntityName"].Position + 1).Width  = 20;
                    sheet.Column(table.Columns["Category"].Position + 1).Width    = 30;
                    sheet.Column(table.Columns["Code"].Position + 1).Width        = 15;
                    sheet.Column(table.Columns["Name"].Position + 1).Width        = 50;
                    sheet.Column(table.Columns["Description"].Position + 1).Width = 40;

                    ExcelAddress cfAddressGrade = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["Grade"].Position + 1, sheet.Dimension.Rows, table.Columns["Grade"].Position + 1);
                    var          cfGrade        = sheet.ConditionalFormatting.AddThreeColorScale(cfAddressGrade);
                    cfGrade.LowValue.Type     = eExcelConditionalFormattingValueObjectType.Num;
                    cfGrade.LowValue.Color    = colorRedFor3ColorScales;
                    cfGrade.LowValue.Value    = 1;
                    cfGrade.MiddleValue.Type  = eExcelConditionalFormattingValueObjectType.Num;
                    cfGrade.MiddleValue.Value = 3;
                    cfGrade.MiddleValue.Color = colorYellowFor3ColorScales;
                    cfGrade.HighValue.Type    = eExcelConditionalFormattingValueObjectType.Num;
                    cfGrade.HighValue.Color   = colorGreenFor3ColorScales;
                    cfGrade.HighValue.Value   = 5;

                    sheet = excelReport.Workbook.Worksheets[SHEET_HEALTH_CHECK_RULE_RESULTS_DESCRIPTION_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT - 4, 1], range, PIVOT_HEALTH_CHECK_RULE_RESULTS_DESCRIPTION_TYPE);
                    setDefaultPivotTableSettings(pivot);
                    addRowFieldToPivot(pivot, "Controller");
                    addRowFieldToPivot(pivot, "Application");
                    addRowFieldToPivot(pivot, "Category");
                    addRowFieldToPivot(pivot, "EntityType");
                    addRowFieldToPivot(pivot, "Name");
                    addRowFieldToPivot(pivot, "Description");
                    addColumnFieldToPivot(pivot, "Grade", eSortType.Ascending);
                    addDataFieldToPivot(pivot, "Name", DataFieldFunctions.Count, "Rating");

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                    sheet.Column(3).Width = 20;
                    sheet.Column(4).Width = 20;
                    sheet.Column(5).Width = 30;
                    sheet.Column(6).Width = 30;
                }

                #endregion

                #region Health Check Results Display

                sheet = excelReport.Workbook.Worksheets[SHEET_HEALTH_CHECK_RULE_RESULTS_DISPLAY];

                List <HealthCheckRuleResult> healthCheckRuleResults = new List <HealthCheckRuleResult>();

                List <HealthCheckRuleResult> healthCheckRuleResultsController = FileIOHelper.ReadListFromCSVFile(FilePathMap.ControllerHealthCheckRuleResultsReportFilePath(), new HealthCheckRuleResultReportMap());
                if (healthCheckRuleResultsController != null)
                {
                    healthCheckRuleResults.AddRange(healthCheckRuleResultsController);
                }

                List <HealthCheckRuleResult> healthCheckRuleResultsAPM = FileIOHelper.ReadListFromCSVFile(FilePathMap.APMHealthCheckRuleResultsReportFilePath(), new HealthCheckRuleResultReportMap());
                if (healthCheckRuleResultsAPM != null)
                {
                    healthCheckRuleResults.AddRange(healthCheckRuleResultsAPM);
                }

                if (healthCheckRuleResults != null)
                {
                    #region Output summary of Applications by Category table

                    // Make this following table out of the list of health rule evaluations
                    // Controller | Application | Category1 | Category2 | Category 3
                    // -------------------------------------------------------------
                    // CntrVal    | AppName     | Avg(Grade)| Avg(Grade)| Avg(Grade)

                    // To do this, we measure number of rows (Controller/Application pairs) and Columns (Category values), and build a table
                    int numRows    = healthCheckRuleResults.Select(h => String.Format("{0}/{1}", h.Controller, h.Application)).Distinct().Count();
                    int numColumns = healthCheckRuleResults.Select(h => h.Category).Distinct().Count();

                    Dictionary <string, int> categoryTableRowsLookup    = new Dictionary <string, int>(numRows);
                    Dictionary <string, int> categoryTableColumnsLookup = new Dictionary <string, int>(numColumns);

                    List <HealthCheckRuleResult>[,] categoryTableValues = new List <HealthCheckRuleResult> [numRows, numColumns];

                    foreach (HealthCheckRuleResult healthCheckRuleResult in healthCheckRuleResults)
                    {
                        int rowIndex    = 0;
                        int columnIndex = 0;

                        string rowIndexValue    = String.Format("{0}/{1}", healthCheckRuleResult.Controller, healthCheckRuleResult.Application);
                        string columnIndexValue = healthCheckRuleResult.Category;

                        if (categoryTableRowsLookup.ContainsKey(rowIndexValue) == true)
                        {
                            rowIndex = categoryTableRowsLookup[rowIndexValue];
                        }
                        else
                        {
                            rowIndex = categoryTableRowsLookup.Count;
                            categoryTableRowsLookup.Add(rowIndexValue, rowIndex);
                        }

                        if (categoryTableColumnsLookup.ContainsKey(columnIndexValue) == true)
                        {
                            columnIndex = categoryTableColumnsLookup[columnIndexValue];
                        }
                        else
                        {
                            columnIndex = categoryTableColumnsLookup.Count;
                            categoryTableColumnsLookup.Add(columnIndexValue, columnIndex);
                        }

                        // Fill in the cell
                        List <HealthCheckRuleResult> healthCheckRuleResultsInCell = categoryTableValues[rowIndex, columnIndex];
                        if (healthCheckRuleResultsInCell == null)
                        {
                            healthCheckRuleResultsInCell = new List <HealthCheckRuleResult>();
                            categoryTableValues[rowIndex, columnIndex] = healthCheckRuleResultsInCell;
                        }
                        healthCheckRuleResultsInCell.Add(healthCheckRuleResult);
                    }

                    // Output headers
                    int rowTableStart    = 4;
                    int gradeColumnStart = 4;
                    int fromRow          = rowTableStart;
                    int fromColumn       = gradeColumnStart;
                    sheet.Cells[fromRow, 1].Value = "Controller";
                    sheet.Cells[fromRow, 2].Value = "Application";
                    sheet.Cells[fromRow, 3].Value = "ApplicationID";
                    foreach (KeyValuePair <string, int> categoriesKVP in categoryTableColumnsLookup)
                    {
                        sheet.Cells[fromRow, fromColumn].Value         = categoriesKVP.Key;
                        sheet.Cells[fromRow - 1, fromColumn].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<See Details>"")", String.Format(SHEET_HEALTH_CHECK_RULE_CATEGORY_RESULTS_DISPLAY, categoriesKVP.Key));
                        sheet.Cells[fromRow - 1, fromColumn].StyleName = "HyperLinkStyle";
                        fromColumn++;
                    }
                    fromRow++;

                    // Output table
                    for (int rowIndex = 0; rowIndex < numRows; rowIndex++)
                    {
                        for (int columnIndex = 0; columnIndex < numColumns; columnIndex++)
                        {
                            List <HealthCheckRuleResult> healthCheckRuleResultsInCell = categoryTableValues[rowIndex, columnIndex];
                            if (healthCheckRuleResultsInCell != null && healthCheckRuleResultsInCell.Count > 0)
                            {
                                double gradeAverage = Math.Round((double)healthCheckRuleResultsInCell.Sum(h => h.Grade) / healthCheckRuleResultsInCell.Count, 1);

                                sheet.Cells[fromRow + rowIndex, gradeColumnStart + columnIndex].Value = gradeAverage;

                                sheet.Cells[fromRow + rowIndex, 1].Value = healthCheckRuleResultsInCell[0].Controller;
                                sheet.Cells[fromRow + rowIndex, 2].Value = healthCheckRuleResultsInCell[0].Application;
                                sheet.Cells[fromRow + rowIndex, 3].Value = healthCheckRuleResultsInCell[0].ApplicationID;
                            }
                            else
                            {
                                sheet.Cells[fromRow + rowIndex, gradeColumnStart + columnIndex].Value = "-";
                            }
                        }
                    }
                    fromRow = fromRow + numRows;

                    // Insert the table
                    range            = sheet.Cells[4, 1, 4 + numRows, 3 + numColumns];
                    table            = sheet.Tables.Add(range, TABLE_HEALTH_CHECK_RULE_APPLICATIONS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.None;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    // Resize the columns
                    sheet.Column(table.Columns["Controller"].Position + 1).Width  = 20;
                    sheet.Column(table.Columns["Application"].Position + 1).Width = 25;
                    for (int columnIndex = 0; columnIndex < numColumns; columnIndex++)
                    {
                        sheet.Column(gradeColumnStart + columnIndex).Width = 15;
                        // Make the header column cells wrap text for Categories headings
                        sheet.Cells[rowTableStart, gradeColumnStart + columnIndex].Style.WrapText = true;
                    }

                    // Make header row taller
                    sheet.Row(rowTableStart).Height = 40;

                    if (sheet.Dimension.Rows > rowTableStart)
                    {
                        // Color code it
                        ExcelAddress cfGradeNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, 4, sheet.Dimension.Rows, 4 + numColumns);
                        var          cfGrade    = sheet.ConditionalFormatting.AddThreeColorScale(cfGradeNum);
                        cfGrade.LowValue.Type     = eExcelConditionalFormattingValueObjectType.Num;
                        cfGrade.LowValue.Color    = colorRedFor3ColorScales;
                        cfGrade.LowValue.Value    = 1;
                        cfGrade.MiddleValue.Type  = eExcelConditionalFormattingValueObjectType.Num;
                        cfGrade.MiddleValue.Value = 3;
                        cfGrade.MiddleValue.Color = colorYellowFor3ColorScales;
                        cfGrade.HighValue.Type    = eExcelConditionalFormattingValueObjectType.Num;
                        cfGrade.HighValue.Color   = colorGreenFor3ColorScales;
                        cfGrade.HighValue.Value   = 5;
                    }

                    #endregion

                    #region Output individual categories on separate sheets

                    // Get list of categories for which we'll be making things
                    List <string> listOfCategories = healthCheckRuleResults.Select(h => h.Category).Distinct().ToList <string>();

                    foreach (string category in listOfCategories)
                    {
                        sheet = excelReport.Workbook.Worksheets.Add(String.Format(SHEET_HEALTH_CHECK_RULE_CATEGORY_RESULTS_DISPLAY, category));
                        sheet.Cells[1, 1].Value     = "Table of Contents";
                        sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                        sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                        sheet.Cells[2, 1].Value     = "See Table";
                        sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_HEALTH_CHECK_RULE_RESULTS);
                        sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                        sheet.Cells[3, 1].Value     = "See Display";
                        sheet.Cells[3, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_HEALTH_CHECK_RULE_RESULTS_DISPLAY);
                        sheet.Cells[3, 2].StyleName = "HyperLinkStyle";
                        sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);


                        // Make this following table out of the list of health rule evaluations
                        // Controller | Application | EntityType | EntityName | Rule 1 | Rule 2 | Rule 3
                        // -----------------------------------------------------------------------------
                        // CntrVal    | AppName     | APMApp     | AppName    | Grade  | Grade  | Grade (with comment of value)

                        // To do this, we measure number of rows (Controller/Application/EntityType/EntityName quads) and Columns (Rules within Category), and build a table
                        numRows    = healthCheckRuleResults.Where(h => h.Category == category).Select(h => String.Format("{0}/{1}/{2}/{3}", h.Controller, h.Application, h.EntityType, h.EntityName)).Distinct().Count();
                        numColumns = healthCheckRuleResults.Where(h => h.Category == category).Select(h => h.Name).Distinct().Count();

                        Dictionary <string, int> nameTableRowsLookup    = new Dictionary <string, int>(numRows);
                        Dictionary <string, int> nameTableColumnsLookup = new Dictionary <string, int>(numColumns);

                        List <HealthCheckRuleResult>[,] nameTableValues = new List <HealthCheckRuleResult> [numRows, numColumns];

                        foreach (HealthCheckRuleResult healthCheckRuleResult in healthCheckRuleResults)
                        {
                            // Only process the rules with the desired category
                            if (healthCheckRuleResult.Category != category)
                            {
                                continue;
                            }

                            int rowIndex    = 0;
                            int columnIndex = 0;

                            string rowIndexValue    = String.Format("{0}/{1}/{2}/{3}", healthCheckRuleResult.Controller, healthCheckRuleResult.Application, healthCheckRuleResult.EntityType, healthCheckRuleResult.EntityName);
                            string columnIndexValue = healthCheckRuleResult.Name;

                            if (nameTableRowsLookup.ContainsKey(rowIndexValue) == true)
                            {
                                rowIndex = nameTableRowsLookup[rowIndexValue];
                            }
                            else
                            {
                                rowIndex = nameTableRowsLookup.Count;
                                nameTableRowsLookup.Add(rowIndexValue, rowIndex);
                            }

                            if (nameTableColumnsLookup.ContainsKey(columnIndexValue) == true)
                            {
                                columnIndex = nameTableColumnsLookup[columnIndexValue];
                            }
                            else
                            {
                                columnIndex = nameTableColumnsLookup.Count;
                                nameTableColumnsLookup.Add(columnIndexValue, columnIndex);
                            }

                            // Fill in the cell
                            List <HealthCheckRuleResult> healthCheckRuleResultsInCell = nameTableValues[rowIndex, columnIndex];
                            if (healthCheckRuleResultsInCell == null)
                            {
                                healthCheckRuleResultsInCell           = new List <HealthCheckRuleResult>();
                                nameTableValues[rowIndex, columnIndex] = healthCheckRuleResultsInCell;
                            }
                            healthCheckRuleResultsInCell.Add(healthCheckRuleResult);
                        }

                        // Output headers
                        rowTableStart    = 4;
                        gradeColumnStart = 6;
                        fromRow          = rowTableStart;
                        fromColumn       = gradeColumnStart;
                        sheet.Cells[fromRow, 1].Value = "Controller";
                        sheet.Cells[fromRow, 2].Value = "Application";
                        sheet.Cells[fromRow, 3].Value = "ApplicationID";
                        sheet.Cells[fromRow, 4].Value = "EntityType";
                        sheet.Cells[fromRow, 5].Value = "EntityName";
                        foreach (KeyValuePair <string, int> namesKVP in nameTableColumnsLookup)
                        {
                            sheet.Cells[fromRow, fromColumn].Value = namesKVP.Key;
                            fromColumn++;
                        }
                        fromRow++;

                        // Output table
                        for (int rowIndex = 0; rowIndex < numRows; rowIndex++)
                        {
                            for (int columnIndex = 0; columnIndex < numColumns; columnIndex++)
                            {
                                List <HealthCheckRuleResult> healthCheckRuleResultsInCell = nameTableValues[rowIndex, columnIndex];
                                if (healthCheckRuleResultsInCell != null && healthCheckRuleResultsInCell.Count > 0)
                                {
                                    double gradeAverage = Math.Round((double)healthCheckRuleResultsInCell.Sum(h => h.Grade) / healthCheckRuleResultsInCell.Count, 1);

                                    sheet.Cells[fromRow + rowIndex, gradeColumnStart + columnIndex].Value = gradeAverage;

                                    sheet.Cells[fromRow + rowIndex, 1].Value = healthCheckRuleResultsInCell[0].Controller;
                                    sheet.Cells[fromRow + rowIndex, 2].Value = healthCheckRuleResultsInCell[0].Application;
                                    sheet.Cells[fromRow + rowIndex, 3].Value = healthCheckRuleResultsInCell[0].ApplicationID;
                                    sheet.Cells[fromRow + rowIndex, 4].Value = healthCheckRuleResultsInCell[0].EntityType;
                                    sheet.Cells[fromRow + rowIndex, 5].Value = healthCheckRuleResultsInCell[0].EntityName;

                                    StringBuilder sb = new StringBuilder(healthCheckRuleResultsInCell.Count * 128);
                                    for (int k = 0; k < healthCheckRuleResultsInCell.Count; k++)
                                    {
                                        HealthCheckRuleResult healthCheckRuleResult = healthCheckRuleResultsInCell[k];
                                        sb.AppendFormat("{0}: {1}\n", k + 1, wordWrapString(healthCheckRuleResult.Description, 100));
                                    }

                                    // Limit the size of the comment generated to ~2K of text because I think the Excel barfs when the comments are too long.
                                    if (sb.Length > 2500)
                                    {
                                        sb.Length = 2547;
                                        sb.Append("...");
                                    }

                                    // Excessive comments in the workbook lead to poor use experience. Need to rethink and refactor this
                                    ExcelComment comment = sheet.Cells[fromRow + rowIndex, gradeColumnStart + columnIndex].AddComment(sb.ToString(), healthCheckRuleResultsInCell[0].Code);
                                    comment.AutoFit = true;
                                }
                                else
                                {
                                    sheet.Cells[fromRow + rowIndex, gradeColumnStart + columnIndex].Value = "-";
                                }
                            }
                        }
                        fromRow = fromRow + numRows;

                        // Insert the table
                        range            = sheet.Cells[4, 1, 4 + numRows, 5 + numColumns];
                        table            = sheet.Tables.Add(range, getExcelTableOrSheetSafeString(String.Format(TABLE_HEALTH_CHECK_RULE_CATEGORY_RESULTS, category)));
                        table.ShowHeader = true;
                        table.TableStyle = TableStyles.None;
                        table.TableStyle = TableStyles.Medium2;
                        table.ShowFilter = true;
                        table.ShowTotal  = false;

                        // Resize the columns
                        sheet.Column(table.Columns["Controller"].Position + 1).Width  = 20;
                        sheet.Column(table.Columns["Application"].Position + 1).Width = 25;
                        sheet.Column(table.Columns["EntityName"].Position + 1).Width  = 25;
                        sheet.Column(table.Columns["EntityType"].Position + 1).Width  = 25;
                        for (int columnIndex = 0; columnIndex < numColumns; columnIndex++)
                        {
                            sheet.Column(gradeColumnStart + columnIndex).Width = 15;
                            // Make the header column cells wrap text for Categories headings
                            sheet.Cells[rowTableStart, gradeColumnStart + columnIndex].Style.WrapText = true;
                        }

                        // Make header row taller
                        sheet.Row(rowTableStart).Height = 50;

                        if (sheet.Dimension.Rows > rowTableStart)
                        {
                            // Color code it
                            ExcelAddress cfGradeNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, 5, sheet.Dimension.Rows, 5 + numColumns);
                            var          cfGrade    = sheet.ConditionalFormatting.AddThreeColorScale(cfGradeNum);
                            cfGrade.LowValue.Type     = eExcelConditionalFormattingValueObjectType.Num;
                            cfGrade.LowValue.Color    = colorRedFor3ColorScales;
                            cfGrade.LowValue.Value    = 1;
                            cfGrade.MiddleValue.Type  = eExcelConditionalFormattingValueObjectType.Num;
                            cfGrade.MiddleValue.Value = 3;
                            cfGrade.MiddleValue.Color = colorYellowFor3ColorScales;
                            cfGrade.HighValue.Type    = eExcelConditionalFormattingValueObjectType.Num;
                            cfGrade.HighValue.Color   = colorGreenFor3ColorScales;
                            cfGrade.HighValue.Value   = 5;
                        }
                    }

                    #endregion
                }

                #endregion

                #region TOC sheet

                // TOC sheet again
                sheet = excelReport.Workbook.Worksheets[SHEET_TOC];
                fillTableOfContentsSheet(sheet, excelReport);

                #endregion

                #region Save file

                FileIOHelper.CreateFolder(FilePathMap.ReportFolderPath());

                string reportFilePath = FilePathMap.HealthCheckResultsExcelReportFilePath(jobConfiguration.Input.TimeRange);
                logger.Info("Saving Excel report {0}", reportFilePath);
                loggerConsole.Info("Saving Excel report {0}", reportFilePath);

                try
                {
                    // Save full report Excel files
                    excelReport.SaveAs(new FileInfo(reportFilePath));
                }
                catch (InvalidOperationException ex)
                {
                    logger.Warn("Unable to save Excel file {0}", reportFilePath);
                    logger.Warn(ex);
                    loggerConsole.Warn("Unable to save Excel file {0}", reportFilePath);
                }

                #endregion

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
Ejemplo n.º 18
0
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            try
            {
                if (this.ShouldExecute(jobConfiguration) == false)
                {
                    return(true);
                }

                List <MetricExtractMapping> entityMetricExtractMappingList = getMetricsExtractMappingList(jobConfiguration);

                // Process each target
                for (int i = 0; i < jobConfiguration.Target.Count; i++)
                {
                    Stopwatch stopWatchTarget = new Stopwatch();
                    stopWatchTarget.Start();

                    JobTarget jobTarget = jobConfiguration.Target[i];

                    StepTiming stepTimingTarget = new StepTiming();
                    stepTimingTarget.Controller      = jobTarget.Controller;
                    stepTimingTarget.ApplicationName = jobTarget.Application;
                    stepTimingTarget.ApplicationID   = jobTarget.ApplicationID;
                    stepTimingTarget.JobFileName     = programOptions.OutputJobFilePath;
                    stepTimingTarget.StepName        = jobConfiguration.Status.ToString();
                    stepTimingTarget.StepID          = (int)jobConfiguration.Status;
                    stepTimingTarget.StartTime       = DateTime.Now;

                    try
                    {
                        this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1);

                        #region Target state check

                        if (jobTarget.Status != JobTargetStatus.ConfigurationValid)
                        {
                            loggerConsole.Trace("Target in invalid state {0}, skipping", jobTarget.Status);

                            continue;
                        }

                        #endregion

                        #region Target step variables

                        stepTimingTarget.NumEntities = entityMetricExtractMappingList.Count;

                        #endregion

                        loggerConsole.Info("Extract Metrics for All Entities ({0} time ranges)", jobConfiguration.Input.HourlyTimeRanges.Count);

                        Parallel.Invoke(
                            () =>
                        {
                            #region Application

                            getMetricsForEntities(jobTarget, jobConfiguration, entityMetricExtractMappingList, EntityApplication.ENTITY_FOLDER, EntityApplication.ENTITY_TYPE);

                            #endregion
                        },
                            () =>
                        {
                            #region Tiers

                            getMetricsForEntities(jobTarget, jobConfiguration, entityMetricExtractMappingList, EntityTier.ENTITY_FOLDER, EntityTier.ENTITY_TYPE);

                            #endregion
                        },
                            () =>
                        {
                            #region Nodes

                            getMetricsForEntities(jobTarget, jobConfiguration, entityMetricExtractMappingList, EntityNode.ENTITY_FOLDER, EntityNode.ENTITY_TYPE);

                            #endregion
                        },
                            () =>
                        {
                            #region Backends

                            getMetricsForEntities(jobTarget, jobConfiguration, entityMetricExtractMappingList, EntityBackend.ENTITY_FOLDER, EntityBackend.ENTITY_TYPE);

                            #endregion
                        },
                            () =>
                        {
                            #region Business Transactions

                            getMetricsForEntities(jobTarget, jobConfiguration, entityMetricExtractMappingList, EntityBusinessTransaction.ENTITY_FOLDER, EntityBusinessTransaction.ENTITY_TYPE);

                            #endregion
                        },
                            () =>
                        {
                            #region Service Endpoints

                            getMetricsForEntities(jobTarget, jobConfiguration, entityMetricExtractMappingList, EntityServiceEndpoint.ENTITY_FOLDER, EntityServiceEndpoint.ENTITY_TYPE);

                            #endregion
                        },
                            () =>
                        {
                            #region Errors

                            getMetricsForEntities(jobTarget, jobConfiguration, entityMetricExtractMappingList, EntityError.ENTITY_FOLDER, EntityError.ENTITY_TYPE);

                            #endregion
                        },
                            () =>
                        {
                            #region Information Points

                            getMetricsForEntities(jobTarget, jobConfiguration, entityMetricExtractMappingList, EntityInformationPoint.ENTITY_FOLDER, EntityInformationPoint.ENTITY_TYPE);

                            #endregion
                        }
                            );
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                        loggerConsole.Warn(ex);
                    }
                    finally
                    {
                        stopWatchTarget.Stop();

                        this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget);

                        stepTimingTarget.EndTime    = DateTime.Now;
                        stepTimingTarget.Duration   = stopWatchTarget.Elapsed;
                        stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds;

                        List <StepTiming> stepTimings = new List <StepTiming>(1);
                        stepTimings.Add(stepTimingTarget);
                        FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
Ejemplo n.º 19
0
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            if (this.ShouldExecute(programOptions, jobConfiguration) == false)
            {
                return(true);
            }

            if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_BIQ) == 0)
            {
                logger.Warn("No {0} targets to process", APPLICATION_TYPE_BIQ);
                loggerConsole.Warn("No {0} targets to process", APPLICATION_TYPE_BIQ);

                return(true);
            }

            try
            {
                loggerConsole.Info("Prepare Detected BIQ Entities Report File");

                #region Prepare the report package

                // Prepare package
                ExcelPackage excelReport = new ExcelPackage();
                excelReport.Workbook.Properties.Author  = String.Format("AppDynamics DEXTER {0}", Assembly.GetEntryAssembly().GetName().Version);
                excelReport.Workbook.Properties.Title   = "AppDynamics DEXTER Detected BIQ Entities Report";
                excelReport.Workbook.Properties.Subject = programOptions.JobName;

                excelReport.Workbook.Properties.Comments = String.Format("Targets={0}\nFrom={1:o}\nTo={2:o}", jobConfiguration.Target.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To);

                #endregion

                #region Parameters sheet

                // Parameters sheet
                ExcelWorksheet sheet = excelReport.Workbook.Worksheets.Add(SHEET_PARAMETERS);

                var hyperLinkStyle = sheet.Workbook.Styles.CreateNamedStyle("HyperLinkStyle");
                hyperLinkStyle.Style.Font.UnderLineType = ExcelUnderLineType.Single;
                hyperLinkStyle.Style.Font.Color.SetColor(colorBlueForHyperlinks);

                fillReportParametersSheet(sheet, jobConfiguration, "AppDynamics DEXTER Detected BIQ Entities Report");

                #endregion

                #region TOC sheet

                // Navigation sheet with link to other sheets
                sheet = excelReport.Workbook.Worksheets.Add(SHEET_TOC);

                #endregion

                #region Entity sheets and their associated pivots

                // Entity sheets
                sheet = excelReport.Workbook.Worksheets.Add(SHEET_CONTROLLERS_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_APPLICATIONS_ALL_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_APPLICATIONS_BIQ_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_SEARCHES_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Pivot";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_SEARCHES_TYPE_PIVOT);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_SEARCHES_TYPE_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_SEARCHES_LIST);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 4, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_WIDGETS_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Pivot";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_WIDGETS_TYPE_PIVOT);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_WIDGETS_TYPE_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_WIDGETS_LIST);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_SAVED_METRICS_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Pivot";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_SAVED_METRICS_TYPE_PIVOT);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_SAVED_METRICS_TYPE_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_SAVED_METRICS_LIST);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_BUSINESS_JOURNEYS_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Pivot";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_BUSINESS_JOURNEYS_TYPE_PIVOT);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_BUSINESS_JOURNEYS_TYPE_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_BUSINESS_JOURNEYS_LIST);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_EXPERIENCE_LEVELS_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Pivot";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_EXPERIENCE_LEVELS_TYPE_PIVOT);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_EXPERIENCE_LEVELS_TYPE_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_EXPERIENCE_LEVELS_LIST);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 4, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_SCHEMAS_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_FIELDS_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Pivot";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_FIELDS_TYPE_PIVOT);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_FIELDS_TYPE_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_FIELDS_LIST);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 4, 1);

                #endregion

                loggerConsole.Info("Fill Detected BIQ Entities Report File");

                #region Report file variables

                ExcelRangeBase range = null;
                ExcelTable     table = null;

                #endregion

                #region Controllers

                loggerConsole.Info("List of Controllers");

                sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerSummaryReportFilePath(), 0, typeof(ControllerSummary), sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Applications - All

                loggerConsole.Info("List of Applications - All");

                sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ALL_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerApplicationsReportFilePath(), 0, typeof(ControllerApplication), sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Applications

                loggerConsole.Info("List of Applications");

                sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_BIQ_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.BIQApplicationsReportFilePath(), 0, typeof(BIQApplication), sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Searches

                loggerConsole.Info("List of Searches");

                sheet = excelReport.Workbook.Worksheets[SHEET_SEARCHES_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.BIQSearchesReportFilePath(), 0, typeof(BIQSearch), sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Widgets

                loggerConsole.Info("List of Widgets");

                sheet = excelReport.Workbook.Worksheets[SHEET_WIDGETS_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.BIQWidgetsReportFilePath(), 0, typeof(BIQWidget), sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Saved Metrics

                loggerConsole.Info("List of Saved Metrics");

                sheet = excelReport.Workbook.Worksheets[SHEET_SAVED_METRICS_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.BIQMetricsReportFilePath(), 0, typeof(BIQMetric), sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Business Journeys

                loggerConsole.Info("List of Business Journeys");

                sheet = excelReport.Workbook.Worksheets[SHEET_BUSINESS_JOURNEYS_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.BIQBusinessJourneysReportFilePath(), 0, typeof(BIQBusinessJourney), sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Experience Levels

                loggerConsole.Info("List of Experience Levels");

                sheet = excelReport.Workbook.Worksheets[SHEET_EXPERIENCE_LEVELS_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.BIQExperienceLevelsReportFilePath(), 0, typeof(BIQExperienceLevel), sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Schemas

                loggerConsole.Info("List of Schemas");

                sheet = excelReport.Workbook.Worksheets[SHEET_SCHEMAS_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.BIQSchemasReportFilePath(), 0, typeof(BIQSchema), sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Schema Fields

                loggerConsole.Info("List of Schema Fields");

                sheet = excelReport.Workbook.Worksheets[SHEET_FIELDS_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.BIQSchemaFieldsReportFilePath(), 0, typeof(BIQSchema), sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                loggerConsole.Info("Finalize Detected BIQ Entities Report File");

                #region Controllers sheet

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_CONTROLLERS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width = 25;
                    sheet.Column(table.Columns["Version"].Position + 1).Width    = 15;
                }

                #endregion

                #region Applications - All

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ALL_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_APPLICATIONS_ALL);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["Description"].Position + 1).Width     = 15;

                    sheet.Column(table.Columns["CreatedBy"].Position + 1).Width = 15;
                    sheet.Column(table.Columns["UpdatedBy"].Position + 1).Width = 15;

                    sheet.Column(table.Columns["CreatedOn"].Position + 1).Width    = 20;
                    sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width    = 20;
                    sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width = 20;
                }

                #endregion

                #region Applications

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_BIQ_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_APPLICATIONS_BIQ);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20;

                    ExcelAddress cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSearches"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSearches"].Position + 1);
                    var          cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumMultiSearches"].Position + 1, sheet.Dimension.Rows, table.Columns["NumMultiSearches"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSingleSearches"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSingleSearches"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumLegacySearches"].Position + 1, sheet.Dimension.Rows, table.Columns["NumLegacySearches"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSavedMetrics"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSavedMetrics"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumBusinessJourneys"].Position + 1, sheet.Dimension.Rows, table.Columns["NumBusinessJourneys"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumExperienceLevels"].Position + 1, sheet.Dimension.Rows, table.Columns["NumExperienceLevels"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSchemas"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSchemas"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumFields"].Position + 1, sheet.Dimension.Rows, table.Columns["NumFields"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);
                }

                #endregion

                #region Searches

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_SEARCHES_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_SEARCHES);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["SearchName"].Position + 1).Width      = 20;
                    sheet.Column(table.Columns["SearchType"].Position + 1).Width      = 10;
                    sheet.Column(table.Columns["SearchMode"].Position + 1).Width      = 10;
                    sheet.Column(table.Columns["Visualization"].Position + 1).Width   = 10;
                    sheet.Column(table.Columns["ViewMode"].Position + 1).Width        = 10;
                    sheet.Column(table.Columns["DataSource"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["CreatedOn"].Position + 1).Width       = 20;
                    sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width       = 20;
                    sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width    = 20;
                    sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width    = 20;

                    // Make pivot
                    sheet = excelReport.Workbook.Worksheets[SHEET_SEARCHES_TYPE_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 1, 1], range, PIVOT_SEARCHES_TYPE);
                    setDefaultPivotTableSettings(pivot);
                    addFilterFieldToPivot(pivot, "ViewMode");
                    addRowFieldToPivot(pivot, "Controller");
                    addRowFieldToPivot(pivot, "DataSource");
                    addRowFieldToPivot(pivot, "SearchName");
                    addColumnFieldToPivot(pivot, "SearchMode");
                    addColumnFieldToPivot(pivot, "SearchType");
                    addDataFieldToPivot(pivot, "NumWidgets", DataFieldFunctions.Sum, "NumWidgets");

                    ExcelChart chart = sheet.Drawings.AddChart(GRAPH_SEARCHES_TYPE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                    sheet.Column(3).Width = 20;
                }

                #endregion

                #region Widgets

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_WIDGETS_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_WIDGETS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["SearchName"].Position + 1).Width      = 20;
                    sheet.Column(table.Columns["SearchType"].Position + 1).Width      = 10;
                    sheet.Column(table.Columns["WidgetName"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["WidgetType"].Position + 1).Width      = 10;
                    sheet.Column(table.Columns["DataSource"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["StartTime"].Position + 1).Width       = 20;
                    sheet.Column(table.Columns["EndTime"].Position + 1).Width         = 20;
                    sheet.Column(table.Columns["StartTimeUtc"].Position + 1).Width    = 20;
                    sheet.Column(table.Columns["EndTime"].Position + 1).Width         = 20;

                    // Make pivot
                    sheet = excelReport.Workbook.Worksheets[SHEET_WIDGETS_TYPE_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_WIDGETS_TYPE);
                    setDefaultPivotTableSettings(pivot);
                    addFilterFieldToPivot(pivot, "Resolution", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "IsStacking");
                    addRowFieldToPivot(pivot, "Controller");
                    addRowFieldToPivot(pivot, "DataSource");
                    addRowFieldToPivot(pivot, "SearchName");
                    addRowFieldToPivot(pivot, "WidgetName");
                    addColumnFieldToPivot(pivot, "WidgetType");
                    addDataFieldToPivot(pivot, "WidgetID", DataFieldFunctions.Count);

                    ExcelChart chart = sheet.Drawings.AddChart(GRAPH_WIDGETS_TYPE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                    sheet.Column(3).Width = 20;
                    sheet.Column(4).Width = 20;
                }

                #endregion

                #region Saved Metrics

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_SAVED_METRICS_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_SAVED_METRICS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["MetricName"].Position + 1).Width      = 20;
                    sheet.Column(table.Columns["DataSource"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["EventType"].Position + 1).Width       = 15;
                    sheet.Column(table.Columns["CreatedOn"].Position + 1).Width       = 20;
                    sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width    = 20;

                    // Make pivot
                    sheet = excelReport.Workbook.Worksheets[SHEET_SAVED_METRICS_TYPE_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_SAVED_METRICS_TYPE);
                    setDefaultPivotTableSettings(pivot);
                    addFilterFieldToPivot(pivot, "IsEnabled");
                    addRowFieldToPivot(pivot, "Controller");
                    addRowFieldToPivot(pivot, "DataSource");
                    addRowFieldToPivot(pivot, "MetricName");
                    addColumnFieldToPivot(pivot, "LastExecStatus");
                    addDataFieldToPivot(pivot, "MetricName", DataFieldFunctions.Count);

                    ExcelChart chart = sheet.Drawings.AddChart(GRAPH_SAVED_METRICS_TYPE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                    sheet.Column(3).Width = 20;
                }

                #endregion

                #region Business Journeys

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_BUSINESS_JOURNEYS_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_BUSINESS_JOURNEYS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["JourneyName"].Position + 1).Width     = 20;
                    sheet.Column(table.Columns["Stages"].Position + 1).Width          = 30;
                    sheet.Column(table.Columns["CreatedOn"].Position + 1).Width       = 20;
                    sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width       = 20;
                    sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width    = 20;
                    sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width    = 20;

                    // Make pivot
                    sheet = excelReport.Workbook.Worksheets[SHEET_BUSINESS_JOURNEYS_TYPE_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_BUSINESS_JOURNEY_TYPE);
                    setDefaultPivotTableSettings(pivot);
                    addFilterFieldToPivot(pivot, "NumStages", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "IsEnabled");
                    addRowFieldToPivot(pivot, "Controller");
                    addRowFieldToPivot(pivot, "KeyField");
                    addRowFieldToPivot(pivot, "JourneyName");
                    addDataFieldToPivot(pivot, "JourneyID", DataFieldFunctions.Count);

                    ExcelChart chart = sheet.Drawings.AddChart(GRAPH_BUSINESS_JOURNEY_TYPE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                    sheet.Column(3).Width = 20;
                }

                #endregion

                #region Experience Levels

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_EXPERIENCE_LEVELS_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_EXPERIENCE_LEVELS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width          = 15;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width     = 20;
                    sheet.Column(table.Columns["ExperienceLevelName"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["DataSource"].Position + 1).Width          = 15;
                    sheet.Column(table.Columns["EventField"].Position + 1).Width          = 15;
                    sheet.Column(table.Columns["StartOn"].Position + 1).Width             = 20;
                    sheet.Column(table.Columns["CreatedOn"].Position + 1).Width           = 20;
                    sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width           = 20;
                    sheet.Column(table.Columns["StartOnUtc"].Position + 1).Width          = 20;
                    sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width        = 20;
                    sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width        = 20;

                    // Make pivot
                    sheet = excelReport.Workbook.Worksheets[SHEET_EXPERIENCE_LEVELS_TYPE_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1], range, PIVOT_EXPERIENCE_LEVELS_TYPE);
                    setDefaultPivotTableSettings(pivot);
                    addFilterFieldToPivot(pivot, "IsActive");
                    addFilterFieldToPivot(pivot, "EventField", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "ThresholdOperator", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "ThresholdValue", eSortType.Ascending);
                    addRowFieldToPivot(pivot, "Controller");
                    addRowFieldToPivot(pivot, "DataSource");
                    addRowFieldToPivot(pivot, "Criteria");
                    addRowFieldToPivot(pivot, "ExperienceLevelName");
                    addColumnFieldToPivot(pivot, "Period");
                    addDataFieldToPivot(pivot, "ExperienceLevelName", DataFieldFunctions.Count);

                    ExcelChart chart = sheet.Drawings.AddChart(GRAPH_EXPERIENCE_LEVELS_TYPE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                    sheet.Column(3).Width = 20;
                    sheet.Column(4).Width = 20;
                }

                #endregion

                #region Schemas

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_SCHEMAS_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_SCHEMAS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["SchemaName"].Position + 1).Width      = 20;
                }

                #endregion

                #region Schema Fields

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_FIELDS_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_FIELDS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["SchemaName"].Position + 1).Width      = 20;
                    sheet.Column(table.Columns["FieldName"].Position + 1).Width       = 20;
                    sheet.Column(table.Columns["FieldType"].Position + 1).Width       = 15;

                    // Make pivot
                    sheet = excelReport.Workbook.Worksheets[SHEET_FIELDS_TYPE_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1], range, PIVOT_FIELD_TYPE);
                    setDefaultPivotTableSettings(pivot);
                    addFilterFieldToPivot(pivot, "Category", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "NumParents", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "IsHidden");
                    addFilterFieldToPivot(pivot, "IsDeleted");
                    addRowFieldToPivot(pivot, "Controller");
                    addRowFieldToPivot(pivot, "SchemaName");
                    addRowFieldToPivot(pivot, "FieldName");
                    addColumnFieldToPivot(pivot, "FieldType");
                    addDataFieldToPivot(pivot, "FieldName", DataFieldFunctions.Count);

                    ExcelChart chart = sheet.Drawings.AddChart(GRAPH_FIELD_TYPE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                    sheet.Column(3).Width = 20;
                }

                #endregion

                #region TOC sheet

                // TOC sheet again
                sheet = excelReport.Workbook.Worksheets[SHEET_TOC];
                fillTableOfContentsSheet(sheet, excelReport);

                #endregion

                #region Save file

                FileIOHelper.CreateFolder(FilePathMap.ReportFolderPath());

                string reportFilePath = FilePathMap.BIQEntitiesExcelReportFilePath(jobConfiguration.Input.TimeRange);
                logger.Info("Saving Excel report {0}", reportFilePath);
                loggerConsole.Info("Saving Excel report {0}", reportFilePath);

                try
                {
                    // Save full report Excel files
                    excelReport.SaveAs(new FileInfo(reportFilePath));
                }
                catch (InvalidOperationException ex)
                {
                    logger.Warn("Unable to save Excel file {0}", reportFilePath);
                    logger.Warn(ex);
                    loggerConsole.Warn("Unable to save Excel file {0}", reportFilePath);
                }

                #endregion

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            try
            {
                if (this.ShouldExecute(programOptions, jobConfiguration) == false)
                {
                    return(true);
                }

                bool reportFolderCleaned = false;

                // Process each Controller once
                int i           = 0;
                var controllers = jobConfiguration.Target.GroupBy(t => t.Controller);
                foreach (var controllerGroup in controllers)
                {
                    Stopwatch stopWatchTarget = new Stopwatch();
                    stopWatchTarget.Start();

                    JobTarget jobTarget = controllerGroup.ToList()[0];

                    StepTiming stepTimingTarget = new StepTiming();
                    stepTimingTarget.Controller      = jobTarget.Controller;
                    stepTimingTarget.ApplicationName = jobTarget.Application;
                    stepTimingTarget.ApplicationID   = jobTarget.ApplicationID;
                    stepTimingTarget.JobFileName     = programOptions.OutputJobFilePath;
                    stepTimingTarget.StepName        = jobConfiguration.Status.ToString();
                    stepTimingTarget.StepID          = (int)jobConfiguration.Status;
                    stepTimingTarget.StartTime       = DateTime.Now;

                    try
                    {
                        this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1);

                        #region Target step variables

                        List <HealthCheckRuleResult> healthCheckRuleResults = new List <HealthCheckRuleResult>();

                        #endregion

                        #region Preload all the reports that will be filtered by the subsequent entities

                        loggerConsole.Info("Entity Details Data Preloading");

                        // This file will always be there
                        List <HealthCheckSettingMapping> healthCheckSettingsList = FileIOHelper.ReadListFromCSVFile <HealthCheckSettingMapping>(FilePathMap.HealthCheckSettingMappingFilePath(), new HealthCheckSettingMappingMap());
                        if (healthCheckSettingsList == null || healthCheckSettingsList.Count == 0)
                        {
                            loggerConsole.Warn("Health check settings file did not load. Exiting the health checks");

                            return(false);
                        }
                        Dictionary <string, HealthCheckSettingMapping> healthCheckSettingsDictionary = healthCheckSettingsList.ToDictionary(h => h.Name, h => h);

                        List <ControllerSummary> controllerSummariesList = FileIOHelper.ReadListFromCSVFile <ControllerSummary>(FilePathMap.ControllerSummaryIndexFilePath(jobTarget), new ControllerSummaryReportMap());
                        List <ControllerSetting> controllerSettingsList  = FileIOHelper.ReadListFromCSVFile <ControllerSetting>(FilePathMap.ControllerSettingsIndexFilePath(jobTarget), new ControllerSettingReportMap());

                        #endregion

                        #region Controller Version and Properties

                        healthCheckRuleResults.Add(
                            evaluate_Controller_Version(
                                new HealthCheckRuleDescription("Platform", "PLAT-001-PLATFORM-VERSION", "Controller Version"),
                                jobTarget,
                                healthCheckSettingsDictionary,
                                controllerSummariesList));

                        healthCheckRuleResults.Add(
                            evaluate_Controller_SaaS_OnPrem(
                                new HealthCheckRuleDescription("Platform", "PLAT-002-PLATFORM-SAAS", "SaaS or OnPrem"),
                                jobTarget,
                                healthCheckSettingsDictionary));

                        healthCheckRuleResults.Add(
                            evaluate_Controller_Setting_Performance_Profile(
                                new HealthCheckRuleDescription("Platform", "PLAT-003-PLATFORM-PERFORMANCE-PROFILE", "Performance Profile"),
                                jobTarget,
                                healthCheckSettingsDictionary,
                                controllerSettingsList));

                        healthCheckRuleResults.AddRange(
                            evaluate_Controller_Setting_Buffer_Sizes(
                                new HealthCheckRuleDescription("Platform", "PLAT-004-PLATFORM-BUFFER-SIZES", "Buffer Size"),
                                jobTarget,
                                healthCheckSettingsDictionary,
                                controllerSettingsList));

                        healthCheckRuleResults.AddRange(
                            evaluate_Controller_Setting_ADD_Limits(
                                new HealthCheckRuleDescription("Platform", "PLAT-005-PLATFORM-ADD-LIMITS", "ADD Limit"),
                                jobTarget,
                                healthCheckSettingsDictionary,
                                controllerSettingsList));


                        // TODO Add things like ADD limits, etc

                        #endregion

                        // Remove any health rule results that weren't very good
                        healthCheckRuleResults.RemoveAll(h => h == null);

                        // Sort them
                        healthCheckRuleResults = healthCheckRuleResults.OrderBy(h => h.EntityType).ThenBy(h => h.EntityName).ThenBy(h => h.Category).ThenBy(h => h.Name).ToList();

                        // Set version to each of the health check rule results
                        string versionOfDEXTER = Assembly.GetEntryAssembly().GetName().Version.ToString();
                        foreach (HealthCheckRuleResult healthCheckRuleResult in healthCheckRuleResults)
                        {
                            healthCheckRuleResult.Version = versionOfDEXTER;
                        }

                        FileIOHelper.WriteListToCSVFile(healthCheckRuleResults, new HealthCheckRuleResultReportMap(), FilePathMap.ControllerHealthCheckRuleResultsIndexFilePath(jobTarget));

                        stepTimingTarget.NumEntities = healthCheckRuleResults.Count;

                        #region Combine All for Report CSV

                        // If it is the first one, clear out the combined folder
                        if (reportFolderCleaned == false)
                        {
                            FileIOHelper.DeleteFolder(FilePathMap.ControllerHealthCheckReportFolderPath());
                            Thread.Sleep(1000);
                            FileIOHelper.CreateFolder(FilePathMap.ControllerHealthCheckReportFolderPath());
                            reportFolderCleaned = true;
                        }

                        // Append all the individual report files into one
                        if (File.Exists(FilePathMap.ControllerHealthCheckRuleResultsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ControllerHealthCheckRuleResultsIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.ControllerHealthCheckRuleResultsReportFilePath(), FilePathMap.ControllerHealthCheckRuleResultsIndexFilePath(jobTarget));
                        }

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                        loggerConsole.Warn(ex);

                        return(false);
                    }
                    finally
                    {
                        stopWatchTarget.Stop();

                        this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget);

                        stepTimingTarget.EndTime    = DateTime.Now;
                        stepTimingTarget.Duration   = stopWatchTarget.Elapsed;
                        stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds;

                        List <StepTiming> stepTimings = new List <StepTiming>(1);
                        stepTimings.Add(stepTimingTarget);
                        FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            try
            {
                if (this.ShouldExecute(jobConfiguration) == false)
                {
                    return(true);
                }

                // Process each target
                for (int i = 0; i < jobConfiguration.Target.Count; i++)
                {
                    Stopwatch stopWatchTarget = new Stopwatch();
                    stopWatchTarget.Start();

                    JobTarget jobTarget = jobConfiguration.Target[i];

                    StepTiming stepTimingTarget = new StepTiming();
                    stepTimingTarget.Controller      = jobTarget.Controller;
                    stepTimingTarget.ApplicationName = jobTarget.Application;
                    stepTimingTarget.ApplicationID   = jobTarget.ApplicationID;
                    stepTimingTarget.JobFileName     = programOptions.OutputJobFilePath;
                    stepTimingTarget.StepName        = jobConfiguration.Status.ToString();
                    stepTimingTarget.StepID          = (int)jobConfiguration.Status;
                    stepTimingTarget.StartTime       = DateTime.Now;

                    try
                    {
                        this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1);

                        #region Target state check

                        if (jobTarget.Status != JobTargetStatus.ConfigurationValid)
                        {
                            loggerConsole.Trace("Target in invalid state {0}, skipping", jobTarget.Status);

                            continue;
                        }

                        #endregion

                        #region Target step variables

                        // Set up controller access
                        ControllerApi controllerApi = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword));

                        // Login into private API
                        controllerApi.PrivateApiLogin();

                        #endregion

                        #region Get list of Snapshots in time ranges

                        loggerConsole.Info("Extract List of Snapshots ({0} time ranges)", jobConfiguration.Input.HourlyTimeRanges.Count);

                        // Get list of snapshots in each time range
                        int totalSnapshotsFound = 0;
                        foreach (JobTimeRange jobTimeRange in jobConfiguration.Input.HourlyTimeRanges)
                        {
                            logger.Info("Extract List of Snapshots from {0:o} to {1:o}", jobTimeRange.From, jobTimeRange.To);
                            loggerConsole.Info("Extract List of Snapshots from {0:G} to {1:G}", jobTimeRange.From.ToLocalTime(), jobTimeRange.To.ToLocalTime());

                            string snapshotsDataFilePath = FilePathMap.SnapshotsDataFilePath(jobTarget, jobTimeRange);

                            int differenceInMinutes = (int)(jobTimeRange.To - jobTimeRange.From).TotalMinutes;

                            if (File.Exists(snapshotsDataFilePath) == false)
                            {
                                JArray listOfSnapshots = new JArray();

                                // Extract snapshot list
                                long   serverCursorId     = 0;
                                string serverCursorIdType = String.Empty;
                                do
                                {
                                    string snapshotsJSON = String.Empty;
                                    if (serverCursorId == 0)
                                    {
                                        // Extract first page of snapshots
                                        snapshotsJSON = controllerApi.GetListOfSnapshotsFirstPage(jobTarget.ApplicationID, jobTimeRange.From, jobTimeRange.To, differenceInMinutes, SNAPSHOTS_QUERY_PAGE_SIZE);
                                    }
                                    else
                                    {
                                        // If there are more snapshots on the server, the server cursor would be non-0
                                        switch (serverCursorIdType)
                                        {
                                        case "scrollId":
                                            // Sometimes - >4.3.3? the value of scroll is in scrollId, not rsdScrollId
                                            // "serverCursor" : {
                                            //    "scrollId" : 1509543646696
                                            //  }
                                            snapshotsJSON = controllerApi.GetListOfSnapshotsNextPage_Type_scrollId(jobTarget.ApplicationID, jobTimeRange.From, jobTimeRange.To, differenceInMinutes, SNAPSHOTS_QUERY_PAGE_SIZE, serverCursorId);

                                            break;

                                        case "rsdScrollId":
                                            // "serverCursor" : {
                                            //    "rsdScrollId" : 1509543646696
                                            //  }
                                            snapshotsJSON = controllerApi.GetListOfSnapshotsNextPage_Type_rsdScrollId(jobTarget.ApplicationID, jobTimeRange.From, jobTimeRange.To, differenceInMinutes, SNAPSHOTS_QUERY_PAGE_SIZE, serverCursorId);

                                            break;

                                        case "fetchMoreDataHandle":
                                            // Seen this on 4.2.3.0 Controller. Maybe that's how it used to be?
                                            // "fetchMoreDataHandle":1509626881987
                                            // Can't seem to make it load more than 600 items
                                            snapshotsJSON = controllerApi.GetListOfSnapshotsNextPage_Type_handle(jobTarget.ApplicationID, jobTimeRange.From, jobTimeRange.To, differenceInMinutes, SNAPSHOTS_QUERY_PAGE_SIZE, serverCursorId);

                                            break;

                                        default:
                                            logger.Warn("Unknown type of serverCursorIdType={0}, not going to retrieve any snapshots", serverCursorIdType);

                                            break;
                                        }
                                    }

                                    // Assume we have no more pages
                                    serverCursorId = 0;

                                    // Process retrieved snapshots and check if we actually have more pages
                                    if (snapshotsJSON != String.Empty)
                                    {
                                        Console.Write(".");

                                        // Load snapshots into array
                                        JObject snapshotsParsed = JObject.Parse(snapshotsJSON);
                                        JArray  snapshots       = (JArray)snapshotsParsed["requestSegmentDataListItems"];
                                        foreach (JObject snapshot in snapshots)
                                        {
                                            listOfSnapshots.Add(snapshot);
                                        }

                                        // Check whether we have more snapshots and if yes, get continuation type and cursor ID
                                        JToken fetchMoreDataHandleObj = snapshotsParsed["fetchMoreDataHandle"];
                                        JToken serverCursorObj        = snapshotsParsed["serverCursor"];
                                        if (serverCursorObj != null)
                                        {
                                            JToken scrollIdObj    = serverCursorObj["scrollId"];
                                            JToken rsdScrollIdObj = serverCursorObj["rsdScrollId"];

                                            if (scrollIdObj != null)
                                            {
                                                serverCursorIdType = "scrollId";
                                                // Parse the cursor ID
                                                if (Int64.TryParse(scrollIdObj.ToString(), out serverCursorId) == false)
                                                {
                                                    // Nope, not going to go forward
                                                    serverCursorId = 0;
                                                }
                                            }
                                            else if (rsdScrollIdObj != null)
                                            {
                                                serverCursorIdType = "rsdScrollId";
                                                // Parse the cursor ID
                                                if (Int64.TryParse(rsdScrollIdObj.ToString(), out serverCursorId) == false)
                                                {
                                                    // Nope, not going to go forward
                                                    serverCursorId = 0;
                                                }
                                            }
                                        }
                                        else if (fetchMoreDataHandleObj != null)
                                        {
                                            serverCursorIdType = "fetchMoreDataHandle";
                                            // Parse the cursor ID
                                            if (Int64.TryParse(fetchMoreDataHandleObj.ToString(), out serverCursorId) == false)
                                            {
                                                // Nope, not going to go forward
                                                serverCursorId = 0;
                                            }
                                        }
                                        else
                                        {
                                            logger.Warn("Snapshot list retrival call unexpectedly did not have any evidence of continuation CursorId");
                                        }

                                        logger.Info("Retrieved snapshots from Controller {0}, Application {1}, From {2:o}, To {3:o}', number of snapshots {4}, continuation type {5}, continuation CursorId {6}", jobTarget.Controller, jobTarget.Application, jobTimeRange.From, jobTimeRange.To, snapshots.Count, serverCursorIdType, serverCursorId);

                                        // Move to next loop
                                        Console.Write("+{0}", listOfSnapshots.Count);
                                    }
                                }while (serverCursorId > 0);

                                Console.WriteLine();

                                FileIOHelper.WriteJArrayToFile(listOfSnapshots, snapshotsDataFilePath);

                                totalSnapshotsFound = totalSnapshotsFound + listOfSnapshots.Count;

                                logger.Info("{0} snapshots from {1:o} to {2:o}", listOfSnapshots.Count, jobTimeRange.From, jobTimeRange.To);
                                loggerConsole.Info("{0} snapshots from {1:G} to {2:G}", listOfSnapshots.Count, jobTimeRange.From.ToLocalTime(), jobTimeRange.To.ToLocalTime());
                            }
                        }

                        logger.Info("{0} snapshots in all time ranges", totalSnapshotsFound);
                        loggerConsole.Info("{0} snapshots in all time ranges", totalSnapshotsFound);

                        #endregion

                        #region Get individual Snapshots

                        // Extract individual snapshots
                        loggerConsole.Info("Extract Individual Snapshots");

                        List <AppDRESTTier> tiersList = FileIOHelper.LoadListOfObjectsFromFile <AppDRESTTier>(FilePathMap.TiersDataFilePath(jobTarget));
                        List <AppDRESTBusinessTransaction> businessTransactionsList = FileIOHelper.LoadListOfObjectsFromFile <AppDRESTBusinessTransaction>(FilePathMap.BusinessTransactionsDataFilePath(jobTarget));

                        // Identify Node.JS tiers that will extact call graph using a different call
                        List <AppDRESTTier> tiersNodeJSList = null;
                        if (tiersList != null)
                        {
                            tiersNodeJSList = tiersList.Where(t => t.agentType == "NODEJS_APP_AGENT").ToList();
                        }

                        // Process each hour at a time
                        foreach (JobTimeRange jobTimeRange in jobConfiguration.Input.HourlyTimeRanges)
                        {
                            string snapshotsDataFilePath = FilePathMap.SnapshotsDataFilePath(jobTarget, jobTimeRange);

                            JArray listOfSnapshotsInHour = FileIOHelper.LoadJArrayFromFile(snapshotsDataFilePath);
                            if (listOfSnapshotsInHour != null && listOfSnapshotsInHour.Count > 0)
                            {
                                logger.Info("Filter Snapshots {0:o} to {1:o} ({2} snapshots)", jobTimeRange.From, jobTimeRange.To, listOfSnapshotsInHour.Count);
                                loggerConsole.Info("Filter Snapshots {0:G} to {1:G} ({2} snapshots)", jobTimeRange.From.ToLocalTime(), jobTimeRange.To.ToLocalTime(), listOfSnapshotsInHour.Count);

                                // Filter the list of snapshots based on SnapshotSelectionCriteria
                                List <JToken> listOfSnapshotsInHourFiltered = new List <JToken>(listOfSnapshotsInHour.Count);
                                foreach (JToken snapshotToken in listOfSnapshotsInHour)
                                {
                                    logger.Trace("Considering filtering snapshot requestGUID={0}, firstInChain={1}, userExperience={2}, fullCallgraph={3}, delayedCallGraph={4}, applicationComponentName={5}, businessTransactionName={6}",
                                                 snapshotToken["requestGUID"],
                                                 snapshotToken["firstInChain"],
                                                 snapshotToken["userExperience"],
                                                 snapshotToken["fullCallgraph"],
                                                 snapshotToken["delayedCallGraph"],
                                                 snapshotToken["applicationComponentName"],
                                                 snapshotToken["businessTransactionName"]);

                                    // Only grab first in chain snapshots
                                    if ((bool)snapshotToken["firstInChain"] == false)
                                    {
                                        continue;
                                    }

                                    // Filter user experience
                                    switch (snapshotToken["userExperience"].ToString())
                                    {
                                    case "NORMAL":
                                        if (jobConfiguration.Input.SnapshotSelectionCriteria.UserExperience.Normal != true)
                                        {
                                            continue;
                                        }
                                        break;

                                    case "SLOW":
                                        if (jobConfiguration.Input.SnapshotSelectionCriteria.UserExperience.Slow != true)
                                        {
                                            continue;
                                        }
                                        break;

                                    case "VERY_SLOW":
                                        if (jobConfiguration.Input.SnapshotSelectionCriteria.UserExperience.VerySlow != true)
                                        {
                                            continue;
                                        }
                                        break;

                                    case "STALL":
                                        if (jobConfiguration.Input.SnapshotSelectionCriteria.UserExperience.Stall != true)
                                        {
                                            continue;
                                        }
                                        break;

                                    case "ERROR":
                                        if (jobConfiguration.Input.SnapshotSelectionCriteria.UserExperience.Error != true)
                                        {
                                            continue;
                                        }
                                        break;

                                    default:
                                        // Not sure what kind of beast it is
                                        continue;
                                    }

                                    // Filter call graph
                                    if ((bool)snapshotToken["fullCallgraph"] == true)
                                    {
                                        if (jobConfiguration.Input.SnapshotSelectionCriteria.SnapshotType.Full != true)
                                        {
                                            continue;
                                        }
                                    }
                                    else if ((bool)snapshotToken["delayedCallGraph"] == true)
                                    {
                                        if (jobConfiguration.Input.SnapshotSelectionCriteria.SnapshotType.Partial != true)
                                        {
                                            continue;
                                        }
                                    }
                                    else
                                    {
                                        if (jobConfiguration.Input.SnapshotSelectionCriteria.SnapshotType.None != true)
                                        {
                                            continue;
                                        }
                                    }

                                    // Filter Tier type
                                    if (jobConfiguration.Input.SnapshotSelectionCriteria.TierType.All != true)
                                    {
                                        if (tiersList != null)
                                        {
                                            AppDRESTTier tier = tiersList.Where(t => t.id == (long)snapshotToken["applicationComponentId"]).FirstOrDefault();
                                            if (tier != null)
                                            {
                                                PropertyInfo pi = jobConfiguration.Input.SnapshotSelectionCriteria.TierType.GetType().GetProperty(tier.agentType);
                                                if (pi != null)
                                                {
                                                    if ((bool)pi.GetValue(jobConfiguration.Input.SnapshotSelectionCriteria.TierType) == false)
                                                    {
                                                        continue;
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // Filter BT type
                                    if (jobConfiguration.Input.SnapshotSelectionCriteria.BusinessTransactionType.All != true)
                                    {
                                        if (businessTransactionsList != null)
                                        {
                                            AppDRESTBusinessTransaction businessTransaction = businessTransactionsList.Where(b => b.id == (long)snapshotToken["businessTransactionId"] && b.tierId == (long)snapshotToken["applicationComponentId"]).FirstOrDefault();
                                            if (businessTransaction != null)
                                            {
                                                PropertyInfo pi = jobConfiguration.Input.SnapshotSelectionCriteria.BusinessTransactionType.GetType().GetProperty(businessTransaction.entryPointType);
                                                if (pi != null)
                                                {
                                                    if ((bool)pi.GetValue(jobConfiguration.Input.SnapshotSelectionCriteria.BusinessTransactionType) == false)
                                                    {
                                                        continue;
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // Filter Tier name
                                    bool tierNameMatch = false;
                                    if (jobConfiguration.Input.SnapshotSelectionCriteria.Tiers.Length == 0)
                                    {
                                        tierNameMatch = true;
                                    }
                                    foreach (string matchCriteria in jobConfiguration.Input.SnapshotSelectionCriteria.Tiers)
                                    {
                                        if (matchCriteria.Length > 0)
                                        {
                                            // Try straight up string compare first
                                            if (String.Compare(snapshotToken["applicationComponentName"].ToString(), matchCriteria, true) == 0)
                                            {
                                                tierNameMatch = true;
                                                break;
                                            }

                                            // Try regex compare second
                                            Regex regexQuery = new Regex(matchCriteria, RegexOptions.IgnoreCase);
                                            Match regexMatch = regexQuery.Match(snapshotToken["applicationComponentName"].ToString());
                                            if (regexMatch.Success == true && regexMatch.Index == 0)
                                            {
                                                tierNameMatch = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (tierNameMatch == false)
                                    {
                                        continue;
                                    }

                                    // Filter BT name
                                    bool businessTransactionNameMatch = false;
                                    if (jobConfiguration.Input.SnapshotSelectionCriteria.BusinessTransactions.Length == 0)
                                    {
                                        businessTransactionNameMatch = true;
                                    }
                                    foreach (string matchCriteria in jobConfiguration.Input.SnapshotSelectionCriteria.BusinessTransactions)
                                    {
                                        if (matchCriteria.Length > 0)
                                        {
                                            // Try straight up string compare first
                                            if (String.Compare(snapshotToken["businessTransactionName"].ToString(), matchCriteria, true) == 0)
                                            {
                                                businessTransactionNameMatch = true;
                                                break;
                                            }

                                            // Try regex compare second
                                            Regex regexQuery = new Regex(matchCriteria, RegexOptions.IgnoreCase);
                                            Match regexMatch = regexQuery.Match(snapshotToken["businessTransactionName"].ToString());
                                            if (regexMatch.Success == true && regexMatch.Index == 0)
                                            {
                                                businessTransactionNameMatch = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (businessTransactionNameMatch == false)
                                    {
                                        continue;
                                    }

                                    // If we got here, then the snapshot passed the filter
                                    logger.Trace("Keeping snapshot requestGUID={0}, firstInChain={1}, userExperience={2}, fullCallgraph={3}, delayedCallGraph={4}, applicationComponentName={5}, businessTransactionName={6}",
                                                 snapshotToken["requestGUID"],
                                                 snapshotToken["firstInChain"],
                                                 snapshotToken["userExperience"],
                                                 snapshotToken["fullCallgraph"],
                                                 snapshotToken["delayedCallGraph"],
                                                 snapshotToken["applicationComponentName"],
                                                 snapshotToken["businessTransactionName"]);

                                    listOfSnapshotsInHourFiltered.Add(snapshotToken);
                                }

                                logger.Info("Total Snapshots {0:o} to {1:o} is {2}, after filtered {3}", jobTimeRange.From.ToLocalTime(), jobTimeRange.To.ToLocalTime(), listOfSnapshotsInHour.Count, listOfSnapshotsInHourFiltered.Count);

                                // Now extract things
                                logger.Info("Extract Snapshots {0:o} to {1:o} ({2} snapshots)", jobTimeRange.From, jobTimeRange.To, listOfSnapshotsInHourFiltered.Count);
                                loggerConsole.Info("Extract Snapshots {0:G} to {1:G} ({2} snapshots)", jobTimeRange.From.ToLocalTime(), jobTimeRange.To.ToLocalTime(), listOfSnapshotsInHourFiltered.Count);

                                stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + listOfSnapshotsInHourFiltered.Count;

                                int numSnapshots = 0;

                                if (programOptions.ProcessSequentially == false)
                                {
                                    var listOfSnapshotsInHourChunks = listOfSnapshotsInHourFiltered.BreakListIntoChunks(SNAPSHOTS_EXTRACT_NUMBER_OF_ENTITIES_TO_PROCESS_PER_THREAD);

                                    Parallel.ForEach <List <JToken>, int>(
                                        listOfSnapshotsInHourChunks,
                                        new ParallelOptions {
                                        MaxDegreeOfParallelism = SNAPSHOTS_EXTRACT_NUMBER_OF_THREADS
                                    },
                                        () => 0,
                                        (listOfSnapshotsInHourChunk, loop, subtotal) =>
                                    {
                                        // Set up controller access
                                        ControllerApi controllerApiParallel = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword));
                                        // Login into private API
                                        controllerApiParallel.PrivateApiLogin();

                                        subtotal += extractSnapshots(jobConfiguration, jobTarget, controllerApiParallel, listOfSnapshotsInHourChunk, tiersNodeJSList, false);
                                        return(subtotal);
                                    },
                                        (finalResult) =>
                                    {
                                        Interlocked.Add(ref numSnapshots, finalResult);
                                        Console.Write("[{0}].", numSnapshots);
                                    }
                                        );
                                }
                                else
                                {
                                    numSnapshots = extractSnapshots(jobConfiguration, jobTarget, controllerApi, listOfSnapshotsInHourFiltered, tiersNodeJSList, true);
                                }

                                loggerConsole.Info("{0} snapshots", numSnapshots);
                            }
                        }

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                        loggerConsole.Warn(ex);
                    }
                    finally
                    {
                        stopWatchTarget.Stop();

                        this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget);

                        stepTimingTarget.EndTime    = DateTime.Now;
                        stepTimingTarget.Duration   = stopWatchTarget.Elapsed;
                        stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds;

                        List <StepTiming> stepTimings = new List <StepTiming>(1);
                        stepTimings.Add(stepTimingTarget);
                        FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
Ejemplo n.º 22
0
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            if (this.ShouldExecute(jobConfiguration) == false)
            {
                return(true);
            }
            try
            {
                loggerConsole.Info("Prepare Snapshots Method Calls Report File");

                #region Prepare the report package

                // Prepare package
                ExcelPackage excelReport = new ExcelPackage();
                excelReport.Workbook.Properties.Author  = String.Format("AppDynamics DEXTER {0}", Assembly.GetEntryAssembly().GetName().Version);
                excelReport.Workbook.Properties.Title   = "AppDynamics DEXTER Snapshots Method Call Lines Report";
                excelReport.Workbook.Properties.Subject = programOptions.JobName;

                excelReport.Workbook.Properties.Comments = String.Format("Targets={0}\nFrom={1:o}\nTo={2:o}", jobConfiguration.Target.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To);

                #endregion

                #region Parameters sheet

                // Parameters sheet
                ExcelWorksheet sheet = excelReport.Workbook.Worksheets.Add(REPORT_SHEET_PARAMETERS);

                var hyperLinkStyle = sheet.Workbook.Styles.CreateNamedStyle("HyperLinkStyle");
                hyperLinkStyle.Style.Font.UnderLineType = ExcelUnderLineType.Single;
                hyperLinkStyle.Style.Font.Color.SetColor(colorBlueForHyperlinks);

                fillReportParametersSheet(sheet, jobConfiguration, "AppDynamics DEXTER Snapshots Method Call Lines Report");

                #endregion

                #region TOC sheet

                // Navigation sheet with link to other sheets
                sheet = excelReport.Workbook.Worksheets.Add(REPORT_SHEET_TOC);

                #endregion

                #region Entity sheets and their associated pivot

                // Entity sheets
                sheet = excelReport.Workbook.Worksheets.Add(REPORT_SNAPSHOTS_SHEET_CONTROLLERS);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(REPORT_SNAPSHOTS_SHEET_APPLICATIONS);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Type";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES_TYPE_EXEC_AVERAGE_PIVOT);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[3, 1].Value     = "See Location";
                sheet.Cells[3, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES_LOCATION_EXEC_AVERAGE_PIVOT);
                sheet.Cells[3, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[4, 1].Value     = "See Timeline";
                sheet.Cells[4, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES_TIMELINE_EXEC_AVERAGE_PIVOT);
                sheet.Cells[4, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT + 2, 1);

                sheet = excelReport.Workbook.Worksheets.Add(REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES_TYPE_EXEC_AVERAGE_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(REPORT_SNAPSHOTS_PIVOT_SHEET_START_PIVOT_AT + REPORT_SNAPSHOTS_PIVOT_SHEET_CHART_HEIGHT + 5, 1);

                sheet = excelReport.Workbook.Worksheets.Add(REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES_LOCATION_EXEC_AVERAGE_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(REPORT_SNAPSHOTS_PIVOT_SHEET_START_PIVOT_AT + REPORT_SNAPSHOTS_PIVOT_SHEET_CHART_HEIGHT + 3, 1);

                sheet = excelReport.Workbook.Worksheets.Add(REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES_TIMELINE_EXEC_AVERAGE_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(REPORT_SNAPSHOTS_PIVOT_SHEET_START_PIVOT_AT + REPORT_SNAPSHOTS_PIVOT_SHEET_CHART_HEIGHT + 9, 1);

                sheet = excelReport.Workbook.Worksheets.Add(REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES_OCCURRENCES);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Pivot";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES_OCCURRENCES_TYPE_PIVOT);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES_OCCURRENCES_TYPE_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES_OCCURRENCES);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(REPORT_SNAPSHOTS_PIVOT_SHEET_START_PIVOT_AT + REPORT_SNAPSHOTS_PIVOT_SHEET_CHART_HEIGHT + 4, 1);

                #endregion

                #region Report file variables

                ExcelRangeBase range = null;
                ExcelTable     table = null;

                #endregion

                loggerConsole.Info("Fill Snapshots Method Call Lines Report File");

                #region Controllers

                loggerConsole.Info("List of Controllers");

                sheet = excelReport.Workbook.Worksheets[REPORT_SNAPSHOTS_SHEET_CONTROLLERS];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllersReportFilePath(), 0, sheet, REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Applications

                loggerConsole.Info("List of Applications");

                sheet = excelReport.Workbook.Worksheets[REPORT_SNAPSHOTS_SHEET_APPLICATIONS];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ApplicationSnapshotsReportFilePath(), 0, sheet, REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Method Call Lines

                loggerConsole.Info("List of Method Call Lines");

                sheet = excelReport.Workbook.Worksheets[REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.SnapshotsMethodCallLinesReportFilePath(), 0, sheet, REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT + 1, 1);

                #endregion

                #region Method Call Occurrences

                loggerConsole.Info("List of Method Call Occurrences");

                sheet = excelReport.Workbook.Worksheets[REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES_OCCURRENCES];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.SnapshotsMethodCallLinesOccurrencesReportFilePath(), 0, sheet, REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                loggerConsole.Info("Finalize Snapshots Method Call Lines Report File");

                #region Controllers sheet

                // Make table
                sheet = excelReport.Workbook.Worksheets[REPORT_SNAPSHOTS_SHEET_CONTROLLERS];
                logger.Info("Controllers Sheet ({0} rows)", sheet.Dimension.Rows);
                loggerConsole.Info("Controllers Sheet ({0} rows)", sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, REPORT_SNAPSHOTS_TABLE_CONTROLLERS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width = 25;
                    sheet.Column(table.Columns["UserName"].Position + 1).Width   = 25;
                }

                #endregion

                #region Applications

                // Make table
                sheet = excelReport.Workbook.Worksheets[REPORT_SNAPSHOTS_SHEET_APPLICATIONS];
                logger.Info("Applications Sheet ({0} rows)", sheet.Dimension.Rows);
                loggerConsole.Info("Applications Sheet ({0} rows)", sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, REPORT_SNAPSHOTS_TABLE_APPLICATIONS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    adjustColumnsOfEntityRowTableInMetricReport(EntityApplication.ENTITY_TYPE, sheet, table);

                    ExcelAddress cfAddressNum = new ExcelAddress(REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSnapshots"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSnapshots"].Position + 1);
                    var          cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSnapshotsNormal"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSnapshotsNormal"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSnapshotsVerySlow"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSnapshotsVerySlow"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSnapshotsStall"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSnapshotsStall"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSnapshotsSlow"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSnapshotsSlow"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSnapshotsError"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSnapshotsError"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);
                }

                #endregion

                #region Method Call Lines

                // Make table
                sheet = excelReport.Workbook.Worksheets[REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES];
                logger.Info("Method Call Lines Sheet ({0} rows)", sheet.Dimension.Rows);
                loggerConsole.Info("Method Call Lines Sheet ({0} rows)", sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT + 1)
                {
                    range            = sheet.Cells[REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT + 1, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, REPORT_SNAPSHOTS_TABLE_METHOD_CALL_LINES);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width             = 20;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width        = 20;
                    sheet.Column(table.Columns["TierName"].Position + 1).Width               = 20;
                    sheet.Column(table.Columns["NodeName"].Position + 1).Width               = 20;
                    sheet.Column(table.Columns["BTName"].Position + 1).Width                 = 20;
                    sheet.Column(table.Columns["SegmentUserExperience"].Position + 1).Width  = 10;
                    sheet.Column(table.Columns["SnapshotUserExperience"].Position + 1).Width = 10;
                    sheet.Column(table.Columns["RequestID"].Position + 1).Width              = 20;
                    sheet.Column(table.Columns["SegmentID"].Position + 1).Width              = 10;
                    sheet.Column(table.Columns["Type"].Position + 1).Width           = 10;
                    sheet.Column(table.Columns["Framework"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["FullNameIndent"].Position + 1).Width = 45;
                    sheet.Column(table.Columns["ExitCalls"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["Occurred"].Position + 1).Width       = 20;
                    sheet.Column(table.Columns["OccurredUtc"].Position + 1).Width    = 20;

                    ExcelAddress cfAddressUserExperience = new ExcelAddress(REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT + 1, table.Columns["SegmentUserExperience"].Position + 1, sheet.Dimension.Rows, table.Columns["SegmentUserExperience"].Position + 1);
                    addUserExperienceConditionalFormatting(sheet, cfAddressUserExperience);

                    cfAddressUserExperience = new ExcelAddress(REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT + 1, table.Columns["SnapshotUserExperience"].Position + 1, sheet.Dimension.Rows, table.Columns["SnapshotUserExperience"].Position + 1);
                    addUserExperienceConditionalFormatting(sheet, cfAddressUserExperience);

                    sheet = excelReport.Workbook.Worksheets[REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES_TYPE_EXEC_AVERAGE_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[REPORT_SNAPSHOTS_PIVOT_SHEET_START_PIVOT_AT + REPORT_SNAPSHOTS_PIVOT_SHEET_CHART_HEIGHT + 2, 1], range, REPORT_SNAPSHOTS_PIVOT_METHOD_CALL_LINES_TYPE_EXEC_AVERAGE);
                    setDefaultPivotTableSettings(pivot);
                    addFilterFieldToPivot(pivot, "ElementType");
                    addFilterFieldToPivot(pivot, "NumChildren", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "NumExits", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "Depth", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "ExecRange", eSortType.Ascending);
                    addRowFieldToPivot(pivot, "Controller");
                    addRowFieldToPivot(pivot, "ApplicationName");
                    addRowFieldToPivot(pivot, "TierName");
                    addRowFieldToPivot(pivot, "BTName");
                    addRowFieldToPivot(pivot, "FullName");
                    addColumnFieldToPivot(pivot, "Type", eSortType.Ascending);
                    addColumnFieldToPivot(pivot, "Framework", eSortType.Ascending);
                    addDataFieldToPivot(pivot, "Exec", DataFieldFunctions.Average);

                    ExcelChart chart = sheet.Drawings.AddChart(REPORT_SNAPSHOTS_PIVOT_METHOD_CALL_LINES_GRAPH_TYPE_EXEC_AVERAGE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                    sheet.Column(3).Width = 20;
                    sheet.Column(4).Width = 20;
                    sheet.Column(5).Width = 20;

                    sheet = excelReport.Workbook.Worksheets[REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES_LOCATION_EXEC_AVERAGE_PIVOT];
                    pivot = sheet.PivotTables.Add(sheet.Cells[REPORT_SNAPSHOTS_PIVOT_SHEET_START_PIVOT_AT + REPORT_SNAPSHOTS_PIVOT_SHEET_CHART_HEIGHT + 1, 1], range, REPORT_SNAPSHOTS_PIVOT_METHOD_CALL_LINES_LOCATION_EXEC_AVERAGE);
                    setDefaultPivotTableSettings(pivot);
                    addFilterFieldToPivot(pivot, "ElementType");
                    addFilterFieldToPivot(pivot, "NumChildren", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "NumExits", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "Depth", eSortType.Ascending);
                    addRowFieldToPivot(pivot, "Type");
                    addRowFieldToPivot(pivot, "Framework");
                    addRowFieldToPivot(pivot, "FullName");
                    addRowFieldToPivot(pivot, "Controller");
                    addRowFieldToPivot(pivot, "ApplicationName");
                    addRowFieldToPivot(pivot, "TierName");
                    addRowFieldToPivot(pivot, "BTName");
                    addColumnFieldToPivot(pivot, "ExecRange", eSortType.Ascending);
                    addDataFieldToPivot(pivot, "Exec", DataFieldFunctions.Count);

                    chart = sheet.Drawings.AddChart(REPORT_SNAPSHOTS_PIVOT_METHOD_CALL_LINES_GRAPH_LOCATION_EXEC_AVERAGE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                    sheet.Column(3).Width = 20;
                    sheet.Column(4).Width = 20;
                    sheet.Column(5).Width = 20;
                    sheet.Column(6).Width = 20;
                    sheet.Column(7).Width = 20;

                    sheet = excelReport.Workbook.Worksheets[REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES_TIMELINE_EXEC_AVERAGE_PIVOT];
                    pivot = sheet.PivotTables.Add(sheet.Cells[REPORT_SNAPSHOTS_PIVOT_SHEET_START_PIVOT_AT + REPORT_SNAPSHOTS_PIVOT_SHEET_CHART_HEIGHT + 6, 1], range, REPORT_SNAPSHOTS_PIVOT_METHOD_CALL_LINES_TIMELINE_EXEC_AVERAGE);
                    setDefaultPivotTableSettings(pivot);
                    addFilterFieldToPivot(pivot, "ElementType");
                    addFilterFieldToPivot(pivot, "NumChildren", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "NumExits", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "Depth", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "Class", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "Method", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "FullName", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "BTName", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "ExecRange", eSortType.Ascending);
                    ExcelPivotTableField fieldR = pivot.RowFields.Add(pivot.Fields["Occurred"]);
                    fieldR.AddDateGrouping(eDateGroupBy.Days | eDateGroupBy.Hours | eDateGroupBy.Minutes);
                    fieldR.Compact = false;
                    fieldR.Outline = false;
                    addColumnFieldToPivot(pivot, "Type", eSortType.Ascending);
                    addColumnFieldToPivot(pivot, "Framework", eSortType.Ascending);
                    addDataFieldToPivot(pivot, "Exec", DataFieldFunctions.Average);

                    chart = sheet.Drawings.AddChart(REPORT_SNAPSHOTS_PIVOT_METHOD_CALL_LINES_GRAPH_TIMELINE_EXEC_AVERAGE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                }

                #endregion

                #region Method Call Occurrences

                // Make table
                sheet = excelReport.Workbook.Worksheets[REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES_OCCURRENCES];
                logger.Info("Method Call Occurrences Sheet ({0} rows)", sheet.Dimension.Rows);
                loggerConsole.Info("Method Call Occurrences Sheet ({0} rows)", sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, REPORT_SNAPSHOTS_TABLE_METHOD_CALL_LINES_OCCURRENCES);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width             = 20;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width        = 20;
                    sheet.Column(table.Columns["TierName"].Position + 1).Width               = 20;
                    sheet.Column(table.Columns["NodeName"].Position + 1).Width               = 20;
                    sheet.Column(table.Columns["BTName"].Position + 1).Width                 = 20;
                    sheet.Column(table.Columns["SegmentUserExperience"].Position + 1).Width  = 10;
                    sheet.Column(table.Columns["SnapshotUserExperience"].Position + 1).Width = 10;
                    sheet.Column(table.Columns["RequestID"].Position + 1).Width              = 20;
                    sheet.Column(table.Columns["SegmentID"].Position + 1).Width              = 10;
                    sheet.Column(table.Columns["Type"].Position + 1).Width      = 10;
                    sheet.Column(table.Columns["Framework"].Position + 1).Width = 15;
                    sheet.Column(table.Columns["FullName"].Position + 1).Width  = 45;

                    ExcelAddress cfAddressUserExperience = new ExcelAddress(REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT + 1, table.Columns["SegmentUserExperience"].Position + 1, sheet.Dimension.Rows, table.Columns["SegmentUserExperience"].Position + 1);
                    addUserExperienceConditionalFormatting(sheet, cfAddressUserExperience);

                    cfAddressUserExperience = new ExcelAddress(REPORT_SNAPSHOTS_LIST_SHEET_START_TABLE_AT + 1, table.Columns["SnapshotUserExperience"].Position + 1, sheet.Dimension.Rows, table.Columns["SnapshotUserExperience"].Position + 1);
                    addUserExperienceConditionalFormatting(sheet, cfAddressUserExperience);

                    sheet = excelReport.Workbook.Worksheets[REPORT_SNAPSHOTS_SHEET_METHOD_CALL_LINES_OCCURRENCES_TYPE_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[REPORT_SNAPSHOTS_PIVOT_SHEET_START_PIVOT_AT + REPORT_SNAPSHOTS_PIVOT_SHEET_CHART_HEIGHT + 1, 1], range, REPORT_SNAPSHOTS_PIVOT_METHOD_CALL_LINES_OCCURRENCES_TYPE);
                    setDefaultPivotTableSettings(pivot);
                    addFilterFieldToPivot(pivot, "NumChildren", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "NumExits", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "BTName", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "ExecRange", eSortType.Ascending);
                    addRowFieldToPivot(pivot, "NumCalls", eSortType.Ascending);
                    addRowFieldToPivot(pivot, "FullName", eSortType.Ascending);
                    addColumnFieldToPivot(pivot, "Type", eSortType.Ascending);
                    addColumnFieldToPivot(pivot, "Framework", eSortType.Ascending);
                    addDataFieldToPivot(pivot, "Exec", DataFieldFunctions.Average);

                    ExcelChart chart = sheet.Drawings.AddChart(REPORT_SNAPSHOTS_PIVOT_METHOD_CALL_LINES_OCCURRENCES_GRAPH_TYPE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                }

                #endregion

                #region TOC sheet

                // TOC sheet again
                sheet = excelReport.Workbook.Worksheets[REPORT_SHEET_TOC];
                sheet.Cells[1, 1].Value = "Sheet Name";
                sheet.Cells[1, 2].Value = "# Entities";
                sheet.Cells[1, 3].Value = "Link";
                int rowNum = 1;
                foreach (ExcelWorksheet s in excelReport.Workbook.Worksheets)
                {
                    rowNum++;
                    sheet.Cells[rowNum, 1].Value     = s.Name;
                    sheet.Cells[rowNum, 3].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", s.Name);
                    sheet.Cells[rowNum, 3].StyleName = "HyperLinkStyle";
                    if (s.Tables.Count > 0)
                    {
                        table = s.Tables[0];
                        sheet.Cells[rowNum, 2].Value = table.Address.Rows - 1;
                    }
                }
                range            = sheet.Cells[1, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                table            = sheet.Tables.Add(range, REPORT_SNAPSHOTS_TABLE_TOC);
                table.ShowHeader = true;
                table.TableStyle = TableStyles.Medium2;
                table.ShowFilter = true;
                table.ShowTotal  = false;

                sheet.Column(table.Columns["Sheet Name"].Position + 1).Width = 25;
                sheet.Column(table.Columns["# Entities"].Position + 1).Width = 25;

                #endregion

                #region Save file

                if (Directory.Exists(FilePathMap.ReportFolderPath()) == false)
                {
                    Directory.CreateDirectory(FilePathMap.ReportFolderPath());
                }

                string reportFilePath = FilePathMap.SnapshotMethodCallsExcelReportFilePath(jobConfiguration.Input.TimeRange);
                logger.Info("Saving Excel report {0}", reportFilePath);
                loggerConsole.Info("Saving Excel report {0}", reportFilePath);

                try
                {
                    // Save full report Excel files
                    excelReport.SaveAs(new FileInfo(reportFilePath));
                }
                catch (InvalidOperationException ex)
                {
                    logger.Warn("Unable to save Excel file {0}", reportFilePath);
                    logger.Warn(ex);
                    loggerConsole.Warn("Unable to save Excel file {0}", reportFilePath);
                }

                #endregion

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
Ejemplo n.º 23
0
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;


            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            try
            {
                if (this.ShouldExecute(jobConfiguration) == false)
                {
                    return(true);
                }

                if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_SIM) == 0)
                {
                    return(true);
                }

                // Process each target
                for (int i = 0; i < jobConfiguration.Target.Count; i++)
                {
                    Stopwatch stopWatchTarget = new Stopwatch();
                    stopWatchTarget.Start();

                    JobTarget jobTarget = jobConfiguration.Target[i];

                    if (jobTarget.Type != null && jobTarget.Type.Length > 0 && jobTarget.Type != APPLICATION_TYPE_SIM)
                    {
                        continue;
                    }

                    StepTiming stepTimingTarget = new StepTiming();
                    stepTimingTarget.Controller      = jobTarget.Controller;
                    stepTimingTarget.ApplicationName = jobTarget.Application;
                    stepTimingTarget.ApplicationID   = jobTarget.ApplicationID;
                    stepTimingTarget.JobFileName     = programOptions.OutputJobFilePath;
                    stepTimingTarget.StepName        = jobConfiguration.Status.ToString();
                    stepTimingTarget.StepID          = (int)jobConfiguration.Status;
                    stepTimingTarget.StartTime       = DateTime.Now;

                    stepTimingTarget.NumEntities = 1;

                    try
                    {
                        this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1);

                        // Set up controller access
                        using (ControllerApi controllerApi = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword)))
                        {
                            #region Prepare time range

                            long fromTimeUnix        = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.From);
                            long toTimeUnix          = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.To);
                            long differenceInMinutes = (toTimeUnix - fromTimeUnix) / (60000);

                            #endregion

                            #region Tiers

                            loggerConsole.Info("List of Tiers");

                            string tiersJSON = controllerApi.GetSIMListOfTiers();
                            if (tiersJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(tiersJSON, FilePathMap.SIMTiersDataFilePath(jobTarget));
                            }

                            #endregion

                            #region Nodes

                            loggerConsole.Info("List of Nodes");

                            string nodesJSON = controllerApi.GetSIMListOfNodes();
                            if (nodesJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(nodesJSON, FilePathMap.SIMNodesDataFilePath(jobTarget));
                            }

                            #endregion

                            #region Groups

                            loggerConsole.Info("List of Groups");

                            string groupsJSON = controllerApi.GetSIMListOfGroups();
                            if (groupsJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(groupsJSON, FilePathMap.SIMGroupsDataFilePath(jobTarget));
                            }

                            #endregion

                            #region Service Availability

                            loggerConsole.Info("List of Service Availability");

                            string sasJSON = controllerApi.GetSIMListOfServiceAvailability();
                            if (sasJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(sasJSON, FilePathMap.SIMServiceAvailabilitiesDataFilePath(jobTarget));
                            }

                            JArray sasList = FileIOHelper.LoadJArrayFromFile(FilePathMap.SIMServiceAvailabilitiesDataFilePath(jobTarget));
                            if (sasList != null)
                            {
                                loggerConsole.Info("Service Availability Details ({0} entities)", sasList.Count);

                                foreach (JToken saToken in sasList)
                                {
                                    string saJSON = controllerApi.GetSIMServiceAvailability((long)saToken["id"]);
                                    if (saJSON != String.Empty)
                                    {
                                        FileIOHelper.SaveFileToPath(saJSON, FilePathMap.SIMServiceAvailabilityDataFilePath(jobTarget, saToken["name"].ToString(), (long)saToken["id"]));
                                    }

                                    string saEventsJSON = controllerApi.GetSIMServiceAvailabilityEvents((long)saToken["id"], fromTimeUnix, toTimeUnix, differenceInMinutes);
                                    if (saEventsJSON != String.Empty && saEventsJSON != "[]")
                                    {
                                        FileIOHelper.SaveFileToPath(saEventsJSON, FilePathMap.SIMServiceAvailabilityEventsDataFilePath(jobTarget, saToken["name"].ToString(), (long)saToken["id"], jobConfiguration.Input.TimeRange));
                                    }
                                }

                                loggerConsole.Info("Completed {0} Service Availabilities", sasList.Count);
                            }

                            #endregion

                            #region Machines

                            loggerConsole.Info("List of Machines");

                            string machinesJSON = controllerApi.GetSIMListOfMachines();
                            if (machinesJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(machinesJSON, FilePathMap.SIMMachinesDataFilePath(jobTarget));
                            }

                            JArray machinesArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.SIMMachinesDataFilePath(jobTarget));
                            if (machinesArray != null)
                            {
                                loggerConsole.Info("Machine, Container Details and Processes ({0} entities)", machinesArray.Count);

                                int j = 0;

                                var listOfMachinesChunks = machinesArray.BreakListIntoChunks(ENTITIES_EXTRACT_NUMBER_OF_MACHINES_TO_PROCESS_PER_THREAD);

                                Parallel.ForEach <List <JToken>, int>(
                                    listOfMachinesChunks,
                                    new ParallelOptions {
                                    MaxDegreeOfParallelism = MACHINES_EXTRACT_NUMBER_OF_THREADS
                                },
                                    () => 0,
                                    (listOfMachinesChunk, loop, subtotal) =>
                                {
                                    // Set up controller access
                                    using (ControllerApi controllerApiParallel = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword)))
                                    {
                                        foreach (JToken machineToken in listOfMachinesChunk)
                                        {
                                            if (File.Exists(FilePathMap.SIMMachineDataFilePath(jobTarget, machineToken["name"].ToString(), (long)machineToken["id"])) == false)
                                            {
                                                string machineJSON = controllerApi.GetSIMMachine((long)machineToken["id"]);
                                                if (machineJSON != String.Empty)
                                                {
                                                    FileIOHelper.SaveFileToPath(machineJSON, FilePathMap.SIMMachineDataFilePath(jobTarget, machineToken["name"].ToString(), (long)machineToken["id"]));
                                                }

                                                string machineDockerJSON = controllerApi.GetSIMMachineDockerContainers((long)machineToken["id"]);
                                                if (machineDockerJSON != String.Empty && machineDockerJSON != "[]")
                                                {
                                                    FileIOHelper.SaveFileToPath(machineDockerJSON, FilePathMap.SIMMachineDockerContainersDataFilePath(jobTarget, machineToken["name"].ToString(), (long)machineToken["id"]));
                                                }

                                                string machineProcessesJSON = controllerApi.GetSIMMachineProcesses((long)machineToken["id"], fromTimeUnix, toTimeUnix, differenceInMinutes);
                                                if (machineProcessesJSON != String.Empty && machineProcessesJSON != "[]")
                                                {
                                                    FileIOHelper.SaveFileToPath(machineProcessesJSON, FilePathMap.SIMMachineProcessesDataFilePath(jobTarget, machineToken["name"].ToString(), (long)machineToken["id"], jobConfiguration.Input.TimeRange));
                                                }
                                            }
                                        }

                                        return(listOfMachinesChunk.Count);
                                    }
                                },
                                    (finalResult) =>
                                {
                                    Interlocked.Add(ref j, finalResult);
                                    Console.Write("[{0}].", j);
                                }
                                    );

                                loggerConsole.Info("Completed {0} Machines", machinesArray.Count);
                            }

                            #endregion
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                        loggerConsole.Warn(ex);

                        return(false);
                    }
                    finally
                    {
                        stopWatchTarget.Stop();

                        this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget);

                        stepTimingTarget.EndTime    = DateTime.Now;
                        stepTimingTarget.Duration   = stopWatchTarget.Elapsed;
                        stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds;

                        List <StepTiming> stepTimings = new List <StepTiming>(1);
                        stepTimings.Add(stepTimingTarget);
                        FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            if (this.ShouldExecute(jobConfiguration) == false)
            {
                return(true);
            }

            try
            {
                loggerConsole.Info("Prepare Events and Health Rule Violations Report File");

                #region Prepare the report package

                // Prepare package
                ExcelPackage excelReport = new ExcelPackage();
                excelReport.Workbook.Properties.Author  = String.Format("AppDynamics DEXTER {0}", Assembly.GetEntryAssembly().GetName().Version);
                excelReport.Workbook.Properties.Title   = "AppDynamics DEXTER Events and Health Rule Violations Report";
                excelReport.Workbook.Properties.Subject = programOptions.JobName;

                excelReport.Workbook.Properties.Comments = String.Format("Targets={0}\nFrom={1:o}\nTo={2:o}", jobConfiguration.Target.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To);

                #endregion

                #region Parameters sheet

                // Parameters sheet
                ExcelWorksheet sheet = excelReport.Workbook.Worksheets.Add(SHEET_PARAMETERS);

                var hyperLinkStyle = sheet.Workbook.Styles.CreateNamedStyle("HyperLinkStyle");
                hyperLinkStyle.Style.Font.UnderLineType = ExcelUnderLineType.Single;
                hyperLinkStyle.Style.Font.Color.SetColor(colorBlueForHyperlinks);

                fillReportParametersSheet(sheet, jobConfiguration, "AppDynamics DEXTER Events and Health Rule Violations Report");

                #endregion

                #region TOC sheet

                // Navigation sheet with link to other sheets
                sheet = excelReport.Workbook.Worksheets.Add(SHEET_TOC);

                #endregion

                #region Entity sheets and their associated pivots

                // Entity sheets
                sheet = excelReport.Workbook.Worksheets.Add(SHEET_CONTROLLERS);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_APPLICATIONS);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_EVENTS);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Pivot";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_EVENTS_PIVOT);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[3, 1].Value     = "See Duration";
                sheet.Cells[3, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_EVENTS_TIMELINE_PIVOT);
                sheet.Cells[3, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_EVENTS_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_EVENTS);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_EVENTS_TIMELINE_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_EVENTS);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 7, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_HEALTH_RULE_VIOLATIONS);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Pivot";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_HEALTH_RULE_VIOLATIONS_PIVOT);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_HEALTH_RULE_VIOLATIONS_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_HEALTH_RULE_VIOLATIONS);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_AUDIT_EVENTS);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Pivot";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_AUDIT_EVENTS_PIVOT);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[3, 1].Value     = "See Duration";
                sheet.Cells[3, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", AUDIT_SHEET_EVENTS_TIMELINE_PIVOT);
                sheet.Cells[3, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_AUDIT_EVENTS_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_AUDIT_EVENTS);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 3, 1);

                sheet = excelReport.Workbook.Worksheets.Add(AUDIT_SHEET_EVENTS_TIMELINE_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_AUDIT_EVENTS);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 4, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_NOTIFICATIONS);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                #endregion

                #region Report file variables

                ExcelRangeBase range = null;
                ExcelTable     table = null;

                #endregion

                loggerConsole.Info("Fill Events and Health Rule Violations Report File");

                #region Controllers

                loggerConsole.Info("List of Controllers");

                sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerSummaryReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Applications

                loggerConsole.Info("List of Applications");

                sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ApplicationEventsSummaryReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Events

                loggerConsole.Info("List of Events");

                sheet = excelReport.Workbook.Worksheets[SHEET_EVENTS];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ApplicationEventsReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Health Rule Violation Events

                loggerConsole.Info("List of Health Rule Violation Events");

                sheet = excelReport.Workbook.Worksheets[SHEET_HEALTH_RULE_VIOLATIONS];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ApplicationHealthRuleViolationsReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Audit Events

                loggerConsole.Info("List of Audit Events");

                sheet = excelReport.Workbook.Worksheets[SHEET_AUDIT_EVENTS];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.AuditEventsReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Notifications

                loggerConsole.Info("List of Notifications");

                sheet = excelReport.Workbook.Worksheets[SHEET_NOTIFICATIONS];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.NotificationsReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                loggerConsole.Info("Finalize Events and Health Rule Violations Report File");

                #region Controllers sheet

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_CONTROLLERS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width = 25;
                    sheet.Column(table.Columns["Version"].Position + 1).Width    = 15;
                }

                #endregion

                #region Applications

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_APPLICATIONS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    adjustColumnsOfEntityRowTableInMetricReport(APMApplication.ENTITY_TYPE, sheet, table);

                    ExcelAddress cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumEvents"].Position + 1, sheet.Dimension.Rows, table.Columns["NumEvents"].Position + 1);
                    var          cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumEventsInfo"].Position + 1, sheet.Dimension.Rows, table.Columns["NumEventsInfo"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumEventsWarning"].Position + 1, sheet.Dimension.Rows, table.Columns["NumEventsWarning"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumEventsError"].Position + 1, sheet.Dimension.Rows, table.Columns["NumEventsError"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumHRViolations"].Position + 1, sheet.Dimension.Rows, table.Columns["NumHRViolations"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumHRViolationsWarning"].Position + 1, sheet.Dimension.Rows, table.Columns["NumHRViolationsWarning"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumHRViolationsCritical"].Position + 1, sheet.Dimension.Rows, table.Columns["NumHRViolationsCritical"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);
                }

                #endregion

                #region Events

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_EVENTS];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_EVENTS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width          = 20;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width     = 20;
                    sheet.Column(table.Columns["EventID"].Position + 1).Width             = 10;
                    sheet.Column(table.Columns["Occurred"].Position + 1).Width            = 20;
                    sheet.Column(table.Columns["OccurredUtc"].Position + 1).Width         = 20;
                    sheet.Column(table.Columns["Summary"].Position + 1).Width             = 35;
                    sheet.Column(table.Columns["Type"].Position + 1).Width                = 20;
                    sheet.Column(table.Columns["SubType"].Position + 1).Width             = 20;
                    sheet.Column(table.Columns["TierName"].Position + 1).Width            = 20;
                    sheet.Column(table.Columns["NodeName"].Position + 1).Width            = 20;
                    sheet.Column(table.Columns["BTName"].Position + 1).Width              = 20;
                    sheet.Column(table.Columns["TriggeredEntityType"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["TriggeredEntityName"].Position + 1).Width = 20;

                    sheet = excelReport.Workbook.Worksheets[SHEET_EVENTS_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_EVENTS_TYPE);
                    setDefaultPivotTableSettings(pivot);
                    addRowFieldToPivot(pivot, "Controller");
                    addRowFieldToPivot(pivot, "ApplicationName");
                    addRowFieldToPivot(pivot, "Type");
                    addRowFieldToPivot(pivot, "SubType");
                    addRowFieldToPivot(pivot, "TierName");
                    addRowFieldToPivot(pivot, "BTName");
                    addRowFieldToPivot(pivot, "NodeName");
                    addColumnFieldToPivot(pivot, "Severity", eSortType.Ascending);
                    addDataFieldToPivot(pivot, "EventID", DataFieldFunctions.Count);

                    ExcelChart chart = sheet.Drawings.AddChart(GRAPH_EVENTS_TYPE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                    sheet.Column(3).Width = 20;
                    sheet.Column(4).Width = 20;
                    sheet.Column(5).Width = 20;
                    sheet.Column(6).Width = 20;
                    sheet.Column(7).Width = 20;

                    sheet = excelReport.Workbook.Worksheets[SHEET_EVENTS_TIMELINE_PIVOT];
                    pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 3, 1], range, PIVOT_EVENTS_TIMELINE);
                    setDefaultPivotTableSettings(pivot);
                    addFilterFieldToPivot(pivot, "ApplicationName");
                    addFilterFieldToPivot(pivot, "TierName");
                    addFilterFieldToPivot(pivot, "BTName");
                    addFilterFieldToPivot(pivot, "TriggeredEntityName");
                    addFilterFieldToPivot(pivot, "ApplicationName");
                    ExcelPivotTableField fieldR = pivot.RowFields.Add(pivot.Fields["Occurred"]);
                    fieldR.AddDateGrouping(eDateGroupBy.Days | eDateGroupBy.Hours | eDateGroupBy.Minutes);
                    fieldR.Compact = false;
                    fieldR.Outline = false;
                    addColumnFieldToPivot(pivot, "Severity", eSortType.Ascending);
                    addColumnFieldToPivot(pivot, "Type", eSortType.Ascending);
                    addColumnFieldToPivot(pivot, "SubType", eSortType.Ascending);
                    addDataFieldToPivot(pivot, "EventID", DataFieldFunctions.Count);

                    chart = sheet.Drawings.AddChart(GRAPH_EVENTS_TIMELINE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                    sheet.Column(3).Width = 20;
                }

                #endregion

                #region Health Rule Violation Events

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_HEALTH_RULE_VIOLATIONS];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_HEALTH_RULE_VIOLATION_EVENTS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width      = 20;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["EventID"].Position + 1).Width         = 10;
                    sheet.Column(table.Columns["From"].Position + 1).Width            = 25;
                    sheet.Column(table.Columns["FromUtc"].Position + 1).Width         = 20;
                    sheet.Column(table.Columns["To"].Position + 1).Width             = 25;
                    sheet.Column(table.Columns["ToUtc"].Position + 1).Width          = 20;
                    sheet.Column(table.Columns["HealthRuleName"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["EntityName"].Position + 1).Width     = 20;

                    sheet = excelReport.Workbook.Worksheets[SHEET_HEALTH_RULE_VIOLATIONS_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_HEALTH_RULE_VIOLATION_EVENTS_TYPE);
                    setDefaultPivotTableSettings(pivot);
                    addRowFieldToPivot(pivot, "Controller");
                    addRowFieldToPivot(pivot, "ApplicationName");
                    addRowFieldToPivot(pivot, "Status");
                    addRowFieldToPivot(pivot, "HealthRuleName");
                    addRowFieldToPivot(pivot, "EntityType");
                    addRowFieldToPivot(pivot, "EntityName");
                    addColumnFieldToPivot(pivot, "Severity", eSortType.Ascending);
                    addDataFieldToPivot(pivot, "EventID", DataFieldFunctions.Count);

                    ExcelChart chart = sheet.Drawings.AddChart(GRAPH_HEALTH_RULE_VIOLATION_EVENTS_TYPE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                    sheet.Column(3).Width = 20;
                    sheet.Column(4).Width = 20;
                    sheet.Column(5).Width = 20;
                    sheet.Column(6).Width = 20;
                }

                #endregion

                #region Audit Events

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_AUDIT_EVENTS];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_AUDIT_EVENTS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width  = 20;
                    sheet.Column(table.Columns["Username"].Position + 1).Width    = 20;
                    sheet.Column(table.Columns["LoginType"].Position + 1).Width   = 15;
                    sheet.Column(table.Columns["Action"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["EntityName"].Position + 1).Width  = 30;
                    sheet.Column(table.Columns["EntityType"].Position + 1).Width  = 20;
                    sheet.Column(table.Columns["Occurred"].Position + 1).Width    = 20;
                    sheet.Column(table.Columns["OccurredUtc"].Position + 1).Width = 20;

                    sheet = excelReport.Workbook.Worksheets[SHEET_AUDIT_EVENTS_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_AUDIT_EVENTS_TYPE);
                    setDefaultPivotTableSettings(pivot);
                    addRowFieldToPivot(pivot, "Controller");
                    addRowFieldToPivot(pivot, "Action");
                    addRowFieldToPivot(pivot, "EntityType");
                    addRowFieldToPivot(pivot, "EntityName");
                    addColumnFieldToPivot(pivot, "LoginType", eSortType.Ascending);
                    addColumnFieldToPivot(pivot, "UserName", eSortType.Ascending);
                    addDataFieldToPivot(pivot, "EntityID", DataFieldFunctions.Count);

                    ExcelChart chart = sheet.Drawings.AddChart(GRAPH_AUDIT_EVENTS_TYPE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                    sheet.Column(3).Width = 20;
                    sheet.Column(4).Width = 30;

                    sheet = excelReport.Workbook.Worksheets[AUDIT_SHEET_EVENTS_TIMELINE_PIVOT];
                    pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_AUDIT_EVENTS_TIMELINE);
                    setDefaultPivotTableSettings(pivot);
                    addFilterFieldToPivot(pivot, "UserName");
                    ExcelPivotTableField fieldR = pivot.RowFields.Add(pivot.Fields["Occurred"]);
                    fieldR.AddDateGrouping(eDateGroupBy.Days | eDateGroupBy.Hours | eDateGroupBy.Minutes);
                    fieldR.Compact = false;
                    fieldR.Outline = false;
                    addColumnFieldToPivot(pivot, "Action", eSortType.Ascending);
                    addColumnFieldToPivot(pivot, "EntityType", eSortType.Ascending);
                    addColumnFieldToPivot(pivot, "EntityName", eSortType.Ascending);
                    addDataFieldToPivot(pivot, "EntityID", DataFieldFunctions.Count);

                    chart = sheet.Drawings.AddChart(GRAPH_AUDIT_EVENTS_TIMELINE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                    sheet.Column(3).Width = 20;
                }

                #endregion

                #region Notifications

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_NOTIFICATIONS];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_NOTIFICATIONS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width          = 20;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width     = 20;
                    sheet.Column(table.Columns["EventID"].Position + 1).Width             = 10;
                    sheet.Column(table.Columns["Occurred"].Position + 1).Width            = 20;
                    sheet.Column(table.Columns["OccurredUtc"].Position + 1).Width         = 20;
                    sheet.Column(table.Columns["Summary"].Position + 1).Width             = 35;
                    sheet.Column(table.Columns["Type"].Position + 1).Width                = 20;
                    sheet.Column(table.Columns["SubType"].Position + 1).Width             = 20;
                    sheet.Column(table.Columns["TierName"].Position + 1).Width            = 20;
                    sheet.Column(table.Columns["NodeName"].Position + 1).Width            = 20;
                    sheet.Column(table.Columns["BTName"].Position + 1).Width              = 20;
                    sheet.Column(table.Columns["TriggeredEntityType"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["TriggeredEntityName"].Position + 1).Width = 20;
                }

                #endregion
                #region TOC sheet

                // TOC sheet again
                sheet = excelReport.Workbook.Worksheets[SHEET_TOC];
                fillTableOfContentsSheet(sheet, excelReport);

                #endregion

                #region Save file

                if (Directory.Exists(FilePathMap.ReportFolderPath()) == false)
                {
                    Directory.CreateDirectory(FilePathMap.ReportFolderPath());
                }

                string reportFilePath = FilePathMap.EventsAndHealthRuleViolationsExcelReportFilePath(jobConfiguration.Input.TimeRange);
                logger.Info("Saving Excel report {0}", reportFilePath);
                loggerConsole.Info("Saving Excel report {0}", reportFilePath);

                try
                {
                    // Save full report Excel files
                    excelReport.SaveAs(new FileInfo(reportFilePath));
                }
                catch (InvalidOperationException ex)
                {
                    logger.Warn("Unable to save Excel file {0}", reportFilePath);
                    logger.Warn(ex);
                    loggerConsole.Warn("Unable to save Excel file {0}", reportFilePath);
                }

                #endregion

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
Ejemplo n.º 25
0
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            try
            {
                if (this.ShouldExecute(jobConfiguration) == false)
                {
                    return(true);
                }

                bool reportFolderCleaned = false;

                // Process each Controller once
                int i           = 0;
                var controllers = jobConfiguration.Target.GroupBy(t => t.Controller);
                foreach (var controllerGroup in controllers)
                {
                    Stopwatch stopWatchTarget = new Stopwatch();
                    stopWatchTarget.Start();

                    JobTarget jobTarget = controllerGroup.ToList()[0];

                    StepTiming stepTimingTarget = new StepTiming();
                    stepTimingTarget.Controller      = jobTarget.Controller;
                    stepTimingTarget.ApplicationName = jobTarget.Application;
                    stepTimingTarget.ApplicationID   = jobTarget.ApplicationID;
                    stepTimingTarget.JobFileName     = programOptions.OutputJobFilePath;
                    stepTimingTarget.StepName        = jobConfiguration.Status.ToString();
                    stepTimingTarget.StepID          = (int)jobConfiguration.Status;
                    stepTimingTarget.StartTime       = DateTime.Now;

                    stepTimingTarget.NumEntities = 0;

                    try
                    {
                        this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1);

                        #region Controller Settings

                        loggerConsole.Info("Controller Settings");

                        List <ControllerSetting> controllerSettingsList = new List <ControllerSetting>();
                        JArray controllerSettingsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.ControllerSettingsDataFilePath(jobTarget));
                        if (controllerSettingsArray != null)
                        {
                            foreach (JObject controllerSettingObject in controllerSettingsArray)
                            {
                                ControllerSetting controllerSetting = new ControllerSetting();

                                controllerSetting.Controller     = jobTarget.Controller;
                                controllerSetting.ControllerLink = String.Format(DEEPLINK_CONTROLLER, controllerSetting.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES);
                                controllerSetting.Name           = getStringValueFromJToken(controllerSettingObject, "name");
                                controllerSetting.Description    = getStringValueFromJToken(controllerSettingObject, "description");
                                controllerSetting.Value          = getStringValueFromJToken(controllerSettingObject, "value");
                                controllerSetting.Updateable     = getBoolValueFromJToken(controllerSettingObject, "updateable");
                                controllerSetting.Scope          = getStringValueFromJToken(controllerSettingObject, "scope");

                                controllerSettingsList.Add(controllerSetting);
                            }
                        }

                        controllerSettingsList = controllerSettingsList.OrderBy(c => c.Name).ToList();
                        FileIOHelper.WriteListToCSVFile(controllerSettingsList, new ControllerSettingReportMap(), FilePathMap.ControllerSettingsIndexFilePath(jobTarget));

                        stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + controllerSettingsList.Count;

                        #endregion

                        #region HTTP Templates

                        loggerConsole.Info("HTTP Templates");

                        List <HTTPAlertTemplate> httpTemplatesList = new List <HTTPAlertTemplate>();
                        JArray httpTemplatesArray       = FileIOHelper.LoadJArrayFromFile(FilePathMap.HTTPTemplatesDataFilePath(jobTarget));
                        JArray httpTemplatesDetailArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.HTTPTemplatesDetailDataFilePath(jobTarget));
                        if (httpTemplatesArray != null)
                        {
                            foreach (JObject httpTemplateObject in httpTemplatesArray)
                            {
                                HTTPAlertTemplate httpAlertTemplate = new HTTPAlertTemplate();

                                httpAlertTemplate.Controller = jobTarget.Controller;

                                httpAlertTemplate.Name = getStringValueFromJToken(httpTemplateObject, "name");

                                httpAlertTemplate.Method = getStringValueFromJToken(httpTemplateObject, "method");
                                httpAlertTemplate.Scheme = getStringValueFromJToken(httpTemplateObject, "scheme");
                                httpAlertTemplate.Host   = getStringValueFromJToken(httpTemplateObject, "host");
                                httpAlertTemplate.Port   = getIntValueFromJToken(httpTemplateObject, "port");
                                httpAlertTemplate.Path   = getStringValueFromJToken(httpTemplateObject, "path");
                                httpAlertTemplate.Query  = getStringValueFromJToken(httpTemplateObject, "query");

                                httpAlertTemplate.AuthType     = getStringValueFromJToken(httpTemplateObject, "authType");
                                httpAlertTemplate.AuthUsername = getStringValueFromJToken(httpTemplateObject, "authUsername");
                                httpAlertTemplate.AuthPassword = getStringValueFromJToken(httpTemplateObject, "authPassword");

                                httpAlertTemplate.Headers = getStringValueOfObjectFromJToken(httpTemplateObject, "headers", true);
                                if (isTokenPropertyNull(httpTemplateObject, "payloadTemplate") == false)
                                {
                                    httpAlertTemplate.ContentType = getStringValueFromJToken(httpTemplateObject["payloadTemplate"], "httpRequestActionMediaType");
                                    httpAlertTemplate.FormData    = getStringValueOfObjectFromJToken(httpTemplateObject["payloadTemplate"], "formDataPairs", true);
                                    httpAlertTemplate.Payload     = getStringValueFromJToken(httpTemplateObject["payloadTemplate"], "payload");
                                }

                                httpAlertTemplate.ConnectTimeout = getLongValueFromJToken(httpTemplateObject, "connectTimeoutInMillis");
                                httpAlertTemplate.SocketTimeout  = getLongValueFromJToken(httpTemplateObject, "socketTimeoutInMillis");

                                httpAlertTemplate.ResponseAny  = getStringValueOfObjectFromJToken(httpTemplateObject, "responseMatchCriteriaAnyTemplate");
                                httpAlertTemplate.ResponseNone = getStringValueOfObjectFromJToken(httpTemplateObject, "responseMatchCriteriaNoneTemplate");

                                if (httpTemplatesDetailArray != null)
                                {
                                    JToken httpAlertTemplateToken = httpTemplatesDetailArray.Where(t => t["name"].ToString() == httpAlertTemplate.Name).FirstOrDefault();
                                    if (httpAlertTemplateToken != null)
                                    {
                                        httpAlertTemplate.TemplateID = getLongValueFromJToken(httpAlertTemplateToken, "id");
                                    }
                                }

                                httpTemplatesList.Add(httpAlertTemplate);
                            }
                        }

                        httpTemplatesList = httpTemplatesList.OrderBy(c => c.Name).ToList();
                        FileIOHelper.WriteListToCSVFile(httpTemplatesList, new HTTPAlertTemplateReportMap(), FilePathMap.HTTPTemplatesIndexFilePath(jobTarget));

                        stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + httpTemplatesList.Count;

                        #endregion

                        #region Email Templates

                        loggerConsole.Info("Email Templates");

                        List <EmailAlertTemplate> emailTemplatesList = new List <EmailAlertTemplate>();
                        JArray emailTemplatesArray       = FileIOHelper.LoadJArrayFromFile(FilePathMap.EmailTemplatesDataFilePath(jobTarget));
                        JArray emailTemplatesDetailArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.EmailTemplatesDetailDataFilePath(jobTarget));
                        if (emailTemplatesArray != null)
                        {
                            foreach (JObject emailTemplateObject in emailTemplatesArray)
                            {
                                EmailAlertTemplate emailAlertTemplate = new EmailAlertTemplate();

                                emailAlertTemplate.Controller = jobTarget.Controller;

                                emailAlertTemplate.Name = getStringValueFromJToken(emailTemplateObject, "name");

                                emailAlertTemplate.OneEmailPerEvent = getBoolValueFromJToken(emailTemplateObject, "oneEmailPerEvent");
                                emailAlertTemplate.EventLimit       = getLongValueFromJToken(emailTemplateObject, "eventClampLimit");

                                try
                                {
                                    string[] emails = emailTemplateObject["toRecipients"].Select(s => getStringValueFromJToken(s, "value")).ToArray();
                                    emailAlertTemplate.To = String.Join(";", emails);
                                }
                                catch { }
                                try
                                {
                                    string[] emails = emailTemplateObject["ccRecipients"].Select(s => getStringValueFromJToken(s, "value")).ToArray();
                                    emailAlertTemplate.CC = String.Join(";", emails);
                                }
                                catch { }
                                try
                                {
                                    string[] emails = emailTemplateObject["bccRecipients"].Select(s => getStringValueFromJToken(s, "value")).ToArray();
                                    emailAlertTemplate.BCC = String.Join(";", emails);
                                }
                                catch { }

                                try
                                {
                                    string[] emails = emailTemplateObject["testToRecipients"].Select(s => getStringValueFromJToken(s, "value")).ToArray();
                                    emailAlertTemplate.TestTo = String.Join(";", emails);
                                }
                                catch { }
                                try
                                {
                                    string[] emails = emailTemplateObject["testCcRecipients"].Select(s => getStringValueFromJToken(s, "value")).ToArray();
                                    emailAlertTemplate.TestCC = String.Join(";", emails);
                                }
                                catch { }
                                try
                                {
                                    string[] emails = emailTemplateObject["testBccRecipients"].Select(s => getStringValueFromJToken(s, "value")).ToArray();
                                    emailAlertTemplate.TestBCC = String.Join(";", emails);
                                }
                                catch { }
                                emailAlertTemplate.TestLogLevel = getStringValueFromJToken(emailTemplateObject, "testLogLevel");

                                emailAlertTemplate.Headers         = getStringValueOfObjectFromJToken(emailTemplateObject, "headers", true);
                                emailAlertTemplate.Subject         = getStringValueFromJToken(emailTemplateObject, "subject");
                                emailAlertTemplate.TextBody        = getStringValueFromJToken(emailTemplateObject, "textBody");
                                emailAlertTemplate.HTMLBody        = getStringValueFromJToken(emailTemplateObject, "htmlBody");
                                emailAlertTemplate.IncludeHTMLBody = getBoolValueFromJToken(emailTemplateObject, "includeHtmlBody");

                                emailAlertTemplate.Properties     = getStringValueOfObjectFromJToken(emailTemplateObject, "defaultCustomProperties");
                                emailAlertTemplate.TestProperties = getStringValueOfObjectFromJToken(emailTemplateObject, "testPropertiesPairs");

                                emailAlertTemplate.EventTypes = getStringValueOfObjectFromJToken(emailTemplateObject, "eventTypeCountPairs");

                                if (emailTemplatesDetailArray != null)
                                {
                                    JToken emailTemplateDetailToken = emailTemplatesDetailArray.Where(t => t["name"].ToString() == emailAlertTemplate.Name).FirstOrDefault();
                                    if (emailTemplateDetailToken != null)
                                    {
                                        emailAlertTemplate.TemplateID = getLongValueFromJToken(emailTemplateDetailToken, "id");
                                    }
                                }

                                emailTemplatesList.Add(emailAlertTemplate);
                            }
                        }

                        emailTemplatesList = emailTemplatesList.OrderBy(c => c.Name).ToList();
                        FileIOHelper.WriteListToCSVFile(emailTemplatesList, new EmailAlertTemplateReportMap(), FilePathMap.EmailTemplatesIndexFilePath(jobTarget));

                        stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + emailTemplatesList.Count;

                        #endregion

                        #region Combine All for Report CSV

                        // If it is the first one, clear out the combined folder
                        if (reportFolderCleaned == false)
                        {
                            FileIOHelper.DeleteFolder(FilePathMap.ControllerSettingsReportFolderPath());
                            Thread.Sleep(1000);
                            FileIOHelper.CreateFolder(FilePathMap.ControllerSettingsReportFolderPath());
                            reportFolderCleaned = true;
                        }

                        // Append all the individual report files into one
                        if (File.Exists(FilePathMap.ControllerSettingsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ControllerSettingsIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.ControllerSettingsReportFilePath(), FilePathMap.ControllerSettingsIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.HTTPTemplatesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.HTTPTemplatesIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.HTTPTemplatesReportFilePath(), FilePathMap.HTTPTemplatesIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.EmailTemplatesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.EmailTemplatesIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.EmailTemplatesReportFilePath(), FilePathMap.EmailTemplatesIndexFilePath(jobTarget));
                        }

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                        loggerConsole.Warn(ex);

                        return(false);
                    }
                    finally
                    {
                        stopWatchTarget.Stop();

                        this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget);

                        stepTimingTarget.EndTime    = DateTime.Now;
                        stepTimingTarget.Duration   = stopWatchTarget.Elapsed;
                        stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds;

                        List <StepTiming> stepTimings = new List <StepTiming>(1);
                        stepTimings.Add(stepTimingTarget);
                        FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
                    }

                    i++;
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            try
            {
                if (this.ShouldExecute(programOptions, jobConfiguration) == false)
                {
                    return(true);
                }

                if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_MOBILE) == 0)
                {
                    logger.Warn("No {0} targets to process", APPLICATION_TYPE_MOBILE);
                    loggerConsole.Warn("No {0} targets to process", APPLICATION_TYPE_MOBILE);

                    return(true);
                }

                List <MetricExtractMapping> entityMetricExtractMappingList = getMetricsExtractMappingList(jobConfiguration);

                // Process each target
                for (int i = 0; i < jobConfiguration.Target.Count; i++)
                {
                    Stopwatch stopWatchTarget = new Stopwatch();
                    stopWatchTarget.Start();

                    JobTarget jobTarget = jobConfiguration.Target[i];

                    if (jobTarget.Type != null && jobTarget.Type.Length > 0 && jobTarget.Type != APPLICATION_TYPE_MOBILE)
                    {
                        continue;
                    }

                    StepTiming stepTimingTarget = new StepTiming();
                    stepTimingTarget.Controller      = jobTarget.Controller;
                    stepTimingTarget.ApplicationName = jobTarget.Application;
                    stepTimingTarget.ApplicationID   = jobTarget.ApplicationID;
                    stepTimingTarget.JobFileName     = programOptions.OutputJobFilePath;
                    stepTimingTarget.StepName        = jobConfiguration.Status.ToString();
                    stepTimingTarget.StepID          = (int)jobConfiguration.Status;
                    stepTimingTarget.StartTime       = DateTime.Now;

                    try
                    {
                        this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1);

                        #region Target step variables

                        stepTimingTarget.NumEntities = entityMetricExtractMappingList.Count;

                        #endregion

                        string applicationType = "iOS";

                        JArray applicationsMobile = FileIOHelper.LoadJArrayFromFile(FilePathMap.MOBILEApplicationsDataFilePath(jobTarget));
                        if (applicationsMobile != null)
                        {
                            foreach (JObject applicationMobile in applicationsMobile)
                            {
                                JArray applicationsInTarget = (JArray)applicationMobile["children"];
                                if (applicationsInTarget != null && applicationsInTarget.Count > 0)
                                {
                                    foreach (JObject application in applicationsInTarget)
                                    {
                                        if (jobTarget.ApplicationID == getLongValueFromJToken(application, "mobileAppId"))
                                        {
                                            applicationType = getStringValueFromJToken(application, "platform");
                                        }
                                    }
                                }
                            }
                        }

                        loggerConsole.Info("Extract Metrics for All Entities in {0} type ({1} time ranges)", applicationType, jobConfiguration.Input.HourlyTimeRanges.Count);

                        ParallelOptions parallelOptions = new ParallelOptions();
                        if (programOptions.ProcessSequentially == true)
                        {
                            parallelOptions.MaxDegreeOfParallelism = 1;
                        }

                        Parallel.Invoke(parallelOptions,
                                        () =>
                        {
                            #region Application

                            getMetricsForEntitiesMOBILE(jobTarget, jobConfiguration, entityMetricExtractMappingList, MOBILEApplication.ENTITY_FOLDER, MOBILEApplication.ENTITY_TYPE, applicationType);

                            #endregion
                        },
                                        () =>
                        {
                            #region Network Requests

                            getMetricsForEntitiesMOBILE(jobTarget, jobConfiguration, entityMetricExtractMappingList, MOBILENetworkRequest.ENTITY_FOLDER, MOBILENetworkRequest.ENTITY_TYPE, applicationType);

                            #endregion
                        }
                                        );
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                        loggerConsole.Warn(ex);

                        return(false);
                    }
                    finally
                    {
                        stopWatchTarget.Stop();

                        this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget);

                        stepTimingTarget.EndTime    = DateTime.Now;
                        stepTimingTarget.Duration   = stopWatchTarget.Elapsed;
                        stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds;

                        List <StepTiming> stepTimings = new List <StepTiming>(1);
                        stepTimings.Add(stepTimingTarget);
                        FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            try
            {
                if (this.ShouldExecute(jobConfiguration) == false)
                {
                    return(true);
                }

                bool haveProcessedAtLeastOneDBCollector = false;

                // Process each target
                for (int i = 0; i < jobConfiguration.Target.Count; i++)
                {
                    Stopwatch stopWatchTarget = new Stopwatch();
                    stopWatchTarget.Start();

                    JobTarget jobTarget = jobConfiguration.Target[i];

                    StepTiming stepTimingTarget = new StepTiming();
                    stepTimingTarget.Controller      = jobTarget.Controller;
                    stepTimingTarget.ApplicationName = jobTarget.Application;
                    stepTimingTarget.ApplicationID   = jobTarget.ApplicationID;
                    stepTimingTarget.JobFileName     = programOptions.OutputJobFilePath;
                    stepTimingTarget.StepName        = jobConfiguration.Status.ToString();
                    stepTimingTarget.StepID          = (int)jobConfiguration.Status;
                    stepTimingTarget.StartTime       = DateTime.Now;

                    try
                    {
                        this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1);

                        if (jobTarget.Type == APPLICATION_TYPE_DB)
                        {
                            if (haveProcessedAtLeastOneDBCollector == false)
                            {
                                haveProcessedAtLeastOneDBCollector = true;
                            }
                            else
                            {
                                continue;
                            }
                        }

                        int numEventsTotal = 0;

                        #region Health Rule violations

                        using (ControllerApi controllerApi = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword)))
                        {
                            loggerConsole.Info("Extract List of Health Rule Violations ({0} time ranges)", jobConfiguration.Input.HourlyTimeRanges.Count);

                            numEventsTotal = numEventsTotal + extractHealthRuleViolations(jobConfiguration, jobTarget, controllerApi);
                        }

                        #endregion

                        #region Events

                        loggerConsole.Info("Extract {0} event types ({1} time ranges)", EVENT_TYPES.Count, jobConfiguration.Input.HourlyTimeRanges.Count);

                        Parallel.ForEach(
                            EVENT_TYPES,
                            new ParallelOptions {
                            MaxDegreeOfParallelism = EVENTS_EXTRACT_NUMBER_OF_THREADS
                        },
                            () => 0,
                            (eventType, loop, subtotal) =>
                        {
                            using (ControllerApi controllerApiParallel = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword)))
                            {
                                int numEventsInType = extractEvents(jobConfiguration, jobTarget, controllerApiParallel, eventType);
                                subtotal            = subtotal + numEventsInType;
                                return(subtotal);
                            }
                        },
                            (finalResult) =>
                        {
                            Interlocked.Add(ref numEventsTotal, finalResult);
                        }
                            );
                        loggerConsole.Info("{0} events total", numEventsTotal);

                        #endregion

                        stepTimingTarget.NumEntities = numEventsTotal;
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                        loggerConsole.Warn(ex);

                        return(false);
                    }
                    finally
                    {
                        stopWatchTarget.Stop();

                        this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget);

                        stepTimingTarget.EndTime    = DateTime.Now;
                        stepTimingTarget.Duration   = stopWatchTarget.Elapsed;
                        stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds;

                        List <StepTiming> stepTimings = new List <StepTiming>(1);
                        stepTimings.Add(stepTimingTarget);
                        FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
        private void getMetricsForEntitiesMOBILE(
            JobTarget jobTarget,
            JobConfiguration jobConfiguration,
            List <MetricExtractMapping> entityMetricExtractMappingList,
            string entityFolderName,
            string entityType,
            string applicationType)
        {
            using (ControllerApi controllerApi = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword)))
            {
                List <MetricExtractMapping> entityMetricExtractMappingListFiltered = entityMetricExtractMappingList.Where(m => m.EntityType == entityType).ToList();

                loggerConsole.Info("Extract {0} ({1} metrics)", entityType, entityMetricExtractMappingListFiltered.Count);
                logger.Info("Extract {0} ({1} metrics)", entityType, entityMetricExtractMappingListFiltered.Count);

                foreach (MetricExtractMapping metricExtractMapping in entityMetricExtractMappingListFiltered)
                {
                    // Get the full range
                    JobTimeRange jobTimeRange = jobConfiguration.Input.TimeRange;

                    string metricPath = String.Format(metricExtractMapping.MetricPath, applicationType, jobTarget.Application);

                    loggerConsole.Trace("{0} {1}", metricExtractMapping.EntityType, metricPath);
                    logger.Info("Retrieving metric summary for Application {0}({1}), Metric='{2}', From {3:o}, To {4:o}", jobTarget.Application, jobTarget.ParentApplicationID, metricPath, jobTimeRange.From, jobTimeRange.To);

                    string metricsJson = String.Empty;

                    string metricsDataFilePath = FilePathMap.MetricFullRangeDataFilePath(jobTarget, entityFolderName, metricExtractMapping.FolderName, jobTimeRange);
                    if (File.Exists(metricsDataFilePath) == false)
                    {
                        // First range is the whole thing
                        metricsJson = controllerApi.GetMetricData(
                            jobTarget.ParentApplicationID,
                            metricPath,
                            UnixTimeHelper.ConvertToUnixTimestamp(jobTimeRange.From),
                            UnixTimeHelper.ConvertToUnixTimestamp(jobTimeRange.To),
                            true);

                        if (metricsJson != String.Empty && metricsJson != "[ ]")
                        {
                            FileIOHelper.SaveFileToPath(metricsJson, metricsDataFilePath);
                        }
                    }

                    if (jobConfiguration.Input.MetricsSelectionCriteria.IncludeHourAndMinuteDetail == true)
                    {
                        // Get the hourly time ranges
                        for (int j = 0; j < jobConfiguration.Input.HourlyTimeRanges.Count; j++)
                        {
                            jobTimeRange = jobConfiguration.Input.HourlyTimeRanges[j];

                            logger.Info("Retrieving metric details for Application {0}({1}), Metric='{2}', From {3:o}, To {4:o}", jobTarget.Application, jobTarget.ParentApplicationID, metricPath, jobTimeRange.From, jobTimeRange.To);

                            metricsDataFilePath = FilePathMap.MetricHourRangeDataFilePath(jobTarget, entityFolderName, metricExtractMapping.FolderName, jobTimeRange);
                            if (File.Exists(metricsDataFilePath) == false)
                            {
                                // Subsequent ones are details
                                metricsJson = controllerApi.GetMetricData(
                                    jobTarget.ParentApplicationID,
                                    metricPath,
                                    UnixTimeHelper.ConvertToUnixTimestamp(jobTimeRange.From),
                                    UnixTimeHelper.ConvertToUnixTimestamp(jobTimeRange.To),
                                    false);

                                if (metricsJson != String.Empty && metricsJson != "[ ]")
                                {
                                    FileIOHelper.SaveFileToPath(metricsJson, metricsDataFilePath);
                                }
                            }
                        }
                    }
                }

                loggerConsole.Info("Completed {0} ({1} metrics)", entityType, entityMetricExtractMappingListFiltered.Count);
            }
        }
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            if (this.ShouldExecute(jobConfiguration) == false)
            {
                return(true);
            }

            if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_WEB) == 0)
            {
                return(true);
            }

            try
            {
                loggerConsole.Info("Prepare Detected WEB Entities Report File");

                #region Prepare the report package

                // Prepare package
                ExcelPackage excelReport = new ExcelPackage();
                excelReport.Workbook.Properties.Author  = String.Format("AppDynamics DEXTER {0}", Assembly.GetEntryAssembly().GetName().Version);
                excelReport.Workbook.Properties.Title   = "AppDynamics DEXTER Detected WEB Entities Report";
                excelReport.Workbook.Properties.Subject = programOptions.JobName;

                excelReport.Workbook.Properties.Comments = String.Format("Targets={0}\nFrom={1:o}\nTo={2:o}", jobConfiguration.Target.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To);

                #endregion

                #region Parameters sheet

                // Parameters sheet
                ExcelWorksheet sheet = excelReport.Workbook.Worksheets.Add(SHEET_PARAMETERS);

                var hyperLinkStyle = sheet.Workbook.Styles.CreateNamedStyle("HyperLinkStyle");
                hyperLinkStyle.Style.Font.UnderLineType = ExcelUnderLineType.Single;
                hyperLinkStyle.Style.Font.Color.SetColor(colorBlueForHyperlinks);

                fillReportParametersSheet(sheet, jobConfiguration, "AppDynamics DEXTER Detected WEB Entities Report");

                #endregion

                #region TOC sheet

                // Navigation sheet with link to other sheets
                sheet = excelReport.Workbook.Worksheets.Add(SHEET_TOC);

                #endregion

                #region Entity sheets and their associated pivots

                // Entity sheets
                sheet = excelReport.Workbook.Worksheets.Add(SHEET_CONTROLLERS_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_APPLICATIONS_ALL_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_APPLICATIONS_WEB_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_WEB_PAGES_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Pivot";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_WEB_PAGES_TYPE_PIVOT);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_WEB_PAGES_TYPE_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_WEB_PAGES_LIST);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 3, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_PAGE_RESOURCES_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Pivot";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_PAGE_RESOURCES_TYPE_PIVOT);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_PAGE_RESOURCES_TYPE_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_PAGE_RESOURCES_LIST);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_PAGE_BUSINESS_TRANSACTIONS_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Pivot";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_PAGE_BUSINESS_TRANSACTIONS_TYPE_PIVOT);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_PAGE_BUSINESS_TRANSACTIONS_TYPE_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_PAGE_BUSINESS_TRANSACTIONS_LIST);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_GEO_LOCATIONS_LIST);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Pivot";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_GEO_LOCATIONS_TYPE_PIVOT);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_GEO_LOCATIONS_TYPE_PIVOT);
                sheet.Cells[1, 1].Value     = "Table of Contents";
                sheet.Cells[1, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC);
                sheet.Cells[1, 2].StyleName = "HyperLinkStyle";
                sheet.Cells[2, 1].Value     = "See Table";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_GEO_LOCATIONS_LIST);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1);

                #endregion

                loggerConsole.Info("Fill Detected WEB Entities Report File");

                #region Report file variables

                ExcelRangeBase range = null;
                ExcelTable     table = null;

                #endregion

                #region Controllers

                loggerConsole.Info("List of Controllers");

                sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerSummaryReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Applications - All

                loggerConsole.Info("List of Applications - All");

                sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ALL_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerApplicationsReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Applications

                loggerConsole.Info("List of Applications");

                sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_WEB_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.WEBApplicationsReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Web Pages

                loggerConsole.Info("List of Web Pages");

                sheet = excelReport.Workbook.Worksheets[SHEET_WEB_PAGES_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.WEBPagesReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Web Page Resources

                loggerConsole.Info("List of Web Page Resources");

                sheet = excelReport.Workbook.Worksheets[SHEET_PAGE_RESOURCES_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.WEBPageResourcesReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Web Page Business Transactions

                loggerConsole.Info("List of Web Page Business Transactions");

                sheet = excelReport.Workbook.Worksheets[SHEET_PAGE_BUSINESS_TRANSACTIONS_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.WEBPageBusinessTransactionsReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Geo Locations

                loggerConsole.Info("List of Geo Locations");

                sheet = excelReport.Workbook.Worksheets[SHEET_GEO_LOCATIONS_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.WEBGeoLocationsReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                loggerConsole.Info("Finalize Detected WEB Entities Report File");

                #region Controllers sheet

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_CONTROLLERS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width = 25;
                    sheet.Column(table.Columns["Version"].Position + 1).Width    = 15;
                }

                #endregion

                #region Applications - All

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ALL_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_APPLICATIONS_ALL);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["Description"].Position + 1).Width     = 15;

                    sheet.Column(table.Columns["CreatedBy"].Position + 1).Width = 15;
                    sheet.Column(table.Columns["UpdatedBy"].Position + 1).Width = 15;

                    sheet.Column(table.Columns["CreatedOn"].Position + 1).Width    = 20;
                    sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width    = 20;
                    sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width = 20;
                }

                #endregion

                #region Applications

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_WEB_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_APPLICATIONS_WEB);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20;

                    ExcelAddress cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumPages"].Position + 1, sheet.Dimension.Rows, table.Columns["NumPages"].Position + 1);
                    var          cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumAJAXRequests"].Position + 1, sheet.Dimension.Rows, table.Columns["NumAJAXRequests"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumVirtualPages"].Position + 1, sheet.Dimension.Rows, table.Columns["NumVirtualPages"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumIFrames"].Position + 1, sheet.Dimension.Rows, table.Columns["NumIFrames"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumActivity"].Position + 1, sheet.Dimension.Rows, table.Columns["NumActivity"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumNoActivity"].Position + 1, sheet.Dimension.Rows, table.Columns["NumNoActivity"].Position + 1);
                    cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);
                }

                #endregion

                #region Web Pages

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_WEB_PAGES_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_WEB_PAGES);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["PageType"].Position + 1).Width        = 10;
                    sheet.Column(table.Columns["PageName"].Position + 1).Width        = 20;
                    sheet.Column(table.Columns["FirstSegment"].Position + 1).Width    = 20;
                    sheet.Column(table.Columns["From"].Position + 1).Width            = 20;
                    sheet.Column(table.Columns["To"].Position + 1).Width      = 20;
                    sheet.Column(table.Columns["FromUtc"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["ToUtc"].Position + 1).Width   = 20;

                    // Make pivot
                    sheet = excelReport.Workbook.Worksheets[SHEET_WEB_PAGES_TYPE_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 1, 1], range, PIVOT_WEB_PAGES_TYPE);
                    setDefaultPivotTableSettings(pivot);
                    addFilterFieldToPivot(pivot, "HasActivity");
                    addFilterFieldToPivot(pivot, "ARTRange", eSortType.Ascending);
                    addFilterFieldToPivot(pivot, "NumNameSegments", eSortType.Ascending);
                    addRowFieldToPivot(pivot, "Controller");
                    addRowFieldToPivot(pivot, "ApplicationName");
                    addRowFieldToPivot(pivot, "PageType");
                    addRowFieldToPivot(pivot, "FirstSegment");
                    addRowFieldToPivot(pivot, "PageName");
                    addDataFieldToPivot(pivot, "PageID", DataFieldFunctions.Count, "NumPages");
                    addDataFieldToPivot(pivot, "ART", DataFieldFunctions.Average, "ART");
                    addDataFieldToPivot(pivot, "TimeTotal", DataFieldFunctions.Sum, "Time");
                    addDataFieldToPivot(pivot, "Calls", DataFieldFunctions.Sum, "Calls");
                    addDataFieldToPivot(pivot, "CPM", DataFieldFunctions.Average, "CPM");

                    ExcelChart chart = sheet.Drawings.AddChart(GRAPH_WEB_PAGES_TYPE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                    sheet.Column(3).Width = 20;
                    sheet.Column(4).Width = 20;
                    sheet.Column(5).Width = 20;
                }

                #endregion

                #region Web Page Resources

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_PAGE_RESOURCES_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_PAGE_RESOURCES);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["PageType"].Position + 1).Width        = 10;
                    sheet.Column(table.Columns["PageName"].Position + 1).Width        = 20;
                    sheet.Column(table.Columns["ChildPageType"].Position + 1).Width   = 10;
                    sheet.Column(table.Columns["ChildPageName"].Position + 1).Width   = 20;
                    sheet.Column(table.Columns["From"].Position + 1).Width            = 20;
                    sheet.Column(table.Columns["To"].Position + 1).Width      = 20;
                    sheet.Column(table.Columns["FromUtc"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["ToUtc"].Position + 1).Width   = 20;

                    // Make pivot
                    sheet = excelReport.Workbook.Worksheets[SHEET_PAGE_RESOURCES_TYPE_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_PAGE_RESOURCES_TYPE);
                    setDefaultPivotTableSettings(pivot);
                    addFilterFieldToPivot(pivot, "HasActivity");
                    addFilterFieldToPivot(pivot, "ARTRange", eSortType.Ascending);
                    addRowFieldToPivot(pivot, "Controller");
                    addRowFieldToPivot(pivot, "ApplicationName");
                    addRowFieldToPivot(pivot, "PageName");
                    addRowFieldToPivot(pivot, "ChildPageType");
                    addRowFieldToPivot(pivot, "ChildPageName");
                    addDataFieldToPivot(pivot, "ChildPageID", DataFieldFunctions.Count, "NumPages");
                    addDataFieldToPivot(pivot, "ART", DataFieldFunctions.Average, "ART");
                    addDataFieldToPivot(pivot, "Calls", DataFieldFunctions.Sum, "Calls");
                    addDataFieldToPivot(pivot, "CPM", DataFieldFunctions.Average, "CPM");

                    ExcelChart chart = sheet.Drawings.AddChart(GRAPH_PAGE_RESOURCES_TYPE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                    sheet.Column(3).Width = 20;
                    sheet.Column(4).Width = 20;
                    sheet.Column(5).Width = 20;
                }

                #endregion

                #region Web Page Business Transactions

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_PAGE_BUSINESS_TRANSACTIONS_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_PAGE_BUSINESS_TRANSACTIONS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["PageType"].Position + 1).Width        = 10;
                    sheet.Column(table.Columns["PageName"].Position + 1).Width        = 20;
                    sheet.Column(table.Columns["TierName"].Position + 1).Width        = 20;
                    sheet.Column(table.Columns["BTName"].Position + 1).Width          = 20;
                    sheet.Column(table.Columns["BTType"].Position + 1).Width          = 15;
                    sheet.Column(table.Columns["From"].Position + 1).Width            = 20;
                    sheet.Column(table.Columns["To"].Position + 1).Width      = 20;
                    sheet.Column(table.Columns["FromUtc"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["ToUtc"].Position + 1).Width   = 20;

                    // Make pivot
                    sheet = excelReport.Workbook.Worksheets[SHEET_PAGE_BUSINESS_TRANSACTIONS_TYPE_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_PAGE_RESOURCES_TYPE);
                    setDefaultPivotTableSettings(pivot);
                    addFilterFieldToPivot(pivot, "HasActivity");
                    addFilterFieldToPivot(pivot, "ARTRange", eSortType.Ascending);
                    addRowFieldToPivot(pivot, "Controller");
                    addRowFieldToPivot(pivot, "ApplicationName");
                    addRowFieldToPivot(pivot, "PageName");
                    addRowFieldToPivot(pivot, "TierName");
                    addRowFieldToPivot(pivot, "BTName");
                    addDataFieldToPivot(pivot, "BTID", DataFieldFunctions.Count, "NumBTs");
                    addDataFieldToPivot(pivot, "ART", DataFieldFunctions.Average, "ART");
                    addDataFieldToPivot(pivot, "Calls", DataFieldFunctions.Sum, "Calls");
                    addDataFieldToPivot(pivot, "CPM", DataFieldFunctions.Average, "CPM");

                    ExcelChart chart = sheet.Drawings.AddChart(GRAPH_PAGE_BUSINESS_TRANSACTIONS_TYPE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                    sheet.Column(3).Width = 20;
                    sheet.Column(4).Width = 20;
                    sheet.Column(5).Width = 20;
                }

                #endregion

                #region Geo Locations

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_GEO_LOCATIONS_LIST];
                logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
                if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_GEO_LOCATIONS);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    sheet.Column(table.Columns["Controller"].Position + 1).Width      = 15;
                    sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["LocationName"].Position + 1).Width    = 15;
                    sheet.Column(table.Columns["Country"].Position + 1).Width         = 15;
                    sheet.Column(table.Columns["Region"].Position + 1).Width          = 15;
                    sheet.Column(table.Columns["GeoCode"].Position + 1).Width         = 15;
                    sheet.Column(table.Columns["From"].Position + 1).Width            = 20;
                    sheet.Column(table.Columns["To"].Position + 1).Width      = 20;
                    sheet.Column(table.Columns["FromUtc"].Position + 1).Width = 20;
                    sheet.Column(table.Columns["ToUtc"].Position + 1).Width   = 20;

                    // Make pivot
                    sheet = excelReport.Workbook.Worksheets[SHEET_GEO_LOCATIONS_TYPE_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_PAGE_RESOURCES_TYPE);
                    setDefaultPivotTableSettings(pivot);
                    addFilterFieldToPivot(pivot, "HasActivity");
                    addFilterFieldToPivot(pivot, "ARTRange", eSortType.Ascending);
                    addRowFieldToPivot(pivot, "Controller");
                    addRowFieldToPivot(pivot, "ApplicationName");
                    addRowFieldToPivot(pivot, "LocationType");
                    addRowFieldToPivot(pivot, "Country");
                    addRowFieldToPivot(pivot, "Region");
                    addRowFieldToPivot(pivot, "LocationName");
                    addDataFieldToPivot(pivot, "ART", DataFieldFunctions.Average, "ART");
                    addDataFieldToPivot(pivot, "Calls", DataFieldFunctions.Sum, "Calls");
                    addDataFieldToPivot(pivot, "CPM", DataFieldFunctions.Average, "CPM");

                    ExcelChart chart = sheet.Drawings.AddChart(GRAPH_GEO_LOCATIONS_TYPE, eChartType.ColumnClustered, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(1).Width = 20;
                    sheet.Column(2).Width = 20;
                    sheet.Column(3).Width = 20;
                    sheet.Column(4).Width = 20;
                    sheet.Column(5).Width = 20;
                    sheet.Column(6).Width = 20;
                }

                #endregion

                #region TOC sheet

                // TOC sheet again
                sheet = excelReport.Workbook.Worksheets[SHEET_TOC];
                fillTableOfContentsSheet(sheet, excelReport);

                #endregion

                #region Save file

                if (Directory.Exists(FilePathMap.ReportFolderPath()) == false)
                {
                    Directory.CreateDirectory(FilePathMap.ReportFolderPath());
                }

                string reportFilePath = FilePathMap.WEBEntitiesExcelReportFilePath(jobConfiguration.Input.TimeRange);
                logger.Info("Saving Excel report {0}", reportFilePath);
                loggerConsole.Info("Saving Excel report {0}", reportFilePath);

                try
                {
                    // Save full report Excel files
                    excelReport.SaveAs(new FileInfo(reportFilePath));
                }
                catch (InvalidOperationException ex)
                {
                    logger.Warn("Unable to save Excel file {0}", reportFilePath);
                    logger.Warn(ex);
                    loggerConsole.Warn("Unable to save Excel file {0}", reportFilePath);
                }

                #endregion

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }
Ejemplo n.º 30
0
        public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.OutputJobFilePath;
            stepTimingFunction.StepName    = jobConfiguration.Status.ToString();
            stepTimingFunction.StepID      = (int)jobConfiguration.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = jobConfiguration.Target.Count;

            this.DisplayJobStepStartingStatus(jobConfiguration);

            FilePathMap = new FilePathMap(programOptions, jobConfiguration);

            try
            {
                if (this.ShouldExecute(programOptions, jobConfiguration) == false)
                {
                    return(true);
                }

                List <JobTarget> listOfTargetsAlreadyProcessed = new List <JobTarget>(jobConfiguration.Target.Count);

                bool reportFolderCleaned = false;
                bool haveProcessedAtLeastOneDBCollector = false;

                // Process each target
                for (int i = 0; i < jobConfiguration.Target.Count; i++)
                {
                    Stopwatch stopWatchTarget = new Stopwatch();
                    stopWatchTarget.Start();

                    JobTarget jobTarget = jobConfiguration.Target[i];

                    StepTiming stepTimingTarget = new StepTiming();
                    stepTimingTarget.Controller      = jobTarget.Controller;
                    stepTimingTarget.ApplicationName = jobTarget.Application;
                    stepTimingTarget.ApplicationID   = jobTarget.ApplicationID;
                    stepTimingTarget.JobFileName     = programOptions.OutputJobFilePath;
                    stepTimingTarget.StepName        = jobConfiguration.Status.ToString();
                    stepTimingTarget.StepID          = (int)jobConfiguration.Status;
                    stepTimingTarget.StartTime       = DateTime.Now;

                    try
                    {
                        this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1);

                        if (listOfTargetsAlreadyProcessed.Count(j => (j.Controller == jobTarget.Controller) && (j.ApplicationID == jobTarget.ApplicationID)) > 0)
                        {
                            // Already saw this target, like an APM and WEB pairs together
                            continue;
                        }

                        // For databases, we only process this once for the first collector we've seen
                        if (jobTarget.Type == APPLICATION_TYPE_DB)
                        {
                            if (haveProcessedAtLeastOneDBCollector == false)
                            {
                                haveProcessedAtLeastOneDBCollector = true;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        listOfTargetsAlreadyProcessed.Add(jobTarget);

                        #region Prepare time variables

                        long   fromTimeUnix            = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.From);
                        long   toTimeUnix              = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.To);
                        long   differenceInMinutes     = (toTimeUnix - fromTimeUnix) / (60000);
                        string DEEPLINK_THIS_TIMERANGE = String.Format(DEEPLINK_TIMERANGE_BETWEEN_TIMES, toTimeUnix, fromTimeUnix, differenceInMinutes);

                        #endregion

                        #region Health Rule violations

                        List <HealthRuleViolationEvent> healthRuleViolationList = new List <HealthRuleViolationEvent>();

                        loggerConsole.Info("Index Health Rule Violations");

                        JArray healthRuleViolationsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.ApplicationHealthRuleViolationsDataFilePath(jobTarget));
                        if (healthRuleViolationsArray != null)
                        {
                            foreach (JObject interestingEventObject in healthRuleViolationsArray)
                            {
                                HealthRuleViolationEvent healthRuleViolationEvent = new HealthRuleViolationEvent();
                                healthRuleViolationEvent.Controller      = jobTarget.Controller;
                                healthRuleViolationEvent.ApplicationName = jobTarget.Application;
                                healthRuleViolationEvent.ApplicationID   = jobTarget.ApplicationID;

                                healthRuleViolationEvent.EventID = getLongValueFromJToken(interestingEventObject, "id");
                                healthRuleViolationEvent.FromUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(interestingEventObject, "startTimeInMillis"));
                                healthRuleViolationEvent.From    = healthRuleViolationEvent.FromUtc.ToLocalTime();
                                if (getLongValueFromJToken(interestingEventObject, "endTimeInMillis") > 0)
                                {
                                    healthRuleViolationEvent.ToUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(interestingEventObject, "endTimeInMillis"));
                                    healthRuleViolationEvent.To    = healthRuleViolationEvent.FromUtc.ToLocalTime();
                                }
                                healthRuleViolationEvent.Status    = getStringValueFromJToken(interestingEventObject, "incidentStatus");
                                healthRuleViolationEvent.Severity  = getStringValueFromJToken(interestingEventObject, "severity");
                                healthRuleViolationEvent.EventLink = String.Format(DEEPLINK_INCIDENT, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EventID, getStringValueFromJToken(interestingEventObject, "startTimeInMillis"), DEEPLINK_THIS_TIMERANGE);;

                                healthRuleViolationEvent.Description = getStringValueFromJToken(interestingEventObject, "description");

                                if (isTokenPropertyNull(interestingEventObject, "triggeredEntityDefinition") == false)
                                {
                                    healthRuleViolationEvent.HealthRuleID   = getLongValueFromJToken(interestingEventObject["triggeredEntityDefinition"], "entityId");
                                    healthRuleViolationEvent.HealthRuleName = getStringValueFromJToken(interestingEventObject["triggeredEntityDefinition"], "name");
                                    // TODO the health rule can't be hotlinked to until platform rewrites the screen that opens from Flash
                                    healthRuleViolationEvent.HealthRuleLink = String.Format(DEEPLINK_HEALTH_RULE, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.HealthRuleID, DEEPLINK_THIS_TIMERANGE);
                                }

                                if (isTokenPropertyNull(interestingEventObject, "affectedEntityDefinition") == false)
                                {
                                    healthRuleViolationEvent.EntityID   = getIntValueFromJToken(interestingEventObject["affectedEntityDefinition"], "entityId");
                                    healthRuleViolationEvent.EntityName = getStringValueFromJToken(interestingEventObject["affectedEntityDefinition"], "name");

                                    string entityType = getStringValueFromJToken(interestingEventObject["affectedEntityDefinition"], "entityType");
                                    if (entityTypeStringMapping.ContainsKey(entityType) == true)
                                    {
                                        healthRuleViolationEvent.EntityType = entityTypeStringMapping[entityType];
                                    }
                                    else
                                    {
                                        healthRuleViolationEvent.EntityType = entityType;
                                    }

                                    // Come up with links
                                    switch (entityType)
                                    {
                                    case ENTITY_TYPE_FLOWMAP_APPLICATION:
                                        healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_APM_APPLICATION, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, DEEPLINK_THIS_TIMERANGE);
                                        break;

                                    case ENTITY_TYPE_FLOWMAP_APPLICATION_MOBILE:
                                        healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_APPLICATION_MOBILE, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE);
                                        break;

                                    case ENTITY_TYPE_FLOWMAP_TIER:
                                        healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_TIER, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE);
                                        break;

                                    case ENTITY_TYPE_FLOWMAP_NODE:
                                        healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_NODE, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE);
                                        break;

                                    case ENTITY_TYPE_FLOWMAP_BUSINESS_TRANSACTION:
                                        healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_BUSINESS_TRANSACTION, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE);
                                        break;

                                    case ENTITY_TYPE_FLOWMAP_BACKEND:
                                        healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_BACKEND, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE);
                                        break;

                                    default:
                                        logger.Warn("Unknown entity type {0} in affectedEntityDefinition in health rule violations", entityType);
                                        break;
                                    }
                                }

                                healthRuleViolationEvent.ControllerLink  = String.Format(DEEPLINK_CONTROLLER, healthRuleViolationEvent.Controller, DEEPLINK_THIS_TIMERANGE);
                                healthRuleViolationEvent.ApplicationLink = String.Format(DEEPLINK_APM_APPLICATION, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, DEEPLINK_THIS_TIMERANGE);

                                healthRuleViolationList.Add(healthRuleViolationEvent);
                            }
                        }

                        loggerConsole.Info("{0} Health Rule Violations", healthRuleViolationList.Count);

                        stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + healthRuleViolationList.Count;

                        // Sort them
                        healthRuleViolationList = healthRuleViolationList.OrderBy(o => o.HealthRuleName).ThenBy(o => o.From).ThenBy(o => o.Severity).ToList();
                        FileIOHelper.WriteListToCSVFile <HealthRuleViolationEvent>(healthRuleViolationList, new HealthRuleViolationEventReportMap(), FilePathMap.ApplicationHealthRuleViolationsIndexFilePath(jobTarget));

                        #endregion

                        #region Events

                        List <Event>       eventsList       = new List <Event>();
                        List <EventDetail> eventDetailsList = new List <EventDetail>();

                        loggerConsole.Info("Index Events");

                        foreach (string eventType in EVENT_TYPES)
                        {
                            JArray eventsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.ApplicationEventsWithDetailsDataFilePath(jobTarget, eventType));
                            if (eventsArray == null)
                            {
                                eventsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.ApplicationEventsDataFilePath(jobTarget, eventType));
                            }
                            if (eventsArray != null)
                            {
                                loggerConsole.Info("{0} Events", eventType);

                                foreach (JObject interestingEventObject in eventsArray)
                                {
                                    Event @event = new Event();
                                    @event.Controller      = jobTarget.Controller;
                                    @event.ApplicationName = jobTarget.Application;
                                    @event.ApplicationID   = jobTarget.ApplicationID;

                                    @event.EventID     = getLongValueFromJToken(interestingEventObject, "id");
                                    @event.OccurredUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(interestingEventObject, "eventTime"));
                                    @event.Occurred    = @event.OccurredUtc.ToLocalTime();
                                    @event.Type        = getStringValueFromJToken(interestingEventObject, "type");
                                    @event.SubType     = getStringValueFromJToken(interestingEventObject, "subType");
                                    @event.Severity    = getStringValueFromJToken(interestingEventObject, "severity");
                                    @event.EventLink   = getStringValueFromJToken(interestingEventObject, "deepLinkUrl");
                                    @event.Summary     = getStringValueFromJToken(interestingEventObject, "summary");

                                    if (isTokenPropertyNull(interestingEventObject, "triggeredEntity") == false)
                                    {
                                        @event.TriggeredEntityID   = getLongValueFromJToken(interestingEventObject["triggeredEntity"], "entityId");
                                        @event.TriggeredEntityName = getStringValueFromJToken(interestingEventObject["triggeredEntity"], "name");
                                        string entityType = getStringValueFromJToken(interestingEventObject["triggeredEntity"], "entityType");
                                        if (entityTypeStringMapping.ContainsKey(entityType) == true)
                                        {
                                            @event.TriggeredEntityType = entityTypeStringMapping[entityType];
                                        }
                                        else
                                        {
                                            @event.TriggeredEntityType = entityType;
                                        }
                                    }

                                    foreach (JObject affectedEntity in interestingEventObject["affectedEntities"])
                                    {
                                        string entityType = getStringValueFromJToken(affectedEntity, "entityType");
                                        switch (entityType)
                                        {
                                        case ENTITY_TYPE_FLOWMAP_APPLICATION:
                                            // already have this data
                                            break;

                                        case ENTITY_TYPE_FLOWMAP_TIER:
                                            @event.TierID   = getIntValueFromJToken(affectedEntity, "entityId");
                                            @event.TierName = getStringValueFromJToken(affectedEntity, "name");
                                            break;

                                        case ENTITY_TYPE_FLOWMAP_NODE:
                                            @event.NodeID   = getIntValueFromJToken(affectedEntity, "entityId");
                                            @event.NodeName = getStringValueFromJToken(affectedEntity, "name");
                                            break;

                                        case ENTITY_TYPE_FLOWMAP_MACHINE:
                                            @event.MachineID   = getIntValueFromJToken(affectedEntity, "entityId");
                                            @event.MachineName = getStringValueFromJToken(affectedEntity, "name");
                                            break;

                                        case ENTITY_TYPE_FLOWMAP_BUSINESS_TRANSACTION:
                                            @event.BTID   = getIntValueFromJToken(affectedEntity, "entityId");
                                            @event.BTName = getStringValueFromJToken(affectedEntity, "name");
                                            break;

                                        case ENTITY_TYPE_FLOWMAP_HEALTH_RULE:
                                            @event.TriggeredEntityID   = getLongValueFromJToken(affectedEntity, "entityId");
                                            @event.TriggeredEntityType = entityTypeStringMapping[getStringValueFromJToken(affectedEntity, "entityType")];
                                            @event.TriggeredEntityName = getStringValueFromJToken(affectedEntity, "name");
                                            break;

                                        default:
                                            logger.Warn("Unknown entity type {0} in affectedEntities in events", entityType);
                                            break;
                                        }
                                    }

                                    @event.ControllerLink  = String.Format(DEEPLINK_CONTROLLER, @event.Controller, DEEPLINK_THIS_TIMERANGE);
                                    @event.ApplicationLink = String.Format(DEEPLINK_APM_APPLICATION, @event.Controller, @event.ApplicationID, DEEPLINK_THIS_TIMERANGE);
                                    if (@event.TierID != 0)
                                    {
                                        @event.TierLink = String.Format(DEEPLINK_TIER, @event.Controller, @event.ApplicationID, @event.TierID, DEEPLINK_THIS_TIMERANGE);
                                    }
                                    if (@event.NodeID != 0)
                                    {
                                        @event.NodeLink = String.Format(DEEPLINK_NODE, @event.Controller, @event.ApplicationID, @event.NodeID, DEEPLINK_THIS_TIMERANGE);
                                    }
                                    if (@event.BTID != 0)
                                    {
                                        @event.BTLink = String.Format(DEEPLINK_BUSINESS_TRANSACTION, @event.Controller, @event.ApplicationID, @event.BTID, DEEPLINK_THIS_TIMERANGE);
                                    }

                                    if (isTokenPropertyNull(interestingEventObject, "details") == false &&
                                        isTokenPropertyNull(interestingEventObject["details"], "eventDetails") == false)
                                    {
                                        JArray eventDetailsArray = (JArray)interestingEventObject["details"]["eventDetails"];
                                        if (eventDetailsArray != null)
                                        {
                                            List <EventDetail> eventDetailsForThisEventList = new List <EventDetail>(eventDetailsArray.Count);

                                            foreach (JObject eventDetailObject in eventDetailsArray)
                                            {
                                                EventDetail eventDetail = new EventDetail();

                                                eventDetail.Controller      = @event.Controller;
                                                eventDetail.ApplicationName = @event.ApplicationName;
                                                eventDetail.ApplicationID   = @event.ApplicationID;
                                                eventDetail.TierName        = @event.TierName;
                                                eventDetail.TierID          = @event.TierID;
                                                eventDetail.NodeName        = @event.NodeName;
                                                eventDetail.NodeID          = @event.NodeID;
                                                eventDetail.MachineName     = @event.MachineName;
                                                eventDetail.MachineID       = @event.MachineID;
                                                eventDetail.BTName          = @event.BTName;
                                                eventDetail.BTID            = @event.BTID;

                                                eventDetail.EventID     = @event.EventID;
                                                eventDetail.OccurredUtc = @event.OccurredUtc;
                                                eventDetail.Occurred    = @event.Occurred;
                                                eventDetail.Type        = @event.Type;
                                                eventDetail.SubType     = @event.SubType;
                                                eventDetail.Severity    = @event.Severity;
                                                eventDetail.Summary     = @event.Summary;

                                                eventDetail.DetailName  = getStringValueFromJToken(eventDetailObject, "name");
                                                eventDetail.DetailValue = getStringValueFromJToken(eventDetailObject, "value");

                                                // Parse the special types of the event types, such as options and envinronment variable changes
                                                bool shouldContinue = true;
                                                switch (@event.Type)
                                                {
                                                    #region APPLICATION_CONFIG_CHANGE

                                                case "APPLICATION_CONFIG_CHANGE":
                                                    if (shouldContinue == true)
                                                    {
                                                        // Added Option 1
                                                        // Removed Option 1
                                                        Regex regex = new Regex(@"(.*\sOption)\s\d+", RegexOptions.IgnoreCase);
                                                        Match match = regex.Match(eventDetail.DetailName);
                                                        if (match != null && match.Groups.Count == 2)
                                                        {
                                                            eventDetail.DetailAction = match.Groups[1].Value;
                                                            //-Dgw.cc.full.upgrade.intended.date=20191112
                                                            //-XX:+UseGCLogFileRotation
                                                            //-XX:NumberOfGCLogFiles=< number of log files >
                                                            //-XX:GCLogFileSize=< file size >[ unit ]
                                                            //-Xloggc:/path/to/gc.log
                                                            parseJavaStartupOptionIntoEventDetail(eventDetail);
                                                            shouldContinue = false;
                                                        }
                                                    }

                                                    if (shouldContinue == true)
                                                    {
                                                        // Added Variable 1:
                                                        // Removed Variable 1:
                                                        Regex regex = new Regex(@"((Added|Removed) Variable)\s\d+", RegexOptions.IgnoreCase);
                                                        Match match = regex.Match(eventDetail.DetailName);
                                                        if (match != null && match.Groups.Count == 3)
                                                        {
                                                            eventDetail.DetailAction = match.Groups[1].Value;
                                                            // SSH_TTY=/dev/pts/0
                                                            // HOSTNAME=felvqcap1174.farmersinsurance.com
                                                            parseEnvironmentVariableIntoEventDetail(eventDetail);
                                                            shouldContinue = false;
                                                        }
                                                    }

                                                    if (shouldContinue == true)
                                                    {
                                                        // Modified Variable 1:
                                                        Regex regex = new Regex(@"(Modified Variable)\s\d+", RegexOptions.IgnoreCase);
                                                        Match match = regex.Match(eventDetail.DetailName);
                                                        if (match != null && match.Groups.Count == 2)
                                                        {
                                                            eventDetail.DetailAction = match.Groups[1].Value;
                                                            // MAIL=/var/mail/jbossapp (changed to) MAIL=/var/spool/mail/jbossapp
                                                            // SHLVL=5 (changed to) SHLVL=3
                                                            parseModifiedEnvironmentVariableIntoEventDetail(eventDetail);
                                                            shouldContinue = false;
                                                        }
                                                    }

                                                    if (shouldContinue == true)
                                                    {
                                                        // Modified Property 2:
                                                        Regex regex = new Regex(@"(Modified Property)\s\d+", RegexOptions.IgnoreCase);
                                                        Match match = regex.Match(eventDetail.DetailName);
                                                        if (match != null && match.Groups.Count == 2)
                                                        {
                                                            eventDetail.DetailAction = match.Groups[1].Value;
                                                            // gw.cc.full.upgrade.intended.date=20191112 (changed to) gw.cc.full.upgrade.intended.date=20191113
                                                            // user.dir=/jboss/scripts/jenkins/28/slave/workspace/ClaimsCenter/GWCC_GW_DB_APP_DP/perfcc06post (changed to) user.dir=/jboss/scripts/ccperf06
                                                            parseModifiedPropertyIntoEventDetail(eventDetail);
                                                            shouldContinue = false;
                                                        }
                                                    }

                                                    break;

                                                    #endregion

                                                    #region POLICY_***

                                                case "POLICY_OPEN_WARNING":
                                                case "POLICY_OPEN_CRITICAL":
                                                case "POLICY_CLOSE_WARNING":
                                                case "POLICY_CLOSE_CRITICAL":
                                                case "POLICY_UPGRADED":
                                                case "POLICY_DOWNGRADED":
                                                case "POLICY_CANCELED_WARNING":
                                                case "POLICY_CANCELED_CRITICAL":
                                                case "POLICY_CONTINUES_CRITICAL":
                                                case "POLICY_CONTINUES_WARNING":
                                                    if (eventDetail.DetailName == "Evaluation End Time" ||
                                                        eventDetail.DetailName == "Evaluation Start Time")
                                                    {
                                                        // These are a unix datetime value
                                                        DateTime dateTimeVal1 = UnixTimeHelper.ConvertFromUnixTimestamp(Convert.ToInt64(eventDetail.DetailValue));
                                                        eventDetail.DataType    = "DateTime";
                                                        eventDetail.DetailValue = dateTimeVal1.ToLocalTime().ToString("G");
                                                    }
                                                    break;

                                                    #endregion

                                                default:
                                                    break;
                                                }

                                                if (eventDetail.DataType == null || eventDetail.DataType.Length == 0)
                                                {
                                                    // Get datatype of value
                                                    long     longVal     = 0;
                                                    double   doubleVal   = 0;
                                                    DateTime dateTimeVal = DateTime.MinValue;
                                                    if (Int64.TryParse(eventDetail.DetailValue, out longVal) == true)
                                                    {
                                                        eventDetail.DataType = "Integer";
                                                    }
                                                    else if (Double.TryParse(eventDetail.DetailValue, out doubleVal) == true)
                                                    {
                                                        eventDetail.DataType = "Double";
                                                    }
                                                    else if (DateTime.TryParse(eventDetail.DetailValue, out dateTimeVal) == true)
                                                    {
                                                        eventDetail.DataType = "DateTime";
                                                    }
                                                    else
                                                    {
                                                        eventDetail.DataType = "String";
                                                    }
                                                }

                                                eventDetailsForThisEventList.Add(eventDetail);
                                            }
                                            @event.NumDetails = eventDetailsForThisEventList.Count;

                                            // Sort them
                                            eventDetailsForThisEventList = eventDetailsForThisEventList.OrderBy(o => o.DetailName).ToList();

                                            eventDetailsList.AddRange(eventDetailsForThisEventList);
                                        }
                                    }

                                    eventsList.Add(@event);
                                }
                            }
                        }

                        loggerConsole.Info("{0} Events", eventsList.Count);

                        stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + eventsList.Count;

                        // Sort them
                        eventsList = eventsList.OrderBy(o => o.Type).ThenBy(o => o.Occurred).ThenBy(o => o.Severity).ToList();
                        FileIOHelper.WriteListToCSVFile <Event>(eventsList, new EventReportMap(), FilePathMap.ApplicationEventsIndexFilePath(jobTarget));

                        FileIOHelper.WriteListToCSVFile <EventDetail>(eventDetailsList, new EventDetailReportMap(), FilePathMap.ApplicationEventDetailsIndexFilePath(jobTarget));

                        #endregion

                        #region Application

                        ApplicationEventSummary application = new ApplicationEventSummary();

                        application.Controller      = jobTarget.Controller;
                        application.ApplicationName = jobTarget.Application;
                        application.ApplicationID   = jobTarget.ApplicationID;
                        application.Type            = jobTarget.Type;

                        application.NumEvents        = eventsList.Count;
                        application.NumEventsError   = eventsList.Count(e => e.Severity == "ERROR");
                        application.NumEventsWarning = eventsList.Count(e => e.Severity == "WARN");
                        application.NumEventsInfo    = eventsList.Count(e => e.Severity == "INFO");

                        application.NumHRViolations         = healthRuleViolationList.Count;
                        application.NumHRViolationsCritical = healthRuleViolationList.Count(e => e.Severity == "CRITICAL");
                        application.NumHRViolationsWarning  = healthRuleViolationList.Count(e => e.Severity == "WARNING");

                        application.Duration = (int)(jobConfiguration.Input.TimeRange.To - jobConfiguration.Input.TimeRange.From).Duration().TotalMinutes;
                        application.From     = jobConfiguration.Input.TimeRange.From.ToLocalTime();
                        application.To       = jobConfiguration.Input.TimeRange.To.ToLocalTime();
                        application.FromUtc  = jobConfiguration.Input.TimeRange.From;
                        application.ToUtc    = jobConfiguration.Input.TimeRange.To;

                        // Determine what kind of entity we are dealing with and adjust accordingly
                        application.ControllerLink  = String.Format(DEEPLINK_CONTROLLER, application.Controller, DEEPLINK_THIS_TIMERANGE);
                        application.ApplicationLink = String.Format(DEEPLINK_APM_APPLICATION, application.Controller, application.ApplicationID, DEEPLINK_THIS_TIMERANGE);

                        if (application.NumEvents > 0 || application.NumHRViolations > 0)
                        {
                            application.HasActivity = true;
                        }

                        List <ApplicationEventSummary> applicationList = new List <ApplicationEventSummary>(1);
                        applicationList.Add(application);
                        FileIOHelper.WriteListToCSVFile(applicationList, new ApplicationEventSummaryReportMap(), FilePathMap.ApplicationEventsSummaryIndexFilePath(jobTarget));

                        #endregion

                        #region Combine All for Report CSV

                        // If it is the first one, clear out the combined folder
                        if (reportFolderCleaned == false)
                        {
                            FileIOHelper.DeleteFolder(FilePathMap.ApplicationEventsReportFolderPath());
                            Thread.Sleep(1000);
                            FileIOHelper.CreateFolder(FilePathMap.ApplicationEventsReportFolderPath());
                            reportFolderCleaned = true;
                        }

                        // Append all the individual report files into one
                        if (File.Exists(FilePathMap.ApplicationHealthRuleViolationsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ApplicationHealthRuleViolationsIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.ApplicationHealthRuleViolationsReportFilePath(), FilePathMap.ApplicationHealthRuleViolationsIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.ApplicationEventsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ApplicationEventsIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.ApplicationEventsReportFilePath(), FilePathMap.ApplicationEventsIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.ApplicationEventDetailsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ApplicationEventDetailsIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.ApplicationEventDetailsReportFilePath(), FilePathMap.ApplicationEventDetailsIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.ApplicationEventsSummaryIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ApplicationEventsSummaryIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.ApplicationEventsSummaryReportFilePath(), FilePathMap.ApplicationEventsSummaryIndexFilePath(jobTarget));
                        }

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(ex);
                        loggerConsole.Warn(ex);

                        return(false);
                    }
                    finally
                    {
                        stopWatchTarget.Stop();

                        this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget);

                        stepTimingTarget.EndTime    = DateTime.Now;
                        stepTimingTarget.Duration   = stopWatchTarget.Elapsed;
                        stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds;

                        List <StepTiming> stepTimings = new List <StepTiming>(1);
                        stepTimings.Add(stepTimingTarget);
                        FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                loggerConsole.Error(ex);

                return(false);
            }
            finally
            {
                stopWatch.Stop();

                this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch);

                stepTimingFunction.EndTime    = DateTime.Now;
                stepTimingFunction.Duration   = stopWatch.Elapsed;
                stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds;

                List <StepTiming> stepTimings = new List <StepTiming>(1);
                stepTimings.Add(stepTimingFunction);
                FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true);
            }
        }