Desktop productivity for business analysts and programmers

Serializing Custom Tasks

Reply
Frequent Contributor
Posts: 91

Serializing Custom Tasks

Hi,

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?

Any advice appreciated.

Nick
Community Manager
Posts: 2,889

Re: Serializing Custom Tasks

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.

Most of the examples at:
http://support.sas.com/documentation/onlinedoc/guide/customtasks/index.htm

show this technique. Note that I added several examples in the past couple of months, in case you haven't checked there lately.

Look at the Calculate Lag example or System Command example.

Chris
Frequent Contributor
Posts: 91

Re: Serializing Custom Tasks

Thanks Chris,

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?

Thanks,

Nick
Community Manager
Posts: 2,889

Re: Serializing Custom Tasks

Nick, sorry for the delay in getting back.

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.

Chris
Frequent Contributor
Posts: 91

Re: Serializing Custom Tasks

Thanks Chris,

I have done exactly that - serialized to an XML in Windows/temp. Just wanted to make sure there was no inbuilt method.

Nick
Ask a Question
Discussion stats
  • 4 replies
  • 157 views
  • 0 likes
  • 2 in conversation