Ejemplo n.º 1
0
 /// <summary>
 /// Same as ToString just without the 3000 character limitation USE CAREFULLY! This can create huge memory allocation
 /// </summary>
 /// <returns></returns>
 public string ToAllString()
 {
     return($"{TheCommonUtils.GetDateTimeString(TIM, 0, "yyyy-MM-dd HH:mm:ss.fff")} : {FID}/{QDX}/{LVL} : {ENG} : {ORG} : MSG=({(TheBaseAssets.MyServiceHostInfo.ShowMarkupInLog ? TheCommonUtils.cdeStripHTML(TXT) : TXT)}){(string.IsNullOrEmpty(PLS) ? "" : $" Payload=({(TheBaseAssets.MyServiceHostInfo.ShowMarkupInLog ? TheCommonUtils.cdeStripHTML(PLS) : PLS)})")}");
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns the TSM Header information
 /// </summary>
 /// <returns></returns>
 public string MsgHeader()
 {
     return($"{TheCommonUtils.GetDateTimeString(TIM, 0, "yyyy-MM-dd HH:mm:ss.fff")} : {FID}/{QDX}/{LVL} : {ENG} : {ORG}");
 }
Ejemplo n.º 3
0
        //private void MyUnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
        //{
        //    if (e?.IsTerminating == true)
        //    {
        //        TheBaseAssets.MySYSLOG.WriteToLog(4150, new BaseClasses.TSM("TheBaseApplication", "Unhandled exception: Calling Shutdown. Process will terminate.", eMsgLevel.l1_Error, e?.ExceptionObject?.ToString()));
        //        Shutdown(true, true);
        //    }
        //}

        void sinkEnginesStarted()
        {
            if (MyCommonDisco != null)
            {
                MyCommonDisco.StartDiscoDevice();   //MSU-OK Starts the Discovery Service -  as Device AND scanning for other relays/services
            }
            string iis = "";

            switch (TheBaseAssets.MyServiceHostInfo.cdeHostingType)
            {
            case cdeHostType.IIS: iis = " (Hosted in IIS)"; break;

            case cdeHostType.ASPCore: iis = " (Hosted in ASP.NET Core)"; break;
            }
            TheBaseAssets.MySYSLOG.WriteToLog(2, new TSM(TheBaseAssets.MyServiceHostInfo.ApplicationName, TheBaseAssets.MyServiceHostInfo.ApplicationTitle + iis + " Started at : " + TheCommonUtils.GetDateTimeString(DateTimeOffset.Now), eMsgLevel.l3_ImportantMessage)); //Log Entry that service has been started
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Shutsdown the C-DEngine and all plugins
        /// Applications can override this function to add custom shutdown code
        /// </summary>
        /// <param name="ForceExit">If True and the C-DEngine will Stop or restart the hosting application. If it is hosted in IIS, the Application Pool hosting the app will be Stopped or Restarted depending on the next parameter</param>
        /// <param name="waitIfPending">Waits in case The shutdown is already initiated</param>
        public virtual void Shutdown(bool ForceExit, bool waitIfPending = false)
        {
            if (!waitIfPending)
            {
                if (!TheBaseAssets.MasterSwitch || TheCommonUtils.cdeIsLocked(ShutdownLock))
                {
                    return;                                                                                                            //Make sure we dont do this twice
                }
            }
            lock (ShutdownLock)
            {
                if (TheBaseAssets.MasterSwitch)
                {
                    if (TheBaseAssets.IsStarting)
                    {
                        TheBaseAssets.MySYSLOG?.WriteToLog(3, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM(TheBaseAssets.MyServiceHostInfo.ApplicationName, "Shutdown was requested, but startup has not finished. Waiting for startup to finish.", eMsgLevel.l3_ImportantMessage));
                        // Ensure we wait for user manager so CUOFS first-run-only settings are applied
                        var sw = System.Diagnostics.Stopwatch.StartNew();
                        while (TheBaseAssets.IsStarting && sw.ElapsedMilliseconds < 60000)
                        {
                            Thread.Sleep(100);
                        }
                        if (TheBaseAssets.IsStarting)
                        {
                            TheBaseAssets.MySYSLOG?.WriteToLog(3, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM(TheBaseAssets.MyServiceHostInfo.ApplicationName, "Shutdown was requested, but startup has not finished after wait time (60 seconds). Shutting down regardless. Some first-run-only settings may not have been applied.", eMsgLevel.l1_Error));
                        }
                    }
                    if (TheBaseAssets.MyServiceHostInfo.PreShutDownDelay > 0)
                    {
                        var tcsPreHandlers = new TaskCompletionSource <bool>();
                        TheCommonUtils.cdeRunAsync("PreShutdownHandlers", true, (o) =>
                        {
                            TheCDEngines.MyContentEngine?.FireEvent(eEngineEvents.PreShutdown, null, TheBaseAssets.MyServiceHostInfo.PreShutDownDelay, false);
                            tcsPreHandlers.TrySetResult(true);
                        });
                        tcsPreHandlers.Task.Wait(TheBaseAssets.MyServiceHostInfo.PreShutDownDelay);
                    }
                    while (Interlocked.Read(ref TheBaseAssets.DelayShutDownCount) > 0)
                    {
                        TheCommonUtils.SleepOneEye(100, 100);
                    }
                    TheBaseAssets.MySYSLOG?.WriteToLog(3, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM(TheBaseAssets.MyServiceHostInfo.ApplicationName, TheBaseAssets.MyServiceHostInfo.ApplicationTitle + " Initiating shutdown at : " + TheCommonUtils.GetDateTimeString(DateTimeOffset.Now), eMsgLevel.l6_Debug));
                    TheBaseAssets.MasterSwitch  = false;
                    TheBaseAssets.ForceShutdown = ForceExit;
                    TheCDEngines.StopAllEngines();
                    TheBaseAssets.MySYSLOG?.WriteToLog(3, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM(TheBaseAssets.MyServiceHostInfo.ApplicationName, TheBaseAssets.MyServiceHostInfo.ApplicationTitle + " Shutdown: Engines stopped at: " + TheCommonUtils.GetDateTimeString(DateTimeOffset.Now), eMsgLevel.l6_Debug));

                    TheCommCore.StopCommunication();
                    TheBaseAssets.MySYSLOG?.WriteToLog(3, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM(TheBaseAssets.MyServiceHostInfo.ApplicationName, TheBaseAssets.MyServiceHostInfo.ApplicationTitle + " Shutdown: Communications stopped at: " + TheCommonUtils.GetDateTimeString(DateTimeOffset.Now), eMsgLevel.l6_Debug));
                    if (MyCommonDisco != null)
                    {
                        MyCommonDisco.ShutdownDiscoService();
                        TheBaseAssets.MySYSLOG?.WriteToLog(3, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM(TheBaseAssets.MyServiceHostInfo.ApplicationName, TheBaseAssets.MyServiceHostInfo.ApplicationTitle + " Shutdown: Discovery Service stopped at: " + TheCommonUtils.GetDateTimeString(DateTimeOffset.Now), eMsgLevel.l6_Debug));
                    }
                    if (TheBaseAssets.MySYSLOG != null)
                    {
                        string iis = "";
                        switch (TheBaseAssets.MyServiceHostInfo.cdeHostingType)
                        {
                        case cdeHostType.IIS: iis = " (Hosted in IIS)"; break;

                        case cdeHostType.ASPCore: iis = " (Hosted in ASP.NET Core)"; break;
                        }
                        TheBaseAssets.MySYSLOG.WriteToLog(3, new TSM(TheBaseAssets.MyServiceHostInfo.ApplicationName, TheBaseAssets.MyServiceHostInfo.ApplicationTitle + iis + " Stopped at : " + TheCommonUtils.GetDateTimeString(DateTimeOffset.Now), eMsgLevel.l4_Message)); //Log Entry that service has been started
                        TheBaseAssets.MySYSLOG.Shutdown();
                    }
                }
            }
        }
Ejemplo n.º 5
0
        internal string GetNodeLog(TheSessionState pSession, string InTopic, bool ShowLinks)
        {
            string outText = "";

            if (!string.IsNullOrEmpty(InTopic))
            {
                InTopic = TheCommonUtils.cdeUnescapeString(InTopic);
            }
            outText += $"<div class=\"cdeInfoBlock\" style=\"clear:both; width:initial; \"><div class=\"cdeInfoBlockHeader cdeInfoBlockHeaderText\" id=\"systemLog\">Current SystemLog <a download=\"cdeSysLog_{TheCommonUtils.GetMyNodeName()}.csv\" href=\"#\" class=\'cdeExportLink\' onclick=\"return ExcellentExport.csv(this, 'cdeSysLog');\">(Export as CSV)</a></div>";
            try
            {
                outText += "<table class=\"cdeHilite\" id=\"cdeSysLog\" style=\"width:95%\">";
                outText += "<tr><th style=\"background-color:rgba(90,90,90, 0.25);font-size:small;\">Serial</th>";
                outText += "<th style=\"background-color:rgba(90,90,90, 0.25);font-size:small; \">LogID</th>";
                outText += "<th style=\"background-color:rgba(90,90,90, 0.25);font-size:small; \">Entry Date</th>";
                outText += "<th style=\"background-color:rgba(90,90,90, 0.25);font-size:small; \">Level</th>";
                //outText += "<th style=\"background-color:rgba(90,90,90, 0.25);font-size:small; \">ORG</th>";
                outText += "<th style=\"background-color:rgba(90,90,90, 0.25);font-size:small; \">Engine</th>";
                outText += "<th style=\"background-color:rgba(90,90,90, 0.25);font-size:small; \">Text</th><tr>";
                int MaxCnt = MyMessageLog.MyMirrorCache.Count;
                foreach (TheEventLogEntry tLogEntry in MyMessageLog.MyMirrorCache.MyRecords.Values.OrderByDescending(s => s.Serial).ToList()) //.cdeCTIM).ThenByDescending(s=>s.cdeCTIM.Millisecond).ToList())
                {
                    TSM tMsg = tLogEntry.Message;
                    if (!string.IsNullOrEmpty(InTopic) && !tMsg.ENG.Equals(InTopic))
                    {
                        continue;
                    }
                    if (tMsg.TXT == null)
                    {
                        tMsg.TXT = "";
                    }
                    var tColor = "black";
                    if (tMsg.TXT.Contains("ORG:2;"))
                    {
                        tColor = "blue";
                    }
                    else
                    {
                        if (tMsg.TXT.Contains("ORG:4;"))
                        {
                            tColor = "purple";
                        }
                        else
                        {
                            if (tMsg.TXT.Contains("ORG:3;"))
                            {
                                tColor = "navy";
                            }
                            else
                            {
                                if (tMsg.TXT.Contains("ORG:7;"))
                                {
                                    tColor = "brown";
                                }
                                else
                                {
                                    if (tMsg.TXT.Contains("ORG:8;") || TheCommonUtils.DoesContainLocalhost(tMsg.TXT))
                                    {
                                        tColor = "gray";
                                    }
                                }
                            }
                        }
                    }
                    switch (tMsg.LVL)
                    {
                    case eMsgLevel.l1_Error:
                        tColor = "red";
                        break;

                    case eMsgLevel.l2_Warning:
                        tColor = "orange";
                        break;

                    case eMsgLevel.l3_ImportantMessage:
                        tColor = "green";
                        break;

                    case eMsgLevel.l7_HostDebugMessage:
                        tColor = "gray";
                        break;

                    case eMsgLevel.l6_Debug:
                        tColor = "gray";
                        break;
                    }
                    outText += $"<tr>";
                    outText += $"<td class=\"cdeLogEntry\" style=\"color:{tColor}\">{tLogEntry.Serial}</td>";
                    outText += $"<td class=\"cdeLogEntry\" style=\"color:{tColor}\">{tLogEntry.EventID}</td>";
                    outText += $"<td class=\"cdeLogEntry\" style=\"color:{tColor}\">{TheCommonUtils.GetDateTimeString(tMsg.TIM, 0, "yyyy-MM-dd HH:mm:ss.fff")}</td>";
                    outText += $"<td class=\"cdeLogEntry\" style=\"color:{tColor}\">{tMsg.LVL}{(TSM.L(eDEBUG_LEVELS.ESSENTIALS)?tMsg.GetHash().ToString():"")}</td>";
                    //outText += $"<td class=\"cdeLogEntry\" style=\"color:{tColor}\">{tMsg.ORG}</td>";    //ORG-OK
                    if (ShowLinks && pSession != null)
                    {
                        outText += $"<td class=\"cdeLogEntry\"><SMALL><a href=\"/cdeStatus.aspx?Filter={TheCommonUtils.cdeEscapeString(tMsg.ENG)}\">{tMsg.ENG}</a></SMALL></td>";
                    }
                    else
                    {
                        outText += $"<td class=\"cdeLogEntry\"><SMALL>{tMsg.ENG.Replace(".", " ")}</SMALL></td>";
                    }
                    outText += $"<td class=\"cdeLogEntry\" style=\"color:{tColor}\">{tMsg.TXT}</td>";
                    outText += "</tr>";
                    if (!string.IsNullOrEmpty(tMsg.PLS))
                    {
                        outText += $"<tr><td class=\"cdeLogEntry\" style=\"color:{tColor}\">{tLogEntry.Serial}</td><td class=\"cdeLogEntry\" colspan=\"7\" style=\"color:{tColor}\"><SMALL>{TheCommonUtils.cdeESCXMLwBR(TheCommonUtils.cdeSubstringMax(tMsg.PLS, 2000))}</SMALL></td></tr>"; //Find a better way. This does not work with the sorttable
                    }
                    MaxCnt--;
                }
                outText += "</tbody></table></div>";
            }
            catch (Exception e)
            {
                outText += "Exception in Log: " + e;
            }
            return(outText);
        }