/// <summary>
        /// Sends the events asynchronous.
        /// </summary>
        /// <param name="events">The events.</param>
        /// <param name="transmissionSequenceNumber">The transmission sequence number.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public Task SendEventsAsync(IReadOnlyCollection <EventData> events, long transmissionSequenceNumber, CancellationToken cancellationToken)
        {
            if (events == null || !events.Any())
            {
                return(CompletedTask);
            }

            try
            {
                foreach (var evt in events)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return(CompletedTask);
                    }

                    var level = evt.Level.ToString();
                    RIExtendedMessageProperty.AttachToRequest(TraceTag, "Provider", evt.ProviderName);
                    RIExtendedMessageProperty.AttachToRequest(TraceTag, "Level", level);

                    evt.Payload.TryGetValue("Message", out object message);
                    _reflectInsight.SendJSON($"[{level}] {(message as string) ?? evt.ProviderName}", evt);
                }

                _healthReporter.ReportHealthy();

                return(CompletedTask);
            }
            catch (Exception ex)
            {
                _healthReporter.ReportProblem($"{TraceTag}: Fail to send events in batch. Error details: {ex.ToString()}");
                throw;
            }
        }
示例#2
0
        //---------------------------------------------------------------------
        public String Process(String name, DateTime DOB, String SIN)
        {
            // assume we got these customer values from the identity object.
            Random rnd = new Random();

            RIExtendedMessageProperty.AttachToRequest("Company Information", "ClientID", String.Format("{0:D4}", rnd.Next(10000)));
            RIExtendedMessageProperty.AttachToRequest("Company Information", "CompanyID", String.Format("{0:D5}", rnd.Next(100000)));

            ReflectInsight ri = RILogManager.Get("WebApi");

            using (ri.TraceMethod(MethodBase.GetCurrentMethod(), true))
            {
                try
                {
                    ri.SendMsg("I'm somewhere inside the WebApi.Process method");
                    ri.SendNote("name: {0}", name);
                    ri.SendNote("DOB: {0}", DOB);

                    Business bus = new Business();
                    bus.ProcessRecord(name, DOB);

                    ri.SendInformation("Just got back from calling the Business Layer");

                    return(Guid.NewGuid().ToString());
                }
                catch (Exception ex)
                {
                    ri.SendException(ex);
                    throw;
                }
            }
        }
        /// <summary>
        /// Publishes the specified exception.
        /// </summary>
        /// <param name="exception">The exception.</param>
        /// <param name="additionalParameters">The additional parameters.</param>
        public void Publish(Exception exception, NameValueCollection additionalParameters)
        {
            if (additionalParameters != null)
            {
                foreach (var key in additionalParameters.AllKeys)
                {
                    RIExtendedMessageProperty.AttachToSingleMessage("Additional Info", key, additionalParameters[key]);
                }
            }

            var details = ExceptionFormatter.ConstructIndentedMessage(exception, additionalParameters /*, _exceptionExtender.Extender*/);

            RILogManager.Get(_category).Send(MessageType.SendException, exception.Message, details);
        }
