/// <summary>
 /// Get the details about the SAS option
 /// and its value
 /// </summary>
 /// <param name="optionName">Name of the option</param>
 /// <param name="whereset">return value: where the value was set</param>
 /// <param name="startup">return value: value at startup</param>
 /// <param name="fullval">return value: full value of the option</param>
 private void getOptionInfo(string optionName,
                            ref string whereset,
                            ref string startup,
                            ref string fullval)
 {
     whereset = "<cannot determine>";
     startup  = "<cannot determine>";
     try
     {
         SAS.Tasks.Toolkit.SasSubmitter submitter =
             new SasSubmitter(cmbServers.Text);
         if (!submitter.IsServerBusy())
         {
             string outLog;
             string program = string.Format(
                 optionDetails +
                 (dServerVer > 9.2 ? optionStartup : ""),
                 optionName);
             bool success = submitter.SubmitSasProgramAndWait(program, out outLog);
             if (success)
             {
                 SasServer s = new SasServer(cmbServers.Text);
                 whereset = s.GetSasMacroValue("_EGOPTHOWSET");
                 fullval  = s.GetSasMacroValue("_EGOPTFULLVAL");
                 if (dServerVer > 9.2)
                 {
                     startup = s.GetSasMacroValue("_EGOPTSTARTUP");
                 }
             }
         }
     }
     catch
     {
     }
 }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCalc_Click(object sender, EventArgs e)
        {
            string code = SAS.Tasks.Toolkit.Helpers.UtilityFunctions.ReadFileFromAssembly("SAS.Tasks.DataCardinality.getcardinality.sas");

            code +=
                string.Format("%getcardinality({0}, {1},0);\n",
                              SAS.Tasks.Toolkit.Helpers.TaskDataHelpers.GetSasCodeReference(Consumer.ActiveData as ISASTaskData2),
                              "work._ds_cardinalities"
                              );
            SasSubmitter s = new SasSubmitter(Consumer.AssignedServer);

            if (!s.IsServerBusy())
            {
                _savedCursor                = Cursor.Current;
                Cursor.Current              = Cursors.WaitCursor;
                s.SubmitSasProgramComplete += handle_SubmitSasProgramComplete;
                sasJobId    = s.SubmitSasProgram(code);
                progressdlg = new SubmitProgressForm();
                if (progressdlg.ShowDialog(this) == DialogResult.Cancel)
                {
                    s.CancelJob(sasJobId);
                    progressdlg = null;
                }
            }
            else
            {
                MessageBox.Show(string.Format("The server {0} is busy; cannot process cardinalities.", Consumer.AssignedServer));
            }
        }
Beispiel #3
0
        private void ViewFormatDetails(string p)
        {
            SasSubmitter s = new SasSubmitter(currentServer);

            if (s.IsServerBusy())
            {
                MessageBox.Show(string.Format(Translate.MessageServerBusy, currentServer), Translate.TitleError);
                return;
            }

            Cursor c = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;

            string[] parts = p.Split('.');
            if (parts.Length == 4)
            {
                // if this is an INFORMAT, the SELECT needs an @ symbol
                // if Char, then the $ symbol
                string prefix = "";
                switch (parts[3])
                {
                case "INFMT": prefix = "@";
                    break;

                case "FORMATC": prefix = "$";
                    break;

                case "INFMTC": prefix = "@$";
                    break;

                default: prefix = "";
                    break;
                }
                ;

                string code = string.Format(fmtProgram, parts[0], parts[1], parts[2], prefix);

                string log     = "";
                bool   success = s.SubmitSasProgramAndWait(code, out log);

                Cursor.Current = c;

                if (success)
                {
                    string formatReport = GetTextFromFileref("fmtout");

                    ListingViewForm dlg = new ListingViewForm();
                    dlg.Text    = string.Format(Translate.LabelFormatDefinition, parts[2], parts[0], parts[1]);
                    dlg.Content = formatReport;
                    dlg.ShowDialog(this);
                    s = null;
                }
                else
                {
                    MessageBox.Show(Translate.MessageErrorFormat, Translate.TitleError);
                }
            }
        }
