/// <summary>
        /// Gets the server configuration using the organizationID stored in the UserSettings file
        /// </summary>
        /// <param name="serverURL">out: URL of the gitHub server to which the organisation belongs to</param>
        /// <param name="serverName">out: Name of the gitHub server to which the organisation belongs to</param>
        /// <param name="organizationName">out: Name of the organisation</param>
        /// <param name="author">out: author configured for that sever</param>
        /// <param name="encryptKey">out: encrypted key configured for that server</param>
        /// <param name="encryptedUserName">out: encrypted username</param>
        void getServerConfiguration(out string serverURL, out string serverName, out string organizationName, out string author, out string encryptKey, out string encryptedUserName, out string encryptedPassword, out string organizationID)
        {
            //The organizationID is obtained from the UserSetting file
            organizationID = EM_AppContext.Instance.GetUserSettingsAdministrator().Get().VCOrganizationID;
            serverURL      = string.Empty; serverName = string.Empty; organizationName = string.Empty; author = string.Empty; encryptKey = string.Empty; encryptedUserName = string.Empty; encryptedPassword = string.Empty;

            if (!String.IsNullOrEmpty(organizationID))
            {
                //The file is read
                VCServersInfo      serverInfo             = VCSettingsInfo.getVCServerInfoByOrganizationID(organizationID);
                VCOrganizationInfo organization           = null;
                string             selectedOrganizationID = organizationID;

                if (serverInfo != null)
                {
                    serverURL         = serverInfo.serverURL;
                    serverName        = serverInfo.serverName;
                    organization      = serverInfo.organizations.FirstOrDefault(o => o.organizationID == selectedOrganizationID);
                    author            = serverInfo.authorName;
                    encryptKey        = serverInfo.encryptKey;
                    encryptedUserName = serverInfo.encryptedUserName;
                    encryptedPassword = serverInfo.encryptedPassword;
                }

                if (organization != null)
                {
                    organizationName = organization.organizationName;
                }
                else
                {
                    organizationName = string.Empty;
                }
            }
        }
Ejemplo n.º 2
0
        private void btnOK_Click_1(object sender, EventArgs e)
        {
            //Proxy
            String proxyURLText  = proxyURL.Text.Trim();
            String proxyPortText = proxyPort.Text.Trim();
            bool   useProxy      = radioBtnYesProxy.Checked;
            bool   saveProxyConfigurationAndClose  = false;
            bool   saveServerConfigurationAndClose = false;

            if (!useProxy)
            {
                saveProxyConfigurationAndClose = true;
            }
            else
            {
                if (String.IsNullOrEmpty(proxyURLText) && String.IsNullOrEmpty(proxyPortText))
                {
                    MessageBox.Show("You haven't provided any values for proxy configuration. Please, provide proxy information or select 'Do not use proxy configuration'.");
                    saveProxyConfigurationAndClose = false;
                }
                else if ((String.IsNullOrEmpty(proxyURLText) && !String.IsNullOrEmpty(proxyPortText)) || (!String.IsNullOrEmpty(proxyURLText) && String.IsNullOrEmpty(proxyPortText)))
                {
                    MessageBox.Show("Both fields (proxy URL and proxy port) are needed to configure the proxy.");
                }
                else if (!Uri.IsWellFormedUriString(proxyURLText, UriKind.Absolute))
                {
                    MessageBox.Show("You need to insert a valid proxy URL (starting with http://) in the proxy URL field.");
                }
                else if (!int.TryParse(proxyPortText, out int n))
                {
                    MessageBox.Show("You need to insert a numberic value in proxy port.");
                }
                else
                {
                    saveProxyConfigurationAndClose = true;
                }
            }

            //Server
            var           selectedRadioButton = groupBox2.Controls.OfType <RadioButton>().Where(rb => rb.Checked).FirstOrDefault();
            VCServersInfo selectedServer      = null;
            string        orgID   = string.Empty;
            string        orgName = string.Empty;


            if (selectedRadioButton == null)
            {
                MessageBox.Show("You have to select and organization to connect to.");
                saveServerConfigurationAndClose = false;
            }
            else
            {
                orgName        = selectedRadioButton.Text;
                orgID          = selectedRadioButton.Tag.ToString();
                selectedServer = VCSettingsInfo.getVCServerInfoByOrganizationID(orgID);
                saveServerConfigurationAndClose = true;
            }

            if (saveProxyConfigurationAndClose && saveServerConfigurationAndClose)
            {
                //Proxy
                EM_AppContext.Instance.GetUserSettingsAdministrator().Get().VCProxyURL  = proxyURL.Text;
                EM_AppContext.Instance.GetUserSettingsAdministrator().Get().VCProxyPort = proxyPort.Text;
                EM_AppContext.Instance.GetUserSettingsAdministrator().Get().VCUseProxy  = radioBtnYesProxy.Checked;

                //Server
                EM_AppContext.Instance.GetUserSettingsAdministrator().Get().VCOrganizationID = orgID;

                EM_AppContext.Instance.GetUserSettingsAdministrator().SaveCurrentSettings(true);

                _vcAdministrator.setProxyConfiguration(proxyURL.Text, proxyPort.Text, radioBtnYesProxy.Checked);

                string userName = string.Empty; string password = string.Empty;
                _vcAdministrator.setServerConfiguration(selectedServer.serverURL, selectedServer.serverName, orgName, selectedServer.encryptKey, selectedServer.authorName, selectedServer.encryptedUserName, out userName, selectedServer.encryptedPassword, out password);

                DialogResult = System.Windows.Forms.DialogResult.OK;
                Close();
            }
        }