/* * private Dictionary<String, String> GetBeaconPropertyLoadConfig(String path) * { * * string fullPathName = string.Empty; * if (path != null) * { * fullPathName = propertyDirPath + "\\Collector.properties"; * } * else * { * string projectDir = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; * LoggingMessage.DisplayMessage("CXOptimize - Project Target Dir Path -> " + projectDir, LoggingMessage.MessageType.DEBUG, log); * GetPropertyFile(projectDir); * * } * string[] split; * string line = String.Empty; * Dictionary<String, String> config = null; * * //string projectDir = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; * * * string environmentKey = ConfigurationManager.AppSettings["Environment"]; * if (environmentKey == null || environmentKey == string.Empty) * fullPathName = propertyDirPath + "\\Collector.properties"; * else * fullPathName = string.Format("{0}\\{1}_Collector.properties", propertyDirPath, environmentKey); * * LoggingMessage.DisplayMessage("CXOptimize - Config Path-> " + fullPathName, LoggingMessage.MessageType.DEBUG, log); * * if (File.Exists(fullPathName)) * { * config = new Dictionary<string, string>(); * using (StreamReader file = new StreamReader(fullPathName)) * { * while ((line = file.ReadLine()) != null) * { * split = line.Split('='); * if (split.Length == 2) * config.Add(split[0], split[1]); * } * } * * } * else * { * throw new ArgumentException("Collector Property file missing"); * } * * return config; * } */ protected ConfigurationLoader() { try { log.Debug("Starting Loading Configuration"); String path = CollectorConstants.getCollectorProperties(); if (path == null) { GetPropertyFile(AppDomain.CurrentDomain.SetupInformation.ApplicationBase); path = propertyDirPath + "\\Collector.properties"; } else { path = path + "\\Collector.properties"; } Dictionary <String, String> config; string[] split; string line = String.Empty; if (File.Exists(path)) { config = new Dictionary <string, string>(); using (StreamReader file = new StreamReader(path)) { while ((line = file.ReadLine()) != null) { split = line.Split('='); if (split.Length == 2) { config.Add(split[0], split[1]); } } } } else { throw new ArgumentException("Collector Property file missing"); } if (config != null) { log.Debug("Properties Load Successfull from file : " + config.ToString()); CollectorConstants.setBeaconURL(config["beaconUrl"]); CollectorConstants.setClientName(config["clientName"]); CollectorConstants.setProjectName(config["projectName"]); CollectorConstants.setScenarioName(config["scenarioName"]); CollectorConstants.setLicenseKey(config["LicenseKey"]); CollectorConstants.setUserName(config["UserName"]); CollectorConstants.setPassword(config["Password"]); /* * if (config.ContainsKey("Release") && config["Release"] != String.Empty) * { * CollectorConstants.setRelease(config["Release"].ToString()); * } * else * { * CollectorConstants.setRelease("NA"); * } * if (config.ContainsKey("Build") && config["Build"] != String.Empty) * { * CollectorConstants.setBuild(config["Build"].ToString()); * } * else * { * CollectorConstants.setBuild("NA"); * }*/ if (config.ContainsKey("isLoadTest") && config["isLoadTest"].Contains("true")) { CollectorConstants.setLoadTest("true"); } else { CollectorConstants.setLoadTest("false"); } if (config.ContainsKey("markWaitTime") && config["markWaitTime"] != String.Empty) { CollectorConstants.setMarkWaitTime(Int32.Parse(config["markWaitTime"])); } else { CollectorConstants.setMarkWaitTime(5000); } if (config.ContainsKey("resourceSettleTime")) { CollectorConstants.setResourceSettleTime(Int32.Parse(config["resourceSettleTime"])); } else { CollectorConstants.setResourceSettleTime(2000); } log.Debug("Loaded initialization parameters"); } if (CollectorConstants.getBeaconURL() == null || CollectorConstants.getBeaconURL() == "") { throw new ArgumentException("Missing value for BeaconURL"); } if (CollectorConstants.getClientName() == null || CollectorConstants.getClientName() == "") { throw new ArgumentException("Missing value for ClientName"); } if (CollectorConstants.getProjectName() == null || CollectorConstants.getProjectName() == "") { throw new ArgumentException("Missing value for ProjectName"); } if (CollectorConstants.getScenarioName() == null || CollectorConstants.getScenarioName() == "") { throw new ArgumentException("Missing value for ScenarioName"); } if (CollectorConstants.getUserName() == null || CollectorConstants.getUserName() == "") { throw new ArgumentException("Missing value for UserName"); } if (CollectorConstants.getPassword() == null || CollectorConstants.getPassword() == "") { throw new ArgumentException("Missing value for Password"); } if (CollectorConstants.getMarkWaitTime() == 0) { CollectorConstants.setMarkWaitTime(5000); } if (CollectorConstants.getResourceSettleTime() == 0) { CollectorConstants.setResourceSettleTime(2000); } if (CollectorConstants.getRelease() == null || CollectorConstants.getRelease() == string.Empty) { CollectorConstants.setRelease(DateTime.Now.ToString("yyyyMM")); } if (CollectorConstants.getBuild() == null || CollectorConstants.getBuild() == string.Empty) { CollectorConstants.setBuild(DateTime.Now.ToString("yyyyMMddHH")); } Dictionary <string, object> configs = new Dictionary <string, object>(); ICXOptimizeService cxOpService = new CXOptimizeServiceImpl(); CollectorConstants.setApiToken(cxOpService.getAuthToken()); log.Debug("Created ApiToken for the session " + CollectorConstants.getApiToken()); configs = cxOpService.getConfiguration(); if (config.ContainsKey("Status")) // Failed to get the config { log.Info("Cannot load configuration: " + config["Reason"]); config.Clear(); } else { configs.Add("beaconUrl", CollectorConstants.getBeaconURL()); configs.Add("RunTime", configs.ContainsKey("runTimestamp") ? configs["runTimestamp"] : (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds); CollectorConstants.setStaticExt(configs.ContainsKey("staticResourceExtension") ? configs["staticResourceExtension"].ToString() : ""); CollectorConstants.setImages(configs.ContainsKey("imageResourceExtension") ? configs["imageResourceExtension"].ToString() : ""); CollectorConstants.setResDurThreshold((configs.ContainsKey("resourceDurationThreshold") ? Double.Parse(configs["resourceDurationThreshold"].ToString()) : Double.Parse("10"))); configs.Add("Release", CollectorConstants.getRelease()); configs.Add("BuildNumber", CollectorConstants.getBuild()); clientConfig = configs; log.Debug("Complete Configuration " + config.ToString()); } } catch (Exception e) { log.Error("Cannot load configuration due to exception : " + e); } }
private static void PersistData(Dictionary <String, Object> collectedData) { log.Debug("Starting persistData for transaction " + collectedData["TxnName"]); String strsuccess = "Success"; try { Dictionary <String, Object> hostDetails = new Dictionary <String, Object>(); Dictionary <String, Object> details = new Dictionary <String, Object>(); Dictionary <String, Object> others = new Dictionary <String, Object>(); Dictionary <String, Double> resourceTime = new Dictionary <String, Double>(); hostDetails.Add("name", Dns.GetHostName()); others.Add("domElementCount", collectedData["DomElements"]); others.Add("dom", collectedData["DOMContent"].ToString()); if (collectedData.ContainsKey("msFirstPaint")) { others.Add("msFirstPaint", collectedData["msFirstPaint"]); } details.Add("ClientName", collectedData["ClientName"]); details.Add("ProjectName", collectedData["ProjectName"]); details.Add("Scenario", collectedData["Scenario"]); details.Add("licenseKey", collectedData.ContainsKey("licenseKey")?collectedData["licenseKey"]:""); details.Add("dataStoreUrl", collectedData.ContainsKey("dataStoreUrl") ? collectedData["dataStoreUrl"]:""); details.Add("transactionName", collectedData["TxnName"]); details.Add("url", collectedData["Url"]); details.Add("txnStatus", collectedData["txnStatus"]); details.Add("Release", collectedData["Release"]); details.Add("RunID", collectedData["RunID"].ToString()); details.Add("RunTime", collectedData["RunTime"]); details.Add("BuildNumber", collectedData["BuildNumber"]); details.Add("staticResourceExtension", collectedData["staticResourceExtension"]); details.Add("imageResourceExtension", collectedData["imageResourceExtension"]); details.Add("resourceDurationThreshold", collectedData["resourceDurationThreshold"]); details.Add("source", "CodedUI"); log.Debug("Calling calculateBackendTime"); resourceTime = CalculateBackendTime((List <Dictionary <string, object> >)collectedData["ResourceTime"], collectedData["NavType"].ToString()); log.Debug("Completed calculateBackendTime"); if (Convert.ToBoolean(collectedData["NavType"])) { details.Add("NavType", "Hard"); details.Add("speedIndex", collectedData["SpeedIndex"]); details.Add("StartTime", collectedData["StartTime"]); details.Add("resourceLoadTime", resourceTime["backendTime"]); details.Add("visuallyComplete", resourceTime["totalTime"]); } else { details.Add("NavType", "Soft"); //details.put("SoftNavTotalTime",(Long.parseLong(collectedData.get("SoftNavTotalTime").toString()) <= 0 ? 0 : collectedData.get("SoftNavTotalTime"))); details.Add("StartTime", collectedData["StartTime"]); details.Add("resourceLoadTime", resourceTime["backendTime"]); details.Add("visuallyComplete", resourceTime["totalTime"]); } Dictionary <string, object> jsonDoc = new Dictionary <string, object>(); jsonDoc.Add("details", details); jsonDoc.Add("host", hostDetails); jsonDoc.Add("platform", collectedData["Browser"]); jsonDoc.Add("memory", collectedData["Memory"]); jsonDoc.Add("others", others); jsonDoc.Add("navtime", collectedData["NavigationTime"]); if (collectedData.ContainsKey("MarkTime")) { jsonDoc.Add("marktime", markListProcessed((List <Dictionary <string, object> >)collectedData["MarkTime"])); } Boolean crawlEnabled = (collectedData.ContainsKey("isResourceCrawlingEnabled") ? Convert.ToBoolean(collectedData["isResourceCrawlingEnabled"]) : true); log.Debug("Crawl Enabled is " + crawlEnabled + " for " + collectedData["TxnName"]); if (crawlEnabled) { jsonDoc.Add("resources", CrawlUtils.getResourceDetails((List <Dictionary <String, Object> >)collectedData["ResourceTime"])); } else { jsonDoc.Add("resources", collectedData["ResourceTime"]); } log.Debug("Crawl Completed: "); log.Debug("Data collected for " + collectedData["TxnName"] + " : " + jsonDoc.ToString()); ICXOptimizeService cxOpService = new CXOptimizeServiceImpl(); String post = cxOpService.uploadPerformanceData(JSONUtils.MapToJsonString(jsonDoc)); log.Debug("Post Status : " + post); //Checking if the response is null. If so, then it will go to finally block if (post == null) { log.Error("Unable to insert stats into datastore for " + collectedData["TxnName"] + ". Please check logs for further details."); return; } if (!post.Contains(strsuccess)) { log.Error("The data could not be uploaded for " + collectedData["TxnName"] + ". The response from data store is " + post); } else { log.Info("DataUploaded for succesfully for {}" + collectedData["TxnName"]); } } catch (Exception e) { log.Error("Exception in persistData for " + collectedData["TxnName"] + " at " + e); } }