示例#1
0
      private GetSubscriberInfoResult _getCustomer(A.GetContactRelatedInfoResponse res) {
         if (res == null || res.person == null || res.person.personDetails == null) return null;
         var details = res.person.personDetails;

         var opco = _getOperator(details.IMTSI);
         if (opco == null) return null;

         var driver = new DriverInfo {
            DriverId = BplIdentity.Get(details.IMTSI),
            DriverSsn = details.personID,
            Operator = opco,
            Gender = _getGender(details.gender),
            Type = DriverTypes.Subscriber
         };

         var subscriber = new GetSubscriberInfoResult {
            DriverInfo = driver
         };

         var lang = opco.DefaultLanguage;
         if (lang.NotEmpty()) {
            driver.DefaultLocale = new Locale(lang);
            driver.Name = _getMultiString("{0} {1}".Substitute(details.firstName, details.lastName), lang);
         }
         
         if (details.birthdateSpecified) {
            driver.BirthDate = (Date)details.birthdate;
         }

         if (details.primaryAddress != null) {
            var addr = _getAddress(details.primaryAddress, opco, ContactTypes.HomeAddress);
            if (addr != null) {
               driver.Contacts.Add(addr);
            }
         }

         if (details.additionalAddresses != null) {
            foreach (var a in details.additionalAddresses) {
               var addr = _getAddress(a, opco, ContactTypes.OtherAddress);
               if (addr != null) {
                  driver.Contacts.Add(addr);
               }
            }
         }

         if (details.email != null) {
            driver.Contacts.Add(new Contact { Type = ContactTypes.Email, Value = details.email });
         }

         if (details.contactMethodInfo != null) {
            driver.Contacts.AddRange(details.contactMethodInfo.Select(c => _getContactInfo(c, opco)));
         }

         if (details.invoiceIndicator != null) {
            driver.Type = (bool)details.invoiceIndicator ? DriverTypes.Payer : DriverTypes.Subscriber;
         }

         if (res.vehicleList != null) {
            for (int i = 0; i < res.vehicleList.Length; i++) {
               subscriber.DriverVehicles.Add(new VehicleInfo {
                  LicensePlate = res.vehicleList[i].licensePlate,
                  VehicleId = BplIdentity.Get(res.vehicleList[i].vehicleID)
               });
            }
         }

         return subscriber;
      }
