public void Init(NavObject navObject) { Username = navObject.Username; Repository = navObject.Repository; Branch = navObject.Branch; Filename = navObject.Filename; _actualFilename = System.IO.Path.GetFileName(Filename); if (_actualFilename == null) _actualFilename = Filename.Substring(Filename.LastIndexOf('/') + 1); Title = _actualFilename; _commitFileModel = Mvx.Resolve<IViewModelTxService>().Get() as ChangesetDiffModel; }
protected override async Task Load(bool forceCacheInvalidation) { //Make sure we have this information. If not, go get it if (_commitFileModel == null) { var data = await Task.Run(() => this.GetApplication().Client.Users[Username].Repositories[Repository].Changesets[Branch].GetDiffs(forceCacheInvalidation)); _commitFileModel = data.First(x => string.Equals(x.File, Filename)); } if (_commitFileModel.Type == "added" || _commitFileModel.Type == "modified") { var filepath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetFileName(Filename)); var mime = await Task.Run<string>(() => { using (var stream = new System.IO.FileStream(filepath, System.IO.FileMode.Create, System.IO.FileAccess.Write)) { return this.GetApplication().Client.Users[Username].Repositories[Repository].Branches[Branch].Source.GetFileRaw(Filename, stream); } }); var isText = mime.Contains("text"); if (!isText) { FilePath = filepath; return; } File1 = filepath; } if (_commitFileModel.Type == "removed" || _commitFileModel.Type == "modified") { var changeset = await Task.Run(() => this.GetApplication().Client.Users[Username].Repositories[Repository].Changesets[Branch].GetInfo(forceCacheInvalidation)); if (changeset.Parents == null || changeset.Parents.Count == 0) throw new Exception("Diff has no parent. Unable to generate view."); var parent = changeset.Parents[0]; var filepath2 = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetFileName(Filename) + ".parent"); var mime = await Task.Run<string>(() => { using (var stream = new System.IO.FileStream(filepath2, System.IO.FileMode.Create, System.IO.FileAccess.Write)) { return this.GetApplication().Client.Users[Username].Repositories[Repository].Branches[parent].Source.GetFileRaw(Filename, stream); } }); var isText = mime.Contains("text"); if (!isText) { FilePath = filepath2; return; } File2 = filepath2; } if (File1 != null) FilePath = File1; else if (File2 != null) FilePath = File2; Comments.SimpleCollectionLoad(() => this.GetApplication().Client.Users[Username].Repositories[Repository].Changesets[Branch].Comments.GetComments(forceCacheInvalidation)).FireAndForget(); }