Example #1
0
        private CutterData ProcessRow(CutterSubscription subscription, DataRow row)
        {
            var        dataHeader = subscription.DataHeader;
            CutterData data       = null;

            try
            {
                switch (dataHeader.Type)
                {
                case "Double":
                    data = SetDouble(dataHeader, row, subscription.LastData);
                    break;

                case "Error":
                    data = SetError(dataHeader, row);
                    break;

                case "Status":
                    data = SetStatus(dataHeader, row);
                    break;

                case "String":
                    data = SetString(dataHeader, row);
                    break;
                }

                subscription.LastData = data;

                if (Verbose)
                {
                    Log.InfoFormat("ProcessRow: {0}", data);
                }
            }
            catch (Exception ex)
            {
                Error++;
                if (dataHeader != null)
                {
                    Log.WarnFormat("Exception Column: {0}", dataHeader);
                }
                DumpRow("Exception", row);
                Log.WarnFormat("Exception Data: {0}", ex);
            }
            return(data);
        }
Example #2
0
        private CutterData SetString(CutterDataHeader dataHeader, DataRow row)
        {
            var valueString = row.Field <string>(dataHeader.Legend);

            if (string.IsNullOrEmpty(valueString))
            {
                return(null);
            }

            var data = new CutterData
            {
                Date        = row.Field <DateTime>("Date"),
                Value       = 0.0,
                ValueString = valueString
            };

            return(data);
        }
Example #3
0
        private CutterData SetDouble(CutterDataHeader dataHeader, DataRow row, CutterData lastData)
        {
            var valueString = row.Field <string>(dataHeader.Legend);

            if (string.IsNullOrEmpty(valueString))
            {
                if (lastData == null)
                {
                    return(null);
                }

                valueString = lastData.ValueString;
            }

            return(new CutterData
            {
                Date = row.Field <DateTime>("Date"),
                Value = Double.Parse(valueString),
                ValueString = valueString
            });
        }
Example #4
0
        private CutterData SetError(CutterDataHeader dataHeader, DataRow row)
        {
            var valueString = row.Field <string>(dataHeader.Legend);

            if (string.IsNullOrEmpty(valueString))
            {
                return(null);
            }

            int value = int.Parse(valueString);

            if (value == 0)
            {
                return(null);
            }

            // Status index is one less than the Error Index
            CutterDataHeader statusHeader = null;

            foreach (var header in _dataHeaders)
            {
                if (header.Value.Index == dataHeader.Index - 1)
                {
                    statusHeader = header.Value;
                    break;
                }
            }

            if (statusHeader == null)
            {
                return(null);
            }

            var statusString = row.Field <string>(statusHeader.Legend);

            if (string.IsNullOrEmpty(statusString))
            {
                return(null);
            }
            int status = int.Parse(statusString);

            if (status == 0)
            {
                return(null);
            }

            var error = "Unknown";

            if ((status & StartFault) == StartFault)
            {
                error = _startErrors[value];
            }
            else if ((status & StopFault) == StopFault)
            {
                error = _stopErrors[value];
            }

            try
            {
                var data = new CutterData
                {
                    Date        = row.Field <DateTime>("Date"),
                    Value       = Double.Parse(valueString),
                    ValueString = error
                };

                return(data);
            }
            catch (Exception)
            {
                Log.ErrorFormat("Invalid Error code for {0} = {1}", dataHeader.Legend, value);
            }

            return(null);
        }