コード例 #1
0
        /// <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);
        }
コード例 #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);
        }
コード例 #3
0
 /// <summary>
 /// In the special case where we have a local SAS data set file (sas7bdat),
 /// and a local SAS server, we have to make sure that there is a library
 /// assigned.  The DatasetConverter class can read data only from a
 /// data source that is accessed via a SAS library (LIBNAME.MEMBER).
 /// </summary>
 /// <param name="sd"></param>
 internal static void AssignLocalLibraryIfNeeded(ISASTaskConsumer3 consumer, SasTask taskModel)
 {
     SAS.Tasks.Toolkit.Data.SasData sd = new SAS.Tasks.Toolkit.Data.SasData(consumer.ActiveData as ISASTaskData2);
     // get a SasServer object so we can see if it's the "Local" server
     SAS.Tasks.Toolkit.SasServer server = new SAS.Tasks.Toolkit.SasServer(sd.Server);
     // local server with local file, so we have to assign library
     if (server.IsLocal)
     {
         // see if the data reference is a file path ("c:\data\myfile.sas7bdat")
         if (!string.IsNullOrEmpty(consumer.ActiveData.File) &&
             consumer.ActiveData.Source == SourceType.SasDataset &&
             consumer.ActiveData.File.Contains("\\"))
         {
             string path = System.IO.Path.GetDirectoryName(consumer.ActiveData.File);
             taskModel.SubmitSASProgramAndWait(string.Format("libname {0} \"{1}\";\r\n", sd.Libref, path));
         }
     }
 }
コード例 #4
0
 /// <summary>
 /// In the special case where we have a local SAS data set file (sas7bdat),
 /// and a local SAS server, we have to make sure that there is a library
 /// assigned.  
 /// </summary>
 /// <param name="sd"></param>
 internal static void AssignLocalLibraryIfNeeded(ISASTaskConsumer3 consumer)
 {
     SAS.Tasks.Toolkit.Data.SasData sd = new SAS.Tasks.Toolkit.Data.SasData(consumer.ActiveData as ISASTaskData2);
     // get a SasServer object so we can see if it's the "Local" server
     SAS.Tasks.Toolkit.SasServer server = new SAS.Tasks.Toolkit.SasServer(sd.Server);
     // local server with local file, so we have to assign library
     if (server.IsLocal)
     {
         // see if the data reference is a file path ("c:\data\myfile.sas7bdat")
         if (!string.IsNullOrEmpty(consumer.ActiveData.File) &&
             consumer.ActiveData.Source == SourceType.SasDataset &&
             consumer.ActiveData.File.Contains("\\"))
         {
             string path = System.IO.Path.GetDirectoryName(consumer.ActiveData.File);
             SasSubmitter submitter = new SasSubmitter(sd.Server);
             string log;
             submitter.SubmitSasProgramAndWait(string.Format("libname {0} \"{1}\";\r\n", sd.Libref, path), out log);
         }
     }
 }
コード例 #5
0
        /// <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;
        }
コード例 #6
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);
        }