public void TestInstallPerformanceCounters()
		{
			ProgramOptions options = new ProgramOptions();
			Assert.IsFalse(options.InstallPerformanceCounters);
			options.ProcessArgs(new string[] { "--install-performance-counters"});
			Assert.IsTrue(options.InstallPerformanceCounters);
		}
	    private static void AssertTransparentPersistence(string arg)
		{
			ProgramOptions options = new ProgramOptions();
			Assert.IsFalse(options.TransparentPersistence);
			options.ProcessArgs(new string[] { arg });
			Assert.IsTrue(options.TransparentPersistence);
		}
Пример #3
0
        private static Aes CreateAesForServer(ProgramOptions options, BinaryReader reader, BinaryWriter writer)
        {
            if (!options.Encrypt) return null;

            using (var ke = new ECDiffieHellmanCng())
            {
                // expecting client's public key

                var len = reader.ReadInt32();
                byte[] key;

                using (var remotePubKey = CngKey.Import(reader.ReadBytes(len), CngKeyBlobFormat.EccPublicBlob))
                    key = ke.DeriveKeyMaterial(remotePubKey);

                var aes = new AesCryptoServiceProvider();
                using (var kdf = new Rfc2898DeriveBytes(key, Salt.ToArray(), KdfIterations))
                    aes.Key = kdf.GetBytes(aes.KeySize / 8);

                // send pub key and IV to client
                var localPubKey = ke.PublicKey.ToByteArray();
                writer.Write(localPubKey.Length);
                writer.Write(localPubKey);
                writer.Write(aes.IV.Length);
                writer.Write(aes.IV);

                return aes;
            }
        }
Пример #4
0
        private static Aes CreateAes(ProgramOptions options, byte[] iv = null)
        {
            if (!options.EncryptionEnabled)
                return null;

            var salt = Convert.FromBase64String("hkuDTnecxj+oDytliJ69BQ==");
            using (var kdf = new Rfc2898DeriveBytes(options.EncryptionPassword, salt))
            {
                var aes = new AesCryptoServiceProvider();
                var keyLen = aes.KeySize/8;

                if (iv != null)
                {
                    aes.Key = kdf.GetBytes(keyLen);
                    aes.IV = iv;
                    return aes;
                }

                var ivLength = aes.BlockSize/8;
                var bytes = kdf.GetBytes(keyLen + ivLength);
                aes.Key = bytes.SubArray(0, keyLen);
                aes.IV = bytes.SubArray(keyLen, ivLength);
                return aes;
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            try
            {
                var cmdLine = new ProgramOptions(args);

                var fileName = cmdLine.Output;
                bool isConsoleOutput = String.IsNullOrEmpty(fileName);

                if (!isConsoleOutput)
                {
                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }
                }

                var graphGenerator = new EngineRandomGraphGenerator();
                var randomGraph = graphGenerator.Generate(Guid.NewGuid().ToString());

                var writer = isConsoleOutput ? Console.Out : File.CreateText(fileName);
                var formatWriter = GraphFormatWriterFactory.Create(cmdLine.Format);

                formatWriter.Write(randomGraph, writer);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception:\n{0}", ex);
            }
        }
Пример #6
0
        private static int Main(string[] args)
        {
            try
            {
                ConsoleBrush defaultBrush = ConsoleBrush.Current;

                try
                {
                    ProgramOptions options = new ProgramOptions();
                    options.Help += delegate { Help(); Environment.Exit(0); };
                    options.Palette = JsonPalette.Auto(defaultBrush);
                    args = options.Parse(args);

                    string path = args.Length > 0 ? args[0] : "-";
                    PrettyColorPrint(path, Console.Out, options.Palette);

                    return 0;
                }
                finally
                {
                    defaultBrush.Apply();
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.GetBaseException().Message);
                Trace.WriteLine(e.ToString());
                return -1;
            }
        }
		private static ProgramOptions ProgramOptionsFor(string assemblyPath)
		{
			ProgramOptions po = new ProgramOptions();
			po.ProcessArgs(new string[] {"-ta", assemblyPath,});

			return po;
		}
Пример #8
0
        public void VersionBadFormat()
        {
            var options = new ProgramOptions() { FileName = @"NonExistingFile.c42", };
            options.Variables.Add("Version", "a1b2c3e4f5g6h7i8j9k0");

            ProjectInfo.Open(options);
        }
Пример #9
0
        private static int Main(string[] args)
        {
            try
            {
                var defaultBrush = ConsoleBrush.Current;

                var options = new ProgramOptions();
                options.Help += delegate { Help(); Environment.Exit(0); };
                options.Palette = JsonPalette.Auto(defaultBrush);
                args = options.Parse(args);
                
                var path = args.Length > 0 ? args[0] : "-";

                try
                {
                    try
                    {
                        PrettyColorPrint(path, Console.Out, options.Palette);
                    }
                    finally
                    {
                        //
                        // The location of this finally clause is significant
                        // and should not be merged with the outer catch
                        // block. The default brush needs to be restored
                        // in case an error message is about to be printed 
                        // and the standard output and error point to the 
                        // same console device.
                        //

                        defaultBrush.Apply();
                    }
                }
                catch (JsonException e)
                {
                    //
                    // In case of JsonException, we don't display the
                    // base exception since the root cause would not provide
                    // line and position information and which JsonException
                    // does. For example, "Unterminated string" has the
                    // root case of FormatException, but which bubble as
                    // JsonException with line and position about where the
                    // error was found in the source.
                    //

                    Console.Error.WriteLine(e.Message);
                    Trace.WriteLine(e.ToString());
                    return 2;
                }

                return 0;
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.GetBaseException().Message);
                Trace.WriteLine(e.ToString());
                return 1;
            }
        }
Пример #10
0
        public static void Run(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            ProgramOptions options = new ProgramOptions();

            string settingPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Oxel.Settings.xml");
            VoxelizationInput input = VoxelizationInput.Load(settingPath);
            if (input == null)
                input = new VoxelizationInput();

            if (args.Contains("-c"))
            {
                // Make sure user can see console output
                AttachConsole(PARENT_PROCESS_ID);

                input.Clone(options);

                if (!CommandLineParser.Parse<ProgramOptions>(args, ref options))
                    return;

                options.Clone(input);
            }
            else
            {
                CommandLineParser.Parse<VoxelizationInput>(args, ref input);
            }

            if (options.UseCommandLine)
            {
                Logger.IsCommandLine = true;

                Operations operations = new Operations();
                operations.Initialize(input);
                operations.Open(options.InputMesh, input.WindingOrder);
                WaitHandle waitHandle = operations.GenerateOccluder((VoxelizationProgress vp) => {
                    string coverage =
                        String.Format("Volume Coverage     : {0,5:0.##}%", (100 * vp.VolumeCoverage)) + "    " +
                        String.Format("Silhouette Coverage : {0,5:0.##}%", (100 * vp.SilhouetteCoverage));

                    if (!String.IsNullOrEmpty(vp.Status))
                        Console.WriteLine(vp.Status + "\r\n");

                    Console.WriteLine(coverage);
                }, new Action(() => { }));
                waitHandle.WaitOne();
                operations.Save(options.OutputMesh);
            }
            else
            {
                using (MainWindow window = new MainWindow(input))
                {
                    window.ShowDialog();
                }
            }
        }
Пример #11
0
        public void SetProjectVersion()
        {
            var options = new ProgramOptions() { FileName = @"NonExistingFile.c42", };
            options.Variables.Add("Version", "1.2.3.4");

            var projectInfo = ProjectInfo.Open(options);

            Assert.AreEqual(new Version(1, 2, 3, 4), projectInfo.ProjectVersion);
        }
Пример #12
0
        public void SysVariablesIsNotOverwrittenByUserVariable()
        {
            var options = new ProgramOptions() { FileName = @"NonExistingFile.c42", };
            options.Variables.Add("Version", "v2.1.3.0-14-ged5ff9d");

            var projectInfo = ProjectInfo.Open(options);
            var actual = projectInfo.ParseVariables(null, "$(Version)");
            Assert.AreEqual("2.1.3.0", actual);
        }
Пример #13
0
        public void VersionDoesNotSetReleaseName()
        {
            var options = new ProgramOptions() { FileName = @"NonExistingFile.c42", };
            options.Variables.Add("Version", "v1.2.3.4-5-abc");

            var projectInfo = ProjectInfo.Open(options);

            Assert.AreEqual(new Version(1, 2, 3, 4), projectInfo.ProjectVersion);
            Assert.AreEqual(null, projectInfo.ReleaseName);
        }
        public void DefinitiveOutputFileWithOutputFileIsNotNullReturnsOutputFile()
        {
            // Arrange
            var programOptions = new ProgramOptions();
            programOptions.OutputFile = @"c:\gladiator.jpg";

            // Act

            // Assert
            Assert.Equal(programOptions.OutputFile, programOptions.DefinitiveOutputFile);
        }
Пример #15
0
        public void VariableCreated()
        {
            var options = new ProgramOptions() { FileName = @"NonExistingFile.c42", };
            options.Variables.Add("Foo", "bar");

            var projectInfo = ProjectInfo.Open(options);

            Assert.AreEqual(
                "bar",
                projectInfo.GlobalUserVariables.Where(v => v.Key == "Foo").Select(v => v.Value.Value).FirstOrDefault());
        }
        public void DefinitiveOutputFileWithOutputFileIsNullReturnsInputFileWithAppendedBackdropName()
        {
            // Arrange
            var programOptions = new ProgramOptions();
            programOptions.OutputFile = null;
            programOptions.InputFile = @"c:\gladiator.jpg";

            // Act

            // Assert
            Assert.Equal(@"c:\gladiator-backdrop.jpg", programOptions.DefinitiveOutputFile);
        }
Пример #17
0
        static byte[] ClientHandshake(Stream stream, ProgramOptions options)
        {
            if (!options.EncryptionEnabled) return null;

            using (var aes = new AesCryptoServiceProvider())
            {
                // we are expecting the IV very first thing

                var iv = new byte[aes.BlockSize/8];
                var read = stream.Read(iv, 0, iv.Length);

                if (read != iv.Length)
                    throw new ApplicationException("Didn't get enough bytes for handshake.");

                return iv;
            }
        }
		public void Test()
		{
			if (!IsCurrentUserAnAdministrator() && IsLenientPerformanceCounterInstallTest())
			{
				Console.Error.WriteLine("WARNING: {0} requires administrator access rights to run.", GetType());
				return;
			}

			if (Db4oCategoryExists())
			{
				PerformanceCounterCategory.Delete(Db4oPerformanceCounters.CategoryName);
			}

			ProgramOptions options = new ProgramOptions();
			options.InstallPerformanceCounters = true;

			Db4oTool.Program.Run(options);

			Assert.IsTrue(Db4oCategoryExists());
		}
        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_DB) == 0)
                {
                    return(true);
                }

                #region Template comparisons

                if (jobConfiguration.Input.ConfigurationComparisonReferenceDB.Controller == BLANK_APPLICATION_CONTROLLER &&
                    jobConfiguration.Input.ConfigurationComparisonReferenceDB.Application == BLANK_APPLICATION_DB)
                {
                    jobConfiguration.Target.Add(jobConfiguration.Input.ConfigurationComparisonReferenceDB);
                }
                else
                {
                    // Check if there is a valid reference application
                    JobTarget jobTargetReferenceApp = jobConfiguration.Target.Where(t =>
                                                                                    t.Type == APPLICATION_TYPE_DB &&
                                                                                    String.Compare(t.Controller, jobConfiguration.Input.ConfigurationComparisonReferenceDB.Controller, StringComparison.InvariantCultureIgnoreCase) == 0 &&
                                                                                    String.Compare(t.Application, jobConfiguration.Input.ConfigurationComparisonReferenceDB.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.ConfigurationComparisonReferenceDB);
                        loggerConsole.Warn("Unable to find reference target {0}, will index default template", jobConfiguration.Input.ConfigurationComparisonReferenceDB);

                        jobConfiguration.Input.ConfigurationComparisonReferenceDB.Controller  = BLANK_APPLICATION_CONTROLLER;
                        jobConfiguration.Input.ConfigurationComparisonReferenceDB.Application = BLANK_APPLICATION_DB;
                        jobConfiguration.Input.ConfigurationComparisonReferenceDB.Type        = APPLICATION_TYPE_DB;

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

                #endregion

                bool reportFolderCleaned = false;

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

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

                    if (jobTarget.Type != null && jobTarget.Type.Length > 0 && jobTarget.Type != APPLICATION_TYPE_DB)
                    {
                        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 Database Collector Definitions

                        List <DBCollectorDefinition> dbCollectorDefinitionsList = null;

                        JArray dbCollectorDefinitionsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.DBCollectorDefinitionsDataFilePath(jobTarget));
                        if (dbCollectorDefinitionsArray != null)
                        {
                            loggerConsole.Info("Index List of DB Collector Definitions ({0} entities)", dbCollectorDefinitionsArray.Count);

                            dbCollectorDefinitionsList = new List <DBCollectorDefinition>(dbCollectorDefinitionsArray.Count);

                            foreach (JToken dbCollectorDefinitionToken in dbCollectorDefinitionsArray)
                            {
                                if (isTokenPropertyNull(dbCollectorDefinitionToken, "config") == false)
                                {
                                    JToken dbCollectorDefinitionConfigToken = dbCollectorDefinitionToken["config"];

                                    DBCollectorDefinition dbCollectorDefinition = new DBCollectorDefinition();
                                    dbCollectorDefinition.Controller      = jobTarget.Controller;
                                    dbCollectorDefinition.CollectorName   = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "name");
                                    dbCollectorDefinition.CollectorType   = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "type");
                                    dbCollectorDefinition.CollectorStatus = getStringValueFromJToken(dbCollectorDefinitionToken, "collectorStatus");

                                    dbCollectorDefinition.AgentName = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "agentName");

                                    dbCollectorDefinition.Host     = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "hostname");
                                    dbCollectorDefinition.Port     = getIntValueFromJToken(dbCollectorDefinitionConfigToken, "port");
                                    dbCollectorDefinition.UserName = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "username");

                                    dbCollectorDefinition.IsEnabled        = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "enabled");
                                    dbCollectorDefinition.IsLoggingEnabled = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "loggingEnabled");

                                    dbCollectorDefinition.DatabaseName           = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "databaseName");
                                    dbCollectorDefinition.FailoverPartner        = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "failoverPartner");
                                    dbCollectorDefinition.SID                    = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "sid");
                                    dbCollectorDefinition.CustomConnectionString = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "customConnectionString");

                                    dbCollectorDefinition.UseWindowsAuth  = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "useWindowsAuth");
                                    dbCollectorDefinition.ConnectAsSysDBA = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "connectAsSysdba");
                                    dbCollectorDefinition.UseServiceName  = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "useServiceName");
                                    dbCollectorDefinition.UseSSL          = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "useSSL");

                                    dbCollectorDefinition.IsEnterpriseDB = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "enterpriseDB");

                                    dbCollectorDefinition.IsOSMonitoringEnabled = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "enableOSMonitor");
                                    dbCollectorDefinition.UseLocalWMI           = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "useLocalWMI");

                                    dbCollectorDefinition.HostOS             = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "hostOS");
                                    dbCollectorDefinition.HostDomain         = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "hostDomain");
                                    dbCollectorDefinition.HostUserName       = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "hostUsername");
                                    dbCollectorDefinition.UseCertificateAuth = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "certificateAuth");
                                    dbCollectorDefinition.SSHPort            = getIntValueFromJToken(dbCollectorDefinitionConfigToken, "sshPort");
                                    dbCollectorDefinition.DBInstanceID       = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "dbInstanceIdentifier");
                                    dbCollectorDefinition.Region             = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "region");
                                    dbCollectorDefinition.RemoveLiterals     = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "removeLiterals");
                                    dbCollectorDefinition.IsLDAPEnabled      = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "ldapEnabled");

                                    dbCollectorDefinition.CreatedBy  = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "createdBy");
                                    dbCollectorDefinition.CreatedOn  = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(dbCollectorDefinitionConfigToken, "createdOn"));
                                    dbCollectorDefinition.ModifiedBy = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "modifiedBy");
                                    dbCollectorDefinition.ModifiedOn = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(dbCollectorDefinitionConfigToken, "modifiedOn"));

                                    dbCollectorDefinition.ConfigID = getLongValueFromJToken(dbCollectorDefinitionToken, "configId");

                                    dbCollectorDefinition.ControllerLink  = String.Format(DEEPLINK_CONTROLLER, dbCollectorDefinition.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES);
                                    dbCollectorDefinition.ApplicationLink = String.Format(DEEPLINK_DB_APPLICATION, dbCollectorDefinition.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES);

                                    dbCollectorDefinitionsList.Add(dbCollectorDefinition);
                                }
                            }

                            // Sort them
                            dbCollectorDefinitionsList = dbCollectorDefinitionsList.OrderBy(o => o.CollectorType).ThenBy(o => o.CollectorName).ToList();
                            FileIOHelper.WriteListToCSVFile(dbCollectorDefinitionsList, new DBCollectorDefinitionReportMap(), FilePathMap.DBCollectorDefinitionsIndexFilePath(jobTarget));

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

                        #endregion

                        #region Custom Metrics

                        List <DBCustomMetric> dbCustomMetricsList = null;

                        JArray dbCustomMetricsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.DBCustomMetricsDataFilePath(jobTarget));
                        if (dbCustomMetricsArray != null)
                        {
                            loggerConsole.Info("Index List of DB Custom Metrics ({0} entities)", dbCustomMetricsArray.Count);

                            dbCustomMetricsList = new List <DBCustomMetric>(dbCustomMetricsArray.Count);

                            foreach (JObject dbCustomMetricObject in dbCustomMetricsArray)
                            {
                                DBCustomMetric dbCustomMetric = new DBCustomMetric();

                                dbCustomMetric.Controller = jobTarget.Controller;

                                dbCustomMetric.MetricName = getStringValueFromJToken(dbCustomMetricObject, "name");
                                dbCustomMetric.MetricID   = getLongValueFromJToken(dbCustomMetricObject, "id");

                                dbCustomMetric.Frequency = getIntValueFromJToken(dbCustomMetricObject, "timeIntervalInMin");

                                dbCustomMetric.IsEvent = getBoolValueFromJToken(dbCustomMetricObject, "isEvent");

                                dbCustomMetric.Query = getStringValueFromJToken(dbCustomMetricObject, "queryText");

                                // Get SQL statement type
                                dbCustomMetric.SQLClauseType = getSQLClauseType(dbCustomMetric.Query, 100);

                                // Check other clauses
                                dbCustomMetric.SQLWhere   = doesSQLStatementContain(dbCustomMetric.Query, @"\bWHERE\s");
                                dbCustomMetric.SQLGroupBy = doesSQLStatementContain(dbCustomMetric.Query, @"\bGROUP BY\s");
                                dbCustomMetric.SQLOrderBy = doesSQLStatementContain(dbCustomMetric.Query, @"\bORDER BY\s");
                                dbCustomMetric.SQLHaving  = doesSQLStatementContain(dbCustomMetric.Query, @"\bHAVING\s");
                                dbCustomMetric.SQLUnion   = doesSQLStatementContain(dbCustomMetric.Query, @"\bUNION\s");

                                // Get join type if present
                                dbCustomMetric.SQLJoinType = getSQLJoinType(dbCustomMetric.Query);

                                // Now lookup the collector assigned
                                if (dbCollectorDefinitionsList != null)
                                {
                                    if (isTokenPropertyNull(dbCustomMetricObject, "dbaemc") == false)
                                    {
                                        if (isTokenPropertyNull(dbCustomMetricObject["dbaemc"], "dbServerIds") == false)
                                        {
                                            JValue configIDValue = null;
                                            try { configIDValue = (JValue)dbCustomMetricObject["dbaemc"]["dbServerIds"].First(); } catch { }
                                            if (configIDValue != null)
                                            {
                                                long configID = (long)configIDValue;

                                                DBCollectorDefinition dbCollectorDefinition = dbCollectorDefinitionsList.Where(d => d.ConfigID == configID).FirstOrDefault();
                                                if (dbCollectorDefinition != null)
                                                {
                                                    dbCustomMetric.CollectorName = dbCollectorDefinition.CollectorName;
                                                    dbCustomMetric.CollectorType = dbCollectorDefinition.CollectorType;

                                                    dbCustomMetric.ConfigID = dbCollectorDefinition.ConfigID;
                                                }
                                            }
                                        }
                                    }
                                }

                                dbCustomMetricsList.Add(dbCustomMetric);
                            }

                            // Sort them
                            dbCustomMetricsList = dbCustomMetricsList.OrderBy(o => o.CollectorType).ThenBy(o => o.CollectorName).ToList();
                            FileIOHelper.WriteListToCSVFile(dbCustomMetricsList, new DBCustomMetricReportMap(), FilePathMap.DBCustomMetricsIndexFilePath(jobTarget));

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

                        #endregion

                        #region Application

                        loggerConsole.Info("Index Application");

                        stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + 1;

                        DBApplicationConfiguration applicationConfiguration = new DBApplicationConfiguration();
                        applicationConfiguration.Controller      = jobTarget.Controller;
                        applicationConfiguration.ControllerLink  = String.Format(DEEPLINK_CONTROLLER, applicationConfiguration.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES);
                        applicationConfiguration.ApplicationName = jobTarget.Application;
                        applicationConfiguration.ApplicationLink = String.Format(DEEPLINK_DB_APPLICATION, applicationConfiguration.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES);
                        applicationConfiguration.ApplicationID   = jobTarget.ApplicationID;

                        if (dbCollectorDefinitionsList != null)
                        {
                            applicationConfiguration.NumCollectorDefinitions = dbCollectorDefinitionsList.Count;
                        }

                        if (dbCustomMetricsList != null)
                        {
                            applicationConfiguration.NumCustomMetrics = dbCustomMetricsList.Count;
                        }

                        List <DBApplicationConfiguration> applicationConfigurationsList = new List <DBApplicationConfiguration>(1);
                        applicationConfigurationsList.Add(applicationConfiguration);

                        FileIOHelper.WriteListToCSVFile(applicationConfigurationsList, new DBApplicationConfigurationReportMap(), FilePathMap.DBApplicationConfigurationIndexFilePath(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.DBConfigurationReportFolderPath());
                            Thread.Sleep(1000);
                            FileIOHelper.CreateFolder(FilePathMap.DBConfigurationReportFolderPath());
                            reportFolderCleaned = true;
                        }

                        // Append all the individual report files into one
                        if (File.Exists(FilePathMap.DBCollectorDefinitionsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.DBCollectorDefinitionsIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.DBCollectorDefinitionsReportFilePath(), FilePathMap.DBCollectorDefinitionsIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.DBCustomMetricsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.DBCustomMetricsIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.DBCustomMetricsReportFilePath(), FilePathMap.DBCustomMetricsIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.DBApplicationConfigurationIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.DBApplicationConfigurationIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.DBApplicationConfigurationReportFilePath(), FilePathMap.DBApplicationConfigurationIndexFilePath(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++;
                }

                // 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);
            }
        }
Пример #20
0
 public Display(ProgramOptions options, int port)
 {
     _port = port;
     Options = options;
 }
Пример #21
0
        /// <summary>
        /// parse command line arguments and open forms</summary>
        public Main()
        {
            // inicialize program
            options = new ProgramOptions();
            optionsFile = new OptionsFile(options);

            // create local server for comunication between local instances
            server = new Server(this);

            Program.log.write("Program: Main");

            #if DEBUG
            Program.log.write("program: debug mode");
            #else
            Program.log.write("program: release mode");
            #endif

            // TODO: Load global options file and save it when application is closed
            // load options
            // options.loadOptions();

            // get command line arguments
            this.args = Environment.GetCommandLineArgs();
            #if DEBUG
            // custom debug arguments
            if (this.args.Length == 1 && Os.FileExists("test.diagram")) // if not argument is added from system ad some testing arguments
            {
                // comand line arguments testing
                this.args = new string[] {
                    System.Reflection.Assembly.GetExecutingAssembly().Location
                    ,"test.diagram"
                };
            }
            #endif
            // process comand line arguments
            this.ParseCommandLineArguments(this.args);

            #if !MONO
            SystemEvents.PowerModeChanged += OnPowerChange;
            #endif

            // check if this program instance created server
            if (server.mainProcess)
            {
                this.mainform = new MainForm(this);
            }
        }
Пример #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);

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

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

                    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_WEB)
                    {
                        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 = 3;

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

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

                            #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 EUM Pages

                            loggerConsole.Info("Pages and AJAX Requests");

                            string pagesJSON = controllerApi.GetWEBPages(jobTarget.ApplicationID, fromTimeUnix, toTimeUnix);
                            if (pagesJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(pagesJSON, FilePathMap.WEBPagesDataFilePath(jobTarget));
                            }

                            #endregion

                            #region EUM Pages Performance

                            if (pagesJSON != String.Empty)
                            {
                                JObject pagesListContainer = JObject.Parse(pagesJSON);

                                if (isTokenPropertyNull(pagesListContainer, "data") == false)
                                {
                                    JArray pagesArray = (JArray)pagesListContainer["data"];

                                    loggerConsole.Info("Performance of Pages and Ajax Requests ({0}) entities", pagesArray.Count);

                                    int j = 0;

                                    var listOfPagesChunks = pagesArray.BreakListIntoChunks(ENTITIES_EXTRACT_NUMBER_OF_PAGES_TO_PROCESS_PER_THREAD);

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

                                    Parallel.ForEach <List <JToken>, int>(
                                        listOfPagesChunks,
                                        parallelOptions,
                                        () => 0,
                                        (listOfPagesChunk, loop, subtotal) =>
                                    {
                                        // Set up controller access
                                        using (ControllerApi controllerApiParallel = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword)))
                                        {
                                            controllerApiParallel.PrivateApiLogin();

                                            foreach (JToken pageToken in listOfPagesChunk)
                                            {
                                                string pageName = getStringValueFromJToken(pageToken, "name");
                                                string pageType = getStringValueFromJToken(pageToken, "type");
                                                long pageID     = getLongValueFromJToken(pageToken, "addId");

                                                if (File.Exists(FilePathMap.WEBPagePerformanceDataFilePath(jobTarget, pageType, pageName, pageID, jobConfiguration.Input.TimeRange)) == false)
                                                {
                                                    string pageJSON = controllerApi.GetWEBPagePerformance(jobTarget.ApplicationID, pageID, fromTimeUnix, toTimeUnix, differenceInMinutes);
                                                    if (pageJSON != String.Empty)
                                                    {
                                                        FileIOHelper.SaveFileToPath(pageJSON, FilePathMap.WEBPagePerformanceDataFilePath(jobTarget, pageType, pageName, pageID, jobConfiguration.Input.TimeRange));
                                                    }
                                                }
                                            }
                                            return(listOfPagesChunk.Count);
                                        }
                                    },
                                        (finalResult) =>
                                    {
                                        Interlocked.Add(ref j, finalResult);
                                        Console.Write("[{0}].", j);
                                    }
                                        );

                                    loggerConsole.Info("Completed {0} Pages", pagesArray.Count);
                                }
                            }

                            #endregion

                            #region Geo Regions

                            loggerConsole.Info("Geo Locations");

                            string geoRegionsJSON = controllerApi.GetWEBGeoRegions(jobTarget.ApplicationID, String.Empty, String.Empty, String.Empty, fromTimeUnix, toTimeUnix, differenceInMinutes);
                            if (geoRegionsJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(geoRegionsJSON, FilePathMap.WEBGeoLocationsDataFilePath(jobTarget, "all"));
                            }

                            if (geoRegionsJSON != String.Empty)
                            {
                                JObject geoRegionsContainerObject = JObject.Parse(geoRegionsJSON);
                                if (geoRegionsContainerObject != null)
                                {
                                    if (isTokenPropertyNull(geoRegionsContainerObject, "rumItems") == false)
                                    {
                                        int    j = 0;
                                        JArray geoRegionsArray = (JArray)geoRegionsContainerObject["rumItems"];
                                        foreach (JObject geoRegionObject in geoRegionsArray)
                                        {
                                            if (isTokenPropertyNull(geoRegionObject, "eumRegionPerformanceSummaryData") == false)
                                            {
                                                string country = getStringValueFromJToken(geoRegionObject["eumRegionPerformanceSummaryData"], "country");

                                                string geoRegionJSON = controllerApi.GetWEBGeoRegions(jobTarget.ApplicationID, country, String.Empty, String.Empty, fromTimeUnix, toTimeUnix, differenceInMinutes);
                                                if (geoRegionJSON != String.Empty)
                                                {
                                                    FileIOHelper.SaveFileToPath(geoRegionJSON, FilePathMap.WEBGeoLocationsDataFilePath(jobTarget, country));
                                                }
                                            }

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

                                        loggerConsole.Info("Completed {0} Geo Locations and Regions", j);
                                    }
                                }
                            }

                            #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);
            }
        }
