Giter Site home page Giter Site logo

alexreich / rulesengineeditor Goto Github PK

View Code? Open in Web Editor NEW
371.0 17.0 80.0 132.65 MB

Editor for Microsoft RulesEngine - Blazor UI library intended for integration in Web or Desktop

Home Page: https://github.com/alexreich/RulesEngineEditor

License: Creative Commons Attribution 4.0 International

HTML 42.28% CSS 8.67% C# 49.06%
rules-engine rules-engine-editor blazor-component rules workflow engine expression-evaluator

rulesengineeditor's Introduction

Rules Engine Editor

RulesEngineEditor Editor for Microsoft Rules Engine - Blazor UI library intended for integration in Web or Desktop
CC BY 4.0

Animation of Rules Engine Editor Demo

Overview

Rules Engine Editor is a library/NuGet package for use with Microsoft Rules Engine which itself is a package for abstracting business logic/rules/policies out of a system.

Installation

To install this library, download the latest version of NuGet Package from nuget.org.

How to use it

There are several ways to populate workflows for the Rules Engine Editor as listed below.

Rules are based on the Microsoft Rules Engine schema definition and can be stored in anything deemed appropriate like Azure Blob Storage, Cosmos DB, Azure App Configuration, Entity Framework, SQL Servers, file systems etc. For RuleExpressionType LamdaExpression, the rule is written as a lambda expressions.

The Rules Engine Editor can also use a format for Input Rule Parameters based on the schema defintiion and can likewise be stored as the aforementioned workflow schema. Input Rule Parameters allow the seeding of arbitrary input data to be used in the Rules Engine. Consider Input Rule Parameters like interactive "unit tests" which allow for "What-If" type analysis.

Live Demo

WebAssembly

https://alexreich.github.io/RulesEngineEditor

This can also be installed as a standalone PWA and used offline.

With Sample Data

https://alexreich.github.io/RulesEngineEditor/demo

Features

Usage

Simple:

<RulesEngineEditorPage />

Complex:

<RulesEngineEditorPage EditorRulesEngine="re" @bind-Workflows="Workflows" InputJSON="@Inputs" />

Complex (EF Supported):

<RulesEngineEditorPage EditorRulesEngine="re" @bind-WorkflowDatas="WorkflowDatas" InputJSON="@Inputs" />

Install

NuGet

Blazor WebAssembly / Client-side Blazor

  1. In Program.cs add
builder.Services.AddRulesEngineEditor();
  1. In _Imports.razor
@using RulesEngineEditor.Pages
  1. Add relevant styles, either add css included to site.css or inside the <head> element of wwwroot/index.html with the following statements:
<link href="_content/RulesEngineEditor/css/reeditor.css" rel="stylesheet" />
<link href="_content/RulesEngineEditor/css/dragdrop.css" rel="stylesheet" />

Server-side Blazor

  1. In Startup.cs add
services.AddRulesEngineEditor();
  1. In _Imports.razor
@using RulesEngineEditor.Pages
  1. Add relevant styles, either add css included to site.css or inside the <head> element of Pages/_Host.cshtml with the following statements:
<link href="_content/RulesEngineEditor/css/reeditor.css" rel="stylesheet" />
<link href="_content/RulesEngineEditor/css/dragdrop.css" rel="stylesheet" />

Entity Framework Demo Setup

  1. Ensure SQL Express is set up
    c:\> sqllocaldb
  2. Create an instance of the test database
    >sqllocaldb c "RulesEngineEditorDB" -s
  3. Open Package Manager Console (View > Other Windows > Package Manager Console)
    Add-Migration init
    Update-Database

Suppress top level Buttons

Any/all of the following menu buttons can explicitly disabled:
NewWorkflows, DownloadWorkflows, ImportWorkflows, AddWorkflow, NewInputs, DownloadInputs, ImportInputs, AddInput
See DemoEF for example usage.

What's Next

  • More UI Updates - large field data (rule name, success, expression) autosize?
  • Pretty JSON Expression Handling - Prism Live?
  • PDF Printing, XSLX Export
  • Support for more types (ActionInfo, RuleActions, etc.)
  • Continued synchronization with releases of Microsoft Rules Engine
  • Blazor Desktop

This work is licensed under a Creative Commons Attribution 4.0 International License.

CC BY 4.0

❤️ Sponsor

rulesengineeditor's People

Contributors

alexreich avatar chrisdrobison avatar luohuarain avatar mongeon avatar rose-pace 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  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  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  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  avatar  avatar  avatar  avatar  avatar  avatar

rulesengineeditor's Issues

Inputs for "non human" input should disable browser auto correction behavior

Pretty much every input field in this editor component should use the following HTML attributes to disable unwanted browser "autocorrect" behavior.

autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"

This should prevent things like the red squiggle "spelling" errors and automatic capitalizations done by various browsers.

Checkbox UI Broken

Hello,

It took me awhile to figure this out, but if you are using Bootstrap 5 and above with RulesEngineEditor the checkbox for enabled/disabled UI is broken. It doesn't show the check, it's just an empty box. If you downgrade to Bootstrap 4.3.1 it works.

Thanks
-Cameron

Cannot add more than 1 workflow in EF demo

Hi Alex, I don't know if this is intentional or not, but because of this phrase in RulesEngineEditorPage.razor it is not possible to import a second rule.

