private void PingAndConnectWithServers(Simulation simulation, SimulationSettings settings,
                                               CancellationToken token)
        {
            // Ping each node by using info endpoint and connect in order to update status
            simulation.ServerNodes.Where(n => settings.NodesAndTransactions.Keys.Contains(n.Id)).ParallelForEach(node =>
            {
                var uri             = $"{node.HttpAddress}/api/info";
                var responseMessage = _httpService.Get(uri, _nodeTimeout, _hostingRetryCount, token);
                if ((node.IsConnected = responseMessage.IsSuccessStatusCode) != true)
                {
                    Console.WriteLine($"Could not ping server node: {node.Id}");
                }
                else if (responseMessage.IsSuccessStatusCode)
                {
                    var url            = $"{node.HttpAddress}/simulationHub";
                    node.HubConnection = new HubConnectionBuilder().WithUrl(url).Build();

                    // Reconnect when connection is closing
                    node.HubConnection.Closed += async error =>
                    {
                        await Task.Delay(new Random().Next(0, 5) * 1000, token);
                        await node.HubConnection.StartAsync(token);
                    };

                    // Register action: change of working status
                    const string methodName = nameof(ISimulationClient.ChangeWorkingStatus);
                    node.HubConnection.On <bool>(methodName, isWorking => { node.IsWorking = isWorking; });

                    // Start the connection
                    node.HubConnection.StartAsync(token).Wait(token);
                }
            }, token);
        }
Exemple #2
0
        public AuthUserQueryResponse SearchUserByEmail
            (string email)
        {
            var result = new AuthUserQueryResponse {
                Condition = false, Message = string.Empty, User = new UserQueryModel()
            };
            //var emailEncoded = System.Net.WebUtility.UrlEncode(email);
            var url         = $"{_applicationSetting.Authority}api/v2/users-by-email?email={email}";
            var tokenResult = GetManagementApiToken();

            var httpResult = _httpService.Get(url, tokenResult.token);

            if (!httpResult.condition)
            {
                _logService.Log(LogLevel.Exception, $"(bool condition, string message, UserQueryModel value)  SearchUserByEmail -> there was a issue getting the details from auth0");
                result.Message = "There was a issue getting the user information.";
                return(result);
            }
            try
            {
                var deserializedResult = JsonConvert.DeserializeObject <List <UserQueryModel> > (httpResult.result);
                result.Condition = true;
                result.User      = deserializedResult.First();
                return(result);
            }
            catch (Exception e)
            {
                _logService.Log(LogLevel.Exception, e.Message);
                result.Message = e.Message;
                return(result);
            }
        }
Exemple #3
0
        public async Task <ShopifyProductModel[]> GetProducts(string username)
        {
            var creds = await GetCredentials(username);

            if (creds == null)
            {
                return(new ShopifyProductModel[0]); //Not integrated into shopify
            }
            string endpoint = ShopifyEndpoints.BaseEndpoint(creds.Shop, ShopifyEndpoints.Products);

            var response = await http.Get(endpoint, (client) =>
            {
                addAuthenticatoin(client, creds.AccessToken);
            });

            string message = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                var productResponse = JObject.Parse(message).SelectToken("product").ToString();
                var ret             = JsonConvert.DeserializeObject <ShopifyProductModel[]>(productResponse, jsonSettings);
                return(ret);
            }

            return(new ShopifyProductModel[0]);
        }
Exemple #4
0
        public WeatherResponse GetWeather(string city)
        {
            _logger.Debug("Weather getting...");
            var query    = String.Format(QUERY, city);
            var response = _httpService.Get(query);

            return(response);
        }
        public async Task <BusPassport> getBusPassForUser(int userId)
        {
            string url      = "/api/BusPassport/" + userId.ToString();
            var    response = await _httpService.Get <BusPassport> (url);

            Console.WriteLine(response);
            return(response);
        }