示例#4
0
        static void ThreadDemoBackorder(Object state)
        {
            // Attach Request Extended data
            Random rnd1 = new Random((Int32)DateTime.Now.Ticks + (Int32)state);

            String source = Sources[rnd1.Next(Sources.Length)];

            RIExtendedMessageProperty.AttachToRequest("Company Information", "ClientID", String.Format("{0:D4}", rnd1.Next(10000)));
            RIExtendedMessageProperty.AttachToRequest("Company Information", "CompanyID", String.Format("{0:D5}", rnd1.Next(100000)));
            RIExtendedMessageProperty.AttachToRequest("Company Information", "Source", source);

            ReflectInsight ri = RILogManager.Get("Backorder");

            using (ri.TraceMethod("Starting Backorder thread block"))
            {
                try
                {
                    ri.SendThreadInformation();
                    Thread.Sleep(500);

                    Int32 poNumber = rnd1.Next(100000);

                    using (ri.TraceMethod("Initiating purchase order: {0}", String.Format("{0:D5}", poNumber)))
                    {
                        ri.SendDataSet("Customer order information loaded", DataSet1);
                        Thread.Sleep(500);

                        using (ri.TraceMethod("Validate Customer"))
                        {
                            ri.SendCheckmark("Customer certificate validation successfully", Checkmark.Green);
                            ri.SendCheckmark("Customer threshold is within fair standings", Checkmark.Yellow);

                            Thread.Sleep(500);
                            using (ri.TraceMethod("Validate Customer Backorders"))
                            {
                                ri.SendInformation("Backorders detected: {0}", rnd1.Next(20));
                                ri.SendMsg("Processing {0} records", rnd1.Next(21, 200));
                            }

                            using (ri.TraceMethod("Preparing source configuration data for state: '{0}'", source))
                            {
                                ri.SendMsg("Reading source configuration data");

                                if (source == "Georgia")
                                {
                                    ri.SendError("Unable to retrieve source data for state: '{0}'. Source data is either missing or isn't properly configured.", source);
                                    Thread.Sleep(1000);
                                    ri.SendXMLFile("See failed configuration", String.Format(@"{0}Samples\state_config.xml", AppDomain.CurrentDomain.BaseDirectory));

                                    // show dummy configuration file
                                    using (ri.TraceMethod("Requeuing order: {0}", poNumber))
                                    {
                                        ri.SendMsg("Recoil start indicators");
                                        ri.SendTimestamp("Requeued Timestamp");
                                    }

                                    return;
                                }

                                Thread.Sleep(500);
                                ri.SendCheckmark("Source configuration data was successfully loaded", Checkmark.Green);
                            }
                        }

                        using (ri.TraceMethod("Processing order: {0}", poNumber))
                        {
                            try
                            {
                                if (source == "Minnesota")
                                {
                                    ri.SendError("item 3 'Quantity' value exceeds customer's threshold limit of 20, for PartNumber: '872-AX'");
                                    ri.SendWarning("Order: {0} was not processed due to exceeding threshold limit: 'Quantity'", poNumber);
                                    Thread.Sleep(1000);
                                    ri.SendXMLFile(String.Format("See failed order: {0}", poNumber), String.Format(@"{0}Samples\purchase_order.xml", AppDomain.CurrentDomain.BaseDirectory));

                                    Thread.Sleep(100);
                                    using (ri.TraceMethod("Prepare CRM failed compensation report workflow"))
                                    {
                                        ri.SendMsg("Establish CRM connection");
                                        Thread.Sleep(100);
                                        ri.SendCheckmark("CRM connection successfully establised", Checkmark.Green);

                                        Thread.Sleep(100);
                                        using (ri.TraceMethod("Insert CRM failed compensation report"))
                                        {
                                            ri.SendMsg("Insert compensation");
                                            ri.SendMsg("Insert item status");
                                            ri.SendMsg("CRM record id: {0}", rnd1.Next(10000, 100000));
                                            ri.SendTimestamp("CRM Timestamp");
                                        }
                                    }

                                    return;
                                }

                                ri.SendCheckmark(String.Format("Successfully processed {0} order items", rnd1.Next(1, 50)), Checkmark.Green);
                                ri.SendMsg("Preparing reciept");
                                ri.SendMsg("Preparing client processed notification");
                                ri.SendMsg("Preparing dispatch record");

                                Thread.Sleep(500);
                                using (ri.TraceMethod("Prepare CRM reciept workflow"))
                                {
                                    ri.SendMsg("Establish CRM connection");
                                    Thread.Sleep(100);
                                    if (source == "Michigan")
                                    {
                                        SecurityException e1 = new SecurityException("Account is disabled. Please contact IT Support.");
                                        ri.SendException(new Exception("Unable to connect to client's CRM system. Please see inner exception for more details", e1));
                                        return;
                                    }

                                    Thread.Sleep(500);
                                    ri.SendCheckmark("CRM connection successfully establised", Checkmark.Green);

                                    using (ri.TraceMethod("Insert CRM order process completion"))
                                    {
                                        ri.SendMsg("Insert reciept");
                                        ri.SendMsg("Insert dispatch record");
                                        ri.SendMsg("CRM record id: {0}", rnd1.Next(10000, 100000));
                                        ri.SendTimestamp("CRM Timestamp");
                                    }
                                }

                                ri.SendCheckmark(String.Format("Order: {0} was successfully processed", poNumber), Checkmark.Green);
                            }
                            catch (Exception)
                            {
                                using (ri.TraceMethod("Reverting order: {0} due to fatal error.", poNumber))
                                {
                                    ri.SendCheckmark("Order successfuly reverted", Checkmark.Green);
                                    using (ri.TraceMethod("Requeuing order: {0}", poNumber))
                                    {
                                        ri.SendMsg("Recoil start indicators");
                                        ri.SendTimestamp("Requeued Timestamp");
                                    }
                                }

                                throw;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    ri.SendException(ex);
                }
            }
        }