示例#2
0
      internal void Handle(PeriodicUpdateRequest request) {
         var resp = new PeriodicUpdateResponse();

         using (var dbConn = DatabaseManager.DbConn()) {
            var dataSource = DataSources.Vehicle;

            var opco = _detectOperator(request.OperatorName);
            var platformId = (request.PlatformVersion == null) ? BplIdentity.Empty : BplIdentity.Get(request.PlatformVersion.Revision.ToString("X08"));
            var deviceId = MasterDataHelpers.DeviceResolveId(dbConn, request.AutosSerialNumber, request.HardwareId);
            var codeName = "";

            if (platformId.IsEmpty || deviceId.IsEmpty) {
               DiagnosticsHelpers.ReportIntegrityError(dbConn, "PeriodicUpdateRequest", DumpRequest(), "No device information found (Device Id: '{0}') or no device type (Platform Id: '{1}'). Record skipped.", deviceId, platformId);
               Reply(resp);
               return;
            }

            var imageInstalls = dbConn.ExecuteBpl(new InstallGetByPlatformIdType { PlatformId = platformId, Type = Mpcr.Services.Oscar.Logistics.SoftwareUpdateType.Image });
            if (imageInstalls == null || imageInstalls.Count == 0) {
               Log.Warn("No installations found for platform {0}. Record skipped.", platformId.LocalId.ToString());
               Reply(resp);
               return;
            }

            var deviceType = DeviceType.Get(request.PlatformVersion.Revision);

            foreach (var cv in request.ClientVersions) {
               if (cv.Version == null || cv.UpdateType != SoftwareUpdateType.Image) {
                  continue;
               }

               var vn = SwlVersion.FromVersion(cv.Version).ToInt32();

               var ii = dbConn.ExecuteBpl(new InstallGetByPlatformIdTypeVersionNumber(platformId, (Mpcr.Services.Oscar.Logistics.SoftwareUpdateType)cv.UpdateType, vn));
               if (ii == null) {
                  continue;
               }

               codeName = ii.CodeName;
            }

            if (codeName.IsEmpty()) {
               DiagnosticsHelpers.ReportIntegrityError(dbConn, "PeriodicUpdateRequest", DumpRequest(), "No code name found for device '{0}'. Record skipped.", deviceId);
               Reply(resp);
               return;
            }

            var dei = new DeviceInfo();

            dei.DeviceId = deviceId;
            dei.Operator = opco;
            dei.Type = deviceType;
            dei.DeviceSN = request.AutosSerialNumber;
            dei.DialupPhone = PhoneStruct.ToPhone(request.AutOSClient.ModemNumber);
            dei.SimIMEI = request.AutOSClient.SimIMEI;
            dei.SimIMSI = request.AutOSClient.SimIMSI;
            dei.SecretCode = request.AutOSClient.SecretCode;
            dei.HardwareId = request.HardwareId;
            dei.DataSource = dataSource;

            var exDevice = dbConn.ExecuteBpl(new DeviceGetById { DeviceId = dei.DeviceId });
            if (exDevice != null) {
               if (dei.Operator == null) {
                  dei.Operator = exDevice.Operator;
               }

               dbConn.ExecuteBpl(new DeviceUpdate { Device = dei });
            } else {
               dbConn.ExecuteBpl(new DeviceAdd { Device = dei });
            }

            //
            // Master Data update
            //

            if (codeName.StartsWith("SP4")) {
               Log.Trace("Processing old master data update (SP4 path)");

               dbConn.BeginTransaction(this);

               var dbbi = new DbBatteryInfo();
               if (request.Battery != null) {
                  dbbi.BatteryInfo = new BatteryInfo();

                  dbbi.BatteryInfo.BatteryId = (request.Battery.IsFactory) ? BplIdentity.Empty : request.Battery.Id;
                  dbbi.BatteryInfo.Operator = opco;
                  dbbi.BatteryInfo.Type = request.Battery.Type;
                  dbbi.BatteryInfo.BatterySN = request.Battery.SerialNumber;
                  dbbi.BatteryInfo.DataSource = dataSource;

                  dbbi = MasterDataHelpers.BatterySave(dbConn, deviceType, dbbi);
               } else {
                  // no battery in request - is normal, e.g. while battery is being switched, so nothing to log here
                  dbbi = null;
               }

               var dbvi = new DbVehicleInfo();
               if (request.Vehicle != null) {
                  dbvi.VehicleInfo = new VehicleInfo();

                  dbvi.VehicleInfo.VehicleId = (request.Vehicle.IsFactory) ? BplIdentity.Empty : request.Vehicle.Id;
                  dbvi.VehicleInfo.Operator = opco;
                  dbvi.VehicleInfo.Type = request.Vehicle.Type;
                  dbvi.VehicleInfo.VehicleSN = _decodeLegacyVehicleSN(request.Vehicle.SerialNumber);
                  dbvi.VehicleInfo.VehicleVIN = request.Vehicle.VIN;
                  dbvi.VehicleInfo.LicensePlate = request.Vehicle.LicensePlate;
                  dbvi.VehicleInfo.ModelColor = request.Vehicle.Color;
                  dbvi.VehicleInfo.ModelName = request.Vehicle.ModelName;
                  dbvi.VehicleInfo.ModelYear = request.Vehicle.ModelYear;
                  dbvi.VehicleInfo.DeviceId = dei.DeviceId;
                  dbvi.VehicleInfo.DataSource = dataSource;
                  dbvi.BatteryKey = (dbbi != null) ? dbbi.BatteryKey : null;

                  dbvi = MasterDataHelpers.VehicleSave(dbConn, deviceType, dbvi);
               } else {
                  Log.Warn("No vehicle in request");
                  dbvi = null;
               }

               var dri = new DriverInfo();
               if (request.PrimaryDriver != null && request.PrimaryDriver.Type != DriverTypes.Factory) {
                  dri.DriverId = request.PrimaryDriver.Id;
                  dri.Operator = opco;
                  dri.Type = request.PrimaryDriver.Type;

                  if (request.PrimaryDriver.LocalizedName.IsEmpty) {
                     var dict = new Dictionary<Locale, string>();
                     dict[request.PrimaryDriver.PrimaryLocale] = "{0}, {1}".Substitute(request.PrimaryDriver.FirstName, request.PrimaryDriver.LastName);
                     dri.Name = MultiString.FromDictionary(dict);
                  } else {
                     dri.Name = request.PrimaryDriver.LocalizedName;
                  }

                  dri.Gender = request.PrimaryDriver.Gender;
                  dri.BirthDate = Date.Undefined;
                  dri.DriverSsn = "";
                  dri.DefaultLocale = request.PrimaryDriver.PrimaryLocale;
                  dri.DefaultVehicleId = (dbvi != null) ? dbvi.VehicleInfo.VehicleId : BplIdentity.Empty;
                  dri.DataSource = dataSource;

                  dri = MasterDataHelpers.DriverSave(dbConn, dri);

                  if ((dbvi != null) && (dri != null)) {
                     var subi = new DbSubscriptionInfo();

                     subi.SubscriptionInfo = new SubscriptionInfo();
                     subi.SubscriptionInfo.SubscriptionId = BplIdentity.Get(Guid.NewGuid().ToString());
                     subi.SubscriptionInfo.Operator = opco;
                     subi.SubscriptionInfo.Type = SubscriptionType.Get("EV");
                     subi.SubscriptionInfo.Status = SubscriptionStatus.Active;
                     subi.SubscriptionInfo.DriverId = dri.DriverId;
                     subi.SubscriptionInfo.DataSource = dataSource;
                     subi.VehicleKey = dbvi.VehicleKey;

                     dbConn.ExecuteBpl(new SubscriptionAdd { i = subi });
                  }
               } else {
                  dri = null;
               }

               dbConn.CommitTransaction();
            }

            //
            // Logistics Data update
            //

            if (!deviceId.IsEmpty) {
               dbConn.BeginTransaction(this);

               dei = dbConn.ExecuteBpl(new DeviceGetById { DeviceId = deviceId });
               if (dei != null) {
                  var devPlatformId = dbConn.ExecuteBpl(new DeviceGetPlatformId { DeviceId = deviceId });

                  if (platformId != devPlatformId) {
                     if (!platformId.IsEmpty) {
                        dbConn.ExecuteBpl(new DeviceSetPlatformId { DeviceId = dei.DeviceId, PlatformId = platformId });
                     } else {
                        platformId = devPlatformId;
                     }
                  }

                  if (!platformId.IsEmpty) {
                     dbConn.ExecuteBpl(new DeviceInstallDeleteByDeviceId(deviceId));

                     foreach (var cv in request.ClientVersions) {
                        if (cv.Version == null) {
                           Log.Warn("Version NULL in type {0}", cv.UpdateType);
                           continue;
                        }

                        var vn = SwlVersion.FromVersion(cv.Version).ToInt32();

                        Log.Trace("Type {0} Version {1} ({2})", cv.UpdateType, vn, cv.Version);

                        var ii = dbConn.ExecuteBpl(new InstallGetByPlatformIdTypeVersionNumber(platformId, (Mpcr.Services.Oscar.Logistics.SoftwareUpdateType)cv.UpdateType, vn));
                        if (ii == null) {
                           Log.Warn("No installation PLID {0}, Type {1}, Version {2}", platformId, (Mpcr.Services.Oscar.Logistics.SoftwareUpdateType)cv.UpdateType, vn);
                           continue;
                        }

                        dbConn.ExecuteBpl(new DeviceInstallAdd(deviceId, (Mpcr.Services.Oscar.Logistics.SoftwareUpdateType)cv.UpdateType, ii.InstallId));
                     }
                  }
               }

               dbConn.CommitTransaction();
            }

            var target = LogisticsHelpers.CampaignTargetCheckForUpdate(dbConn, deviceId);
            if (target != null) {
               PeriodicUpdate pu = new PeriodicUpdate();

               pu.UpdateType = (Mpcr.Messages.AutOS_SW.SoftwareUpdateType)target.CampaignType;
               pu.UpdateId = new Guid(target.TargetId.LocalId.ToString());

               resp.AvailableUpdates.Add(pu);
            }
         }

         Reply(resp);
      }
