I have searched this forum for my problem but didn't find anything that suited, Im having a problem with my program flow.
I have a MobileService on Azure that has a question table, my app has a main menu and quiz button that takes the user to the quiz page, on the quiz page I have a start quiz button that shows the first question in the list.
This is the code im using to get the questions from the database, I placed it in the pages constructor and now when the user presses the quiz button there is a delay in the page opening which isn't that bad as its not a long wait, only a few seconds, is there a better way to do this?
Task<IMobileServiceTable<Question>> getDataFromDatabase = new Task<IMobileServiceTable<Question>>(getQuestions);
getDataFromDatabase.Start();
QuestionList = await getDataFromDatabase;
In the same function I have this code which modifies the start quiz button isEnabled attribute. This stops the quiz going forward unless the data has came through from the server, but its not working all the time and sometimes the start button isenabled is set to true and I get nullreference from my MobileServiceCollectionView QuestionList even though the task has completed.
Task<bool> assignData = new Task<bool>(assignTabletoitems);
assignData.Start();
startbutton.IsEnabled = await assignData;
Any help on this would be appreciated.
Thanks
You shouldn't have to create a new instance of Task<T> to query the database (you haven't provided the definition of getQuestions which is used in your first code snippet, so I can't tell whether that code is doing what it's supposed to). What you'd typically do is to get a table for the appropriate type from the MobileServiceClient object, and then query on it:
var client = new MobileServiceClient(appUrl, appKey);
var table = client.GetTable<Question>();
var questionList = await table.ToListAsync();
Regarding your second code snippet, without the definition of assignTabletoitems it's really hard to know what you're intending that code to do.
Related
I'm doing some kind of social, it's when i open a post a new scene is created which initializes the elements with the data taken from the database. the problem is that the big photos take time to load, and until they load the program does not respond, I would like a way to be able to open the scene first so as to wait until the image loads without the program crashing
public void init(int idpost) throws SQLException {
this.post = new PostDAOImpl().getPost(idpost);
photo.fitWidthProperty().bind(imgContainer.widthProperty());
photo.fitHeightProperty().bind(imgContainer.heightProperty());
photo.setImage(new Image(post.getPhoto()));
name.setText(post.getProfile().getName());
username.setText("#" + post.getProfile().getUsername());
if (post.getProfile().getAvatar() != null)
avatar.setImage(new Image(post.getProfile().getAvatar()));
description.setText(post.getDescription());
}
here is the code, which is executed as soon as the scene loads. I was thinking of doing another DAO to first fetch all the data except the photo, load the scene and only then fetch the image or something like that, but I don't know how to do it
I think it is always a good idea to create and show a GUI in the empty state quickly first and then launch some background task to collect the data and once this data is available update the GUI. Just think of a word-processor GUI. When you launch it it's in the empty state without any document. Then the user selects a document which gets loaded and as soon as the data is available the GUI changes and displays the document. The only difference in your case is that you already know which data you want to load.
I am currently working on a /inventory command, the way it works is that the user does /inventory and I saved that user.id with the page they are on { user.id: page } and based on that generate the page. The way you move from page to page is with buttons and collectors, but my problem is that when the same user does /inventory twice so that there is 2 inventory embeds both with the exact same buttons whenever the user presses one button, the code checks if I am the user who did the /inventory commands (so true) and what customId the button has (both embeds have the same button customId). Due to this both inv embeds are updated and I get an error "Interaction has already been acknowledged."
Is there anyway to differentiate which button has been pressed to update the corresponding embed correctly?
Since there is no actual bug with the code I am not posting the code here, if you need the code just ask. I just want to know what I should do to avoid this.
I encountered a similar issue right now. You should create your collector on a message instead of a channel. You can use fetchReply: true on your reply() method to fetch a message and then use it to call createMessageComponentCollector() method from it.
I know this question is 4 months old, but maybe it'll help someone anyway.
The best way to do this is to create your collector on the message you want to send.
// For example:
const MSG = await message.channel.send({embeds: [yourEmbed]});
const collector = await MSG.createMessageComponentCollector({ filter, idle: 20000 });
Another way to solve this is to create a random ID for your buttons. Like this:
const randomID = Math.floor(100000 + Math.random() * 900000);
const button = new MessageButton()
.setCustomId(`button${randomID}`)
.setLabel('Just a button')
.setStyle('PRIMARY')
There is still a small possibility of getting the same ID on two interactions, but it's really low. You can also create longer IDs to lower the chances even further.
And lastly, another way would be to prevent the user from using the command again while your inventory command is active. This would be achievable by creating a
Map and when the user triggers the command you add user's ID and the command's name.
After the collector ends or the command is stopped you can clear the Map.
I started learning MVC and i am stuck in this problem.
I have an Order Details page in which I have a button "Edit". When the user clicks on it, opens up a Bootstrap Modal, which i called from a Partial View.
Now Modal opens up and shows the data, loaded from database and saves the data to database.
Everything is working just fine.
I just want the user to go back to that Specific Detail Page from where He/She clicked "Edit" Button.
For example
Detail Page URL is
../orders/details/2
form saves at
..order_detail/edit/[id]
after form submit it should go back to
../orders/details/2
How can i achieve this?
Any help would be much appreciated
Instead of returning on your current View after executing post method you can redirect to the action you want, passing the id. For example:
public ActionResult Edit(int id) {
...
return RedirectToAction("YourDetailsActionHere", new { id = id});
}
And if your action is in different controller you have to pass the controller name as well
return RedirectToAction("YourDetailsActionHere", "YourOtherController", new { id = id});
How to identify controls while replay in 2nd IE instance in coded UI.
I have recorded some assertions in a second IE instance, but coded UI is not passing the focus to the second IE instance while replay.
The scenario is like my report is generated in a new window. I have added some assertions to it. It gets saved properly. But when I replay it, coded UI never turns its focus on second IE, that is why my test fails.
Any help on this.
Thanks...
First you actually need to distinguish the first and the second IE windows.
When launching them, store references for them somewhere, and then pass these instances as parent when finding controls.
In pseudocode:
// Open first and second window
var window1 = BrowserWindow.Launch("http://url1");
var window2 = BrowserWindow.Launch("http://url2");
// Do some work in window 1
var button = new HtmlButton(window1);
button.FilterProperties = blah-blah-blah
button.Click();
// Verify work in window 2
var label = new HtmlLabel(window2);
Assert.Equals("foo", label.Text);
Hope this gives you general idea.
I have a search form I generated using the filterGrid option in JqGrid. I want to add a JavaScript logic which is invoked before I submit the Search form. I have added a method which is invoked by the beforeSubmit property for the filterGrid. It goes into the method before submitting, but always submits the form regardless of the value returned. I would like the form to not submit if the javascript returns false.
Have any of you guys implemented anything like this before. Or is there any othe rbetter way to implement this. Any help on this will be really appreciated.
Code:
$("#search").filterGrid("#resultsGrid",
{gridModel:true,gridNames:true,enableSearch:true,
formtype:"vertical",buttonclass:"submitButton",
enableClear:true,beforeSearch:validateDate});
function validateDate(dateDiff) {
if(daysDiff < 0){
return [false,"Message"];
}
} // ??? (commented by Oleg)
return [true,""];
}
There are at least three different ways how searching can be used: Toolbar Searching, Custom Searching which you use and Single field searching or Advanced Searching which share the same code. So one have currently three different implementations of close things.
Only Toolbar Searching has beforeSearch event handler which can return false to stop searching. In case of Custom Searching the value returned by the event handler beforeSearch will not used. Single field searching or Advanced Searching don't call any event handler before searching. In all cases for the searching will set searching filter and the jqGrid parameter search to true and then force grid reloading with the code like
$("#gridId").trigger("reloadGrid",[{page:1}]);
To be able to make any validations and stop reloading of the grid I see no simple way. So I suggest only following.
You can overwrite the standard reloadGrid event handler and chain it. The corresponding code con look like following:
var grid = $("#gridId");
var events = grid.data("events"); // read all events bound to
var originalReloadGrid; // here we will save the original event handle
var skipRefresh = false; // this can be changed by owe validation function
// Verify that one reloadGrid event hanler is set. It is typical sitation
if (events && events.reloadGrid && events.reloadGrid.length === 1) {
originalReloadGrid = events.reloadGrid[0].handler; // save old
grid.unbind('reloadGrid');
var newEvents = grid.data("events");
grid.bind('reloadGrid', function(e,opts) {
if (!skipRefresh && grid[0].p.search) {
originalReloadGrid(e,opts);
}
});
}
Probably I will create later a demo which demonstrate this on an example and place the link to the demo here. Moreover I will try to suggest code changes to jqGrid so, that in all different implementations of searching will be possible to stop serching by returning false by beforeSearch event handle.
UPDATED: OK! I prepared a demo for you. In the demo I use no server components, so it will not really do searching, but you can see the results if the grid will be refreshed and goes to the page 1.
To test the demo you can do following:
type in the "Client" input field a text not starting with 'test' and click "search" button. You receive an alert which simulate the validation dialog.
type in the "Client" input field a text starting with 'test' like test1 and click "search" button. Now the grig will refreshed because the validation will be OK.