Skip to content

Commit

Permalink
iterating on offline and file, some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
edatkinvey committed Jan 19, 2015
1 parent d1118dd commit 4c798ac
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 52 deletions.
63 changes: 60 additions & 3 deletions Kinvey-Xamarin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RestSharp.Portable", "RestS
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kinvey-Utils", "Kinvey-Utils\Kinvey-Utils.csproj", "{444456B1-5B55-48D6-9637-00ADCA92B7C9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibTester", "LibTester\LibTester.csproj", "{F305304B-081C-44B5-BE53-F24A07BCDC56}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Android-StatusShare", "..\..\ksamples\xamarin\StatusShare-Xamarin\android\Android-StatusShare.csproj", "{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Android-TestDrive", "..\..\ksamples\xamarin\TestDrive-Xamarin\android\Android-TestDrive.csproj", "{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -58,6 +64,24 @@ Global
{6644D98D-026B-48E9-95A3-61C4D98D82E7}.Release|iPhone.Build.0 = Release|Any CPU
{6644D98D-026B-48E9-95A3-61C4D98D82E7}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{6644D98D-026B-48E9-95A3-61C4D98D82E7}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}.AppStore|Any CPU.Build.0 = Debug|Any CPU
{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}.AppStore|iPhone.Build.0 = Debug|Any CPU
{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}.Debug|iPhone.Build.0 = Debug|Any CPU
{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}.Release|Any CPU.Build.0 = Release|Any CPU
{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}.Release|iPhone.ActiveCfg = Release|Any CPU
{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}.Release|iPhone.Build.0 = Release|Any CPU
{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{6CD7DF58-9BFE-4402-B3F3-BF2D4297F267}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{992EF0A6-40EA-48E3-9E42-AFFF703E4627}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{992EF0A6-40EA-48E3-9E42-AFFF703E4627}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{992EF0A6-40EA-48E3-9E42-AFFF703E4627}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -94,8 +118,41 @@ Global
{BA2352E1-CB07-4795-A2EB-F70720B2BBC9}.Release|iPhone.Build.0 = Release|Any CPU
{BA2352E1-CB07-4795-A2EB-F70720B2BBC9}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{BA2352E1-CB07-4795-A2EB-F70720B2BBC9}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Android-Libtester\Android-Libtester.csproj
{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}.AppStore|Any CPU.Build.0 = Debug|Any CPU
{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}.AppStore|iPhone.Build.0 = Debug|Any CPU
{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}.Debug|iPhone.Build.0 = Debug|Any CPU
{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}.Release|Any CPU.Build.0 = Release|Any CPU
{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}.Release|iPhone.ActiveCfg = Release|Any CPU
{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}.Release|iPhone.Build.0 = Release|Any CPU
{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{CC4D99EF-0740-47BD-96AD-2FCD4C36C7FA}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{F305304B-081C-44B5-BE53-F24A07BCDC56}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{F305304B-081C-44B5-BE53-F24A07BCDC56}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{F305304B-081C-44B5-BE53-F24A07BCDC56}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
{F305304B-081C-44B5-BE53-F24A07BCDC56}.AppStore|Any CPU.Build.0 = Debug|Any CPU
{F305304B-081C-44B5-BE53-F24A07BCDC56}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{F305304B-081C-44B5-BE53-F24A07BCDC56}.AppStore|iPhone.Build.0 = Debug|Any CPU
{F305304B-081C-44B5-BE53-F24A07BCDC56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F305304B-081C-44B5-BE53-F24A07BCDC56}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F305304B-081C-44B5-BE53-F24A07BCDC56}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{F305304B-081C-44B5-BE53-F24A07BCDC56}.Debug|iPhone.Build.0 = Debug|Any CPU
{F305304B-081C-44B5-BE53-F24A07BCDC56}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{F305304B-081C-44B5-BE53-F24A07BCDC56}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{F305304B-081C-44B5-BE53-F24A07BCDC56}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F305304B-081C-44B5-BE53-F24A07BCDC56}.Release|Any CPU.Build.0 = Release|Any CPU
{F305304B-081C-44B5-BE53-F24A07BCDC56}.Release|iPhone.ActiveCfg = Release|Any CPU
{F305304B-081C-44B5-BE53-F24A07BCDC56}.Release|iPhone.Build.0 = Release|Any CPU
{F305304B-081C-44B5-BE53-F24A07BCDC56}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{F305304B-081C-44B5-BE53-F24A07BCDC56}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
21 changes: 2 additions & 19 deletions Kinvey-Xamarin/AppData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,7 @@ public GetRequest (Type myClass, AbstractClient client, Dictionary<string, strin
this.collectionName = urlParameters ["collectionName"];
}

public override T[] Execute ()
{
return base.Execute ();
}

}

/// <summary>
Expand All @@ -331,11 +328,7 @@ public GetEntityRequest (string entityId, Type myClass, AbstractClient client, D

}

public override T Execute ()
{
T myEntity = base.Execute ();
return myEntity;
}


}

