static private void OnShutdown()
        {
            try
            {
                AppDomain.CurrentDomain.ProcessExit -= OnShutdown;
                RIEventManager.OnConfigChange       -= OnConfigFileChange;

                RIEventManager.DoOnShutdown();
                ReflectInsight.OnShutdown();
                DebugManager.OnShutdown();
                RIMessageColors.OnShutdown();
                RILogManager.OnShutdown();
                RIListenerGroupManager.OnShutdown();
                ReflectInsightConfig.OnShutdown();
                TraceMethod.OnShutdown();

                RITraceListener.OnShutdown();
            }
            catch (Exception ex)
            {
                RIExceptionManager.Publish(ex, "Failed during: static ReflectInsightService.OnShutdown()");
            }
            finally
            {
                RIExceptionManager.OnShutdown();
                DebugTextLoggerManager.OnShutdown();
            }
        }
Example #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>
        /// Initializes a new instance of the <see cref="TraceMethod"/> class.
        /// </summary>
        /// <param name="ri">The ri.</param>
        /// <param name="message">The message.</param>
        internal TraceMethod(ReflectInsight ri, String message)
        {
            RI       = ri;
            Message  = message ?? "(null)";
            Disposed = false;

            ControlValues = RequestManager.GetRequestObject();
            TraceStates   = ControlValues.GetState <TraceMethodState>("TraceMethodState");

            if (TraceStates == null)
            {
                // must be parent trace method
                TraceStates = new TraceMethodState()
                {
                    TraceLevel = 0, ExceptionHandled = false
                };
                ControlValues.AddState("TraceMethodState", TraceStates);
            }

            RICustomData cData = null;

            if (cData == null)
            {
                RI.EnterMethod(Message);
            }
            else
            {
                FSendMethodInfo.Invoke(RI, new object[] { MessageType.EnterMethod, message, cData, new object[] { } });
            }

            LastIndentLevel = ReflectInsight.IndentLevel;
            TraceStates.TraceLevel++;
        }
Example #4
0
        static void Main(string[] args)
        {
            // get RI instances predefined in the config settings
            RILogManager.Get("ViewerOnly").SendMessage("Only the Viewer will get this message");
            RILogManager.Get("File1Only").SendMessage("Only TextFile1 and BinaryFile1 will get this message");
            RILogManager.Get("File2Only").SendMessage("Only TextFile2 and BinaryFile2 will get this message");


            // by code - example 1a
            using (ReflectInsight ri = new ReflectInsight("Example1"))
            {
                ri.SetDestinationBindingGroup("ViewerOnlyBinding");
                ri.SendMessage("Only the Viewer will get this message");
            }

            // by code - example 1b
            using (ReflectInsight ri = new ReflectInsight("Example1"))
            {
                ri.SetDestinationBindingGroup("File1OnlyBinding");
                ri.SendMessage("Only TextFile1 and BinaryFile1 will get this message");
            }

            // you can create instances on the fly and used them throughout the application as needed
            RILogManager.Add("AnotherViewerOnlyInstance", "Another Category", String.Empty, "ViewerOnlyBinding");
            RILogManager.Add("AnotherFile1OnlyInstance", "Another Category", String.Empty, "File1OnlyBinding");

            RILogManager.Get("AnotherViewerOnlyInstance").SendMessage("Only the Viewer will get this message");
            RILogManager.Get("AnotherFile1OnlyInstance").SendMessage("Only TextFile1 and BinaryFile1 will get this message");
        }
        /// <summary>
        /// Called when initializing worker.
        /// </summary>
        protected override void OnInitialize()
        {
            base.OnInitialize();

            // Create ReflectInsight Object for Logging.
            ri = new ReflectInsight("TTSServicePOC.Service.Worker.TTSWorker");

            try
            {
                #region Load in the parameters from the Worker configuration

                //CacheSize = int.Parse(Parameters("cacheSize", "200"));

                #endregion

                synthesizer = new SpeechSynthesizer();                
                voices = SpeechSynthesizer.AllVoices;

                ri.SendInformation("Starting TTSWorker ({0})", this.Name);
            }
            catch (Exception ex)
            {
                ri.SendException(ex);
                throw;
            }
        }
