public async Task <WorklightResult> UnprotectedInvokeAsync()
        {
            var result = new WorklightResult();

            try
            {
                StringBuilder uriBuilder = new StringBuilder()
                                           .Append("/adapters")
                                           .Append("/ResourceAdapter") //Name of the adapter
                                           .Append("/publicData");     // Name of the adapter procedure

                WorklightResourceRequest rr = client.ResourceRequest(new Uri(uriBuilder.ToString(), UriKind.Relative),
                                                                     "GET");

                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);
        }
        private async void InvokeProcedureOld()
        {
            //Invoke Procedure - the old way
            Articles.Clear();
            //Params for the invocation
            WorklightProcedureInvocationData proceduerParams = new WorklightProcedureInvocationData("SampleHTTPAdapter", "getFeed", new object[] { });

            WorklightResponse resp = await MFPNewsReader.App.wlClient.InvokeProcedure(proceduerParams);

            if (resp.Success)
            {
                JsonArray jsonArray = (JsonArray)resp.ResponseJSON["rss"]["channel"]["item"];
                foreach (JsonObject title in jsonArray)
                {
                    System.Json.JsonValue titleString;
                    title.TryGetValue("title", out titleString);
                    System.Json.JsonValue itemString;
                    title.TryGetValue("description", out itemString);
                    Articles.Add(new Article(titleString, itemString));
                }
            }
            else
            {
                DisplayAlert("Connection Status failed", resp.Message, "Close");
            }
        }
Exemple #3
0
        /// <summary>
        /// Handle for the Login Information
        /// </summary>
        /// <param name="challenge">The acctually handle response for the Login</param>
        public override void HandleChallenge(WorklightResponse challenge = null)
        {
#if DEBUG
            Debug.WriteLine("We were challenged.. so we are handling it");
#endif
            var parms = new Dictionary <string, string>();
            parms.Add("j_username", "worklight");
            parms.Add("j_password", "password");

            LoginFormParameters    = new LoginFormInfo("j_security_check", parms, null, 30000, "post");
            _shouldSubmitLoginForm = true;

            //this is for Adapter based authentication
            if (challenge.ResponseJSON["authRequired"] == true)
            {
                AdapterAuthenticationInfo        AdapterAuthenticationParameters = new AdapterAuthenticationInfo();
                WorklightProcedureInvocationData invocationData = new WorklightProcedureInvocationData("HTTP",
                                                                                                       "submitAuthentication", new object[1]);
                AdapterAuthenticationParameters.InvocationData = invocationData;
                AdapterAuthenticationParameters.RequestOptions = null;
            }
            else
            {
                _isAdapterAuth = false;
                _authSuccess   = true;
            }
        }
        public override void HandleChallenge(WorklightResponse challenge)
        {
            Console.WriteLine("We were challenged.. so we are handling it");
            Dictionary <String, String> parms = new Dictionary <String, String> ();

            parms.Add("j_username", "worklight");
            parms.Add("j_password", "password");
            LoginFormParameters   = new LoginFormInfo("j_security_check", parms, null, 30000, "post");
            shouldSubmitLoginForm = true;
            //authSuccess = true;
            //this is for Adapter based authentication
            //            if (challenge.ResponseJSON["authRequired"] == true)
            //            {
            //				AdapterAuthenticationInfo AdapterAuthenticationParameters = new AdapterAuthenticationInfo();
            //                WorklightProcedureInvocationData invocationData = new WorklightProcedureInvocationData("HTTP",
            //                    "submitAuthentication" , new object[1]);
            //				AdapterAuthenticationParameters.InvocationData = invocationData;
            //				AdapterAuthenticationParameters.RequestOptions = null;
            //            }
            //            else
            //            {
            //				isAdapterAuth = false;
            //				authSuccess = true;
            //            }
        }
        private async void InvokeProcedure()
        {
            //Invoke Procedure - the new REST way
            Articles.Clear();
            //hopefully I can integrate oAuth with this sample soon
            Uri adapterMethod = new Uri(App.wlClient.ServerUrl + "/adapters/SampleHTTPAdapter/getFeed");
            WorklightResourceRequest wlResReq = MFPNewsReader.App.wlClient.ResourceRequest(adapterMethod, "GET");
            WorklightResponse        resp     = await wlResReq.Send();

            if (resp.Success)
            {
                JsonArray jsonArray = (JsonArray)resp.ResponseJSON["rss"]["channel"]["item"];
                foreach (JsonObject title in jsonArray)
                {
                    System.Json.JsonValue titleString;
                    title.TryGetValue("title", out titleString);
                    System.Json.JsonValue itemString;
                    title.TryGetValue("description", out itemString);
                    Articles.Add(new Article(titleString, itemString));
                }
            }
            else
            {
                DisplayAlert("Connection Status failed", resp.Message, "Close");
            }
        }
        public async Task <WorklightResult> RestInvokeAsync()
        {
            var result = new WorklightResult();

            try
            {
                StringBuilder uriBuilder = new StringBuilder()
                                           .Append(client.ServerUrl.AbsoluteUri) // Get the server URL
                                           .Append("/adapters")
                                           .Append("/SampleHTTPAdapter")         //Name of the adapter
                                           .Append("/getStories");               // Name of the adapter procedure
                WorklightResourceRequest rr = client.ResourceRequest(new Uri(uriBuilder.ToString()), "GET");

                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);
        }
        private async void SubmitValues()
        {
            User _UserFromPage = ResourceRequestXamarinFormsPage.GetTextValues();

            IWorklightClient _newClient = App.GetWorklightClient;

            StringBuilder uriBuilder = new StringBuilder().Append("/adapters/JavaAdapter/users")
                                       .Append("/").Append(_UserFromPage.FirstName)
                                       .Append("/").Append(_UserFromPage.MiddleName)
                                       .Append("/").Append(_UserFromPage.LastName);

            WorklightResourceRequest rr = _newClient.ResourceRequest(new Uri(uriBuilder.ToString(), UriKind.Relative), "POST", "");

            rr.SetQueryParameter("age", _UserFromPage.Age);

            System.Net.WebHeaderCollection headerCollection = new WebHeaderCollection();

            headerCollection["birthdate"] = _UserFromPage.BirthDate;

            rr.AddHeader(headerCollection);

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

            formParams.Add("height", _UserFromPage.Height);

            WorklightResponse resp = await rr.Send(formParams);

            Debug.WriteLine(resp.ResponseJSON);

            ResourceRequestXamarinFormsPage.DisplayOutput(resp.ResponseText);
        }
 public override void HandleChallenge(WorklightResponse challenge)
 {
     Console.WriteLine ("We were challenged.. so we are handling it");
     Dictionary<String,String > parms = new Dictionary<String, String> ();
     parms.Add ("j_username", "admin");
     parms.Add ("j_password", "admin");
     LoginFormParameters = new LoginFormInfo ("j_security_check", parms, null, 30000, "post");
     shouldSubmitLoginForm = true;
 }
