I made a UWP application. I use the roamingdata.I save the setting by this:
public static void WriteCode(string pwd)
{
ApplicationDataContainer RoamingSettings = ApplicationData.Current.RoamingSettings;
RoamingSettings.Values["Code"] = EncryptHelper.PwdEncrypt(pwd);
}
I read the setting by this:
public static string GetCode()
{
ApplicationDataContainer RoamingSettings = ApplicationData.Current.RoamingSettings;
string str = (String)RoamingSettings.Values["Code"];
if (!String.IsNullOrEmpty(str))
return str;
else
return EncryptHelper.PwdEncrypt("123");
}
I complete the application and upload to windows store and passed check. Then I download this app on my phone.
I change the ApplicationData.Current.RoamingSettings on phone. I write something to the ApplicationData.Current.RoamingFolder on my phone.
Next I closed the app on my phone and download the app on my PC. But when I opened the app on my PC, I found that the ApplicationData.Current.RoamingSettings and the ApplicationData.Current.RoamingFolder didn't change anything.
I checked the C:\Users\XXX\AppData\Local\Packages\XXX\RoamingState on my PC,there was nothing. I checked C:\Users\XXX\AppData\Local\Packages\XX\Settings on my PC,there was roaming.lock and settings.dat. But I can't read the lastest settings and roaming data that I haved added on my phone anymore.
I have waited for 2 hours, there was no change on my PC.
there is something that I should state first:
1 All the deploy work was done by windows store.
2 I check my PC application setting after closed the app on phone. I even shut down my mobile phone to observe the change to my PC.
what's wrong with my code? or what's wrong with the roamingdata mechanism? I need an answer, thank you!
The code you've posted is right. However, there are some possible reasons for the failure of roaming data sync:
Any user can benefit from roaming app data if they use a Microsoft account to log on to their device. However, users and group policy administrators can switch off roaming app data on a device at any time. If a user chooses not to use a Microsoft account or disables roaming data capabilities, she will still be able to use your app, but app data be local to each device.
Keep in mind that roaming data is associated with a user's Microsoft account. Roaming data will only sync if a user logs into her devices using the same Microsoft account and installs the app on several devices.
Don't use roaming for data that relies on instant syncing. Windows doesn't guarantee an instant sync; roaming could be significantly delayed if a user is offline or on a high latency network.
Roaming of settings is not instant. The system weighs several factors when determining when to send the data. We can detect whether new roaming data has arrived on the local device by listening for the ApplicationData.DataChanged event. This event occurs when app data has just finished syncing from the cloud. Any time a device receives new roaming data, the DataChanged event will fire, passing in the updated ApplicationData object. This lets us make any adjustments to our app when data has changed.
For important, time critical settings, use the HighPriority setting associated with RoamingSettings like following:
// High Priority setting, for example, last page position in book reader app
roamingSettings.values["HighPriority"] = "65";
This is a special key in the roaming settings we can use for data we need to sync immediately. Adding HighPriority to any setting will have it synced as quickly as possible.
Don't roam large sets of app data. There's a limit to the amount of app data an app may roam; use RoamingStorageQuota property to get this maximum. If an app hits this limit, no data can roam until the size of the app data store no longer exceeds the limit.
The name of each setting can be 255 characters in length at most. Each setting can be up to 8K bytes in size and each composite setting can be up to 64K bytes in size. The sync engine may limit the total size of settings and files that can roam. It’s important to keep track of the amount of data you’re attempting to roam. If the total amount of data you’re attempting to sync exceeds the limit, then nothing will sync between the devices.
App data only roams between installed apps with the same version number. For example, devices on version 2 will transition data between each other and devices on version 3 will do the same, but no roaming will occur between a device running version 2 and a device running version 3. If you install a new app that utilized various version numbers on other devices, the newly installed app will sync the app data associated with the highest version number.
If you are using versioning in your roaming date, please make sure you are dealing with the right version.
These are some possible reasons that can cause roaming data doesn't sync between devices. For more info, please check Roaming data in Store and retrieve settings and other app data.
Related
As part of some work I need to get done for Windows 10, I have written a code in C# that essentially detects every minute whether a PC is in screen saver mode or not, and it writes to a table in MySQL the relevant status ("PC in use" if the screen saver is off, "available PC" if the screen saver is on).
I did this using (full link if required - https://www.codeproject.com/Articles/17067/Controlling-The-Screen-Saver-With-C):
// Returns TRUE if the screen saver is actually running
public static bool GetScreenSaverRunning( )
{
bool isRunning = false;
SystemParametersInfo( SPI_GETSCREENSAVERRUNNING, 0,
ref isRunning, 0 );
return isRunning;
}
The code works flawlessly in console application mode (I made a loop to test it out over a minute with a check up on screen save status every 10 seconds), this means in MySQL the status was set correctly every time, depending on the screen save status at the moment of the check up.
The problem occurs when I use this code for a windows service. The service is installed correctly, the log on tab is set on Local System (I also tried with the logged in user instead, same results) and I allow the service to interact with the desktop, just in case, but the difference here is that no matter if the PC enters screen save or not, it always returns false on GetScreenSaverRunning(), thus setting the status of the PC in MySQL as "PC in use", even if the screen saver is on at the moment of check up.
I get the sense that the problem isn't in the code itself, since it works without any issues as a console application, but perhaps something behind the scenes. I tried to search here and on many other websites, haven't found anything related to such a problem.
Does anyone have any idea at all what might be the issue? Any help and/or suggestions will be greatly appreciated!
Thank you in advance.
(I could post the code if required, but it is pretty much straight forward and the main part of it, controlling the screen save detection, is taken from the website mentioned above, afterwards it's a simple if (GetScreenSaverRunning() == true) )
Ever since Vista, Services are barred from a Interactive Session. Even if they run under the same rights, they do not get a interactive Session. I would guess that is getting in the way here.
While you can overwrite this behavior in the Service settings, this is not adviseable for new code. Consider making this a Background Task started by the Task Sheduler instead.
Because the windows service runs in different session then the windows logon. You can't interact with the desktop related services unless you run the windows service in win logon session. There used to be an option in Windows service manager where you can set the properties to "Interact with desktop session" but I don't think that ever worked.
There's a work around to run the windows service using the win logo session.
See this helper class that can get the current logged on user session and interact with the desktop services. https://github.com/murrayju/CreateProcessAsUser/blob/master/ProcessExtensions/ProcessExtensions.cs
One of my clients has a deal with an OEM. Their app X will be preinstalled on a number of laptops. This app will receive updates from the Windows 10 store. This app X will also available for download in the Windows 10 store to other users. Only users using the preinstalled version should receive a free 3-month trial.
Unfortunately, the OEM is not providing any device IDs, and the users are not getting any unlock codes for their trial. I came up with the following initial "solution":
Use version 1.0.1.0 for the preinstalled app.
Upload 1.0.0.0 to the store.
When the app starts and the version is 1.0.1.0, it is identified as a preinstalled version, at which point I can make a server call to send a device ID to the client's server to recognize this device even after app deletions.
I can update the store app without losing any knowledge of preinstalled apps since I can update to any version below 1.0.1.0. This means the preinstalled version will not be overwritten by auto update with the store version (since the installed version number is greater than the store version). However, if a serious bug is detected in the preinstalled version, I cannot update that app or a certain class of users will not receive their free trial. Namely, the users that have not started the app on the device yet before Windows 10 updates the app with the new version (1.0.1.1 for example).
This all sounds unnecessarily complicated, and I hope it is. Can anyone think of an easier way to distinguish between the preinstalled and downloaded version that's foolproof?
Thanks!
As you are already thinking about offering 2 different versions, this one might be a better solution, where you can deploy two times the version 1.0.0.0.
Instead of using the versions to differ between the state, use build symbols.
Create two differnt builds, one for your OEM client, and one for store deployment.
For the OEM, where you want to allow the trial, use the following - as an example:
private bool CanUseTrial()
{
#if OEM
return true;
#else
return false;
#endif
}
Doing it this way will allow you to maintain the same code base for all clients, but differing between case OEM and case store deployment, without much logic needed.
EDIT #1:
To address the problem of OEM clients updating to non-OEM clients, you can still go with this approach (as long as the app runs at least once as #OEM build):
private async Task<bool> CanUseTrial()
{
var clientCode = GenerateClientCode(); // However you're going to do this
#if OEM
WebServiceXyz.RegisterOemClient(clientCode);
return true;
#else
try
{
return await WebServiceXyz.IsRegisteredOemClient(clientCode);
}
catch
{
return false;
}
#endif
}
Background
The company I work on is developing a kiosk-like application for tablets running Windows 8 Pro (on desktop mode). The user shouldn't be able to access anything that isn't the application itself: charms will be disabled, the taskbar will be hidden behind the application, etc.
This also means the user shouldn't be able to change network settings, leaving the responsability to keep the device always connected to us. Up to now, I had success using the Mobile Broadband API to assure the device is connected whenever there's a mobile network available. It'll detect disconnect events and try to connect again.
The Problem
Although the user shouldn't be able to do it, I'm considering the case where the user follows this steps:
User opens right-side charm,
clicks on Settings,
clicks on Network,
clicks on More PC Settings,
clicks on Wireless, and
disables the mobile broadband device.
I would like to be able to revert this programmatically and enable it again.
The Attempts
I have tried some different ways to force 3G being reenabled. Most of them give me the same result: they supposedly enable the device without errors, but I still cannot use it. Enable-NetAdapter in Powershell doesn't throw errors, and the Enable method of Win32_NetworkAdapter appears to work, but no dice.
I thought maybe the method IMbnRadio::SetSoftwareRadioState could be what I'm after, but I can't get to it when the device is disabled. The method IMbnInterfaceManager::GetInterfaces throws a COMException claiming the element could not be found (HRESULT = 0x80070490).
MbnInterfaceManager mbnInterfaceManager = new MbnInterfaceManager();
IMbnInterfaceManager interfaceManager = (IMbnInterfaceManager)mbnInterfaceManager;
// The following line throws a COMException:
IMbnInterface[] interfaces = (IMbnInterface[])interfaceManager.GetInterfaces();
mobileInterface = interfaces[0];
mobileRadio = (IMbnRadio)mobileInterface;
uint requestId;
mobileRadio.SetSoftwareRadioState(MBN_RADIO.MBN_RADIO_ON, out requestId);
Is there a way to override user preferences set on "More PC Settings?"
I found a sketchy way to solve this. Keep in mind this is undocumented, wrong, shameless and immoral, and will probably break eventually. The client is aware of this, but prefers to keep the access to the OS limited.
The setting in case is saved in the Registry. At least in the computers I've checked, it's stored in HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0022 in a key named RadioOff.
The Airplane Mode setting is also stored in the Registry, but in a different place. It's at HKLM\SYSTEM\CurrentControlSet\Control\RadioManagement\SystemRadioState in a key named (Default).
After changing these keys and rebooting, everything seems to work fine. I'll repeat though: you really shouldn't be doing this, especially the Airplane Mode thing.
I have created a windows store application that prints out network information using the using Windows.Networking.Connectivity; name space.
Although the application is running and working correctly, the MegabytesUsed method is return "Not Defined". why is this.
If you run the app in Local Machine and you are connected with ethernet you dont use DataPlan.
If you want to debug open with Simulator and enable "Use simulated network prperties" and then change Data Limit Status Flag and you will see results.
ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();
DataPlanStatus dps = profile .GetDataPlanStatus() ;
textBlock.Text = dps.DataPlanUsage.MegabytesUsed.ToString();
I have my project files on my Dropbox folder so I can play around with my files at the office as well.
My project contains an EmbeddableDocumentStore with UseEmbeddedHttpServer set to true.
const int ravenPort = 8181;
NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(ravenPort);
var ds = new EmbeddableDocumentStore {
DataDirectory = "Data",
UseEmbeddedHttpServer = true,
Configuration = { Port = ravenPort }
};
Now, this day when I started my project on my office pc I saw this message: Could not open transactional storage: D:\Dropbox\...\Data
Since it's early in my development stage I deleted the data folder on my Dropbox and the project started flawlessly. Now I'm back at home I ran into the same issue! I don't want to end up deleting this folder every time of course.
Can't I store my development data on my Dropbox? Should I bypass something to get this to work?
Set a data directory to a physical disk volume on your local computer. You will not be able to use any sort of mapped drive, network share, UNC path, dropbox or skydrive as a data directory. Just because you have a drive letter does not mean you have a physical disk.
The only types of non-physical storage that even make sense is a LUN attached from a SAN over iSCSI or FibreChannel, or an attached VHD in a virtualized or cloud environment. They will all present as physical disks to the OS.
This would be the case for just about ANY data access environment. Try it with SQL Server if you don't believe me. In RavenDB's case, it is using ESENT as its data store, which requires direct access to the filesystem.
Update
To clarify, even if you are storing on a physical disk, you can't rely on any type of synchronization technology like DropBox or SkyDrive. Why? Because they will be taking a shared read lock on the files to watch for changes. Technologies like ESENT (which RavenDB is based upon) require an exclusive lock to the file.
Other technologies like SQL Server and Windows Virtual Machine also take exclusive locks on their data stores. Why? Because they are constantly reading and writing bits of data in a random-access manner to the file. Would you really want DropBox to be trying to perform an sync operation for every bit of data change? It would be very inefficient and problematic.
Applications that use shared locks don't have this problem. For example, when you work on an MS Word document, it is all being done in memory. When you save the file, DropBox can read the entire file and sync it to the cloud. It can optimize by sending only the bits that have changed, but it still needs to be able to read the file to do so.
So if DropBox has a shared read lock on the ESENT file, then when RavenDB tries to open it exclusively, it gets an error and raises the exception you are seeing.