Пример #23
0
        /// <summary>
        /// Sets a new regular expression program to run.  It is this method which
        /// performs any special compile-time search optimizations.  Currently only
        /// two optimizations are in place - one which checks for backreferences
        /// (so that they can be lazily allocated) and another which attempts to
        /// find an prefix anchor string so that substantial amounts of input can
        /// potentially be skipped without running the actual program.
        /// </summary>
        /// <param name="instruction">Program instruction buffer</param>
        /// <param name="lenInstruction">Length of instruction buffer in use</param>
        void setInstructions(char[] instruction, int lenInstruction)
        {
            // Save reference to instruction array
            this.instruction = instruction;
            this.lenInstruction = lenInstruction;

            // Initialize other program-related variables
            this.flags = 0;
            this.prefix = null;

            // Try various compile-time optimizations if there's a program
            if (instruction != null && lenInstruction != 0)
            {
                // If the first node is a branch
                if (lenInstruction >= Regex.nodeSize && instruction[0 + Regex.offsetOpcode] == OpCode.Branch)
                {
                    // to the end node
                    int next = (short)instruction[0 + Regex.offsetNext];
                    if (instruction[next + Regex.offsetOpcode] == OpCode.EndProgram && lenInstruction >= (Regex.nodeSize * 2))
                    {
                        char nextOp = instruction[Regex.nodeSize + Regex.offsetOpcode];
                        // the branch starts with an atom
                        if (nextOp == OpCode.Atom)
                        {
                            // then get that atom as an prefix because there's no other choice
                            int lenAtom = instruction[Regex.nodeSize + Regex.offsetOpdata];
                            this.prefix = new char[lenAtom];
                            System.Array.Copy(instruction, Regex.nodeSize * 2, prefix, 0, lenAtom);
                        }
                        // the branch starts with a BOL
                        else if (nextOp == OpCode.BeginOfLine)
                        {
                            // then set the flag indicating that BOL is present
                            this.flags |= ProgramOptions.HasBeginOfLine;
                        }
                    }
                }

                // Check for backreferences
                for (int i = 0; i < lenInstruction; i += Regex.nodeSize)
                {
                    switch (instruction[i + Regex.offsetOpcode])
                    {
                        case OpCode.AnyOf:
                            i += (instruction[i + Regex.offsetOpdata] * 2);
                            break;

                        case OpCode.Atom:
                            i += instruction[i + Regex.offsetOpdata];
                            break;

                        case OpCode.BackRef:
                            flags |= ProgramOptions.HasBackrefrence;
                            return;
                    }
                }

            }
        }
Пример #24
0
 public RandomService(ProgramOptions options)
 {
     this.log = LogManager.GetLogger(typeof(RandomService));
     this.options = options;
 }
        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);
                }

                // 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 = 5;

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

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

                            #region Security Provider Type

                            loggerConsole.Info("Security Configuration");

                            string securityProviderTypeJSON = controllerApi.GetSecurityProviderType();
                            if (securityProviderTypeJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(securityProviderTypeJSON, FilePathMap.SecurityProviderTypeDataFilePath(jobTarget));
                            }

                            string requireStrongPasswordsJSON = controllerApi.GetRequireStrongPasswords();
                            if (requireStrongPasswordsJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(requireStrongPasswordsJSON, FilePathMap.StrongPasswordsDataFilePath(jobTarget));
                            }

                            #endregion

                            #region Users

                            loggerConsole.Info("Users");

                            // Users
                            string usersJSON = controllerApi.GetUsersExtended();
                            if (usersJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(usersJSON, FilePathMap.UsersDataFilePath(jobTarget));
                            }

                            #endregion

                            #region Groups

                            loggerConsole.Info("Groups");

                            // Groups
                            string groupsJSON = controllerApi.GetGroupsExtended();
                            if (groupsJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(groupsJSON, FilePathMap.GroupsDataFilePath(jobTarget));
                            }

                            #endregion

                            #region Roles

                            loggerConsole.Info("Roles");

                            // Roles
                            string rolesJSON = controllerApi.GetRolesExtended();
                            if (rolesJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(rolesJSON, FilePathMap.RolesDataFilePath(jobTarget));
                            }

                            #endregion

                            #region User Details

                            JArray usersArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.UsersDataFilePath(jobTarget));
                            if (usersArray != null)
                            {
                                loggerConsole.Info("User Details ({0} entities)", usersArray.Count);

                                int j = 0;

                                foreach (JObject userObject in usersArray)
                                {
                                    string userJSON = controllerApi.GetUserExtended((long)userObject["id"]);
                                    if (userJSON != String.Empty)
                                    {
                                        FileIOHelper.SaveFileToPath(userJSON, FilePathMap.UserDataFilePath(jobTarget, userObject["name"].ToString(), (long)userObject["id"]));
                                    }

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

                                loggerConsole.Info("Completed {0} Users", usersArray.Count);

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

                            #endregion

                            #region Group Details

                            JArray groupsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.GroupsDataFilePath(jobTarget));
                            if (groupsArray != null)
                            {
                                loggerConsole.Info("Group Details and Members ({0} entities)", groupsArray.Count);

                                int j = 0;

                                foreach (JObject groupObject in groupsArray)
                                {
                                    string groupJSON = controllerApi.GetGroupExtended((long)groupObject["id"]);
                                    if (groupJSON != String.Empty)
                                    {
                                        FileIOHelper.SaveFileToPath(groupJSON, FilePathMap.GroupDataFilePath(jobTarget, groupObject["name"].ToString(), (long)groupObject["id"]));
                                    }

                                    string usersInGroupJSON = controllerApi.GetUsersInGroup((long)groupObject["id"]);
                                    if (usersInGroupJSON != String.Empty)
                                    {
                                        FileIOHelper.SaveFileToPath(usersInGroupJSON, FilePathMap.GroupUsersDataFilePath(jobTarget, groupObject["name"].ToString(), (long)groupObject["id"]));
                                    }

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

                                loggerConsole.Info("Completed {0} Groups", groupsArray.Count);

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

                            #endregion

                            #region Role Details

                            JArray rolesArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.RolesDataFilePath(jobTarget));
                            if (rolesArray != null)
                            {
                                loggerConsole.Info("Role Details ({0} entities)", rolesArray.Count);

                                int j = 0;

                                foreach (JObject roleObject in rolesArray)
                                {
                                    string roleJSON = controllerApi.GetRoleExtended((long)roleObject["id"]);
                                    if (roleJSON != String.Empty)
                                    {
                                        FileIOHelper.SaveFileToPath(roleJSON, FilePathMap.RoleDataFilePath(jobTarget, roleObject["name"].ToString(), (long)roleObject["id"]));
                                    }

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

                                loggerConsole.Info("Completed {0} Roles", rolesArray.Count);

                                stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + rolesArray.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);
                    }

                    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);
            }
        }
