Exemple #1
0
        /// <summary>
        /// Start an asynchronous request to an HTTP server, returning a promise that will resolve when
        /// the request is completed or rejected.
        /// </summary>
        ///
        /// <param name="url">
        /// The URL of the remote server
        /// </param>
        /// <param name="options">
        /// The options to use when creating the reqest
        /// </param>
        ///
        /// <returns>
        /// A promise that resolves when the request completes
        /// </returns>

        public static IPromise <ICsqWebResponse> CreateFromUrlAsync(string url, ServerConfig options = null)
        {
            var deferred = When.Deferred <ICsqWebResponse>();
            int uniqueID = AsyncWebRequestManager.StartAsyncWebRequest(url, deferred.Resolve, deferred.Reject, options);

            return(deferred);
        }
Exemple #2
0
        public void RandomUrls()
        {
            ServerConfig options = new ServerConfig {
                TimeoutSeconds = 5
            };

            int           outer       = totalTests / simultaneousThreads;
            var           list        = GetRandomUrls(totalTests);
            List <string> successList = new List <string>();
            List <string> failList    = new List <string>();

            int cur = 0;

            for (int i = 0; i < outer; i++)
            {
                IPromise[]    promises = new IPromise[simultaneousThreads];
                List <string> active   = new List <string>();

                for (int j = 0; j < simultaneousThreads; j++)
                {
                    string url = list[cur++];
                    active.Add(url);

                    promises[j] = CQ.CreateFromUrlAsync(url, options).Then((success) =>
                    {
                        successList.Add(FormatResult(success));
                        active.Remove(success.Url);
                    }, (fail) => {
                        failList.Add(FormatResult(fail));
                        active.Remove(fail.Url);
                    });
                }


                if (!AsyncWebRequestManager.WaitForAsyncEvents(10000))
                {
                    AsyncWebRequestManager.CancelAsyncEvents();
                    foreach (var item in active)
                    {
                        failList.Add(item + ": aborted");
                    }
                }
            }

            Debug.WriteLine(FormatTestOutput(successList, failList));
        }
Exemple #3
0
        /// <summary>
        /// Start an asynchronous request to an HTTP server.
        /// </summary>
        ///
        /// <param name="url">
        /// The URL of the remote server.
        /// </param>
        /// <param name="callbackSuccess">
        /// A delegate to invoke upon successful completion of the request.
        /// </param>
        /// <param name="callbackFail">
        /// A delegate to invoke upon failure.
        /// </param>
        /// <param name="options">
        /// Options to use when creating the request.
        /// </param>
        ///
        /// <returns>
        /// A unique identifier which will be passed through to the response and can be used to assocate
        /// a response with this request.
        /// </returns>

        public static int CreateFromUrlAsync(string url, Action <ICsqWebResponse> callbackSuccess, Action <ICsqWebResponse> callbackFail = null, ServerConfig options = null)
        {
            return(AsyncWebRequestManager.StartAsyncWebRequest(url, callbackSuccess, callbackFail, options));
        }
Exemple #4
0
        /// <summary>
        /// Waits until all async events have completed. Use for testing primarily as a web app should
        /// not stop normally.
        /// </summary>
        ///
        /// <param name="timeout">
        /// The maximum number of milliseconds to wait.
        /// </param>
        ///
        /// <returns>
        /// true if all events were cleared in the allotted time, false if not.
        /// </returns>

        public static bool WaitForAsyncEvents(int timeout = -1)
        {
            return(AsyncWebRequestManager.WaitForAsyncEvents(timeout));
        }