private void AuthenticateRequest() { try { if (ZCRMConfigUtil.HandleAuthentication) { string accessToken = (string)(Type.GetType(ZCRMConfigUtil.GetAuthenticationClass()).GetMethod("GetAccessToken", BindingFlags.Static | BindingFlags.Public).Invoke(null, null)); if (accessToken == null) { ZCRMLogger.LogError("Access token is not set"); throw new ZCRMException(APIConstants.AUTHENTICATION_FAILURE, "Access token is not set"); } SetHeader("Authorization", APIConstants.authHeaderPrefix + accessToken); ZCRMLogger.LogInfo("Token fetched successfully.."); } } catch (TargetInvocationException e) { ZCRMLogger.LogError(e.GetBaseException()); if (e.GetBaseException() is ZCRMException) { throw (ZCRMException)(e.GetBaseException()); } throw new ZCRMException(e.GetBaseException()); } catch (Exception e) when(e is TargetException || e is MethodAccessException) { ZCRMLogger.LogError(e); throw new ZCRMException(e); } }
private HttpWebRequest GetHttpWebRequestClient() { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); if (ZCRMConfigUtil.ConfigProperties.ContainsKey("timeout")) { int?timeoutPeriod = Convert.ToInt32(ZCRMConfigUtil.GetConfigValue("timeout")); if (timeoutPeriod != null) { request.Timeout = (int)timeoutPeriod; } } request.UserAgent = APIConstants.USER_AGENT; return(request); }
public FileAPIResponse DownloadUserPhoto(CommonUtil.PhotoSize?photoSize) { try { requestMethod = APIConstants.RequestMethod.GET; urlPath = ZCRMConfigUtil.GetPhotoUrl(); if (photoSize != null) { requestQueryParams.Add("photo_size", photoSize.ToString()); } return(APIRequest.GetInstance(this).DownloadFile()); } catch (Exception e) when(!(e is ZCRMException)) { ZCRMLogger.LogError(e); throw new ZCRMException(APIConstants.SDK_ERROR, e); } }
internal static void Init() { Trace.AutoFlush = true; logger = new ZCRMLogger(); logSwitch = new TraceSwitch("ZCRMLogger", "ZCRMSDK Logger"); string minLoglevel = ZCRMConfigUtil.GetConfigValue(APIConstants.MIN_LOG_LEVEL); if ((minLoglevel == null) || (!APIConstants.LOGGER_LEVELS.ContainsKey(minLoglevel))) { logSwitch.Level = TraceLevel.Info; } else if (APIConstants.LOGGER_LEVELS.ContainsKey(minLoglevel)) { logSwitch.Level = APIConstants.LOGGER_LEVELS[minLoglevel]; } string logFile = ZCRMConfigUtil.GetConfigValue("logFilePath"); if (string.IsNullOrEmpty(logFile)) { logFile = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location) + Path.DirectorySeparatorChar + "LogFile.log"; } else { logFile += "LogFile.log"; } DefaultTraceListener defaultTrace = new DefaultTraceListener { LogFileName = logFile }; while (Trace.Listeners.Count > 0) { Trace.Listeners.RemoveAt(0); } Trace.Listeners.Add(defaultTrace); }
/// <summary> /// To Initialize SDK with configuration property values through app.config. /// </summary> /* public static void Initialize() * { * Initialize(true); * } * * public static void Initialize(bool handleAuthentication) * { * ZCRMConfigUtil.Initialize(handleAuthentication, null, null); * } * * /// <summary> * /// To Initialize SDK with configuration property values through text file like stream data. * /// </summary> * /// <param name="inputStream">File stream data.(Stream)</param> * public static void Initialize(Stream inputStream) * { * ZCRMConfigUtil.CustomInitialize(inputStream); * }*/ /// <summary> /// To Initialize SDK with configuration property values through Dictionary. /// </summary> /// <param name="config">Is the Dictionary contains C#SDK configuration key values.</param> public static void Initialize(Dictionary <string, string> config) { ZCRMConfigUtil.CustomInitialize(config); }