Skip to content

Developmen with Git

Kyryl Krylov, CPA edited this page Apr 15, 2020 · 151 revisions

Modern application development often involves multiple people working on a solution at any one time. Within the context of Creatio platform you may need a back end developer, and a front end developers and a business analysts to compose a deliverable package.

Over the past decade application development undergone significant changes, however it still requires the source code. When working in such environment major major challenges is to synchronize changes across the codebase. Git is of many tools that can help you with this task. Git only works with files and folders and cannot query the database, thus if you choose to use git you have to configure your development environment to use developments in filesystem mode. Developments in filesystem mode also yields additional benefits such as, debugging, and freedom to use any IDE.

When development in filesystem is not enabled, changes can only be saved to SVN or database directly. In fact when changes are committed to SVN, the source code is first exported from the database, then saved to disk and then committed to SVN from disk.

Source Code in database
  select SysSchemaContent.Id, SysSchema.Name, ManagerName, Caption, 
  SysPackage.Name [Package] , SysSchemaId, convert(varchar(max), Content) [SourceCode]
  from 
    SysSchemaContent, SysSchema, SysPackage
  where 
    SysSchemaId = SysSchema.Id and 
    SysSchema.SysPackageId = SysPackage.Id;

  select SysSchemaSource.Id, SysSchemaSource.Name, ManagerName, Caption, 
    SysPackage.Name [Package] , SysSchemaId, 
    SysPackage.Name [Package] , SysSchemaId, convert(varchar(max), Source) [SourceCode]
  from 
    SysSchemaSource, SysSchema, SysPackage
  where
    SysSchemaId = SysSchema.Id and 
    SysSchema.SysPackageId = SysPackage.Id;

The remainder of this article will discuss various approaches when targeting Git version control system. There are many IDEs that a developer may favour thus article will not discuss specific implementations but rather concentrate in concepts at hand.

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Creatio can work with Git, but only when it is configured for development in filesystem mode.

When developing on Creatio platform, a solution is provided in a form of a single package or multiple packages. Creatio Package is a collection of configuration elements such as schemas, bound(copied) data, sql scripts, and additional libraries that work together to implements particular block of functionality. In the file system, packages are directories with various subdirectories and files. Basic information about the packages is described in the Package structure and contents and Package dependencies articles.

There are multiple ways to create packages, however irrespective of how one choses to create a package, all of its content will be located inside a directory, with descriptor.json file at its root. When user executes Upload packages from file system command Creatio will traverse all directories located in App_Root_Dir\Terrasoft.WebApp\Terrasoft.Configuration\Pkg and look for descriptor.json file. If it finds it, then the directory is deemed to contain package contents, otherwise its skipped. Since all changes are saved on disk one can now use Git version control system.

What is Clio, and how can it accelerate development ?

Clio is a command line line utility and can benefit its users in multiple ways. When thinking of Clio its best to separate its functions into three broad categories:

  • Working with packages

    Clio lays necessary foundation to configure sophisticated CI/CD pipeline. For example Clio can install a package to a remote system, get package from a remote system and much more. See Clio documentatio for full details.

  • Working with the application environment(s)

    In some cases Clio offers functionality otherwise unavailable to its user. For example, it can restart an application hosted in the cloud, or clear its redis database, or execute ad-hoc sql script.

  • Working with source code

    Clio allows you to effortlessly create files in your solution, add references and to other assemblies, add NuGet packages and more.

Workflows

Single developer / Single package (Solo) Workflow