Exemple #9
0
        public override void HandleChallenge(WorklightResponse challenge)
        {
            Console.WriteLine("We were challenged.. so we are handling it");
            Dictionary <String, String> parms = new Dictionary <String, String> ();

            parms.Add("j_username", "admin");
            parms.Add("j_password", "admin");
            LoginFormParameters   = new LoginFormInfo("j_security_check", parms, null, 30000, "post");
            shouldSubmitLoginForm = true;
        }
        public override bool IsCustomResponse(WorklightResponse response)
        {
            Console.WriteLine ("Determining if its a custom response");
            if (response == null || response.ResponseText==null || !(response.ResponseText.Contains("j_security_check")))
            {
                return false;
            }

            return true;
        }
        public override bool IsCustomResponse(WorklightResponse response)
        {
            Console.WriteLine("Determining if its a custom response");
            if (response == null || response.ResponseText == null || !(response.ResponseText.Contains("j_security_check")))
            {
                return(false);
            }

            return(true);
        }
        private async void Connect()
        {
            WorklightResponse resp = await MFPNewsReader.App.wlClient.Connect();

            if (resp.Success)
            {
                DisplayAlert("Connection Status", "Yay!!", "Close");
            }
            else
            {
                DisplayAlert("Connection Status failed", resp.Message, "Close");
            }
        }