Beispiel #4
0
        private void DeleteEntry(string catEntry)
        {
            SasSubmitter s = new SasSubmitter(currentServer);

            if (s.IsServerBusy())
            {
                MessageBox.Show(string.Format(Translate.MessageServerBusy, currentServer), Translate.TitleError);
                return;
            }

            if (catEntry.Length > 0)
            {
                if (DialogResult.Yes == MessageBox.Show(string.Format(Translate.MessageDeleteConfirm, catEntry),
                                                        Translate.TitleDeleteConfirm,
                                                        MessageBoxButtons.YesNo))
                {
                    Cursor c = Cursor.Current;
                    Cursor.Current = Cursors.WaitCursor;

                    string[] parts = catEntry.Split('.');

                    if (parts.Length == 4)
                    {
                        string code = string.Format("PROC CATALOG CATALOG={0}.{1}; DELETE {2}.{3}; RUN; ;*';*\";*/;quit;run;", parts[0], parts[1], parts[2], parts[3]);
                        string log  = "";

                        if (s.SubmitSasProgramAndWait(code, out log))
                        {
                            // refresh view
                            PopulateMembers(parts[0], parts[1]);
                            statusBar.Text = string.Format(Translate.MessageCatalogDeleted, catEntry);
                        }
                        else
                        {
                            MessageBox.Show(string.Format(Translate.MessageCatalogNotDeleted, catEntry), Translate.TitleError);
                        }
                    }
                    Cursor.Current = c;
                }
            }
        }
        /// <summary>
        /// This submits a bit of SAS code to run PROC IOMOPERATE
        /// The code is submitted asynchronously, so a cancel dialog is shown
        /// in case it runs longer than the user wants to wait
        /// </summary>
        private void RefreshProcesses()
        {
            string connectUrl = string.Format(SpawnerUrl, txtHost.Text, txtPort.Text, txtUser.Text, txtPW.Text);
            string code = SAS.Tasks.Toolkit.Helpers.UtilityFunctions.ReadFileFromAssembly("SAS.Tasks.SASProcesses.prociomoperate.sas");
            code = connectUrl + code;
            SasSubmitter s = new SasSubmitter(Consumer.AssignedServer);
            if (!s.IsServerBusy())
            {
                _savedCursor = Cursor.Current;
                Cursor.Current = Cursors.WaitCursor;
                s.SubmitSasProgramComplete += handle_SubmitSasProgramComplete;
                sasJobId = s.SubmitSasProgram(code);

                // show the Progress dialog with cancel button
                progressdlg = new SubmitProgressForm();
                if (progressdlg.ShowDialog(this) == DialogResult.Cancel)
                {
                    s.CancelJob(sasJobId);
                    progressdlg = null;
                }
            }
            else
                MessageBox.Show(string.Format("The server {0} is busy; cannot check server processes.", Consumer.AssignedServer));
        }
        private void btnKill_Click(object sender, EventArgs e)
        {
            if (listProcesses.SelectedItems.Count == 1)
            {
                SasServer serv = new SasServer(Consumer.AssignedServer);
                string thisProcess = serv.GetSasMacroValue("SYSJOBID");
                SasProcess proc = (listProcesses.SelectedItems[0].Tag as SasProcess);
                if (proc.PID.Trim() == thisProcess.Trim())
                {
                    // confirm before killing the current active SAS session
                    if (DialogResult.No ==
                        MessageBox.Show("The selected process is your active SAS session.  Do you still want to stop it?",
                        "Warning", MessageBoxButtons.YesNo))
                        return;
                }
                string log = "";
                string UUID = (listProcesses.SelectedItems[0].Tag as SasProcess).UUID;
                string program = string.Format(killProgram, UUID );
                SasSubmitter s = new SasSubmitter(Consumer.AssignedServer);

                if (s.IsServerBusy())
                {
                   MessageBox.Show(string.Format("The server {0} is busy; cannot end selected process.", Consumer.AssignedServer));
                    // bail out, return control to UI
                   return;
                }

                // server is available, so submit code synchronously
                bool success = s.SubmitSasProgramAndWait(program, out log);
                if (success)
                    RefreshProcesses();
                else
                {
                    // ERROR - provide option to show the SAS log
                    if (DialogResult.Yes ==
                    MessageBox.Show("An error occurred while trying to end the selected process.  Would you like to view the error log?",
                        "Error",
                        MessageBoxButtons.YesNo))
                    {
                        SAS.Tasks.Toolkit.Controls.SASLogViewDialog logView =
                            new SASLogViewDialog("Error log", "PROC IOMOPERATE log:", log);
                        logView.ShowDialog(this);
                    };
                }
            }
        }
        /// <summary>
        /// Submit a bit of code to assign a macro var to with the
        /// expression, and then retrieve the resulting value.
        /// If ERROR, show the error in the field instead
        /// </summary>
        /// <param name="expression">
        /// Expression to evaluate as macro expression
        /// </param>
        /// <param name="sasServer">
        /// Name of the SAS server
        /// </param>
        private void SolveExpression(string expression, string sasServer)
        {
            // set UI elements to default state
            txtEval.ForeColor = SystemColors.WindowText;
            Cursor c = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;

            // prepare to measure the time it takes to run
            DateTime start = DateTime.Now;
            try
            {
                if (!string.IsNullOrEmpty(expression))
                {
                    // disable solve button while running
                    btnSolve.Enabled = false;

                    string resolveProgram =
                        string.Format("%let _egMacroQuickEval = {0};",
                          expression);
                    string outLog;
                    SAS.Tasks.Toolkit.SasSubmitter submitter = new SasSubmitter(sasServer);

                    // show busy message if needed
                    if (submitter.IsServerBusy())
                    {
                        MessageBox.Show(
                            string.Format("Unable evaluate expression using {0}: Server is running another program.",
                              sasServer),
                              "Server busy");
                    }
                    else
                    {
                        // submit expression and wait
                        bool success = submitter.SubmitSasProgramAndWait(resolveProgram, out outLog);
                        if (success)
                        {
                            SasServer s = new SasServer(sasServer);
                            txtEval.Text = s.GetSasMacroValue("_EGMACROQUICKEVAL");

                            // scan output log for warning messages
                            string[] lines = outLog.Split('\n');
                            string msg = "";
                            foreach (string l in lines)
                            {
                                // WARNING lines prefixed with 'w'
                                if (l.StartsWith("w"))
                                {
                                    // color WARNINGs blue
                                    msg = msg + l.Substring(2) + Environment.NewLine;
                                    txtEval.ForeColor = Color.Blue;
                                }
                            }
                            txtEval.Text += Environment.NewLine + msg;
                        }
                        else
                        {
                            // scan output log for error lines
                            string[] lines = outLog.Split('\n');
                            string msg = "";
                            foreach (string l in lines)
                            {
                                // ERROR lines prefixed with 'e', WARNING with 'w'
                                if (l.StartsWith("w") || l.StartsWith("e"))
                                    msg = msg + l.Substring(2) + Environment.NewLine;
                            }
                            // color ERRORs red
                            txtEval.Text = msg;
                            txtEval.ForeColor = Color.Red;
                        }
                    }
                }
            }
            // catch any errant exceptions
            catch (Exception ex)
            {
                MessageBox.Show(
                    string.Format("Unable evaluate expression using {0}: {1}",
                      sasServer,
                      ex.Message),
                      "Error");
            }
            // finally block to clean/reset UI controls
            finally
            {
                btnSolve.Enabled = true;
                Cursor.Current = c;
                // add summary with timing
                TimeSpan s = new TimeSpan(DateTime.Now.Ticks - start.Ticks);
                stsMsgLabel.Text =
                    string.Format("Evaluated expression in {0} seconds",
                      Convert.ToInt32(s.TotalSeconds));
            }
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnCalc_Click(object sender, EventArgs e)
 {            
     string code = SAS.Tasks.Toolkit.Helpers.UtilityFunctions.ReadFileFromAssembly("SAS.Tasks.DataCardinality.getcardinality.sas");
     code += 
         string.Format("%getcardinality({0}, {1},0);\n",
         SAS.Tasks.Toolkit.Helpers.TaskDataHelpers.GetSasCodeReference(Consumer.ActiveData as ISASTaskData2),
         "work._ds_cardinalities"
         );
     SasSubmitter s = new SasSubmitter(Consumer.AssignedServer);
     if (!s.IsServerBusy())
     {
         _savedCursor = Cursor.Current;
         Cursor.Current = Cursors.WaitCursor;
         s.SubmitSasProgramComplete += handle_SubmitSasProgramComplete;
         sasJobId = s.SubmitSasProgram(code);
         progressdlg = new SubmitProgressForm();
         if (progressdlg.ShowDialog(this) == DialogResult.Cancel)
         {
             s.CancelJob(sasJobId);
             progressdlg = null;
         }
     }
     else
         MessageBox.Show(string.Format("The server {0} is busy; cannot process cardinalities.", Consumer.AssignedServer));
 }
Beispiel #9
0
        /// <summary>
        /// Submit a bit of code to assign a macro var to with the
        /// expression, and then retrieve the resulting value.
        /// If ERROR, show the error in the field instead
        /// </summary>
        /// <param name="expression">
        /// Expression to evaluate as macro expression
        /// </param>
        /// <param name="sasServer">
        /// Name of the SAS server
        /// </param>
        private void SolveExpression(string expression, string sasServer)
        {
            // set UI elements to default state
            txtEval.ForeColor = SystemColors.WindowText;
            Cursor c = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;

            // prepare to measure the time it takes to run
            DateTime start = DateTime.Now;

            try
            {
                if (!string.IsNullOrEmpty(expression))
                {
                    // disable solve button while running
                    btnSolve.Enabled = false;

                    string resolveProgram =
                        string.Format("%let _egMacroQuickEval = {0};",
                                      expression);
                    string outLog;
                    SAS.Tasks.Toolkit.SasSubmitter submitter = new SasSubmitter(sasServer);

                    // show busy message if needed
                    if (submitter.IsServerBusy())
                    {
                        MessageBox.Show(
                            string.Format("Unable evaluate expression using {0}: Server is running another program.",
                                          sasServer),
                            "Server busy");
                    }
                    else
                    {
                        // submit expression and wait
                        bool success = submitter.SubmitSasProgramAndWait(resolveProgram, out outLog);
                        if (success)
                        {
                            SasServer s = new SasServer(sasServer);
                            txtEval.Text = s.GetSasMacroValue("_EGMACROQUICKEVAL");

                            // scan output log for warning messages
                            string[] lines = outLog.Split('\n');
                            string   msg   = "";
                            foreach (string l in lines)
                            {
                                // WARNING lines prefixed with 'w'
                                if (l.StartsWith("w"))
                                {
                                    // color WARNINGs blue
                                    msg = msg + l.Substring(2) + Environment.NewLine;
                                    txtEval.ForeColor = Color.Blue;
                                }
                            }
                            txtEval.Text += Environment.NewLine + msg;
                        }
                        else
                        {
                            // scan output log for error lines
                            string[] lines = outLog.Split('\n');
                            string   msg   = "";
                            foreach (string l in lines)
                            {
                                // ERROR lines prefixed with 'e', WARNING with 'w'
                                if (l.StartsWith("w") || l.StartsWith("e"))
                                {
                                    msg = msg + l.Substring(2) + Environment.NewLine;
                                }
                            }
                            // color ERRORs red
                            txtEval.Text      = msg;
                            txtEval.ForeColor = Color.Red;
                        }
                    }
                }
            }
            // catch any errant exceptions
            catch (Exception ex)
            {
                MessageBox.Show(
                    string.Format("Unable evaluate expression using {0}: {1}",
                                  sasServer,
                                  ex.Message),
                    "Error");
            }
            // finally block to clean/reset UI controls
            finally
            {
                btnSolve.Enabled = true;
                Cursor.Current   = c;
                // add summary with timing
                TimeSpan s = new TimeSpan(DateTime.Now.Ticks - start.Ticks);
                stsMsgLabel.Text =
                    string.Format("Evaluated expression in {0} seconds",
                                  Convert.ToInt32(s.TotalSeconds));
            }
        }
 /// <summary>
 /// Get the details about the SAS option 
 /// and its value
 /// </summary>
 /// <param name="optionName">Name of the option</param>
 /// <param name="whereset">return value: where the value was set</param>
 /// <param name="startup">return value: value at startup</param>
 /// <param name="fullval">return value: full value of the option</param>
 private void getOptionInfo(string optionName, 
     ref string whereset, 
     ref string startup, 
     ref string fullval)
 {
     whereset = "<cannot determine>";
     startup = "<cannot determine>";
     try
     {
         SAS.Tasks.Toolkit.SasSubmitter submitter =
             new SasSubmitter(cmbServers.Text);
         if (!submitter.IsServerBusy())
         {
             string outLog;
             string program = string.Format(
                 optionDetails +
                 (dServerVer > 9.2 ? optionStartup : ""),
                 optionName);
             bool success = submitter.SubmitSasProgramAndWait(program, out outLog);
             if (success)
             {
                 SasServer s = new SasServer(cmbServers.Text);
                 whereset = s.GetSasMacroValue("_EGOPTHOWSET");
                 fullval = s.GetSasMacroValue("_EGOPTFULLVAL");
                 if (dServerVer > 9.2) startup = s.GetSasMacroValue("_EGOPTSTARTUP");
             }
         }
     }
     catch
     {
     }
 }