private void LoadRepos(IsolatedStorageFile iso) { if (!iso.FileExists(RepoFilename)) return; try { using (var stream = iso.OpenFile(RepoFilename, FileMode.Open, FileAccess.Read)) using (var br = new BinaryReader(stream)) { var fileVer = br.ReadInt32(); var numContexts = br.ReadInt32(); for (int i = 0; i < numContexts; i++) { var login = br.ReadString(); foreach (var context in Contexts) { if (context.User.Login.Equals(login)) { var numMyRepos = br.ReadInt32(); context.Repositories.Clear(); for (int j = 0; j < numMyRepos; j++) { var repo = new Repo(); repo.Load(br, fileVer); context.Repositories.Add(repo); } break; } } } br.Close(); } } catch (EndOfStreamException) { iso.DeleteFile(RepoFilename); } }
public void UploadIssue(Repo r, string title, string body, Action<Issue> callback) { _client.Issues.CreateIssueAsync(r.Repository.Owner, r.Repository.Name, title, body, callback, _exceptionAction); }
public void DownloadIssues(Context context, Repo r, Action onStart, Action onComplete) { if (onStart != null) { // Call twice for two GET operations onStart(); onStart(); } // Download open issues _client.Issues.GetIssuesAsync(r.Repository.Owner, r.Repository.Name, State.Open, issues => Dispatcher.BeginInvoke(() => { foreach (var i in issues) { var oldIssue = r.Issues.FirstOrDefault(iss => iss.Number == i.Number); if (oldIssue != null) r.Issues.Remove(oldIssue); r.Issues.Add(i); } if (onComplete != null) onComplete(); }), _exceptionAction); // Download closed issues _client.Issues.GetIssuesAsync(r.Repository.Owner, r.Repository.Name, State.Closed, issues => Dispatcher.BeginInvoke(() => { foreach (var i in issues) { var oldIssue = r.Issues.FirstOrDefault(iss => iss.Number == i.Number); if (oldIssue != null) r.Issues.Remove(oldIssue); r.Issues.Add(i); } if (onComplete != null) onComplete(); }), _exceptionAction); }
public void RefreshContextRepos(Context context, Action onStart, Action onComplete) { if (!IsAuthenticated || Dispatcher == null) return; if (onStart != null) { // Call twice for two GET operations onStart(); onStart(); } _client.Users.GetRepositoriesAsync(context.User.Login, repos => Dispatcher.BeginInvoke(() => { foreach (var repo in context.Repositories.Where(r => (r.Type & RepoType.Owned) == RepoType.Owned)) repo.Type ^= RepoType.Owned; foreach (var repo in repos) { var newRepo = context.Repositories.FirstOrDefault(r => r.Repository.FullName == repo.FullName); if (newRepo == null) { newRepo = new Repo(repo); newRepo.Type |= RepoType.Owned; context.Repositories.Add(newRepo); } else newRepo.Repository = repo; newRepo.Type |= RepoType.Owned; } if (onComplete != null) onComplete(); }), _exceptionAction); _client.Users.GetWatchedRepositoriesAsync(context.User.Login, repos => Dispatcher.BeginInvoke(() => { foreach (var repo in context.Repositories.Where(r => (r.Type & RepoType.Watched) == RepoType.Watched)) repo.Type ^= RepoType.Watched; foreach (var repo in repos) { var newRepo = context.Repositories.FirstOrDefault(r => r.Repository.FullName == repo.FullName); if (newRepo == null) { newRepo = new Repo(repo); newRepo.Type |= RepoType.Watched; context.Repositories.Add(newRepo); } else newRepo.Repository = repo; newRepo.Type |= RepoType.Watched; } if (onComplete != null) onComplete(); }), _exceptionAction); }
public void DownloadIssueComments(Context context, Repo r, Issue i, Action<Repo> callback) { //_client.Issues. _client.Issues.GetCommentsAsync(r.Repository.Owner, r.Repository.Name, i.Number, comments => Dispatcher.BeginInvoke(() => { if (r.IssueComments.ContainsKey(i)) r.IssueComments[i].Clear(); else r.IssueComments.Add(i, new ObservableCollection<Comment>()); foreach (var c in comments) { r.IssueComments[i].Add(c); } callback(r); }), _exceptionAction); }