Quantcast
Channel: Manufacturing DevBlog
Viewing all articles
Browse latest Browse all 531

Monitor User Configuration Changes Using Autodesk Vault API

$
0
0
By Daniel Du
 

As you know, it is possbile to write event handler to customize the business logic. These handlers will receive notification whenever a Vault client on that machine does an action that you subscribed to. For example if a program tries to check in a file, your code can get notified of that action.  Then you can proceed to block the operation or perform additional tasks.  As demoed in the “RestrictOperations” sample in Vault SDK, many services provide many events which can be hooked to do customization. One user is asking how to monitor user configiruation changes, for example, When a new user is created and added to a group, or when a existing user's ACL has been modified, a email notification should be sent to administrator, or create a configuration changes log into database.

It is natrual to look into AdminService or SecurtyService, expecting some specfic events like DocumentService, ItemService ,etc. Unfortunatly, AdminService or SecurtyService does not expose such specific events, but they do have some events:

Public Event PostInvokeEvents Subscribe to this event to get a notification after every web service call. 
Public Event PreInvokeEvents   Subscribe to this event to get a notification before every web service call. 

The event handler receives an argument of type WebServiceInvokeEventArgs containing data related to this event. The following WebServiceInvokeEventArgs properties provide information specific to this event.

MethodNameThe name of the method being called.
ParametersThe method parameters
ReturnValueThe return values. The first element will be the standard return. Elements after are from [out] parameters.

PostInvokeEvents will be triggered after every single service methods is call, PreInvokeEvents will be triggered before a service method is called. We can create our own event hander, in which we can check the MethodName so that we know which method is called, then take some necessory action to customize the business logic.

To monistor user related changes, we need to hook up AdminService.PreInvokeEvents or AdminService.PostInvokeEvents, for ACL changes, we need to hook up SecurityServices.PreInvokeEvents and SecurityService.PostInvokeEvents.

Here is a sample :

      //register events
      connection.WebServiceManager.AdminService.PreInvokeEvents += AdminService_PreInvokeEvents;
      connection.WebServiceManager.AdminService.PostInvokeEvents += AdminService_PostInvokeEvents;

      connection.WebServiceManager.SecurityService.PostInvokeEvents += SecurityService_PostInvokeEvents;
 
    void SecurityService_PostInvokeEvents(object sender, WebServiceInvokeEventArgs e)
    {
        //do something according to e.MethodName
    }

    void AdminService_PostInvokeEvents(object sender, WebServiceInvokeEventArgs e)
    {


      string para = "";
      for (int i = 0; i < e.Parameters.Length; i++)
      {
        para += e.Parameters[i].ToString() + "\n";
      }

      string msg = "MethodName : " + e.MethodName + "\n"
                + "Parameters :" + para + "\n"
                + "ReturnValue :" + e.ReturnValue + "\n";


      MessageBox.Show(msg + " Excution complete");

      // if a new use added
      if (e.MethodName == "AddUser")
      {
         MessageBox.Show("A new user is added.");
      }
    }

    void AdminService_PreInvokeEvents(object sender, WebServiceInvokeEventArgs e)
    {
      string para = "";
      for (int i = 0; i < e.Parameters.Length; i++)
      {
        para += e.Parameters[i].ToString() + "\n";
      }

      string msg = "MethodName : " + e.MethodName + "\n"
                + "Parameters :" + para + "\n"
                + "ReturnValue :" + e.ReturnValue + "\n";

      MessageBox.Show(msg + " will run.");

      if (e.MethodName == "AddUser")
      {
        MessageBox.Show("A new user will be added.");
      }
    }

Viewing all articles
Browse latest Browse all 531

Trending Articles