Ejemplo n.º 1
0
        public static IApiService GetWebService(Api.AccessToken accessToken, string accountName)
        {
            if (UseLocalDispatcher())
            {
                var dispatcher = DispatcherService.Wrapper;
                var dtoService = new ApiToDispatcherAdapter(dispatcher, "2.2.2.2", accountName);
                var apiService = new ApiService(dtoService, accessToken);
                return(apiService);
            }
            var uri = ApiHelper.GetApiUrl(accountName);

            if (CanRunApiOnIisExpress && uri.AbsoluteUri.StartsWith("http://localhost"))
            {
                CanRunApiOnIisExpress = false;
                IisExpress.StartApiWebService();
            }
            var dtoService2 = new DtoServiceProxy(uri);

            return(new ApiService(dtoService2, accessToken));
        }
Ejemplo n.º 2
0
        protected DtoServiceProxy CreateDtoService(string accountName)
        {
            if (string.IsNullOrEmpty(accountName))
            {
                throw new ResponseCodeException(ResponseCode.EmptyAccountName, "Не указан AccountName");
            }

            Uri apiUrl = null;

            if (!string.IsNullOrEmpty(Config.Access.Url))
            {
                try
                {
                    apiUrl = new Uri(Config.Access.Url);
                }
                catch (UriFormatException exception)
                {
                    throw new ResponseCodeException(ResponseCode.ApiUrlFormatError, "Неверный формат адреса Api: " + exception.Message);
                }
            }
            else
            {
                try
                {
                    apiUrl = ApiHelper.GetApiUrl(accountName);
                }
                catch (UriFormatException exception)
                {
                    throw new ResponseCodeException(ResponseCode.AccountNameFormatError, "Неверный формат имени аккаунта: " + exception.Message);
                }
            }

            InternalLog.Info("ApiUrl: " + apiUrl.AbsoluteUri);

            var dtoService = new DtoServiceProxy(apiUrl);

            return(dtoService);
        }