Skip to content

Requests

TypNull edited this page May 8, 2024 · 1 revision

Summary

$\text{\color{none}WebRequest<\color{orange}TOptions\color{none},\color{green}TCompleated\color{none}>}$ Class

This class serves as the base class for all WebRequest<TOptions, TCompleated> implementations that use the HttpClient.

Generic Parameters:

  • $\text{\color{orange}TOptions}$: Type: WebRequestOptions<TCompleated>
    • Specifies the type of options used by the web request.
  • $\text{\color{green}TCompleated}$: Type: none
    • Specifies the return type of the request.

Properties:

  • Url: Type: string
    • This property gets the string that represents the URL of the WebRequest<TOptions, TCompleated>.

Methods:

  • Constructor:
    • This method initializes a new instance of the WebRequest<TOptions, TCompleated> class. It takes a string URL that the WebRequest<TOptions, TCompleated> will call and TOptions? options used to modify the WebRequest<TOptions, TCompleated>.
  • protected GetPresetRequestMessage: Type: HttpRequestMessage
    • This method sets the headers of the WebRequestOptions<TCompleated> to a HttpRequestMessage. It returns a HttpRequestMessage with all the default headers set.

StatusRequest Class

This class represents a web request that only retrieves the headers of a URL. This is achieved by sending a HttpMethod.Head request.

Methods:

  • Constructor:
    • This method initializes a new instance of the StatusRequest class. It takes a string URL from which to retrieve the head response and WebRequestOptions<HttpResponseMessage>? options used to modify the Request<TOptions, TCompleated, TFailed>.
  • protected override RunRequestAsync: Type: Task<RequestReturn>
    • This method executes the StatusRequest that the HttpClient should start. It returns a Request<TOptions, TCompleated, TFailed>.RequestReturn object indicating whether the StatusRequest was successful and containing the return objects.
  • private SendHttpMenssage: Type: Task<HttpResponseMessage>
    • This method creates an HttpRequestMessage and sends it. It returns the HttpResponseMessage resulting from the request.
  • private SetTimedToken: Type: void
    • This method sets up a cancellation token that will cancel the request after a specified timeout.
  • private static SetRequestReturn: Type: void
    • This method populates the Request<TOptions, TCompleated, TFailed>.RequestReturn object with data from the HttpResponseMessage.

SiteRequest Class

A request that scans a website for references and files.

Properties:

  • HTML: Type: string
    • Gets the HTML content of the website.
  • BaseURl: Type: string
    • Gets the base URL of the website.
  • Links: Type: IReadOnlyList<WebItem>
    • Gets all the links on the website.
  • Videos: Type: IReadOnlyList<WebItem>
    • Gets all the videos on the website.
  • Audios: Type: IReadOnlyList<WebItem>
    • Gets all the audios on the website.
  • Images: Type: IReadOnlyList<WebItem>
    • Gets all the images on the website.
  • Files: Type: IReadOnlyList<WebItem>
    • Gets all the files on the website.
  • Scripts: Type: IReadOnlyList<WebItem>
    • Gets all the scripts on the website.
  • UnknownType: Type: IReadOnlyList<WebItem>
    • Gets all the unknown type files on the website.
  • CSS: Type: IReadOnlyList<WebItem>
    • Gets all the CSS files on the website.
  • References: Type: IReadOnlyList<WebItem>
    • Gets all the references on the website.

Methods:

  • Constructor:
    • Initializes a new instance of the SiteRequest class. Throws a UriFormatException when the provided URL is not well-formed.
  • private SendHttpMenssage: Type: Task<HttpResponseMessage>
    • Sends an HTTP message.
  • protected RunRequestAsync: Type: Task<RequestReturn>
    • Runs the request asynchronously.
  • private ScanReferences: Type: void
    • Scans the HTML for references.
  • private SortReferneces: Type: void
    • Sorts the references by type.
  • private ScanOther: Type: IEnumerable<WebItem>
    • Scans for other items in the HTML.
  • private ScanReferences: Type: IEnumerable<WebItem>
    • Scans the tags for references.
  • private FileExtensionToMediaTag: Type: string
    • Converts the file extension of a URI to a media tag.
  • private GetTag: Type: string
    • Extracts the value of a specified tag from a string.

GetRequest Class

This class represents a GET request to download content from a specified URL. It inherits from the WebRequest<GetRequestOptions, string> class and implements the IProgressableRequest interface. It starts an HttpGet and saves the content stream to a file.

Properties:

  • BytesWritten: Type: long
    • This property gets the number of bytes that were written to the destination file.
  • ContentLength: Type: long
    • This property gets the length of the content that will be downloaded. It returns the partial content length if the GetRequest is partial, otherwise it returns the full content length.
  • FullContentLength: Type: Nullable<long>
    • This property gets the full length of the content, even if the GetRequest is partial.
  • PartialContentLength: Type: Nullable<long>
    • This property gets the partial length of the content if the GetRequest is partial.
  • Filename: Type: string
    • This property gets the name of the file that should be downloaded.
  • ContentName: Type: string
    • This property gets the name of the content from the server.
  • ContentExtension: Type: string
    • This property gets the extension of the content from the server.
  • ContentHeaders: Type: Nullable<HttpContentHeaders>
    • This property gets the content headers of the last attempt.
  • FilePath: Type: string
    • This property gets the path to the download file.
  • Progress: Type: Progress<float>
    • This property gets the progress to receive updates of the download process.
  • private Range: Type: LoadRange
    • This property gets the range that should be downloaded.

