public async Task <ActionResult> Index(string originalUrl) { try { var uri = UriBuilderHelper.TryCreateUri(originalUrl); if (await _snapshotManager.CheckUriIsAvailable(uri)) { return(Redirect(uri.ToString())); } else { var archivedLink = _contentManager.Query().Where <ArchivedLinkPartRecord>(link => link.OriginalUrl == originalUrl).Slice(1).SingleOrDefault(); if (archivedLink != null) { var commonPart = archivedLink.As <CommonPart>(); if (commonPart != null) { var snapshotTaken = commonPart.ModifiedUtc == null ? commonPart.CreatedUtc : commonPart.ModifiedUtc; return(View(new SnapshotViewModel { SnapshotIndexPublicUrl = _snapshotManager.GetSnapshotIndexPublicUrl(uri), SnapshotTaken = (DateTime)snapshotTaken })); } } return(HttpNotFound()); } } catch (UriFormatException) { return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest, "Bad Request")); } }
protected override DriverResult Editor(ArchivedLinkPart part, IUpdateModel updater, dynamic shapeHelper) { if (updater.TryUpdateModel(part, Prefix, null, null)) { try { var uri = UriBuilderHelper.TryCreateUri(part.OriginalUrl); _snapshotManager.SaveSnapshot(uri); } catch (UriFormatException) { updater.AddModelError("UriFormatException", T("There was a problem with the given url: {0}", part.OriginalUrl)); } catch (Exception ex) { if (ex.IsFatal()) { throw; } updater.AddModelError("Exception", T("Unknown problem while saving your url.")); } } return(Editor(part, shapeHelper)); }
public ArchivedLinkHandler(IRepository <ArchivedLinkPartRecord> repository, Work <ISnapshotManager> snapshotManagerWork) { Filters.Add(StorageFilter.For(repository)); OnRemoving <ArchivedLinkPart>((context, part) => { var uri = UriBuilderHelper.TryCreateUri(part.OriginalUrl); snapshotManagerWork.Value.RemoveSnapshot(uri); }); }
protected override DriverResult Display(ArchivedLinkPart part, string displayType, dynamic shapeHelper) { return(ContentShape("Parts_ArchivedLink", () => { var uri = UriBuilderHelper.TryCreateUri(part.OriginalUrl); return shapeHelper.Parts_ArchivedLink( OriginalUrl: part.OriginalUrl, SnapshotUrl: _snapshotManager.GetSnapshotIndexPublicUrl(uri).ToString() ); })); }
/// <summary> /// Gets the full URI for the authorize endpoint /// </summary> /// <param name="clientId">Client ID</param> /// <param name="responseType">Response type</param> /// <param name="redirectUri">Redirect URI</param> /// <param name="state">The state</param> /// <param name="scope">The scope</param> /// <returns>The full URI for the authorize endpoint</returns> public Uri GetAuthorizeUri( string clientId, string responseType, string redirectUri, string state, string scope) { string baseUri = "https://accounts.spotify.com/authorize"; Dictionary <string, string> queryString = new Dictionary <string, string>() { ["client_id"] = clientId, ["response_type"] = responseType, ["redirect_uri"] = redirectUri, ["state"] = state, ["scope"] = scope }; return(UriBuilderHelper.Create(baseUri, queryString)); }