Ejemplo n.º 1
0
        //---------------------------------------------------------------------------------------//

        /// <summary>
        /// Get the ServiceBroker info for the specified name. Return null if the ServiceBroker's name is not in the list.
        /// </summary>
        /// <param name="sbName"></param>
        /// <returns></returns>
        public ServiceBrokerInfo GetServiceBrokerInfo(string sbName)
        {
            ServiceBrokerInfo serviceBrokerInfo = null;

            if (sbName != null)
            {
                // Remove whitespace
                sbName = sbName.Trim();

                //
                // Scan the allowed ServiceBroker info list for a matching entry
                //
                for (int i = 0; i < this.serviceBrokerInfoList.Count; i++)
                {
                    //
                    // Compare name - comparison is not case-sensitive
                    //
                    if (this.serviceBrokerInfoList[i].name.Equals(sbName, StringComparison.OrdinalIgnoreCase) == true)
                    {
                        //
                        // Save the ServiceBroker info
                        //
                        serviceBrokerInfo = this.serviceBrokerInfoList[i];
                        break;
                    }
                }
            }

            return(serviceBrokerInfo);
        }
Ejemplo n.º 2
0
        //---------------------------------------------------------------------------------------//

        public bool Update(ServiceBrokerInfo serviceBroker)
        {
            const string STRLOG_MethodName = "Update";

            string logMessage = STRLOG_name + Logfile.STRLOG_Quote + serviceBroker.name + Logfile.STRLOG_Quote;

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            //
            // Catch all exceptions thrown and return false if an error occurred.
            //
            bool success = false;

            try
            {
                //
                // Update queued experiment status
                //
                SqlCommand sqlCommand = new SqlCommand(STRSQLCMD_UpdateServiceBroker, this.sqlConnection);
                sqlCommand.CommandType = CommandType.StoredProcedure;

                sqlCommand.Parameters.Add(new SqlParameter(STRSQLPRM_Name, serviceBroker.name));
                sqlCommand.Parameters.Add(new SqlParameter(STRSQLPRM_Guid, serviceBroker.guid));
                sqlCommand.Parameters.Add(new SqlParameter(STRSQLPRM_IncomingPasskey, serviceBroker.incomingPasskey));
                sqlCommand.Parameters.Add(new SqlParameter(STRSQLPRM_OutgoingPasskey, serviceBroker.outgoingPasskey));
                sqlCommand.Parameters.Add(new SqlParameter(STRSQLPRM_WebServiceUrl, serviceBroker.webServiceUrl));
                sqlCommand.Parameters.Add(new SqlParameter(STRSQLPRM_IsAllowed, serviceBroker.isAllowed));

                try
                {
                    this.sqlConnection.Open();

                    success = (sqlCommand.ExecuteNonQuery() != 0);
                }
                catch (SqlException ex)
                {
                    throw new Exception(STRERR_SqlException + ex.Message);
                }
                catch (Exception ex)
                {
                    throw new Exception(STRERR_Exception + ex.Message);
                }
                finally
                {
                    this.sqlConnection.Close();
                }
            }
            catch (Exception ex)
            {
                Logfile.WriteError(ex.Message);
            }

            logMessage = STRLOG_success + success.ToString();

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return(success);
        }
        //=======================================================================================//
        private List<ServiceBrokerInfo> RetrieveAll()
        {
            const string STRLOG_MethodName = "RetrieveAll";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            List<ServiceBrokerInfo> serviceBrokerInfoList = new List<ServiceBrokerInfo>();

            try
            {
                SqlCommand sqlCommand = new SqlCommand(STRSQLCMD_RetrieveServiceBrokerAll, this.sqlConnection);
                sqlCommand.CommandType = CommandType.StoredProcedure;

                try
                {
                    this.sqlConnection.Open();

                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    while (sqlDataReader.Read() == true)
                    {
                        ServiceBrokerInfo serviceBrokerInfo = new ServiceBrokerInfo();

                        object sdrObject = null;
                        if ((sdrObject = sqlDataReader[STRSQL_Name]) != System.DBNull.Value)
                            serviceBrokerInfo.name = (string)sdrObject;
                        if ((sdrObject = sqlDataReader[STRSQL_Guid]) != System.DBNull.Value)
                            serviceBrokerInfo.guid = (string)sdrObject;
                        if ((sdrObject = sqlDataReader[STRSQL_OutgoingPasskey]) != System.DBNull.Value)
                            serviceBrokerInfo.outgoingPasskey = (string)sdrObject;
                        if ((sdrObject = sqlDataReader[STRSQL_IncomingPasskey]) != System.DBNull.Value)
                            serviceBrokerInfo.incomingPasskey = (string)sdrObject;
                        if ((sdrObject = sqlDataReader[STRSQL_WebServiceUrl]) != System.DBNull.Value)
                            serviceBrokerInfo.webServiceUrl = (string)sdrObject;
                        if ((sdrObject = sqlDataReader[STRSQL_IsAllowed]) != System.DBNull.Value)
                            serviceBrokerInfo.isAllowed = (bool)sdrObject;

                        //
                        // Add the ServiceBroker information to the list
                        //
                        serviceBrokerInfoList.Add(serviceBrokerInfo);
                    }
                    sqlDataReader.Close();
                }
                catch (SqlException ex)
                {
                    throw new Exception(STRERR_SqlException + ex.Message);
                }
                catch (Exception ex)
                {
                    throw new Exception(STRERR_Exception + ex.Message);
                }
                finally
                {
                    this.sqlConnection.Close();
                }
            }
            catch (Exception ex)
            {
                Logfile.WriteError(ex.Message);
            }

            string logMessage = STRLOG_count + serviceBrokerInfoList.Count.ToString();

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return serviceBrokerInfoList;
        }
        //---------------------------------------------------------------------------------------//
        public bool Update(ServiceBrokerInfo serviceBroker)
        {
            const string STRLOG_MethodName = "Update";

            string logMessage = STRLOG_name + Logfile.STRLOG_Quote + serviceBroker.name + Logfile.STRLOG_Quote;

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            //
            // Catch all exceptions thrown and return false if an error occurred.
            //
            bool success = false;
            try
            {
                //
                // Update queued experiment status
                //
                SqlCommand sqlCommand = new SqlCommand(STRSQLCMD_UpdateServiceBroker, this.sqlConnection);
                sqlCommand.CommandType = CommandType.StoredProcedure;

                sqlCommand.Parameters.Add(new SqlParameter(STRSQLPRM_Name, serviceBroker.name));
                sqlCommand.Parameters.Add(new SqlParameter(STRSQLPRM_Guid, serviceBroker.guid));
                sqlCommand.Parameters.Add(new SqlParameter(STRSQLPRM_IncomingPasskey, serviceBroker.incomingPasskey));
                sqlCommand.Parameters.Add(new SqlParameter(STRSQLPRM_OutgoingPasskey, serviceBroker.outgoingPasskey));
                sqlCommand.Parameters.Add(new SqlParameter(STRSQLPRM_WebServiceUrl, serviceBroker.webServiceUrl));
                sqlCommand.Parameters.Add(new SqlParameter(STRSQLPRM_IsAllowed, serviceBroker.isAllowed));

                try
                {
                    this.sqlConnection.Open();

                    success = (sqlCommand.ExecuteNonQuery() != 0);
                }
                catch (SqlException ex)
                {
                    throw new Exception(STRERR_SqlException + ex.Message);
                }
                catch (Exception ex)
                {
                    throw new Exception(STRERR_Exception + ex.Message);
                }
                finally
                {
                    this.sqlConnection.Close();
                }
            }
            catch (Exception ex)
            {
                Logfile.WriteError(ex.Message);
            }

            logMessage = STRLOG_success + success.ToString();

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return success;
        }
        //---------------------------------------------------------------------------------------//
        public ServiceBrokerInfo Retrieve(string guid)
        {
            const string STRLOG_MethodName = "Retrieve";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            ServiceBrokerInfo serviceBrokerInfo = null;

            try
            {
                SqlCommand sqlCommand = new SqlCommand(STRSQLCMD_RetrieveServiceBroker, this.sqlConnection);
                sqlCommand.CommandType = CommandType.StoredProcedure;

                sqlCommand.Parameters.Add(new SqlParameter(STRSQLPRM_Guid, guid));

                try
                {
                    this.sqlConnection.Open();

                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    if (sqlDataReader.Read() == true)
                    {
                        serviceBrokerInfo = new ServiceBrokerInfo();

                        //
                        // Get the experiment information from waiting experiment
                        //
                        object sdrObject = null;
                        if ((sdrObject = sqlDataReader[STRSQL_Name]) != System.DBNull.Value)
                            serviceBrokerInfo.name = (string)sdrObject;
                        if ((sdrObject = sqlDataReader[STRSQL_Guid]) != System.DBNull.Value)
                            serviceBrokerInfo.guid = (string)sdrObject;
                        if ((sdrObject = sqlDataReader[STRSQL_OutgoingPasskey]) != System.DBNull.Value)
                            serviceBrokerInfo.outgoingPasskey = (string)sdrObject;
                        if ((sdrObject = sqlDataReader[STRSQL_IncomingPasskey]) != System.DBNull.Value)
                            serviceBrokerInfo.incomingPasskey = (string)sdrObject;
                        if ((sdrObject = sqlDataReader[STRSQL_WebServiceUrl]) != System.DBNull.Value)
                            serviceBrokerInfo.webServiceUrl = (string)sdrObject;
                        if ((sdrObject = sqlDataReader[STRSQL_IsAllowed]) != System.DBNull.Value)
                            serviceBrokerInfo.isAllowed = (bool)sdrObject;
                    }
                    sqlDataReader.Close();
                }
                catch (SqlException ex)
                {
                    throw new Exception(STRERR_SqlException + ex.Message);
                }
                catch (Exception ex)
                {
                    throw new Exception(STRERR_Exception + ex.Message);
                }
                finally
                {
                    this.sqlConnection.Close();
                }
            }
            catch (Exception ex)
            {
                Logfile.WriteError(ex.Message);
            }

            string logMessage = null;
            if (serviceBrokerInfo != null)
            {
                logMessage = STRLOG_name + serviceBrokerInfo.name;
            }
            else
            {
                logMessage = STRLOG_ServiceBrokerNotFound;
            }

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return serviceBrokerInfo;
        }