private void WorkflowJSONChange()
{
workflowJSONErrors = "";
try
{
var workflows = JsonSerializer.Deserialize<List>(WorkflowJSON, jsonOptions);

        if (!WorkflowService.Workflows.Any())
        {
            WorkflowService.Workflows = workflows;
        }
        else
        {
            Mapper.Map<WorkflowData>(workflows, WorkflowService.Workflows);
        }

I would like to know your thoughts on this.

Support action workflows

See #11, apparently action workflows are not supported yet.

Would also love to see support for action workflows.

The current thread is not associated with the renderer's synchronization context

I have server side blazor project where I am using server side rules engine editor. when I deployd this application on server, time to time I am getting error: 'The current thread is not associated with the renderer's synchronization context'. I think that problem is for StateHasChanged() is called withoud
'InvokeAsync'. It should be called like that: 'InvokeAsync(()=>{ StateHasChanged() })'. If there is some another better solution for this issue, someone help me pls.

Breaking changes in RulesEngine 4.0.0

You're probably aware, there are breaking ctor changes in RulesEngine v4.0.0 while your NuGet library only asks for RulesEngine >= 3.5.0. Reverting back to 3.5.0 resolved my runtime issues.

All changes get wiped out when databinding workflows

I've downloaded this project and ran both the Web Assembly and Server demo apps and received the same issue. No changes happen when the add rules button is clicked. If I add a new workflow and add a name that new workflow is deleted. If I edit the name of the current workflow it is reverted. Any changes to existing rules are likewise instantly reverted.

When I debug the code I can see that whenever the Workflows property written to it is always writing the original workflow object that was originally bound to it. This appears to be different than the online demo where data can be changed.

accessibility

Can you share with us the current level of accessibility of this library?

Is it WCAG 2.1 compliant?

How save workflows in story

So, I want to make CRUD operations on workflows. I've installed already editor, created ef core dbcontext class configured
but when I add migration there is an error
image

image
Also, I couldn't find a way to make some "Save" button and handle workflows on click
So, which one could I save to database Workflow or WorkflowData?

WorkflowsSaved and WorkflowsChanged send stale data without changes

Any changes I make in the editor before I hit save are ignored and it just saves what was in the page originally. The file metadata shows that it has been overwritten but the changes I make aren't persisted.

This is the case no matter if I use the Workflow[] passed into my save method or the one I bound to the RulesEngineEditorPage with @bind-Workflows. No matter if I use WorkflowsChanged="Save" or WorkflowsSaved="Save" it doesn't work right.

The only way to get your changes to workflows back out of the editor is the download button.

@using Newtonsoft.Json
@using RulesEngine.Models
@using System.Runtime.Serialization
@using System.Security.Cryptography
@using System.Text
@using Azure.Storage.Blobs.Models
@inject AppConfig AppConfig

<p>Last Saved: @lastSaved</p>
<RulesEngineEditorPage @bind-Workflows=Workflows MenuButtons=@menuButtons WorkflowsSaved="Save" />

@code {
    DateTime? lastSaved;
    private BlobStorageService blobStorageService;
    private byte[] startingHash;
    
    private Workflow[] Workflows { get; set; }
    private List<MenuButton> menuButtons = new List<MenuButton>()
    {
        new MenuButton("NewWorkflows"),
        new MenuButton("DownloadWorkflows"),
        new MenuButton("ImportWorkflows"),
        new MenuButton("AddWorkflow"),
        new MenuButton("SaveWorkflow")
    };

    protected override async Task OnInitializedAsync() {
        string fileContents;
        blobStorageService = new BlobStorageService(Environment.GetEnvironmentVariable("CONNECTION_STRING"));
        await using Stream blobStream = await blobStorageService.GetBlobAsync("json", AppConfig.RulesJsonFilename);
        using (var streamReader = new StreamReader(blobStream)) {
            fileContents = await streamReader.ReadToEndAsync();
        }
        var workflowList = JsonConvert.DeserializeObject<List<Workflow>>(fileContents); 

        BlobProperties properties = await blobStorageService.GetBlobPropertiesAsync("json", AppConfig.RulesJsonFilename);
        lastSaved = properties.LastModified.LocalDateTime; 
        startingHash = properties.ContentHash;
        Workflows = workflowList.ToArray();
    }
    
    protected async Task Save(Workflow[] workflows) {
        Workflows = workflows; // I've tried it with this line commented out for no difference
        string serializedWorkflows = JsonConvert.SerializeObject(Workflows, Formatting.Indented);
        Stream memoryStream = new MemoryStream(Encoding.Default.GetBytes(serializedWorkflows));
        byte[] newChecksum = MD5.HashData(memoryStream);
        if (newChecksum.SequenceEqual(startingHash)) {
            Console.WriteLine("Content is unchanged!!!!");
            byte[] paramChecksum = MD5.HashData(new MemoryStream(Encoding.Default.GetBytes(JsonConvert.SerializeObject(workflows, Formatting.Indented))));
            Console.WriteLine("is the param also the same? " + paramChecksum.SequenceEqual(startingHash));
            throw new TaskCanceledException();
        } 
        Task<BlobContentInfo> saveTask = blobStorageService.UploadBlobAsync("json", AppConfig.RulesJsonFilename, memoryStream);
        BlobContentInfo info = await saveTask;
        if (saveTask.IsFaulted) {
            await Console.Error.WriteLineAsync($"Failed to Save! {saveTask.Exception}");
        }
        else {
            Console.WriteLine($"Save attempt {saveTask.Status}");
            lastSaved = info.LastModified.LocalDateTime;
            await InvokeAsync(StateHasChanged);
        }
    }

After saving a few changes, and Console output is :

Content is unchanged!!!! 
is the param also the same? True

If you comment out the if block with the checksum code and attempt to save changes, the lastSaved date updates, but the workflows are unchanged.

Download button doesnt work

Clicking download in workflows tab, in any browser doesnt do anything (only if i edit some rules, then i can download it).
Although download for "Input rule parameters" works as expected out of the box, with default values.

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.