/// <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 async Task<Employee[]> FindEmployee (string empName) { WorklightProcedureInvocationData invocationData; WorklightResponse task; try { await ConnectMobileFirst(); invocationData = new WorklightProcedureInvocationData ( MFPAdapter, "findEmployee", new object[] { empName }); task = await WorklightClientInstance.InvokeProcedure (invocationData); if (task.Success) { Employee emp = ParseSingleEmployeeResult((JsonObject)task.ResponseJSON); return new Employee[] {emp}; } else { throw new Exception ("Adapter procedure failed."); } } catch (Exception ex) { Console.WriteLine (ex.Message); } return null; }
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"); } }
/// <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); }
public async Task<Employee[]> AllEmployees () { //Configure the MobileBackendManager, here we load from embedded json var mcsconfig = ResourceLoader.GetEmbeddedResourceStream(Assembly.GetAssembly(typeof(Application)),"McsConfiguration.json"); MobileBackendManager.Manager.Configuration = new MobileBackendManagerConfiguration(mcsconfig); var backend = MobileBackendManager.Manager.DefaultMobileBackend; //You must authenticate first bool success = await backend.Authorization.AuthenticateAsync("username", "password"); using (var client = backend.CreateHttpClient()) { var response = await client.GetAsync(backend.CustomCodeUri + "/customapitest/test"); response.EnsureSuccessStatusCode(); var json = await response.Content.ReadAsStringAsync(); } try { await ConnectMobileFirst(); invocationData = new WorklightProcedureInvocationData ( MFPAdapter, "allEmployees", new object[] {}); task = await WorklightClientInstance.InvokeProcedure (invocationData); if (task.Success) { Employee[] emp = ParseEmployeeResultSet((JsonObject)task.ResponseJSON); return emp; } else { throw new Exception ("Adapter procedure failed."); } } catch (Exception ex) { Console.WriteLine (ex.Message); } return null; }
/// <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); }
/// <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); }
//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"); 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.ResponseJSON.ToString ()); } else { Console.WriteLine ("adapter failed"); Console.WriteLine (task3.ResponseJSON.ToString ()); } } //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 if (isConnected) { //adding challengehandler string appRealm = "PlentyAppRealm"; ChallengeHandler customCH = new CustomChallengeHandler (appRealm); mfpClient.RegisterChallengeHandler (customCH); System.Console.WriteLine ("MFP before SL url"); //calling protected url (strongLoop) WorklightResourceRequest resourceRequest = mfpClient.ResourceRequest ( new Uri (URL_STRONGLOOP), "GET"); WorklightResponse task2 = await resourceRequest.Send (); if (task2.Success) { Console.WriteLine ("strongloop url connected"); Console.WriteLine (task2.ResponseText.ToString ()); Plenty.Offers.offers = new List<OffersModel> {}; //getting offers from JSON 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"); //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 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"), }; } }
/// <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", "getFeed", new object[] { "technology" }); // getStories 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; }
public async Task<GeoLocation> GetGeolocation(string city) { WorklightProcedureInvocationData invocationData; WorklightResponse task; try { await ConnectMobileFirst(); invocationData = new WorklightProcedureInvocationData ( MFPGeoAdapter, "getLocation", new object[] {city}); task = await WorklightClientInstance.InvokeProcedure (invocationData); if (task.Success) { GeoLocation loc = ParseLocationResult((JsonObject)task.ResponseJSON); return loc; } else { throw new Exception ("Adapter procedure failed."); } } catch (Exception ex) { Console.WriteLine (ex.Message); } return null; }
//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"), }; } }