示例#1
0
        private bool InitializeApi(FsApiWebService fsApiService, bool serverAuthenticated)
        {
            if (serverAuthenticated)
            {
                if (User != null)
                {
                    return(true);
                }
            }
            else if (ClientUser != null)
            {
                return(true);
            }

            LoginModel model = new LoginModel {
                UserName = AppConfig.FsUserEmail, Password = AppConfig.FsPassword
            };

            UserTDO user = null;

            try {
                FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Authorizing for fotoShout on {0}...", fsApiService.BaseAddress));
                user = fsApiService.Login(AppConfig.FsApiKey, model);
                if (user == null)
                {
                    FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("There is no user on {0} associated with the fotoShout Authorization key. The authentication will be retried in the next round.", fsApiService.BaseAddress));
                    return(false);
                }
                FotoShoutUtils.Log.LogManager.Info(_logger, "Succeeded to access to the user info.");
            }
            catch (Exception ex) {
                if (ex is WebException)
                {
                    FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Exception on {0}: {1}.", fsApiService.BaseAddress, ex.Message));
                }
                else
                {
                    FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("There is no user on {0} associated with the fotoShout Authorization key. The authentication will be retried in the next round.", fsApiService.BaseAddress));
                }
                return(false);
            }

            if (serverAuthenticated)
            {
                User = user;
            }
            else
            {
                ClientUser = user;
            }

            return(true);
        }