Example #6
0
        static private IReflectInsight CreateInstance(RIInstance instance)
        {
            IReflectInsight ri = new ReflectInsight(instance.Category);

            ri.BackColor = RIPastelBackColor.GetColorByName(instance.BkColor);
            ri.SetDestinationBindingGroup(instance.DestinationBindingGroup);

            return(ri);
        }
        //---------------------------------------------------------------------
        public LogLinqToSql(String label, ReflectInsight ri)
        {
            FLabel          = label;
            FReflectInsight = ri;
            FOwnsRI         = ri != null;

            OnConfigChange();
            RIEventManager.OnServiceConfigChange += DoOnConfigChange;
        }
        public MainWindow()
        {
            InitializeComponent();

            // Create ReflectInsight Object for Logging.
            ri = new ReflectInsight("SpeechSynthesizerService.TestClient");

            // Initialize the WorkManager
            wManager = new WorkManager();            
        }
 /// <summary>
 /// Does the on created instance.
 /// </summary>
 /// <param name="ri">The ri.</param>
 static internal void DoOnCreatedInstance(ReflectInsight ri)
 {
     try
     {
         OnCreatedInstance?.Invoke(ri);
     }
     catch (Exception ex)
     {
         RIExceptionManager.Publish(ex, "Failed during: RIEventManager.DoOnCreatedInstance()");
     }
 }
Example #10
0
        static void MiscellaneousSample()
        {
            ReflectInsight ri = RILogManager.Get("Miscellaneous");

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

                ri.SendImage("Hello, World", String.Format(@"{0}Samples\earth.jpg", AppDomain.CurrentDomain.BaseDirectory));
                ri.SendStream("Some Stream", String.Format(@"{0}Samples\Earth.jpg", AppDomain.CurrentDomain.BaseDirectory));
                ri.SendCustomData("Sample Custom Data", GetCustomData1());
                ri.SendColor("Some Color", Color.Aquamarine);
            }
        }
        //---------------------------------------------------------------------
        protected override void Dispose(bool disposing)
        {
            lock (this)
            {
                RIEventManager.OnServiceConfigChange -= DoOnConfigChange;

                if (FOwnsRI && FReflectInsight != null)
                {
                    FReflectInsight.Dispose();
                    FReflectInsight = null;
                }
            }

            base.Dispose(disposing);
        }
Example #12
0
        //---------------------------------------------------------------------
        public void ProcessRecord(String name, DateTime DOB)
        {
            MethodBase     mb = MethodBase.GetCurrentMethod();
            ReflectInsight ri = RITraceManager.ActiveLogger;

            ri.AddCheckpoint();
            ri.SendMsg("This is message one in: {0}", mb.Name);
            ri.SendNote("This is message two in: {0}", mb.Name);

            DataAccess da = new DataAccess();

            da.UpateRecord(name, DateTime.Now.Year - DOB.Year);

            ri.SendDebug("This is message three in: {0}", mb.Name);
            ri.SendWarning("This is message four in: {0}", mb.Name);
        }
Example #13
0
        public void UpateRecord(String name, Int32 age)
        {
            MethodBase     mb = MethodBase.GetCurrentMethod();
            ReflectInsight ri = RITraceManager.ActiveLogger;

            ri.AddCheckpoint();
            ri.SendMsg("This is message one in: {0}", mb.Name);
            ri.SendNote("This is message two in: {0}", mb.Name);

            if (age <= 0)
            {
                throw new Exception("Age must be greater than zero.");
            }

            ri.SendDebug("This is message three in: {0}", mb.Name);
            ri.SendWarning("This is message four in: {0}", mb.Name);
        }
Example #14
0
        //---------------------------------------------------------------------
        private void BtnBulkSend_Click(object sender, EventArgs e)
        {
            ReflectInsight ri = RILogManager.Default;

            Stopwatch sw = new Stopwatch();

            sw.Start();

            for (Int32 i = 0; i < (Int32)nsSendNumber.Value; i++)
            {
                ri.SendMsg("Message: {0}", i);
            }

            sw.Stop();
            LbThreadTime2.Text    = String.Format("{0} msecs", sw.ElapsedMilliseconds);
            LbThreadTime2.Visible = true;
        }
