Skip to content

Commit

Permalink
Merge pull request #5526 from cb1kenobi/timob-16672_3_2_X_hybrid
Browse files Browse the repository at this point in the history
[TIMOB-16672] Fixed serious race condition with downloadFile() as well a...
  • Loading branch information
cb1kenobi committed Mar 25, 2014
2 parents cfea310 + b9e2124 commit 9455550
Show file tree
Hide file tree
Showing 13 changed files with 437 additions and 335 deletions.
32 changes: 17 additions & 15 deletions mobileweb/src/wp8.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,24 +194,26 @@
});
},

downloadFile: function (url, opts, callback) {
if (!url) {
throw new Error('downloadFile requires a "url"');
downloadFile: function (opts) {
if (!opts.url) {
throw new Error('Missing required "url"');
}
if (!opts && !callback) {
throw new Error('downloadFile requires a "callback"');
}
if (typeof opts == 'function') {
callback = opts;
opts = 0;
}
opts || (opts = {});
opts.url = url;
var r = sendRequest('download', opts);
r.addEventListener('complete', function (e) {
var r = sendRequest('download', {
url: opts.url,
saveTo: opts.saveTo,
overwrite: opts.overwrite
}),
oncomplete = opts.oncomplete,
onerror = opts.onerror;
r.addEventListener('complete', function (evt) {
r.destroy();
oncomplete && typeof oncomplete == 'function' && oncomplete(evt);
});
r.addEventListener('error', function (evt) {
r.destroy();
callback(e);
onerror && typeof onerror == 'function' && onerror(new Error(evt.error && evt.error.Message || "Unknown error"));
});
r.invoke('send');
},

fireEvent: function (data) {
Expand Down
13 changes: 13 additions & 0 deletions mobileweb/templates/packages/wp8/{{ProjectName}}/ErrorEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace TitaniumApp
{
public class ErrorEventArgs : EventArgs
{
public ErrorEventArgs(Exception ex) {
this.error = ex;
}

public Exception error { get; private set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@

namespace TitaniumApp
{
public class InstanceRegistryException : Exception
{
public string Type = "InstanceRegistryException";

public InstanceRegistryException() {}
public InstanceRegistryException(string message) : base(message) {}
public InstanceRegistryException(string message, Exception inner) : base(message, inner) {}
}

public static class InstanceRegistry
{
private static Dictionary<string, Type> cachedTypes = new Dictionary<string, Type>();
Expand Down Expand Up @@ -88,7 +97,7 @@ public static class InstanceRegistry
public static string createHandle(object instance) {
string handle = instanceCount++.ToString();
if (instanceCount > UInt64.MaxValue) {
throw new Exception("Reflection Handler Exception: Maximum instance count exceeded");
throw new InstanceRegistryException("Maximum instance count exceeded");
}
Logger.log("InstanceRegistry", "Creating instance handle " + handle + ": " + instance.ToString());
instances[handle] = instance;
Expand Down
22 changes: 11 additions & 11 deletions mobileweb/templates/packages/wp8/{{ProjectName}}/TiRequest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;

namespace TitaniumApp
{
class TiRequest
{
public string type { get; set; }
public string token { get; set; }
public TiRequestParams data { get; set; }
}
}
using System;

namespace TitaniumApp
{
public class TiRequest
{
public string type { get; set; }
public string token { get; set; }
public TiRequestParams data { get; set; }
}
}

0 comments on commit 9455550

Please sign in to comment.