Code Monkey home page Code Monkey logo

srktoolkit's Introduction

SrkToolkit

Here goes another set of libraries to help out: SandRock's toolkit. Separated into a few assemblies to avoid loading too much stuff in your app.

License: Apache License Version 2.0

Branches

  • release/2.0 current major release (WIP)
    • dev/v2.0.0 current development effort
  • release/1.2 previous release (hotfixes only)
  • release/1.1 old release (hotfixes only)

Assemblies and nugets

v2.0 (netstandard2.0 and AspNetCore, keep partial support for net46) - "near stable"

Keep support for latest .NET Framework and MVC5, full support for AspNetCore.

WARNING: work is in progress

Assembly FX Nuget Remark
SrkToolkit.Common net46, netstandard2.0, net7.0 nuget prerelease
SrkToolkit.Domain net46, netstandard2.0, net7.0 nuget prerelease
SrkToolkit.Web.AspMvcCore2 netstandard2.0, net7.0 nuget prerelease
SrkToolkit.Domain.AspMvcCore2 netstandard2.0, net7.0, nuget prerelease

v1.2 (support for net40 and MVC 4, net45 and MVC 5, netstandard2.0) - "stable"

Keep support for many .NET Framework and MVC5, growing support for newer .NET.

Assembly FX Nuget Remark
SrkToolkit.Common net40, net45, netstandard2.0 nuget
SrkToolkit.Domain net40, net45, netstandard2.0 nuget
SrkToolkit.Web (for ASP MVC 3) net40 nuget mvc4
SrkToolkit.Web (for ASP MVC 4) net45 nuget mvc5
SrkToolkit.Domain.AspMvc3 net40, nuget mvc4
SrkToolkit.Domain.AspMvc4 net45 nuget mvc5
SrkToolit.WebForms net40

v1.1 (support for net40 and MVC 4, net45 and MVC 5) - "obsolete"

Support for many .NET Framework and MVC4/MVC5.

Assembly FX Nuget Remark
SrkToolkit.Common net40, net45 nuget
SrkToolkit.Common.Unsafe net40
SrkToolkit.Domain net40, net45 nuget
SrkToolkit.Web (for ASP MVC 3) net40 nuget mvc4
SrkToolkit.Web (for ASP MVC 4) net45 nuget mvc5
SrkToolkit.Domain.AspMvc3 net40, nuget mvc4
SrkToolkit.Domain.AspMvc4 net45 nuget mvc5
SrkToolit.WebForms net40
SrkToolit.Xaml net40, wp70, wp71, sl4
SrkToolkit.Mvvm net40, wp70, wp71, sl4
SrkToolkit.Services net40, wp70, wp71, sl4

See all nuget packages

Content at-a-glance

extend the framework to write code faster

  • date manipulations, DataAnnotations
  • string manipulations (trim with suffix, AsNullIfEmpty(), AddHtmlLineBreaks(), TrimTextToWord(), HtmlParagraphizify(), RemoveDiacritics(), MakeUrlFriendly())
  • NameValueCollection.ToDictionary()
  • ObservableCollection: AddRange(IEnumerable<T>), RemoveAll(Func<T, bool>)
  • StopwatchExtensions: fluent methods to avoid writing many lines of code when using it
  • email address decomposition (account, tags, local part, domain part) and validation
  • no fancy stuff like StringExtension.IsEmpty())

And more...

Request-Result-ErrorCode pattern

SrkToolkit.Domain contains a few classes to represent API or domain operations.

Use the rrr code snippet to obtain a set of types for an operation.

extensions for ASP MVC

  • date and time display helpers (based on timezone, standard formats, tag...)
  • PageInfo is the one object to set your page title, description, meta tags, opengraph values...
  • fixed AuthorizeAttribute to return a "HTTP 403 Forbidden" instead of 401 auth page when already authenticated
  • 1-line error handling code for customized http-accept-aware error pages
  • wrapper for tempmessages to show nice informations, warnings and errors (extension methods for both controllers and view)
  • DecimalModelBinder with "friendly" decimal separator detection (useful for stupid cultures like French)
  • OpenGraph extensions to easily ouput tags in your page
  • BaseSessionService class that allows auto-populating new and expired sessions in a lazy way
  • ResultService class that allows oupting error pages from actions
  • Html.DescriptionFor() to show the Description property from the [DisplayAttribute(Name = "", Description = "<desc here>")]
  • Html.Submit() 'cauz it's missing
  • UrlHelper.SetQueryString(string url, params string[] keysAndValues) to add/change query strings from a raw url
  • JsonNetResult: ActionResult class that allows you to specify your favorite JSON serializer
  • HttpRequest: .IsXmlHttpRequest(), .IsUrlLocalToHost(url), IsPost()...

