private void ConnectToServer()
        {
            activeSession = new SasServer();

            string settingsFile = Path.Combine(Application.LocalUserAppDataPath, appSettings);

            if (File.Exists(settingsFile))
            {
                string xml = File.ReadAllText(settingsFile);
                activeSession = SasServer.FromXml(xml);
            }
            SasServerLoginDlg login = new SasServerLoginDlg(activeSession);

            if (login.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                activeSession = login.SasServer;

                try
                {
                    activeSession.Connect();
                    File.WriteAllText(settingsFile, activeSession.ToXml());
                    if (activeSession.UseLocal)
                    {
                        statusMsg.Text = string.Format("Connected to Local SAS session as {0}",
                                                       System.Environment.UserName);
                    }
                    else
                    {
                        statusMsg.Text = string.Format("Connected to {0} ({1}) as {2}",
                                                       activeSession.Name,
                                                       activeSession.Host,
                                                       string.IsNullOrEmpty(activeSession.UserId) ? Environment.UserName : activeSession.UserId);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("Could not connect: {0}", ex.Message));
                    statusMsg.Text = "";
                }
            }
        }
Esempio n. 2
0
        private void ConnectToServer()
        {
            activeSession = new SasServer();

            string settingsFile = Path.Combine(Application.LocalUserAppDataPath, appSettings);
            if (File.Exists(settingsFile))
            {
                string xml = File.ReadAllText(settingsFile);
                activeSession = SasServer.FromXml(xml);
            }
            SasServerLoginDlg login = new SasServerLoginDlg(activeSession);

            if (login.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                activeSession = login.SasServer;

                try
                {
                    activeSession.Connect();
                    File.WriteAllText(settingsFile, activeSession.ToXml());
                    if (activeSession.UseLocal)
                        statusMsg.Text = string.Format("Connected to Local SAS session as {0}",
                            System.Environment.UserName);
                    else
                        statusMsg.Text = string.Format("Connected to {0} ({1}) as {2}",
                            activeSession.Name,
                            activeSession.Host,
                            string.IsNullOrEmpty(activeSession.UserId) ? Environment.UserName : activeSession.UserId);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("Could not connect: {0}", ex.Message));
                    statusMsg.Text = "";
                }
            }
        }