-
Notifications
You must be signed in to change notification settings - Fork 63
Utilizing a probe
A probe is an executable code deployed directly to the analysed instance. It runs within the instance's context and has access to the same data as the instance itself (e.g., cache items). The KInspector contains API which facilitates automatic installing and uninstalling of the probe files from the analysed instance.
Most modules query the database in order to analyse the Kentico instance. Some modules access the file system to do so.
But in some cases, you might need to utilize the API of the analysed instance. This could be achieved by referencing the proper version of Kentico DLLs in the KInspector tool and adding the analysed instance connection string to the config file, but it would require bundling lots of DLLs with the tool. That's why such approach is discouraged.
The code of a probe should work in both Web Site and Web Application environments.
One of the possible approaches utilizes Web Forms (.aspx file) with CodeFile and designer file (.designer.cs). Such Web Forms can be compiled at runtime by either Web Site or Web Application (important: even in Web Application, the Web Form uses CodeFile instead of CodeBehind attribute in its Page element in the .aspx file). All you have to do is place your probe's files to the .\ProbeData folder within the KInspector tool and call the ProbeHelper.EnsureProbeInstallation method at the beginning of your module. This results in copying the ProbeData folder's content to the analysed instance's folder (e.g., C:\inetpub\wwwroot<myInstance>\CMS for Kentico 8).
The probe should work with as much Kentico instance versions as possible. For that reason, you should rather avoid shipping precompiled DLLs in the ProbeData folder. The DLLs would most likely reference Kentico libraries with a specific version and would require configuring of binding redirects in the target instance's web.config file. Moreover, if the DLL was meant to be automatically discovered by the analysed Kentico instance, it would have to be signed (i.e., have a strong name).
Since the probe is expected to provide some kind of analytical data for the tool, you will most likely need to retrieve the result of its execution. It is recommended to do an HTTP request to load the data from the target instance and then work with those data (although it could just display the information to the user in the Web Form's markup, requiring the user to access the URL of the probe's Web Form within the analysed instance).
Uninstallation should be ensured in the code for each time the module finishes its work.
Take a look at the implementation of the CacheItemsModule.cs and the related probe file.
The probe's code is not executed by KInspector itself. It is deployed to the analysed instance (i.e., Kentico Web Site or Web Application) where it runs within IIS. You still have to implement a KInspector module, which will utilize the data obtained by your probe.
It can be anything, even a handler. But handler's code is usually compiled in a DLL (if not written directly in the .ashx file, which is not very nice). And if the handler requires access to the Kentico API, the handler's DLL has to reference Kentico's DLLs. But when you compile your handler's DLL with Kentico 8 libraries, you have to make sure it will work with Kentico 7, 8.1, 8.2, XY as well. That usually requires setting binding redirects in the config file of the web, which is another complication for you.
Most likely, you have forgotten to set the Build Action to Content in the .aspx (or .aspx.cs or .designer.cs) file's Properties in Visual Studio. You do not want the KInspector tool to compile the .aspx Web Form's code, you want the analysed Kentico instance to do so.
Make sure that in the .aspx file, the Page element uses CodeFile and not CodeBehind attribute to specify the Web Form's code (IIS can compile code files at runtime whereas it expects code behind to be already compiled).
Make sure the Web Form consists of .aspx, .aspx.cs and .designer.cs files. If you have developed your probe in Kentico Web Site environment, the designer file will be missing. You should develop in a Web Application environment and then just make sure the CodeBehind attribute is replaced by CodeFile.