internal void Configure(INetSuiteService service, SearchPreferences searchPref)
        {
            service.Timeout = System.Threading.Timeout.Infinite;
            service.Url     = EndPointUrl;

            service.preferences       = Preferences;
            service.searchPreferences = searchPref ?? SearchPreferences;

            if (service.CookieContainer == null)
            {
                service.CookieContainer = new System.Net.CookieContainer();
            }

            if (service.applicationInfo != null)
            {
                service.applicationInfo.applicationId = ApplicationId;
            }
            else if (ApplicationId != null)
            {
                service.applicationInfo = new ApplicationInfo()
                {
                    applicationId = ApplicationId
                };
            }
        }
Ejemplo n.º 2
0
 private static void ExecuteLogout(INetSuiteService serviceProxy, ILogger log)
 {
     try
     {
         serviceProxy.logout();
         serviceProxy.CookieContainer = null; // Will be set on next method call..
     }
     catch (Exception ex)
     {
         log.Warn("Non critical error while trying to log off", ex);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NetSuiteServiceManager"/> class.
        /// </summary>
        /// <param name="service">The service proxy object.</param>
        /// <param name="logger">The logger to be used by the Service Manager.</param>
        public NetSuiteServiceManager(INetSuiteService service, ILogger logger)
        {
            ServiceProxy  = service;
            Configuration = new NetSuiteServiceConfiguration();

            if (logger != null)
            {
                _log = logger;
            }
            else
            {
                _log = new NullLogger();
            }
        }
Ejemplo n.º 4
0
        private static SessionResponse TryLogin(INetSuiteService serviceProxy,
                                                Passport passport,
                                                ILogger log,
                                                ServiceInvocationEventArgs invokerEventArgs,
                                                Action <ServiceInvocationEventArgs> onErrorCallback)
        {
            SessionResponse response = null;

            try
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug(string.Format("Logging into NetSuite [Username={0}, Account={1}, RoleId={2}]",
                                            passport.email,
                                            passport.account,
                                            passport.role == null ? null : passport.role.internalId
                                            ));
                }

                invokerEventArgs.Exception = null;
                response = serviceProxy.login(passport);
            }
            catch (SoapException soapEx)
            {
                invokerEventArgs.Exception = soapEx;
                log.Debug("Login Failed", soapEx);

                // if this is a InvalidCredentialFault then there's no point in continuing
                bool isInvalidCredentialError = soapEx.Detail.FirstChild.Name.EndsWith("invalidCredentialsFault") ||
                                                soapEx.Detail.InnerText.StartsWith("WS_FEATURE_REQD");
                if (isInvalidCredentialError && null == onErrorCallback)
                {
                    invokerEventArgs.Exception = new InvalidCredentialException(invokerEventArgs.Exception);
                }
                else if (isInvalidCredentialError)
                {
                    invokerEventArgs.Exception = new InvalidCredentialException(invokerEventArgs.Exception);
                    onErrorCallback(invokerEventArgs);
                }
            }
            catch (Exception ex)
            {
                log.Debug("Login Failed", ex);
                invokerEventArgs.Exception = ex;
            }

            invokerEventArgs.Result = response;
            return(response);
        }
Ejemplo n.º 5
0
        /// <summary>Performs the actual login</summary>
        /// <returns></returns>
        private SessionResponse ExecuteLogin(INetSuiteService serviceProxy,
                                             NetSuiteCredential credential,
                                             Action <ServiceInvocationEventArgs> onErrorCallback)
        {
            bool loggedIn = false;

            _log.Debug("Initializing NetSuite Service Proxy", null);
            serviceProxy.CookieContainer = new CookieContainer();
            Configuration.Configure(serviceProxy);

            SessionResponse ssnResponse = null;

            ServiceInvocationEventArgs invokerEventArgs = new ServiceInvocationEventArgs("login", credential);

            for (; invokerEventArgs.InvokationAttempt < Configuration.RetryCount; invokerEventArgs.InvokationAttempt++)
            {
                ssnResponse = TryLogin(serviceProxy,
                                       credential.GetPassport(),
                                       _log,
                                       invokerEventArgs,
                                       onErrorCallback);
                loggedIn = (ssnResponse != null && ssnResponse.status.isSuccessSpecified && ssnResponse.status.isSuccess);
                if (this.IsSuspended)
                {
                    this.IsSuspended = !loggedIn;
                }

                if (loggedIn || invokerEventArgs.Cancel)
                {
                    break;
                }
                else if (!invokerEventArgs.ForceRetry)
                {
                    throw invokerEventArgs.Exception;
                }
                else if (invokerEventArgs.InvokationAttempt != Configuration.RetryCount - 1)
                {
                    WaitForRetryInterval();
                }
            }

            if (!loggedIn)
            {
                ProcessLoginError(ssnResponse, invokerEventArgs);
            }

            return(ssnResponse);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="UserSession"/> class.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <param name="credential">Credential used to create this session.</param>
        /// <param name="response">The response.</param>
        internal UserSession(INetSuiteService service, NetSuiteCredential credential, SessionResponse response)
        {
            UserId = response.userId;
            Roles  = response.wsRoleList;

            ServiceProxy = service;
            Credentials  = credential;
            IsSuccess    = response.status.isSuccess;

            if (service.CookieContainer != null)
            {
                var nsUrl   = new Uri(service.Url);
                var cookies = service.CookieContainer.GetCookies(nsUrl);
                for (int i = 0; i < cookies.Count; i++)
                {
                    if (cookies[i].Name.Equals(JSESSIONID, StringComparison.CurrentCultureIgnoreCase))
                    {
                        SessionId = cookies[i].Value;
                        break;
                    }
                }
            }
        }
 internal void Configure(INetSuiteService service)
 {
     Configure(service, SearchPreferences);
 }