Expand All @@ -362,11 +355,6 @@ public GetQueryRequest (string queryString, Type myClass, AbstractClient client,
this.QueryString = queryString;
}

// public override T[] Execute ()
// {
// T[] myEntity = base.Execute ();
// return myEntity;
// }

}

Expand Down Expand Up @@ -395,11 +383,6 @@ public SaveRequest (T entity, string entityId, Type myClass, SaveMode update, Ab
}
}

public override T Execute ()
{
T myEntity = base.Execute ();
return myEntity;
}
}

/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions Kinvey-Xamarin/Async/AsyncAppData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public async Task<T[]> GetAsync(){
return await GetBlocking ().ExecuteAsync ();
}

public async Task<T[]> GetAsync(string queryString){
return await base.getQueryBlocking (queryString).ExecuteAsync ();
}

/// <summary>
/// Save the specified entity to a Kinvey collection.
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions Kinvey-Xamarin/File/FileMetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public class FileMetaData
public FileMetaData ()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="KinveyXamarin.FileMetaData"/> class with the specified _id
/// </summary>
/// <param name="id">the _id of the file.</param>
public FileMetaData(string id){
this.id = id;
}
/// <summary>
/// Gets or sets the identifier.
/// </summary>
Expand Down
6 changes: 5 additions & 1 deletion Kinvey-Xamarin/File/KinveyFileRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ private void downloadFile(FileMetaData metadata, Stream stream){

request.ResponseWriter = (responseStream) => responseStream.CopyTo (stream);

client.DownloadDataAsync (request);
var req = client.DownloadDataAsync (request);
var response = req.Result;

stream = new MemoryStream (response);
var x = 123;
}

