Interacting with other Vault Applications#

CtrlShare takes control of an M-Files object’s state, checking it out while it is being shared.

For some M-Files applications, such as CtrlSync, this can be an issue.

In order to accommodate multiple M-Files Vault Applications in the same M-Files Vault, CtrlShare (>= 2.24.4.0) exposes an EventConfiguration.

This EventConfiguration contains four different entries that can be populated with identifiers for other Vault Application Extension methods, so that these may be called at specific times when CtrlShare is acting on an M-Files object.

  • BeforeCheckOutActions - Runs before a document is checked out to be shared

  • AfterCheckOutActions - Runs right after a document has been checked out to be shared

  • BeforeCheckInActions - Runs right before a document is checked back in from sharing

  • AfterCheckInActions - Runs right after a document has been checked back in from sharing

JSON Schema#

Each Vault Extension Method registered in either of these event lists will be called with a JSON string following the following JSON schema.

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "name": "CoAuthoringAction",
  "type": "object",
  "properties": {
    "ID": {
      "type": "integer",
      "$comment": "The ID of the object."
    },
    "ObjType": {
      "type": "integer",
      "$comment": "The object type."
    },
    "Platform": {
      "type": "string",
      "$comment": "The platform that CtrlShare is using this object with."
    },
    "IsFolder": {
      "type": "boolean",
      "$comment": "Whether the file is actually a folder."
    },
    "FirstTime": {
      "type": "boolean",
      "$comment": "Whether the file is being "
    },
    "Permissions": {
      "$ref": "#/definitions/Permissions"
    }
  },
  "required": ["ID", "ObjType", "Platform", "IsFolder", "FirstTime", "Permissions"],
  "definitions": {
    "Permissions": {
      "type": "object",
      "properties": {
        "Message": {
          "type": "string"
        },
        "WritersToAdd": {
          "type": "array",
          "items": {
            "type": "integer"
          }
        },
        "WritersToRemove": {
          "type": "array",
          "items": {
            "type": "integer"
          }
        },
        "ReadersToAdd": {
          "type": "array",
          "items": {
            "type": "integer"
          }
        },
        "ReadersToRemove": {
          "type": "array",
          "items": {
            "type": "integer"
          }
        }
      },
      "required": ["Message", "WritersToAdd", "WritersToRemove", "ReadersToAdd", "ReadersToRemove"]
    }
  }
}

VAF Example#

In your Vault Application, you can define a C# method for receiving a call from CtrlShare. Let’s say that we want to log whenever a document has been checked out.

using MFiles.VAF.Common;
using MFilesAPI;
using Newtonsoft.Json;


namespace Example;

public class VaultApplication : VaultApplicationBase {

    [VaultExtensionMethod("MyVaultApp.LogCheckout", RequiredVaultAccess = MFVaultAccess.MFVaultAccessNone)]
    public string LogCheckout(EventHandlerEnvironment env) {
        if (string.IsNullOrWhiteSpace(env.Input)) {
            throw new Exception("No input!");
        }

        dynamic action = JsonConvert.DeserializeObject(env.Input);

        var ovx = new ObjVerEx(env.Vault, (int)action.ObjType, (int)action.ID, -1);

        using var context = Logger.BeginLoggingContext($"{nameof(LogCheckout)}");

        // Log a formatted string like "[LogCheckout] <object title>(<object ids>)"
        context.Trace($"{ovx.Title}{ovx}");
    }
}