And more...

Signed code

All assemblies are signed. The real key is not in source control; I keep it to ensure my builds are only made by myself (yes, I know that is not 100% true).

The latest build can be found here: https://www.nuget.org/packages?q=Tags%3A%22srktoolkit%22

Want unsigned assemblies? Get the code, remove the option and build.

srktoolkit's People

Contributors

dependabot[bot] avatar pydez avatar sandrock avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

srktoolkit's Issues

Use new csproj format, drop old things, target AspMvcCore

Questions and decisions

v1 and v2 maintenance

  • Use two git branches?

    • (+) dual changes: allows cherry-picking
  • Use two solutions in one git branch?

    • (-) dual changes: copy code or use complex file links and conditional symbols
  • decide how:

    • branch release/v1.1 to maintain v1.1
    • branch release/v1.2 to maintain v1.2
    • branch release/v2.2 to maintain v2.0
    • branch dev/vX/FEATURE for development
    • remove branch master
    • change solution name to avoid IDE craziness

Target frameworks for v2

  • SrkToolkit.Common should have maximum framework compatibility, because there is not much framework-specific code.
    • net40/net45/net46 (for FX aficionados)
    • net6.0/net7.0 (why? / why not?)
    • netstandard2.0 (for whatever else)
  • SrkToolkit.Domain should use the same support as SrkToolkit.Common
  • AspMvc4
    • SrkToolkit.Web.AspMvc4 -> drop support in v2 (old stuff -> use v1)
    • SrkToolkit.Domain.AspMvc4 -> drop support in v2 (old stuff -> use v1)
  • AspMvc5
    • SrkToolkit.Web.AspMvc5 -> drop support in v2 (old stuff -> use v1)
    • SrkToolkit.Domain.AspMvc5 -> drop support in v2 (old stuff -> use v1)
  • AspNetCore2
    • SrkToolkit.Web.AspNetCore2 -> added support in v2
    • SrkToolkit.Domain.AspNetCore2 -> added support in v2

Async support for WebDependency

Some WebDependency should be loaded using the new async attribute. The following code should generate a <script async> tag.

return new WebDependency("BigScript")
{
    new WebDependencyFile("/Scripts/BigScript.js", WebDependencyFileType.Javascript)
    {
        Async = true,
    },
};

Do not put extension methods into the System namespaces

Invading the System namespaces should not continue. But what namespace should we use?


Use a prefix notation like this?

  • System -> SrkToolkit.System
  • System.Collections -> SrkToolkit.System.Collections
  • ...

(-) This may lead to a lot of new using statements.
(+) Fine-grained choice of extensions to use


Or use a single namespace? SrkToolkit.Extensions?

(-) This may lead to a binary choice of using all referenced toolkits or none.
(+) Binary-grained choice of extensions to use


Or put extensions in each nuget's namespace? SrkToolkit.Common, SrkToolkit.Web...

(+) Coarse-grained choice of extensions to use
(+) This may lead to an acceptable quantity of new using statements.

Use params for string.ContainsAny()

Current extension method:

bool ContainsAny(IEnumerable<string> values, StringComparison comparisonType);

Desired overloads:

bool ContainsAny(StringComparison comparisonType, params string[] values);
bool ContainsAny(StringComparison comparisonType, params char[] values);

Fate of thing in v2