Пример #26
0
        private static void Main(string[] args)
        {
            ProgramOptions options = new ProgramOptions();

            // Parse command line options any errors and you get Usage
            if (options.ParseArgs(args) == false) ProgramOptions.Usage();

            // We must have at least 1 path to process files, else Usage and exit
            if (options.PathList.Count < 1) ProgramOptions.Usage("You must specify at least one TVShowFolder.");

            List<String> validPaths = new List<string>();

            foreach (string p in options.PathList)
            {
                Console.WriteLine("Processing: {0}", p);

                TVShowFolder f = new TVShowFolder(p);

                if (f.IsValid)
                {
                    validPaths.Add(p);
                }
                else
                {
                    Console.WriteLine("INGNORED! NOT A VALID PATH: {0}", p);
                }
            }

            // Read program options from the App.Config
            AppConfigOptions AppConfig = new AppConfigOptions();

            // Setup new search object
            TVSearcher tvSearcher = new TVSearcher(AppConfig.ApiKey);

            foreach (string p in validPaths)
            {
                int TotalEpisodes = 0;
                int RenamedEpisodes = 0;
                int ErrorsEpisodes = 0;

                TVShowFolder myShow = new TVShowFolder(p);

                if (myShow.HasError())
                {
                    Console.WriteLine("Error parsing show name: {0}", myShow.ErrorMessage);
                    continue;
                }

                Console.WriteLine("Looking for show: {0}", myShow.ShowName);

                string outputFile = String.Empty;

                if (String.IsNullOrEmpty(options.OutputPath))
                {
                    outputFile = Platform.IsWindows()
                                     ? Path.Combine(myShow.Location, ".rename.bat")
                                     : Path.Combine(myShow.Location, ".rename.sh");
                }
                else
                {
                    outputFile = Path.Combine(options.OutputPath,
                                              Path.ChangeExtension(myShow.ShowName, Platform.IsWindows() ? "bat" : "sh"));
                }

                TextWriter tw = new StreamWriter(outputFile);

                string showID;

                if (myShow.HasAssignedID)
                {
                    showID = myShow.AssignedID;
                    Console.WriteLine("Has Assigned ID: {0}", showID);
                }
                else
                {
                    TVSeries tvSearch = new TVSeries();

                    tvSearch = tvSearcher.GetSeries(myShow.ShowName);

                    if (tvSearch.IsSearchResult())
                    {
                        foreach (DataSeries s in tvSearch.Shows)
                        {
                            Console.WriteLine("Located: {0} {1} {2}", s.id, s.FirstAired, s.SeriesName);
                        }
                    }

                    if (tvSearch.Shows.Count > 1)
                    {
                        Console.WriteLine("Ambigious search for: {0}", myShow.ShowName);
                        Console.WriteLine("Create a .thetvdb.id file wiht the show ID as the 1st line.");
                        continue;
                    }

                    if (tvSearch.Shows.Count == 0)
                    {
                        Console.WriteLine("Unable to locate: {0}", myShow.ShowName);
                        continue;
                    }

                    showID = tvSearch.Series.id;
                }

                Console.WriteLine("Located show Number: {0}", showID);

                TVSeries tvShow = new TVSeries();

                tvShow = tvSearcher.GetShow(showID);

                if (!tvShow.HasEpisodes())
                {
                    Console.WriteLine("Unable to locate any episode data!");
                    continue;
                }

                DirectoryInfo dir = new DirectoryInfo(myShow.Location);
                foreach (FileInfo f in dir.GetFiles("*.*"))
                {
                    // Ignore any . files
                    if (f.Name.StartsWith(".")) continue;

                    TotalEpisodes++;

                    TVShowNameParser myNameParser = new TVShowNameParser(f.Name);

                    if (myNameParser.Matched())
                    {
                        DataEpisode thisShow = tvShow.GetEpisode(myNameParser.Season, myNameParser.Episode);

                        tvShow.nameMaskS99E99 = AppConfig.namemasks99e99;
                        tvShow.nameMask99x99 = AppConfig.namemask99x99;

                        if (thisShow != null)
                        {
                            string newName = String.Empty;

                            if (myNameParser.wasSENaming)
                            {
                                newName = tvShow.SEFileName(myNameParser.Season, myNameParser.Episode,
                                                            Path.GetExtension(f.Name));
                            }

                            if (myNameParser.wasXNaming)
                            {
                                newName = tvShow.XFileName(myNameParser.Season, myNameParser.Episode,
                                                           Path.GetExtension(f.Name));
                            }

                            if (myNameParser.wasSMNaming)
                            {
                                newName = tvShow.SMFileName(myNameParser.Season, myNameParser.Episode,
                                                            Path.GetExtension(f.Name));
                            }

                            if (options.ForceXNaming)
                            {
                                newName = tvShow.XFileName(myNameParser.Season, myNameParser.Episode,
                                                           Path.GetExtension(f.Name));
                            }

                            if (options.ForceENaming)
                            {
                                newName = tvShow.SEFileName(myNameParser.Season, myNameParser.Episode,
                                                            Path.GetExtension(f.Name));
                            }

                            if (newName != f.Name)
                            {
                                RenamedEpisodes++;

                                string sourcePath;
                                string destpath;

                                if (options.UseRelativeNaming)
                                {
                                    sourcePath = f.Name;
                                    destpath = newName;
                                }
                                else
                                {
                                    sourcePath = Path.Combine(myShow.Location, f.Name);
                                    destpath = Path.Combine(myShow.Location, newName);
                                }

                                if (File.Exists(destpath))
                                {
                                    Console.WriteLine("WARNING! {0} already exists!");
                                }

                                if (Platform.IsWindows())
                                {
                                    tw.WriteLine(@"ren ""{0}"" ""{1}"" ", sourcePath, destpath);
                                }
                                else
                                {
                                    tw.WriteLine(@"mv ""{0}"" ""{1}"" ", sourcePath, destpath);
                                }

                                Console.WriteLine("RENAME: {0}", newName);
                            }
                            else
                            {
                                Console.WriteLine("GOOD: {0}", f.Name);
                            }
                        }
                        else
                        {
                            ErrorsEpisodes++;
                            Console.WriteLine("ERROR: {0} (Can't Locate)", f.Name);
                        }
                    }
                    else
                    {
                        if (myNameParser.AmbigiousNaming)
                        {
                            ErrorsEpisodes++;
                            Console.WriteLine("ERROR: {0} (AMBIGIOUS NAMING)", f.Name);
                        }
                        else
                        {
                            ErrorsEpisodes++;
                            Console.WriteLine("ERROR: {0} (CAN'T MATCH)", f.Name);
                        }
                    }
                }

                Console.WriteLine("");
                Console.WriteLine("Total Episodes  : {0}", TotalEpisodes);
                Console.WriteLine("Renamed Episodes: {0}", RenamedEpisodes);
                Console.WriteLine("Episode Errors  : {0}", ErrorsEpisodes);

                if (RenamedEpisodes > 0)
                {
                    Console.WriteLine("");
                    Console.WriteLine("Created {0} for renaming.", outputFile);
                    Console.WriteLine("Please inspect and execute CAREFULLY!");
                    Console.WriteLine("");
                }

                tw.Close();

                // If we didn't rename anything, remove the empty outputFile
                if (RenamedEpisodes == 0)
                {
                    File.Delete(outputFile);
                }
            }

            Misc.PauseIfInIDE();
        }
 public override bool ShouldExecute(ProgramOptions programOptions)
 {
     return(true);
 }
        public override bool Execute(ProgramOptions programOptions)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.ReportJobFilePath;
            stepTimingFunction.StepName    = programOptions.ReportJob.Status.ToString();
            stepTimingFunction.StepID      = (int)programOptions.ReportJob.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = 0;

            this.DisplayJobStepStartingStatus(programOptions);

            this.FilePathMap = new FilePathMap(programOptions);

            try
            {
                FileIOHelper.CreateFolder(this.FilePathMap.Report_FolderPath());
                FileIOHelper.CreateFolder(this.FilePathMap.Report_Role_FolderPath());
                FileIOHelper.CreateFolder(this.FilePathMap.Report_Grant_FolderPath());

                List <Role>       rolesList         = FileIOHelper.ReadListFromCSVFile <Role>(FilePathMap.Data_ShowRoles_FilePath(), new RoleShowRolesMap());
                List <RoleMember> grantsOfRolesList = FileIOHelper.ReadListFromCSVFile <RoleMember>(FilePathMap.Report_RoleMember_FilePath(), new RoleMemberMap());
                if (rolesList != null)
                {
                    Dictionary <string, Role> rolesDict = rolesList.ToDictionary(k => k.Name, r => r);

                    loggerConsole.Info("Parsing role details for {0} roles", rolesList.Count);

                    int j = 0;

                    foreach (Role role in rolesList)
                    {
                        logger.Trace("Parsing details for role {0}", role.Name);

                        if (String.Compare(role.Name, quoteObjectIdentifier(role.Name), true, CultureInfo.InvariantCulture) == 0)
                        {
                            role.IsObjectIdentifierSpecialCharacters = false;
                        }
                        else
                        {
                            role.IsObjectIdentifierSpecialCharacters = true;
                        }

                        // Parse the list of users and child roles
                        if (grantsOfRolesList != null)
                        {
                            List <RoleMember> grantsOfRoleToUserList = grantsOfRolesList.Where(g => g.Name == role.Name && g.ObjectType == "USER").ToList();
                            if (grantsOfRoleToUserList != null && grantsOfRoleToUserList.Count > 0)
                            {
                                role.AssignedUsers = String.Join(',', grantsOfRoleToUserList.Select(g => g.GrantedTo).ToArray());
                            }
                        }

                        j++;
                        if (j % 50 == 0)
                        {
                            Console.Write("{0}.", j);
                        }
                    }
                    Console.WriteLine("Done {0} items", rolesList.Count);

                    loggerConsole.Info("Parsing role usage hierarchy");

                    // Now load the all the Roles and their USAGE permission to build parent and child hierarchy
                    List <Grant> grantsToRolesList = FileIOHelper.ReadListFromCSVFile <Grant>(FilePathMap.Report_RoleGrant_ObjectType_FilePath("ROLE"), new GrantMap());
                    if (grantsToRolesList != null)
                    {
                        List <Grant> grantsToRolesUsageList = grantsToRolesList.Where(g => g.Privilege == "USAGE").ToList();
                        if (grantsToRolesUsageList != null)
                        {
                            foreach (Grant grant in grantsToRolesUsageList)
                            {
                                Role roleBeingGranted;
                                Role grantedToRole;

                                if (rolesDict.TryGetValue(grant.ObjectName, out roleBeingGranted) == true &&
                                    rolesDict.TryGetValue(grant.GrantedTo, out grantedToRole) == true)
                                {
                                    grantedToRole.ChildRoles.Add(roleBeingGranted);
                                    roleBeingGranted.ParentRoles.Add(grantedToRole);
                                }
                            }
                        }
                    }

                    loggerConsole.Info("Analyzing role types");

                    // Load selected types of grants to use to determine whether the role is Functional or Access
                    // Going to just use SCHEMA and TABLE
                    List <Grant> grantsToSchemaAllList = FileIOHelper.ReadListFromCSVFile <Grant>(FilePathMap.Report_RoleGrant_ObjectType_FilePath("SCHEMA"), new GrantMap());
                    List <Grant> grantsToTableAllList  = FileIOHelper.ReadListFromCSVFile <Grant>(FilePathMap.Report_RoleGrant_ObjectType_FilePath("TABLE"), new GrantMap());
                    List <Grant> grantsToViewAllList   = FileIOHelper.ReadListFromCSVFile <Grant>(FilePathMap.Report_RoleGrant_ObjectType_FilePath("VIEW"), new GrantMap());
                    List <Grant> grantsToRoleAllList   = FileIOHelper.ReadListFromCSVFile <Grant>(FilePathMap.Report_RoleGrant_ObjectType_FilePath("ROLE"), new GrantMap());

                    Dictionary <string, List <Grant> > grantsToSchemaDict = new Dictionary <string, List <Grant> >();
                    Dictionary <string, List <Grant> > grantsToTableDict  = new Dictionary <string, List <Grant> >();
                    Dictionary <string, List <Grant> > grantsToViewDict   = new Dictionary <string, List <Grant> >();
                    Dictionary <string, List <Grant> > grantsToRoleDict   = new Dictionary <string, List <Grant> >();

                    var grantsToSchemaGroups = grantsToSchemaAllList.GroupBy(g => g.GrantedTo);
                    foreach (var grantsGroup in grantsToSchemaGroups)
                    {
                        grantsToSchemaDict.Add(grantsGroup.Key, grantsGroup.ToList());
                    }
                    var grantsToTableGroups = grantsToTableAllList.GroupBy(g => g.GrantedTo);
                    foreach (var grantsGroup in grantsToTableGroups)
                    {
                        grantsToTableDict.Add(grantsGroup.Key, grantsGroup.ToList());
                    }
                    var grantsToViewGroups = grantsToViewAllList.GroupBy(g => g.GrantedTo);
                    foreach (var grantsGroup in grantsToViewGroups)
                    {
                        grantsToViewDict.Add(grantsGroup.Key, grantsGroup.ToList());
                    }
                    var grantsToRoleGroups = grantsToRoleAllList.GroupBy(g => g.GrantedTo);
                    foreach (var grantsGroup in grantsToRoleGroups)
                    {
                        grantsToRoleDict.Add(grantsGroup.Key, grantsGroup.ToList());
                    }

                    j = 0;

                    // Detect role types and inheritance rollups
                    foreach (Role role in rolesList)
                    {
                        // Detect built-in roles and
                        if (role.Name == "ACCOUNTADMIN" || role.Name == "SECURITYADMIN" || role.Name == "USERADMIN" || role.Name == "SYSADMIN" || role.Name == "PUBLIC")
                        {
                            role.Type = RoleType.BuiltIn;
                        }
                        else if (role.Name == "AAD_PROVISIONER" || role.Name == "OKTA_PROVISIONER" || role.Name == "GENERIC_SCIM_PROVISIONER")
                        {
                            role.Type = RoleType.SCIM;
                        }
                        else
                        {
                            // Detect other types of roles
                            Role roleSECURITYADMIN;
                            Role roleUSERADMIN;
                            Role roleSYSADMIN;
                            Role roleACCOUNTADMIN;

                            if (rolesDict.TryGetValue("ACCOUNTADMIN", out roleACCOUNTADMIN) == true &&
                                rolesDict.TryGetValue("SECURITYADMIN", out roleSECURITYADMIN) == true &&
                                rolesDict.TryGetValue("USERADMIN", out roleUSERADMIN) &&
                                rolesDict.TryGetValue("SYSADMIN", out roleSYSADMIN))
                            {
                                // Check what we are rooted to
                                if ((role.RollsUpTo(roleUSERADMIN) == true || role.RollsUpTo(roleSECURITYADMIN) == true) && role.RollsUpTo(roleSYSADMIN) == false)
                                {
                                    role.Type = RoleType.RoleManagement;
                                }

                                // Check between Functional and Access
                                List <Grant> grantsToSchemaList = null;
                                List <Grant> grantsToTableList  = null;
                                List <Grant> grantsToViewList   = null;
                                List <Grant> grantsToRoleList   = null;
                                grantsToSchemaDict.TryGetValue(role.Name, out grantsToSchemaList);
                                grantsToTableDict.TryGetValue(role.Name, out grantsToTableList);
                                grantsToViewDict.TryGetValue(role.Name, out grantsToViewList);
                                grantsToRoleDict.TryGetValue(role.Name, out grantsToRoleList);

                                // Schemas first
                                if (role.Type == RoleType.Unknown && grantsToSchemaList != null)
                                {
                                    List <Grant> grantsToSchemaForThisRoleList = grantsToSchemaList.Where(
                                        g => g.GrantedTo == role.Name &&
                                        g.Privilege != "USAGE" &&
                                        g.Privilege != "OWNERSHIP" &&
                                        g.Privilege != "MONITOR").ToList();
                                    if (grantsToSchemaForThisRoleList != null && grantsToSchemaForThisRoleList.Count > 0)
                                    {
                                        role.Type = RoleType.Access;
                                    }
                                }

                                // Tables second, and only if the role type is still undetermined
                                if (role.Type == RoleType.Unknown && grantsToTableList != null)
                                {
                                    List <Grant> grantsToTableForThisRoleList = grantsToTableList.Where(
                                        g => g.GrantedTo == role.Name &&
                                        g.Privilege != "USAGE" &&
                                        g.Privilege != "OWNERSHIP" &&
                                        g.Privilege != "REFERENCES" &&
                                        g.Privilege != "REBUILD").ToList();
                                    if (grantsToTableForThisRoleList != null && grantsToTableForThisRoleList.Count > 0)
                                    {
                                        role.Type = RoleType.Access;
                                    }
                                }

                                // Views third, and only if the role type is still undetermined
                                if (role.Type == RoleType.Unknown && grantsToViewList != null)
                                {
                                    List <Grant> grantsToViewForThisRoleList = grantsToViewList.Where(
                                        g => g.GrantedTo == role.Name &&
                                        g.Privilege != "USAGE" &&
                                        g.Privilege != "OWNERSHIP" &&
                                        g.Privilege != "REFERENCES" &&
                                        g.Privilege != "REBUILD").ToList();
                                    if (grantsToViewForThisRoleList != null && grantsToViewForThisRoleList.Count > 0)
                                    {
                                        role.Type = RoleType.Access;
                                    }
                                }

                                // After comparing to schema, table and view, it is still unknown. Does it have any other roles below which would make it Functional?
                                if (role.Type == RoleType.Unknown && grantsToRoleList != null)
                                {
                                    List <Grant> grantsToRoleForThisRoleList = grantsToRoleList.Where(
                                        g => g.GrantedTo == role.Name &&
                                        g.Privilege == "USAGE").ToList();
                                    if (grantsToRoleForThisRoleList != null && grantsToRoleForThisRoleList.Count > 0)
                                    {
                                        role.Type = RoleType.Functional;
                                    }
                                }

                                if (role.Type == RoleType.Unknown && role.RollsUpTo(roleACCOUNTADMIN) == false)
                                {
                                    // This role is not connected to the proper hierarchy
                                    role.Type = RoleType.NotUnderAccountAdmin;
                                }

                                if (role.Type == RoleType.Functional && role.RollsUpTo(roleSYSADMIN) == false)
                                {
                                    // Functional but not in the right hierarchy
                                    role.Type = RoleType.FunctionalNotUnderSysadmin;
                                }

                                if (role.Type == RoleType.Access && role.RollsUpTo(roleSYSADMIN) == false)
                                {
                                    // Access but not in the right hierarchy
                                    role.Type = RoleType.AccessNotUnderSysadmin;
                                }
                            }
                        }

                        j++;
                        if (j % 50 == 0)
                        {
                            Console.Write("{0}.", j);
                        }
                    }
                    Console.WriteLine("Done {0} items", rolesList.Count);

                    loggerConsole.Info("Building role ancestry paths");

                    // Now create role usage hiearchy
                    if (grantsToRolesList != null)
                    {
                        List <Grant> grantsToRolesUsageList = grantsToRolesList.Where(g => g.Privilege == "USAGE").ToList();
                        if (grantsToRolesUsageList != null)
                        {
                            List <RoleHierarchy> roleHierarchiesList = new List <RoleHierarchy>(grantsToRolesUsageList.Count);

                            loggerConsole.Info("Processing Role Usage for {0} hierarchy records", grantsToRolesUsageList.Count);

                            j = 0;

                            // Build stuff for flow diagrams using the USAGE rights and the role hierarchy
                            foreach (Grant grant in grantsToRolesUsageList)
                            {
                                Role roleBeingGranted;

                                if (rolesDict.TryGetValue(grant.ObjectName, out roleBeingGranted) == true)
                                {
                                    RoleHierarchy roleHierarchy = new RoleHierarchy();
                                    roleHierarchy.Name             = roleBeingGranted.Name;
                                    roleHierarchy.Type             = roleBeingGranted.Type;
                                    roleHierarchy.AncestryPaths    = roleBeingGranted.AncestryPaths;
                                    roleHierarchy.NumAncestryPaths = roleHierarchy.AncestryPaths.Split('\n').Count();
                                    roleHierarchy.GrantedTo        = grant.GrantedTo;

                                    if (roleHierarchy.AncestryPaths.StartsWith("ACCOUNTADMIN", true, CultureInfo.InvariantCulture) == false)
                                    {
                                        // Everything should roll up to ACCOUNTADMIN
                                        // But when it doesn't, highlight this by pointing the highest unconnected role
                                        roleHierarchy.ImportantAncestor = String.Format("{0}", roleHierarchy.AncestryPaths.Split('\\')[0]);
                                    }
                                    else if (roleBeingGranted.Type == RoleType.Access || roleBeingGranted.Type == RoleType.Functional)
                                    {
                                        // Walk up to the last Functional role in the hierarchy going up
                                        bool keepGoing   = true;
                                        Role currentRole = roleBeingGranted;
                                        while (keepGoing)
                                        {
                                            if (currentRole.ParentRoles.Count == 0)
                                            {
                                                keepGoing = false;
                                            }
                                            else
                                            {
                                                // only go up on the primary path
                                                Role parentRole = currentRole.ParentRoles[0];
                                                if (parentRole.Type == RoleType.Access || parentRole.Type == RoleType.Functional)
                                                {
                                                    currentRole = parentRole;
                                                }
                                                else
                                                {
                                                    keepGoing = false;
                                                }
                                            }
                                        }
                                        roleHierarchy.ImportantAncestor = currentRole.Name;
                                    }
                                    else
                                    {
                                        // Default for all others to the root
                                        roleHierarchy.ImportantAncestor = "ACCOUNTADMIN";
                                    }

                                    roleHierarchiesList.Add(roleHierarchy);
                                }

                                j++;
                                if (j % 1000 == 0)
                                {
                                    Console.Write("{0}.", j);
                                }
                            }
                            Console.WriteLine("Done {0} items", grantsToRolesUsageList.Count);

                            loggerConsole.Info("Looking for stragglers without parents or children for {0} roles", rolesList.Count);

                            j = 0;

                            // Now loop through the list of roles looking for the stragglers that have no other roles below them or aren't parented to any
                            foreach (Role role in rolesList)
                            {
                                if (roleHierarchiesList.Count(r => r.Name == role.Name) == 0 && roleHierarchiesList.Count(r => r.GrantedTo == role.Name) == 0)
                                {
                                    // Add this role explicily
                                    RoleHierarchy roleHierarchy = new RoleHierarchy();
                                    roleHierarchy.Name             = role.Name;
                                    roleHierarchy.Type             = role.Type;
                                    roleHierarchy.AncestryPaths    = role.AncestryPaths;
                                    roleHierarchy.NumAncestryPaths = roleHierarchy.AncestryPaths.Split('\n').Count();
                                    roleHierarchy.GrantedTo        = "<NOTHING>";

                                    roleHierarchiesList.Add(roleHierarchy);
                                }

                                j++;
                                if (j % 50 == 0)
                                {
                                    Console.Write("{0}.", j);
                                }
                            }
                            Console.WriteLine("Done {0} items", rolesList.Count);

                            roleHierarchiesList = roleHierarchiesList.OrderBy(r => r.Name).ThenBy(r => r.GrantedTo).ToList();
                            FileIOHelper.WriteListToCSVFile <RoleHierarchy>(roleHierarchiesList, new RoleHierarchyMap(), FilePathMap.Report_RoleHierarchy_FilePath());

                            roleHierarchiesList = null;

                            GC.Collect();

                            j = 0;

                            loggerConsole.Info("Processing Role hierarchy for {0} roles", rolesList.Count);

                            // For each role, output the hierarchy records that relate to its parents and children
                            foreach (Role role in rolesList)
                            {
                                // Get list of Roles
                                List <Role> thisRoleAndItsRelationsNonUniqueList = new List <Role>(10);
                                thisRoleAndItsRelationsNonUniqueList.Add(role);
                                role.GetAllParentRoles(role, thisRoleAndItsRelationsNonUniqueList);
                                role.GetAllChildRoles(role, thisRoleAndItsRelationsNonUniqueList);
                                // Filter to only unique items
                                var         thisRoleAndItsRelationsListGrouped = thisRoleAndItsRelationsNonUniqueList.GroupBy(r => r.Name);
                                List <Role> thisRoleAndItsRelationsList        = new List <Role>(thisRoleAndItsRelationsListGrouped.Count());
                                foreach (var roleGroup in thisRoleAndItsRelationsListGrouped)
                                {
                                    thisRoleAndItsRelationsList.Add(roleGroup.First());
                                }

                                // Get hierarchy of roles
                                List <RoleHierarchy> thisRoleAndItsRelationsHierarchiesNonUniqueList = new List <RoleHierarchy>(100);
                                role.GetAllParentRoleHierarchies(role, thisRoleAndItsRelationsHierarchiesNonUniqueList, 10000);
                                role.GetAllChildRoleHierarchies(role, thisRoleAndItsRelationsHierarchiesNonUniqueList, 10000);
                                // Filter to only unique items
                                var thisRoleAndItsRelationsHierarchiesGrouped = thisRoleAndItsRelationsHierarchiesNonUniqueList.GroupBy(r => String.Format("{0}-{1}", r.Name, r.GrantedTo));
                                List <RoleHierarchy> thisRoleAndItsRelationsHierarchiesList = new List <RoleHierarchy>(thisRoleAndItsRelationsHierarchiesGrouped.Count());
                                foreach (var roleHierarchyGroup in thisRoleAndItsRelationsHierarchiesGrouped)
                                {
                                    thisRoleAndItsRelationsHierarchiesList.Add(roleHierarchyGroup.First());
                                }

                                thisRoleAndItsRelationsHierarchiesList = thisRoleAndItsRelationsHierarchiesList.OrderBy(r => r.Name).ThenBy(r => r.GrantedTo).ToList();

                                FileIOHelper.WriteListToCSVFile <Role>(thisRoleAndItsRelationsList, new RoleMap(), FilePathMap.Report_RoleDetail_RoleAndItsRelations_FilePath(role.Name));
                                FileIOHelper.WriteListToCSVFile <RoleHierarchy>(thisRoleAndItsRelationsHierarchiesList, new RoleHierarchyMap(), FilePathMap.Report_RoleHierarchy_RoleAndItsRelations_FilePath(role.Name));

                                j++;
                                if (j % 50 == 0)
                                {
                                    Console.Write("{0}.", j);
                                }
                            }
                            Console.WriteLine("Done {0} items", rolesList.Count);
                        }
                    }

                    rolesList = rolesList.OrderBy(r => r.Name).ToList();

                    FileIOHelper.WriteListToCSVFile <Role>(rolesList, new RoleMap(), FilePathMap.Report_RoleDetail_FilePath());
                    FileIOHelper.WriteListToCSVFile <Role>(rolesList, new RoleOwnerSankeyMap(), FilePathMap.Report_RoleOwnerSankey_FilePath(), false, false);
                }

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

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

                this.DisplayJobStepEndedStatus(programOptions, 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);
            }
        }
