GithubHelp home page GithubHelp logo

lombiq / helpful-libraries Goto Github PK

View Code? Open in Web Editor NEW
27.0 11.0 27.0 2.02 MB

Orchard Core library / Orchard 1.x module with libraries that can be handy when developing for Orchard.

License: BSD 3-Clause "New" or "Revised" License

C# 99.14% HTML 0.86%
orchard orchard-cms orchard-module orchard-core

helpful-libraries's Introduction

Lombiq Helpful Libraries

Lombiq.HelpfulLibraries NuGet Lombiq.HelpfulLibraries.AspNetCore NuGet Lombiq.HelpfulLibraries.Cli NuGet Lombiq.HelpfulLibraries.Common NuGet Lombiq.HelpfulLibraries.LinqToDb NuGet Lombiq.HelpfulLibraries.OrchardCore NuGet Lombiq.HelpfulLibraries.OrchardCore.Testing NuGet Lombiq.HelpfulLibraries.Refit NuGet Lombiq.HelpfulLibraries.RestEase NuGet

About

Various useful libraries that can be handy when developing for .NET, ASP.NET Core, and Orchard Core, to be used from your own projects.

We at Lombiq also used this library for the following projects:

Do you want to quickly try out this project and see it in action? Check it out in our Open-Source Orchard Core Extensions full Orchard Core solution and also see our other useful Orchard Core-related open-source projects!

Note that this project has an Orchard 1 version in the dev-orchard-1 branch.

Documentation

Helpful Libraries consists of the following independent libraries (all in their own projects/packages). Use the one specific to your use-case, or most of them at once by depending on Lombiq.HelpfulLibraries.

Public APIs are always documented so please always read method comments.

Check out the Lombiq.HelpfulLibraries.Samples project for various examples in the form of an Orchard Core module.

Note: The Lombiq.HelpfulLibraries.sln file exists to provide centralized building of the independent library projects but otherwise you don't need to use it.

Contributing and support

Bug reports, feature requests, comments, questions, code contributions and love letters are warmly welcome. You can send them to us via GitHub issues and pull requests. Please adhere to our open-source guidelines while doing so.

This project is developed by Lombiq Technologies. Commercial-grade support is available through Lombiq.

helpful-libraries's People

Contributors

0liver avatar aaron-p avatar aracsibalint avatar aydine avatar barthamark avatar benedekfarkas avatar csuhi29 avatar deanmarcussen avatar demeszabolcs avatar dministro avatar domonkosgabor avatar dorraj07 avatar hishamco avatar i3undy avatar jtkech avatar luko6 avatar mzole avatar piedone avatar porgabi avatar psichorex avatar sarahelsaig avatar szilardcsere89 avatar thehydes avatar wasnk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

helpful-libraries's Issues

The existing field's DisplayName gets overwritten for no reason. (OSOE-474)

The ContentPartDefinitionBuilder<TPart>.WithField<TField>(...) extension method overwrites the DisplayName of an existing field.

public ContentPartDefinitionBuilder<TPart> WithField<TField>(
Expression<Func<TPart, TField>> fieldPropertySelector,
Action<ContentPartFieldDefinitionBuilder> configuration = null)
{
var property = ((MemberExpression)fieldPropertySelector.Body).Member;
var name = property.Name;
Builder = Builder.WithField(
name,
field =>
{
field = field.WithDisplayName(name).OfType(typeof(TField).Name);
configuration?.Invoke(field);
});
return this;
}

Expected behavior:
Keep the original DisplayName value if present.

Jira issue

The collection being enumerated is modified inside the `foreach` loop. (OSOE-605)

System.Collections.Generic.CollectionExtensions.RemoveAll(...) throws InvalidOperationException: 'Collection was modified; enumeration operation may not execute.'

/// <summary>
/// Removes every item <paramref name="collection"/> where <paramref name="predicate"/> returns <see
/// langword="true"/> or if it's <see langword="null"/>.
/// </summary>
public static void RemoveAll<T>(this ICollection<T> collection, Func<T, bool> predicate = null)
{
foreach (var item in collection)
{
if (predicate == null || predicate(item))
{
collection.Remove(item);
}
}
}

Exception:

image

Jira issue

Split the Orchard Core specific methods into its own project (OSOE-70)

We want to split up the main project and separate the .Net and Orchard Core extensions.

Create new projects:

  • Lombiq.HelpfulLibraries.Common
  • Lombiq.HelpfulLibraries.OrchardCore
  • Also see if a third Lombiq.HelpfulLibraries.AspNetCore makes sense.

The OC module should contain the following package references to ensure the projects using them won't have issues with tag helpers and the like:

  • OrchardCore.ContentManagement
  • OrchardCore.DisplayManagement
  • OrchardCore.ResourceManagement

Otherwise, remove all unnecessary package references. This might mean a switch to an *.Abstractions package instead of the implementation one.

The Lombiq.HelpfulLibraries project should remain and become an umbrella project that contains references to the others.

LinqQueryAsync throwing connection error if we setup Persist Security Info=False in connection string. (OSOE-801)

SQL login failed due to incorrect username and password, which was being thrown from the _session.LinqQueryAsync method. We investigated and discovered that the transaction.Connection.ConnectionString did not contain the password. As a workaround, we configured the Persist Security Info flag as true, which resolved the issue.

