private void GetMatch(Match match, PropertyInfo prop, ItemMapping mapping, object entity)
        {
            var pName  = prop.Name;
            var preVal = match.Value;
            var group  = match.Groups[pName];

            if (group.Success)
            {
                preVal = group.Value.Trim();
            }
            else
            {
                if (mapping?.MatchIndex != null)
                {
                    group = match.Groups[mapping.MatchIndex.Value];
                    if (group.Success)
                    {
                        preVal = group.Value;
                    }
                }
            }

            // Empty value is ignored
            if (string.IsNullOrEmpty(preVal))
            {
                return;
            }

            object objVal = null;

            if (!string.IsNullOrEmpty(mapping?.ValuePrepocess))
            {
                objVal = Eval.Invoke(string.Format(mapping.ValuePrepocess, preVal));
            }
            else
            {
                if (prop.PropertyType == typeof(bool))
                {
                    objVal = match.Success;
                }
                else if (prop.PropertyType == typeof(int) && int.TryParse(preVal, System.Globalization.NumberStyles.Number, _configuration.DocumentCulture, out int parVal))
                {
                    objVal = parVal;                     // Convert.ChangeType(preVal, typeof(int), _configuration.DocumentCulture);
                }
                else
                {
                    if (TryGetVal(preVal, prop.PropertyType, out object tryVal))
                    {
                        objVal = tryVal;
                    }
                }
            }

            if (objVal != null)
            {
                prop.SetValue(entity, objVal);
            }
        }
Beispiel #2
0
        private void OnTimerElapsed(object sender, ElapsedEventArgs args)
        {
            try
            {
                IdleScanAnalysis analysis = new IdleScanAnalysis(this);

                Scan?.Invoke(this, analysis);

                try
                {
                    if (analysis.Busy)
                    {
                        IdleCount = 0;

                        Busy?.Invoke(this, analysis);
                    }
                    else
                    {
                        IdleCount++;

                        Idle?.Invoke(this, analysis);
                    }
                }
                catch (Exception e)
                {
                    EventLog.WriteEntry(e.ToString(), EventLogEntryType.Error, 18);

                    analysis.Error = true;
                }

                Eval?.Invoke(this, analysis);
            }
            catch (Exception e)
            {
                EventLog.WriteEntry(e.ToString(), EventLogEntryType.Error, 19);
            }
        }