Exemple #13
0
        /// <summary>
        /// Find Employee by name.
        /// </summary>
        /// <returns>The employee record.</returns>
        /// <param name="empName">employee name</param>
        public async Task <Employee> FindEmployee(string empName)
        {
            Employee emp = null;

            try
            {
                //
                // Connect to MFP
                //
                if (!Connected)
                {
                    WorklightResponse response = await WorklightClientInstance.Connect();

                    if (response.Success)
                    {
                        Connected = true;
                    }
                    else
                    {
                        throw new Exception("Cannot connect to server.");
                    }
                }

                //
                // Invoke MFP Procedure findEmployee
                //
                WorklightProcedureInvocationData invocationData = new WorklightProcedureInvocationData("EmployeeAdapter", "findEmployee", new object[] { empName });
                WorklightResponse task = await WorklightClientInstance.InvokeProcedure(invocationData);

                if (task.Success)
                {
                    JsonObject obj = (JsonObject)task.ResponseJSON;

                    //
                    //parse JSON object returned from MFP
                    //
                    emp = new Employee(obj["fullname"], obj["email"], obj["phone"]);
                }
                else
                {
                    throw new Exception("Invocation of adapter procedure failed.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(emp);
        }
        /// <summary>
        /// Unsubscribes from push notifications
        /// </summary>
        /// <returns>The push.</returns>
        private async Task <WorklightResponse> UnsubscribePush()
        {
            try
            {
                client.Analytics.Log("Unsubscribing Push", metadata);
                WorklightResponse task = await client.PushService.UnsubscribeFromEventSource(pushAlias);

                return(task);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        /// <summary>
        /// Connect to the server instance
        /// </summary>
        private async Task <WorklightResponse> Connect()
        {
            //lets send a message to the server
            client.Analytics.Log("Trying to connect to server", metadata);

            ChallengeHandler customCH = new CustomChallengeHandler(appRealm);

            client.RegisterChallengeHandler(customCH);
            WorklightResponse task = await client.Connect();

            //lets log to the local client (not server)
            client.Logger("Xamarin").Trace("connection");
            //write to the server the connection status
            client.Analytics.Log("Connect response : " + task.Success);
            return(task);
        }
Exemple #16
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);
        }
        /// <summary>
        /// Invokes the procedured
        /// </summary>
        /// <returns>The proc.</returns>
        private async Task <WorklightResult> InvokeProc()
        {
            var result = new WorklightResult();

            try
            {
                client.Analytics.Log("trying to invoking procedure");
                System.Diagnostics.Debug.WriteLine("Trying to invoke proc");
                WorklightProcedureInvocationData invocationData = new WorklightProcedureInvocationData("SampleHTTPAdapter", "getStories", new object[] { "technology" });
                WorklightResponse task = await client.InvokeProcedure(invocationData);

                client.Analytics.Log("invoke response : " + task.Success);
                StringBuilder retval = new StringBuilder();

                result.Success = task.Success;

                if (task.Success)
                {
                    JsonArray jsonArray = (JsonArray)task.ResponseJSON["rss"]["channel"]["item"];
                    foreach (JsonObject title in jsonArray)
                    {
                        System.Json.JsonValue titleString;
                        title.TryGetValue("title", out titleString);
                        retval.Append(titleString.ToString());
                        retval.AppendLine();
                    }
                }
                else
                {
                    retval.Append("Failure: " + task.Message);
                }

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

            return(result);
        }
Exemple #18
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);
        }
 public override void HandleChallenge(WorklightResponse challenge)
 {
     Console.WriteLine ("We were challenged.. so we are handling it");
     Dictionary<String,String > parms = new Dictionary<String, String> ();
     parms.Add ("j_username", "worklight");
     parms.Add ("j_password", "password");
     LoginFormParameters = new LoginFormInfo ("j_security_check", parms, null, 30000, "post");
     shouldSubmitLoginForm = true;
     //authSuccess = true;
     //this is for Adapter based authentication
     //            if (challenge.ResponseJSON["authRequired"] == true)
     //            {
     //				AdapterAuthenticationInfo AdapterAuthenticationParameters = new AdapterAuthenticationInfo();
     //                WorklightProcedureInvocationData invocationData = new WorklightProcedureInvocationData("HTTP",
     //                    "submitAuthentication" , new object[1]);
     //				AdapterAuthenticationParameters.InvocationData = invocationData;
     //				AdapterAuthenticationParameters.RequestOptions = null;
     //            }
     //            else
     //            {
     //				isAdapterAuth = false;
     //				authSuccess = true;
     //            }
 }
Exemple #20
0
        /// <summary>
        /// Connect to the server instance
        /// </summary>
        private async Task <WorklightResponse> Connect()
        {
            try
            {
                // Lets send a message to the server
                _client.Analytics.Log("Trying to connect to server", _metadata);

                //ChallengeHandler customCH = new CustomChallengeHandler(_appRealm);
                //_client.RegisterChallengeHandler(customCH);

                WorklightResponse task = await _client.Connect();

                // Lets log to the local client (not server)
                _client.Logger("Xamarin").Trace("Connection");
                // Write to the server the connection status
                _client.Analytics.Log("Connect response : " + task.Success);

                return(task);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        //mfp initialilzing environment
        public async void setOffers()
        {
            var isConnected = false;

            //mobileFirst client
            if (mfpClient == null)
            {
                mfpClient = WorklightClient.CreateInstance(this);
            }

            System.Console.WriteLine("MFP before connect");

            //getting connection
            WorklightResponse task1 = await mfpClient.Connect();

            if (task1.Success)
            {
                Console.WriteLine("connected to MFP");

                logger = mfpClient.Logger("Xamarin: MainActivity.cs");

                logger.Info("connection from Android Plenty app established");
                //write to the server the connection status
                mfpClient.Analytics.Log("Connect response : " + task1.Success);
                isConnected = true;
            }
            else
            {
                Console.WriteLine("connection failed");
            }

            //accessing protected feedAdapter
            if (isConnected)
            {
                //adding challengehandler
                string           appRealm = "PlentyAppRealm";
                ChallengeHandler customCH = new CustomChallengeHandler(appRealm);
                mfpClient.RegisterChallengeHandler(customCH);
                System.Console.WriteLine("MFP before adapter");

                WorklightProcedureInvocationData invocationData =
                    new WorklightProcedureInvocationData(
                        "FeedAdapter", "getFeed", new object[] { "" });

                WorklightResponse task3 = await mfpClient.InvokeProcedure(invocationData);

                if (task3.Success)
                {
                    isInitialCall = false;
                    Console.WriteLine("adapter connected");
                    Console.WriteLine(task3.ResponseText.ToString());

                    logger.Info("FeedAdapter Accessed from Android Plenty app");
                    //write to the server the connection status
                    mfpClient.Analytics.Log("FeedAdapter response : " + task3.Success);
                }
                else
                {
                    Console.WriteLine("adapter failed");
                    Console.WriteLine(task3.ResponseJSON.ToString());

                    logger.Error("FeedAdapter FAILED from Android Plenty app");
                    //write to the server the connection status
                    mfpClient.Analytics.Log("FeedAdapter response : " + task3.ResponseText);
                }
            }
            //end of protected feedAdapter


            task1 = await mfpClient.Connect();

            if (task1.Success)
            {
                Console.WriteLine("connected to MFP");
                isConnected = true;
            }
            else
            {
                Console.WriteLine("connection failed");
            }


            //ACCESSING STRONGLOOP for Offers
            if (isConnected)
            {
                System.Console.WriteLine("MFP before SL url");

                //calling protected adapter (strongloop)

                /*WorklightProcedureInvocationData invocationData =
                 *      new WorklightProcedureInvocationData (
                 *              "SLAdapter", "getOffers", new object[] { "" });
                 *
                 * WorklightResponse task2 = await mfpClient.InvokeProcedure (invocationData);
                 */

                //calling protected url (strongLoop)
                WorklightResourceRequest resourceRequest = mfpClient.ResourceRequest(
                    new Uri(URL_STRONGLOOP + "Offers"), "GET");
                WorklightResponse task2 = await resourceRequest.Send();


                if (task2.Success)
                {
                    Console.WriteLine("strongloop url connected");
                    Console.WriteLine(task2.ResponseText.ToString());

                    logger.Info("Strongloop Accessed/Offers from Android Plenty app");
                    //write to the server the connection status
                    mfpClient.Analytics.Log("Strongloop response : " + task2.Success);

                    Plenty.Offers.offers = new List <OffersModel> {
                    };
                    JsonArray jsonArray = new JsonArray(task2.ResponseText);

                    Console.WriteLine(jsonArray.Count);
                    var myObjectList =
                        (List <Offer>)
                        JsonConvert.DeserializeObject(task2.ResponseText, typeof(List <Offer>));
                    foreach (Offer offer in myObjectList)
                    {
                        /*
                         * Console.WriteLine (offer.offername);
                         * Console.WriteLine (offer.offerdescription);
                         * Console.WriteLine (offer.offerpicture);
                         */

                        Plenty.Offers.offers.Add(new OffersModel(
                                                     offer.offername,
                                                     offer.offerdescription,
                                                     offer.offerpicture));
                    }
                }
                else
                {
                    Console.WriteLine("strongloop url failed");
                    Console.WriteLine(task2.ResponseText.ToString());

                    logger.Error("Strongloop FAILED on Offers from Android Plenty app");
                    //write to the server the connection status
                    mfpClient.Analytics.Log("Strongloop response : " + task2.ResponseText);

                    //dummy offers
                    Plenty.Offers.offers = new List <OffersModel> {
                        new OffersModel("potatoes", "For offers refer", "Potatoes.jpg"),
                        new OffersModel(
                            "Buy one get one free on salted nuts for the big game!",
                            "This offer entitles you to a free can of salted nuts for every can you purchase.  Limit 4.",
                            "offers/asparagus.jpg"),
                    };
                }
            }
            else
            {
                Console.WriteLine("connection for SL failed");
                //dummy offers
                logger.Error("Strongloop FAILED even on Connection to MFP? while on Offers from Android Plenty app");
                //write to the server the connection status
                mfpClient.Analytics.Log("FeedAdapter response : " + task1.ResponseText);

                Plenty.Offers.offers = new List <OffersModel> {
                    new OffersModel(
                        "Buy one get one free on salted nuts for the big game!",
                        "This offer entitles you to a free can of salted nuts for every can you purchase.  Limit 4.",
                        "NUTS.jpg"),
                };
            }             //end Strongloops for Offers


            task1 = await mfpClient.Connect();

            if (task1.Success)
            {
                Console.WriteLine("connected to MFP");
                isConnected = true;
            }
            else
            {
                Console.WriteLine("connection failed");
            }


            //ACCESSING STRONGLOOP for Events
            if (isConnected)
            {
                System.Console.WriteLine("MFP before SL url");
                //calling protected url (strongLoop)
                WorklightResourceRequest resourceRequest = mfpClient.ResourceRequest(
                    new Uri(URL_STRONGLOOP + "Events"), "GET");
                WorklightResponse task4 = await resourceRequest.Send();


                if (task4.Success)
                {
                    Console.WriteLine("strongloop url connected");
                    Console.WriteLine(task4.ResponseText.ToString());
                    logger.Info("Strongloop Accessed/Events from Android Plenty app");
                    //write to the server the connection status
                    mfpClient.Analytics.Log("Strongloop response : " + task4.Success);

                    Plenty.SpecialEvents.events = new List <EventsModel> {
                    };

                    JsonArray jsonArray = new JsonArray(task4.ResponseText);

                    Console.WriteLine(jsonArray.Count);
                    var myObjectList =
                        (List <Event>)JsonConvert.DeserializeObject(task4.ResponseText, typeof(List <Event>));
                    foreach (Event myevent in myObjectList)
                    {
                        Plenty.SpecialEvents.events.Add(new EventsModel(
                                                            myevent.offername,
                                                            myevent.offerdescription,
                                                            myevent.offerpicture));
                    }
                }
                else
                {
                    Console.WriteLine("strongloop url failed");
                    Console.WriteLine(task4.ResponseText.ToString());
                    logger.Error("Strongloop FAILED on Events from Android Plenty app");
                    //write to the server the connection status
                    mfpClient.Analytics.Log("Strongloop response : " + task4.ResponseText);
                    //dummy events
                    Plenty.SpecialEvents.events = new List <EventsModel> {
                        new EventsModel(
                            "Growler Fill-Up",
                            "Fill up your growler from a selection of local craft beers!",
                            "events/fillyourgrowler.jpg"),
                    };
                }
            }
            else
            {
                Console.WriteLine("connection for SL failed");
                logger.Error("Strongloop FAILED even on Connection to MFP? while on Offers from Android Plenty app");
                //write to the server the connection status
                mfpClient.Analytics.Log("FeedAdapter response : " + task1.ResponseText);
                //dummy offers
                Plenty.Offers.offers = new List <OffersModel> {
                    new OffersModel(
                        "Buy one get one free on salted nuts for the big game!",
                        "This offer entitles you to a free can of salted nuts for every can you purchase.  Limit 4.",
                        "NUTS.jpg"),
                };
            }
        }
 public override void OnFailure(WorklightResponse response)
 {
     Console.WriteLine("Challenge handler failure");
 }
 public override void OnSuccess(WorklightResponse challenge)
 {
     Console.WriteLine("Challenge handler success");
 }
Exemple #24
0
 /// <summary>
 /// On Failure response
 /// </summary>
 /// <param name="response"></param>
 public override void OnFailure(WorklightResponse response) => Debug.WriteLine("Challenge handler failure");
Exemple #25
0
 /// <summary>
 /// On Success response
 /// </summary>
 public override void OnSuccess(WorklightResponse challenge) => Debug.WriteLine("Challenge handler success");