/// <summary>
        /// Performs the main work of this task.
        /// </summary>
        /// <param name="LogWriter">A log interface that you can use to report messages.</param>
        /// <returns>a status code: did it succeed or fail with errors?</returns>
        public RunStatus Run(ISASTaskTextWriter LogWriter)
        {
            try
            {
                string code = "";

                SAS.Tasks.Toolkit.Data.SasData sd = new SAS.Tasks.Toolkit.Data.SasData(Consumer.ActiveData as ISASTaskData2);
                DatasetConverter.AssignLocalLibraryIfNeeded(Consumer, this);

                DatasetConverter convert = new DatasetConverter(
                    sd.Server,
                    sd.Libref,
                    sd.Member);

                code = convert.GetCompleteSasProgram(OutputData);

                // this builds up the result structure.  It contains the SAS program
                // that was constructed.  By tagging it with the
                // "application/x-sas" mime type, that serves as a cue
                // to SAS Enterprise Guide to treat this as the generated SAS
                // program in the project.
                _resultInfo = new SAS.Tasks.Toolkit.Helpers.ResultInfo();
                if (PreserveEncoding)
                {
                    _resultInfo.Bytes = System.Text.Encoding.UTF8.GetBytes(code.ToCharArray());
                }
                else
                {
                    _resultInfo.Bytes = System.Text.Encoding.ASCII.GetBytes(code.ToCharArray());
                }
                _resultInfo.MimeType         = "application/x-sas";
                _resultInfo.OriginalFileName = string.Format("{0}.sas", Consumer.ActiveData.Member);

                // this puts a summary message into the Log portion of the
                // task in SAS Enterprise Guide
                SAS.Tasks.Toolkit.Helpers.FormattedLogWriter.WriteNormalLine(LogWriter, Messages.ConvertedData);
                SAS.Tasks.Toolkit.Helpers.FormattedLogWriter.WriteNoteLine(LogWriter,
                                                                           string.Format(Messages.ConvertedDataMetrics, convert.ColumnCount, convert.RowCount));
            }
            catch (Exception ex)
            {
                // catch any loose exceptions and report in the log
                SAS.Tasks.Toolkit.Helpers.FormattedLogWriter.WriteErrorLine(LogWriter,
                                                                            string.Format(Messages.ErrorDuringConversion, ex.ToString()));
                return(RunStatus.Error);
            }

            return(RunStatus.Success);
        }
Beispiel #2
0
        /// <summary>
        /// Refresh the SAS program based on the output data field
        /// </summary>
        private void RefreshCodeView()
        {
            SAS.Tasks.Toolkit.Data.SasData sd = new SAS.Tasks.Toolkit.Data.SasData(Consumer.ActiveData as ISASTaskData2);

            DatasetConverter.AssignLocalLibraryIfNeeded(Consumer, TaskModel);

            DatasetConverter convert = new DatasetConverter(
                sd.Server,
                sd.Libref,
                sd.Member);

            // Put just the DATA step definition in the preview window
            // This is a quick operation.  If the data set is large,
            // it could take several moments to populate all of the data
            // values, so we skip that part for the preview.
            sasCodeEditor.EditorText = convert.GetJustDataStepDefinition(txtOutput.Text);
        }
        /// <summary>
        /// Performs the main work of this task.
        /// </summary>
        /// <param name="LogWriter">A log interface that you can use to report messages.</param>
        /// <returns>a status code: did it succeed or fail with errors?</returns>
        public RunStatus Run(ISASTaskTextWriter LogWriter)
        {
            try
            {
                string code = "";

                SAS.Tasks.Toolkit.Data.SasData sd = new SAS.Tasks.Toolkit.Data.SasData(Consumer.ActiveData as ISASTaskData2);
                DatasetConverter.AssignLocalLibraryIfNeeded(Consumer, this);

                DatasetConverter convert = new DatasetConverter(
                    sd.Server,
                    sd.Libref,
                    sd.Member);

                code = convert.GetCompleteSasProgram(OutputData);

                // this builds up the result structure.  It contains the SAS program
                // that was constructed.  By tagging it with the
                // "application/x-sas" mime type, that serves as a cue
                // to SAS Enterprise Guide to treat this as the generated SAS
                // program in the project.
                _resultInfo = new SAS.Tasks.Toolkit.Helpers.ResultInfo();
                if (PreserveEncoding)
                    _resultInfo.Bytes = System.Text.Encoding.UTF8.GetBytes(code.ToCharArray());
                else
                    _resultInfo.Bytes = System.Text.Encoding.ASCII.GetBytes(code.ToCharArray());
                _resultInfo.MimeType = "application/x-sas";
                _resultInfo.OriginalFileName = string.Format("{0}.sas", Consumer.ActiveData.Member);

                // this puts a summary message into the Log portion of the
                // task in SAS Enterprise Guide
                SAS.Tasks.Toolkit.Helpers.FormattedLogWriter.WriteNormalLine(LogWriter, Messages.ConvertedData);
                SAS.Tasks.Toolkit.Helpers.FormattedLogWriter.WriteNoteLine(LogWriter,
                    string.Format(Messages.ConvertedDataMetrics, convert.ColumnCount, convert.RowCount));

            }
            catch (Exception ex)
            {
                // catch any loose exceptions and report in the log
                SAS.Tasks.Toolkit.Helpers.FormattedLogWriter.WriteErrorLine(LogWriter,
                    string.Format(Messages.ErrorDuringConversion, ex.ToString()));
                return RunStatus.Error;
            }

            return RunStatus.Success;
        }
        /// <summary>
        /// Refresh the SAS program based on the output data field
        /// </summary>
        private void RefreshCodeView()
        {
            SAS.Tasks.Toolkit.Data.SasData sd = new SAS.Tasks.Toolkit.Data.SasData(Consumer.ActiveData as ISASTaskData2);

            DatasetConverter.AssignLocalLibraryIfNeeded(Consumer,TaskModel);

            DatasetConverter convert = new DatasetConverter(
                sd.Server,
                sd.Libref,
                sd.Member);

            // Put just the DATA step definition in the preview window
            // This is a quick operation.  If the data set is large,
            // it could take several moments to populate all of the data
            // values, so we skip that part for the preview.
            sasCodeEditor.EditorText = convert.GetJustDataStepDefinition(txtOutput.Text);
        }