Exemplo n.º 1
0
        /// <summary>
        /// Base logging implementation
        /// </summary>
        /// <param name="message">Message to be logged</param>
        /// <param name="ex">Exception to be logged, null can be passed if there are no exception details</param>
        /// <param name="level">Level to be used for the logged message</param>
        /// <param name="category">Category to be used for the logged message</param>
        static void LogBase(string message, Exception ex, EventLevel level, EventCategory category)
        {
            var msg = string.Format("{0} {1}: {2}", category.ToString().PadRight(15), level.ToString().PadRight(15), message);

            if (ex != null)
            {
                msg += "\r\nEXCEPTION: " + ex;
            }

            // Log to Console
            Console.WriteLine(msg);

            // Log to Debug
            Debug.WriteLine(msg);

            // TODO: Log to other logging providers here
        }
Exemplo n.º 2
0
 public static void SendEvent(EventCategory category, string name, TimeSpan duration, string message = null, string description = null)
 {
     SendEvent(category, category.ToString(), name, message, description, duration);
 }
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            if (VoteHandler.voteActive || !Rand.MTBEventOccurs(ToolkitSettings.HodlBotMTBDays, 60000f, 1000f))
            {
                if (!forced)
                {
                    yield break;
                }
            }

            if (Rand.Range(0, 1) == 1)
            {
                voteType = Vote_VotingIncident.VoteLabelType.Type;
            }

            List <VotingIncidentEntry> source  = VotingIncidentsByWeight();
            List <VotingIncidentEntry> winners = new List <VotingIncidentEntry>();

            string str = null;

            switch (voteType)
            {
            case Vote_VotingIncident.VoteLabelType.Category:
            {
                EventCategory category = RandomCategory();
                source = (from s in source
                          where s.incident.eventCategory == category
                          select s).ToList();
                str = "Which " + category.ToString() + " event should happen?";
                Helper.Log("rand cat picked " + category);
                break;
            }

            case Vote_VotingIncident.VoteLabelType.Type:
            {
                EventType randType = RandomType();
                source = (from s in source
                          where s.incident.eventType == randType
                          select s).ToList();
                str = "Which " + randType + " event should happen?";
                Helper.Log("rand type picked " + randType);
                break;
            }
            }

            for (int i = 0; i < ToolkitSettings.VoteOptions; i++)
            {
                if (GenCollection.TryRandomElementByWeight <VotingIncidentEntry>
                        (from s in source
                        where !winners.Contains(s)
                        select s, (Func <VotingIncidentEntry, float>)((VotingIncidentEntry vi) => vi.weight), out VotingIncidentEntry votingIncidentEntry))
                {
                    votingIncidentEntry.incident.Helper.target = target;

                    if (votingIncidentEntry.incident.Helper.IsPossible())
                    {
                        winners.Add(votingIncidentEntry);
                    }
                }
            }

            if (winners.Count < 3)
            {
                Helper.Log("Less than 3 possible votes were found");
                yield break;
            }

            Dictionary <int, VotingIncident> dictionary = new Dictionary <int, VotingIncident>();

            for (int i = 0; i < winners.Count; i++)
            {
                dictionary.Add(i, winners[i].incident);
            }

            StorytellerPack named = DefDatabase <StorytellerPack> .GetNamed("HodlBot", true);

            VoteHandler.QueueVote(new Vote_HodlBot(dictionary, named, voteType, str));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Base logging implementation
        /// </summary>
        /// <param name="message">Message to be logged</param>
        /// <param name="ex">Exception to be logged, null can be passed if there are no exception details</param>
        /// <param name="level">Level to be used for the logged message</param>
        /// <param name="category">Category to be used for the logged message</param>
        static void LogBase(string message, Exception ex, EventLevel level, EventCategory category)
        {
            var msg = string.Format("{0} {1}: {2}", category.ToString().PadRight(15), level.ToString().PadRight(15), message);

            if (ex != null)
                msg += "\r\nEXCEPTION: " + ex;

            // Log to Console
            Console.WriteLine(msg);

            // Log to Debug
            Debug.WriteLine(msg);

            // TODO: Log to other logging providers here
        }
Exemplo n.º 5
0
 public CategoryInfo(EventCategory category, string name = null)
 {
     Category = category;
     Name     = name ?? category.ToString();
 }