Example #15
0
        static void PrimeThread()
        {
            ReflectInsight ri = RILogManager.Default;

            using (ri.TraceMethod(MethodBase.GetCurrentMethod(), true))
            {
                using (DataSet1 = new DataSet())
                {
                    DataSet1.ReadXml(String.Format(@"{0}Samples\dataset.xml", AppDomain.CurrentDomain.BaseDirectory), XmlReadMode.Auto);

                    ri.SendMemoryStatus("Before thread launch memory status");
                    ri.SendLoadedAssemblies("Before thread launch loaded assemblies");
                    ri.SendLoadedProcesses("Before thread launch loaded processes");

                    ri.SendInformation("Preparing thread launch");

                    List <Thread> threadIds = new List <Thread>();
                    for (Int32 i = 0; i < 30; i++)
                    {
                        Thread t = new Thread(ThreadDemoBackorder);
                        t.Start(i);
                        threadIds.Add(t);

                        Thread.Sleep(500 + (10 * i));
                    }

                    ri.SendInformation("Waiting on threads to complete");
                    foreach (Thread t in threadIds)
                    {
                        t.Join();
                    }

                    ri.AddSeparator();
                    MiscellaneousSample();
                }

                ri.SendCheckmark("All threads completed successfully", Checkmark.Green);

                ri.SendMemoryStatus("After thread launch memory status");
                ri.SendLoadedAssemblies("After thread launch loaded assemblies");
                ri.SendLoadedProcesses("After thread launch loaded processes");
            }
        }
Example #16
0
        //---------------------------------------------------------------------
        public String Method1(String name, DateTime DOB, String SIN)
        {
            MethodBase     mb = MethodBase.GetCurrentMethod();
            ReflectInsight ri = RITraceManager.ActiveLogger;

            ri.AddCheckpoint();
            ri.SendMsg("This is message one in: {0}", mb.Name);
            ri.SendNote("This is message two in: {0}", mb.Name);
            ri.SendInformation("SIN: {0}", SIN);

            Business bus = new Business();

            bus.ProcessRecord(name, DOB);

            ri.SendDebug("This is message three in: {0}", mb.Name);
            ri.SendWarning("This is message four in: {0}", mb.Name);

            return(Guid.NewGuid().ToString());
        }
        //---------------------------------------------------------------------
        private void OnConfigChange()
        {
            try
            {
                lock (this)
                {
                    if (!FOwnsRI)
                    {
                        String instanceName = ReflectInsightConfig.Settings.GetExtensionAttribute("logLinqToSql", "instance", "logLinqToSql");
                        FReflectInsight = RILogManager.Get(instanceName) ?? RILogManager.Default;

                        FRequestObjectManager.RequestDetachLifeSpan = GetRequestObjectLifeSpan();
                    }
                }
            }
            catch (Exception ex)
            {
                RIExceptionManager.Publish(ex, "Failed during: LogLinqToSql.OnConfigChange()");
            }
        }
 static private void OnConfigFileChange()
 {
     try
     {
         lock (FLockObject)
         {
             RIExceptionManager.OnConfigFileChange();
             MessageQueue.OnConfigFileChange();
             MessageManager.OnConfigFileChange();
             RIListenerGroupManager.OnConfigFileChange();
             RILogManager.OnConfigFileChange();
             RIMessageColors.OnConfigFileChange();
             TraceMethod.OnConfigFileChange();
             ReflectInsight.OnConfigFileChange();
             RIEventManager.DoOnServiceConfigChange();
         }
     }
     catch (Exception ex)
     {
         RIExceptionManager.Publish(ex, "Failed during: static ReflectInsightService.OnConfigFileChange()");
     }
 }
Example #19
0
        private void TrackIndent()
        {
            RITraceListenerRequest request = FRequestObjectManager.GetRequestObject(null);

            if (request != null)
            {
                return;
            }

            if (IndentLevel > FLastIndentLevel)
            {
                ReflectInsight.Indent();
                FLastIndentLevel++;
                TrackIndent();
            }
            else if (IndentLevel < FLastIndentLevel)
            {
                ReflectInsight.Unindent();
                FLastIndentLevel--;
                TrackIndent();
            }
        }
        static private void OnStartup()
        {
            try
            {
                RIExceptionManager.OnStartup();
                MessageQueue.OnStartup();
                MessageManager.OnStartup();
                RIListenerGroupManager.OnStartup();
                DebugManager.OnStartup();
                RILogManager.OnStartup();
                RIMessageColors.OnStartup();
                TraceMethod.OnStartup();
                ReflectInsight.OnStartup();
                RIEventManager.DoOnStartup();

                RITraceListener.OnStartup();
            }
            catch (Exception ex)
            {
                RIExceptionManager.Publish(ex, "Failed during: static ReflectInsightService.OnStartup()");
            }
        }
        //---------------------------------------------------------------------
        public void UpateRecord(String name, Int32 age)
        {
            ReflectInsight ri = RILogManager.Get("DataAccess");

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

                    if (age <= 0)
                    {
                        throw new Exception("Invalid age. Age must be greater than 0 (zero)");
                    }

                    using (DataSet ds = new DataSet())
                    {
                        ds.ReadXml(String.Format(@"{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "dataset.xml"), XmlReadMode.Auto);
                        ri.SendDataSet("DataSet with 4 tables", ds);
                        ri.SendDataTable("Showing only one table (the last one)", ds.Tables[ds.Tables.Count - 1]);
                    }

                    using (var db = new NorthwindContext())
                    {
                        var orders  = (from order in db.Orders select order).ToList();
                        var details = (from order_details in db.Order_Details select order_details).ToList();

                        ri.SendEnumerable("EF Dataset", new IEnumerable[] { orders, details });
                    }
                }
                catch (Exception ex)
                {
                    ri.SendException(ex);
                    throw;
                }
            }
        }
