I am designing a custom task that sets the fmtsearch option by clicking on radio buttons. The custom task does not persist, i.e. you open it, set your option, run it and the task disappears. What I want to be able to do is store the current choice so that when the user opens up the task again, it remembers during the session what the current choice is.
Is there a way to serialize this information so it can be used for the duration of a SAS EG session?
Yes. Serializing the state of the task requires that you implement the XmlState property (get and set). Or, if you are using the SAS.Tasks.Toolkit and inheriting from the SasTask class, override the RestoreStateFromXml and GetXmlState methods.
The problem is that I dont quite get how these get and set methods work. The methods return or deserialize a string, but does this string need to be stored somewhere? Remember, my custom task's show method returns a 'Canceled' ShowResult value, and therefore does not store a result. I have tried to implement what is demonstrated in the examples into my custom task, but it doesnt seem to work. What might I be doing wrong?
I have had to resort to serialize the properties into an xml file, but your examples don't seem to require this. An explanation, or a reference to somewhere which explains how these methods are handled would be helpful. Is there something being done behind the scenes with these methods that might help me figure it out?
If your task returns Cancel as a result, then the state is *not* stored in the EG project. You might have realized that by now.
So, then you are on your own for serializing the state elsewhere, if the state is not project specific. You can use .NET methods to read/write a file of your own design into a safe location, such as somewhere in %appdata% where the user is sure to have write access.