You are viewing limited content. For full access, please sign in.

Question

Question

How to restore TrusteeAttributeCollection from XML file using simple SDK Script

asked on February 23, 2022 Show version history

I am trying to periodically restore the saved attributes for a public kiosk user.  Unfortunately, I can't seem to do it with simple serialization.  When I execute the following SDK Script I get the message "You must implement a default accessor on Laserfiche.RepositoryAccess.TrusteeAttributeCollection because it inherits from ICollection."

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
'Imports System.Xml
Imports Laserfiche.RepositoryAccess
'Imports Laserfiche.Serialization

Namespace WorkflowActivity.Scripting.SDKScriptResetReaderAttributes
    '''<summary>
    '''Provides one or more methods that can be run when the workflow scripting activity is performed.
    '''</summary>
    Public Class Script1
        Inherits RAScriptClass104
        '''<summary>
        '''This method is run when the activity is performed.
        '''</summary>
        Protected Overrides Sub Execute()
            'Write your code here. The BoundEntryInfo property will access the entry, RASession will get the Repository Access session
            Dim ReaderAccount As AccountReference = New AccountReference("USERNAME", RASession)
            Dim ReaderAttributes As TrusteeAttributeCollection = Trustee.GetAttributes(ReaderAccount, RASession)
            ReaderAttributes.Clear()

    Dim reader As New System.Xml.Serialization.XmlSerializer(GetType(TrusteeAttributeCollection))
    Dim file As New System.IO.StreamReader(
        "C:\WorkflowAdminFiles\UserAttributes_USERNAME.xml")
    ReaderAttributes = CType(reader.Deserialize(file), TrusteeAttributeCollection)

            ReaderAttributes.Save()
        End Sub
    End Class
End Namespace
0 0

Answer

SELECTED ANSWER
replied on February 24, 2022
XmlDocument xDoc = new XmlDocument();
                xDoc.Load("D:\\Properties.xml");

                XmlNodeList nodes = xDoc.SelectNodes("Properties/Attribute");
                XmlNode node = null;
                string name = null;
                string value = null;
                foreach(XmlNode parentNode in nodes)
                {
                    node = parentNode.SelectSingleNode("Name");
                    name = node.InnerText;
                    node = parentNode.SelectSingleNode("Data");
                    value = node.InnerText;
                    ReaderAttributes.Add(name, value);
                }
                ReaderAttributes.Save();

 

1 0

Replies

replied on February 23, 2022

Are you trying to do this because the public kiosk users are changing settings on that trustee and you need to revert them to a baseline set? If so, could you use the Settings Lockdown feature to prevent the attributes from being changed in the first place? Settings Lockdown is only available for a subset of attribute categories, so it may or may not do everything you need.

0 0
replied on February 23, 2022

Yeah, I looked at that and settings lockdown isn't going to work in this instance.

0 0
replied on February 24, 2022

It's tedious but you could read the .xml file and build the TrusteeAttributeCollection "manually" instead of trying to cast it directly.

0 0
replied on February 24, 2022 Show version history

Yeah that's what I'm trying to teach myself at the moment.  Clearing and adding the attributes to the collection is fine, but I've never read and parsed an XML file before.  Got any tips or examples? TIA.

0 0
replied on February 24, 2022

I'm not familiar with how it's serialized, but if you post the file, I'd be happy to whip something up - in c#, though - smiley

0 0
replied on February 24, 2022

TrusteeAttributesCollection is serialized into an XML file like so...

