To know when an client Office Document is closed usging ITHit WebDAV AJAX Library plugin

937 views Asked by At

we are using an "IT Hit WebDAV AJAX Library Redistribution Licence" library.

We have been using successfuly this library for this workflow: 1) the client clicks on a button en the webpage 2) the webpage finds a document on a webdav server 3) the plugin connects the webdav document with Ms Office Word of the client. 4) the client updates the content of the document 5) the client saves his changes. This changes are reflected and stored in the webdav storage.

Our problem is: We need to add these following tasks in this workflow:

6) the client closes the Ms Office Word application 7) the wepage is notified that the client has closed the webdav document 8) the webpage do something with that information ....

We don't know how to get a callback from your library, in order to trigger many tasks that are necessary for our logic.

We are using this code for open the document:

function editWordVersion(document_url){
    oNs= ITHit.WebDAV.Client.DocManager;
    oNs.EditDocument(document_url);
}

We Appreciate any way or alternative for doing this with your library.

1

There are 1 answers

0
IT Hit WebDAV On

There is no way to get the information about the document being closed directly from the MS Office application to IT Hit WebDAV Ajax library. After the document is opened, the WebDAV Ajax Library does not have any control over the document, it just initiates the process of opening the document.

To get the notification about about the document being closed you need to use the websockets and to send a notification to a webpages from your ILock.Unlock method implementation. Here is how to add SigmalR to a MVC 5 project with a WebDAV, send and consume the notification:

  1. Create MVC 5 ASP.NET Web Application in VS 2013.

  2. Add WebDAV to your project using 'Add WebDAV Server Implementation' wizard.

  3. Add web sockets to your project on a server site:

    Add reference to Microsoft.AspNet.SignalR.Core and Microsoft.AspNet.SignalR.SystemWeb in your project.

    Call app.MapSignalR() in Startup.cs:

    public void Configuration(IAppBuilder app) {
    
        app.MapSignalR();
    
        ConfigureAuth(app);
    }
    

    Create a class derived from Hub. You can leave it empty:

    public class MyHub1 : Hub
    {
    }
    
  4. In ILock.Unlock method implementation send a notification to a webpage. By default Add WebDAV Server Implementation wizard adds Unlock method to DavHierarchyItem class, which implements ILock, extend this method with the following code:

     public void Unlock(string lockToken)
    {
        // your unlock implementation goes here
        ...
    
        // get the document url (optional)
        string documentUrl = System.Web.HttpContext.Current.Response.ApplyAppPathModifier(
            context.Request.ApplicationPath.TrimEnd('/') + '/' + this.Path);
    
        // send SignalR message to all web browsers
        var signalCntx = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext<MyHub1>();
        signalCntx.Clients.All.documentModified(context.Request.HttpMethod, documentUrl);
    }
    
  5. Consume the event on the client side. Add the following JavaScript to your web page, for example to MyCustomHandlerPage.aspx page generated by the WebDAV wizard:

    <script src="/Scripts/jquery-1.10.2.js"></script>
    <script src="/Scripts/jquery.signalR-2.1.2.min.js"></script>
    
    <!--Reference the autogenerated SignalR hub script. -->
    <script src="/signalr/hubs"></script>
    
    <!--SignalR script to update the chat page and send messages.--> 
    <script>
    $(function () {
        // Reference the auto-generated proxy for the hub.  
        var chat = $.connection.myHub1;
    
        // This function is called when the document is unlocked.
        chat.client.documentModified = function (httpMethod, docPath) {
            window.location.reload(); 
        };
    
        // Start the connection.
        $.connection.hub.start().done(function () {
    
        });
    });
    </script>