Example #1
0
        public Task <IConnectionState> Run(Action <ServerSentEvent> donothing, CancellationToken cancelToken)
        {
            IWebRequester requester = _webRequesterFactory.Create();
            var           taskResp  = requester.Get(_url, _tokenService, _headers);

            return(taskResp.ContinueWith <IConnectionState>(tsk =>
            {
                if (tsk.Status == TaskStatus.RanToCompletion && !cancelToken.IsCancellationRequested)
                {
                    IServerResponse response = tsk.Result;
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        return new ConnectedState(response, _webRequesterFactory, _headers, _tokenService, _logger);
                    }
                    else
                    {
                        _logger.LogInformation("Failed to connect to: " + _url.ToString() + response ?? (" Http statuscode: " + response.StatusCode));
                    }
                }
                else
                {
                    _logger.LogDebug("Task Status {@Status}: {Reason}", tsk.Status, ExceptionDetails.InnermostMessage(tsk.Exception));
                }

                return new DisconnectedState(_url, _webRequesterFactory, _headers, _tokenService, _logger);
            }));
        }
Example #2
0
    //working
    public IEnumerator getLevels(long idUser)
    {
        clearList();

        Debug.Log("Getting levels for user " + idUser + "...");
        string sailsUrl = "https://secure-sands-20186.herokuapp.com/getalllevelbyiduserwithjson";

        Dictionary <string, string> parameters = new Dictionary <string, string>();

        parameters.Add("iduser", idUser.ToString());


        UnityWebRequest resultRequest = _webRequester.Get(sailsUrl, parameters);

        yield return(new WaitUntil(() => resultRequest.isDone));

        Debug.Log(resultRequest.responseCode + " Result : " + resultRequest.downloadHandler.text);

        levelsObj = JsonUtility.FromJson <LevelsForEd>("{\"levels\":" + resultRequest.downloadHandler.text + "}");

        foreach (LevelForEd lvl in levelsObj.levels)
        {
            GameObject button = Instantiate(levelButtonGroup, grid);
            button.GetComponent <ButtonUpdater>().setValues(lvl, menuEditor, editor);
        }
    }
Example #3
0
    private IEnumerator getMeteo()
    {
        Dictionary <string, string> parameters = new Dictionary <string, string>();

        Debug.Log(_locationFinder);
        StartCoroutine(_locationFinder.Refresh(locationMaxTime));
        yield return(new WaitUntil(() => _locationFinder.getLastStatus() != LocationFinderStatus.ONGOING));

        if (_locationFinder.getLastStatus() == LocationFinderStatus.ERROR && _locationFinder.hasInitialized())
        {
            Debug.Log("Failed to Initialize Meteo");
            yield break;
        }

        Debug.Log(_locationFinder.getLastStatus() + " " + _locationFinder.getLastCoordinates().latitude + " " + _locationFinder.getLastCoordinates().longitude);

        parameters.Add("lat", _locationFinder.getLastCoordinates().latitude.ToString());
        parameters.Add("lon", _locationFinder.getLastCoordinates().longitude.ToString());
        parameters.Add("APPID", apiKey);
        parameters.Add("mode", "xml");

        UnityWebRequest resultRequest = _webRequester.Get("http://api.openweathermap.org/data/2.5/weather", parameters);

        yield return(new WaitUntil(() => resultRequest.isDone));

        meteoStatus.Init(resultRequest.downloadHandler.text);

        Debug.Log(resultRequest.downloadHandler.text);
        //text.text = meteoStatus.ToString();

        string meteoString = meteoStatus.ToString();

        if (meteoStatus.getWeatherType() == WeatherType.NO)
        {
            meteoVisual.transform.GetChild(0).gameObject.SetActive(true);
            meteoVisual.transform.GetChild(1).gameObject.SetActive(false);
            meteoVisual.transform.GetChild(2).gameObject.SetActive(false);
        }
        else if (meteoStatus.getWeatherType() == WeatherType.RAIN)
        {
            meteoVisual.transform.GetChild(0).gameObject.SetActive(false);
            meteoVisual.transform.GetChild(1).gameObject.SetActive(true);
            meteoVisual.transform.GetChild(2).gameObject.SetActive(false);
        }
        else if (meteoStatus.getWeatherType() == WeatherType.SNOW)
        {
            meteoVisual.transform.GetChild(0).gameObject.SetActive(false);
            meteoVisual.transform.GetChild(1).gameObject.SetActive(false);
            meteoVisual.transform.GetChild(2).gameObject.SetActive(true);
        }
    }
Example #4
0
    public IEnumerator updateLevels()
    {
        Debug.Log("Welcome to Levels Getter");
        UnityWebRequest allLevelsRequest = _webRequester.Get("https://immense-lake-57494.herokuapp.com/levels", null);

        yield return(new WaitUntil(() => allLevelsRequest.isDone)); // To replace with personnal levels

        MetaData currentMetaData;

        if (MetaDataAction.metadataExists())
        {
            currentMetaData = MetaDataAction.readMetaData();
        }
        else
        {
            currentMetaData        = new MetaData();
            currentMetaData.levels = new List <level>();
        }


        Debug.Log("Finish downloading...");

        if (allLevelsRequest.responseCode != 200)
        {
            yield return(null);
        }

        Debug.Log("Start parsing... " + allLevelsRequest.downloadHandler.text);

        Levels allLevels = JsonUtility.FromJson <Levels>("{\"all\":" + allLevelsRequest.downloadHandler.text + "}");

        foreach (Level level in allLevels.all)
        {
            Debug.Log("OBJET LEVEL : " + JsonUtility.ToJson(level));
            if (!currentMetaData.levels.Exists(x => x.id == Convert.ToInt64(level.id)))
            {
                string filePath = Path.Combine(Application.persistentDataPath, "Levels/" + level.name);
                File.WriteAllText(filePath, JsonUtility.ToJson(level.json));
                currentMetaData.levels.Add(MetaDataAction.LevelToMetaDataLevel(level));
            }
        }

        Debug.Log("Current Meta Data... " + JsonUtility.ToJson(currentMetaData));

        yield return(MetaDataAction.modifyMetaData(currentMetaData));

        menuManager.StartMenu();
    }
        public Task <IConnectionState> Run(Action <ServerSentEvent> donothing, CancellationToken cancelToken)
        {
            IWebRequester requester = mWebRequesterFactory.Create();
            var           taskResp  = requester.Get(mUrl);

            return(taskResp.ContinueWith <IConnectionState>(tsk =>
            {
                if (tsk.Status == TaskStatus.RanToCompletion && !cancelToken.IsCancellationRequested)
                {
                    IServerResponse response = tsk.Result;
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        return new ConnectedState(response, mWebRequesterFactory);
                    }
                    else
                    {
                        _logger.Info("Failed to connect to: " + mUrl.ToString() + response ?? (" Http statuscode: " + response.StatusCode));
                    }
                }

                return new DisconnectedState(mUrl, mWebRequesterFactory);
            }));
        }