Exemplo n.º 1
0
        private IRemoteDataServer CreateRemoteConnection(ConnectionModel connectionModel)
        {
            var securePassword = _passwordService.CreateSecurePassword(connectionModel.Password);

            return(DataLinkManager.GetRemoteDataServer(
                       connectionModel.ServerName,
                       connectionModel.RemotePort,
                       connectionModel.Binding,
                       connectionModel.UserName,
                       securePassword));
        }
        /// <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);
            }
        }