/// <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
     {
     }
 }
示例#2
0
        public override ShowResult Show(IWin32Window Owner)
        {
            try
            {
                if (flag)
                {
                    EGTitle = System.Diagnostics.Process.GetCurrentProcess().MainWindowTitle;
                    flag    = false;
                }

                IntPtr    hwnd   = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
                SasServer server = new SasServer(Consumer.AssignedServer);
                if (null != hwnd && WorkspaceID != server.GetWorkspaceIdentifier())
                {
                    string sas_pid = server.GetSasMacroValue("SYSJOBID");

                    string title = string.Format("{0} (EG_PID={1}; SAS_PID={2})", EGTitle,
                                                 System.Diagnostics.Process.GetCurrentProcess().Id, sas_pid);

                    SetWindowText(hwnd, title);

                    WorkspaceID = server.GetWorkspaceIdentifier();
                }
            }
            catch { };

            return(ShowResult.Canceled);
        }
        private void RetrieveOptionValues()
        {
            SasServer s = cmbServers.SelectedItem as SasServer;

            dServerVer = 9.2;
            string ver = s.GetSasMacroValue("SYSVER");

            try
            {
                dServerVer = Convert.ToDouble(ver);
            }
            catch { }


            using (System.Data.OleDb.OleDbConnection dbConnection = s.GetOleDbConnection())
            {
                //----- make provider connection
                dbConnection.Open();

                //----- Read values from query command
                string          sql        = @"select * from sashelp.vallopt order by optname";
                OleDbCommand    cmdDB      = new OleDbCommand(sql, dbConnection);
                OleDbDataReader dataReader = cmdDB.ExecuteReader(CommandBehavior.CloseConnection);
                try
                {
                    Options = new List <Option>();
                    while (dataReader.Read())
                    {
                        Option opt = new Option()
                        {
                            Name        = dataReader["optname"].ToString(),
                            Setting     = dataReader["setting"].ToString(),
                            Type        = dataReader["opttype"].ToString(),
                            Description = dataReader["optdesc"].ToString(),
                            Level       = dataReader["level"].ToString(),
                            Start       = dServerVer > 9.2 ? dataReader["optstart"].ToString() : "",
                            Group       = dataReader["group"].ToString()
                        };

                        if (opt.Level.ToUpper() == "GRAPH")
                        {
                            opt.Group = "GRAPH";
                            opt.Level = "Portable";
                            opt.Start = "OPTIONS or GOPTIONS statement";
                        }
                        switch (opt.Start.ToLower())
                        {
                        case "anytime": opt.Start = "OPTIONS statement or startup";
                            break;

                        case "startup": opt.Start = "Startup only";
                            break;

                        case "": opt.Start = opt.Start = "(requires SAS 9.3 or later to determine)";
                            break;

                        default: break;
                        }
                        ;


                        Options.Add(opt);
                    }
                }

                finally
                {
                    dataReader.Close();
                    dbConnection.Close();
                }
            }
        }
        // When code query is complete, read the process details from
        // a SAS data set on the server session.
        // Use this to populate the list view of processes.
        private void AddProcesses()
        {
            listProcesses.BeginUpdate();
            listProcesses.Items.Clear();
            SasServer s = new SasServer(Consumer.AssignedServer);
            string thisProcess = s.GetSasMacroValue("SYSJOBID");
            using (OleDbConnection conn = s.GetOleDbConnection())
            {
                try
                {
                    //----- make provider connection
                    conn.Open();

                    //----- Read values from query command
                    string sql = @"select * from work._allpids_";
                    OleDbCommand cmdDB = new OleDbCommand(sql, conn);
                    OleDbDataReader dataReader = cmdDB.ExecuteReader(CommandBehavior.CloseConnection);
                    while (dataReader.Read())
                    {
                        // create an in-memory object of the process
                        // so we can use this in a PropertyGrid control later
                        SasProcess proc = new SasProcess();
                        proc.PID = dataReader["ProcessIdentifier"].ToString().Trim();
                        proc.Host = dataReader["HostKnownBy"].ToString().Trim();
                        proc.Type = dataReader["ServerComponentName"].ToString().Trim();
                        proc.ServerPort = dataReader["ServerPort"].ToString().Trim();
                        proc.UUID = dataReader["UniqueIdentifier"].ToString().Trim();
                        proc.CPUs = dataReader["CPUCount"].ToString().Trim();
                        proc.Command = dataReader["Command"].ToString().Trim();
                        proc.Owner = dataReader["ProcessOwner"].ToString().Trim();
                        proc.SASVersion = dataReader["VersionLong"].ToString().Trim();
                        proc.StartTime = dataReader["UpTime"].ToString().Trim();

                        ListViewItem li = new ListViewItem(proc.PID);
                        li.Tag = proc;
                        li.SubItems.Add(proc.Type);
                        li.SubItems.Add(proc.Host);
                        li.SubItems.Add(proc.Owner);
                        li.SubItems.Add(proc.StartTime);
                        li.SubItems.Add(proc.UUID);
                        if (proc.PID.Trim() == thisProcess.Trim()) li.BackColor = Color.LightGoldenrodYellow;
                        listProcesses.Items.Add(li);
                    }
                }
                catch
                {
                    MessageBox.Show("An error occurred while trying to retrieve the list of spawned processes.", "Cannot retrieve processes");
                }
                finally
                {
                   conn.Close();
                }
            }
            listProcesses.EndUpdate();
        }
        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);
                    };
                }
            }
        }
示例#6
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));
            }
        }
示例#7
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
     {
     }
 }