Ejemplo n.º 1
0
 private T PerformGenericRequest <T>(HttpRequest request)
 {
     using (HttpClient httpClient = new HttpClient())
     {
         XmlDocument response = httpClient.PerformRequest(request);
         return(ResponseReader.ReadGenericResponse <T>(response));
     }
 }
Ejemplo n.º 2
0
        public SalesforceSession Login()
        {
            lock (Lock)
            {
                SalesforceSession session;
                if (_config.UseSessionStore)
                {
                    session = _sessionStore.RetrieveSession(_config.Environment ?? "Default");
                    if (session != null)
                    {
                        return(session);
                    }
                }

                if (_config.Session != null)
                {
                    return(_config.Session);
                }

                using (HttpClient httpClient = new HttpClient())
                {
                    XmlDocument response = httpClient.PerformRequest(SoapRequestManager.GetLoginRequest(_config));
                    SimpleLogin result   = ResponseReader.ReadGenericResponse <SimpleLogin>(response, "result");

                    Uri instanceUrl = new Uri(result.ServerUrl);
                    session = new SalesforceSession
                    {
                        Environment = _config.Environment,
                        ApiVersion  = _config.ApiVersion,
                        IsSandbox   = _config.IsSandbox,
                        LastLogin   = DateTime.Now,
                        InstanceUrl = instanceUrl.Scheme + "://" + instanceUrl.Host,
                        SessionId   = result.SessionId,
                        Proxy       = _config.Proxy,
                        BatchSize   = _config.BatchSize,
                    };

                    if (_config.UseSessionStore)
                    {
                        _sessionStore.StoreSession(session);
                    }
                    _config.Session = session;

                    return(session);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Login Action
        ///     - Stores session data for re-use
        /// </summary>
        /// <returns></returns>
        public ZuoraSession Login()
        {
            lock (Lock)
            {
                ZuoraSession session;
                if (_config.UseSessionStore)
                {
                    session = _sessionStore.RetrieveSession(_config.EnvironmentName ?? "Default");
                    if (session != null)
                    {
                        return(session);
                    }
                }

                if (_config.Session != null)
                {
                    return(_config.Session);
                }

                using (HttpClient httpClient = new HttpClient())
                {
                    XmlDocument response = httpClient.PerformRequest(SoapRequestManager.GetLoginRequest(_config));
                    SimpleLogin result   = ResponseReader.ReadGenericResponse <SimpleLogin>(response);

                    Uri instanceUrl = new Uri(result.ServerUrl);
                    session = new ZuoraSession
                    {
                        SoapUrl     = _config.SoapUrl,
                        InstanceUrl = instanceUrl.Scheme + "://" + instanceUrl.Host,
                        SessionId   = result.SessionId
                    };

                    if (_config.UseSessionStore)
                    {
                        _sessionStore.StoreSession(session);
                    }
                    _config.Session     = session;
                    _config.InstanceUrl = session.InstanceUrl;

                    return(session);
                }
            }
        }