/// <summary> /// Adds new HTTP error to the list /// </summary> /// <param name="error">Error you want to add</param> public void Add(HTTPError error) { if (!this.httpErrors.Contains(error)) { this.httpErrors.Add(error); } }
/// <summary> /// Reads text from file /// </summary> /// <param name="path">Path to file with text which contains code of errors</param> /// <returns>Pair of text from file and changed text</returns> /// <exception cref="System.IO.IOException">Throw when an incorrect file path is specified</exception> public MyTextPair ReadTextFromFile(string path) { FileInfo fi = new FileInfo(path); if (fi.Exists == false) { throw new FileNotFoundException("There is no such file."); } using (var streamReader = new StreamReader(path)) { var str = streamReader.ReadToEnd(); char[] separators = { ' ', '-', '.', '(', ')', ',', ':', '\n', '\t', '?', '!', ';' }; this.httpErrors = (from t in str.Split(separators, StringSplitOptions.RemoveEmptyEntries) where t.StartsWith("#") select new HTTPError(int.Parse(t.Substring(1)), DateTime.Now)).ToList <HTTPError>(); var newStr = new StringBuilder(str); foreach (var httpError in this.httpErrors) { newStr.Replace(httpError.Code.ToString(), $"['{HTTPError.GetDescriptionOf(httpError.Code)}', {httpError.Date.ToString(CultureInfo.CurrentCulture)}]"); } return(new MyTextPair(str, newStr.ToString())); } }
/// <summary> /// Removes specified HTTP error from the list /// </summary> /// <param name="error">Error you want to remove</param> /// <returns>Error that was removed</returns> public bool Remove(HTTPError error) { if (this.httpErrors.Contains(error)) { return(this.httpErrors.Remove(error)); } return(false); }
/// <summary> /// Checks if list contains specified HTTP error /// </summary> /// <param name="error">An error whose presence will be checked</param> /// <returns> <see langword="true"/> if the error is on the list, <see langword="false"/> otherwise</returns> public bool Contains(HTTPError error) { return(this.httpErrors.Contains(error)); }