Ejemplo n.º 6
0
        //=======================================================================================//

        private List <ServiceBrokerInfo> RetrieveAll()
        {
            const string STRLOG_MethodName = "RetrieveAll";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            List <ServiceBrokerInfo> serviceBrokerInfoList = new List <ServiceBrokerInfo>();

            try
            {
                SqlCommand sqlCommand = new SqlCommand(STRSQLCMD_RetrieveServiceBrokerAll, this.sqlConnection);
                sqlCommand.CommandType = CommandType.StoredProcedure;

                try
                {
                    this.sqlConnection.Open();

                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    while (sqlDataReader.Read() == true)
                    {
                        ServiceBrokerInfo serviceBrokerInfo = new ServiceBrokerInfo();

                        object sdrObject = null;
                        if ((sdrObject = sqlDataReader[STRSQL_Name]) != System.DBNull.Value)
                        {
                            serviceBrokerInfo.name = (string)sdrObject;
                        }
                        if ((sdrObject = sqlDataReader[STRSQL_Guid]) != System.DBNull.Value)
                        {
                            serviceBrokerInfo.guid = (string)sdrObject;
                        }
                        if ((sdrObject = sqlDataReader[STRSQL_OutgoingPasskey]) != System.DBNull.Value)
                        {
                            serviceBrokerInfo.outgoingPasskey = (string)sdrObject;
                        }
                        if ((sdrObject = sqlDataReader[STRSQL_IncomingPasskey]) != System.DBNull.Value)
                        {
                            serviceBrokerInfo.incomingPasskey = (string)sdrObject;
                        }
                        if ((sdrObject = sqlDataReader[STRSQL_WebServiceUrl]) != System.DBNull.Value)
                        {
                            serviceBrokerInfo.webServiceUrl = (string)sdrObject;
                        }
                        if ((sdrObject = sqlDataReader[STRSQL_IsAllowed]) != System.DBNull.Value)
                        {
                            serviceBrokerInfo.isAllowed = (bool)sdrObject;
                        }

                        //
                        // Add the ServiceBroker information to the list
                        //
                        serviceBrokerInfoList.Add(serviceBrokerInfo);
                    }
                    sqlDataReader.Close();
                }
                catch (SqlException ex)
                {
                    throw new Exception(STRERR_SqlException + ex.Message);
                }
                catch (Exception ex)
                {
                    throw new Exception(STRERR_Exception + ex.Message);
                }
                finally
                {
                    this.sqlConnection.Close();
                }
            }
            catch (Exception ex)
            {
                Logfile.WriteError(ex.Message);
            }

            string logMessage = STRLOG_count + serviceBrokerInfoList.Count.ToString();

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return(serviceBrokerInfoList);
        }
