/// <summary> /// 绩效报告存储路径 /// </summary> /// <returns>绩效报告存储路径</returns> internal string getPerformanceReportDataStorePath() { string configItemValue = string.Format("{0}", _AppsflyerConfig.getConfigItem(CONFIG_ITEM_PERFORMANCE_REPORT_DATA)); if (configItemValue == null) { return(string.Format("{0}/{1}", CPublic.getAppStartPath(), "performance_report_data")); } return(configItemValue); }
private string getDataStorePath() { string configItemValue = string.Format("{0}", _AppsflyerConfig.getConfigItem(CONFIG_ITEM_USER_DATA_PATH)); if (configItemValue == null) { return(string.Format("{0}/{1}", CPublic.getAppStartPath(), "data")); } return(configItemValue); }
/// <summary> /// 创建浏览器驱动对象 /// </summary> /// <returns>失败返回null,成功返回对象指针</returns> public E_ERROR_CODE initWebDriver() { string message = string.Empty; PhantomJSDriverService driverService = PhantomJSDriverService.CreateDefaultService(CPublic.getAppStartPath()); driverService.LogFile = getWebDriverLogFile(); driverService.LocalStoragePath = string.Format("{0}/{1}", CPublic.getAppStartPath(), "LocalStorage"); driverService.LocalStorageQuota = 1024 * 1024 * 5; driverService.HideCommandPromptWindow = true; driverService.IgnoreSslErrors = true; driverService.DiskCache = true; driverService.MaxDiskCacheSize = 1024 * 1024 * 10; driverService.LocalToRemoteUrlAccess = true; driverService.CookiesFile = string.Format("{0}/{1}/{2}", CPublic.getAppStartPath(), "cookies", Guid.NewGuid().ToString()); PhantomJSOptions options = new PhantomJSOptions(); options.AddAdditionalCapability("phantomjs.page.settings.userAgent", _UserAgent); try { _WebDriver = new QA.PhantomJS.PhantomJSDriver(driverService, options); _IsInitWebDriverCompleted = true; PhantomjsDriverProcessId = driverService.ProcessId; return(E_ERROR_CODE.OK); } catch (Exception ex) { _IsInitWebDriverCompleted = false; _WebDriver = null; message = string.Format("Init webdriver faild:{0}", ex.Message); _SystemLog.writeLog2Console(LOG_LEVEL.ERR, message); return(E_ERROR_CODE.ERROR_INIT_WEBDRIVER_FAILED); } }
static int Main(string[] args) { E_ERROR_CODE errorCode = E_ERROR_CODE.ERROR; _SystemLog = new CSystemLog(true, LOG_LEVEL.DEBUG, string.Format("{0}/{1}", CPublic.getAppStartPath(), "system_log")); _SystemConfig = new CSystemConfig(CPublic.SYSTEM_CONFIG_FILE, _SystemLog); errorCode = _SystemConfig.initConfig(); if (errorCode != E_ERROR_CODE.OK) { _SystemLog.writeLog2Console(LOG_LEVEL.CRIT, string.Format("Init system config <{0}> failed, error code <{1}>.", CPublic.SYSTEM_CONFIG_FILE, errorCode)); return((int)errorCode); } _SystemConfig.printSystemConfig(); _AppsflyerConfigFilePath = string.Format("{0}", _SystemConfig.getConfigItem(CONFIG_ITEM_APPSFLYER_CONFIG_FILE)).Trim(); if (!File.Exists(_AppsflyerConfigFilePath)) { _SystemLog.writeLog2Console(LOG_LEVEL.CRIT, string.Format("Appsflyer config file <{0}> not exits.", _AppsflyerConfigFilePath)); return((int)E_ERROR_CODE.ERROR_FILE_NOT_EXIST); } CAppsFlyerDataSpider appsFlyerDataSpider = new CAppsFlyerDataSpider(_AppsflyerConfigFilePath, _SystemLog); errorCode = appsFlyerDataSpider.initAppsFlyerSpiderConfig(); if (errorCode != E_ERROR_CODE.OK) { appsFlyerDataSpider.cleanUp(); _SystemLog.writeLog2Console(LOG_LEVEL.CRIT, string.Format("Init appsflyer spider config failed, error code <{0}>.", errorCode)); return((int)errorCode); } errorCode = appsFlyerDataSpider.initWebDriver(); if (errorCode != E_ERROR_CODE.OK) { appsFlyerDataSpider.cleanUp(); _SystemLog.writeLog2Console(LOG_LEVEL.CRIT, string.Format("Init webdriver failed, error code <{0}>.", errorCode)); return((int)errorCode); } int retentionPeriod = appsFlyerDataSpider.AppsFlyerDataSpiderConfig.getRetentionPeriod(); int appsflyerDelayDay = appsFlyerDataSpider.AppsFlyerDataSpiderConfig.getAppsflyerDelayDay(); int queryCycle = appsFlyerDataSpider.AppsFlyerDataSpiderConfig.getDownloadDataCycle(); while (true) { _CurrentTime = DateTime.Now; _LastTime = _CurrentTime; errorCode = appsFlyerDataSpider.loginSystem(); if ((errorCode != E_ERROR_CODE.OK) || (!appsFlyerDataSpider.IsLoginSuccessed)) { _SystemLog.writeLog2Console(LOG_LEVEL.ERR, string.Format("Login appsflyer system failed, after <{0}> login again.", 60)); Thread.Sleep(TimeSpan.FromSeconds(30)); } /* 每8小时取一个留存数据 */ if (_CurrentTime.Subtract(_LastTime).Hours >= queryCycle) { DateTime endDate = _CurrentTime.Date.Subtract(TimeSpan.FromDays(appsflyerDelayDay)); DateTime startDate = endDate.Subtract(TimeSpan.FromDays((retentionPeriod - 1))); errorCode = appsFlyerDataSpider.downloadAndroidData(startDate, endDate); if (errorCode != E_ERROR_CODE.OK) { _SystemLog.writeLog2Console(LOG_LEVEL.ERR, string.Format("Download android data <{0},{1}> failed .", CPublic.getDateString(startDate), CPublic.getDateString(endDate))); } errorCode = appsFlyerDataSpider.downloadIOSData(startDate, endDate); if (errorCode != E_ERROR_CODE.OK) { _SystemLog.writeLog2Console(LOG_LEVEL.ERR, string.Format("Download ios data <{0},{1}> failed .", CPublic.getDateString(startDate), CPublic.getDateString(endDate))); } } /* AppsFlyer汇总绩效报告 Performance report */ if (_CurrentTime.Hour != _LastTime.Hour) { errorCode = appsFlyerDataSpider.downloadAndroidPerformanceReportData(_CurrentTime); if (errorCode != E_ERROR_CODE.OK) { _SystemLog.writeLog2Console(LOG_LEVEL.ERR, string.Format("Download android performance report data <{0}> failed .", CPublic.getDateString(_CurrentTime))); } errorCode = appsFlyerDataSpider.downloadIOSPerformanceReportData(_CurrentTime); if (errorCode != E_ERROR_CODE.OK) { _SystemLog.writeLog2Console(LOG_LEVEL.ERR, string.Format("Download ios performance report data <{0}> failed .", CPublic.getDateString(_CurrentTime))); } } _LastTime = _CurrentTime; _SystemLog.writeLog2Console(LOG_LEVEL.INFO, string.Format("Query cycle <{0}>, Current time <{1}>, Next download data at <{2}> .", queryCycle, CPublic.getDateTimeString(_CurrentTime), CPublic.getDateTimeString(_CurrentTime.AddSeconds(queryCycle)))); Thread.Sleep(TimeSpan.FromSeconds(30 * 60)); } }