<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Possible bug or strange behavior: Recursion in DocumentService.GetFileDeleteRestrictionsByMasterId in Vault Customization Forum</title>
    <link>https://forums.autodesk.com/t5/vault-customization-forum/possible-bug-or-strange-behavior-recursion-in-documentservice/m-p/10018828#M3433</link>
    <description>&lt;P&gt;Hello again &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;also described in the Recycle Bin idea threat, when I want to check of other Restrictions in the&amp;nbsp;DocumentService.DeleteFileEvents Event I programmed myself, it wents into a recursion. Below a excerpt from my code without the fix.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you don´t remove the event, it will call itself again and again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using Autodesk.Connectivity.Extensibility.Framework;
using Autodesk.Connectivity.WebServices;
using System;
using System.Collections.Generic;
using System.Linq;

namespace MyVaultExtensions {
	public class MyVaultRestrictions : IWebServiceExtension {
		public void OnLoad() {
			DocumentService.DeleteFileEvents.GetRestrictions += new EventHandler&amp;lt;DeleteFileCommandEventArgs&amp;gt;(DeleteFileEvents_GetRestrictions);
		}

		private void DeleteFileEvents_GetRestrictions(object sender, DeleteFileCommandEventArgs e) {
			var ds = (DocumentService)sender;
			
			// Check if Vault or other restrictions are found for the file, if so, don´t do anything
			var res = documentService.GetFileDeleteRestrictionsByMasterId(eventArgs.FileMasterIds.FirstOrDefault(), eventArgs.FolderId); // here he runs forever now
				
			/* the rest of your code will never be executed */
		}
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The fix is to remove the Event for the time of the check&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private void DeleteFileEvents_GetRestrictions(object sender, DeleteFileCommandEventArgs e) {
	var ds = (DocumentService)sender;
	
	// Check if Vault or other restrictions are found for the file, if so, don´t do anything
	var res = documentService.GetFileDeleteRestrictionsByMasterId(eventArgs.FileMasterIds.FirstOrDefault(), eventArgs.FolderId); // here he runs forever now
		
	/* the rest of your code will never be executed */
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would rather not have to do such hacks, but I trust Vault that the restrictions from i.e. LifeCycles are working and my code should not run.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any other suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;</description>
    <pubDate>Thu, 21 Jan 2021 10:06:58 GMT</pubDate>
    <dc:creator>thomas.behrendY5FX4</dc:creator>
    <dc:date>2021-01-21T10:06:58Z</dc:date>
    <item>
      <title>Possible bug or strange behavior: Recursion in DocumentService.GetFileDeleteRestrictionsByMasterId</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/possible-bug-or-strange-behavior-recursion-in-documentservice/m-p/10018828#M3433</link>
      <description>&lt;P&gt;Hello again &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;also described in the Recycle Bin idea threat, when I want to check of other Restrictions in the&amp;nbsp;DocumentService.DeleteFileEvents Event I programmed myself, it wents into a recursion. Below a excerpt from my code without the fix.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you don´t remove the event, it will call itself again and again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using Autodesk.Connectivity.Extensibility.Framework;
using Autodesk.Connectivity.WebServices;
using System;
using System.Collections.Generic;
using System.Linq;

namespace MyVaultExtensions {
	public class MyVaultRestrictions : IWebServiceExtension {
		public void OnLoad() {
			DocumentService.DeleteFileEvents.GetRestrictions += new EventHandler&amp;lt;DeleteFileCommandEventArgs&amp;gt;(DeleteFileEvents_GetRestrictions);
		}

		private void DeleteFileEvents_GetRestrictions(object sender, DeleteFileCommandEventArgs e) {
			var ds = (DocumentService)sender;
			
			// Check if Vault or other restrictions are found for the file, if so, don´t do anything
			var res = documentService.GetFileDeleteRestrictionsByMasterId(eventArgs.FileMasterIds.FirstOrDefault(), eventArgs.FolderId); // here he runs forever now
				
			/* the rest of your code will never be executed */
		}
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The fix is to remove the Event for the time of the check&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private void DeleteFileEvents_GetRestrictions(object sender, DeleteFileCommandEventArgs e) {
	var ds = (DocumentService)sender;
	
	// Check if Vault or other restrictions are found for the file, if so, don´t do anything
	var res = documentService.GetFileDeleteRestrictionsByMasterId(eventArgs.FileMasterIds.FirstOrDefault(), eventArgs.FolderId); // here he runs forever now
		
	/* the rest of your code will never be executed */
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would rather not have to do such hacks, but I trust Vault that the restrictions from i.e. LifeCycles are working and my code should not run.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any other suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 10:06:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/possible-bug-or-strange-behavior-recursion-in-documentservice/m-p/10018828#M3433</guid>
      <dc:creator>thomas.behrendY5FX4</dc:creator>
      <dc:date>2021-01-21T10:06:58Z</dc:date>
    </item>
  </channel>
</rss>

