<?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 Re: Connection to Vault in the Event Handling Extension in Vault Customization Forum</title>
    <link>https://forums.autodesk.com/t5/vault-customization-forum/connection-to-vault-in-the-event-handling-extension/m-p/8913754#M4933</link>
    <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/561925"&gt;@pzuziak&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You shouldn't have the&amp;nbsp;need to construct the connection object. Once you have the WebServiceManager, you can make use of that to access the&amp;nbsp;DocumentService etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, an important note for the above approach:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;SPAN style="color: rgb(51, 51, 51); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: Helvetica, Arial, sans-serif; font-size: 16.8px; font-weight: 400; word-spacing: 0px; float: none; display: inline !important; white-space: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"&gt;"Some operations may not work correctly when it’s executed from event handler (i.e. modifying of mapped properties when file is already open in Inventor). For such cases the safer approach may be to schedule a job and perform operation later."&lt;/SPAN&gt;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Sajith&lt;/P&gt;</description>
    <pubDate>Wed, 17 Jul 2019 08:09:35 GMT</pubDate>
    <dc:creator>sajith_subramanian</dc:creator>
    <dc:date>2019-07-17T08:09:35Z</dc:date>
    <item>
      <title>Connection to Vault in the Event Handling Extension</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/connection-to-vault-in-the-event-handling-extension/m-p/8911854#M4931</link>
      <description>&lt;P&gt;Good day,&lt;/P&gt;&lt;P&gt;I am working on an extension that modifies property values on state change.&amp;nbsp; The code below is working but I am not sure if am doing this the best way. What is the significance of the UserID argument in the Connection constructor? It does not seem to matter - I tried a couple of different values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        private void UpdateFileLifecycleStateEvents_Pre(object sender, UpdateFileLifeCycleStateCommandEventArgs e)
        {         
            Connection connection = new Connection(sender.WebServiceManager, "vault", 1, "server", AuthenticationFlags.WindowsAuthentication);         

...&lt;/PRE&gt;&lt;P&gt;Another instance of UserID that does not seem to matter is:&lt;/P&gt;&lt;PRE&gt;IExplorerUtil explorerUtil = ExplorerLoader.LoadExplorerUtil(connection.Server, connection.Vault, 1, authTicket);&lt;/PRE&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;Przemek&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 13:21:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/connection-to-vault-in-the-event-handling-extension/m-p/8911854#M4931</guid>
      <dc:creator>pzuziak</dc:creator>
      <dc:date>2019-07-16T13:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: Connection to Vault in the Event Handling Extension</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/connection-to-vault-in-the-event-handling-extension/m-p/8913710#M4932</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;No - it's not best way &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Take a look at my example:&lt;/P&gt;&lt;PRE&gt;private void UpdateItemLifecycleStateEvents_GetRestrictions(object sender, UpdateItemLifeCycleStateCommandEventArgs e)
        {
            Logger.Trace("Start");

            if (!(sender is IWebService webService)) return;
            if (e.ItemMasterIds == null || e.ItemMasterIds.Length == 0) return;
            if (e.ToStateIds == null || e.ToStateIds.Length == 0) return;

            Logger.Debug("ItemMasterIds: {itemMasterIds}", e.ItemMasterIds);
            Logger.Debug("ToStateIds: {toStateIds}", e.ToStateIds);

            try
            {
                var items = webService.WebServiceManager.ItemService.GetLatestItemsByItemMasterIds(e.ItemMasterIds);
                var states = webService.WebServiceManager.LifeCycleService.GetLifeCycleStatesByIds(e.ToStateIds);&lt;/PRE&gt;&lt;P&gt;And so on...&lt;/P&gt;&lt;P&gt;The most important part is to cast sender to IWebService, then use it &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;Let me know if that helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rafal K.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 07:48:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/connection-to-vault-in-the-event-handling-extension/m-p/8913710#M4932</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-07-17T07:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: Connection to Vault in the Event Handling Extension</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/connection-to-vault-in-the-event-handling-extension/m-p/8913754#M4933</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/561925"&gt;@pzuziak&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You shouldn't have the&amp;nbsp;need to construct the connection object. Once you have the WebServiceManager, you can make use of that to access the&amp;nbsp;DocumentService etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, an important note for the above approach:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;SPAN style="color: rgb(51, 51, 51); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: Helvetica, Arial, sans-serif; font-size: 16.8px; font-weight: 400; word-spacing: 0px; float: none; display: inline !important; white-space: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"&gt;"Some operations may not work correctly when it’s executed from event handler (i.e. modifying of mapped properties when file is already open in Inventor). For such cases the safer approach may be to schedule a job and perform operation later."&lt;/SPAN&gt;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Sajith&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 08:09:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/connection-to-vault-in-the-event-handling-extension/m-p/8913754#M4933</guid>
      <dc:creator>sajith_subramanian</dc:creator>
      <dc:date>2019-07-17T08:09:35Z</dc:date>
    </item>
    <item>
      <title>Re: Connection to Vault in the Event Handling Extension</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/connection-to-vault-in-the-event-handling-extension/m-p/8913809#M4934</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4069635"&gt;@sajith_subramanian&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the reply.&lt;/P&gt;&lt;P&gt;The job processor approach might be more suitable and I think I will pursue that route.&lt;/P&gt;&lt;P&gt;Just to satisfy my curiosity.......&lt;/P&gt;&lt;P&gt;I was using connection to get the PropertyManager and the property definition:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PropertyDefinition property1 = connection.PropertyManager.GetPropertyDefinitionBySystemName(prop.SysName);&lt;/PRE&gt;&lt;P&gt;as well as to get IExplorerUtil object:&lt;/P&gt;&lt;PRE&gt;IExplorerUtil explorerUtil = ExplorerLoader.LoadExplorerUtil(connection.Server, connection.Vault, 1, authTicket);&lt;/PRE&gt;&lt;P&gt;I couldn't find another way apart from creating connection........&lt;/P&gt;&lt;P&gt;Even if there was another way could you explain the significance of the UserId argument in&amp;nbsp;LoadExplorerUtil plaese?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;Przemek&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 08:36:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/connection-to-vault-in-the-event-handling-extension/m-p/8913809#M4934</guid>
      <dc:creator>pzuziak</dc:creator>
      <dc:date>2019-07-17T08:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: Connection to Vault in the Event Handling Extension</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/connection-to-vault-in-the-event-handling-extension/m-p/8913832#M4935</link>
      <description>&lt;P&gt;Przemek,&lt;/P&gt;&lt;P&gt;You do not have to access PropertyManager.&lt;/P&gt;&lt;P&gt;Property service is all You need:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;var itemPropDefs = webService.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId(EntityClassIds.Items);
var itemPropInsts = webService.WebServiceManager.PropertyService.GetPropertiesByEntityIds(EntityClassIds.Items, itemIds);&lt;/PRE&gt;&lt;P&gt;How to get webService - You have it in my first answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;UserId is indication for WebServices to determine who is calling function. It then is used to determine authorization for further actions. If You are using value 1 (hard coded), it is first user in Vault - in most cases it's Administrator.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 08:44:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/connection-to-vault-in-the-event-handling-extension/m-p/8913832#M4935</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-07-17T08:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: Connection to Vault in the Event Handling Extension</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/connection-to-vault-in-the-event-handling-extension/m-p/8913941#M4936</link>
      <description>&lt;P&gt;@Anonymous&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just one more question &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; how to get the property value?&lt;/P&gt;&lt;P&gt;I was doing it this way:&lt;/P&gt;&lt;PRE&gt;currentPropertyVaule = connection.PropertyManager.GetPropertyValue(fileIter, property1, null).ToString();&lt;/PRE&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;Przemek&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 09:40:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/connection-to-vault-in-the-event-handling-extension/m-p/8913941#M4936</guid>
      <dc:creator>pzuziak</dc:creator>
      <dc:date>2019-07-17T09:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: Connection to Vault in the Event Handling Extension</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/connection-to-vault-in-the-event-handling-extension/m-p/8913979#M4937</link>
      <description>&lt;P&gt;No problem Przemek.&lt;/P&gt;&lt;P&gt;Example for Items. You can change to Files by changing that line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;var itemPropDefs = webService.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId(EntityClassIds.Items);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;private void UpdateItemLifecycleStateEvents_GetRestrictions(object sender, UpdateItemLifeCycleStateCommandEventArgs e)
{
	Logger.Trace("Start");

	if (!(sender is IWebService webService)) return;
	if (e.ItemMasterIds == null || e.ItemMasterIds.Length == 0) return;
	if (e.ToStateIds == null || e.ToStateIds.Length == 0) return;

	Logger.Debug("ItemMasterIds: {itemMasterIds}", e.ItemMasterIds);
	Logger.Debug("ToStateIds: {toStateIds}", e.ToStateIds);

	try
	{
		var items = webService.WebServiceManager.ItemService.GetLatestItemsByItemMasterIds(e.ItemMasterIds);
		var itemPropDefs = webService.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId(EntityClassIds.Items);
		var itemPropInsts = webService.WebServiceManager.PropertyService.GetPropertiesByEntityIds(EntityClassIds.Items, items.Select(i =&amp;gt; i.Id).ToArray());

		foreach (var item in items)
		{
			var itemPropInstsForEntity = itemPropInsts.Where(i =&amp;gt; i.EntityId == item.Id).ToArray();
			var propValue = GetPropertyValue(itemPropDefs, itemPropInstsForEntity, false, "Materiał")
		}
	}
	catch (Exception ex)
	{
		e.AddRestriction(
			new ExtensionRestriction(
				"Wyjątek",
				ex.Message));

		Logger.Error(ex);
	}
	Logger.Trace("Finish");
}

private static object GetPropertyValue(PropDef[] propDefs, IEnumerable&amp;lt;PropInst&amp;gt; propInsts, bool isSystem, string propName)
{
	return propInsts.SingleOrDefault(i =&amp;gt; 
		i.PropDefId == propDefs.SingleOrDefault(j =&amp;gt; 
			isSystem &amp;amp;&amp;amp; j.SysName == propName || !isSystem &amp;amp;&amp;amp; j.DispName == propName)?.Id)?.Val;
}&lt;/PRE&gt;&lt;P&gt;Feel free to contact me if You have further questions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rafal K.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 10:00:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/connection-to-vault-in-the-event-handling-extension/m-p/8913979#M4937</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-07-17T10:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: Connection to Vault in the Event Handling Extension</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/connection-to-vault-in-the-event-handling-extension/m-p/8913984#M4938</link>
      <description>&lt;P&gt;Thanks a lot&amp;nbsp;@Anonymous&amp;nbsp;!!!&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;Przemek&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 10:01:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/connection-to-vault-in-the-event-handling-extension/m-p/8913984#M4938</guid>
      <dc:creator>pzuziak</dc:creator>
      <dc:date>2019-07-17T10:01:50Z</dc:date>
    </item>
  </channel>
</rss>