Methods:

  • Constructor:
    • This method initializes a new instance of the GetRequest class. It throws a NotSupportedException when LoadMode.Append and Range.Start are set.
  • IsPartial: Type: bool
    • This method determines whether the request is partial. It returns true if the HTTP GET request is partial; otherwise, it returns false.
  • ShouldBePartial: Type: bool
    • This method determines whether the last request should be partial. It returns true if the HTTP GET request has to be partial; otherwise, it returns false.
  • RunToCompleatedAsync: Type: Task
    • This method allows the request to complete successfully without performing any additional actions.
  • SetContentLength: Type: void
    • This method sets the content length of the request if known. It throws an ArgumentOutOfRangeException when the length is 0 or less.
  • Dispose: Type: void
    • This method disposes the GetRequest instance. It is called automatically by the RequestHandler. It throws an AggregateException when one or more errors occur during the disposal of the GetRequest instance. It also throws an ArgumentException when an argument provided to a method is not valid, an ObjectDisposedException when an attempt is made to access an object that has been disposed, and an InvalidOperationException when a method call is invalid for the object's current state.
  • protected RunRequestAsync: Type: Task<RequestReturn>
    • This method handles the request of this IRequest.
  • private LoadWrittenBytes: Type: void
    • This method loads file info if the file exists. It throws an InvalidOperationException when the mode is not WriteMode.Append, BytesWritten is greater than 0, Filename is empty, or Filename does not contain '.'.
  • private SetHttpGet: Type: void
    • This method initializes a new instance of the HttpGet class that holds the HTTP information.
  • private LoadAsync: Type: Task<RequestReturn>
    • This method asynchronously loads the request.
  • private ReloadActions: Type: Task<HttpResponseMessage>
    • This method checks if further actions on the file or the request are necessary.
  • private SetFileInfo: Type: void
    • This method sets the information for the HTTP request.
  • private SendRequestAsync: Type: Task<HttpResponseMessage>
    • This method starts the HTTP GET request and overwrites the bytes written.
  • private WriteToFileAsync: Type: Task
    • This method writes the response to a file.
  • private WriterAsync: Type: Task
    • This method writes the response stream to the file stream.
  • private IsFinished: Type: bool
    • This method determines whether the file download is finished. It returns true if the number of bytes written is equal to the content length; otherwise, it returns false.
  • private CheckReload: Type: bool
    • This method checks if the HTTP request should be sent again when the filename exists on the drive. It returns true if a reload is necessary; otherwise, it returns false.
  • private CheckClearFile: Type: bool
    • This method checks if the HTTP request should be partial but is not. It returns true if the file should be deleted; otherwise, it returns false.

LoadRequest Class

This class represents a WebRequest that loads a response as a stream and saves it to a file.

Properties:

  • Range: Type: LoadRange
    • Gets the range of data that should be downloaded.
  • Filename: Type: Nullable<string>
    • Gets the filename of the content that is being downloaded.
  • BytesWritten: Type: long
    • Gets the number of bytes that have been written to the temporary file.
  • BytesDownloaded: Type: long
    • Gets the number of bytes that have been downloaded.
  • ContentLength: Type: long
    • Gets the length of the content that will be downloaded.
  • IsChunked: Type: bool
    • Gets a value indicating whether this LoadRequest downloads in parts.
  • Destination: Type: string
    • Gets the path to the download file.
  • TempDestination: Type: string
    • Gets the path to the temporary file created during the download process.
  • Progress: Type: Progress<float>
    • Gets the progress of the download process.
  • override Exception: Type: Nullable<AggregateException>
    • Gets the AggregateException that contains the exceptions thrown during the request.
  • override AttemptCounter: Type: int
    • Inherits from the base class.
  • override Task: Type: Task
    • Inherits from the base class.

Methods:

  • LoadRequest: Type: Constructor
    • Initializes a new instance of the LoadRequest class. Throws an IndexOutOfRangeException when the start of the range is greater than or equal to the end of the range. Throws a NotSupportedException when the start of the range is not null and the write mode is set to append.
  • override Start: Type: void
    • Starts the LoadRequest if it hasn't started or is paused.
  • override Pause: Type: void
    • Pauses the LoadRequest.
  • override Cancel: Type: void
    • Cancels the LoadRequest.
  • override Wait: Type: void
    • Blocks the current thread until the LoadRequest completes execution.
  • override Dispose: Type: void
    • Releases all resources used by the LoadRequest.
  • async StartRequestAsync: Type: Task
    • Asynchronously starts the request.
  • protected override async RunRequestAsync: Type: Task<RequestReturn>
    • Executes the request asynchronously.
  • private CreateDirectory: Type: void
    • Creates the directories specified in the options and sets them to the options.
  • private CreateRequest: Type: void
    • Creates the GetRequest based on the options provided.
  • private CreateChunk: Type: GetRequest
    • Creates a chunk of the GetRequest with the specified index and options.
  • private OnStateChanged: Type: void
    • Handles the state change of the request.
  • private OnFailure: Type: void
    • Handles the failure of the request.
  • private OnInfosFetched: Type: void
    • Handles the fetching of information from the GetRequest.
  • private async CheckPartFile: Type: void
    • Checks the part file and loads its information if it exists. It also handles file creation based on the write mode.
  • private ExcludedExtensions: Type: void
    • Checks if the provided content extension is in the list of excluded extensions. If it is, an exception is added and the failure handler is invoked.
  • private async OnCompletion: Type: void
    • Handles the completion of the request. If the request is chunked, it starts merging the chunks. If the request is not chunked, it moves the temporary file to the destination.
  • private TempToDestination: Type: void
    • Transfers the temporary file to the final destination.
  • private ClearOnFailure: Type: void
    • Resets the failure state of the request and deletes temporary files if necessary.