コード例 #1
0
        /// <summary>
        /// Register Analytics Data to the Server
        /// </summary>
        /// <returns></returns>
        public async Task <WorklightResult> SendActivityAsync(string data)
        {
            var result = new WorklightResult();

            try
            {
                var resp = await Task.Run <string>(() =>
                {
                    _client.Analytics.Send();
                    _client.LogActivity(data);

                    return("Activity Logged");
                });

                result.Success = true;
                result.Message = resp;
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Invokes the procedured
        /// </summary>
        /// <returns>The proc.</returns>
        private async Task <WorklightResult> InvokeProc(string adapterName, string adapterProcedureName, object[] parameters)
        {
            var result = new WorklightResult();

            try
            {
                _client.Analytics.Log("Trying to invoking procedure...");

#if DEBUG
                Debug.WriteLine("Trying to invoke proc");
#endif

                var invocationData     = new WorklightProcedureInvocationData(adapterName, adapterProcedureName, parameters);
                WorklightResponse task = await _client.InvokeProcedure(invocationData);

#if DEBUG
                _client.Analytics.Log("Invoke Response : " + task.Success);
#endif

                var retval = string.Empty;

                result.Success = task.Success;

                if (task.Success)
                {
                    retval = task.ResponseJSON;
                }
                else
                {
                    retval = $"Failure: { task.Message}";
                }

                result.Message = retval.ToString();
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Call unsubscribes from the Push Notifications server
        /// </summary>
        /// <returns></returns>
        public async Task <WorklightResult> UnSubscribeAsync()
        {
            var result = new WorklightResult();

            try
            {
                var resp = await UnsubscribePush();

                result.Success  = resp.Success;
                result.Message  = "Unsubscribed";
                result.Response = resp.ResponseText;
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Make a async connection with the Server
        /// </summary>
        /// <returns></returns>
        public async Task <WorklightResult> ConnectAsync()
        {
            var result = new WorklightResult();

            try
            {
                var resp = await Connect();

                result.Success  = resp.Success;
                result.Message  = (resp.Success) ? "Connected" : resp.Message;
                result.Response = resp.ResponseText;
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }

            return(result);
        }
コード例 #5
0
        /// <summary>
        /// Make a REST call to the Adapter on the Server
        /// </summary>
        /// <param name="adapterName">The name of the adapter</param>
        /// <param name="adapterProcedureName">The name of the procedure</param>
        /// <param name="methodType">The HTTP verb used to call the procedure</param>
        /// <param name="parameters">JSON parameters</param>
        /// <returns></returns>
        public async Task <WorklightResult> RestInvokeAsync(string adapterName, string adapterProcedureName, string methodType, object[] parameters)
        {
            var result = new WorklightResult();

            try
            {
                var uriBuilder = $"{_client.ServerUrl.AbsoluteUri}/adapters/{adapterName}/{adapterProcedureName}";
                WorklightResourceRequest rr   = _client.ResourceRequest(new Uri(uriBuilder.ToString()), methodType);
                WorklightResponse        resp = await rr.Send();

                result.Success  = resp.Success;
                result.Message  = (resp.Success) ? "Connected" : resp.Message;
                result.Response = resp.ResponseText;
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }

            return(result);
        }
コード例 #6
0
        /// <summary>
        /// Call a procedure from Async Method
        /// </summary>
        /// <returns></returns>
        public async Task <WorklightResult> InvokeAsync(string adapterName, string adapterProcedureName, object[] parameters)
        {
            var result = new WorklightResult();

            try
            {
                var conResp = await ConnectAsync();

                if (!conResp.Success)
                {
                    return(conResp);
                }

                result = await InvokeProc(adapterName, adapterProcedureName, parameters);
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }

            return(result);
        }