示例#1
0
 /// <summary>Checks whether this device type is owned by the given parent type.</summary>
 public bool IsA(DeviceType parentType) {
    if (parentType == null) return false;
    for (var type = this; type != null; type = type.Parent as DeviceType) {
       if (type == parentType) return true;
    }
    return false;
 }
示例#2
0
      internal static string BuildKey(DeviceType dt, string sn) {
         if (sn.IsEmpty()) {
            Log.Warn("Can not build object key: Serial number is empty.");
            return null;
         }

         var prefix = "0000";
         if (dt == null) {
            Log.Warn("Device type is null, key may be invalid.");
         } else if (dt.IsA(DeviceTypes.L38E)) {
            prefix = "0004";
         } else if (dt.IsA(DeviceTypes.ICE)) {
            prefix = "0001";
         }

         return prefix + "." + sn;
      }
示例#3
0
      internal static DbBatteryInfo BatterySave(DbConnector dbConn, DeviceType dt, DbBatteryInfo bi) {
         if ((bi == null) || (bi.BatteryInfo == null)) {
            Log.Warn("Exiting: Battery info is null.");
            return null;
         }

         if (bi.BatteryInfo.BatterySN.IsEmpty()) {
            Log.Warn("Exiting: Battery serial number is empty.");
            return null;
         }

         if (IsSimulated(bi.BatteryInfo.BatterySN) || IsFactory(bi.BatteryInfo.BatterySN)) {
            Log.Warn("Exiting: Battery serial number '{0}' is factory or simulated.", bi.BatteryInfo.BatterySN);
            return null;
         }

         if (!bi.BatteryInfo.BatteryId.IsEmpty) {
            if (!bi.BatteryInfo.BatteryId.LocalId.ToString().EndsWith(bi.BatteryInfo.BatterySN)) {
               Log.Warn("BatteryId '{0}' does not match BatterySN '{1}'. Cleared.", bi.BatteryInfo.BatteryId.LocalId.ToString(), bi.BatteryInfo.BatterySN);
               bi.BatteryInfo.BatteryId = BplIdentity.Empty;
            }
         }

         bi.BatteryKey = BuildKey(dt, bi.BatteryInfo.BatterySN);
         if (bi.BatteryKey.IsEmpty()) {
            Log.Warn("Exiting: Battery Key is empty.");
            return null;
         }
        
         var exBattery = dbConn.ExecuteBpl(new BatteryGetByKey { BatteryKey = bi.BatteryKey });
         if (exBattery != null) {
            if ((exBattery.BatteryInfo.DataSource == DataSources.Vehicle) || (!OscarServer.UseBackendMasterData)) {
               if (bi.BatteryInfo.Operator == null) {
                  bi.BatteryInfo.Operator = exBattery.BatteryInfo.Operator;
               }

               dbConn.ExecuteBpl(new BatteryUpdate { i = bi });
            }
         } else {
            dbConn.ExecuteBpl(new BatteryAdd { i = bi });
         }

         return bi;
      }
示例#4
0
      internal static DbVehicleInfo VehicleSave(DbConnector dbConn, DeviceType dt, DbVehicleInfo vi) {
         if ((vi == null) || (vi.VehicleInfo == null)) {
            Log.Warn("Exiting: Vehicle info is null.");
            return null;
         }

         if (vi.VehicleInfo.VehicleSN.IsEmpty()) {
            Log.Warn("Exiting: Vehicle serial number is empty.");
            return null;
         }

         if (IsSimulated(vi.VehicleInfo.VehicleSN) || IsFactory(vi.VehicleInfo.VehicleSN)) {
            Log.Warn("Exiting: Vehicle serial number '{0}' is factory or simulated.", vi.VehicleInfo.VehicleSN);
            return null;
         }

         if (!vi.VehicleInfo.VehicleId.IsEmpty) {
            if (!vi.VehicleInfo.VehicleId.LocalId.ToString().EndsWith(vi.VehicleInfo.VehicleSN)) {
               Log.Warn("VehicleId '{0}' does not match VehicleSN '{1}'. Cleared.", vi.VehicleInfo.VehicleId.LocalId.ToString(), vi.VehicleInfo.VehicleSN);
               vi.VehicleInfo.VehicleId = BplIdentity.Empty;
            }
         }

         vi.VehicleKey = BuildKey(dt, vi.VehicleInfo.VehicleSN);
         if (vi.VehicleKey.IsEmpty()) {
            Log.Warn("Exiting: Vehicle Key is empty.");
            return null;
         }

         var exVehicle = dbConn.ExecuteBpl(new VehicleGetByKey { VehicleKey = vi.VehicleKey });
         if (exVehicle != null) {
            if ((exVehicle.VehicleInfo.DataSource == DataSources.Vehicle) || (!OscarServer.UseBackendMasterData)) {
               if (vi.VehicleInfo.Operator == null) {
                  vi.VehicleInfo.Operator = exVehicle.VehicleInfo.Operator;
               }

               dbConn.ExecuteBpl(new VehicleUpdate { i = vi });
            }
         } else {
            dbConn.ExecuteBpl(new VehicleAdd { i = vi });
         }

         if (OscarServer.UseBackendMasterData) {
            var viReq = new GetVehicleInfoHandler();
            viReq.RequestVehicleInfo(vi.VehicleInfo.VehicleId);
         }

         return vi;
      }