private IConnectedServer CreateServerConnection(ConnectionModel connectionModel)
 {
     return(ServerManager.ConnectToServer(
                connectionModel.ServerName,
                connectionModel.Port,
                connectionModel.UserName,
                _passwordService.CreateSecurePassword(connectionModel.Password),
                connectionModel.Binding));
 }
        /// <summary>
        /// Establishes a connection to a Blaise server.
        /// </summary>
        /// <param name="serverName">The location of the Blaise server.</param>
        /// <param name="userName">Username with access to the specified server.</param>
        /// <param name="password">Password for the specified user to access the server.</param>
        /// <param name="binding">Binding for the specified server.</param>
        /// <returns>A IConnectedServer2 object which is connected to the server provided.</returns>
        public IConnectedServer2 ConnectToBlaiseServer(string serverName, string userName, string password, string binding)
        {
            int port = 8031;

            try
            {
                IConnectedServer2 connServer =
                    (IConnectedServer2)ServerManager.ConnectToServer(serverName, port, userName, GetPassword(password), binding);

                return(connServer);
            }
            catch (Exception e)
            {
                log.Error("Error getting Blaise connection.");
                log.Error(e.Message);
                return(null);
            }
        }
        /// <summary>
        /// Method for connecting to Blaise data sets.
        /// </summary>
        /// /// <param name="hostname">The name of the hostname.</param>
        /// <param name="instrumentName">The name of the instrument.</param>
        /// <param name="serverPark">The name of the server park.</param>
        /// <returns> IDataLink4 object for the connected server park.</returns>
        public static IDataLink4 GetDataLink(string hostname, string instrumentName, string serverPark)
        {
            // Get authenication details from the app.config file.
            // For now we assume all Blaise servers will have the same authenication details.
            string userName = ConfigurationManager.AppSettings["BlaiseServerUserName"];
            string password = ConfigurationManager.AppSettings["BlaiseServerPassword"];
            string binding  = ConfigurationManager.AppSettings["BlaiseServerBinding"];
            int    port     = 8031;

            // Get the GIID of the instrument.
            Guid instrumentID = Guid.NewGuid();

            try
            {
                // Connect to the Blaise Server Manager.
                IConnectedServer serManConn = ServerManager.ConnectToServer(hostname, port, userName, GetPassword(password), binding);

                // Loop through the surveys installed on the server to find the GUID of the survey we are working on.
                bool foundSurvey = false;
                foreach (ISurvey survey in serManConn.GetServerPark(serverPark).Surveys)
                {
                    if (survey.Name == instrumentName)
                    {
                        instrumentID = survey.InstrumentID;
                        foundSurvey  = true;
                    }
                }
                if (foundSurvey == false)
                {
                    log.Error("Survey " + instrumentName + " not found on " + serverPark + "@" + hostname + ".");
                }

                // Connect to the data.
                IRemoteDataServer dataLinkConn = DataLinkManager.GetRemoteDataServer(hostname, 8033, binding, userName, GetPassword(password));

                return(dataLinkConn.GetDataLink(instrumentID, serverPark));
            }
            catch (Exception e)
            {
                log.Error(e.Message);
                return(null);
            }
        }