Пример #29
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_MOBILE) == 0)
                {
                    return(true);
                }

                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);
                    }
                }

                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);
                }

                if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_WEB) == 0)
                {
                    return(true);
                }

                #region Template comparisons

                if (jobConfiguration.Input.ConfigurationComparisonReferenceWEB.Controller == BLANK_APPLICATION_CONTROLLER &&
                    jobConfiguration.Input.ConfigurationComparisonReferenceWEB.Application == BLANK_APPLICATION_WEB)
                {
                    jobConfiguration.Target.Add(jobConfiguration.Input.ConfigurationComparisonReferenceWEB);
                }
                else
                {
                    // Check if there is a valid reference application
                    JobTarget jobTargetReferenceApp = jobConfiguration.Target.Where(t =>
                                                                                    t.Type == APPLICATION_TYPE_WEB &&
                                                                                    String.Compare(t.Controller, jobConfiguration.Input.ConfigurationComparisonReferenceWEB.Controller, StringComparison.InvariantCultureIgnoreCase) == 0 &&
                                                                                    String.Compare(t.Application, jobConfiguration.Input.ConfigurationComparisonReferenceWEB.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.ConfigurationComparisonReferenceWEB);
                        loggerConsole.Warn("Unable to find reference target {0}, will index default template", jobConfiguration.Input.ConfigurationComparisonReferenceWEB);

                        jobConfiguration.Input.ConfigurationComparisonReferenceWEB.Controller  = BLANK_APPLICATION_CONTROLLER;
                        jobConfiguration.Input.ConfigurationComparisonReferenceWEB.Application = BLANK_APPLICATION_WEB;
                        jobConfiguration.Input.ConfigurationComparisonReferenceWEB.Type        = APPLICATION_TYPE_WEB;

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

                #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_WEB)
                    {
                        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

                        WEBApplicationConfiguration applicationConfiguration = new WEBApplicationConfiguration();

                        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_WEB && a.ApplicationID == applicationConfiguration.ApplicationID).FirstOrDefault();
                            if (controllerApplication != null)
                            {
                                applicationConfiguration.ApplicationDescription = controllerApplication.Description;
                            }
                        }

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

                        // Instrumentation Options
                        JObject instrumentationObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.WEBAgentConfigDataFilePath(jobTarget));
                        if (instrumentationObject != null)
                        {
                            applicationConfiguration.IsXsccEnabled = getBoolValueFromJToken(instrumentationObject, "enableXssc");
                            applicationConfiguration.HostOption    = getIntValueFromJToken(instrumentationObject, "hostOption");

                            applicationConfiguration.AgentHTTP   = getStringValueFromJToken(instrumentationObject, "jsAgentUrlHttp");
                            applicationConfiguration.AgentHTTPS  = getStringValueFromJToken(instrumentationObject, "jsAgentUrlHttps");
                            applicationConfiguration.GeoHTTP     = getStringValueFromJToken(instrumentationObject, "geoUrlHttp");
                            applicationConfiguration.GeoHTTPS    = getStringValueFromJToken(instrumentationObject, "geoUrlHttps");
                            applicationConfiguration.BeaconHTTP  = getStringValueFromJToken(instrumentationObject, "beaconUrlHttp");
                            applicationConfiguration.BeaconHTTPS = getStringValueFromJToken(instrumentationObject, "beaconUrlHttps");

                            applicationConfiguration.AgentCode = getStringValueFromJToken(instrumentationObject, "codeSnippet");
                        }

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

                        // Error Detection
                        JObject errorDetectionRulesObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.WEBAgentErrorRulesDataFilePath(jobTarget));
                        if (errorDetectionRulesObject != null)
                        {
                            applicationConfiguration.IsJSErrorEnabled   = getBoolValueFromJToken(errorDetectionRulesObject, "javaScriptErrorCaptureEnabled");
                            applicationConfiguration.IsAJAXErrorEnabled = getBoolValueFromJToken(errorDetectionRulesObject, "ajaxRequestErrorCaptureEnabled");
                            applicationConfiguration.IgnoreJSErrors     = getStringValueOfObjectFromJToken(errorDetectionRulesObject, "ignoreJavaScriptErrorConfigRules", true);
                            applicationConfiguration.IgnorePageNames    = getStringValueOfObjectFromJToken(errorDetectionRulesObject, "ignorePageNames", true);
                            applicationConfiguration.IgnoreURLs         = getStringValueOfObjectFromJToken(errorDetectionRulesObject, "ignoreUrls", true);
                        }

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

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

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

                            applicationConfiguration.EnableSlowSnapshots     = getBoolValueFromJToken(pageSettingsObject["eventPolicy"], "enableSlowSnapshotCollection");
                            applicationConfiguration.EnablePeriodicSnapshots = getBoolValueFromJToken(pageSettingsObject["eventPolicy"], "enablePeriodicSnapshotCollection");
                            applicationConfiguration.EnableErrorSnapshots    = getBoolValueFromJToken(pageSettingsObject["eventPolicy"], "enableErrorSnapshotCollection");
                        }

                        #endregion

                        #region Rules of all kinds

                        loggerConsole.Info("Page and AJAX Request Rules");

                        #region Page Rules

                        List <WEBPageDetectionRule> pageDetectionRulesList = new List <WEBPageDetectionRule>(1024);

                        JObject pageRulesObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.WEBAgentPageRulesDataFilePath(jobTarget));
                        if (pageRulesObject != null)
                        {
                            if (isTokenPropertyNull(pageRulesObject, "customNamingIncludeRules") == false)
                            {
                                JArray includeRulesArray = (JArray)pageRulesObject["customNamingIncludeRules"];
                                foreach (JObject includeRuleObject in includeRulesArray)
                                {
                                    WEBPageDetectionRule webPageDetectionRule = fillWebPageDetectionRule(includeRuleObject, jobTarget);
                                    if (webPageDetectionRule != null)
                                    {
                                        webPageDetectionRule.DetectionType  = "INCLUDE";
                                        webPageDetectionRule.EntityCategory = "Pages&IFrames";

                                        pageDetectionRulesList.Add(webPageDetectionRule);
                                    }
                                }
                            }

                            if (isTokenPropertyNull(pageRulesObject, "customNamingExcludeRules") == false)
                            {
                                JArray excludeRulesArray = (JArray)pageRulesObject["customNamingExcludeRules"];
                                foreach (JObject excludeRuleObject in excludeRulesArray)
                                {
                                    WEBPageDetectionRule webPageDetectionRule = fillWebPageDetectionRule(excludeRuleObject, jobTarget);
                                    if (webPageDetectionRule != null)
                                    {
                                        webPageDetectionRule.DetectionType  = "EXCLUDE";
                                        webPageDetectionRule.EntityCategory = "Pages&IFrames";

                                        pageDetectionRulesList.Add(webPageDetectionRule);
                                    }
                                }
                            }
                        }

                        #endregion

                        #region AJAX Rules

                        JObject ajaxRulesObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.WEBAgentAjaxRulesDataFilePath(jobTarget));
                        if (ajaxRulesObject != null)
                        {
                            if (isTokenPropertyNull(ajaxRulesObject, "customNamingIncludeRules") == false)
                            {
                                JArray includeRulesArray = (JArray)ajaxRulesObject["customNamingIncludeRules"];
                                foreach (JObject includeRuleObject in includeRulesArray)
                                {
                                    WEBPageDetectionRule webPageDetectionRule = fillWebPageDetectionRule(includeRuleObject, jobTarget);
                                    if (webPageDetectionRule != null)
                                    {
                                        webPageDetectionRule.DetectionType  = "INCLUDE";
                                        webPageDetectionRule.EntityCategory = "Ajax";

                                        pageDetectionRulesList.Add(webPageDetectionRule);
                                    }
                                }
                            }

                            if (isTokenPropertyNull(ajaxRulesObject, "customNamingExcludeRules") == false)
                            {
                                JArray excludeRulesArray = (JArray)ajaxRulesObject["customNamingExcludeRules"];
                                foreach (JObject excludeRuleObject in excludeRulesArray)
                                {
                                    WEBPageDetectionRule webPageDetectionRule = fillWebPageDetectionRule(excludeRuleObject, jobTarget);
                                    if (webPageDetectionRule != null)
                                    {
                                        webPageDetectionRule.DetectionType  = "EXCLUDE";
                                        webPageDetectionRule.EntityCategory = "Ajax";

                                        pageDetectionRulesList.Add(webPageDetectionRule);
                                    }
                                }
                            }

                            if (isTokenPropertyNull(ajaxRulesObject, "eventServiceIncludeRules") == false)
                            {
                                JArray includeRulesArray = (JArray)ajaxRulesObject["eventServiceIncludeRules"];
                                foreach (JObject includeRuleObject in includeRulesArray)
                                {
                                    WEBPageDetectionRule webPageDetectionRule = fillWebPageDetectionRule(includeRuleObject, jobTarget);
                                    if (webPageDetectionRule != null)
                                    {
                                        webPageDetectionRule.DetectionType  = "INCLUDE";
                                        webPageDetectionRule.EntityCategory = "AjaxEventsSvc";

                                        pageDetectionRulesList.Add(webPageDetectionRule);
                                    }
                                }
                            }

                            if (isTokenPropertyNull(ajaxRulesObject, "eventServiceExcludeRules") == false)
                            {
                                JArray excludeRulesArray = (JArray)ajaxRulesObject["eventServiceExcludeRules"];
                                foreach (JObject excludeRuleObject in excludeRulesArray)
                                {
                                    WEBPageDetectionRule webPageDetectionRule = fillWebPageDetectionRule(excludeRuleObject, jobTarget);
                                    if (webPageDetectionRule != null)
                                    {
                                        webPageDetectionRule.DetectionType  = "EXCLUDE";
                                        webPageDetectionRule.EntityCategory = "AjaxEventsSvc";

                                        pageDetectionRulesList.Add(webPageDetectionRule);
                                    }
                                }
                            }
                        }

                        #endregion

                        #region Virtual Page Rules

                        JObject virtualPageRulesObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.WEBAgentVirtualPageRulesDataFilePath(jobTarget));
                        if (virtualPageRulesObject != null)
                        {
                            if (isTokenPropertyNull(virtualPageRulesObject, "customNamingIncludeRules") == false)
                            {
                                JArray includeRulesArray = (JArray)virtualPageRulesObject["customNamingIncludeRules"];
                                foreach (JObject includeRuleObject in includeRulesArray)
                                {
                                    WEBPageDetectionRule webPageDetectionRule = fillWebPageDetectionRule(includeRuleObject, jobTarget);
                                    if (webPageDetectionRule != null)
                                    {
                                        webPageDetectionRule.DetectionType  = "INCLUDE";
                                        webPageDetectionRule.EntityCategory = "VirtualPage";

                                        pageDetectionRulesList.Add(webPageDetectionRule);
                                    }
                                }
                            }

                            if (isTokenPropertyNull(virtualPageRulesObject, "customNamingExcludeRules") == false)
                            {
                                JArray excludeRulesArray = (JArray)virtualPageRulesObject["customNamingExcludeRules"];
                                foreach (JObject excludeRuleObject in excludeRulesArray)
                                {
                                    WEBPageDetectionRule webPageDetectionRule = fillWebPageDetectionRule(excludeRuleObject, jobTarget);
                                    if (webPageDetectionRule != null)
                                    {
                                        webPageDetectionRule.DetectionType  = "EXCLUDE";
                                        webPageDetectionRule.EntityCategory = "VirtualPage";

                                        pageDetectionRulesList.Add(webPageDetectionRule);
                                    }
                                }
                            }
                        }

                        #endregion

                        // Sort them
                        pageDetectionRulesList = pageDetectionRulesList.OrderBy(o => o.EntityCategory).ThenBy(o => o.DetectionType).ThenBy(o => o.Priority).ToList();
                        FileIOHelper.WriteListToCSVFile(pageDetectionRulesList, new WEBPageDetectionRuleReportMap(), FilePathMap.WEBPageAjaxVirtualPageRulesIndexFilePath(jobTarget));

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

                        #endregion

                        #region Synthetic Jobs

                        loggerConsole.Info("Synthetic Jobs");

                        List <WEBSyntheticJobDefinition> syntheticJobDefinitionsList = null;

                        JObject syntheticJobsObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.WEBSyntheticJobsDataFilePath(jobTarget));
                        if (syntheticJobsObject != null)
                        {
                            if (isTokenPropertyNull(syntheticJobsObject, "jobListDatas") == false)
                            {
                                JArray syntheticJobsArray = (JArray)syntheticJobsObject["jobListDatas"];

                                syntheticJobDefinitionsList = new List <WEBSyntheticJobDefinition>(syntheticJobsArray.Count);

                                foreach (JObject syntheticJobObject in syntheticJobsArray)
                                {
                                    if (isTokenPropertyNull(syntheticJobObject, "config") == false)
                                    {
                                        JObject syntheticJobConfigObject = (JObject)syntheticJobObject["config"];

                                        WEBSyntheticJobDefinition syntheticJobDefinition = new WEBSyntheticJobDefinition();

                                        syntheticJobDefinition.Controller      = jobTarget.Controller;
                                        syntheticJobDefinition.ControllerLink  = String.Format(DEEPLINK_CONTROLLER, jobTarget.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES);
                                        syntheticJobDefinition.ApplicationName = jobTarget.Application;
                                        syntheticJobDefinition.ApplicationID   = jobTarget.ApplicationID;
                                        syntheticJobDefinition.ApplicationLink = String.Format(DEEPLINK_APM_APPLICATION, jobTarget.Controller, jobTarget.ApplicationID, DEEPLINK_TIMERANGE_LAST_15_MINUTES);

                                        syntheticJobDefinition.JobName = getStringValueFromJToken(syntheticJobConfigObject, "description");
                                        syntheticJobDefinition.JobID   = getStringValueFromJToken(syntheticJobConfigObject, "id");

                                        syntheticJobDefinition.IsUserEnabled   = getBoolValueFromJToken(syntheticJobConfigObject, "userEnabled");
                                        syntheticJobDefinition.IsSystemEnabled = getBoolValueFromJToken(syntheticJobConfigObject, "systemEnabled");
                                        syntheticJobDefinition.FailOnError     = getBoolValueFromJToken(syntheticJobConfigObject, "failOnPageError");
                                        syntheticJobDefinition.IsPrivateAgent  = getBoolValueFromJToken(syntheticJobObject, "hasPrivateAgent");

                                        syntheticJobDefinition.RateUnit = getStringValueFromJToken(syntheticJobConfigObject["rate"], "unit");
                                        syntheticJobDefinition.Rate     = getIntValueFromJToken(syntheticJobConfigObject["rate"], "value");
                                        syntheticJobDefinition.Timeout  = getIntValueFromJToken(syntheticJobConfigObject, "timeoutSeconds");

                                        syntheticJobDefinition.Days      = getStringValueOfObjectFromJToken(syntheticJobConfigObject, "daysOfWeek", true);
                                        syntheticJobDefinition.Browsers  = getStringValueOfObjectFromJToken(syntheticJobConfigObject, "browserCodes", true);
                                        syntheticJobDefinition.Locations = getStringValueOfObjectFromJToken(syntheticJobConfigObject, "locationCodes", true);
                                        if (syntheticJobDefinition.Locations.Length > 0)
                                        {
                                            syntheticJobDefinition.NumLocations = ((JArray)syntheticJobConfigObject["locationCodes"]).Count();
                                        }
                                        syntheticJobDefinition.ScheduleMode = getStringValueFromJToken(syntheticJobConfigObject, "scheduleMode");

                                        syntheticJobDefinition.URL    = getStringValueFromJToken(syntheticJobConfigObject, "url");
                                        syntheticJobDefinition.Script = getStringValueFromJToken(syntheticJobConfigObject["script"], "script");

                                        if (syntheticJobDefinition.URL.Length > 0)
                                        {
                                            syntheticJobDefinition.JobType = "URL";
                                        }
                                        else
                                        {
                                            syntheticJobDefinition.JobType = "SCRIPT";
                                        }

                                        syntheticJobDefinition.Network      = getStringValueOfObjectFromJToken(syntheticJobConfigObject, "networkProfile", false);
                                        syntheticJobDefinition.Config       = getStringValueOfObjectFromJToken(syntheticJobConfigObject, "composableConfig", false);
                                        syntheticJobDefinition.PerfCriteria = getStringValueOfObjectFromJToken(syntheticJobConfigObject, "performanceCriteria", false);

                                        syntheticJobDefinition.CreatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(syntheticJobConfigObject, "created"));
                                        try { syntheticJobDefinition.CreatedOn = syntheticJobDefinition.CreatedOnUtc.ToLocalTime(); } catch { }
                                        syntheticJobDefinition.UpdatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(syntheticJobConfigObject, "updated"));
                                        try { syntheticJobDefinition.UpdatedOn = syntheticJobDefinition.UpdatedOnUtc.ToLocalTime(); } catch { }

                                        syntheticJobDefinitionsList.Add(syntheticJobDefinition);
                                    }
                                }

                                // Sort them
                                syntheticJobDefinitionsList = syntheticJobDefinitionsList.OrderBy(o => o.JobName).ToList();
                                FileIOHelper.WriteListToCSVFile(syntheticJobDefinitionsList, new WEBSyntheticJobDefinitionReportMap(), FilePathMap.WEBSyntheticJobsIndexFilePath(jobTarget));

                                loggerConsole.Info("Completed {0} Synthetic Jobs", syntheticJobDefinitionsList.Count);
                            }
                        }

                        #endregion

                        #region Application Settings

                        if (pageDetectionRulesList != null)
                        {
                            applicationConfiguration.NumPageRulesInclude     = pageDetectionRulesList.Count(r => r.EntityCategory == "Pages&IFrames" && r.DetectionType == "INCLUDE");
                            applicationConfiguration.NumPageRulesExclude     = pageDetectionRulesList.Count(r => r.EntityCategory == "Pages&IFrames" && r.DetectionType == "EXCLUDE");
                            applicationConfiguration.NumAJAXRulesInclude     = pageDetectionRulesList.Count(r => r.EntityCategory == "Ajax" && r.DetectionType == "INCLUDE");
                            applicationConfiguration.NumAJAXRulesExclude     = pageDetectionRulesList.Count(r => r.EntityCategory == "Ajax" && r.DetectionType == "EXCLUDE");
                            applicationConfiguration.NumVirtPageRulesInclude = pageDetectionRulesList.Count(r => r.EntityCategory == "VirtualPage" && r.DetectionType == "INCLUDE");
                            applicationConfiguration.NumVirtPageRulesExclude = pageDetectionRulesList.Count(r => r.EntityCategory == "VirtualPage" && r.DetectionType == "EXCLUDE");
                        }

                        if (syntheticJobDefinitionsList != null)
                        {
                            applicationConfiguration.NumSyntheticJobs = syntheticJobDefinitionsList.Count;
                        }

                        List <WEBApplicationConfiguration> applicationConfigurationsList = new List <WEBApplicationConfiguration>(1);
                        applicationConfigurationsList.Add(applicationConfiguration);
                        FileIOHelper.WriteListToCSVFile(applicationConfigurationsList, new WEBApplicationConfigurationReportMap(), FilePathMap.WEBApplicationConfigurationIndexFilePath(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.WEBConfigurationReportFolderPath());
                            Thread.Sleep(1000);
                            FileIOHelper.CreateFolder(FilePathMap.WEBConfigurationReportFolderPath());
                            reportFolderCleaned = true;
                        }

                        // Append all the individual report files into one
                        if (File.Exists(FilePathMap.WEBApplicationConfigurationIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.WEBApplicationConfigurationIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.WEBApplicationConfigurationReportFilePath(), FilePathMap.WEBApplicationConfigurationIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.WEBPageAjaxVirtualPageRulesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.WEBPageAjaxVirtualPageRulesIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.WEBPageAjaxVirtualPageRulesReportFilePath(), FilePathMap.WEBPageAjaxVirtualPageRulesIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.WEBSyntheticJobsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.WEBSyntheticJobsIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.WEBSyntheticJobsReportFilePath(), FilePathMap.WEBSyntheticJobsIndexFilePath(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);
            }
        }
