Created
March 14, 2012 18:03
-
-
Save wwahammy/2038267 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CoAppService : ICoAppService | |
{ | |
internal readonly PackageManager Pm; | |
public CoAppService() | |
{ | |
Pm = PackageManager.Instance; | |
} | |
public Task<Tuple<string, IEnumerable<string>>> GetPolicy(PolicyType type) | |
{ | |
var tcs = new TaskCompletionSource<Tuple<string, IEnumerable<string>>>(); | |
Pm.GetPolicy(type.ToString(), new PackageManagerMessages | |
{ | |
Error = (a, b, c) => tcs.SetException(new Exception()), | |
PolicyInformation = | |
(a, b, c) => | |
tcs.SetResult(new Tuple<string, IEnumerable<string>>(b, c)) | |
}); | |
return tcs.Task; | |
} | |
public Task AddPrincipalToPolicy(PolicyType type, string principal) | |
{ | |
//var tcs = new TaskCompletionSource<Tuple<string, IEnumerable<string>>>(); | |
//TODO is this okay? | |
return Pm.AddToPolicy(type.ToString(), principal); | |
} | |
public Task RemovePrincipalFromPolicy(PolicyType type, string principal) | |
{ | |
return Pm.RemoveFromPolicy(type.ToString(), principal); | |
} | |
/// <summary> | |
/// TODO: holy cow, is this confusing | |
/// </summary> | |
public Task<IEnumerable<string>> SystemFeeds | |
{ | |
get | |
{ | |
var tcs = new TaskCompletionSource<IEnumerable<string>>(); | |
var list = new List<string>(); | |
Pm.ListFeeds(default(int?), default(int?), | |
new PackageManagerMessages{ | |
Error = (a, b, c) => tcs.SetException(new Exception()), | |
NoFeedsFound = () => tcs.SetResult(Enumerable.Empty<string>()), | |
FeedDetails = (s, d, b1, b2, b3) => | |
{ | |
if (!b1) | |
lock (list) | |
{ | |
list.Add(s); | |
} | |
} | |
}).ContinueWith((t) => | |
{ | |
if (tcs.Task.IsCompleted || tcs.Task.IsFaulted) | |
{ | |
//no feeds! | |
} | |
else | |
{ | |
tcs.SetResult(list); | |
} | |
}); | |
return tcs.Task; | |
} | |
} | |
public Task AddSystemFeed(string feedUrl) | |
{ | |
var tcs = new TaskCompletionSource<bool>(); | |
Pm.AddFeed(feedUrl, false, new PackageManagerMessages | |
{ | |
Error = (a, b, c) => tcs.SetException(new Exception()), | |
FeedAdded = (a) => tcs.SetResult(true) | |
}); | |
return tcs.Task; | |
} | |
public Task RemoveSystemFeed(string feedUrl) | |
{ | |
var tcs = new TaskCompletionSource<bool>(); | |
var list = new List<string>(); | |
Pm.RemoveFeed(feedUrl, false, new PackageManagerMessages | |
{ | |
Error = (a, b, c) => tcs.SetException(new Exception()), | |
FeedAdded = (a) => tcs.SetResult(true) | |
}); | |
return tcs.Task; | |
} | |
public Task<IEnumerable<string>> SessionFeeds | |
{ | |
get { throw new NotImplementedException(); } | |
} | |
public Task<bool> OptedIn | |
{ | |
get { return Task.Factory.StartNew(() => false); } | |
} | |
public Task SetOptedIn(bool optedIn) | |
{ | |
throw new NotImplementedException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment