🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

GlobalShared.CommonUtils.Library

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

GlobalShared.CommonUtils.Library

Common Utilities Used For Project. 1.The Utils class offers helper functions for string manipulation, data conversion, configuration retrieval (Appsettings and Web.Config), encryption (SHA-256) and MD5, formatting (currency, date), and standardized response handling. 2.The RestExtension class extends HttpClient, providing async methods for GET, POST, and PATCH requests. It handles headers, request creation, response deserialization, and error handling via ApiResponse. It supports JSON, lists, and binary data (PDFs) with cancellation tokens to prevent long-running requests. Potential improvements include strongly typed models, better logging, and optimized header management. 3.The Logs class manages structured logging for security (SIEMLogs), exceptions, and API requests. It dynamically creates log files, ensures directory existence, sets access permissions, and timestamps entries for monitoring, debugging, and auditing. 4.DataServiceUtils provides async methods for executing SQL queries using SqlConnection. It includes GetScalarAsync for fetching a single value and ExecuteNonQueryAsync for non-query commands, both supporting optional SQL parameters. It ensures resource management and preserves exception stack traces, but CommandTimeout = 0 may cause indefinite waits. 5.MongoDataServiceUtils is a utility class that provides asynchronous CRUD operations for MongoDB. It includes methods for inserting (InsertDocumentAsync), updating (UpdateDocumentAsync), retrieving (GetDocumentsAsync), and deleting (DeleteDocumentAsync) documents based on filter criteria. Additionally, it offers a synchronous method (CountDocuments) to count documents in a collection. This class simplifies MongoDB interactions by providing reusable and efficient database operations.

4.0.10
NuGet
Version published
Maintainers
1
Created
Source

Utils Class :- The Utils class is a helper utility that provides commonly used functions for various operations, including string manipulation, data type conversion, configuration retrieval, encryption, and response mapping. It offers methods for quoting strings and dates, checking for null or blank values, and converting strings to different data types such as integers, booleans, dates, decimals, floats, and longs with default values. Additionally, it retrieves application settings from appsettings.json and the configuration manager, ensures security through SHA-256 hashing and MD5,and formats data, such as currency values and date conversions. The class also standardizes response handling by creating structured response objects with status, descriptions, and error messages.

RestExtension Class:- The RestExtension class is a static utility that extends HttpClient, providing various asynchronous methods for making HTTP requests such as GET, POST, and PATCH. It simplifies API calls by handling request creation, adding headers dynamically, and managing response deserialization. Each method includes a cancellation token to prevent long-running requests from blocking execution. Error handling is built-in, returning a standardized ApiResponse object with status codes and messages. The class supports different response formats, including JSON objects, lists, and binary data (e.g., PDFs).Potential improvements include using strongly typed models for deserialization, better exception logging, and optimized header management with AuthenticationHeaderValue.

Logs Class:- The Logs class is a utility for logging different types of events, such as security incidents (SIEMLogs), exceptions (ExceptionLogs), and API requests (APIRequestLogs). Each method dynamically creates a log file based on the method name and date, ensuring the necessary directories exist before writing logs. It also sets access permissions for the log files and records log entries with timestamps in a structured format. This class helps in monitoring, debugging, and auditing application activity by maintaining detailed logs.

DataServiceUtils Class :- The DataServiceUtils class provides asynchronous utility methods for executing SQL queries using SqlConnection and SqlCommand. It includes two variations of the GetScalarAsync method, which retrieve a single value from the database�one with SQL parameters and one without. Similarly, the ExecuteNonQueryAsync method is available in two versions: one for executing non-query SQL statements such as INSERT, UPDATE, and DELETE without parameters and another that supports SQL parameters. The class ensures proper usage of using statements to manage SqlCommand resources efficiently. Additionally, exception handling uses throw; instead of throw ex; to preserve the original stack trace. However, setting sqlCommand.CommandTimeout = 0; may cause indefinite waits, and it is advisable to define a reasonable timeout to avoid performance issues.

MongoDataServiceUtils Class :- The MongoDataServiceUtils class that provides asynchronous CRUD operations for MongoDB. It includes methods for inserting (InsertDocumentAsync), updating (UpdateDocumentAsync), retrieving (GetDocumentsAsync), and deleting (DeleteDocumentAsync) documents based on filter criteria. Additionally, it offers a synchronous method (CountDocuments) to count documents in a collection. This class simplifies MongoDB interactions by providing reusable and efficient database operations.

Keywords

BhukyaSandhya

FAQs

Package last updated on 18 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts