Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-16672] Fixed serious race condition with downloadFile() as well a... #5526

Merged
merged 1 commit into from
Mar 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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; }
}
}