public void GetPasteAlive(IEnumerable <Paste> pastes) { foreach (var paste in pastes) { if (String.Compare(paste.PasteExpiration, "Never") != 0 && TimeSpan.Compare(DateTime.Now.Subtract(paste.CreatedDateTime), PasteExpiration.ToTimeSpan(paste.PasteExpiration)) == 1) { var obj = _context.Pastes.FirstOrDefault(p => p.Id == paste.Id); if (obj != null) { _context.Pastes.Remove(obj); } } } _context.SaveChanges(); }
/// <summary> /// Creates a new paste under the current user asynchronously. /// </summary> /// <param name="title">The title of the paste as it will appear on the page.</param> /// <param name="languageId"> /// The the language ID of the paste's content. A full list of language IDs can be found at /// https://pastebin.com/api#5 /// </param> /// <param name="code">The contents of the paste.</param> /// <param name="exposure">The visibility of the paste (private, public, or unlisted).</param> /// <param name="expiration">The duration of time the paste will be available before expiring.</param> /// <returns>The newly created <see cref="Paste" />.</returns> /// <exception cref="System.Net.WebException">Thrown when the underlying HTTP client encounters an error.</exception> /// <exception cref="ArgumentNullException">Thrown when <paramref name="code" /> is null.</exception> /// <exception cref="PastebinException">Thrown when a bad API request is made.</exception> public async Task <Paste> CreatePasteAsync( string title, string languageId, string code, PasteExposure?exposure = null, PasteExpiration expiration = PasteExpiration.Never) { var parameters = PastebinClient.CreatePasteImpl( title, languageId, code, exposure ?? this.DefaultExposure, expiration); await this._agent.PostAsync(PastebinClient.PasteOption, parameters); return((await this.GetPastesAsync(1).ConfigureAwait(false)).Single()); }
/// <summary> /// Creates a new anonymous paste asynchronously. Private pastes are not allowed when pasting anonymously. /// </summary> /// <param name="title">The title of the paste as it will appear on the page.</param> /// <param name="languageId"> /// The the language ID of the paste's content. A full list of language IDs can be found at /// https://pastebin.com/api#5 /// </param> /// <param name="code">The contents of the paste.</param> /// <param name="exposure">The visibility of the paste (private, public, or unlisted).</param> /// <param name="expiration">The duration of time the paste will be available before expiring.</param> /// <returns>The URL for the newly created paste.</returns> /// <exception cref="System.Net.WebException">Thrown when the underlying HTTP client encounters an error.</exception> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="code" /> is null.</exception> /// <exception cref="PastebinException">Thrown when a bad API request is made.</exception> public async Task <string> CreatePasteAsync( string title, string languageId, string code, PasteExposure exposure = PasteExposure.Public, PasteExpiration expiration = PasteExpiration.Never ) { var parameters = PastebinClient.CreatePasteImpl( title, languageId, code, exposure, expiration ); return(await this._agent.PostAsync(PastebinClient.PasteOption, parameters).ConfigureAwait(false)); }
internal static string CreatePasteImpl( WebAgent agent, bool authenticated, string title, string languageId, string code, PasteExposure exposure, PasteExpiration expiration ) { if( code == null ) throw new ArgumentNullException( "code" ); if( title == null ) title = "Untitled"; if( languageId == null ) languageId = "text"; string expirationString; switch( expiration ) { case PasteExpiration.Never: expirationString = "N"; break; case PasteExpiration.OneDay: expirationString = "1D"; break; case PasteExpiration.OneHour: expirationString = "1H"; break; case PasteExpiration.OneMonth: expirationString = "1M"; break; case PasteExpiration.OneWeek: expirationString = "1W"; break; case PasteExpiration.TenMinutes: expirationString = "10M"; break; case PasteExpiration.TwoWeeks: expirationString = "2W"; break; default: throw new NotImplementedException(); } var parameters = new Dictionary<string, object> { { "api_paste_code", code }, { "api_paste_name", title }, { "api_paste_format", languageId }, { "api_paste_private", (int)exposure }, { "api_paste_expire_date", expirationString }, }; return agent.Post( PasteOption, parameters ); }
/// <summary> /// Creates a new anonymous paste. Private pastes are not allowed when pasting anonymously. /// </summary> /// <param name="title">The title of the paste as it will appear on the page.</param> /// <param name="languageId">The the language ID of the paste's content. A full list of language IDs can be found at http://pastebin.com/api#5 </param> /// <param name="code">The contents of the paste.</param> /// <param name="exposure">The visibility of the paste (private, public, or unlisted).</param> /// <param name="expiration">The duration of time the paste will be available before expiring.</param> /// <returns>The URL for the newly created paste.</returns> /// <exception cref="System.Net.WebException">Thrown when the underlying HTTP client encounters an error.</exception> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="code"/> is null.</exception> /// <exception cref="PastebinException">Thrown when a bad API request is made.</exception> public string CreatePaste( string title, string languageId, string code, PasteExposure exposure = PasteExposure.Public, PasteExpiration expiration = PasteExpiration.Never ) { return Pastebin.CreatePasteImpl( this.agent, false, title, languageId, code, exposure, expiration ); }
/// <summary> /// Creates a new paste under the current user. /// </summary> /// <param name="title">The title of the paste as it will appear on the page.</param> /// <param name="languageId">The the language ID of the paste's content. A full list of language IDs can be found at http://pastebin.com/api#5 </param> /// <param name="code">The contents of the paste.</param> /// <param name="exposure">The visibility of the paste (private, public, or unlisted).</param> /// <param name="expiration">The duration of time the paste will be available before expiring.</param> /// <returns>The URL for the newly created paste.</returns> /// <exception cref="System.Net.WebException">Thrown when the underlying HTTP client encounters an error.</exception> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="code"/> is null.</exception> /// <exception cref="PastebinException">Thrown when a bad API request is made.</exception> public string CreatePaste(string title, string languageId, string code, PasteExposure exposure = PasteExposure.Public, PasteExpiration expiration = PasteExpiration.Never) { return(Pastebin.CreatePasteImpl(this.agent, true, title, languageId, code, exposure, expiration)); }
internal static Dictionary <string, object> CreatePasteImpl( string title, string languageId, string code, PasteExposure exposure, PasteExpiration expiration) { if (code == null) { throw new ArgumentNullException(nameof(code)); } if (title == null) { title = "Untitled"; } if (languageId == null) { languageId = "text"; } string expirationString; switch (expiration) { case PasteExpiration.Never: expirationString = "N"; break; case PasteExpiration.OneDay: expirationString = "1D"; break; case PasteExpiration.OneHour: expirationString = "1H"; break; case PasteExpiration.OneMonth: expirationString = "1M"; break; case PasteExpiration.OneWeek: expirationString = "1W"; break; case PasteExpiration.TenMinutes: expirationString = "10M"; break; case PasteExpiration.TwoWeeks: expirationString = "2W"; break; default: throw new NotSupportedException(); } return(new Dictionary <string, object> { { "api_paste_code", code }, { "api_paste_name", title }, { "api_paste_format", languageId }, { "api_paste_private", (int)exposure }, { "api_paste_expire_date", expirationString } }); }
internal static string CreatePasteImpl(WebAgent agent, bool authenticated, string title, string languageId, string code, PasteExposure exposure, PasteExpiration expiration) { if (code == null) { throw new ArgumentNullException("code"); } if (title == null) { title = "Untitled"; } if (languageId == null) { languageId = "text"; } string expirationString; switch (expiration) { case PasteExpiration.Never: expirationString = "N"; break; case PasteExpiration.OneDay: expirationString = "1D"; break; case PasteExpiration.OneHour: expirationString = "1H"; break; case PasteExpiration.OneMonth: expirationString = "1M"; break; case PasteExpiration.OneWeek: expirationString = "1W"; break; case PasteExpiration.TenMinutes: expirationString = "10M"; break; case PasteExpiration.TwoWeeks: expirationString = "2W"; break; default: throw new NotImplementedException(); } var parameters = new Dictionary <string, object> { { "api_paste_code", code }, { "api_paste_name", title }, { "api_paste_format", languageId }, { "api_paste_private", (int)exposure }, { "api_paste_expire_date", expirationString }, }; return(agent.Post(PasteOption, parameters, authenticated)); }