I am new with universal windows app development, and I am looking for some way to share data (on each device database) created on windows phone app with windows app and vice versa, I don't want involve a webserver to manage this, the only exception maybe is the user's onedrive, I'm think if it's possible the windows app (rt or desktop) version run a little service to handle this over wi-fi? or some way tho backup and restore database using onedrive?
You should use the roaming app data. I don't know how big your database is. But to maintain integrity you could serialize each table into JSON and store it. It's easy as pie:
var roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
roamingSettings.Values["exampleSetting"] = "Hello World";
If that isn't enough for you, you can even store a file inside the roaming folder:
var roamingFolder = Windows.Storage.ApplicationData.Current.RoamingFolder;
StorageFile database = await roamingFolder.CreateFileAsync("mydb.sqlite",
CreateCollisionOption.ReplaceExisting);
Read more here:
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh700362.aspx
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh464917.aspx#roaming_app_data
Related
I have a WP8.1 app using the new OneDrive API. I use the C# SDK provided, I get therefore something like this:
var dlStream = await Connection.DownloadStreamForItemAsync(mNode.ItemReference(),
StreamDownloadOptions.Default);
file = await folder.CreateFileAsync(fileName,
CreationCollisionOption.ReplaceExisting).AsTask();
fileStream = (await file.OpenAsync(FileAccessMode.ReadWrite)).AsStream();
var v=dlStream.CopyToAsync(tn.FileStream);
I have not tried it yet, but it seems to be the right way to do it. My concern now is "how to monitor the transfer progress and status?"
Knowing that the DownloadStreamForItemAsync method does something like this:
response = await GetHttpResponseAsync(request);
var responseStream = await response.GetResponseStreamAsync();
I have thought about using a timer, and each second check the stream length, but
I don't know if it is the right approach of if there is an alternative way
I don't know if this may not create some cross-thread errors for the stream
How to detect a transfer failure ?
I guess one of the approaches would be to re-write partially the OneDrive SDK portable project, target only WinRT projects and use Windows.Web objects instead of System.Net, but it seems to be some work for an unsure result.
Any help? :)
You can use the LiveConnectClient class inside the Live SDK instead of downloading the file as a stream and saving it to a file.
Use the BackgroundDownloadAsync(string path, Uri downloadLocation) method to download a file
Begins downloading a file from Microsoft OneDrive to a Windows Phone
isolated storage. [Windows Phone only]
The file download should continue even if the app that starts the file
download quits or is suspended.
Subscribe to the BackgroundDownloadProgressChanged event
Raised at indeterminate times while a file is downloading from Microsoft OneDrive to Windows Phone isolated storage. [Windows Phone only]
Hope it helps!
In a Windows Phone 8.0 application I calculate the size of a file with this following method:
Windows.Storage.FileProperties.BasicProperties props = await thisFile.GetBasicPropertiesAsync();
size = props.Size;
I've read here that this is for Windows Stors apps or WP 8.1 only, not below but it works and I am not getting any Exceptions. Why does it work if it's not supported? Are they going to reject my application submitting to Store?
If it's really not supported, what is the proper way, API to calculate the size of a file in Isolated Storage on WP 8.0?
If it works, it might be the documentation problem and there is no reason to reject your application from the store.
I am running an Air App I did for the desktop, from the actual installed executable already deployed in the machine (Not from Flash Pro / Flex dev. environment). For some reason the app will not read a text file stored in the same application folder unless I run my app as administrator from the OS.
When I run the app as admin, or within the development environment it works fine. Maybe this is related to some security issue? I read the adobe air documentation, and this should work...
I am using openAsync/readUTFBytes on user as shown here:
var continueGamesConnection:FileStream();
var continueFile:File = new File(File.applicationDirectory.resolvePath("continueGames.txt").nativePath.toString());
continueGamesConnection.addEventListener(Event.COMPLETE, openSavedGames);
continueGamesConnection.openAsync(continueFile, FileMode.UPDATE);
function openSavedGames(event:Event):void
{
continueGamesConnection.removeEventListener(Event.COMPLETE, openSavedGames);
var content:URLVariables = new URLVariables();
var loadedContent:String = new String();
loadedContent = continueGamesConnection.readUTFBytes(continueGamesConnection.bytesAvailable);
content.decode(loadedContent);
variableX = content. variableX
//etc, etc.
continueGamesConnection.close();
}
By the way, I have also, tried using FileMode.READ, and others, and it still gives me the same problem. Only works if ran on admin mode or from the dev. environment.
It's very frustrating, I tried reading other posts without any luck... What solutions do people use for this kind of problem?
I have seen that you can set the app to run as admin somehow, and I guess that could work. However, this should work just fine, since it doesn't seem to violate any of the security APIs of Air. Seems like an overkill. But even so, how do I do that?
You help is greatly appreciated!
Typically for security reasons, applications do not have write permissions to the File.applicationDirectory.
It is recommended you use File.applicationStorageDirectory instead as that is the most appropriate place to save user data (such as a save game file).
Alternatively, you could also let the user browse to a directory with the FileReference class which may or not have permission.
Assuming that you are using a Windows SO, the problem that you have is about user access restrictions to folders C:\Program Files and C:\Program Files (x86) and there is nothing you can do from Flash or AIR to solve it. You could modify you security settings by right click on the folder or you should simply avoid using the app folder to store anything
I'm upgrading windows phone 8 application. I created Universal app (Windows.Phone 8.1).
The settings in old WP8.0 application are saved in following way:
IsolatedStorageSettings.ApplicationSettings.Add("MY_SETTINGS", value);
Question:
How can i get this settings when app is upgraded to WP8.1 (Universal app).
I try the following:
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
var isContains1 = localSettings.Values.ContainsKey("MY_SETTINGS");
var roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
var isContains2 = roamingSettings.Values.ContainsKey("MY_SETTINGS");
But no "MY_SETTINGS" are found. (isContains1, isContains2 == false):\
Many Thanks for help
LocalSettings in WP8.1 works differently than those in WP8.0 - where settings were saved in a file (after serialization). The file is __ApplicationSettings - take a look at it (via IS explorer tool) and you will see its structure - part of it is a serialized dictionary. I've made some research once, which showed that all the old files are preserved during the update - which means that the settings are still there.
Once you update your WP8.0 app to WP8.1 and you want to read your old settings, you can retrive the values from the file.
This blog post has your exact answer, including the code needed to deserialize the migrated settings file!
You can use ApplicationData.LocalSettings It would Get you the application settings container in the local app data store. here is a Dev center link in which its Described how to use it.
Everytime I want to access the filesystem, does my app need to call webkitRequestFileSystem? Or is there some way to persist the filesystem stored in a variable across shutdowns and restarts?
For example:
Request Quote and the filesystem
On granted, store the returned DOMFileSystem object in a variable
User shuts down chrome and computer
User starts chrome up again
My app wants to access file system, what does it do?
It's a hosted app, but this question also applies to any web app I believe.
You will always need to request a FileSystem, if that's what you need. To use the same one each time use a PERSISTENT type when requesting the file system.
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(window.PERSISTENT, size, successCallback, opt_errorCallback);
There are other local storage options that might suit you better if making this request is too onerous.