Пример #1
0
        // -----------------------------------------------------------------------------------------

        /// <summary>
        /// Seperate function to deal with the actual creation of the Debug Log entry.
        /// </summary>
        /// <returns>The new generated log entry.</returns>
        public LogEntry GenerateLogEntry(object source, Tranzmit.DeliveryStatuses status, List <Tranzmit.Errors> errors, Tranzmit.EventNames eventName, Type requiredDataType, Type providedDataType, Tranzmit.EventData.TranzmitDelegate tranzmitDelegate)
        {
            var entry = new LogEntry();

            entry.Status           = status;
            entry.Errors           = errors;
            entry.TranzmitEvent    = eventName;
            entry.RequiredDataType = requiredDataType;
            entry.ProvidedDataTypes.Add(providedDataType);
            entry.Broadcasters.Add(source, new ButtonData()
            {
                EventCount = 0
            });

            var subscribers = Tranzmit.GetSubscribersInSentEvent(tranzmitDelegate);

            foreach (object subscriber in subscribers)
            {
                entry.Subscribers.Add(subscriber, new ButtonData());
            }

            return(entry);
        }
Пример #2
0
        // -----------------------------------------------------------------------------------------

        /// <summary>
        /// The business end of Tranzmit Debug. When Tranzmit ATTEMPTS to send an event, it also broadacasts information about it. This is sent regadless of whether the requested Tranzmit Event was valid and sent.
        /// It creates and saves the associated data. Notice that we store the button information in here. This allows for more eficient updating of the Graphview.
        /// </summary>
        /// <param name="source">The object that requested for a Tranzmit event to be sent. Can be Null</param>
        /// <param name="status">A basic 'Success' or 'Failed' output.</param>
        /// <param name="errors">A list of Enums that will show ALL issues (if any) with the Tranzmit Event Send request.</param>
        /// <param name="eventName">The name of the Tranzmit Event.</param>
        /// <param name="requiredDataType">The data type specified by the user when they configured the Tranzmit Event.</param>
        /// <param name="providedDataType">The type of data the user actually attached to the event. Can be Null.</param>
        /// <param name="tranzmitDelegate">The Event/Delegate of the Tranzmit Event.</param>
        public void EventSent(object source, Tranzmit.DeliveryStatuses status, List <Tranzmit.Errors> errors, Tranzmit.EventNames eventName, Type requiredDataType, Type providedDataType, Tranzmit.EventData.TranzmitDelegate tranzmitDelegate)
        {
            // This will be assigned to later on, and allows for cleaner code and less if statements etc
            Dictionary <Tranzmit.EventNames, List <LogEntry> > saveLocation = null;

            // Allocate the Dicitonary to use
            if (status == Tranzmit.DeliveryStatuses.Success)
            {
                saveLocation = Success;
            }
            else
            {
                saveLocation = Failed;
            }

            // Deal with potential NULL source
            if (source == null)
            {
                // We have to give it something!
                source = NullSourceObject;
            }

            // CREATE NEW EVENT LOGS FIRST - WILL APPLY TOTAL TO SUBSCRIBERS AND BROADCASTERS AFTER (BELOW)
            // NEW ENTRY INTO LIST - AS EVENT NAME NOT FOUND
            if (!saveLocation.ContainsKey(eventName))
            {
                var newLogEntry = GenerateLogEntry(source, status, errors, eventName, requiredDataType, providedDataType, tranzmitDelegate);
                saveLocation.Add(eventName, new List <LogEntry>()
                {
                    newLogEntry
                });

                Tranzmit.Broadcast_Tranzmit_Log_Update(newLogEntry);
            }
            else // EXISTING EVENT - We now Compare the ERRORS list - If no match found create a new entry based on ERRRORS
            {
                // Null if not match found
                var foundLog = ReturnFirstLogEntryWithMatchingErrorsList(saveLocation[eventName], errors);

                // NEW ERRORS LIST
                if (foundLog == null)
                {
                    var newLogEntry = GenerateLogEntry(source, status, errors, eventName, requiredDataType, providedDataType, tranzmitDelegate);
                    saveLocation[eventName].Add(newLogEntry);
                    Tranzmit.Broadcast_Tranzmit_Log_Update(newLogEntry);
                }
            }

            // SUBSCRIBERS - We update subscribers in case new ones have been added through code at some point.
            //...and also add to the count if they already exist
            var currentSubscribers = Tranzmit.GetSubscribersInSentEvent(tranzmitDelegate);

            // SUBSCRIBERS
            if (saveLocation.ContainsKey(eventName))
            {
                var foundLog = ReturnFirstLogEntryWithMatchingErrorsList(saveLocation[eventName], errors);

                if (foundLog != null)
                {
                    foreach (object o in currentSubscribers)
                    {
                        if (foundLog.Subscribers.ContainsKey(o))
                        {
                            foundLog.Subscribers[o].EventCount++;
                        }
                        else
                        {
                            foundLog.Subscribers.Add(o, new ButtonData()
                            {
                                EventCount = 0
                            });
                        }
                    }

                    Tranzmit.Broadcast_Tranzmit_Log_Update(foundLog);
                }
            }

            // BROADCASTERS
            if (saveLocation.ContainsKey(eventName))
            {
                var foundLog = ReturnFirstLogEntryWithMatchingErrorsList(saveLocation[eventName], errors);

                if (foundLog != null)
                {
                    if (foundLog.Broadcasters.ContainsKey(source))
                    {
                        foundLog.Broadcasters[source].EventCount++;
                    }
                    else
                    {
                        foundLog.Broadcasters.Add(source, new ButtonData()
                        {
                            EventCount = 1
                        });
                    }

                    Tranzmit.Broadcast_Tranzmit_Log_Update(foundLog);
                }
            }
        }