Coder Social home page Coder Social logo

lorddev / utilities Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 2.0 10.24 MB

Multipurpose universal utilities library so you don't have to write your own utils for every project. Includes extensions, encapsulation of logging and encryption, basic datareader-to-POCO mapping, a mailer throttle, and strongly-typed API callers.

License: GNU General Public License v3.0

C# 99.13% PowerShell 0.87%
logging encryption data-access-layer distance-matrix-api utilities c-sharp

utilities's Introduction

devlord utilities

A useful class library for universal utilities like encryption, sending emails, and consuming RESTful APIs.

Master Develop NuGet
Build status Build status NuGet Package

To install Devlord.Utilities, run the following command in the Package Manager Console:

PM> Install-Package Devlord.Utilities

Or from the command-line:

dotnet add package Devlord.Utilities

Feature Summary

  • .NET Core compatibility
  • System.Threading.Timers service clocks
  • Email throttling to help you avoid being suspended by your ISP
  • Generic HTTP API wrappers
  • Two-way AES encryption
  • "Micro-ORM" DataReader mapper for when using a full-featured ORM would be overkill

More details below, but for even more details, see the project wiki.

Service Timers

We've provided 3 types of timers for back-end services to execute operations

  • At a certain time
  • At a certain regular interval
  • Continuously, repeating an action as soon as the previous action is complete

ApiCall

The ApiCall class wraps the .NET HttpClient, and returns a deserialized object using Generics. It also features a Dictionary for query parameter input. The WebApiCall subclass will build your endpoint for ASP.NET MVC Web API based on the supplied controller, action, and id as input parameters.

Distance API

POCO classes for accessing the Google Maps distance API.

Usage with a custom JSON contract resolver that converts the Google JSON property names to POCO object properties.

    const string BaseUri = "https://maps.googleapis.com/maps/api/distancematrix/json";

    using (IApiCall client = new ApiCall(BaseUri,
            new JsonSerializerSettings { ContractResolver = new UnderscoreContractResolver() }))
    {
        client.QueryParams.Add("sensor", "false");
        client.QueryParams.Add("origins", "95969");
        client.QueryParams.Add("destinations", "95928");
        IApiResult<dynamic> result = client.Execute<DistanceResults>();
    }

DataManager

A handy generic DataManager abstract base class for your business layer that serves to enforce a CRUD contract between your business entities and your data layer. Useful for pagination as well.

Mailbot

A multithreaded SMTP queued mail sender, has a configurable throttle for mail frequency sent by a single account.

Configuration

{
  "Devlord.Utilities": {
    "GoogleMapsApiKey": "",
    "MailSettings": [
      {
        "Name": "Gmail",
        "SmtpServer": "mail.google.com",
        "SmtpPort": 587,
        "SmtpPassword": "",
        "MaxPerMinute": 500,
        "MaxPerHour": 500,
        "MaxPerDay": 500
      }
    ]
  }
}

Crypt

Bidirectional encryption methods useful for storing credit cards or encrypting passwords or API keys to save in a project's configuration files. (Not recommend for use with user's site credentials as those should use one-way encryption.)

DRMapper

Allows mapping of an IDataReader to POCO classes using reflection. It's faster than you might expect.

Pagination

    var query = from a in context.Addresses where a.IsActive select a;
    var results = query.GetPage(pageNumber, pageSize); 

Contributing

Yes, please!

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Contact lorddev on GitHub or @[email protected] on Mastodon.

utilities's People

Contributors

dependabot[bot] avatar gitter-badger avatar lorddev avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

utilities's Issues

What do we do about config.json files served from the web?

Historically, web.config is something that you can't download from the root of someone's website because IIS protected it. You couldn't get their connection strings or SMTP passwords or API keys out of it, for example. Is there a mechanism for protecting settings.json files? Because *.json is just JavaScript. Chances are it will be served in plaintext if someone types in the file name correctly.

Updates to Encryptamajig per earlier notes

Many years ago, I wrote a note to the original dev:

My next recommendation, at least for this fork, would be to change it into a class that's not static, so that we can reference some of the parameters as private fields instead of passing them from function to function. I also think it might help to have it work as a sort of singleton so that once the key/salt/iv bytes were initialized they wouldn't have to be recalculated for every operation. This would help improve performance for larger-scale encryption operations.

Retool the logging feature

Elmah isn't compatible with .NET Core. The Logger class was basically a wrapper for Elmah with a fallback. We need to make it more robust, and perhaps create our own display page similar to elmah.axd.

ApiCall formatting issue

The format setting in ApiCall.cs is based on whether the Payload is of type string vs a custom class. This means if you are making a simple GET call without a body and you want an XML response to be parsed properly, you have to set the Payload value to a string as a workaround. Fix will be to allow the format to be specified via a separate property.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.