We received exceptions from Azure Application Insights, but no exceptions appeared on the local environment console.
image

Jira issue

Make it possible to replace content items with an unknown ID using recipes (OSOE-648)

Currently it's not possible to overwrite a content item with a recipe if its ContentItemId is unknown - for example if it was created from a recipe using "ContentItemId": "[js: uuid()]". We should include some recipe mechanism to get around this. Some ideas:

  1. Add a IGlobalMethodProvider that let's you find the ContentItemId from alias, e.g.
    "ContentItemId": "[js: idFromAlias('main-menu')]".
  2. Create a new recipe step that removes a content item by query.

I'm not sure if either of these is possible during setup, if the alias index may not be populated yet?

Jira issue

Create `InvokeAsync` extension methods for `Task` returning delegates

When calling something like await delegate.Invoke() on a Task returning delegate there is a danger that it might be a multicast delegate. If so, actually only the final method will be awaited on the method's invocation list and the rest will be fire-and-forget.

If we introduce matching InvokeAsync methods, then AsyncFixer will emit a warning wherever the stock Invoke methods are called, preventing this dangerous practice. Such a method should call the methods on the invocation list in series, like here.

Enable nullable reference types in the solution and evaluate code (OSOE-754)

Enabling nullable mode for the HL would make the code much safer and give us more confidence about where additional null checks are needed or not. It's also painful to implement abstract methods from HL that should be able to return null in a nullable enabled project because the IDE gets confused.

Also the codebase should be reviewed to guarantee that the methods only return null when it has a special meaning (e.g. in drivers) and to consider making the inputs as resilient as possible.

Jira issue

Change the OC package references to 1.8.0 instead of 1.8.2 (OSOE-846)

Based on @Piedone 's advice in OCC:

I think the OCC packages should always target the .0 minor version of the latest version; i.e., 1.8.0 in this case, so people can use the packages regardless of them being on 1.8.0, 1.8.1, 1.8.2, or 1.8.3 (currently they're forced to use at least 1.8.2). During development and testing though, we should use the very latest, if somehow this can be done.

This is not possible for the projects that use HL, specifically OrchardCore.Commerce.Inventory and OrchardCore.Commerce.ContentFields.

Once this is done, also update OCC's Directory.Packages.props as suggested here.

Jira issue

Updated for 1.10?

I downloaded the 1.10 branch for this module but I am getting a ton of build errors due to references not being correctly set, and I don't think it was updated to use Nuget?

Add source generator that reads a JSON value as a const string at compile time. (OSOE-819)

Disclaimer: I'm not sure if this is the right repo for this suggestion. I don't think we have done any source generators yet, so maybe it should be a new repo if we do this. The idea ties into node/npm but it's not dependent on Node Extensions.

Problem

When you include a vendor resource in OC, it's a good idea to include the version too, for the purpose of cache busting. For example

        _manifest
            .DefineScript(Library)
            .SetUrl(Vendors + "chart.js/Chart.min.js", Vendors + "chart.js/Chart.js")
            .SetVersion("2.9.4");

As you can see, the version here is just a raw string. It's derived from the matching "chart.js": "2.9.4", in package.json. Then later you update the package file and forget to update the matching version number in the resource manifest! It's a maintenance nightmare.

Solution

Create a source generator that creates a compile time constant. For instance:

[ConstantFromJson("ChartJsVersion", "package.json", "$..['chart.js']")]
public class ResourceManagementOptionsConfiguration : IConfigureOptions<ResourceManagementOptions>
{
    // ...
        _manifest
            .DefineScript(Library)
            .SetUrl(Vendors + "chart.js/Chart.min.js", Vendors + "chart.js/Chart.js")
            .SetVersion(ChartJsVersion);
    // ...
}

Here [ConstantFromJson(variableName, fileName, jsonPath)] would instruct the source generator to insert string constant called variableName and set its value to the first result in fileName that matches jsonPath. Then at compile time it will become private const ChartJsVersion = "2.9.4";. Of course, there should be a shortcut like [ValueFromNpm("chart.js")] as well.

I looked for existing projects, but this was the only thing vaguely similar.

Alternatives

You could mark the package.json an embedded file, then read & parse it rune time at every startup.
Just writing that sentence down made me feel ill.

Jira issue

Relative URL prefixed with /Admin in case of an admin controller action if [Route] attribute is used (OSOE-653)

The relative URL created by the TypedRoute.ToString() for a controller action where the controller has [Admin] attribute and the action has [Route] gets prefixed with /Admin. I think the expected result is the URL is not prefixed with /Admin.

public override string ToString()
{
var prefix = _isAdminLazy.Value ? "/Admin/" : "/";
var route = _routeLazy.Value;
var arguments = _arguments.Any()
? "?" + string.Join('&', _arguments.Select((key, value) => $"{key}={WebUtility.UrlEncode(value)}"))
: string.Empty;
return prefix + route + arguments;
}

For the following example, the relative URL will be: /Admin/SampleModule/Admin/Edit

[Admin]
public class AdminController : Controller
{
    ...

    [Route("SampleModule/Edit")]
    public async Task<IActionResult> Edit(string contentItemId, string returnUrl)
    {
        ...
    }
}

Jira issue

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.