public DownloadStatus RetrieveBranchList(BranchListRetrieved onRetrieved) { if (dlBranches != null || dlRepo != null) { Reset(); } if (!NetworkInterface.GetIsNetworkAvailable()) { return(DownloadStatus.NoInternet); } dlBranches = CreateWebClient(); dlBranches.DownloadStringCompleted += (sender, args) => { if (args.Cancelled || args.Error != null) { onRetrieved(null, ProcessWebException(args.Error as WebException)); return; } List <string> branches = new List <string>(2); foreach (object entry in (object[])new JavaScriptSerializer().DeserializeObject(args.Result)) { branches.Add((string)((Dictionary <string, object>)entry)["name"]); } onRetrieved(branches.Remove("master") ? Enumerable.Repeat("master", 1).Concat(branches) : branches, null); }; try{ dlBranches.DownloadStringAsync(BranchesUrl); return(DownloadStatus.Started); }catch (WebException) { return(DownloadStatus.NoConnection); } }
public DownloadStatus RetrieveBranchList(BranchListRetrieved onRetrieved) { if (dlBranches != null || dlRepo != null){ Reset(); } if (!NetworkInterface.GetIsNetworkAvailable()){ return DownloadStatus.NoInternet; } dlBranches = CreateWebClient(); dlBranches.DownloadStringCompleted += (sender, args) => { if (args.Cancelled || args.Error != null){ onRetrieved(null, ProcessWebException(args.Error as WebException)); return; } List<string> branches = new List<string>(2); foreach(object entry in (object[])new JavaScriptSerializer().DeserializeObject(args.Result)){ branches.Add((string)((Dictionary<string, object>)entry)["name"]); } onRetrieved(branches.Remove("master") ? Enumerable.Repeat("master", 1).Concat(branches) : branches, null); }; try{ dlBranches.DownloadStringAsync(BranchesUrl); return DownloadStatus.Started; }catch(WebException){ return DownloadStatus.NoConnection; } }