예제 #1
0
        private IEnumerator UpdateEndPoints(Action onFailed)
        {
            if (!_endPointSelector.HasAnyEndPointInfo())
            {
                yield break;
            }

            var url       = EndPointSelectorSettings.ENDPOINT_INFO_URL;
            var reqHeader = endPointGetRequestHeaderDelegate(url, new Dictionary <string, string>());

            OnEndPointGetRequestStarted();
            var cor = _endPointSelector.UpToDate(
                url,
                reqHeader,
                responseStr =>
            {
                return(OnEndPointsParseFromUpdateResponse(responseStr));
            },
                errors =>
            {
                if (0 < errors.Length)
                {
                    OnEndPointUpdateFailed(errors);
                    onFailed();
                    return;
                }
                OnEndPointUpdateSucceeded();
            },
                failReason =>
            {
                OnEndPointUpdateFailed(
                    new (string, Exception)[] {
                    (failReason, new Exception(failReason))
                }
예제 #2
0
    public IEnumerator ChangeEndPoint()
    {
        /*
         *  この機構は、起動時に通信を行い、特定のファイルの内容を更新することを前提としている。
         *  失敗した場合は起動しない、という選択肢も取る必要がある。
         */
        var retryCount = 3;

        var endPointSelector = new EndPointSelector(
            new IEndPoint[] {
            new main(),
            new sub(),
        }
            );

        var succeeded = false;

        var cor = endPointSelector.UpToDate(
            "https://raw.githubusercontent.com/sassembla/Autoya/master/Assets/AutoyaTests/RuntimeData/EndPoints/mainAndSub.json",
            new Dictionary <string, string>(),
            responseStr =>
        {
            var endPoints = new List <EndPoint>();
            var classNamesAndValuesSource = MiniJson.JsonDecode(responseStr) as Dictionary <string, object>;
            foreach (var classNamesAndValueSrc in classNamesAndValuesSource)
            {
                var className        = classNamesAndValueSrc.Key;
                var rawParameterList = classNamesAndValueSrc.Value as List <object>;

                var parameterDict = new Dictionary <string, string>();
                foreach (var rawParameters in rawParameterList)
                {
                    var parameters = rawParameters as Dictionary <string, object>;
                    foreach (var parameter in parameters)
                    {
                        var key            = parameter.Key;
                        var val            = parameter.Value as string;
                        parameterDict[key] = val;
                    }
                }

                var endPoint = new EndPoint(className, parameterDict);
                endPoints.Add(endPoint);
            }

            return(new EndPoints(endPoints.ToArray()));
        },
            namesAndErrors =>
        {
            if (namesAndErrors.Length == 0)
            {
                succeeded = true;
                return;
            }
            Debug.LogError("fauled to parse, errors:" + namesAndErrors.Length);
        },
            failReason =>
        {
            Debug.LogError("failed to get endPoints.");
        },
            10.0,
            retryCount
            );

        while (cor.MoveNext())
        {
            yield return(null);
        }

        Assert.True(succeeded);

        var ep = endPointSelector.GetEndPoint <main>();

        Assert.True(ep.key0 == "val0");
        Assert.True(ep.key1 == "default_val1");
    }