Пример #31
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);
            }

            if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_APM) == 0)
            {
                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(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(SHEET_TOC);

                #endregion

                #region Entity sheets and their associated pivot

                // 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_METHOD_CALL_LINES);
                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 Type";
                sheet.Cells[2, 2].Formula   = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", 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>"")", 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>"")", SHEET_METHOD_CALL_LINES_TIMELINE_EXEC_AVERAGE_PIVOT);
                sheet.Cells[4, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 2, 1);

                sheet = excelReport.Workbook.Worksheets.Add(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>"")", 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_METHOD_CALL_LINES);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 5, 1);

                sheet = excelReport.Workbook.Worksheets.Add(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>"")", 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_METHOD_CALL_LINES);
                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_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>"")", 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_METHOD_CALL_LINES);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 9, 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[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.ApplicationSnapshotsReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Method Call Lines

                loggerConsole.Info("List of Method Call Lines");

                sheet = excelReport.Workbook.Worksheets[SHEET_METHOD_CALL_LINES];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.SnapshotsMethodCallLinesReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT + 1, 1);

                #endregion

                loggerConsole.Info("Finalize Snapshots Method Call Lines 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["NumSnapshots"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSnapshots"].Position + 1);
                    var          cfNum        = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars);

                    cfAddressNum = new ExcelAddress(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(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(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(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(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[SHEET_METHOD_CALL_LINES];
                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 + 1)
                {
                    range            = sheet.Cells[LIST_SHEET_START_TABLE_AT + 1, 1, sheet.Dimension.Rows, sheet.Dimension.Columns];
                    table            = sheet.Tables.Add(range, TABLE_METHOD_CALL_LINES);
                    table.ShowHeader = true;
                    table.TableStyle = TableStyles.Medium2;
                    table.ShowFilter = true;
                    table.ShowTotal  = false;

                    try
                    {
                        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;
                    }
                    catch (OutOfMemoryException ex)
                    {
                        // Do nothing, we must have a lot of cells
                        logger.Warn("Ran out of memory due to too many rows/cells");
                        logger.Warn(ex);
                    }

                    ExcelAddress cfAddressUserExperience = new ExcelAddress(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(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[SHEET_METHOD_CALL_LINES_TYPE_EXEC_AVERAGE_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1], range, 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(GRAPH_METHOD_CALL_LINESTYPE_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[SHEET_METHOD_CALL_LINES_LOCATION_EXEC_AVERAGE_PIVOT];
                    pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 1, 1], range, 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(GRAPH_METHOD_CALL_LINESLOCATION_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[SHEET_METHOD_CALL_LINES_TIMELINE_EXEC_AVERAGE_PIVOT];
                    pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 6, 1], range, 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(GRAPH_METHOD_CALL_LINESTIMELINE_EXEC_AVERAGE, eChartType.Line, pivot);
                    chart.SetPosition(2, 0, 0, 0);
                    chart.SetSize(800, 300);

                    sheet.Column(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.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);
            }
        }
Пример #32
0
 private static void Run(ProgramOptions options)
 => new WebHostBuilder()
 .UseDefaultForApi <Startup>(options)
 .RunWithLock <Program>();
        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];

                    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 Health Rule violations

                        loggerConsole.Info("Index health rule violations");

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

                        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);

                        if (File.Exists(FilePathMap.HealthRuleViolationsDataFilePath(jobTarget)))
                        {
                            JArray eventsInHour = FileIOHelper.LoadJArrayFromFile(FilePathMap.HealthRuleViolationsDataFilePath(jobTarget));
                            if (eventsInHour != null)
                            {
                                foreach (JObject interestingEvent in eventsInHour)
                                {
                                    HealthRuleViolationEvent eventRow = new HealthRuleViolationEvent();
                                    eventRow.Controller      = jobTarget.Controller;
                                    eventRow.ApplicationName = jobTarget.Application;
                                    eventRow.ApplicationID   = jobTarget.ApplicationID;

                                    eventRow.EventID = (long)interestingEvent["id"];
                                    eventRow.FromUtc = UnixTimeHelper.ConvertFromUnixTimestamp((long)interestingEvent["startTimeInMillis"]);
                                    eventRow.From    = eventRow.FromUtc.ToLocalTime();
                                    if ((long)interestingEvent["endTimeInMillis"] > 0)
                                    {
                                        eventRow.ToUtc = UnixTimeHelper.ConvertFromUnixTimestamp((long)interestingEvent["endTimeInMillis"]);
                                        eventRow.To    = eventRow.FromUtc.ToLocalTime();
                                    }
                                    eventRow.Status    = interestingEvent["incidentStatus"].ToString();
                                    eventRow.Severity  = interestingEvent["severity"].ToString();
                                    eventRow.EventLink = String.Format(DEEPLINK_INCIDENT, eventRow.Controller, eventRow.ApplicationID, eventRow.EventID, interestingEvent["startTimeInMillis"], DEEPLINK_THIS_TIMERANGE);;

                                    eventRow.Description = interestingEvent["description"].ToString();

                                    if (interestingEvent["triggeredEntityDefinition"].HasValues == true)
                                    {
                                        eventRow.HealthRuleID   = (int)interestingEvent["triggeredEntityDefinition"]["entityId"];
                                        eventRow.HealthRuleName = interestingEvent["triggeredEntityDefinition"]["name"].ToString();
                                        // TODO the health rule can't be hotlinked to until platform rewrites the screen that opens from Flash
                                        eventRow.HealthRuleLink = String.Format(DEEPLINK_HEALTH_RULE, eventRow.Controller, eventRow.ApplicationID, eventRow.HealthRuleID, DEEPLINK_THIS_TIMERANGE);
                                    }

                                    if (interestingEvent["affectedEntityDefinition"].HasValues == true)
                                    {
                                        eventRow.EntityID   = (int)interestingEvent["affectedEntityDefinition"]["entityId"];
                                        eventRow.EntityName = interestingEvent["affectedEntityDefinition"]["name"].ToString();

                                        string entityType = interestingEvent["affectedEntityDefinition"]["entityType"].ToString();
                                        if (entityTypeStringMapping.ContainsKey(entityType) == true)
                                        {
                                            eventRow.EntityType = entityTypeStringMapping[entityType];
                                        }
                                        else
                                        {
                                            eventRow.EntityType = entityType;
                                        }

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

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

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

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

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

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

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

                                    eventRow.ControllerLink  = String.Format(DEEPLINK_CONTROLLER, eventRow.Controller, DEEPLINK_THIS_TIMERANGE);
                                    eventRow.ApplicationLink = String.Format(DEEPLINK_APPLICATION, eventRow.Controller, eventRow.ApplicationID, DEEPLINK_THIS_TIMERANGE);

                                    healthRuleViolationList.Add(eventRow);
                                }
                            }
                        }

                        loggerConsole.Info("{0} events", 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.HealthRuleViolationsIndexFilePath(jobTarget));

                        #endregion

                        #region Events

                        loggerConsole.Info("Index events");

                        List <Event> eventsList = new List <Event>();
                        foreach (string eventType in EVENT_TYPES)
                        {
                            loggerConsole.Info("Type {0} events", eventType);

                            if (File.Exists(FilePathMap.EventsDataFilePath(jobTarget, eventType)))
                            {
                                JArray eventsInHour = FileIOHelper.LoadJArrayFromFile(FilePathMap.EventsDataFilePath(jobTarget, eventType));
                                if (eventsInHour != null)
                                {
                                    foreach (JObject interestingEvent in eventsInHour)
                                    {
                                        Event eventRow = new Event();
                                        eventRow.Controller      = jobTarget.Controller;
                                        eventRow.ApplicationName = jobTarget.Application;
                                        eventRow.ApplicationID   = jobTarget.ApplicationID;

                                        eventRow.EventID     = (long)interestingEvent["id"];
                                        eventRow.OccurredUtc = UnixTimeHelper.ConvertFromUnixTimestamp((long)interestingEvent["eventTime"]);
                                        eventRow.Occurred    = eventRow.OccurredUtc.ToLocalTime();
                                        eventRow.Type        = interestingEvent["type"].ToString();
                                        eventRow.SubType     = interestingEvent["subType"].ToString();
                                        eventRow.Severity    = interestingEvent["severity"].ToString();
                                        eventRow.EventLink   = interestingEvent["deepLinkUrl"].ToString();
                                        eventRow.Summary     = interestingEvent["summary"].ToString();

                                        if (interestingEvent["triggeredEntity"].HasValues == true)
                                        {
                                            eventRow.TriggeredEntityID   = (int)interestingEvent["triggeredEntity"]["entityId"];
                                            eventRow.TriggeredEntityName = interestingEvent["triggeredEntity"]["name"].ToString();
                                            string entityType = interestingEvent["triggeredEntity"]["entityType"].ToString();
                                            if (entityTypeStringMapping.ContainsKey(entityType) == true)
                                            {
                                                eventRow.TriggeredEntityType = entityTypeStringMapping[entityType];
                                            }
                                            else
                                            {
                                                eventRow.TriggeredEntityType = entityType;
                                            }
                                        }

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

                                            case ENTITY_TYPE_FLOWMAP_TIER:
                                                eventRow.TierID   = (int)affectedEntity["entityId"];
                                                eventRow.TierName = affectedEntity["name"].ToString();
                                                break;

                                            case ENTITY_TYPE_FLOWMAP_NODE:
                                                eventRow.NodeID   = (int)affectedEntity["entityId"];
                                                eventRow.NodeName = affectedEntity["name"].ToString();
                                                break;

                                            case ENTITY_TYPE_FLOWMAP_MACHINE:
                                                eventRow.MachineID   = (int)affectedEntity["entityId"];
                                                eventRow.MachineName = affectedEntity["name"].ToString();
                                                break;

                                            case ENTITY_TYPE_FLOWMAP_BUSINESS_TRANSACTION:
                                                eventRow.BTID   = (int)affectedEntity["entityId"];
                                                eventRow.BTName = affectedEntity["name"].ToString();
                                                break;

                                            case ENTITY_TYPE_FLOWMAP_HEALTH_RULE:
                                                eventRow.TriggeredEntityID   = (int)affectedEntity["entityId"];
                                                eventRow.TriggeredEntityType = entityTypeStringMapping[affectedEntity["entityType"].ToString()];
                                                eventRow.TriggeredEntityName = affectedEntity["name"].ToString();
                                                break;

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

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

                                        eventsList.Add(eventRow);
                                    }
                                }
                            }
                        }
                        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.EventsIndexFilePath(jobTarget));

                        #endregion

                        #region Application

                        List <EntityApplication> applicationList = FileIOHelper.ReadListFromCSVFile <EntityApplication>(FilePathMap.ApplicationIndexFilePath(jobTarget), new ApplicationEntityReportMap());
                        if (applicationList != null && applicationList.Count > 0)
                        {
                            EntityApplication applicationsRow = applicationList[0];

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

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

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

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

                            FileIOHelper.WriteListToCSVFile(applicationList, new ApplicationEventReportMap(), FilePathMap.ApplicationEventsIndexFilePath(jobTarget));
                        }

                        #endregion

                        #region Combine All for Report CSV

                        // If it is the first one, clear out the combined folder
                        if (i == 0)
                        {
                            FileIOHelper.DeleteFolder(FilePathMap.EventsReportFolderPath());
                            Thread.Sleep(1000);
                            FileIOHelper.CreateFolder(FilePathMap.EventsReportFolderPath());
                        }

                        // Append all the individual application files into one
                        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.HealthRuleViolationsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.HealthRuleViolationsIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.HealthRuleViolationsReportFilePath(), FilePathMap.HealthRuleViolationsIndexFilePath(jobTarget));
                        }
                        if (File.Exists(FilePathMap.EventsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.EventsIndexFilePath(jobTarget)).Length > 0)
                        {
                            FileIOHelper.AppendTwoCSVFiles(FilePathMap.EventsReportFilePath(), FilePathMap.EventsIndexFilePath(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);
            }
        }
Пример #34
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);
                }

                // 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);

                        #region All Dashboards

                        // Set up controller access
                        string allDashboardsJSON = String.Empty;
                        using (ControllerApi controllerApi = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword)))
                        {
                            controllerApi.PrivateApiLogin();

                            loggerConsole.Info("All Dashboards");

                            allDashboardsJSON = controllerApi.GetControllerDashboards();
                            if (allDashboardsJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(allDashboardsJSON, FilePathMap.ControllerDashboards(jobTarget));
                            }
                        }

                        #endregion

                        #region Dashboards

                        if (allDashboardsJSON != String.Empty)
                        {
                            JArray allDashboardsArray = JArray.Parse(allDashboardsJSON);

                            loggerConsole.Info("Dashboards ({0} entities)", allDashboardsArray.Count);

                            int numDashboards = 0;

                            var listOfDashboardsChunks = allDashboardsArray.BreakListIntoChunks(DASHBOARDS_EXTRACT_NUMBER_OF_ENTITIES_TO_PROCESS_PER_THREAD);

                            Parallel.ForEach <List <JToken>, int>(
                                listOfDashboardsChunks,
                                new ParallelOptions {
                                MaxDegreeOfParallelism = DASHBOARDS_EXTRACT_NUMBER_OF_THREADS
                            },
                                () => 0,
                                (listOfDashboardsChunk, loop, subtotal) =>
                            {
                                // Set up controller access
                                using (ControllerApi controllerApiParallel = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword)))
                                {
                                    controllerApiParallel.PrivateApiLogin();

                                    foreach (JObject dashboardObject in listOfDashboardsChunk)
                                    {
                                        if (File.Exists(FilePathMap.ControllerDashboard(jobTarget, dashboardObject["name"].ToString(), (long)dashboardObject["id"])) == false)
                                        {
                                            string dashboardJSON = controllerApiParallel.GetControllerDashboard((long)dashboardObject["id"]);
                                            if (dashboardJSON != String.Empty)
                                            {
                                                FileIOHelper.SaveFileToPath(dashboardJSON, FilePathMap.ControllerDashboard(jobTarget, dashboardObject["name"].ToString(), (long)dashboardObject["id"]));
                                            }
                                        }
                                    }
                                    return(listOfDashboardsChunk.Count);
                                }
                            },
                                (finalResult) =>
                            {
                                Interlocked.Add(ref numDashboards, finalResult);
                                Console.Write("[{0}].", numDashboards);
                            }
                                );

                            loggerConsole.Info("Completed {0} Dashboards", allDashboardsArray.Count);

                            stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + allDashboardsArray.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);
                    }

                    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);
            }
        }
Пример #35
0
 public virtual bool ShouldExecute(ProgramOptions programOptions)
 {
     return(false);
 }
