/// <summary> /// /// </summary> /// <returns> API Context without user crendials /// </returns> private static ApiContext GetGenericApiContext() { ApiContext apiContext = new ApiContext(); apiContext.Version = System.Configuration.ConfigurationManager.AppSettings.Get(VERSION); apiContext.Timeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings.Get(TIME_OUT)); apiContext.SoapApiServerUrl = System.Configuration.ConfigurationManager.AppSettings.Get(API_SERVER_URL); apiContext.EPSServerUrl = System.Configuration.ConfigurationManager.AppSettings.Get(EPS_SERVER_URL); apiContext.SignInUrl = System.Configuration.ConfigurationManager.AppSettings.Get(SIGNIN_URL); ApiAccount apiAccount = new ApiAccount(); apiAccount.Developer = System.Configuration.ConfigurationManager.AppSettings.Get(DEV_ID); apiAccount.Application = System.Configuration.ConfigurationManager.AppSettings.Get(APP_ID); apiAccount.Certificate = System.Configuration.ConfigurationManager.AppSettings.Get(CERT_ID); ApiCredential apiCredential = new ApiCredential(); apiCredential.ApiAccount = apiAccount; apiContext.ApiCredential = apiCredential; apiContext.EnableMetrics = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings.Get(ENABLE_METRICS)); string site = System.Configuration.ConfigurationManager.AppSettings.Get(EBAY_USER_SITE_ID); if (site != null) { apiContext.Site = (SiteCodeType)Enum.Parse(typeof(SiteCodeType), site, false); } apiContext.RuleName = System.Configuration.ConfigurationManager.AppSettings.Get(RULE_NAME); return apiContext; }
public ApiContext GetApiContext() { //ApiContext is a singleton, if (apiContext != null) { return apiContext; } else { apiContext = new ApiContext(); //supply Api Server Url apiContext.SoapApiServerUrl = ConfigurationManager.AppSettings["Environment.ApiServerUrl"]; //Supply user token ApiCredential apiCredential = new ApiCredential(); apiCredential.eBayToken = ConfigurationManager.AppSettings["UserAccount.ApiToken"]; apiContext.ApiCredential = apiCredential; //Specify site: here we use US site apiContext.Site = eBay.Service.Core.Soap.SiteCodeType.US; return apiContext; } // else }
public static ApiContext GetGenericApiContext(string site) { ApiContext apiContext = new ApiContext(); apiContext.Version = System.Configuration.ConfigurationManager.AppSettings.Get(VERSION); apiContext.Timeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings.Get(TIME_OUT)); apiContext.SoapApiServerUrl = System.Configuration.ConfigurationManager.AppSettings.Get(API_SERVER_URL); apiContext.EPSServerUrl = System.Configuration.ConfigurationManager.AppSettings.Get(EPS_SERVER_URL); apiContext.SignInUrl = System.Configuration.ConfigurationManager.AppSettings.Get(SIGNIN_URL); ApiAccount apiAccount = new ApiAccount(); apiAccount.Developer = System.Configuration.ConfigurationManager.AppSettings["Environment.DevId"]; apiAccount.Application = System.Configuration.ConfigurationManager.AppSettings["Environment.AppId"]; apiAccount.Certificate = System.Configuration.ConfigurationManager.AppSettings["Environment.CertId"]; ApiCredential apiCredential = new ApiCredential(); apiCredential.ApiAccount = apiAccount; apiContext.ApiCredential = apiCredential; apiContext.EnableMetrics = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings.Get(ENABLE_METRICS)); if (!string.IsNullOrEmpty(site)) { apiContext.Site = (SiteCodeType)Enum.Parse(typeof(SiteCodeType), site, true); } apiContext.RuleName = System.Configuration.ConfigurationManager.AppSettings["RuName"];// EBayPriceChanges.Config.RuName; apiContext.RuName = System.Configuration.ConfigurationManager.AppSettings["RuName"];// EBayPriceChanges.Config.RuName; return apiContext; }
//get parameters from config file and create //ApiContext object static ApiContext GetApiContext() { ApiContext cxt = new ApiContext(); // set api server address cxt.SoapApiServerUrl = ConfigurationManager.AppSettings[KEY_API_URL]; // set token ApiCredential ac = new ApiCredential(); string token = ConfigurationManager.AppSettings[KEY_APITOKEN]; ac.eBayToken = token; cxt.ApiCredential = ac; // initialize log. ApiLogManager logManager = null; string logPath = ConfigurationManager.AppSettings[KEY_LOGFILE]; if (logPath.Length > 0) { logManager = new ApiLogManager(); logManager.EnableLogging = true; logManager.ApiLoggerList = new ApiLoggerCollection(); ApiLogger log = new FileLogger(logPath, true, true, true); logManager.ApiLoggerList.Add(log); } cxt.ApiLogManager = logManager; return cxt; }
/// <summary> /// Populate eBay SDK ApiContext object with data from application configuration file /// </summary> /// <returns>ApiContext</returns> static ApiContext GetApiContext() { //apiContext is a singleton, //to avoid duplicate configuration reading if (apiContext != null) { return apiContext; } else { apiContext = new ApiContext(); //set Api Server Url apiContext.SoapApiServerUrl = ConfigurationManager.AppSettings["Environment.ApiServerUrl"]; //set Api Token to access eBay Api Server ApiCredential apiCredential = new ApiCredential(); apiCredential.eBayToken = ConfigurationManager.AppSettings["UserAccount.ApiToken"]; apiContext.ApiCredential = apiCredential; //set eBay Site target to US apiContext.Site = SiteCodeType.US; return apiContext; } }
protected void Page_Init() { //get eBayToken and ServerAddress from Web.config string tradingServerAddress = System.Configuration.ConfigurationManager.AppSettings["TradingServerAddress"]; string eBayToken = System.Configuration.ConfigurationManager.AppSettings["EBayToken"]; apiContext = new ApiContext(); //set Api Server Url apiContext.SoapApiServerUrl = tradingServerAddress; //set Api Token to access eBay Api Server ApiCredential apiCredential = new ApiCredential(); apiCredential.eBayToken = eBayToken; apiContext.ApiCredential = apiCredential; //set eBay Site target to US apiContext.Site = SiteCodeType.US; //set Api logging apiContext.ApiLogManager = new ApiLogManager(); apiContext.ApiLogManager.ApiLoggerList.Add( new FileLogger("trading_log.txt", true, true, true) ); apiContext.ApiLogManager.EnableLogging = true; }
/// <summary> /// Populate eBay SDK ApiContext object with data from application configuration file /// </summary> /// <returns>ApiContext object</returns> static ApiContext GetApiContext() { //apiContext is a singleton, //to avoid duplicate configuration reading if (apiContext != null) { return apiContext; } else { apiContext = new ApiContext(); //set Api Server Url apiContext.SoapApiServerUrl = ConfigurationManager.AppSettings["Environment.ApiServerUrl"]; //set Api Token to access eBay Api Server ApiCredential apiCredential = new ApiCredential(); apiCredential.eBayToken = ConfigurationManager.AppSettings["UserAccount.ApiToken"]; apiContext.ApiCredential = apiCredential; //set eBay Site target to US apiContext.Site = SiteCodeType.US; //set Api logging apiContext.ApiLogManager = new ApiLogManager(); apiContext.ApiLogManager.ApiLoggerList.Add( new FileLogger("listing_log.txt", true, true, true) ); apiContext.ApiLogManager.EnableLogging = true; return apiContext; } }
/// <summary> /// Populate eBay SDK ApiContext object with data from application configuration file /// </summary> /// <returns>ApiContext</returns> static ApiContext GetApiContext(bool live) { //apiContext is a singleton, //to avoid duplicate config file reading if (apiContext != null) { return apiContext; } else { apiContext = new ApiContext(); ApiCredential apiCredential = new ApiCredential(); if (live) { //set Api Server Url apiContext.SoapApiServerUrl = "https://api.ebay.com/wsapi"; apiContext.EPSServerUrl = "https://api.ebay.com/ws/api.dll"; //set Api Token to access eBay Api Server using (var sw = new StreamReader("../../../ebayliveaccess.txt")) { apiCredential.eBayToken = sw.ReadLine(); } } else { //set Api Server Url apiContext.SoapApiServerUrl = "https://api.sandbox.ebay.com/wsapi"; apiContext.EPSServerUrl = "https://api.sandbox.ebay.com/ws/api.dll"; //set Api Token to access eBay Api Server using (var sw = new StreamReader("../../../ebayaccess.txt")) { apiCredential.eBayToken = sw.ReadLine(); } } apiContext.ApiCredential = apiCredential; //set eBay Site target to US apiContext.Site = SiteCodeType.US; using (var sw = new StreamReader("../../../ebayinfo.txt")) { paypalEmail = sw.ReadLine(); locationZip = int.Parse(sw.ReadLine()); } return apiContext; } }
private void InitializeContext() { Context = new ApiContext(); Context.SoapApiServerUrl = ConfigurationManager.AppSettings["Environment.ApiServerUrl"]; ApiCredential apiCredential = new ApiCredential(); apiCredential.eBayToken = ConfigurationManager.AppSettings["UserAccount.ApiToken"]; apiCredential.ApiAccount = new ApiAccount(); apiCredential.ApiAccount.Application = ConfigurationManager.AppSettings["Environment.AppId"]; apiCredential.ApiAccount.Certificate = ConfigurationManager.AppSettings["Environment.CertId"]; apiCredential.ApiAccount.Developer = ConfigurationManager.AppSettings["Environment.DevId"]; Context.ApiCredential = apiCredential; Context.Site = SiteCodeType.Germany; Context.ApiLogManager = new ApiLogManager(); Context.ApiLogManager.ApiLoggerList.Add(new FileLogger( ConfigurationManager.AppSettings["Ebay.Logfile"], false, false, true)); Context.ApiLogManager.EnableLogging = true; }
ApiContext GetApiSession() { ApiContext session = new ApiContext(); session.SoapApiServerUrl = ConfigurationManager.AppSettings[KEY_API_URL]; // Initialize log. if( LogManager != null ) { session.ApiLogManager = LogManager; } ApiCredential ac = new ApiCredential(); session.ApiCredential = ac; string tokenStr = ConfigurationManager.AppSettings[KEY_APITOKEN]; bool useToken = tokenStr.Length > 0; if( useToken ) { ac.eBayToken = tokenStr; } return session; }
static void SetServiceContext() { eBayApiServiceUrl = Utility.GetApplicationSetting<string>(Constants.CONST_SETTINGS_EBAY_API_SERVER_URL, ""); eBayApiToken = Utility.GetApplicationSetting<string>(Constants.CONST_SETTINGS_EBAY_API_TOKEN, ""); _apiContext = new ApiContext(); _apiContext.SoapApiServerUrl = eBayApiServiceUrl; ApiCredential apiCredential = new ApiCredential(); apiCredential.eBayToken = eBayApiToken; _apiContext.ApiCredential = apiCredential; _apiContext.Site = SiteCodeType.UK; _apiContext.ApiLogManager = new ApiLogManager(); CallRetry retry = new CallRetry(); retry.DelayTime = 3000; retry.MaximumRetries = 5; retry.TriggerHttpStatusCodes.Add(500); retry.TriggerHttpStatusCodes.Add(502); _apiContext.CallRetry = retry; FileLogger loger = new FileLogger(); string path = Utility.GetApplicationSetting<string>("LogFilePath", @"D:\"); //string assemblyDir = Path.GetDirectoryName(path); string logFileDirectory = Path.Combine(path, @"LogFilePath"); if (!Directory.Exists(logFileDirectory)) { Directory.CreateDirectory(logFileDirectory); } string logFileName = string.Format(@"{0}\eBayLog_{1}.txt", logFileDirectory, DateTime.Now.Date.ToString("yyyyMMdd")); loger.FileName = logFileName; //loger.LogApiMessages = true; loger.LogExceptions = true; loger.LogInformations = false; _apiContext.ApiLogManager.ApiLoggerList.Add(loger); _apiContext.ApiLogManager.EnableLogging = true; }