Exemplo n.º 1
0
    /// <summary>
    /// Executes the RegisterOperation asynchronously. The RegisterOperationCallback will be invoked when the operation has completed.
    /// </summary>
    /// <param name="registerOperationCallback">The RegisterOperationCallback to be invoked when the operation completes.</param>
    public void ExecuteAsync(RegisterOperationCallback registerOperationCallback)
    {
        Asserter.NotNull(registerOperationCallback, "RegisterOperation.ExecuteAsync:registerOperationCallback is null");
        WebOperationCallback webOperationCallback = (ResultSet results) =>
        {
            RegisterOperationResult result = CreateResultFromResultSet(results);
            registerOperationCallback(result);
        };

        WebOperation.ExecuteAsync(new WebOperationCriteria(WebOperationURLs.GetURL(GetType()), CreateFieldDictionaryFromCriteria(_criteria)), webOperationCallback);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Executes a WebOperation with the given criteria asynchronously. Upon completion, the given WebOperationCallback is invoked with the results of the operation.
    /// </summary>
    /// <param name="criteria">Criteria that specifies how to invoke the operation.</param>
    /// <param name="callback">The callback to be invoked upon completion of the operation.</param>
    public static void ExecuteAsync(WebOperationCriteria criteria, WebOperationCallback webOperationCallback)
    {
        Asserter.NotNull(criteria, "WebOperation.ExecuteAsync:criteria is null");
        Asserter.NotNull(webOperationCallback, "WebOpreation.ExecuteAsync:webOperationCallback");

        if (_webOperation == null)
        {
            _webOperation = new WebOperation();
        }

        _webOperation.ExecuteOperationAsync(criteria, webOperationCallback);
    }
Exemplo n.º 3
0
    /// <summary>
    /// Executes the web operation asynchronously from the given WebOperationCriteria, and invokes the given WebOperationCallback upon completion.
    /// </summary>
    /// <param name="criteria">The criteria containing the data that governs the action of this operation.</param>
    /// <param name="callback">The callback to be invoked upon completion of the operation.</param>
    private void ExecuteOperationAsync(WebOperationCriteria criteria, WebOperationCallback callback)
    {
        WWWForm form = new WWWForm();

        foreach (KeyValuePair <string, string> pair in criteria.Fields)
        {
            form.AddField(pair.Key, pair.Value);
        }

        WWW www = new WWW(criteria.URL, form);

        _coroutineRunner.StartCoroutine(WaitForWWW(www, callback));
    }
Exemplo n.º 4
0
    /// <summary>
    /// Executes the LoginOperation asynchronously. The LoginOperationCallback will be invoked when the results are ready.
    /// </summary>
    /// <param name="loginOperationCallback">The callback to be invoked when the result of the LoginOperation is ready.</param>
    public void ExecuteAsync(LoginOperationCallback loginOperationCallback)
    {
        Asserter.NotNull(loginOperationCallback, "LoginOperation.ExecuteAsync:loginOperationCallback is null");
        Dictionary <string, string> fields = new Dictionary <string, string>();

        fields.Add(kUSERNAME_FIELD, _criteria.Username);
        fields.Add(kPASSWORD_FIELD, _criteria.Password);

        WebOperationCallback webOperationCallback = (ResultSet resultSet) =>
        {
            LoginOperationResult result = CreateResultFromResultSet(resultSet);
            loginOperationCallback(result);
        };

        WebOperation.ExecuteAsync(new WebOperationCriteria(WebOperationURLs.GetURL(GetType()), fields), webOperationCallback);
    }
Exemplo n.º 5
0
    /// <summary>
    /// Coroutine function to yield control flow back to Unity while waiting for the WWW operation to complete. Upon completion,
    /// the WebOperationCallback is invoked.
    /// </summary>
    /// <param name="request">The WWW to yield for while waiting for completion.</param>
    /// <param name="callback">The callback to be invoked upon completion of the operation.</param>
    /// <returns></returns>
    private static IEnumerator WaitForWWW(WWW request, WebOperationCallback callback)
    {
        yield return(request);

        callback(ParseResponse(request));
    }