예제 #1
0
        public override void Process(PublishedEvent evt)
        {
            if (xeadapter == null)
            {
                xeadapter               = new XEventDataTableAdapter(EventsTable);
                xeadapter.Filter        = this.Filter;
                xeadapter.OutputColumns = new List <OutputColumn>();
            }
            xeadapter.ReadEvent(evt);

            lock (EventsTable)
            {
                foreach (DataRow dr in EventsTable.Rows)
                {
                    Dictionary <string, object> eventTokens = new Dictionary <string, object>();
                    foreach (DataColumn dc in EventsTable.Columns)
                    {
                        eventTokens.Add(dc.ColumnName, dr[dc]);
                    }
                    // also add the Response tokens
                    foreach (string k in Tokens.Keys)
                    {
                        if (!eventTokens.ContainsKey(k))
                        {
                            eventTokens.Add(k, Tokens[k]);
                        }
                    }
                    string formattedTSQL = SmartFormatHelper.Format(TSQL, eventTokens);

                    Task t = Task.Factory.StartNew(() => ExecuteTSQL(formattedTSQL));
                }

                EventsTable.Clear();
            }
        }
        protected override void Upload()
        {
            logger.Trace("Writing grouped XE data");

            int numRows, originalRows;

            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = ConnectionString;
                conn.Open();

                DataTable groupedData = null;
                lock (EventsTable)
                {
                    originalRows = EventsTable.Rows.Count;
                    groupedData  = GroupBy();
                    EventsTable.Rows.Clear();
                }

                if (!TargetTableCreated)
                {
                    CreateTargetTable(groupedData);
                }

                DataTableTSQLAdapter adapter = new DataTableTSQLAdapter(groupedData, conn)
                {
                    DestinationTableName = SmartFormatHelper.Format(TableName, Tokens)
                };
                numRows      = adapter.MergeToServer(_outputColumns);
                originalRows = groupedData.Rows.Count;
            }
            logger.Info(String.Format("{0} rows aggregated, {1} rows written", originalRows, numRows));
        }
        protected override void CreateTargetTable(DataTable data)
        {
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = ConnectionString;
                conn.Open();

                DataTableTSQLAdapter adapter = new DataTableTSQLAdapter(data, conn)
                {
                    DestinationTableName = SmartFormatHelper.Format(TableName, Tokens)
                };
                if (!adapter.CheckTableExists())
                {
                    adapter.CreateFromDataTable();
                }
            }
        }
예제 #4
0
        public override void Process(PublishedEvent evt)
        {
            if (xeadapter == null)
            {
                xeadapter               = new XEventDataTableAdapter(EventsTable);
                xeadapter.Filter        = this.Filter;
                xeadapter.OutputColumns = new List <OutputColumn>();
            }
            xeadapter.ReadEvent(evt);

            lock (EventsTable)
            {
                foreach (DataRow dr in EventsTable.Rows)
                {
                    string formattedBody    = Body;
                    string formattedSubject = Subject;

                    Dictionary <string, object> eventTokens = new Dictionary <string, object>();
                    foreach (DataColumn dc in EventsTable.Columns)
                    {
                        eventTokens.Add(dc.ColumnName, dr[dc]);
                    }
                    // also add the Response tokens
                    foreach (string t in Tokens.Keys)
                    {
                        if (!eventTokens.ContainsKey(t))
                        {
                            eventTokens.Add(t, Tokens[t]);
                        }
                    }
                    formattedBody    = SmartFormatHelper.Format(Body, eventTokens);
                    formattedSubject = SmartFormatHelper.Format(Subject, eventTokens);

                    using (MailMessage msg = new MailMessage()
                    {
                        From = new MailAddress(Sender), Subject = formattedSubject, Body = formattedBody
                    })
                    {
                        foreach (var addrTo in To.Split(';'))
                        {
                            msg.To.Add(new MailAddress(addrTo));
                        }

                        using (MemoryStream attachStream = new MemoryStream())
                        {
                            if (!String.IsNullOrEmpty(Attachment) && dr.Table.Columns.Contains(Attachment))
                            {
                                StreamWriter wr = new StreamWriter(attachStream);
                                wr.Write(dr[Attachment].ToString());
                                wr.Flush();
                                attachStream.Position = 0;

                                System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType(System.Net.Mime.MediaTypeNames.Text.Plain);
                                Attachment at = new Attachment(attachStream, ct);
                                at.ContentDisposition.FileName = AttachmentFileName;
                                msg.Attachments.Add(at);
                            }
                            msg.IsBodyHtml = HTMLFormat;

                            using (SmtpClient client = new SmtpClient(SMTPServer))
                            {
                                if (!String.IsNullOrEmpty(UserName))
                                {
                                    client.Credentials = new System.Net.NetworkCredential(UserName, Password);
                                }
                                // could be inefficient: sends synchronously
                                client.Send(msg);
                            }
                        }
                    }
                }

                EventsTable.Clear();
            }
        }
예제 #5
0
        private void Replay()
        {
            lock (eventsTable)
            {
                foreach (DataRow dr in eventsTable.Rows)
                {
                    string commandText = null;
                    if (dr["name"].ToString() == "rpc_completed")
                    {
                        commandText = dr["statement"].ToString();
                    }
                    else if (dr["name"].ToString() == "sql_batch_completed")
                    {
                        commandText = dr["batch_text"].ToString();
                    }
                    else
                    {
                        //ignore events not suitable for replay
                        logger.Debug(String.Format("Skipping event {0}", dr["name"].ToString()));
                        continue;
                    }

                    ReplayCommand command = new ReplayCommand()
                    {
                        CommandText = commandText
                    };

                    if (dr.Table.Columns.Contains("database_name") && !String.IsNullOrEmpty((string)dr["database_name"]))
                    {
                        string dbname = dr["database_name"].ToString();
                        command.Database = dbname;
                    }

                    int session_id = -1;
                    if (dr.Table.Columns.Contains("session_id"))
                    {
                        session_id = Convert.ToInt32(dr["session_id"]);
                    }
                    else
                    {
                        throw new Exception("Unable to replay if session_id is not collected. Please add this action to your session.");
                    }

                    ReplayWorker rw = null;
                    if (ReplayWorkers.TryGetValue(session_id, out rw))
                    {
                        rw.AppendCommand(command);
                    }
                    else
                    {
                        rw = new ReplayWorker()
                        {
                            ServerName            = SmartFormatHelper.Format(ServerName, Tokens),
                            UserName              = UserName,
                            Password              = Password,
                            DatabaseName          = SmartFormatHelper.Format(DatabaseName, Tokens),
                            ReplayIntervalSeconds = ReplayIntervalSeconds,
                            StopOnError           = StopOnError,
                            Name = session_id.ToString()
                        };
                        ReplayWorkers.TryAdd(session_id, rw);
                        rw.Start();
                        rw.AppendCommand(command);

                        logger.Info(String.Format("Started new Replay Worker for session_id {0}", session_id));
                    }
                }

                eventsTable.Rows.Clear();
            }
        }