How do I put and replace a file using in a client machine in a Silverlight app? - silverlight

I'm trying to make a Silverlight app which has a local sqlite file to search some data when the app gets offline. I found the following library, http://code.google.com/p/csharp-sqlite/ and it seems pretty nice.
So, what I want to know is, what is a good approach to have and place a file which might be replaced by automatically when the data in a server gets updated at some points?
I've tried to put a file into a folder under the app, but I couldn't access to the file by using csSQLite.sqlite3_open (This method is from the library above). Sorry, I'm pretty new to Silverlight, so my question might be very odd.
Thanks in advance,
yokyo

It doesn't look like this library has been specifially coded for Silverlight. Despite being a pure C# implementation its still likely to assume the full .NET API is available. This is not true in Silverlight.
Specifically Silverlight cannot ordinarily access the local file system. The SQLLite code would need to be modified to understand Silverlight's IsolatedStorage. It would also have to limit its file operations to those that are supported by the streams available Isolated Storage.
The creation of a DB-esq. data source in Silverlight is typically done by create Classes the represent records and collections of records, using LINQ to query them and Xml serialisation into Isolated storage to persist them.

Here is a hacked version of the SQLite code to work with Silverlight, you can use it for some ideas on what to do: http://www.itwriting.com/blog/1695-proof-of-concept-c-sqlite-running-in-silverlight.html

Related

How to read a file directly from disk in Liferay?

I'd like to manage a bunch of report files directly on a file system directly for easier use, especially when updating or excanging them with newer versions. And to avoid this intransparent document library.
Now i want to read one of these Files directly in liferay to pass them to JasperReports in general (e.g. as a ByteStream). I coudln't find any way to do this or something that discribes any way to handly files.
How is this possible to achieve?
Or do i completely mess around with my idea?
You basically can leverage the powers of the Spring framework, since Liferay makes use of Spring more or less directly.
You need to use some sort of "resource adapter" to open files, which you can do in many ways. It pretty much depends where you put files and how they get there (if provided from outside or generated by a Liferay portlet itself, or provided as deployed resource).
I can recommend searching for the following Spring class to be used:
org.springframework.core.io.FileSystemResource
Nevertheless you should think about storing these files in the database, as this is much safer after all (transaction safety, security, ...).

Work with Database using Spock and Geb.

I hope someone have already faced an issue to verify that application shows correct data from database. I reviewd how groovy used SQL, but I have no idea where and how I should do that. I'm just starting to use gradle+Spock+Geb for testing application. I have a few files where I described a couple of pages from application, a couple of modules and a file with spock specification. Where and how I need to connect to Oracle DB, use SQL and compare result's data with application's ones?
P.S. I write everything in notepad++ and launch from command line writing 'gradlew firefoxTest'. Does exist any more comfortable way to work with gradle+spock+geb?
Thanks in advance.
Because there are no other answers, I wanted to provide a solution someone at my company thought of. This assumes you already have a project that uses some sort of JDBC. In our case it is JDBI.
The idea is to extend Classloader and then use that to directly access the data access object class via the JVM. That idea should work.
I have not tested it out because it doesn't completely fit our use-case. I'll admit that this does not completely apply to your use case, but technically you could just run the jar of an existing project, which can access the database.

Best way to store data in wpf app

I just want to know about the best way to store simple data in wfp application. I'm using SQL CE, but sometimes I need to store simple data (for instance one string). I don't want to use for it db, and I think it's the right decision.
Could you please give me a guidance on how should I do that in best way or any useful resource?
Is there any particular features data settings storage for pattern MVVM?
Thank You.
Use Settings for exactly this scenario. It's simple, allows per user and system wide scenarios and is build into Visual Studio nicely.
Double clicking on Settings.settings in the Properties folder of your project (in Solution Explorer) brings up the editor and you can access these in code with something simple like Properties.Settings.Default.StringPropertyX.
http://msdn.microsoft.com/en-us/library/aa730869(v=vs.80).aspx
if you're going to be upgrading in the future, I suggest that you create a small abstraction layer that you can upgrade to using any DB or other source, when you need to.
Until you do the upgrade, I would suggest a simple XML file using XDocument and XElement (and the rest of that api).
The reason why I am suggesting this is because you can use Linq on them easily and this enables you to change the provider in the future without any problems.
here is the MSDN on XDocument http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx .
I hope this proves to be helpful to you ;-)
Cheers,
Max
p.s. lemme know if this is what you needed or not!
If you publish the application through ClickOnce then you can use IsolatedStorage. It is pretty easy to use, just a few lines of code. You can learn how to use it on WPF isolated storage.
If you don't publish it through ClickOnce then I would suggest you keep it simple and use static class.
you can use file system.. try to create xml file or csv file in the wpf app directory...
you can read and write to same file.. so that you can save what ever you want to that file and read from the same file..

Loading a new Silverlight application from isolated storage

Is there any way i can load a silverlight application from isolated storage and replace the current application ?
Short answer: no, you cannot do this. You could however store a dll, read and load it via reflection if you are in a trusted out-of-the-browser application.
Anyway I don't believe this to be a very good practice, it's very likely there is a different better way to solve your particular problem.
You can't replace the currently running application from within Silverlight code.
However you could create a single application to act as a shell. You could store assemblies or entire Xaps in isolated storage. Using the AssemblyPart class allows you to load an assembly from this storage, create an instance of an entry type and execute an entry point method.
The big caveat would be that this "stored application" would have to be coded specifically to work within your shell. You would need to provide your ways in particular to allow for "application" level state to be accessed and a means of loading content assets such as images.

Silverlight3: What to use: WebClient or database with RIA

I'm asking for the advice. I'm working at the Silverlight 3 application and now I should select the mean how to save the information and get it. I could save the necessary info in files (from 1 to 300K size) or I could save them in database. If I would use WebClient for accessing to separate file there's very low loading of the server. If I get data from database the server would load much more I think and the code on the server too.
Please correct me if I'm not right.
I'm looking forward to hearing from you!
Thanks
there are additional considerations if you use a file that is localized to the users machine. If you wish to save data w/o any user intervention then you are limited to using Isolated Storage, which has constraints on the size of your data. Otherwise, you have to ask the user for information on where to save/load the file. This is due to the security model used by silverlight.
i am thinking that a Database and the RIA framework might be the way to go.
just my 2ยข
If you are saving and loading the entire file at a time, then it might be okay to use a WebClient. This might take a little coding to handle errors that may result in incomplete saves.
If you're serializing some objects or xml data and storing that in a file, then you should probably be using a database instead.
Edit: It can be a pain to get WebClient or HttpWebRequest working correctly with GET/POST, but WCF can also be a pain to configure if you haven't done it before. WCF is probably better style, and you'll want to use a binary binding and send the file across as a byte[].

Resources