Ejemplo n.º 7
0
        //---------------------------------------------------------------------------------------//

        public ServiceBrokerInfo Retrieve(string guid)
        {
            const string STRLOG_MethodName = "Retrieve";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            ServiceBrokerInfo serviceBrokerInfo = null;

            try
            {
                SqlCommand sqlCommand = new SqlCommand(STRSQLCMD_RetrieveServiceBroker, this.sqlConnection);
                sqlCommand.CommandType = CommandType.StoredProcedure;

                sqlCommand.Parameters.Add(new SqlParameter(STRSQLPRM_Guid, guid));

                try
                {
                    this.sqlConnection.Open();

                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    if (sqlDataReader.Read() == true)
                    {
                        serviceBrokerInfo = new ServiceBrokerInfo();

                        //
                        // Get the experiment information from waiting experiment
                        //
                        object sdrObject = null;
                        if ((sdrObject = sqlDataReader[STRSQL_Name]) != System.DBNull.Value)
                        {
                            serviceBrokerInfo.name = (string)sdrObject;
                        }
                        if ((sdrObject = sqlDataReader[STRSQL_Guid]) != System.DBNull.Value)
                        {
                            serviceBrokerInfo.guid = (string)sdrObject;
                        }
                        if ((sdrObject = sqlDataReader[STRSQL_OutgoingPasskey]) != System.DBNull.Value)
                        {
                            serviceBrokerInfo.outgoingPasskey = (string)sdrObject;
                        }
                        if ((sdrObject = sqlDataReader[STRSQL_IncomingPasskey]) != System.DBNull.Value)
                        {
                            serviceBrokerInfo.incomingPasskey = (string)sdrObject;
                        }
                        if ((sdrObject = sqlDataReader[STRSQL_WebServiceUrl]) != System.DBNull.Value)
                        {
                            serviceBrokerInfo.webServiceUrl = (string)sdrObject;
                        }
                        if ((sdrObject = sqlDataReader[STRSQL_IsAllowed]) != System.DBNull.Value)
                        {
                            serviceBrokerInfo.isAllowed = (bool)sdrObject;
                        }
                    }
                    sqlDataReader.Close();
                }
                catch (SqlException ex)
                {
                    throw new Exception(STRERR_SqlException + ex.Message);
                }
                catch (Exception ex)
                {
                    throw new Exception(STRERR_Exception + ex.Message);
                }
                finally
                {
                    this.sqlConnection.Close();
                }
            }
            catch (Exception ex)
            {
                Logfile.WriteError(ex.Message);
            }

            string logMessage = null;

            if (serviceBrokerInfo != null)
            {
                logMessage = STRLOG_name + serviceBrokerInfo.name;
            }
            else
            {
                logMessage = STRLOG_ServiceBrokerNotFound;
            }

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return(serviceBrokerInfo);
        }
