示例#1
0
        public static Task <bool> ParseCSVData(TheThing tThing, string fileName, string csvData, int delayBetweenRows, CSVParserOptions options, long previousErrorCount, Action <long, long, bool> onLineParsed)
        {
            int  lineCount      = 0;
            long lineErrorCount = previousErrorCount;

            var result = ParseCSVData(csvData,
                                      options,
                                      async(dict, sourceTimestamp) =>
            {
                lineCount++;

                if (dict == null || options.NameValuePairs && dict.Count == 0)
                {
                    lineErrorCount++;
                }
                else
                {
                    try
                    {
                        if (!String.IsNullOrEmpty(fileName))
                        {
                            dict["CurrentFile"] = fileName;
                        }
                        tThing.SetProperties(dict, sourceTimestamp);
                    }
                    catch
                    {
                        lineErrorCount++;
                    }

                    if (delayBetweenRows > 0)
                    {
                        await TheCommonUtils.TaskDelayOneEye(delayBetweenRows, 100);
                    }
                }
                onLineParsed?.Invoke(lineCount, lineErrorCount, false);
            });

            onLineParsed?.Invoke(lineCount, lineErrorCount, true);
            return(result);
        }
示例#2
0
        void GenerateStressThingData(object stressThingObj)
        {
            if (!TheBaseAssets.MasterSwitch)
            {
                m_Timer?.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
                m_Timer?.Dispose();
                m_Timer = null;
                return;
            }
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            var now = DateTimeOffset.UtcNow;

            for (int i = 1; i <= this.Gen_Config_NumberOfActiveProperties; i++)
            {
                var value = (double)valueCounter++; //r.Next(0, 1000);
                if (valueCounter % 25 == 0)
                {
                    value = double.NaN;
                }
                var propName = String.Format("Gen_Prop{0:D4}", i);
                if (bFirstRun && this.MyBaseThing.GetProperty(propName, false)?.IsSensor != true)
                {
                    this.MyBaseThing.DeclareSensorProperty(propName, ePropertyTypes.TNumber, new cdeP.TheSensorMeta {
                    });
                }
                this.MyBaseThing.SetProperty(propName, value, now);

                var newCount = System.Threading.Interlocked.Increment(ref propGenerateCounter);
            }
            bFirstRun = false;

            if (TheThing.GetSafePropertyBool(MyBaseThing, "Gen_Config_35Running"))
            {
                MyBaseThing.SetProperties(new Dictionary <string, object>
                {
                    { "35.Running", b35_Running },
                    { "35.Ended", !b35_Running },
                    { "35.Aborted", false },
                    { "35.StoppedOperator", false },
                    { "35.StoppedMalfunction", false },
                }, now);
                b35_Running = !b35_Running;
            }

            if (g_sw.ElapsedMilliseconds > this.Gen_Config_StatsUpdateInterval)
            {
                long elapsed = 0;
                lock (g_sw)
                {
                    elapsed = g_sw.ElapsedMilliseconds;
                    if (elapsed > this.Gen_Config_StatsUpdateInterval)
                    {
                        g_sw.Restart();
                    }
                }
                if (elapsed > this.Gen_Config_StatsUpdateInterval)
                {
                    var newCount = System.Threading.Interlocked.Exchange(ref propGenerateCounter, 0);
                    this.Gen_Stats_PropertyCounter    += newCount;
                    this.Gen_Stats_PropertiesPerSecond = newCount / (elapsed / 1000.0);
                    this.Gen_Stats_UpdateTime          = DateTimeOffset.Now;
                    TheBaseAssets.MySYSLOG.WriteToLog(700, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("Data Generator", "Generate", eMsgLevel.l6_Debug, String.Format("Generate Rate: {0,11:N2} properties/s", this.Gen_Stats_PropertiesPerSecond)));
                }
            }
            sw.Stop();
            long newDueTime = this.Gen_Config_PropertyUpdateInterval - sw.ElapsedMilliseconds;

            if (newDueTime < 0)
            {
                TheBaseAssets.MySYSLOG.WriteToLog(700, TSM.L(eDEBUG_LEVELS.VERBOSE) ? null : new TSM("Data Generator", "Generate", eMsgLevel.l6_Debug, String.Format("Falling behing by {0} ms", -newDueTime)));
                newDueTime = 0;
            }
            try
            {
                if (m_Timer != null)
                {
                    m_Timer.Change(newDueTime, System.Threading.Timeout.Infinite);
                }
            }
            catch (Exception)
            {
            }
        }