I have a DataService
, which should talk to the server and store vars (for complicated calls, for example).
Last time, I ended up with this approach (for the example, I'm working with a list):
GetList()
- returns cached data (just a property)SetList()
- sets a propertyReadList()
- read data from file fromIsoStorage
WriteList()
- write data to filePullList()
- pull data from the serverPushList()
- push data to the server
NB: I'm using my old IsoStorage
approach (IsoSettingsManager).
Now, after some time, I understood that I can merge first two stages: caching and writing to IsoStorage
. Now I'm thinking of something like
private int? deliveryId = null;
public int DeliveryId
{
get { return deliveryId ?? IsoSettingsManager.GetProperty<int>("DeliveryId"); }
set { deliveryId = value; IsoSettingsManager.SetProperty("DeliveryId", value); }
}
Where setting property is
public static void SetProperty(string propertyName, object content)
{
if (System.ComponentModel.DesignerProperties.IsInDesignTool)
return;
if (content == null)
RemoveProperty(propertyName); // if (isoSettings.Contains(propertyName)) isoSettings.Remove(propertyName);
isoSettings[propertyName] = content;
isoSettings.Save();
}
What do you think about it?
First thing that comes to my mind is to make SetProperty
to return the setted value so I'd be able to use it like
public int DeliveryId
{
set { deliveryId = IsoSettingsManager.SetProperty("DeliveryId", value); }
***
unsetting DeliveryId = null;
is not working for int
s (fair enough), and I couldn't yet find how to push/pull them effectively.