Exemple #6
0
        public async Task <ListExperimentsResponse> ListExperiments(ViewType viewtype)
        {
            var response = await _httpService.Get <ListExperimentsResponse, Object>(
                _getPath(MLFlowAPI.Experiments.BasePath, MLFlowAPI.Experiments.List),
                new { viewtype = viewtype.ToString() });

            return(response);
        }
        public override async Task <ItemDetail> SearchItem(SingleItemRequest item)
        {
            if (item.ID.EmptyOrNull() && item.Title.EmptyOrNull())
            {
                if (item.Link.EmptyOrNull())
                {
                    throw new AllowedException("ID, Title and Link cannot be empty");
                }

                item = new AliexpressQueryString().DecodeItemLink(item.Link);

                //Means there was a translation error in the URI format
                if (item.ID.EmptyOrNull() & item.Title.EmptyOrNull())
                {
                    return(null);
                }
            }

            string endpoint = SearchEndpoints.AliexpressItemUrl(item.Title, item.ID);

            var        response = "";
            ItemDetail detail   = null;

            try
            {
                var responseMessage = await http.Get(endpoint);

                response = await responseMessage.Content.ReadAsStringAsync();
            }
            catch (Exception e)
            {
            }

            try
            {
                detail = new AliexpressPageDecoder().ScrapeSingleItem(response);

                var freights = await CalculateFreight(new FreightAjaxRequest()
                {
                    ProductID    = item.ID,
                    Country      = item.ShipCountry,
                    CurrencyCode = "USD"
                });

                if (freights.Length > 0)
                {
                    var def = freights.FirstOrDefault(x => x.IsDefault == true);
                    detail.ShippingPrice = def.LocalPrice;
                    detail.ShippingType  = def.CompanyDisplayName;
                }
            }
            catch (Exception e)
            {
                await raven.CaptureNetCoreEventAsync(e);
            }

            return(detail);
        }
 public async Task<List<Department>> GetDepartments()
 {
     var response = await _httpService.Get<List<Department>>(url);
     if (!response.Success)
     {
         throw new ApplicationException(await response.GetBody());
     }
     return response.Response;
 }
Exemple #9
0
        public async Task <Tuple <List <StopPredictionData>, int> > GetStopPredictionsForRoute(string stopId, string routeCode)
        {
            var result = await _httpService.Get <PredictionDataResult>(PredictionDataApi + "?shouldLog=false&stopId=" + HttpUtility.UrlEncode(stopId));

            var routeData = result.GrpByPtrn.Where(x => x.RouteCode == routeCode).FirstOrDefault();
            int patternId = routeData?.PatternId ?? 0;

            return(new Tuple <List <StopPredictionData>, int>(routeData?.Predictions, patternId));
        }
        public async Task <List <Link> > GetLinks(int id)
        {
            var response = await httpService.Get <List <Link> >($"{url}/{id}/list");

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }
            return(response.Response);
        }
        public async Task <ProjectOutDto> GetProject(Guid projectId)
        {
            var httpresponse = await _httpService.Get <ProjectOutDto>($"projects/{projectId}");

            if (!httpresponse.Success)
            {
                throw new ApplicationException();
            }
            return(httpresponse.Data);
        }
        /// <summary>
        /// Get Interval
        /// </summary>
        /// <param name="periodId">Destination Period Id</param>
        /// <returns>Calendar</returns>

        public async Task <CalendarDto> GetInterval(int periodId)
        {
            var pathParams = new HttpPathParameters();

            pathParams.Add(periodId, -1);

            var settings = new HttpSettings(Url, null, pathParams);

            return(await _httpService.Get <CalendarDto>(settings));
        }
        public async Task <List <ConnectParameters> > GetSources()
        {
            var response = await httpService.Get <List <ConnectParameters> >(url);

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }
            return(response.Response);
        }
        public async Task <List <Person> > GetPeople()
        {
            var response = await httpService.Get <List <Person> >(url);

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }
            return(response.Response);
        }
Exemple #15
0
        public async Task <List <Vote> > GetVotes()
        {
            var httpResponse = await httpService.Get <List <Vote> >(url);

            if (!httpResponse.Success)
            {
                throw new ApplicationException(await httpResponse.GetBody());
            }
            return(httpResponse.Response);
        }
        public async Task <Genre> GetGenre(int id)
        {
            var response = await httpService.Get <Genre>($"{url}/{id}");

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }
            return(response.Response);
        }
Exemple #17
0
        public async Task <T> Get <T>(string url)
        {
            var response = await httpService.Get <T>(url);

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }
            return(response.Response);
        }
        public async Task <List <SubCategory> > GetSubCategories()
        {
            var response = await httpService.Get <List <SubCategory> >(url);

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }
            return(response.Response);
        }
        public async Task <List <HistoricoStatus> > GetHistoricoStatus()
        {
            var response = await httpService.Get <List <HistoricoStatus> >(url);

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }
            return(response.Response);
        }
