Exemple #1
0
        public override void Connect(TheProcessMessage pMsg)
        {
            if (IsConnected)
            {
                return;
            }
            IsConnected             = true;
            MyBaseThing.StatusLevel = 1;
            MyBaseThing.LastMessage = $"Connected to Logger at {DateTimeOffset.Now}";

            mLogFilePath    = Address;
            mMaxLogFileSize = (int)TheThing.GetSafePropertyNumber(MyBaseThing, "MaxLogFileSize");
            mWriteToConsole = TheThing.GetSafePropertyBool(MyBaseThing, "WriteToConsole");
            MyCurLog        = TheThing.GetSafePropertyString(MyBaseThing, "LogFilePath");
            mLogFileDate    = TheThing.GetSafePropertyDate(MyBaseThing, "LogFileDate");
            if (string.IsNullOrEmpty(MyCurLog) || (mLogFileDate != DateTimeOffset.MinValue && mLogFileDate.Day != DateTimeOffset.Now.Day))
            {
                LogFilePath = MyCurLog = TheCommonUtils.cdeFixupFileName(mLogFilePath + string.Format("\\LOG_{0:yyyMMdd_HHmmss}.txt", DateTime.Now));
                LogFileDate = mLogFileDate = DateTimeOffset.Now;
            }
            TheCommonUtils.CreateDirectories(MyCurLog);
            TheCDEngines.MyContentEngine.RegisterEvent(eEngineEvents.NewEventLogEntry, sinkNewEvent);

#if !CDE_NET4 && !CDE_NET35
            if (TheBaseAssets.MyCmdArgs?.ContainsKey("CreateEventLog") != true)
            {
                // CODE REVIEW: What is the purpose of this export?
                var pipelineConfig = MyBaseThing.GetThingPipelineConfigurationAsync(false).Result;
                if (pipelineConfig != null)
                {
                    var tWrite = TheCommonUtils.SerializeObjectToJSONString(pipelineConfig);
                    TheCommonUtils.CreateDirectories(TheCommonUtils.cdeFixupFileName($"\\ConfigTemplates\\{MyBaseThing.FriendlyName}.cdeConfig"));
                    using (System.IO.StreamWriter fs = new System.IO.StreamWriter(TheCommonUtils.cdeFixupFileName($"\\ConfigTemplates\\{MyBaseThing.FriendlyName}.cdeConfig"), false))
                    {
                        fs.Write(tWrite);
                    }
                }
            }
#endif
        }