Ejemplo n.º 8
0
        //---------------------------------------------------------------------------------------//

        /// <summary>
        /// Search the allowed ServiceBroker info list for the specified GUID and passkey.
        /// Return the ServiceBroker's name if found, otherwise return null.
        /// </summary>
        /// <param name="guid"></param>
        /// <param name="sbToLsPasskey"></param>
        /// <returns></returns>
        public string Authentication(string guid, string outgoingPassKey)
        {
            //const string STRLOG_MethodName = "Authentication";

            //Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            string serviceBrokerName = null;

            //
            // Check special case where call is made directly from the LabServerWebService web page
            // on the localhost during application development and testing.
            //
            if (this.isAuthenticating == false && guid == null && outgoingPassKey == null)
            {
                // ServiceBroker is localhost where SOAP header contains no information
                serviceBrokerName = STR_localhost;
            }
            else
            {
                try
                {
                    //
                    // Check for ServiceBroker GUID
                    //
                    if (guid == null)
                    {
                        throw new ArgumentNullException(STR_guid);
                    }

                    //
                    // Check for Outgoing Passkey (ServiceBroker to LabServer)
                    //
                    if (outgoingPassKey == null)
                    {
                        throw new ArgumentNullException(STR_outgoingPasskey);
                    }

                    //
                    // Remove whitespace
                    //
                    guid            = guid.Trim();
                    outgoingPassKey = outgoingPassKey.Trim();

                    //
                    // Check if the GUID and passkey should be logged
                    //
                    if (this.isLoggingServiceBroker == true)
                    {
                        // Log ServiceBroker's GUID and passkey
                        Logfile.Write(STRLOG_Guid + guid);
                        Logfile.Write(STRLOG_OutgoingPasskey + outgoingPassKey);
                    }

                    //
                    // Scan the allowed ServiceBroker info list for a matching entry
                    //
                    for (int i = 0; i < this.serviceBrokerInfoList.Count; i++)
                    {
                        ServiceBrokerInfo serviceBrokerInfo = this.serviceBrokerInfoList[i];

                        //
                        // Find matching GUID - comparison is not case-sensitive
                        //
                        if (guid.Equals(serviceBrokerInfo.guid, StringComparison.OrdinalIgnoreCase) == true)
                        {
                            // Found GUID, now check the passkey - comparison is not case-sensitive
                            if (outgoingPassKey.Equals(serviceBrokerInfo.outgoingPasskey, StringComparison.OrdinalIgnoreCase) == true)
                            {
                                // ServiceBroker found, now check if ServiceBroker is allowed
                                if (serviceBrokerInfo.isAllowed == false)
                                {
                                    // ServiceBroker is not allowed
                                    throw new ArgumentException(STRERR_ServiceBrokerNotAllowed, serviceBrokerInfo.name);
                                }

                                // ServiceBroker is allowed
                                serviceBrokerName = serviceBrokerInfo.name;
                                break;
                            }
                            else
                            {
                                // Passkey does not match, caller not allowed
                                throw new ArgumentException(STRERR_IncorrectPasskey, serviceBrokerInfo.name);
                            }
                        }
                    }

                    if (serviceBrokerName == null)
                    {
                        // ServiceBroker not found in list
                        throw new ArgumentException(STRERR_ServiceBrokerNotFound);
                    }

                    // Caller found
                    Logfile.Write(STRLOG_ServiceBrokerAuthenticated + Logfile.STRLOG_Quote + serviceBrokerName + Logfile.STRLOG_Quote);
                }
                catch (Exception ex)
                {
                    // Log the message but don't throw the exception back to the caller
                    Logfile.WriteError(ex.Message);
                }
            }

            //Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName);

            return(serviceBrokerName);
        }
