예제 #1
0
        private void Notify(NotificationData p_notification)
        {
            if (p_notification == null)
            return;

             if (p_notification.ClearCachedObjects == true)
             {
            m_growlConnectors.Clear(); // should put objects on GC list, but not sure of this

            if (m_logger.IsInfoEnabled)
               m_logger.Info("Cleared the cached Growl objects");
             }

             Sql2GrowlConnector connector = CheckConnector(p_notification);

             Sql2GrowlApplication application = CheckApplication(p_notification);

             // Every time a new type is added we have to register the application again with
             // the new type (and the previously registered types)
             //
             if (application.AddType( p_notification.TypeKey, p_notification.Type ) == true )
            connector.Connector.Register( application, application.Types );

             connector.Connector.Notify( new Notification(p_notification.Application, p_notification.TypeKey,
            "ID", p_notification.Title, p_notification.Message ) );

             m_lastNotification = p_notification;
        }
예제 #2
0
        private Sql2GrowlConnector CheckConnector(NotificationData p_notification)
        {
            if (m_growlConnectors.ContainsKey(p_notification.ConnectorKey) == false)
             {
            Sql2GrowlConnector connector = new Sql2GrowlConnector();

            if (string.IsNullOrEmpty(p_notification.Password) == false)
            {
               if (string.IsNullOrEmpty(p_notification.Host) == false && p_notification.Port > 0)
               {
                  connector.Connector = new GrowlConnector(p_notification.Password, p_notification.Host, p_notification.Port);
               }
               else
               {
                  connector.Connector = new GrowlConnector(p_notification.Password);
               }
            }

            connector.Connector.EncryptionAlgorithm = Cryptography.SymmetricAlgorithmType.PlainText;
            connector.Connector.ErrorResponse += new GrowlConnector.ResponseEventHandler(connector_ErrorResponse);

            m_growlConnectors.Add(p_notification.ConnectorKey, connector);
             }

             return m_growlConnectors[p_notification.ConnectorKey];
        }
예제 #3
0
        private NotificationData GetNextNotification()
        {
            SqlTransaction transaction = m_dbConnection.BeginTransaction();
             try
             {
            if (m_getNextRequestSp == null)
            {
               m_getNextRequestSp = m_dbConnection.CreateCommand();
               m_getNextRequestSp.CommandText = m_parent.Config.GetValue("NotificationProcedure");
               m_getNextRequestSp.CommandType = CommandType.StoredProcedure;
               m_getNextRequestSp.Parameters.Add("@ReturnValue", SqlDbType.Int)
                   .Direction = ParameterDirection.ReturnValue;

               m_getNextRequestSp.Parameters.Add("@TimeoutSec", SqlDbType.Int);

               m_getNextRequestSp.Prepare();
            }

            m_getNextRequestSp.CommandTimeout = m_queryExecuteIntervalSec + 30;
            m_getNextRequestSp.Parameters["@TimeoutSec"].Value = m_queryExecuteIntervalSec;

            m_getNextRequestSp.Transaction = transaction;

            NotificationData notification = null;

            using (SqlDataReader sqlReader = m_getNextRequestSp.ExecuteReader(CommandBehavior.SingleResult))
            {
               int returnValue = 0;
               if (m_getNextRequestSp.Parameters["@ReturnValue"].Value != null)
                  returnValue = (int)m_getNextRequestSp.Parameters["@ReturnValue"].Value;

               if (returnValue == 0 && sqlReader != null && sqlReader.HasRows == true)
               {
                  notification = new NotificationData();

                  while (sqlReader.Read() == true) // we should only get one row
                  {
                     notification.NotificationID = (Guid)sqlReader["NotificationID"];
                     notification.SetFromXml(sqlReader["NotificationXml"]);
                  }
               }
               else
               {
                  if (m_logger.IsInfoEnabled == true && returnValue != 0)
                  {
                     m_logger.InfoFormat("{0} procedure returned: {1}",
                        m_getNextRequestSp.CommandText, returnValue);
                  }

                  // no notification selected
                  //
                  notification = null;
               }
            }
            transaction.Commit();

            return notification;
             }
             catch (ThreadAbortException)
             {
            if (m_getNextRequestSp != null)
               m_getNextRequestSp.Cancel();

            throw;
             }
             catch (SqlException sex)
             {
            Rollback(transaction);

            if ( GetErrorCode(sex) == CommonSqlErrors.Deadlock )
            {
               if (m_logger.IsDebugEnabled)
               {
                  m_logger.DebugFormat("{0} procedure call was picked to be the victim of a deadlock",
                     m_getNextRequestSp.CommandText);
               }

               return null; // as if no notification was returned
            }

            if ( GetErrorCode( sex ) == CommonSqlErrors.ObjectNotFound )
            {
               // We need to reinitialize the procedure call
               //
               m_getNextRequestSp = null;
            }

            throw sex;
             }
             catch (Exception)
             {
            Rollback(transaction);
            throw;
             }
        }
예제 #4
0
        private Sql2GrowlApplication CheckApplication(NotificationData p_notification)
        {
            if (m_growlConnectors[p_notification.ConnectorKey].Applications.ContainsKey(
            p_notification.Application) == false)
             {
            Growl.CoreLibrary.Resource icon = null;

            string iconFile = Path.Combine(Utility.ApplicationPath, "Icons");

            if (string.IsNullOrEmpty(p_notification.IconFile) == false)
            {
               iconFile = Path.Combine(iconFile, p_notification.IconFile);
            }
            else
            {
               iconFile = Path.Combine(iconFile, "Sql2GrowlDefault.png");
            }

            if (File.Exists(iconFile) == true)
               icon = new Uri(iconFile).ToString();

            m_growlConnectors[p_notification.ConnectorKey].AddApplication(
               p_notification.Application, icon);
             }

             return m_growlConnectors[p_notification.ConnectorKey].Applications[p_notification.Application];
        }