Пример #36
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);
                }

                // 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

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

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

                            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");

                            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,
                                         new ParallelOptions {
                                MaxDegreeOfParallelism = FLOWMAP_EXTRACT_NUMBER_OF_THREADS
                            },
                                         () => 0,
                                         (minute, loop, subtotal) =>
                            {
                                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.TiersDataFilePath(jobTarget));
                            if (tiersList != null)
                            {
                                loggerConsole.Info("Extract Flowmaps for Tiers ({0} entities)", tiersList.Count);

                                int j = 0;

                                Parallel.ForEach(
                                    tiersList,
                                    new ParallelOptions {
                                    MaxDegreeOfParallelism = FLOWMAP_EXTRACT_NUMBER_OF_THREADS
                                },
                                    () => 0,
                                    (tier, loop, subtotal) =>
                                {
                                    ControllerApi controllerApi = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword));
                                    controllerApi.PrivateApiLogin();

                                    if (File.Exists(FilePathMap.TierFlowmapDataFilePath(jobTarget, jobConfiguration.Input.TimeRange, tier)) == false)
                                    {
                                        string flowmapJson = controllerApi.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.NodesDataFilePath(jobTarget));
                            if (nodesList != null)
                            {
                                loggerConsole.Info("Extract Flowmaps for Nodes ({0} entities)", nodesList.Count);

                                int j = 0;

                                Parallel.ForEach(
                                    nodesList,
                                    new ParallelOptions {
                                    MaxDegreeOfParallelism = FLOWMAP_EXTRACT_NUMBER_OF_THREADS
                                },
                                    () => 0,
                                    (node, loop, subtotal) =>
                                {
                                    ControllerApi controllerApi = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword));
                                    controllerApi.PrivateApiLogin();

                                    if (File.Exists(FilePathMap.NodeFlowmapDataFilePath(jobTarget, jobConfiguration.Input.TimeRange, node)) == false)
                                    {
                                        string flowmapJson = controllerApi.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.BackendsDataFilePath(jobTarget));
                            if (backendsList != null)
                            {
                                loggerConsole.Info("Extract Flowmaps for Backends ({0} entities)", backendsList.Count);

                                int j = 0;

                                Parallel.ForEach(
                                    backendsList,
                                    new ParallelOptions {
                                    MaxDegreeOfParallelism = FLOWMAP_EXTRACT_NUMBER_OF_THREADS
                                },
                                    () => 0,
                                    (backend, loop, subtotal) =>
                                {
                                    ControllerApi controllerApi = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword));
                                    controllerApi.PrivateApiLogin();

                                    if (File.Exists(FilePathMap.BackendFlowmapDataFilePath(jobTarget, jobConfiguration.Input.TimeRange, backend)) == false)
                                    {
                                        string flowmapJson = controllerApi.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.BusinessTransactionsDataFilePath(jobTarget));
                            if (businessTransactionsList != null)
                            {
                                loggerConsole.Info("Extract Flowmaps for Business Transactions ({0} entities)", businessTransactionsList.Count);

                                int j = 0;

                                Parallel.ForEach(
                                    businessTransactionsList,
                                    new ParallelOptions {
                                    MaxDegreeOfParallelism = FLOWMAP_EXTRACT_NUMBER_OF_THREADS
                                },
                                    () => 0,
                                    (businessTransaction, loop, subtotal) =>
                                {
                                    ControllerApi controllerApi = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword));
                                    controllerApi.PrivateApiLogin();

                                    if (File.Exists(FilePathMap.BusinessTransactionFlowmapDataFilePath(jobTarget, jobConfiguration.Input.TimeRange, businessTransaction)) == false)
                                    {
                                        string flowmapJson = controllerApi.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);
            }
        }
Пример #37
0
        private static void RunClient(ProgramOptions options)
        {
            var display = new Display(options, options.Port) {Delay = .5.Seconds()};

            byte[] aesIV = null;

            using (var client = new TcpClient().Do(c => c.Connect(options.Host, options.Port)))
            using (var netStream = client.GetStream().Do(s => aesIV = ClientHandshake(s, options)))
            using (var compStream = options.Compression.HasValue ? new DeflateStream(netStream, CompressionMode.Decompress) : null)
            using (var aes = CreateAes(options, aesIV))
            using (var dec = aes?.CreateDecryptor())
            using (var cryptoStream = aes != null ? new CryptoStream((Stream)compStream ?? netStream, dec, CryptoStreamMode.Read) : null)
            using (var reader = new BinaryReader(cryptoStream ?? (Stream)compStream ?? netStream))
            using (var nullStream = new NullStream())
            {
                display.Stopwatch.Start();

                var buffer = new byte[Extensions.DefaultStreamCopyBufferSize];

                while (true)
                {
                    display.Refresh();

                    string path;
                    try
                    {
                        path = reader.ReadString();
                    }
                    catch (EndOfStreamException)
                    {
                        break;
                    }

                    var length = reader.ReadInt64();
                    var file = options.Directory.GetFile(path);

                    display.CurrentFile = new FileProgress(path, length).Do(x => x.Stopwatch.Start());

                    Action<long> progress = b =>
                    {
                        display.ByteCount += (display.CurrentFile.BytesTransferred = b);
                        display.Refresh();
                    };

                    var skipFile = (file.Exists && !options.Overwrite);

                    if (skipFile)
                    {
                        reader.BaseStream.CopyTo(nullStream, length, buffer, progress);
                    }
                    else
                    {
                        if (!file.Directory.Exists)
                            file.Directory.Create();

                        using (var fileStream = file.Open(FileMode.Create, FileAccess.Write, FileShare.None))
                            reader.BaseStream.CopyTo(fileStream, length, buffer, progress);
                    }

                    display.FileCount++;
                }
            }
        }
Пример #38
0
        private static void Main(string[] args)
        {
            ProgramOptions options = new ProgramOptions();

            // Parse command line options any errors and you get Usage
            if (options.ParseArgs(args) == false) ProgramOptions.Usage();

            // We must have at least 1 path to process files, else Usage and exit
            if (options.PathList.Count < 1) ProgramOptions.Usage("You must specify at least one TVShowFolder.");

            List<String> validPaths = new List<string>();

            foreach (string p in options.PathList)
            {
                Console.WriteLine("Processing: {0}", p);

                TVShowFolder f = new TVShowFolder(p);

                if (f.IsValid)
                {
                    validPaths.Add(p);
                }
                else
                {
                    Console.WriteLine("INGNORED! NOT A VALID PATH: {0}", p);
                }
            }

            // Read program options from the App.Config
            AppConfigOptions AppConfig = new AppConfigOptions();

            // Setup new search object
            TVSearcher tvSearcher = new TVSearcher(AppConfig.ApiKey);

            // Search each path
            foreach (string p in validPaths)
            {

                TVShowFolder myShow = new TVShowFolder(p);

                Console.WriteLine("Looking for show: {0}", myShow.ShowName);

                string showID;

                if (myShow.HasAssignedID)
                {
                    showID = myShow.AssignedID;
                    Console.WriteLine("Has Assigned ID: {0}", showID);
                }
                else
                {
                    TVSeries tvSearch = tvSearcher.GetSeries(myShow.ShowName);

                    if (tvSearch.IsSearchResult())
                    {
                        foreach (DataSeries s in tvSearch.Shows)
                        {
                            Console.WriteLine("Located: {0} {1} {2}", s.id, s.FirstAired, s.SeriesName);
                        }
                    }

                    if (tvSearch.Shows.Count > 1)
                    {
                        Console.WriteLine("Ambigious search for: {0}", myShow.ShowName);
                        Console.WriteLine("Create a .thetvdb.id file with the show ID as the 1st line.");
                        continue;
                    }

                    if (tvSearch.Shows.Count == 0)
                    {
                        Console.WriteLine("Unable to locate: {0}", myShow.ShowName);
                        continue;
                    }

                    showID = tvSearch.Series.id;
                }

                TVSeries tvShow = tvSearcher.GetShow(showID);

                if (!tvShow.HasEpisodes())
                {
                    Console.WriteLine("Unable to locate any episode data!");
                    continue;
                }

                if (tvShow.Series.Status == "Ended")
                {
                    Console.WriteLine("No more episodes :-( The show has ended!");
                    continue;
                }

                // Load up a list of the existing files in this folder
                TVFiles myTVFiles = new TVFiles(p);

                bool foundNewEpisode = false;

                foreach (DataEpisode de in tvShow.Episodes)
                {
                    DateTime date;

                    try
                    {
                        date = DateTime.ParseExact(de.FirstAired, "yyyy-MM-dd",
                                                   System.Globalization.CultureInfo.InvariantCulture);
                    }
                    catch
                    {
                        // Probably a blank date so it is in the future.
                        continue;
                    }

                    if (date >= DateTime.Now)
                    {
                        foundNewEpisode = true;
                        Console.WriteLine("NEXT AIR: {0}\t{1}\t{2}\t{3}x{4}\t{5}", de.FirstAired, tvShow.Series.id, tvShow.Series.SeriesName, de.SeasonNumber, de.EpisodeNumber, de.EpisodeName);
                        break;
                    }

                    if (!myTVFiles.Exist(Convert.ToInt32(de.SeasonNumber), Convert.ToInt32(de.EpisodeNumber)))
                    {
                        Console.WriteLine("MISSING!  {0}\t{1}\t{2}\t{3}x{4}\t{5}", de.FirstAired, tvShow.Series.id, tvShow.Series.SeriesName, de.SeasonNumber, de.EpisodeNumber, de.EpisodeName);
                    }

                }

                if (!foundNewEpisode)
                {
                    Console.WriteLine("Unable to locate a new episode.");
                }

            }

            Misc.PauseIfInIDE();
        }
Пример #39
0
 public void DisplayJobStepStartingStatus(ProgramOptions programOptions)
 {
     logger.Info("{0}({0:d}): Starting", programOptions.ReportJob.Status);
     loggerConsole.Trace("{0}({0:d}): Starting", programOptions.ReportJob.Status);
 }
Пример #40
0
        private static void DrawMenu()
        {
            // DRAW MENU
            TypewriterText("Create your own Game Builder world with this tool!");
            TypewriterText("What kind of map would you like to create?", autoPauseAtEnd: 0);
            TypewriterText("------------------------------------------", autoPauseAtEnd: 0);
            TypewriterText("1. Default", autoPauseAtEnd: 0);
            TypewriterText("2. Custom", autoPauseAtEnd: 0);
            //TypewriterText("2. Tunnel test", autoPauseAtEnd: 0);
            //TypewriterText("3. One big hill with lake", autoPauseAtEnd: 0);
            //TypewriterText("4. Oval lake with oval mountain", autoPauseAtEnd: 0);
            //TypewriterText("5. Many hills", autoPauseAtEnd: 0);
            TypewriterText("3. Exit", autoPauseAtEnd: 0);
            TypewriterText("> ", newlines: 0, autoPauseAtEnd: 0);

            string line   = string.Empty;
            string choice = Console.ReadLine();

            if (line.Contains("3", StringComparison.OrdinalIgnoreCase))
            {
                Environment.Exit(0);
            }
            TypewriterText("", 2, autoPauseAtEnd: 0);
            TypewriterText("(To choose any default values, simply hit 'Enter')", autoPauseAtEnd: 0);

            // GET MAP GEN OPTIONS
            int    itemp;
            float  ftemp;
            double dtemp;

            try
            {
                ProgramOptions programOptions         = new ProgramOptions();
                string         programOptionsString   = string.Empty;
                string         programOptionsFilepath = Path.Combine(Directory.GetCurrentDirectory(), ProgramOptions.FILENAME);
                if (File.Exists(programOptionsFilepath))
                {
                    using (StreamReader streamReader = new StreamReader(Path.Combine(Directory.GetCurrentDirectory(), ProgramOptions.FILENAME)))
                    {
                        programOptionsString = streamReader.ReadToEnd();
                    }
                    programOptions = JsonConvert.DeserializeObject <ProgramOptions>(programOptionsString);
                }


                int width  = (programOptions != null && programOptions.Width != default(int)) ? programOptions.Width : 250; // in .voos units
                int length = (programOptions != null && programOptions.Length != default(int)) ? programOptions.Length : 250;
                MapGeneratorOptions mapOptions = new MapGeneratorOptions();
                string mapName         = $"CustomMap-{DateTime.Now.ToString("MM_dd_yyyy hh_mm tt")}";
                string mapDesc         = string.Empty;
                string outputDirectory = Romans828 ? @"D:\Program Files (x86)\Steam\steamapps\common\Game Builder\GameBuilderUserData\Games" : (programOptions != null && !string.IsNullOrEmpty(programOptions.SaveTo)) ? programOptions.SaveTo : Directory.GetCurrentDirectory();


                TypewriterText($"How wide would you like your map to be [{width}=DEFAULT])? > ", newlines: 0, autoPauseAtEnd: 0);
                line = Console.ReadLine();
                if (int.TryParse(line, out itemp))
                {
                    width = itemp;
                }

                TypewriterText($"How deep would you like your map to be [{length}=DEFAULT])? > ", newlines: 0, autoPauseAtEnd: 0);
                line = Console.ReadLine();
                if (int.TryParse(line, out itemp))
                {
                    length = itemp;
                }

                TypewriterText($"Would you like to give your map a name ['{mapName}'=DEFAULT])? > ", newlines: 0, autoPauseAtEnd: 0);
                line = Console.ReadLine();
                if (!string.IsNullOrEmpty(line))
                {
                    mapName = line;
                }

                TypewriterText($"Would you like to give your map a description? > ", newlines: 0, autoPauseAtEnd: 0);
                line = Console.ReadLine();
                if (!string.IsNullOrEmpty(line))
                {
                    mapDesc = line;
                }

                TypewriterText($"Where would you like us to save your map ['{outputDirectory}'=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                line = Console.ReadLine();
                if (!string.IsNullOrEmpty(line))
                {
                    outputDirectory = line;
                }

                string[] biomeNames = mapOptions.BiomeNames();
                for (int i = 0; i < biomeNames.Length; i++)
                {
                    biomeNames[i] = $"'{biomeNames[i][0]}'{biomeNames[i].Substring(1)}={Enum.Parse(mapOptions.Biome.GetType(), biomeNames[i])}";
                }
                TypewriterText($"What would you like your biome to be [{mapOptions.EnumName(mapOptions.Biome)}=DEFAULT ({string.Join(',', biomeNames)})]? > ", newlines: 0, autoPauseAtEnd: 0);
                line = Console.ReadLine();

                if (!string.IsNullOrEmpty(line))
                {
                    if (line.Contains("g", StringComparison.OrdinalIgnoreCase))
                    {
                        mapOptions.Biome = MapGeneratorOptions.MapBiome.Grassland;
                    }
                    else if (line.Contains("d", StringComparison.OrdinalIgnoreCase))
                    {
                        mapOptions.Biome = MapGeneratorOptions.MapBiome.Desert;
                    }
                    else if (line.Contains("t", StringComparison.OrdinalIgnoreCase))
                    {
                        mapOptions.Biome = MapGeneratorOptions.MapBiome.Tundra;
                    }
                }

                if (choice.Contains("2", StringComparison.OrdinalIgnoreCase))
                {
                    TypewriterText($"What would you like your plain frequency to be [{mapOptions.PlainFrequency}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                    line = Console.ReadLine();

                    if (!string.IsNullOrEmpty(line))
                    {
                        if (float.TryParse(line, out ftemp))
                        {
                            mapOptions.PlainFrequency = ftemp;
                        }
                    }

                    // Lakes
                    TypewriterText($"Would you like lakes [{mapOptions.Lakes}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                    line = Console.ReadLine();

                    if (!string.IsNullOrEmpty(line))
                    {
                        if (line.Contains("1") || line.Contains("y", StringComparison.OrdinalIgnoreCase))
                        {
                            mapOptions.Lakes = true;
                        }
                        else
                        {
                            mapOptions.Lakes = false;
                        }
                    }

                    if (mapOptions.Lakes)
                    {
                        TypewriterText($"What would you like your lake frequency to be [{mapOptions.LakeFrequency}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                        line = Console.ReadLine();

                        if (!string.IsNullOrEmpty(line))
                        {
                            if (float.TryParse(line, out ftemp))
                            {
                                mapOptions.LakeFrequency = ftemp;
                            }
                        }

                        TypewriterText($"What would you like your lake size to be [{mapOptions.LakeSize}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                        line = Console.ReadLine();

                        if (!string.IsNullOrEmpty(line))
                        {
                            if (int.TryParse(line, out itemp))
                            {
                                mapOptions.LakeSize = itemp;
                            }
                        }
                    }

                    // Hills
                    TypewriterText($"Would you like hills [{mapOptions.Hills}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                    line = Console.ReadLine();

                    if (!string.IsNullOrEmpty(line))
                    {
                        if (line.Contains("1") || line.Contains("y", StringComparison.OrdinalIgnoreCase))
                        {
                            mapOptions.Hills = true;
                        }
                        else
                        {
                            mapOptions.Hills = false;
                        }
                    }

                    if (mapOptions.Hills)
                    {
                        TypewriterText($"What would you like your hill frequency to be [{mapOptions.HillFrequency}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                        line = Console.ReadLine();

                        if (!string.IsNullOrEmpty(line))
                        {
                            if (float.TryParse(line, out ftemp))
                            {
                                mapOptions.HillFrequency = ftemp;
                            }
                        }

                        TypewriterText($"What would you like your hill clamp to be [{mapOptions.HillClamp}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                        line = Console.ReadLine();

                        if (!string.IsNullOrEmpty(line))
                        {
                            if (int.TryParse(line, out itemp))
                            {
                                mapOptions.HillClamp = itemp;
                            }
                        }
                    }

                    // Mountains
                    TypewriterText($"Would you like mountains [{mapOptions.Mountains}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                    line = Console.ReadLine();

                    if (!string.IsNullOrEmpty(line))
                    {
                        if (line.Contains("1") || line.Contains("y", StringComparison.OrdinalIgnoreCase))
                        {
                            mapOptions.Mountains = true;
                        }
                        else
                        {
                            mapOptions.Mountains = false;
                        }
                    }

                    if (mapOptions.Mountains)
                    {
                        TypewriterText($"What would you like your mountain frequency to be [{mapOptions.MountainFrequency}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                        line = Console.ReadLine();

                        if (!string.IsNullOrEmpty(line))
                        {
                            if (float.TryParse(line, out ftemp))
                            {
                                mapOptions.MountainFrequency = ftemp;
                            }
                        }

                        TypewriterText($"What would you like your additional mountain size to be [{mapOptions.AdditionalMountainSize}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                        line = Console.ReadLine();

                        if (!string.IsNullOrEmpty(line))
                        {
                            if (double.TryParse(line, out dtemp))
                            {
                                mapOptions.AdditionalMountainSize = dtemp;
                            }
                        }
                    }
                }

                TypewriterText("", 2);

                if (string.IsNullOrEmpty(mapDesc))
                {
                    mapDesc = $"Map specs => ({width}x{length}) {mapOptions.ToString()} -Built with love by Romans 8:28.";
                }

                // CREATE MAP
                // convert back to proper unit
                width  = (int)Math.Floor(width / 2.5d);
                length = (int)Math.Floor(length / 2.5d);
                BaseGenerator <short> generator = new MapGenerator((short)width, (short)length, 1, mapOptions);
                Map           map           = (Map)generator.GenerateMap();
                VoosGenerator voosGenerator = new VoosGenerator();
                voosGenerator.Generate(map, outputDirectory, mapName, mapDesc);

                TypewriterText("");
            }
            catch (Exception ex)
            {
                TypewriterText("Oops! An error occurred.", autoPauseAtEnd: 0);
                TypewriterText("Please send an entire copy of your console window to Romans 8:28 on the discord server to debug and fix this.", newlines: 2, autoPauseAtEnd: 0);
                TypewriterText($"{ex.Message}", autoPauseAtEnd: 0);
                TypewriterText($"{ex.StackTrace}", autoPauseAtEnd: 0);

                Console.ReadKey();
                Environment.Exit(0);
            }

            TypewriterText("Your map was successfully created!");
            TypewriterText("Have a nice day!");
            TypewriterText("");
            TypewriterText("Press any key to exit...");
            Console.ReadKey();
            Environment.Exit(0);
        }
Пример #41
0
        static void Main(string[] args)
        {
            try
            {
                // Output current wallpaper details
                if (args.Length == 0)
                {
                    Console.WriteLine("Current Wallpaper ");
                    Console.WriteLine("\t Filepath: \"{0}\"", WallpaperInterop.GetWallpaperFilepath());
                    Console.WriteLine("\t Position: {0}",     WallpaperInterop.GetWallpaperPosition());
                    Console.WriteLine("Current login background ");
                    Console.WriteLine("\t Filepath: \"{0}\"", WallpaperInterop.GetLoginBGFilepath());
                }
                // Output usage info
                else if (args.Contains("/?")) {
                    Program.printUsage();
                }
                // Handle just next background
                else if (args[0] == "/next") {
                    SlideshowHelper.NextBackground();
                }
                // Handle just endshow
                else if (args[0] == "/endshow")
                {
                    SlideshowHelper.CancelSlideshow();
                }
                else if (args[0] == "/login")
                {
                    if (args.Length == 1) Program.errorOut("Expected path for option '/login'");
                    WallpaperInterop.SetLoginBG(args[1]);
                }
                // Perform wallpaper change
                else
                {
                    string path = args[0];
                    var opts = new ProgramOptions(args);

                    // End show as requested
                    if (opts.EndShow)
                    {
                        SlideshowHelper.CancelSlideshow();
                    }
                    if (opts.Slideshow)
                    {
                        // Begin slideshow
                        SlideshowHelper.BeginSlideshow(path, opts.Position,
                            opts.ShowInterval, opts.ShowIndex);
                    }
                    else
                    {
                        // Get random image if selecting from directory
                        if (opts.Directory)
                        {
                            string[] walls = SlideshowHelper.GetBackgroundsInFolder(path);
                            path = walls[new Random().Next(0, walls.Length)];
                        }
                        // Call interop code
                        WallpaperInterop.SetWallpaper(path, opts.Position, opts.Copy);
                    }

                }
            }
            catch (Exception e) {
                errorOut(e.Message);
            }
        }
        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_BIQ) == 0)
                {
                    logger.Warn("No {0} targets to process", APPLICATION_TYPE_BIQ);
                    loggerConsole.Warn("No {0} targets to process", APPLICATION_TYPE_BIQ);

                    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_BIQ)
                    {
                        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 Saved Search

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

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

                            getMetricsForEntities(jobTarget, jobConfiguration, entityMetricExtractMappingList, BIQBusinessJourney.ENTITY_FOLDER, BIQBusinessJourney.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);
            }
        }
Пример #43
0
 public static bool LoadOptions()
 {
     try
     {
         XmlSerializer serializer = new XmlSerializer(typeof(ProgramOptions));
         using (FileStream file = File.OpenRead("BFGFontTool.cfg"))
         {
             programOptions = (ProgramOptions)serializer.Deserialize(file);
         }
         return true;
     }
     catch
     {
         return false;
     }
 }
Пример #44
0
        public override bool Execute(ProgramOptions programOptions)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            StepTiming stepTimingFunction = new StepTiming();

            stepTimingFunction.JobFileName = programOptions.ReportJobFilePath;
            stepTimingFunction.StepName    = programOptions.ReportJob.Status.ToString();
            stepTimingFunction.StepID      = (int)programOptions.ReportJob.Status;
            stepTimingFunction.StartTime   = DateTime.Now;
            stepTimingFunction.NumEntities = 0;

            this.DisplayJobStepStartingStatus(programOptions);

            this.FilePathMap = new FilePathMap(programOptions);

            try
            {
                FileIOHelper.CreateFolder(this.FilePathMap.Report_FolderPath());
                FileIOHelper.CreateFolder(this.FilePathMap.Report_Grant_FolderPath());
                FileIOHelper.CreateFolder(this.FilePathMap.Report_Role_FolderPath());

                #region Grants OF - Members of Roles (Roles and Users)

                loggerConsole.Info("Process Grants OF");

                List <RoleMember> grantsOfRolesAndUsersList = FileIOHelper.ReadListFromCSVFile <RoleMember>(FilePathMap.Data_RoleShowGrantsOf_FilePath(), new RoleMemberShowGrantsMap(), "No data returned");
                if (grantsOfRolesAndUsersList != null)
                {
                    foreach (RoleMember roleMember in grantsOfRolesAndUsersList)
                    {
                        // Unescape special names of roles
                        roleMember.Name      = roleMember.Name.Trim('"');
                        roleMember.GrantedTo = roleMember.GrantedTo.Trim('"');
                        roleMember.GrantedBy = roleMember.GrantedBy.Trim('"');
                    }

                    grantsOfRolesAndUsersList = grantsOfRolesAndUsersList.OrderBy(g => g.ObjectType).ThenBy(g => g.Name).ToList();

                    FileIOHelper.WriteListToCSVFile <RoleMember>(grantsOfRolesAndUsersList, new RoleMemberMap(), FilePathMap.Report_RoleMember_FilePath());
                }

                #endregion

                #region Grants ON and Grants TO grants for everything

                loggerConsole.Info("Process Grants ON and TO");

                List <Grant> grantsOnRolesList = FileIOHelper.ReadListFromCSVFile <Grant>(FilePathMap.Data_RoleShowGrantsOn_FilePath(), new GrantShowGrantsMap(), "No data returned");
                List <Grant> grantsToRolesList = FileIOHelper.ReadListFromCSVFile <Grant>(FilePathMap.Data_RoleShowGrantsTo_FilePath(), new GrantShowGrantsMap(), "No data returned");

                if (grantsOnRolesList != null && grantsToRolesList != null)
                {
                    loggerConsole.Info("Loaded {0} ON + {1} TO = {2} grants", grantsOnRolesList.Count, grantsToRolesList.Count, grantsOnRolesList.Count + grantsToRolesList.Count);

                    // Combine both ON and TO into one list
                    List <Grant> grantsNonUniqueList = new List <Grant>(grantsOnRolesList.Count + grantsToRolesList.Count);
                    grantsNonUniqueList.AddRange(grantsOnRolesList);
                    grantsNonUniqueList.AddRange(grantsToRolesList);

                    #region Remove duplicates

                    loggerConsole.Info("Removing duplicate grants");

                    // Now remove duplicate USAGE and OWNERSHIP rows using these kinds of IDs
                    // OWNERSHIP-ROLE-AAD_PROVISIONER-USERADMIN-USERADMIN
                    // USAGE-ROLE-AAD_PROVISIONER-USERADMIN-USERADMIN
                    // These occur only on ROLEs and because a role in hierarchy can be seen when parent says SHOW GRANTS ON and child says SHOW GRANTS TO
                    List <Grant> grantsUniqueList    = new List <Grant>(grantsNonUniqueList.Count);
                    var          uniqueGrantsGrouped = grantsNonUniqueList.GroupBy(g => g.UniqueIdentifier);
                    foreach (var group in uniqueGrantsGrouped)
                    {
                        grantsUniqueList.Add(group.First());
                    }

                    // Unescape special names of objects
                    foreach (Grant grant in grantsUniqueList)
                    {
                        grant.GrantedTo = grant.GrantedTo.Trim('"');
                        grant.GrantedBy = grant.GrantedBy.Trim('"');
                    }

                    grantsUniqueList = grantsUniqueList.OrderBy(g => g.ObjectType).ThenBy(g => g.ObjectName).ThenBy(g => g.GrantedTo).ToList();
                    FileIOHelper.WriteListToCSVFile <Grant>(grantsUniqueList, new GrantMap(), FilePathMap.Report_RoleGrant_FilePath());

                    #endregion

                    #region Individual Object Types

                    loggerConsole.Info("Processing individual Object Types");

                    // Break them up by the type
                    var groupObjectTypesGrouped            = grantsUniqueList.GroupBy(g => g.ObjectType);
                    List <SingleStringRow> objectTypesList = new List <SingleStringRow>(groupObjectTypesGrouped.Count());
                    foreach (var group in groupObjectTypesGrouped)
                    {
                        loggerConsole.Info("Processing grants for {0}", group.Key);

                        SingleStringRow objectType = new SingleStringRow();
                        objectType.Value = group.Key;
                        objectTypesList.Add(objectType);

                        #region Save this set of grants for Object Type

                        List <Grant> grantsOfObjectTypeList = group.ToList();

                        // Save this set as is for one of the tables in report
                        FileIOHelper.WriteListToCSVFile <Grant>(grantsOfObjectTypeList, new GrantMap(), FilePathMap.Report_RoleGrant_ObjectType_FilePath(group.Key));

                        // Pivot each section into this kind of table
                        //
                        // ObjectType | ObjectName | GrantedTo | OWNERSHIP | USAGE | REFERENCE | GrantN
                        // DATABASE   | SomeDB     | SomeRole  | X         | x+    |           |
                        // Where X+ means WithGrantOption=True
                        //       X  means WithGrantOption=False
                        List <ObjectTypeGrant>   objectGrantsList            = new List <ObjectTypeGrant>(grantsOfObjectTypeList.Count / 5);
                        Dictionary <string, int> privilegeToColumnDictionary = new Dictionary <string, int>(20);

                        #endregion

                        #region Convert this set into pivot

                        List <string> listOfPrivileges = grantsOfObjectTypeList.Select(g => g.Privilege).Distinct().OrderBy(g => g).ToList();

                        // Make USAGE and OWNERSHIP be the first columns
                        switch (group.Key)
                        {
                        case "ACCOUNT":
                            break;

                        case "DATABASE":
                        case "FILE_FORMAT":
                        case "FUNCTION":
                        case "INTEGRATION":
                        case "PROCEDURE":
                        case "ROLE":
                        case "SCHEMA":
                        case "SEQUENCE":
                        case "WAREHOUSE":
                            listOfPrivileges.Remove("OWNERSHIP");
                            listOfPrivileges.Insert(0, "OWNERSHIP");
                            listOfPrivileges.Remove("USAGE");
                            listOfPrivileges.Insert(1, "USAGE");
                            break;

                        case "EXTERNAL_TABLE":
                        case "MANAGED_ACCOUNT":
                        case "MASKING_POLICY":
                        case "MATERIALIZED_VIEW":
                        case "NETWORK_POLICY":
                        case "NOTIFICATION_SUBSCRIPTION":
                        case "PIPE":
                        case "RESOURCE_MONITOR":
                        case "SHARE":
                        case "STAGE":
                        case "STREAM":
                        case "TABLE":
                        case "TASK":
                        case "USER":
                        case "VIEW":
                            listOfPrivileges.Remove("OWNERSHIP");
                            listOfPrivileges.Insert(0, "OWNERSHIP");
                            break;

                        default:
                            break;
                        }
                        for (int i = 0; i < listOfPrivileges.Count; i++)
                        {
                            privilegeToColumnDictionary.Add(listOfPrivileges[i], i);
                        }

                        ObjectTypeGrant latestGrantRow = new ObjectTypeGrant();
                        foreach (Grant grant in grantsOfObjectTypeList)
                        {
                            // Loop through rows, starting new objects for each combination of ObjectType+ObjectName+GrantedTo when necessary
                            // ObjectType is always the same in this grouping
                            // ObjectName
                            if (latestGrantRow.ObjectType != grant.ObjectType ||
                                latestGrantRow.ObjectName != grant.ObjectName ||
                                latestGrantRow.GrantedTo != grant.GrantedTo)
                            {
                                // Need to start new row
                                latestGrantRow            = new ObjectTypeGrant();
                                latestGrantRow.ObjectType = grant.ObjectType;
                                latestGrantRow.ObjectName = grant.ObjectName;
                                latestGrantRow.DBName     = grant.DBName;
                                latestGrantRow.SchemaName = grant.SchemaName;
                                latestGrantRow.EntityName = grant.EntityName;
                                latestGrantRow.GrantedTo  = grant.GrantedTo;

                                objectGrantsList.Add(latestGrantRow);
                            }

                            // Find out which column to use
                            int privilegeColumnNumber = privilegeToColumnDictionary[grant.Privilege];

                            switch (privilegeColumnNumber)
                            {
                            case 0:
                                latestGrantRow.Privilege0 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 1:
                                latestGrantRow.Privilege1 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 2:
                                latestGrantRow.Privilege2 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 3:
                                latestGrantRow.Privilege3 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 4:
                                latestGrantRow.Privilege4 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 5:
                                latestGrantRow.Privilege5 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 6:
                                latestGrantRow.Privilege6 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 7:
                                latestGrantRow.Privilege7 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 8:
                                latestGrantRow.Privilege8 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 9:
                                latestGrantRow.Privilege9 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 10:
                                latestGrantRow.Privilege10 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 11:
                                latestGrantRow.Privilege11 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 12:
                                latestGrantRow.Privilege12 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 13:
                                latestGrantRow.Privilege13 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 14:
                                latestGrantRow.Privilege14 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 15:
                                latestGrantRow.Privilege15 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 16:
                                latestGrantRow.Privilege16 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 17:
                                latestGrantRow.Privilege17 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 18:
                                latestGrantRow.Privilege18 = grant.DisplaySettingWithGrantOption;
                                break;

                            case 19:
                                latestGrantRow.Privilege19 = grant.DisplaySettingWithGrantOption;
                                break;

                            default:
                                // Can't fit more than 20 privileges
                                logger.Warn("More then 20 Privileges reached with {0} privilege for object type {1}", grant.Privilege, grant.ObjectType);
                                break;
                            }
                        }

                        List <string> privilegeColumnNames = new List <string>(privilegeToColumnDictionary.Count);
                        for (int i = 0; i < privilegeToColumnDictionary.Count; i++)
                        {
                            privilegeColumnNames.Add(String.Empty);
                        }
                        foreach (var entry in privilegeToColumnDictionary)
                        {
                            privilegeColumnNames[entry.Value] = entry.Key;
                        }

                        // Save the pivot
                        FileIOHelper.WriteListToCSVFile <ObjectTypeGrant>(objectGrantsList, new ObjectTypeGrantMap(privilegeColumnNames), FilePathMap.Report_RoleGrant_ObjectType_Pivoted_FilePath(group.Key));

                        #endregion
                    }

                    FileIOHelper.WriteListToCSVFile <SingleStringRow>(objectTypesList, new SingleStringRowMap(), FilePathMap.Report_RoleGrant_ObjectTypes_FilePath());

                    #endregion
                }

                #endregion

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

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

                this.DisplayJobStepEndedStatus(programOptions, 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);
            }
        }
Пример #45
0
 public FilePathMap(ProgramOptions programOptions)
 {
     this.ProgramOptions = programOptions;
 }
Пример #46
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);
                }

                // 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 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

                            // Increase timeout of the extraction requests to quite a bit more for wider time ranges
                            controllerApi.Timeout = 3;

                            #region License assignments and consumption

                            loggerConsole.Info("Account ID");

                            long   accountID     = -1;
                            string myAccountJSON = controllerApi.GetAccountsMyAccount();
                            if (myAccountJSON != String.Empty)
                            {
                                JObject myAccount = JObject.Parse(myAccountJSON);
                                if (myAccount != null)
                                {
                                    accountID = getLongValueFromJToken(myAccount, "id");
                                }
                            }

                            loggerConsole.Info("License Modules");

                            string licenseModulesJSON = controllerApi.GetLicenseModules(accountID);
                            if (licenseModulesJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(licenseModulesJSON, FilePathMap.LicenseModulesDataFilePath(jobTarget));
                            }

                            if (licenseModulesJSON != String.Empty)
                            {
                                JObject licenseModulesContainer = JObject.Parse(licenseModulesJSON);
                                if (licenseModulesContainer != null &&
                                    isTokenPropertyNull(licenseModulesContainer, "modules") == false)
                                {
                                    JArray licenseModulesArray = (JArray)licenseModulesContainer["modules"];
                                    foreach (JObject licenseModuleObject in licenseModulesArray)
                                    {
                                        string licenseModuleName = getStringValueFromJToken(licenseModuleObject, "name");
                                        loggerConsole.Info("License Module - {0}", licenseModuleName);

                                        string licenseModulePropertiesJSON = controllerApi.GetLicenseModuleProperties(accountID, licenseModuleName);
                                        if (licenseModulePropertiesJSON != String.Empty)
                                        {
                                            FileIOHelper.SaveFileToPath(licenseModulePropertiesJSON, FilePathMap.LicenseModulePropertiesDataFilePath(jobTarget, licenseModuleName));
                                        }

                                        string licenseModuleUsagesJSON = controllerApi.GetLicenseModuleUsages(accountID, licenseModuleName, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To);
                                        if (licenseModuleUsagesJSON != String.Empty)
                                        {
                                            FileIOHelper.SaveFileToPath(licenseModuleUsagesJSON, FilePathMap.LicenseModuleUsagesDataFilePath(jobTarget, licenseModuleName));
                                        }
                                    }
                                }
                            }

                            #endregion

                            #region License Rules

                            loggerConsole.Info("License Rules");

                            string licenseRulesJSON = controllerApi.GetLicenseRules();
                            if (licenseRulesJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(licenseRulesJSON, FilePathMap.LicenseRulesDataFilePath(jobTarget));
                            }

                            if (licenseRulesJSON != String.Empty)
                            {
                                JArray licenseRulesArray = JArray.Parse(licenseRulesJSON);
                                if (licenseRulesArray != null)
                                {
                                    using (ControllerApi controllerApi1 = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword)))
                                    {
                                        controllerApi1.PrivateApiLogin();

                                        foreach (JObject licenseRuleObject in licenseRulesArray)
                                        {
                                            string ruleID   = getStringValueFromJToken(licenseRuleObject, "id");
                                            string ruleName = getStringValueFromJToken(licenseRuleObject, "name");

                                            loggerConsole.Info("License Rule Configuration - {0}", ruleName);

                                            string licenseRuleDetailsJSON = controllerApi.GetLicenseRuleConfiguration(ruleID);
                                            if (licenseRuleDetailsJSON != String.Empty)
                                            {
                                                FileIOHelper.SaveFileToPath(licenseRuleDetailsJSON, FilePathMap.LicenseRuleConfigurationDataFilePath(jobTarget, ruleName, ruleID));
                                            }
                                        }

                                        foreach (JObject licenseRuleObject in licenseRulesArray)
                                        {
                                            string ruleID   = getStringValueFromJToken(licenseRuleObject, "id");
                                            string ruleName = getStringValueFromJToken(licenseRuleObject, "name");

                                            loggerConsole.Info("License Rule Usage - {0}", ruleName);

                                            string licenseRuleUsageJSON = controllerApi1.GetLicenseRuleUsage(ruleID, fromTimeUnix, toTimeUnix, differenceInMinutes);
                                            if (licenseRuleUsageJSON != String.Empty)
                                            {
                                                FileIOHelper.SaveFileToPath(licenseRuleUsageJSON, FilePathMap.LicenseRuleUsageDataFilePath(jobTarget, ruleName, ruleID));
                                            }
                                        }
                                    }
                                }
                            }

                            controllerApi.PrivateApiLogin();

                            loggerConsole.Info("List of Applications Referenced by License Rules");

                            string applicationsListJSON = controllerApi.GetControllerApplicationsForLicenseRule();
                            if (applicationsListJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(applicationsListJSON, FilePathMap.LicenseApplicationsDataFilePath(jobTarget));
                            }

                            loggerConsole.Info("List of Machines Referenced by License Rules");

                            string machinesListJSON = controllerApi.GetControllerSIMMachinesForLicenseRule();
                            if (machinesListJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(machinesListJSON, FilePathMap.LicenseSIMMachinesDataFilePath(jobTarget));
                            }

                            #endregion

                            #region Account Summary

                            loggerConsole.Info("Account Summary");

                            string accountJSON = controllerApi.GetAccount();
                            if (accountJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(accountJSON, FilePathMap.LicenseAccountDataFilePath(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);
            }
        }
Пример #47
0
        public static ProjectInfo Open(ProgramOptions options)
        {
            if (options == null) throw new ArgumentNullException("options");
            if (string.IsNullOrEmpty(options.FileName)) throw new ArgumentException("FileName is null or empty.");

            var result = File.Exists(options.FileName) ? Open(options.FileName) : New(options.FileName);

            foreach (var variable in options.Variables)
            {
                if (result.SetSysVariable(variable.Key, variable.Value)) continue;
                result.GlobalUserVariables[variable.Key] = new UserVariable(variable.Key, variable.Value);
            }

            return result;
        }
Пример #48
0
 public void DisplayJobStepEndedStatus(ProgramOptions programOptions, Stopwatch stopWatch)
 {
     logger.Info("{0}({0:d}): total duration {1:c} ({2} ms)", programOptions.ReportJob.Status, stopWatch.Elapsed, stopWatch.ElapsedMilliseconds);
     loggerConsole.Trace("{0}({0:d}): total duration {1:c} ({2} ms)", programOptions.ReportJob.Status, stopWatch.Elapsed, stopWatch.ElapsedMilliseconds);
 }
Пример #49
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 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.Line, 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.Line, 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);
            }
        }
Пример #50
0
        private static void RunServer(ProgramOptions options)
        {
            var listener = new TcpListener(options.Host, options.Port);
            listener.Start();
            var display = new Display(options, listener.GetPort()) {Delay = .5.Seconds()};
            display.Refresh();

            try
            {

                var files = options.Directory.EnumerateFiles("*", SearchOption.AllDirectories);
                var buffer = new byte[Extensions.DefaultStreamCopyBufferSize];

                using (var it = files.GetEnumerator())
                {
                    using (var client = listener.AcceptTcpClient())
                    using (var netStream = client.GetStream())
                    using (var compStream = options.Compression.HasValue
                            ? new DeflateStream(netStream, options.Compression.Value)
                            : null)
                    using(var clearWriter = new BinaryWriter((Stream)compStream ?? netStream))
                    using (var aes = CreateAes(options))
                    using (var enc = aes?.CreateEncryptor())
                    using (var cryptoStream = aes != null
                            ? new CryptoStream((Stream)compStream ?? netStream, enc, CryptoStreamMode.Write)
                            : null)
                    using (var writer = new BinaryWriter(cryptoStream ?? (Stream)compStream ?? netStream))
                    {
                        if (aes != null)
                            clearWriter.Write(aes.IV);

                        display.Stopwatch.Start();

                        while (it.MoveNext())
                        {
                            var file = it.Current;
                            display.CurrentFile = new FileProgress(
                                file.GetRelativePathFrom(options.Directory),
                                file.Length).Do(x => x.Stopwatch.Start());
                            var path = file.GetRelativePathFrom(options.Directory);

                            writer.Write(path);
                            writer.Write(file.Length);

                            using (var fileStream = file.OpenRead())
                                fileStream.CopyTo(writer.BaseStream, file.Length, buffer,
                                    b =>
                                    {
                                        display.ByteCount += (display.CurrentFile.BytesTransferred = b);
                                        display.Refresh();
                                    });

                            display.FileCount++;
                            display.Refresh();
                        }
                    }
                }
            }
            finally
            {
                listener.Stop();
            }
        }
Пример #51
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_APM) == 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_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 = 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 Application

                            loggerConsole.Info("Application Configuration");

                            if (File.Exists(FilePathMap.APMApplicationConfigurationXMLDataFilePath(jobTarget)) == false)
                            {
                                controllerApi.Timeout = 3;
                                string applicationConfigXml = controllerApi.GetAPMConfigurationExportXML(jobTarget.ApplicationID);
                                if (applicationConfigXml != String.Empty)
                                {
                                    FileIOHelper.SaveFileToPath(applicationConfigXml, FilePathMap.APMApplicationConfigurationXMLDataFilePath(jobTarget));
                                }
                            }

                            controllerApi.PrivateApiLogin();

                            if (File.Exists(FilePathMap.APMApplicationConfigurationDetailsDataFilePath(jobTarget)) == false)
                            {
                                controllerApi.PrivateApiLogin();

                                string applicationConfigJSON = controllerApi.GetAPMConfigurationDetailsJSON(jobTarget.ApplicationID);
                                if (applicationConfigJSON != String.Empty)
                                {
                                    FileIOHelper.SaveFileToPath(applicationConfigJSON, FilePathMap.APMApplicationConfigurationDetailsDataFilePath(jobTarget));
                                }
                            }

                            #endregion

                            #region Service Endpoints

                            // SEPs are not included in the extracted XML
                            // 2018:
                            //  There is Flash/Flex API but I am not going to call it
                            //  Otherwise there is accounts API https://docs.appdynamics.com/display/PRO45/Access+Swagger+and+Accounts+API
                            //  This includes this one:
                            //  GET /accounts/{acctId}/applications/{appId}/sep      Get all ServiceEndPointConfigs for application
                            //  It requires pretty high admin level access but hey, it's not Flash
                            // 12/19/2019:
                            //  Previous API is removed, so we're going to call the RESTUI API

                            loggerConsole.Info("Service Endpoint Detection");

                            if (File.Exists(FilePathMap.APMApplicationConfigurationSEPDetectionRulesDataFilePath(jobTarget)) == false)
                            {
                                string applicationConfigSEPJSON = controllerApi.GetAPMSEPAutodetectionConfiguration(jobTarget.ApplicationID);
                                if (applicationConfigSEPJSON != String.Empty)
                                {
                                    FileIOHelper.SaveFileToPath(applicationConfigSEPJSON, FilePathMap.APMApplicationConfigurationSEPDetectionRulesDataFilePath(jobTarget));
                                }
                            }

                            string tiersJSON = controllerApi.GetAPMTiers(jobTarget.ApplicationID);
                            if (tiersJSON != String.Empty)
                            {
                                List <AppDRESTTier> tiersRESTList = JsonConvert.DeserializeObject <List <AppDRESTTier> >(tiersJSON);
                                if (tiersRESTList != null)
                                {
                                    loggerConsole.Info("Service Endpoint Detection for Tiers");
                                    foreach (AppDRESTTier tier in tiersRESTList)
                                    {
                                        string tierConfigOverrideJSON = controllerApi.GetAPMSEPTierConfigurationOverride(tier.id, tier.agentType);
                                        if (tierConfigOverrideJSON != String.Empty)
                                        {
                                            JObject tierOverrideObject = JObject.Parse(tierConfigOverrideJSON);
                                            if (tierOverrideObject != null)
                                            {
                                                if (getBoolValueFromJToken(tierOverrideObject, "override") == true)
                                                {
                                                    loggerConsole.Info("Service Endpoint Detection for Tier {0}", tier.name);

                                                    string tierConfigSEPJSON = controllerApi.GetAPMSEPTierAutodetectionConfiguration(tier.id, tier.agentType);
                                                    if (tierConfigSEPJSON != String.Empty && tierConfigSEPJSON != "[]" && tierConfigSEPJSON != "[ ]")
                                                    {
                                                        FileIOHelper.SaveFileToPath(tierConfigSEPJSON, FilePathMap.APMApplicationConfigurationSEPTierDetectionRulesDataFilePath(jobTarget, tier));
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    loggerConsole.Info("Explicit Service Endpoint Rules for Tiers");
                                    foreach (AppDRESTTier tier in tiersRESTList)
                                    {
                                        string tierConfigSEPJSON = controllerApi.GetAPMSEPTierRules(tier.id, tier.agentType);
                                        if (tierConfigSEPJSON != String.Empty && tierConfigSEPJSON != "[]" && tierConfigSEPJSON != "[ ]")
                                        {
                                            loggerConsole.Info("Service Endpoint Rule for Tier {0}", tier.name);

                                            FileIOHelper.SaveFileToPath(tierConfigSEPJSON, FilePathMap.APMApplicationConfigurationSEPTierExplicitRulesDataFilePath(jobTarget, tier));
                                        }
                                    }
                                }
                            }

                            #endregion

                            #region Dev mode information

                            loggerConsole.Info("Developer Mode Nodes");

                            if (File.Exists(FilePathMap.APMApplicationDeveloperModeNodesDataFilePath(jobTarget)) == false)
                            {
                                string devModeConfigurationJSON = controllerApi.GetAPMDeveloperModeConfiguration(jobTarget.ApplicationID);
                                if (devModeConfigurationJSON != String.Empty)
                                {
                                    FileIOHelper.SaveFileToPath(devModeConfigurationJSON, FilePathMap.APMApplicationDeveloperModeNodesDataFilePath(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);
            }
        }
	    private void AssertInvalidOptionsCombination(string arguments)
	    {
            ProgramOptions options = new ProgramOptions();
            options.ProcessArgs(arguments.Split(' '));
	        Assert.IsFalse(options.IsValid);
	    }
        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_DB) == 0)
                {
                    return(true);
                }

                // Process each Controller once
                int i           = 0;
                var controllers = jobConfiguration.Target.Where(t => t.Type == APPLICATION_TYPE_DB).ToList().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)))
                        {
                            controllerApi.PrivateApiLogin();

                            #region Collector definitions

                            loggerConsole.Info("Collector Definitions");

                            string collectorDefinitionsJSON = controllerApi.GetDBCollectorsConfiguration("4.5");
                            if (collectorDefinitionsJSON == String.Empty)
                            {
                                collectorDefinitionsJSON = controllerApi.GetDBCollectorsConfiguration("4.4");
                            }
                            if (collectorDefinitionsJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(collectorDefinitionsJSON, FilePathMap.DBCollectorDefinitionsDataFilePath(jobTarget));
                            }

                            #endregion

                            #region Custom Metrics

                            loggerConsole.Info("Custom Metrics");

                            string customMetricsJSON = controllerApi.GetDBCustomMetrics("4.5");
                            if (customMetricsJSON == String.Empty)
                            {
                                customMetricsJSON = controllerApi.GetDBCustomMetrics("4.4");
                            }
                            if (customMetricsJSON != String.Empty && customMetricsJSON != "[ ]" && customMetricsJSON != "[]")
                            {
                                FileIOHelper.SaveFileToPath(customMetricsJSON, FilePathMap.DBCustomMetricsDataFilePath(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);
            }
        }
Пример #54
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);
            }

            if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_MOBILE) == 0)
            {
                return(true);
            }

            try
            {
                loggerConsole.Info("Prepare Detected MOBILE 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 MOBILE 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 MOBILE 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_MOBILE_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_NETWORK_REQUESTS_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_NETWORK_REQUESTS_TYPE_PIVOT);
                sheet.Cells[2, 2].StyleName = "HyperLinkStyle";
                sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1);

                sheet = excelReport.Workbook.Worksheets.Add(SHEET_NETWORK_REQUESTS_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_NETWORK_REQUESTS_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_NETWORK_REQUESTS_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_NETWORK_REQUESTS_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_NETWORK_REQUESTS_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_NETWORK_REQUESTS_BUSINESS_TRANSACTIONS_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 MOBILE 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_MOBILE_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.MOBILEApplicationsReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Network Requests

                loggerConsole.Info("List of Network Requests");

                sheet = excelReport.Workbook.Worksheets[SHEET_NETWORK_REQUESTS_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.MOBILENetworkRequestsReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                #region Network Request Business Transactions

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

                sheet = excelReport.Workbook.Worksheets[SHEET_NETWORK_REQUESTS_BUSINESS_TRANSACTIONS_LIST];
                EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.MOBILENetworkRequestsBusinessTransactionsReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1);

                #endregion

                loggerConsole.Info("Finalize Detected MOBILE 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_MOBILE_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_MOBILE);
                    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["NumNetworkRequests"].Position + 1, sheet.Dimension.Rows, table.Columns["NumNetworkRequests"].Position + 1);
                    var          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 Network Requests

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_NETWORK_REQUESTS_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_NETWORK_REQUESTS);
                    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["RequestName"].Position + 1).Width         = 10;
                    sheet.Column(table.Columns["RequestNameInternal"].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_NETWORK_REQUESTS_TYPE_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 1, 1], range, PIVOT_NETWORK_REQUESTS_TYPE);
                    setDefaultPivotTableSettings(pivot);
                    addFilterFieldToPivot(pivot, "HasActivity");
                    addFilterFieldToPivot(pivot, "ARTRange", eSortType.Ascending);
                    addRowFieldToPivot(pivot, "Controller");
                    addRowFieldToPivot(pivot, "ApplicationName");
                    addRowFieldToPivot(pivot, "RequestName");
                    addRowFieldToPivot(pivot, "RequestNameInternal");
                    addDataFieldToPivot(pivot, "RequestID", DataFieldFunctions.Count, "NumReqs");
                    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_NETWORK_REQUESTS_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 Network Request Business Transactions

                // Make table
                sheet = excelReport.Workbook.Worksheets[SHEET_NETWORK_REQUESTS_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_NETWORK_REQUESTS_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["RequestName"].Position + 1).Width         = 10;
                    sheet.Column(table.Columns["RequestNameInternal"].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_NETWORK_REQUESTS_BUSINESS_TRANSACTIONS_TYPE_PIVOT];
                    ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_NETWORK_REQUESTS_BUSINESS_TRANSACTIONS_TYPE);
                    setDefaultPivotTableSettings(pivot);
                    addFilterFieldToPivot(pivot, "HasActivity");
                    addFilterFieldToPivot(pivot, "ARTRange", eSortType.Ascending);
                    addRowFieldToPivot(pivot, "Controller");
                    addRowFieldToPivot(pivot, "ApplicationName");
                    addRowFieldToPivot(pivot, "RequestName");
                    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_NETWORK_REQUESTS_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 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.MOBILEEntitiesExcelReportFilePath(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);
            }
        }