These things require specific change, decide what to do with them

  • SrkToolkit.Services
    • keep AppEventBus, ApplicationServices, FileTraceListener, TraceEx
  • SrkToolkit.Mvvm
    • drop support
  • SrkToolkit.Xaml
    • drop support
  • SrkToolkit.Common
    • TODO: list things here
    • Collections.DictionaryWrapper<TKey, TValue>: preserved
    • DataAnnotations.CultureInfoAttribute: upgrade and preserve
    • DataAnnotations.DateRangeAttribute: upgrade and preserve
    • DataAnnotations.EmailAddressExAttribute: upgrade and preserve
    • DataAnnotations.PhoneNumberAttribute: upgrade and preserve
    • DataAnnotations.TimezoneAttribute: upgrade and preserve
    • DataAnnotations.TwitterUsernameAttribute: upgrade and preserve
    • CultureInfoHelper: upgrade and preserve
    • Internals.Nothing: preserved
    • IO.RecursiveDelete:
      • preserved
      • requires testing
      • needs an async method
    • System.DateTimePrecision: preserved, namespace must change (#21)
    • System.SrkArrayExtensions: preserved, namespace must change (#21)
    • System.SrkDateTimeExtensions: preserved, namespace must change (#21)
    • System.SrkExceptionExtensions: preserved, namespace must change (#21)
    • System.SrkStringExtensions: preserved, namespace must change (#21)
    • System.SrkTimeZoneInfoExtensions: preserved, namespace must change (#21)
    • System.SrkStringTransformer: preserved, namespace must change (#21)
    • System.Collections.SrkIDictionaryExtensions: preserved, namespace must change (#21)
    • System.Collections.Generic.SrkIDictionaryExtensions: preserved, namespace must change (#21)
    • System.Collections.Generic.SrkIListExtensions: preserved, namespace must change (#21)
    • System.Collections.ObjectModel.SrkObservableCollectionExtensions: preserved, namespace must change (#21)
    • System.Collections.Specialized.SrkNameValueCollectionExtensions: preserved, namespace must change (#21)
    • System.Diagnostics.StopwatchExtensions: preserved, namespace must change (#21)
    • Testing.Assert: preserved
    • Threading.Tasks.TaskEx: preserved
    • Validation.EmailAddress: preserved
    • Validation.Validate: preserved
    • CompositeDisposable: preserved
    • DisposableOnce: preserved
    • EnumTools: preserved
    • RetryLogic: preserved, now obsolete
    • StringComparerEx: preserved
    • StringReplacer: preserved
  • SrkToolkit.Domain
    • preserve everything
  • SrkToolkit.Web.AspNetCore2
    • TODO: list things here
    • Fakes/BasicHttpContext: does not compile, seems useless with AspNetCore2?
    • Fakes/BasicHttpSessionState: does not compile, seems useless with AspNetCore2?
    • Filters/AuthorizeAttribute: does not compile, seems useless with AspNetCore2?
    • HttpErrors/*: does not compile, evaluate if useful with AspNetCore2?
    • Models/HttpErrorModel: looks ok, evaluate if useful with AspNetCore2?
    • Models/TempMessage: ok
    • Mvc/DecimalModelBinder: does not compile, migrate!
    • Mvc/IntegerModelBinder: does not compile, migrate!
    • Open/Open*: looks ok,
    • Open/PageInfo*: looks ok,
    • Services/HttpBaseSessionServiceSource, BaseSessionService: evaluate if useful with AspNetCore2?
    • Services/ResultServiceBase, ResultService: evaluate if useful with AspNetCore2?
    • SrkControllerExtensions: does not compile, migrate!
    • SrkMvcCollectionExtensions: looks ok, change namespace
    • SrkTagBuilderExtensions: does not compile, migrate! change namespace
    • SrkUrlHelperExtensions: looks ok, change namespace
    • SrkViewExtensions: does not compile, migrate! change namespace
    • JsonNetResult: evaluate if useful with AspNetCore2?
    • SrkHtmlExtensions: does not compile, migrate!
    • SrkHttpApplication: seems useless with AspNetCore2?
    • SrkHttpContextExtensions: does not compile, migrate!
    • SrkHttpRequestExtensions: does not compile, migrate!
    • SrkTempDataDictionaryExtensions: compiles, does it work?
    • WebDependency, WebDependencyFile, WebDependencies, WebDependenciesExtensions: does not compile, evaluate if useful with AspNetCore2
    • review namespaces
  • SrkToolkit.Domain.AspNetCore2
    • TODO: list things here
    • SrkDomainControllerExtensions: does not compile, migrate!

Loose nuget cross references

The projects use <ProjectReference> elements. This causes nuget packages to reference strict version conditions.

Try to use this solution to allow loose references between packages.

Assert.Contains should cite the search string in the exception Message

What we see in the VS Test Explorer:

Test Outcome:   Failed
Test Duration:  0:00:00.1276359

Result Message: 
Test method threw exception: 
System.ArgumentException: Searched string was not found
Result StackTrace:  
at SrkToolkit.Testing.Assert.Contains(String search, String value) in NET4.SrkToolkit.Common\Testing\Assert.cs:line 159

I would be nice to also see the string that was searched.

Make WebDependency use relative site URLs (~/)

Current behavior

new WebDependencyFile("/Scripts/common.js", WebDependencyFileType.Javascript) renders as src="/Scripts/common.js"; which is OK but does not allow to put the app in a site subfolder.

new WebDependencyFile("~/Scripts/common.js", WebDependencyFileType.Javascript) renders as src="~/Scripts/common.js"; which is wrong.

Desired behavior

new WebDependencyFile("/Scripts/common.js", WebDependencyFileType.Javascript) should not change.

new WebDependencyFile("~/Scripts/common.js", WebDependencyFileType.Javascript) should render as src="/subfolder/Scripts/common.js"; where /subfolder if computed using the base app url.

Ability to build the solution on Linux

This configuration (firefly) fails to build the solution

"/home/sandrock/dev/github/sandrock/srktoolkit-v2/Sources/SrkToolkit.Common/SrkToolkit.Common.csproj" (build target) (2) ->
(GetReferenceAssemblyPaths target) -> 
/usr/lib/mono/msbuild/Current/bin/Microsoft.Common.CurrentVersion.targets(1232,5): error MSB3971: The reference assemblies for ".NETFramework,Version=v7.0" were not found. You might be using an older .NET SDK to target .NET 5.0 or higher. Update Visual Studio and/or your .NET SDK.

"/home/sandrock/dev/github/sandrock/srktoolkit-v2/Sources/SrkToolkit.Domain/SrkToolkit.Domain.csproj" (build target) (1:2) ->
/usr/lib/mono/msbuild/Current/bin/Microsoft.Common.CurrentVersion.targets(1232,5): error MSB3971: The reference assemblies for ".NETFramework,Version=v7.0" were not found. You might be using an older .NET SDK to target .NET 5.0 or higher. Update Visual Studio and/or your .NET SDK.

"/home/sandrock/dev/github/sandrock/srktoolkit-v2/Sources/SrkToolkit.Common/SrkToolkit.Common.csproj" (build target) (2:2) ->
(ResolvePackageAssets target) -> 
/usr/lib/mono/msbuild/Current/bin/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1005: Assets file '/home/sandrock/dev/github/sandrock/srktoolkit-v2/Sources/SrkToolkit.Common/obj/project.assets.json' doesn't have a target for '.NETFramework,Version=v4.7.2'. Ensure that restore has run and that you have included 'net472' in the TargetFrameworks for your project.
dotnet sdk check
.NET SDKs:
Version      Status
----------------------------------------
2.2.207      .NET 2.2 is out of support.
3.1.120      .NET 3.1 is out of support.
6.0.113      Patch 6.0.115 is available.
7.0.102      Patch 7.0.104 is available.

Try out the newest .NET SDK features with .NET 8.0.100-preview.2.23157.25.

.NET Runtimes:
Name                          Version      Status
----------------------------------------------------------------------
Microsoft.NETCore.App         2.2.8        .NET 2.2 is out of support.
Microsoft.NETCore.App         3.1.20       .NET 3.1 is out of support.
Microsoft.NETCore.App         6.0.13       Patch 6.0.15 is available.
Microsoft.AspNetCore.App      7.0.2        Patch 7.0.4 is available.
Microsoft.NETCore.App         7.0.2        Patch 7.0.4 is available.

Domain Result is missing error message localization capability

While most domain data is implemented in child classes (out out SrkToolkit), the result error messages are declared by SrkToolkit. These do not allow localization. Developers must implement on their side lang negociation in order to obtain localized error messages.

Can SrkToolkit.Domain be enhanced?

  • by defining request properties to set the desired lang, time zone, date format and more?
  • or by allowing multi lang error messages?
  • or any other way?

Release of v2.0.0 and nugets

EmailAddressExAttribute does not fill MemberNames

Validation attributes return a ValidationResult object in case of error. The result should contain a message and a member name.

The EmailAddressExAttribute does not specify the member names when an error is found.

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.