2023.1:Scripting Setup

From Grooper Wiki
Revision as of 15:04, 22 November 2023 by Randallkinard (talk | contribs)

This article seeks to elucidate the requirements for setup of remote scripting in Grooper 2023.1.

About

.Net scripting is a fantastic way to expand the capabilities of Grooper but has historically been a procedure that was inherently tied to the machine that Grooper is installed on.

With Grooper 2023.1 scripting can now be done on a remote computer, compiled, and thanks to the Grooper SDK, uploaded to the Grooper server.

It is worth noting before moving further that "FieldEnter" and "FieldExit" events are not supported with the Grooper Web Client.

Understanding the Environment

Before we dive into how things are setup, let's take a look at what parts make up the demonstration environment. Variables in your environment will obviously be slightly different, but this is a basic setup that should work as a reasonable template.

Grooper Server

This is the main server that is hosting everything Grooper, and as such will be referred to as "Grooper Server". The following components are installed on this machine.

  • Grooper Software
    • Grooper software is installed on this computer normally. For more information on installing Grooper please visit the Install and Setup article.
  • Grooper Web Server
    • The Grooper Web Client is installed on this "Grooper Server" (along with the requisite installation and appropriate configuration of IIS) to allow remote computers to access the Grooper environment remotely without having to have Grooper installed on their machines.
  • Grooper Repository
    • The infrastructure that establishes a repository of information that the Grooper application points to consists of the following pieces that are also installed on this "Grooper Server":
      • Grooper Filestore
        • Files associated with objects in Grooper reside here. This is a file directory located on this "Grooper Server"
      • SQL Server
        • Objects and their configurations are stored in tables in a SQL database that make the backbone of a Grooper repository.

Remote Scripting Computer

This is a generic workstation used by a developer wanting to do scripting for Grooper that is on the same network the "Grooper Server" is on, but it is not itself the "Grooper Server". The following Components are installed on this machine.

  • Grooper Software
    • This is installed on the computer because of the need to access Grooper code for the developer when compiling. SQL server is not installed on this machine, neither is the Filestore for Grooper so it is pointed at the remote repository (the repository hosted on the "Grooper Server") via Grooper Config.
  • Grooper Web Client
    • The Grooper Web Client is installed on the developer's machine so that they can have a debug target when creating their scripts. This is not the main webpage users will interact with to access Grooper. IIS is installed on this machine to facilitate the appropriate installation of the Grooper Web Client, but IIS Express (which is side-loaded when the Grooper SDK is added to Visual Studio) will actually be leveraged upon testing and debugging of scripts.
  • Visual Studio - with Grooper SDK
    • Visual Studio 2019 is the supported version for developing with Grooper 2023.1. From Visual Studio you can download and install the Grooper SDK.




Understaing Both

We have the "Grooper Server" and we have the "Remote Scripting Computer" and their requisite components on each. As stated, the Grooper Software and the Grooper Web Client are installed on the "Remote Scripting Computer" but the Grooper Repository is established on the "Grooper Server". The "Remote Scripting Computer" is simply referencing the repository as it exists on the "Grooper Server".

How To

With an understanding of what is established in this defacto environment we will now walk through the setup of creating, compiling, and sending a script to Grooper from a remote computer.

Establishing a Connection to the "Grooper Server" from the "Remote Scripting Computer"

As discussed, the "Remote Scripting Computer" has Grooper 2023.1, the Grooper Web Client, and Visual Studio 2019 installed, but itself is not hosting a Grooper repository. We will configure this machine to point at the Grooper repository that is being hosed by the "Grooper Server".

Follow the instructions in the screenshots below.







Installing and Configuring the Grooper SDK

We now have the ability to connect to the Grooper Repository hosted by the "Grooper Server", but before we do any work in Grooper, let's jump into Visual Studio to install and configure the Grooper SDK.

Follow the instructions in the screenshots below.















Turn Off Automatic Updates

The default setting for the Grooper SDK as an extension in Visual Studio is to automatically update. It is suggested by the development team to disable this option.

The Grooper SDK will not get updated frequently, but if it does, you do not want to automatically download the update as it would facilitate installing a new sub-version of Grooper. If your environment is stable it is best practice to not introduce unknown variables that may interfere with your setup.

Set a Debug Target Page

When debugging and testing your scripts the default page that will open in your browser will be the Grooper "Home" page. If you want to set this to a different page to save time, you can change the debug target to whichever page you prefer.


Creating an Object Library and Local Project Files

There are five objects in Grooper where you can apply a custom script:

  • Batch Process
  • Data Model
  • Data Table
  • Data Type
  • Object Library

In the following example an Object Library will be created and a C# script applied to it.

Follow the instructions in the screenshots below.



Create Custom Script Button

Because we are using the path localhost/grooper we are using the Grooper website that is hosted on this machine, which is a local site to this "Remote Scripting Computer". However, because the Grooper Repository connection is to the "Grooper Server", this local website is leveraging a Grooper Repository that is remotely hosted.
The "Create a custom script" button is only available to us because we are on a website that is local to this machine. If you use the standard https://(hostname)/grooper your browser is actually connected to a website that is remote, and as a result the "Create a custom script" button would be grayed out.


Script Files Created in the Grooper Filestore

While we are accessing the Grooper Repository that lives on the "Grooper Server" via a local website, the files for the custom solution are still made in the Grooper Filestore that is part of the remote Grooper Repository on the "Grooper Server". Historically when you would edit scripts in Grooper it would be on the files in the Grooper Filestore of that repository. We don't want to do this however, so we will create a local copy of the created files that will live on this "Remote Scripting Computer" in the next steps.


Local Solution Files Copied

Now that the solution files of the custom script have been copied from the Grooper Filestore of the "Grooper Server", we can work on this solution locally and not worry about a connection to the "Grooper Server".

Editing the Custom Script Solution

In this next section we will add some code to our project.
Feel free to use the following code for your purposes.

using Grooper;
using Grooper.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace SetDescription
{
    [DataContract, IconResource("Tap"), DisplayName("SetDescription")]
    public class ObjectCommand : ObjectCommand<GrooperNode>
    {
        [DataMember, Viewable, Required]
        public string Description { get; set; }

        protected override void Execute(GrooperNode "Item)
        {
            Item.Description = Description;
        }
    }
}

The following image is used as an "IconResource" which you can choose to leverage to match what is being used. Be sure to rename it to "Tap.png" so the name matches the code.


Follow the instructions in the screenshots below.





















Testing and Debugging

With the script added, let's now test to see it working and see how we can set a break point for debugging purposes.

Follow the instructions in the screenshots below.





















Saving to Grooper and Compiling

The Grooper SDK extension has three commands:

  • Save - This will take the files of the saved solution and "push" them to the original object in Grooper, overwriting the script files on the object. You will need to go to the object in Grooper and run the compile command if you use this option. After compiling you will need to close your web browser, recycle the GrooperAppPool on the "Grooper Server", then reconnect to your Grooper site.
  • Save and Compile - This will do what the Save command will do, but after "pushing" the files over it will immediately compile the script and create the associated .DLL and .XML descriptor file. After compiling you will need to close your web browser, recycle the GrooperAppPool on the "Grooper Server", then reconnect to your Grooper site.
  • Get Latest - This command syncs with the published version of the code and updates your local code/binaries to the most up-to-date.



Follow the instructions in the screenshots below.