gitSoloMasterImg

  • Convert Creatio to development in file system mode

  • Create new Training package
    • Use Clio to create new package
      • (Step 1) Execute clio init command inside your current directory.

          $ clio init Training;
          $ ls;

        You should see new directory called Training.

      • (Step 2) Move Training directory to Creatio Package directory. In this example application content is located in C:\inetpub\wwwroot\Demo

          $ move .\Training\ C:\inetpub\wwwroot\Demo\Terrasoft.WebApp\Terrasoft.Configuration\Pkg;
          $ cd C:\inetpub\wwwroot\Demo\Terrasoft.WebApp\Terrasoft.Configuration\Pkg\Training;
          $ ls;
      • (Step 3) Navigate to http(s)://[your_instance]/0/dev and click Upload packages from file system
        fileSystemPkgUpDown

      OR

    • Use Configuration to create new package
      • (Step 1) - Navigate to http(s)://[your_instance]/0/dev addPackageConf

      • (Step 2) Click Download packages to file system
        fileSystemPkgUpDown

    RESULT

    Regardless of how one choses to create a package, all of its content will be located inside Training directory. At this point you may want to open and review descriptor.json file. descriptor.json describes various properties of the package and may contain dependency array and package description.

      {
      "Descriptor": {
          "UId": "ca31235f-e3da-41da-b570-dbe2d2e41f97",
          "PackageVersion": "7.8.0",
          "Name": "Training",
          "ModifiedOnUtc": "/Date(1586598729000)/",
          "Maintainer": "Customer",
          "Description": "PACKAGE DESCRIPTION HERE",
          "DependsOn": [
            {
                "UId": "UID_OF_THE_PACKAGE",
                "PackageVersion": "7.8.0",
                "Name": "PackageName"
            },
            {
                "UId": "UID_OF_ANOTHER_PACKAGE",
                "PackageVersion": "7.8.0",
                "Name": "PackageName"
            }
          ]
        }
      }

    You can use SQL query to find package name and its UID from SysPackage table.

      declare @Package varchar(max) = 'ProductCore'
      select [Name] as [Package Name], Uid [UID] 
      from SysPackage where name = @Package;
  • Develop your application

    For the sake of simplicity I will add a simple WebService to the package

    • Add WebService with Clio

      Navigate to your package directory and open solution file with your favorite IDE.

        $ cd
        $ cd C:\inetpub\wwwroot\Demo\Terrasoft.WebApp\Terrasoft.Configuration\Pkg\Training;

      Restore CreatioSDK from NuGet. Create new DemoWs class in Files-->cs
      VSSol
      Build your solution and restart the application, you can user

        $ clio restart
        $ clio open
    • Add WebService with SourceCode Schema (configuration)
      1. Navigate to http(s)://[your_instance]/0/dev and select your package.
      2. Click on Add --> Source Code, give it a name (DemoWs) and Title (DemoWs), and save.
      3. Open Training Directory
        $ cd C:\inetpub\wwwroot\Demo\Terrasoft.WebApp\Terrasoft.Configuration\Pkg\Training;
        $ ls;

      You should see 4(four) files in Schemas subdirectory, where DemoWs.cs is your C# code, and new files in Resources subdirectory. You can open DemoWs.cs with your favorite IDE and add source code below; You should refrain from ever editing files that are not .js or .cs, these are system files and are automatically generated.

    • Source Code
        using System;
        using System.ServiceModel;
        using System.ServiceModel.Activation;
        using System.ServiceModel.Web;
        using Terrasoft.Core;
        using Terrasoft.Web.Common;
      
        namespace MyNameSpace
        {
            [ServiceContract]
            [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
            public class DemoWs : BaseService
            {
                #region Properties
                private SystemUserConnection _systemUserConnection;
                private SystemUserConnection SystemUserConnection
                {
                    get
                    {
                        return _systemUserConnection ?? (_systemUserConnection = (SystemUserConnection)AppConnection.SystemUserConnection);
                    }
                }
                #endregion
      
                #region Methods : REST
                [OperationContract]
                [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
                public string PostMethodName(Guid bankLineId)
                {
                    UserConnection userConnection = UserConnection ?? SystemUserConnection;
                    return $"Hello {userConnection.CurrentUser.Contact.Name}";
                }
      
                [OperationContract]
                [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
                public string GetMethodname(Guid bankLineId)
                {
                    UserConnection userConnection = UserConnection ?? SystemUserConnection;
                    return $"Hello {userConnection.CurrentUser.Contact.Name}"; ;
                }
      
                #endregion
            }
        }
    • Follow the example to create git repository.

    • Deliver your application to client
        $ cd cd C:\inetpub\wwwroot\Demo\Terrasoft.WebApp\Terrasoft.Configuration\Pkg;
        $ clio compress Training Training.gz;
        $ clio install Training.gz -e client -r log.txt 

      OR

        $ cd cd C:\inetpub\wwwroot\Demo\Terrasoft.WebApp\Terrasoft.Configuration\Pkg\Training;
        $ clio install -e client -r log.txt