Example #22
0
        static void RunSample()
        {
            ReflectInsight ri = new ReflectInsight();

            while (true)
            {
                Console.WriteLine("Press any key to run test or press 'q' to quit...");

                ConsoleKeyInfo k = Console.ReadKey();
                if (k.KeyChar == 'q')
                {
                    break;
                }

                ri.SendMsg("Message");
                ri.SendDebug("Debug");
                ri.SendTrace("Trace");
                ri.SendInformation("Information");
                ri.SendWarning("Warning");
                ri.SendError("Error");
                ri.SendFatal("Fatal");
                ri.SendException("Exception", new Exception("Look at inner exception for more details", new Exception("Some major exception occurred")));

                ri.Send(ReflectSoftware.Insight.Common.MessageType.SendError, "Error with details", "These are the details of this error");
                ri.Send(ReflectSoftware.Insight.Common.MessageType.SendTrace, "Trace with details", "These are the details of this trace");

                using (DataSet DataSet1 = new DataSet())
                {
                    DataSet1.ReadXml(String.Format(@"{0}Samples\dataset.xml", AppDomain.CurrentDomain.BaseDirectory), XmlReadMode.Auto);

                    ri.SendDataTable("Data Table", DataSet1.Tables[3]);
                }

                ri.SendImage("Hello, World", String.Format(@"{0}Samples\earth.jpg", AppDomain.CurrentDomain.BaseDirectory));
                ri.SendStream("Some Stream", String.Format(@"{0}Samples\Earth.jpg", AppDomain.CurrentDomain.BaseDirectory));
            }
        }
Example #23
0
        //---------------------------------------------------------------------
        public void ProcessRecord(String name, DateTime DOB)
        {
            ReflectInsight ri = RILogManager.Get("Business");

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

                    DataAccess bus = new DataAccess();
                    bus.UpateRecord(name, DateTime.Now.Year - DOB.Year);

                    ri.SendInformation("Just got back from calling the DataAccess Layer");
                }
                catch (Exception ex)
                {
                    ri.SendException(ex);
                    throw;
                }
            }
        }
Example #24
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);
                }
            }
        }
