Desktop productivity for business analysts and programmers

Custom Tasks .NET Enterprise Guide - GetSasCode()

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

Custom Tasks .NET Enterprise Guide - GetSasCode()

I'm trying to write a custom task that allows users to enter attributes into a form that builds a Proc Datasets to modify a copy of a dataset.

I can get the proc datasets to run correctly with a button event handler that looks like:

SAS.Tasks.Toolkit.SasSubmitter submitter = new SAS.Tasks.Toolkit.SasSubmitter(ActiveServer);

                // holds SAS log output

                string log;

                // submit program and wait for completion

                submitter.SubmitSasProgramAndWait(FinalSasCode, out log);

where FinalSasCode has the program I want to run.

I have a property in the Model also called FinalSasCode and I can set it with the program text (and see in the log that it is set, but when GetSASCode() is invoked the property returns an empty string (as can be seen in the log).

Is this come kind of timing or thread issue? When does GetSasCode() get invoked?

public override string GetSasCode()
    {
        try
        {
           
            dlg.logger.InfoFormat(" /*  From GetSasCode FinalSasCode:  */ \n proc contents data = {0}.{1}; run;\n {2} \n /*   */", Consumer.ActiveData.Library, Consumer.ActiveData.Member, FinalSasCode);
           

            return string.Format(" /*   task complete */ \n proc contents data = {0}.{1}; run;\n {2} \n /*   */", Consumer.ActiveData.Library, Consumer.ActiveData.Member, FinalSasCode);          
        }
        catch (Exception ex)
        {
            dlg.logger.InfoFormat(" Exception caught in GetSASCode {0}", ex.Message);
            return string.Format(" /*  Exception generated in GetSasCode   */");
        }
    }

From the logger:

2013-10-07 19:18:56,229 [Main] INFO  DataLogger [(null)] -  /*  From GetSasCode FinalSasCode:  */

proc contents data = EXTEST.SALES; run;

 

/*   */

This is what is submitted with the OK button:

/*   task complete */

proc contents data = EXTEST.SALES; run;

 

/*   */


Accepted Solutions
Solution
‎10-08-2013 09:13 AM
Community Manager
Posts: 2,707

Re: Custom Tasks .NET Enterprise Guide - GetSasCode()

Larry,

Do you need the code to run while the task is visible?  Or simply after the OK button is clicked?

If you need the code to run in EG after you click OK, you do not need the SasSubmitter piece.  The SasSubmitter class allows you to run SAS statements while your task is visible and then collect/use the results within your UI.  An example is the "solve macro expression" piece in the Macro Variable Viewer example.

It's important to understand the different "modes" of a custom task:

Registration (or discovery) - the few methods that are used to add your task to the menu, determine the name, category, icon.

Design time - when your task shows its UI and allows the end user to make selections.  All selections must be saved in the XmlState member (facilitated by GetXmlState and RestoreStateFromXml within the SasTask-derived task -- methods that you must override).

Run time - EG creates a new instance of your task class and provides the XmlState (which you can process in RestoreStateFromXml), then calls GetSasCode -- in which you construct a SAS program based on the settings you saved.

These topics are covered in more detail in my custom tasks book.  See Chapter 4: Meet the Custom Task APIs.

Chris

View solution in original post


All Replies
Solution
‎10-08-2013 09:13 AM
Community Manager
Posts: 2,707

Re: Custom Tasks .NET Enterprise Guide - GetSasCode()

Larry,

Do you need the code to run while the task is visible?  Or simply after the OK button is clicked?

If you need the code to run in EG after you click OK, you do not need the SasSubmitter piece.  The SasSubmitter class allows you to run SAS statements while your task is visible and then collect/use the results within your UI.  An example is the "solve macro expression" piece in the Macro Variable Viewer example.

It's important to understand the different "modes" of a custom task:

Registration (or discovery) - the few methods that are used to add your task to the menu, determine the name, category, icon.

Design time - when your task shows its UI and allows the end user to make selections.  All selections must be saved in the XmlState member (facilitated by GetXmlState and RestoreStateFromXml within the SasTask-derived task -- methods that you must override).

Run time - EG creates a new instance of your task class and provides the XmlState (which you can process in RestoreStateFromXml), then calls GetSasCode -- in which you construct a SAS program based on the settings you saved.

These topics are covered in more detail in my custom tasks book.  See Chapter 4: Meet the Custom Task APIs.

Chris

Occasional Contributor
Posts: 6

Re: Custom Tasks .NET Enterprise Guide - GetSasCode()

Thanks very much. I missed the Design time vs Run Time distinction in Chapter 4, and had not overridden XMLState. I thought that it was just for restoring the user interface when the task was modified in future EG sessions.

I see how that works now.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 314 views
  • 0 likes
  • 2 in conversation