Exemplo n.º 6
0
        public void addEvent()
        {
            eventName           = EventName.Text;
            eventDateFrom       = EventDateFrom;
            eventDateTo         = EventDateTo;
            eventTimeFrom       = EventTimeFrom;
            eventTimeTo         = EventTimeTo;
            eventLocation       = EventLocation.Text;
            eventDescription    = EventDescription.Text;
            eventAdditionalNote = EventAdditionalNote.Text;
            eventPriorityLevel  = EventPriorityLevel.Text;
            eventCategory       = EventCategory;
            eventContact        = EventContact.Text;
            eventDataGridView   = EventDataGridView;

            try
            {
                SqlConnection databaseConnection = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;Integrated Security=True;database=master");
                databaseConnection.Open();

                var eventCreatedTime = DateTime.Now;
                //string formattedTime = time.ToString("yyyy, MM, dd, hh, mm, ss");

                DateTime startTime = Convert.ToDateTime(eventTimeFrom.Value);
                DateTime endTime   = Convert.ToDateTime(eventTimeTo.Value);

                TimeSpan span = endTime.Subtract(startTime);

                int hoursDifference   = span.Hours;
                int minutesDifference = span.Minutes;
                int secondsDifference = span.Seconds;


                string        checkExistQuery      = "SELECT event_id FROM event_record WHERE event_name ='" + eventName + "';";
                SqlCommand    checkExistcommand    = new SqlCommand(checkExistQuery, databaseConnection);
                SqlDataReader checkExistDataReader = checkExistcommand.ExecuteReader();


                if (checkExistDataReader.Read())
                {
                    MessageBox.Show("Record data by event name already exist", "Add Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    checkExistDataReader.Close();
                    //checkExistDataReader.Dispose();
                }
                else
                {
                    checkExistDataReader.Close();

                    string eventAddQuery = "INSERT INTO event_record(event_name,date_from,date_to," +
                                           "time_from,time_to,location,description," +
                                           "category,additional_note,priority_level,created_date_time,updated_date_time,contact_name) " +
                                           "VALUES('" + eventName + "','" + eventDateFrom.Text + "','"
                                           + eventDateTo.Text + "','" + eventTimeFrom.Text + "','"
                                           + eventTimeTo.Text + "','"
                                           + eventLocation + "','" + eventDescription + "','"
                                           + EventCategory.ToString() + "','" + eventAdditionalNote + "','"
                                           + eventPriorityLevel + "','" + eventCreatedTime + "','"
                                           + eventCreatedTime + "','" + eventContact + "');";

                    SqlCommand eventAddCommand = new SqlCommand(eventAddQuery, databaseConnection);
                    eventAddCommand.ExecuteNonQuery();

                    string checkAddedRecordQuery = "SELECT event_id FROM event_record WHERE event_name='" + eventName + "' ;";

                    SqlCommand    checkAddedRecordCommand = new SqlCommand(checkAddedRecordQuery, databaseConnection);
                    SqlDataReader AddedRecordReader       = checkAddedRecordCommand.ExecuteReader();

                    string addStatus = "";
                    switch (AddedRecordReader.HasRows)
                    {
                    case true:
                        MessageBox.Show("Event : " + eventName + " added successfully. ", "Add Status", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        AddedRecordReader.Close();
                        addStatus = "created successfully.";
                        break;

                    case false:
                        MessageBox.Show("Event : " + eventName + " add failed. ", "Add Status", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        AddedRecordReader.Close();
                        addStatus = "creation failed.";
                        break;
                    }

                    string auditTraceQuery = "INSERT INTO audit_trace(description,traced_page,traced_task,created_date_time)"
                                             + "VALUES('Event " + eventName + "" + addStatus + "','Event Page','Add','" + eventCreatedTime + "');";

                    SqlCommand auditTraceAddCommand = new SqlCommand(auditTraceQuery, databaseConnection);
                    auditTraceAddCommand.ExecuteNonQuery();

                    string checkAuditTraceQuery = "SELECT audit_id FROM audit_trace WHERE created_date_time='" + eventCreatedTime + "' ;";

                    SqlCommand    checkAuditTraceCommand = new SqlCommand(checkAuditTraceQuery, databaseConnection);
                    SqlDataReader AuditTraceReader       = checkAuditTraceCommand.ExecuteReader();

                    switch (AuditTraceReader.HasRows)
                    {
                    case true:
                        Console.WriteLine("Auidt trace for add task created successfully.");
                        AuditTraceReader.Close();
                        break;

                    case false:
                        Console.WriteLine("Audit trace for add task creation failed.");
                        AuditTraceReader.Close();
                        break;
                    }

                    string         refreshGridQuery   = "SELECT * FROM event_record";
                    SqlCommand     refreshGridCommand = new SqlCommand(refreshGridQuery, databaseConnection);
                    SqlDataAdapter dataAdapter        = new SqlDataAdapter(refreshGridCommand);
                    DataTable      dataTable          = new DataTable();
                    dataAdapter.Fill(dataTable);

                    eventDataGridView.DataSource = new BindingSource(dataTable, null);

                    int day   = eventDateFrom.Value.Day;
                    int month = eventDateFrom.Value.Month;
                    int year  = eventDateFrom.Value.Year;


                    string eventPredictPurposeQuery = "INSERT INTO event_prediction_purpose(event_name,date_from,year,month,day,hours_count,minutes_count,seconds_count,created_date_time,updated_date_time)"
                                                      + "VALUES('" + eventName + "','" + eventDateFrom.Text + "','" + year + "','" + month + "','" + day + "','" + hoursDifference + "','" + minutesDifference + "','" + secondsDifference + "','" + eventCreatedTime + "','" + eventCreatedTime + "');";

                    SqlCommand eventPredictPurposeCommand = new SqlCommand(eventPredictPurposeQuery, databaseConnection);
                    eventPredictPurposeCommand.ExecuteNonQuery();

                    databaseConnection.Close();
                }
            }

            catch (SqlException producedException)
            {
                MessageBox.Show("Failed function(s) detected." + Environment.NewLine + "Detailed Information: " + producedException.Message, "Add Status", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void TraceEventProcessed(long commitLogPosition, PartitionEvent evt, EventCategory category, double startedTimestamp, double finishedTimestamp, bool replaying)
        {
            if (this.logLevelLimit <= LogLevel.Information)
            {
                long   nextCommitLogPosition = ((evt as PartitionUpdateEvent)?.NextCommitLogPosition) ?? 0L;
                double queueLatencyMs        = evt.IssuedTimestamp - evt.ReceivedTimestamp;
                double fetchLatencyMs        = startedTimestamp - evt.IssuedTimestamp;
                double latencyMs             = finishedTimestamp - startedTimestamp;

                if (this.logger.IsEnabled(LogLevel.Information))
                {
                    var details = string.Format($"{(replaying ? "Replayed" : "Processed")} {(evt.NextInputQueuePosition > 0 ? "external" : "internal")} {category}");
                    this.logger.LogInformation("Part{partition:D2}.{commitLogPosition:D10} {details} {event} eventId={eventId} pos=({nextCommitLogPosition},{nextInputQueuePosition}) latency=({queueLatencyMs:F0}, {fetchLatencyMs:F0}, {latencyMs:F0})", this.partitionId, commitLogPosition, details, evt, evt.EventIdString, nextCommitLogPosition, evt.NextInputQueuePosition, queueLatencyMs, fetchLatencyMs, latencyMs);
                }

                this.etw?.PartitionEventProcessed(this.account, this.taskHub, this.partitionId, commitLogPosition, category.ToString(), evt.EventIdString, evt.ToString(), nextCommitLogPosition, evt.NextInputQueuePosition, queueLatencyMs, fetchLatencyMs, latencyMs, replaying, TraceUtils.ExtensionVersion);
            }
        }
Exemplo n.º 8
0
        public static void LogInformation(EventCategory enumCategory, string infoMessage)
        {
            SPDiagnosticsCategory category = LoggingService.Instance.Areas[DefaultDiagnosticAreaName].Categories[enumCategory.ToString() + "_INFORMATION"];

            LoggingService.Instance.WriteTrace(0, category, category.TraceSeverity, infoMessage);
        }
Exemplo n.º 9
0
        public static void LogError(EventCategory enumCategory, string errorMessage)
        {
            SPDiagnosticsCategory category = LoggingService.Instance.Areas[DefaultDiagnosticAreaName].Categories[enumCategory.ToString() + "_ERROR"];

            LoggingService.Instance.WriteTrace(0, category, category.TraceSeverity, errorMessage);
        }