コード例 #1
0
        /// <summary>
        /// Converts the supplied <see cref="FaultData"/> into a <see cref="DbFaultData"/>.
        /// </summary>
        /// <param name="">The <see cref="FaultData"/> to be converted.</param>
        /// <returns></returns>
        public static DbFaultData GetDbFaultData(FaultData faultData)
        {
            Controller faultDataController = faultData.Controller;
            Device     faultDataDevice     = faultData.Device;
            Diagnostic faultDataDiagnostic = null;

            if (faultData.Diagnostic != null)
            {
                faultDataDiagnostic = faultData.Diagnostic;
            }
            User        faultDataDismissUser = faultData.DismissUser;
            FailureMode faultDataFailureMode = faultData.FailureMode;
            var         faultDataFaultState  = faultData.FaultState;

            DbFaultData dbFaultData = new DbFaultData
            {
                GeotabId           = faultData.Id.ToString(),
                AmberWarningLamp   = faultData.AmberWarningLamp,
                ControllerId       = faultDataController.Id.ToString(),
                ControllerName     = faultDataController.Name,
                Count              = faultData.Count,
                DateTime           = faultData.DateTime,
                DeviceId           = faultDataDevice.Id.ToString(),
                DiagnosticId       = "",
                DismissDateTime    = faultData.DismissDateTime,
                DismissUserId      = faultDataDismissUser.Id.ToString(),
                FailureModeId      = faultDataFailureMode.Id.ToString(),
                FailureModeName    = faultDataFailureMode.Name,
                FaultLampState     = faultData.FaultLampState.HasValue ? faultData.FaultLampState.ToString() : null,
                MalfunctionLamp    = faultData.MalfunctionLamp,
                ProtectWarningLamp = faultData.ProtectWarningLamp,
                RedStopLamp        = faultData.RedStopLamp,
                Severity           = faultData.Severity.HasValue ? faultData.Severity.ToString() : null,
                SourceAddress      = faultData.SourceAddress
            };

            if (faultDataDiagnostic != null)
            {
                dbFaultData.DiagnosticId = faultDataDiagnostic.Id.ToString();
            }
            if (faultData.ClassCode != null)
            {
                dbFaultData.ClassCode = faultData.ClassCode.ToString();
            }
            if (faultDataFailureMode.Code != null)
            {
                dbFaultData.FailureModeCode = faultDataFailureMode.Code;
            }
            if (faultDataFaultState != null)
            {
                dbFaultData.FaultState = faultDataFaultState.ToString();
            }

            return(dbFaultData);
        }
コード例 #2
0
        /// <summary>
        /// Converts the supplied list of <see cref="FaultData"/> objects into a list of <see cref="DbFaultData"/> objects.
        /// </summary>
        /// <param name="faultDatas">The list of <see cref="FaultData"/> objects to be converted.</param>
        /// <returns></returns>
        public static List <DbFaultData> GetDbFaultDatas(List <FaultData> faultDatas)
        {
            DateTime recordCreationTimeUtc = DateTime.UtcNow;
            var      dbFaultDatas          = new List <DbFaultData>();

            foreach (var faultData in faultDatas)
            {
                DbFaultData dbFaultData = GetDbFaultData(faultData);
                dbFaultData.RecordCreationTimeUtc = recordCreationTimeUtc;
                dbFaultDatas.Add(dbFaultData);
            }
            return(dbFaultDatas);
        }