Пример #55
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);

                        // TODO
                    }
                    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(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;

                    stepTimingTarget.NumEntities = 1;

                    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));

                        #endregion

                        #region Controller

                        if (File.Exists(FilePathMap.ControllerSettingsDataFilePath(jobTarget)) != true)
                        {
                            loggerConsole.Info("Controller Settings");

                            string controllerSettingsJSON = controllerApi.GetControllerConfiguration();
                            if (controllerSettingsJSON != String.Empty)
                            {
                                FileIOHelper.SaveFileToPath(controllerSettingsJSON, FilePathMap.ControllerSettingsDataFilePath(jobTarget));
                            }
                        }

                        #endregion

                        #region Application

                        loggerConsole.Info("Application Configuration");

                        // Application configuration
                        string applicationConfigXml = controllerApi.GetApplicationConfiguration(jobTarget.ApplicationID);
                        if (applicationConfigXml != String.Empty)
                        {
                            FileIOHelper.SaveFileToPath(applicationConfigXml, FilePathMap.ApplicationConfigurationDataFilePath(jobTarget));
                        }

                        #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);
            }
        }
        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_APM) == 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_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);

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

                            #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 snapshotsArray = new JArray();

                                    // Extract snapshot list
                                    long      serverCursorId     = 0;
                                    string    serverCursorIdType = String.Empty;
                                    Hashtable requestIDs         = new Hashtable(10000);

                                    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 snapshotscontainerObject = JObject.Parse(snapshotsJSON);
                                            JArray  retrievedSnapshotsArray  = (JArray)snapshotscontainerObject["requestSegmentDataListItems"];
                                            foreach (JObject snapshotObject in retrievedSnapshotsArray)
                                            {
                                                // Filter out duplicates
                                                if (requestIDs.ContainsKey(snapshotObject["requestGUID"].ToString()) == true)
                                                {
                                                    logger.Warn("Snapshot {0} is a duplicate, skipping", snapshotObject["requestGUID"]);
                                                    continue;
                                                }

                                                snapshotsArray.Add(snapshotObject);
                                                requestIDs.Add(snapshotObject["requestGUID"].ToString(), true);
                                            }

                                            // Check whether we have more snapshots and if yes, get continuation type and cursor ID
                                            JToken fetchMoreDataHandleToken = snapshotscontainerObject["fetchMoreDataHandle"];
                                            JToken serverCursorToken        = snapshotscontainerObject["serverCursor"];
                                            if (serverCursorToken != null)
                                            {
                                                JToken scrollIdToken    = serverCursorToken["scrollId"];
                                                JToken rsdScrollIdToken = serverCursorToken["rsdScrollId"];

                                                if (scrollIdToken != null)
                                                {
                                                    serverCursorIdType = "scrollId";
                                                    // Parse the cursor ID
                                                    if (Int64.TryParse(scrollIdToken.ToString(), out serverCursorId) == false)
                                                    {
                                                        // Nope, not going to go forward
                                                        serverCursorId = 0;
                                                    }
                                                }
                                                else if (rsdScrollIdToken != null)
                                                {
                                                    serverCursorIdType = "rsdScrollId";
                                                    // Parse the cursor ID
                                                    if (Int64.TryParse(rsdScrollIdToken.ToString(), out serverCursorId) == false)
                                                    {
                                                        // Nope, not going to go forward
                                                        serverCursorId = 0;
                                                    }
                                                }
                                            }
                                            else if (fetchMoreDataHandleToken != null)
                                            {
                                                serverCursorIdType = "fetchMoreDataHandle";
                                                // Parse the cursor ID
                                                if (Int64.TryParse(fetchMoreDataHandleToken.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, retrievedSnapshotsArray.Count, serverCursorIdType, serverCursorId);

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

                                    Console.WriteLine();

                                    FileIOHelper.WriteJArrayToFile(snapshotsArray, snapshotsDataFilePath);

                                    totalSnapshotsFound = totalSnapshotsFound + snapshotsArray.Count;

                                    logger.Info("{0} snapshots from {1:o} to {2:o}", snapshotsArray.Count, jobTimeRange.From, jobTimeRange.To);
                                    loggerConsole.Info("{0} snapshots from {1:G} to {2:G}", snapshotsArray.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.APMTiersDataFilePath(jobTarget));
                        List <AppDRESTBusinessTransaction> businessTransactionsList = FileIOHelper.LoadListOfObjectsFromFile <AppDRESTBusinessTransaction>(FilePathMap.APMBusinessTransactionsDataFilePath(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 snapshotsInHourArray = FileIOHelper.LoadJArrayFromFile(snapshotsDataFilePath);
                            if (snapshotsInHourArray != null && snapshotsInHourArray.Count > 0)
                            {
                                #region Filter Snapshots

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

                                // Filter the list of snapshots based on SnapshotSelectionCriteria
                                List <JToken> listOfSnapshotsInHourFiltered = new List <JToken>(snapshotsInHourArray.Count);
                                foreach (JToken snapshotToken in snapshotsInHourArray)
                                {
                                    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, jobTimeRange.To, snapshotsInHourArray.Count, listOfSnapshotsInHourFiltered.Count);

                                #endregion

                                #region Extract Snapshots

                                // 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
                                        using (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
                                {
                                    using (ControllerApi controllerApi = new ControllerApi(jobTarget.Controller, jobTarget.UserName, AESEncryptionHelper.Decrypt(jobTarget.UserPassword)))
                                    {
                                        controllerApi.PrivateApiLogin();

                                        numSnapshots = extractSnapshots(jobConfiguration, jobTarget, controllerApi, listOfSnapshotsInHourFiltered, tiersNodeJSList, true);
                                    }
                                }

                                loggerConsole.Info("{0} snapshots extracted", numSnapshots);

                                #endregion
                            }
                        }

                        #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);
            }
        }