示例#3
0
      internal static DriverInfo DriverSave(DbConnector dbConn, DriverInfo di) {
         if ((di.DriverId.IsEmpty) || (MasterDataHelpers.IsFactory(di.DriverId))) {
            Log.Warn("Driver Id '{0}' is factory, guest or empty, exiting", di.DriverId);
            return null;
         }

         var exDriver = dbConn.ExecuteBpl(new DriverGetById { DriverId = di.DriverId });
         if (exDriver != null) {
            if ((exDriver.DataSource == DataSources.Vehicle) || (!OscarServer.UseBackendMasterData)) {
               if (di.Operator == null) {
                  di.Operator = exDriver.Operator;
               }

               if (di.BirthDate.IsUndefined == true) {
                  di.BirthDate = exDriver.BirthDate;
               }

               if (di.DriverSsn.IsEmpty() == true) {
                  di.DriverSsn = exDriver.DriverSsn;
               }

               dbConn.ExecuteBpl(new DriverUpdate { i = di });
            }
         } else {
            dbConn.ExecuteBpl(new DriverAdd { i = di });
         }

         if ((exDriver == null) ||
            ((exDriver.DataSource == DataSources.Vehicle) || (!OscarServer.UseBackendMasterData))) {
            dbConn.ExecuteBpl(new ContactRemoveById { ContactId = di.DriverId });
            foreach (var ct in di.Contacts) {
               if (ct.Value.IsEmpty()) {
                  continue;
               }

               var ci = new ContactInfo();
               ci.ContactId = di.DriverId;
               ci.Type = ct.Type;
               ci.Value = ct.Value;

               dbConn.ExecuteBpl(new ContactAdd { i = ci });
            }
         }

         if (OscarServer.UseBackendMasterData) {
            var driReq = new GetDriverInfoHandler();
            driReq.RequestDriverInfo(di.DriverId, false);
         }

         return di;
      }