I'm just starting to work with windows 8 development (using c#), and am working on porting one of my applications to a windows store app. Essentially my application takes a user input string, calculates an appropriate output, and responds to the user. So I'm using a list view to track the "conversation." I display the user's input as a list view element and then display the output as the next element (using text blocks with formatting like color...).
What I would like to do is make this "conversation" persist once the app is terminated but am not sure the best way to do this. My first thought was to serialize the list view object on suspension then deserialize it on load, but the listview isn't serializable...So my next thought was to write out each input and output string to a file and try to rebuild the listview from these strings when I load the application, but I am having some issues with this as well.
So I'm curious as to what the best way to go about this is. I would like the application to start back up with the previous conversation already displayed with the same formatting and what not. Does anyone have any ideas?
I wouldn't persist the ListView anyway, you only need to persist the data in it. Are you using a MVVM type model, where your conversation is perhaps captured as an ObservableCollection and then bound to the ListView? If not, you should :)
Then you'd just need to serialize the ObservableCollection (see one option for that here). Where you persist it kind of depends on you:
LocalFolder would use a file based approach and be available on the local device
RoamingFolder would also use a file based approach but sync using the cloud across multiple devices that the user owns (and has the app installed)
Cloud storage (like Windows Azure or Windows Azure Mobile Services) would provide essentially boundless storage for you, but requires managing a cloud account and paying for it (though free tiers may be sufficient)
An in-memory database like SQLite is yet another option and would give you relational semantics should that be interesting to you.
To get started, I'd say use LocalFolder and persist your collection to a file, then when you rehydrate it, simple data binding should automatically handle the display. At some point, you may need to make a decision about how much to store. You want your application to be responsive for the user ('fast and fluid'), so to that end you may need to bring in data as it's requested versus all at once (perhaps a version 2 feature!)
Related
I'm currently working on a winforms application that gets information from a user via a textbox. Since this information is not likely to change very often, I would like my application to save the input and load it into the appropriate text box the next time it is run.
I feel confident in my ability to set this up on the form side of things, my question has to do with how to store the values outside of the program. My first instinct is to just use a text file, but the overhead needed to handle IO and reading in the values seems a bit much. I also would rather not have the user editing it outside of the textbox in the program. I tried using string resources, but those are read only. Is there a more elegant solution available?
You need at least a mediocre database client whether it be sql server, mdf, MS Access, SharePoint, Oracle etc. Sounds like a vis studio prog. (winforms). They are designed for IO procedures but requires data architecture knowledge or relational dbs. (RMDBS). Try a lightswitch project (if a VS proj.) to get the basics of db and form data relationships.
I know it's not outside Your program, but you could try settings, it's easy, kinda like the resources ownly in the settings you can change it.
To change settings goto:
Properties and then double click Settings, here you van add strings, bools etc. Make sure you set them to user
To access them through code use:
Properties.Settings.Default.
To save the settings use:
Properties.Settings.Default.Save()
I am making a C# program that recreates websites in offline mode for use at computers within the company, that are not connected to the internet. These offline websites are identical to their online versions, with all content displayed.
I already have a solution for websites with simple MySQL access, but I need to rewrite the program, so that it can handle Drupal based websites aswell. However, I couldn't figure out how to access Drupal's SQL database, or even what to look for.
The original program uses the website's templates (that are already rewritten in HTML), and places the data mined out of it's database in the templates. Problem is, I don't know where to look for Drupal's templates, or if there aren't any, what data should I gather from it's database.
I use MySQL Connector to reach the database with C#. Should I look for the nodes? If yes, where?
If you want to go down that path you will have to sort of act like Drupal, in order to know which things to read from where. Each module installed has their own tables and functions in a particular way, so not always all the data are nodes with fields.
I you need to work with websites in offline mode, I would suggest using a portable webserver, that way you just copy the website to the root folder and run a script to copy the MySQL database as well, the point being that it's portable, you can carry it around in a flash drive and to run it, you don't need to install anything.
Again, what you want to do is possible, but it will require a tremendous amount of work and you cannot guarantee that things will behave well when you install new modules.
Another approach would be to look into the Boost module, which creates offline, static files based on the request you make to the site, and stores them in a configurable folder.
Another way: build a screenscrapper which reads the HTML from the homepage, and recursively follows the links and modify them before saving the HTML yo your local copy.
Summing it up.. avoid accessing the database yourself and try to read the HTML already rendered.
I am learning C# using Visual Studio and I am running into some issues.
I am developing a Windows form application. The application is meant to track user's running stats.
In settings: they select how many days they run and for each day they add their workout (ie: 1: 100m sprints 2: 50m sprints 3: Run a mile).
Then in the main windows form the user will be able to add their times and save it. Meanwhile a graph is projected of their times- this will allow the user to track their progress.
My question is where should I store their times? Right now I store all settings in the settings.settings doc. For the times should I use the settings file or a SQL database of some sort?
SqlCE or SQLite or any other simple inproc database will be better than Settings file.
Settings are not meant to grow with every user input, this is a task for a database, also it will be much easier to query your data using SQL.
Answering your question in comments:
There is a difference between user data and user preferences. You have to decide which is what in your app.
I would go with Settings file with everything regarding user preferences. Like form layout, colors, sounds, window size and so on.
Since Settings managing framework is pretty sophisticated, you will save yourself some time designing tables for user preferences and developing access to that tables.
Another possibly bright side of Settings file - it can be edited manually with text editor.
It is not possible to answer you without a lot more information about what a "user's running stats" is and how it is used. I can give a few general guidelines, though.
System.Configuration.ApplicationSettings are designed for customizing an application for a specific user; for example, what language the user wants the application to use, where he wants windows to appear, or default values. Settings are part of the application; they are created when the application is installed and deleted when the application is uninstalled. If multiple users run the application, each typically gets their own settings. You typically define settings when you create the application and users never add or remove them.
Databases are used to persist user data. They are typically not tied to a specific user or application; users add the data, which is available to other users or applications. Applications typically aren't installed with all user data, nor is user data deleted when the application is uninstalled.
SQL databases are used for relational data; data that has internal structure, like "all users must have exactly one address", or "any user may have zero or more phone numbers". If your data is not relational you do not need a relational database.
These are general guidelines, specific applications may do things differently for specific purposes. If you tell us more about your application we will be able to provide more specific information.
I am working on a windows app. The user has to register first to use this application. So in order to store user information, I am using MS-Access as a database. There is not much information to be stored as this application will be on individuals machine. There are few settings and some user information to be stored.
What I am feeling is that with the use of MS-Access, my application will be dependent on other application as MS-Access. It is not necessary to have the MS-office on the end user's machine.
So can you suggest me the best way to store the data safely without any dependence.
One thing I want to clear is that, the information will be of different types like it will consists of user information, some folder/files paths and some other information. I would like to keep these information separate from each other.
Thanks
Abhie
I think I found the solution.
Best practice to save application settings in a Windows Forms Application
I hope this will help others facing same problem.
Stackoverflow Team You are doing fabulous job. One suggestion; can you put some chat option for developers to discuss their problems. I think this would make it more easy to find answers to complex problems...:)
Regards
you need to include Access Database Engine drivers in the client PC, in order to connect it .
MS Access Database Engine
If you're using .NET, the best bet for getting the recommended folder locations for application data (e.g. your mdb file) is probably best retrieved using Environment.GetFolderPath
See:
http://msdn.microsoft.com/en-us/library/system.environment.getfolderpath.aspx
You're likely interested in ApplicationData or LocalApplicationData for user specific data or CommonApplicationData for data shared by all users as your storage location (and then the proper company / product subdirectories appended to it).
I would like to have a lot of data (quotes of famous people, arround 100 k quotes). And I want that users are able to search, sort on category and sort on authors.
Got a big big xml file at the moment, but what is smart to do? How can i get all the quotes in the app? maybe a sql lite database? or just loop the xml when app starts?
Any tips are most welcome!
Kevin
UPDATE: Thanks for all the replies and tips, I really appreciate it and I am looking forward to program my App, did make a runkeeper-like app yesterday, now starting the quotes app.
I would recommend storing this data on a webserver somewhere and using some SOAP interface of something like this, to access it. I wouldn't be positively surprised when a downloaded application all of a sudden decides to download a big file of quotes.
I would recommend a SQL CE database (.sdf file)
Great overview here: http://windowsphonegeek.com/tips/Windows-Phone-Mango-Local-Database%28SQL-CE%29-Introduction
And here: http://msdn.microsoft.com/en-us/library/hh202860%28v=VS.92%29.aspx
There's no SQLite on WP7. There's SQL Server Compact though. Read up on the latter, and also on LINQ. WP7.5 only.
Alternatively, store data on the Web server, and use a service to pull it on demand. In that case, read up on services and SOAP.
With the fact that you are looking at a 500mb file I think you have a couple of options.
1) Put all of this data in a database on a webserver, then have your phone application use whatever method you like to contact the database to get specific data that is needed. Obviously your UI would have to be optimised to allow a user to sort by the type of quote and / or the person to whom the quote is attributed.
2) If you want this to be done without the use of the webserver you could have a stripped down basic database of quotes in the application itself, to extend this connect to the database and download more data.
This method may be best as it lets you use the database data to say populate a website if you wanted to (make a bit of money from ad revenue / promote your app) and also it means if your users dont have an internet connection they can still get some use from your app.
Without more knowledge of the platform I couldnt say what would happen if you try load a 500mb application but I doubt it would be good, though having such a large file locally is a bad idea for a mobile device. I can see this going two ways.
1) Im out and see your application, I set it downloading, pay it no attention and then later check to find it has downloaded 500mb over my mobile phone data package. This could mean a big bill.
2) I start to download your application, it hasnt finished downloading after 10mins, I delete it and dont bother trying again.
You can do something like let the user to enter three character minimum before search from webservice ans user the service result to bind the data.
Check the following links
How to connect to a Webservice from a Windows Mobile Device 6.0
http://msdn.microsoft.com/en-us/library/aa446547.aspx
Let me know if this helps.