I'm trying to make a free version of my app. The app saves records to a database, and I have Repository
classes for all of the tables of data.
In the free version I want to limit the number of records that can be saved/retrieved. The easiest way I can think of to do this, is to overload the database functions in the instance of the free app.
I need to figure out how to validate the purchased state of my app, then store that flag in the database. If the user requests a refund, I can then verify that and change the flag in the DB to go back to the free version. (these flags could be recorded as blob
types and (en/de)crypted at runtime when being loaded)
I could then make an overloaded function that would limit the DB access.
My template declaration looks like this
public interface IDataBaseRecord<T>
{
Task<ObservableCollection<T>> GetItems();
}
then in the current implementation of my MaintenanceDataRepository.cs
public class MaintenanceDataRepository : IDataBaseRecord
{
public async Task<ObservableCollection<MaintenanceData>> GetItems()
{
CreateConnection();
return new ObservableCollection<MaintenanceData>(await connection.Table<MaintenanceData>().ToListAsync());
}
}
For instance I could make the following GetItems()
overloaded function.
public overload ObservableCollection<MaintenanceData> GetItems()
{
ObservableCollection<MaintenanceData> returnData = new ObservableCollection<MaintenanceData>();
var items = new ObservableCollection<MaintenanceData>(await connection.Table<MaintenanceData>().ToListAsync());
for (var i = 0; i < _FreeResults_ ; i++)
{
if(items[i] != null)
returnData.Add(items[i]);
else
break;
}
return returnData;
}
But, I have about 15 different data classes I would need to do this to...
Is there a way I can implement the above code as an overloaded function that get's called instead of the automatic GetItems()
? I would need to make it conditional, since there are some tables that specify things like manufacturers so I want all of those records to be called, but want to limit the number of records that a regular call can get.
At the moment the only way I can think to do this is to implement the checks and implement the limiting code in each class in each call that needs to be limited. What I would like is some sort of additional interface, or function I can just pass all of the calls made by all the other data repositories through to handle this. Since not all of my repositories need to have this limiting I would like it to be selective, but I could always just create a separate interface class to handle the limitable records vs the others that don't get limited.
I would then be able to store info in the database, such as number of RewardVideos they've watched and change the number of records based on that, and so on.
Cheers!