<!-- *****  These are the attributes for the xxxxxKiosk user. ***** -->
<Properties>
	<Attribute>
		<Name>[Search]OpenIfOneResult</Name>
		<Data>No</Data>
	</Attribute>
	<Attribute>
		<Name>[Settings]PrintScreenIntercept</Name>
		<Data>No</Data>
	</Attribute>
	<Attribute>
	<!-- do not show 'View Open Edocs' command in the Tools dropdown menu -->
		<Name>[Settings]ShowOpenEDocDlg</Name>
		<Data>FALSE</Data>
	</Attribute>
	<Attribute>
	<!-- Select all search options in Quick search by default -->
		<Name>[Search]SelectedQuickSearches</Name>
		<Data>1,2,4,16</Data>
	</Attribute>
	<Attribute>
		<Name>[Settings]UseDefaultCollation</Name>
		<Data>No</Data>
	</Attribute>
	<Attribute>
	<!-- Default to case and accent insensitive -->
		<Name>[Settings]SearchCollationRule</Name>
		<Data>CI,AI</Data>
	</Attribute>

	<Attribute>
		<Name>[Settings]ShowPreviewPane</Name>
		<Data>FALSE</Data>
	</Attribute>
	<Attribute>
		<Name>[Settings]RememberLeftPane</Name>
		<Data>FALSE</Data>
	</Attribute>
	<Attribute>
		<Name>[Settings]UseManualPageTextSearch</Name>
		<Data>FALSE</Data>
	</Attribute>
	<Attribute>
		<Name>[Search]RememberBasicSearchCheckboxes</Name>
		<Data>FALSE</Data>
	</Attribute>
	<Attribute>
		<Name>[Settings]ShowRecordsManagementSearch</Name>
		<Data>FALSE</Data>
	</Attribute>
	<Attribute>
	<!-- default zoom to "fit window" -->
		<Name>[Settings]DefaultZoom</Name>
		<Data>0</Data>
	</Attribute>
</Properties>

 

0 0
SELECTED ANSWER
replied on February 24, 2022
XmlDocument xDoc = new XmlDocument();
                xDoc.Load("D:\\Properties.xml");

                XmlNodeList nodes = xDoc.SelectNodes("Properties/Attribute");
                XmlNode node = null;
                string name = null;
                string value = null;
                foreach(XmlNode parentNode in nodes)
                {
                    node = parentNode.SelectSingleNode("Name");
                    name = node.InnerText;
                    node = parentNode.SelectSingleNode("Data");
                    value = node.InnerText;
                    ReaderAttributes.Add(name, value);
                }
                ReaderAttributes.Save();

 

1 0
replied on February 28, 2022

Rich,  Sorry for the delay in getting back to you, due to the three hours time difference and getting snowed in on Friday.  I translated your code to VB and it worked first shot.  Thanks, you are a gentleman and a scholar.  Jim.

1 0
replied on February 28, 2022 Show version history

Here's the VB code if anyone needs it.

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports Laserfiche.RepositoryAccess

Imports System.Xml

Namespace WorkflowActivity.Scripting.SDKScriptResetKioskAttributes
    '''<summary>
    '''Provides one or more methods that can be run when the workflow scripting activity is performed.
    '''</summary>
    Public Class Script1
        Inherits RAScriptClass104
        '''<summary>
        '''This method is run when the activity is performed.
        '''</summary>
        Protected Overrides Sub Execute()
            'Write your code here. The BoundEntryInfo property will access the entry, RASession will get the Repository Access session
            Dim UserName As String = GetTokenValue("UserName")
            Dim XMLFilePath As String = GetTokenValue("XmlAttrFilePath")

            Dim KioskAccount As AccountReference = New AccountReference(UserName, RASession)
            Dim KioskAttributes As TrusteeAttributeCollection = Trustee.GetAttributes(KioskAccount, RASession)

            Dim AttrDocument As New XmlDocument
			AttrDocument.Load(XMLFilePath)
			Dim NodeList As XmlNodeList = AttrDocument.SelectNodes("Properties/Attribute")

            Dim AttrNode As XmlNode
			Dim AttrName as String
			Dim AttrValue as String

            KioskAttributes.Clear()
			For Each parentNode As XmlNode In NodeList
				AttrNode  = parentNode.SelectSingleNode("Name")
				AttrName  = AttrNode.InnerText
				AttrNode  = parentNode.SelectSingleNode("Data")
				AttrValue = AttrNode.InnerText
				KioskAttributes.Add(AttrName, AttrValue)
			Next
            KioskAttributes.Save()
            SetTokenValue("AttributeCount", KioskAttributes.Count)

        End Sub
    End Class
End Namespace

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.