Develop an Imported Service
This topic provides guidelines on how to develop an imported service.
Create an Imported Service DLL
-
Create a project in an external IDE tool such as Visual Studio.
-
Develop the services and functions you want to make available in your Automation Studio project.
-
Compile the project into a DLL.
Ensure that the DLL name starts with the prefix ASImportedServices, for example, ASImportedServices.Testing.Library.dll.
Example Imported Service
The following guidelines describe how to create a DLL in Visual Studio 2015 for use in Automation Studio projects. You do not, however, have to use Visual Basic when developing a DLL.
To develop an imported service in Visual Studio:
-
Create a Visual Studio project.
-
Define the assembly properties (AssemblyInfo.cs). Be sure to define the Real-Time Server version and the DLL.
using System.Reflection; using System.run-time.CompilerServices; using System.run-time.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Direct.Sample.Library")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Nice Systems")] [assembly: AssemblyProduct("Direct.Sample.Library")] [assembly: AssemblyCopyright("Copyright © Nice Systems 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("23307381-d190-4207-84dc-4466c0da94e0")] // The version of Real-Time Server. [assembly: AssemblyVersion("6.5.0.0")] // The version of your DLL. This appears in the tooltip. [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: DirectAssembly(false)]
-
Create a class (for example, class1.cs) and include:
// The Real-Time logger using log4net; using Direct.Shared;
-
Specify the name for the DLL. This is what appears in Automation Studio. In this sample code, the DLL is named Sample Library.
[DirectSealed] [DirectDom("Sample Library")] [ParameterType(false)]
-
Include a reference to the Real-Time Logger, as shown in the following code:
private static readonly ILog logArchitect = LogManager.GetLogger(Loggers.LibraryObjects);
-
Code your function. A function is structured in a similar way to the following example:
// Function description that appears in Real-Time Designer [DirectDom("Run a text method")] // Function as it appears in Real-Time Designer with parameters according to the input types available [DirectDomMethod("Enter {text}")] // Function tooltip that appears in Real-Time Designer [MethodDescriptionAttribute("Runs a method that takes a text parameter, appends NICE! and returns a string")] public static string stringMethod(string text) // Function { // Error handling for error- or debug-level logging if (string.IsNullOrEmpty(text)) { if (logArchitect.IsErrorEnabled) logArchitect.Error("SampleLib.stringMethod - argument cannot be empty } if (logArchitect.IsDebugEnabled) { logArchitect.DebugFormat("SampleLib.stringMethod - Function started"); logArchitect.DebugFormat("SampleLib.stringMethod - Parameter: '{0}'", text); } try { // The function itself text = "NICE! " + text; // Logging if debug-level logging is enabled { logArchitect.DebugFormat("SampleLib.stringMethod - Returned '{0}'", text); logArchitect.DebugFormat("SampleLib.stringMethod - Ended") } // What the function returns return text; } catch (Exception ex) { logArchitect.Error("SampleLib.stringMethod - Failed with exception", ex); return text; }