private void downloadFile(FileMetaData metadata, byte[] output){
Expand Down
34 changes: 13 additions & 21 deletions Kinvey-Xamarin/Offline/BackgroundExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,40 +85,32 @@ private void getFromStoreAndExecute(){
/// </summary>
/// <param name="handler">Handler to access database.</param>
/// <param name="item">The queued representation of the request.</param>
private void buildAndExecuteRequest(DatabaseHelper<T> handler, SQLTemplates.QueueItem item){
private async void buildAndExecuteRequest(DatabaseHelper<T> handler, SQLTemplates.QueueItem item){
string collection = item.collection;
string verb = item.action;
string id = item.id;
AsyncAppData<T> appdata = client.AppData<T> (collection, typeof(T));

switch (verb) {
case "QUERY":
appdata.Get (id, new KinveyDelegate<T[]>{
onSuccess = (results) => {

List<string> idresults = new List<string>();
break;
T[] results = await appdata.GetAsync (id);
List<string> idresults = new List<string>();
foreach ( T ent in results){

foreach ( T ent in results){

string entJSON = JsonConvert.SerializeObject(ent);
string entID = JObject.FromObject (ent) ["_id"].ToString();
string entJSON = JsonConvert.SerializeObject(ent);
string entID = JObject.FromObject (ent) ["_id"].ToString();

handler.upsertEntityAsync(entID, collection, entJSON);
await handler.upsertEntityAsync(entID, collection, entJSON);

idresults.Add(entID);
}
idresults.Add(entID);
}
await handler.saveQueryResultsAsync(id, collection, idresults);

handler.saveQueryResultsAsync(id, collection, idresults);
await handler.removeFromQueueAsync(item.key);
doneSuccessfully();

handler.removeFromQueueAsync(item.key);
doneSuccessfully();

},
onError = (error) => {
Logger.Log(error);
}

});
break;
case "PUT":
T entity = handler.getEntityAsync (collection, id).Result;
Expand Down
2 changes: 1 addition & 1 deletion Kinvey-Xamarin/Offline/DatabaseHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface DatabaseHelper<T>
/// Creates a new table
/// </summary>
/// <param name="collectionName">Collection name.</param>
void createTableAsync(string collectionName);
Task<int> createTableAsync(string collectionName);

/// <summary>
/// Returns a list of all collections currently stored offline
Expand Down
3 changes: 2 additions & 1 deletion Kinvey-Xamarin/Offline/SQLiteHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ internal SQLiteHelper(ISQLitePlatform platform, string databasePath)
/// Creates an Offline Table, which manages all offline collection features.
/// </summary>
/// <param name="collectionName">Collection name.</param>
public async void createTableAsync (string collectionName)
public async Task<int> createTableAsync (string collectionName)
{
await onCreateAsync (collectionName);
return 0;
}


Expand Down
12 changes: 6 additions & 6 deletions Kinvey-Xamarin/Offline/SQLiteOfflineStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public async Task<object> executeGetAsync<T>(AbstractKinveyClient client, AppDat
query = query.Replace("?query=","");
query = WebUtility.UrlDecode(query);

handler.createTableAsync (appData.CollectionName);
await handler.createTableAsync (appData.CollectionName);

T[] ok = await handler.getQueryAsync(appData.CollectionName, query);

Expand All @@ -90,13 +90,13 @@ public async Task<object> executeGetAsync<T>(AbstractKinveyClient client, AppDat

} else if (idIndex == (targetURI.Length + 1)|| targetURI.Contains ("query")) {
//it's a get all request (no query, no id)
handler.createTableAsync (appData.CollectionName);
await handler.createTableAsync (appData.CollectionName);
List<T> ok = await handler.getAllAsync (appData.CollectionName);
return ok;
} else {
//it's a get by id
String targetID = targetURI.Substring(idIndex, targetURI.Length - idIndex);
handler.createTableAsync (appData.CollectionName);
await handler.createTableAsync (appData.CollectionName);
ret = (T) await handler.getEntityAsync (appData.CollectionName, targetID);

await handler.enqueueRequestAsync("GET", appData.CollectionName, targetURI.Substring(idIndex, targetURI.Length - idIndex));
Expand Down Expand Up @@ -130,7 +130,7 @@ public async Task<object> executeSaveAsync<T>(AbstractKinveyClient client, AppDa
string id = (string)token.SelectToken("_id");

//insert the entity into the database
handler.createTableAsync (appData.CollectionName);
await handler.createTableAsync (appData.CollectionName);
await handler.upsertEntityAsync(id, appData.CollectionName, jsonContent);
//enque the request
await handler.enqueueRequestAsync("PUT", appData.CollectionName, id);
Expand Down Expand Up @@ -163,7 +163,7 @@ public async Task<KinveyDeleteResponse> executeDeleteAsync<T>(AbstractKinveyClie



handler.createTableAsync (appData.CollectionName);
await handler.createTableAsync (appData.CollectionName);
KinveyDeleteResponse ret = await handler.deleteAsync(appData.CollectionName, targetID);

await handler.enqueueRequestAsync("DELETE",appData.CollectionName, targetURI.Substring(idIndex, targetURI.Length - idIndex));
Expand All @@ -188,7 +188,7 @@ public async Task<int> insertEntityAsync<T>(AbstractKinveyClient client, AppData
JToken token = JObject.Parse(jsonContent);
string id = (string)token.SelectToken("_id");

handler.createTableAsync (appData.CollectionName);
await handler.createTableAsync (appData.CollectionName);

await handler.upsertEntityAsync( id, appData.CollectionName, jsonContent);
return 0;
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions packages/repositories.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<repositories>
<repository path="../../../ksamples/xamarin/StatusShare-Xamarin/android/packages.config" />
<repository path="../../../ksamples/xamarin/TestDrive-Xamarin/android/packages.config" />
<repository path="../Android-Libtester/packages.config" />
<repository path="../Kinvey-Xamarin/packages.config" />
<repository path="../LibTester/packages.config" />
Expand Down

0 comments on commit 4c798ac

Please sign in to comment.