Example #25
0
        // MNIST accuracy tester
        public static void Run(double accuracyThreshold = .9979D)
        {
            MnistData mnistData   = new MnistData(28);
            Real      maxAccuracy = 0;
            //Number of middle layers
            const int N = 30; //It operates at 1000 similar to the reference link but it is slow at the CPU

            ReflectInsight ri = new ReflectInsight("Test21");

            ri.Enabled = true;
            RILogManager.Add("Test21", "Test21");
            RILogManager.SetDefault("Test21");

            //FunctionStack nn = new FunctionStack("Test21",
            //    new Linear(28 * 28, 1024, name: "l1 Linear"),
            //    new Sigmoid(name: "l1 Sigmoid"),
            //    new Linear(1024, 10, name: "l2 Linear")
            //);
            //nn.SetOptimizer(new MomentumSGD());

            FunctionStack nn = new FunctionStack("Test7",
                                                 new Linear(true, 28 * 28, N, name: "l1 Linear"), // L1
                                                 new BatchNormalization(true, N, name: "l1 BatchNorm"),
                                                 new ReLU(name: "l1 ReLU"),
                                                 new Linear(true, N, N, name: "l2 Linear"), // L2
                                                 new BatchNormalization(true, N, name: "l2 BatchNorm"),
                                                 new ReLU(name: "l2 ReLU"),
                                                 new Linear(true, N, N, name: "l3 Linear"), // L3
                                                 new BatchNormalization(true, N, name: "l3 BatchNorm"),
                                                 new ReLU(name: "l3 ReLU"),
                                                 new Linear(true, N, N, name: "l4 Linear"), // L4
                                                 new BatchNormalization(true, N, name: "l4 BatchNorm"),
                                                 new ReLU(name: "l4 ReLU"),
                                                 new Linear(true, N, N, name: "l5 Linear"), // L5
                                                 new BatchNormalization(true, N, name: "l5 BatchNorm"),
                                                 new ReLU(name: "l5 ReLU"),
                                                 new Linear(true, N, N, name: "l6 Linear"), // L6
                                                 new BatchNormalization(true, N, name: "l6 BatchNorm"),
                                                 new ReLU(name: "l6 ReLU"),
                                                 new Linear(true, N, N, name: "l7 Linear"), // L7
                                                 new BatchNormalization(true, N, name: "l7 BatchNorm"),
                                                 new ReLU(name: "l7 ReLU"),
                                                 new Linear(true, N, N, name: "l8 Linear"), // L8
                                                 new BatchNormalization(true, N, name: "l8 BatchNorm"),
                                                 new ReLU(name: "l8 ReLU"),
                                                 new Linear(true, N, N, name: "l9 Linear"), // L9
                                                 new BatchNormalization(true, N, name: "l9 BatchNorm"),
                                                 new ReLU(name: "l9 ReLU"),
                                                 new Linear(true, N, N, name: "l10 Linear"), // L10
                                                 new BatchNormalization(true, N, name: "l10 BatchNorm"),
                                                 new ReLU(name: "l10 ReLU"),
                                                 new Linear(true, N, N, name: "l11 Linear"), // L11
                                                 new BatchNormalization(true, N, name: "l11 BatchNorm"),
                                                 new ReLU(name: "l11 ReLU"),
                                                 new Linear(true, N, N, name: "l12 Linear"), // L12
                                                 new BatchNormalization(true, N, name: "l12 BatchNorm"),
                                                 new ReLU(name: "l12 ReLU"),
                                                 new Linear(true, N, N, name: "l13 Linear"), // L13
                                                 new BatchNormalization(true, N, name: "l13 BatchNorm"),
                                                 new ReLU(name: "l13 ReLU"),
                                                 new Linear(true, N, N, name: "l14 Linear"), // L14
                                                 new BatchNormalization(true, N, name: "l14 BatchNorm"),
                                                 new ReLU(name: "l14 ReLU"),
                                                 new Linear(true, N, 10, name: "l15 Linear") // L15
                                                 );

            // 0.0005 - 97.5, 0.001, 0.00146
            double alpha   = 0.001;
            double beta1   = 0.9D;
            double beta2   = 0.999D;
            double epsilon = 1e-8;

            nn.SetOptimizer(new Adam("Adam21", alpha, beta1, beta2, epsilon));

            Stopwatch sw = new Stopwatch();

            sw.Start();

            for (int epoch = 0; epoch < 3; epoch++)
            {
                Real totalLoss      = 0;
                long totalLossCount = 0;

                for (int i = 1; i < TRAIN_DATA_COUNT + 1; i++)
                {
                    TestDataSet datasetX = mnistData.GetRandomXSet(BATCH_DATA_COUNT, 28, 28);
                    Real        sumLoss  = Trainer.Train(nn, datasetX.Data, datasetX.Label, new SoftmaxCrossEntropy());
                    totalLoss = sumLoss;
                    totalLossCount++;

                    if (i % 20 == 0)
                    {
                        TestDataSet datasetY = mnistData.GetRandomYSet(TEST_DATA_COUNT, 28);
                        Real        accuracy = Trainer.Accuracy(nn, datasetY.Data, datasetY.Label, false);
                        if (accuracy > maxAccuracy)
                        {
                            maxAccuracy = accuracy;
                        }
                        Passed = (accuracy >= accuracyThreshold);

                        sw.Stop();
                        ri.ViewerSendWatch("Iteration", "epoch " + (epoch + 1) + " of 3, batch " + i + " of " + TRAIN_DATA_COUNT);
                        ri.ViewerSendWatch("Max Accuracy", maxAccuracy * 100 + "%");
                        ri.ViewerSendWatch("Current Accuracy", accuracy * 100 + "%");
                        ri.ViewerSendWatch("Total Loss ", totalLoss / totalLossCount);
                        ri.ViewerSendWatch("Elapsed Time", Helpers.FormatTimeSpan(sw.Elapsed));
                        ri.ViewerSendWatch("Accuracy Threshold", Passed ? "Passed" : "Not Passed");
                        sw.Start();
                    }
                }

                sw.Stop();
                ri.SendInformation("Total Processing Time: " + Helpers.FormatTimeSpan(sw.Elapsed));
            }
        }
 //---------------------------------------------------------------------
 public LogLinqToSql(ReflectInsight ri) : this(null, ri)
 {
 }