Ejemplo n.º 9
0
        //---------------------------------------------------------------------------------------//

        /// <summary>
        ///
        /// </summary>
        /// <param name="experimentID"></param>
        /// <param name="sbName"></param>
        /// <returns>True if the ServiceBroker was successfully notified.</returns>
        public bool Notify(int experimentId, string sbName)
        {
            const string STRLOG_MethodName = "Notify";

            string logMessage = STRLOG_experimentId + experimentId.ToString() +
                                Logfile.STRLOG_Spacer + STRLOG_sbName + Logfile.STRLOG_Quote + sbName + Logfile.STRLOG_Quote;

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            bool success = true;

            //
            // Get the ServiceBroker's web service URL for notification
            //
            ServiceBrokerInfo serviceBrokerInfo = this.allowedServiceBrokers.GetServiceBrokerInfo(sbName);
            string            webServiceUrl     = serviceBrokerInfo.webServiceUrl;

            if (webServiceUrl != null && webServiceUrl.Length > 0)
            {
                //
                // Notify Url is specified so notify ServiceBroker
                //
                try
                {
                    Logfile.Write(STRLOG_webServiceUrl + webServiceUrl);

                    //
                    // Get the passkey for notification
                    //
                    string lsToSbPasskey = serviceBrokerInfo.incomingPasskey;
                    if (lsToSbPasskey == null)
                    {
                        throw new ArgumentNullException(STRLOG_lsToSbPasskey);
                    }

                    //Trace.WriteLine(STRLOG_lsToSbPasskey + lsToSbPasskey);

                    //
                    // Get LabServer Id from application's configuration file
                    //
                    string str = Utilities.GetAppSetting(Consts.STRCFG_LabServerGuid);
                    str = str.Substring(0, 16);
                    Int64 labServerId = Convert.ToInt64(str, 16);

                    //Trace.WriteLine(STRLOG_labServerId + "0x" + labServerId.ToString("X"));

                    //
                    // Create ServiceBroker interface
                    //
                    ServiceBrokerService serviceBroker = new ServiceBrokerService();
                    serviceBroker.Url = webServiceUrl;

                    //
                    // Create and fill in authorisation information
                    //
                    sbAuthHeader sbHeader = new sbAuthHeader();
                    sbHeader.couponID               = labServerId;
                    sbHeader.couponPassKey          = lsToSbPasskey;
                    serviceBroker.sbAuthHeaderValue = sbHeader;

                    //
                    // Notify the ServiceBroker that this experiment has finished
                    //
                    serviceBroker.Notify(experimentId);
                }
                catch (Exception ex)
                {
                    //
                    // ServiceBroker notification failed
                    //
                    logMessage = ex.Message;
                    if (ex.InnerException != null)
                    {
                        logMessage += " ==>> " + ex.InnerException.Message;
                    }
                    Logfile.WriteError(logMessage);

                    success = false;
                }
            }
            else
            {
                //
                // Notify Url is not specified so cannot notify ServiceBroker
                //
                Logfile.Write(STRLOG_SbNotifyUrlNotSpecified);
            }

            logMessage = STRLOG_success + success.ToString();

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return(success);
        }