Exemple #20
0
        public async Task <List <Genre> > GetGenres(bool includeToken = true)
        {
            var response = await httpService.Get <List <Genre> >(url, includeToken);

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }
            return(response.Response);
        }
        public async Task <List <WebApiLogs> > Get()
        {
            var response = await _httpService.Get <List <WebApiLogs> >($"{url}/all");

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }
            return(response.Response);
        }
Exemple #22
0
        public async Task <List <MessageQueueInfo> > GetQueueMessage()
        {
            var response = await httpService.Get <List <MessageQueueInfo> >($"{url}");

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }
            return(response.Response);
        }
Exemple #23
0
        public async Task <List <PipeLine> > GetPipeline(string name)
        {
            var response = await httpService.Get <List <PipeLine> >($"{url}/{name}");

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }
            return(response.Response);
        }
        public async Task <List <DmsIndex> > GetIndex(string source)
        {
            var response = await httpService.Get <List <DmsIndex> >($"{url}/{source}");

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }
            return(response.Response);
        }
        public async Task <UpdateUserDTO> GetSingle(int id)
        {
            var response = await _httpService.Get <UpdateUserDTO>($"{userUrl}/{id}");

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }

            return(response.Data);
        }
        public async Task <Filme[]> GetFilmes()
        {
            var response = await http.Get <Filme[]>("api/filmes");

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }

            return(response.Response);
        }
        public async Task <List <ProductViewModel> > GetAll()
        {
            var response = await _httpService.Get <List <ProductViewModel> >(baseURL);

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }

            return(response.Data);
        }
Exemple #28
0
        public async Task <ConnectParameters> GetSource(string Name)
        {
            string url      = baseUrl.BuildFunctionUrl("GetDataSource", $"name={Name}", apiKey);
            var    response = await httpService.Get <ConnectParameters>(url);

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }
            return(response.Response);
        }
        public async Task <List <CustomerOrderViewModel> > GetAllByUser(int id)
        {
            var response = await _httpService.Get <List <CustomerOrderViewModel> >($"{baseURL}/byuser/{id}");

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }

            return(response.Data);
        }
        public async Task <List <Group> > GetItemList()
        {
            var response = await _httpService.Get <List <Group> >(url);

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }

            return(response.Response);
        }
       private static void buildCache(IHttpService http, ITemplateCacheService templateCache)
       {
           string[] uis =
           {  							GameController.View,
 							MinimizeController.View,
 							DebugGameController.View,
 							TestGameController.View,
 							GameEffectsEditorController.View,
 							LoginController.View,
 							DebugQuestionController.View,
 							QuestionController.View,
 							HomeController.View,
 							ActiveLobbyController.View,
 							CreateRoomController.View,
 							GameManagerController.View,
 							GameEditorController.View,
 							GameLayoutEditorController.View,
 							GameTestEditorController.View,
 							GameScenarioEditorController.View,
 							GameCodeController.View,
 							MessageController.View,
                           
           };
           for (int index = 0; index < uis.Length; index++)
           {
               var ui = string.Format("{1}partials/UIs/{0}.html", uis[index], Constants.ContentAddress);
               http.Get(ui, null).Success(a => templateCache.Put(ui, a));
           }
       }
 private static void buildCache(IHttpService http, ITemplateCacheService templateCache)
 {
     string[] uis =
     {
         LevelSelectorController.View,
     };
     for (int index = 0; index < uis.Length; index++)
     {
         var ui = string.Format("{1}partials/UIs/{0}.html", uis[index], Constants.ContentAddress);
         http.Get(ui, null).Success(a => templateCache.Put(ui, a));
     }
 }
Exemple #33
0
        protected RatingResult GetRatingFromApi(string imdbId, IHttpService httpService)
        {
            string data = httpService.Get(@"http://www.omdbapi.com/?i="+imdbId);
            JObject o = JObject.Parse(data);

            return new RatingResult
            {
                Title = o["Title"].ToString(),
                Year = o["Year"].ToString(),
                Rating = o["imdbRating"].ToString(),
                Poster = o["Poster"].ToString()
            };
        }