private int getTotalDuplicateCount() { using (Connection sqlConn = new Connection(SQLiteBoostDB.GetDBPath())) { VehicleDB vdb = new VehicleDB(sqlConn); List <DuplicateCheck> vehiclesToCheck = new List <DuplicateCheck>(); foreach (UploadDealerVehiclesList dealerVehicles in listDealerVehicles) { foreach (int id in dealerVehicles.VehicleIDs) { Vehicle vehicle = vdb.GetVehicle(id); vehiclesToCheck.Add(new DuplicateCheck() { DealershipID = dealerVehicles.DealershipID, StockNumber = vehicle.StockNumber, VIN = vehicle.VIN }); } } if (vehiclesToCheck.Count > 0) { return(uploader.GetTotalDuplicatesFound(vehiclesToCheck)); } } return(0); }
private void PrintData() { // Print car ID and name (if it exists) Console.WriteLine($"ID: {LastUpdate.CarOrdinal}\t{VehicleDB.GetVehicle(LastUpdate.CarOrdinal).ToString()} [ {LastUpdate.CarClass.ToString()} | {LastUpdate.CarPI} ]"); }
private void StartUpload() { //prepare all images to upload List <ImageForUpload> listOfImagesToUpload = prepareImagesForUpload(); if (stopEvent.WaitOne(0)) { return; } //prepare counters and progress bar int totalVehicleCount = GetTotalVehicles(); maxValue = CalculateMaxProgressValue(listOfImagesToUpload); //calculate max value for total progress (total kB of images) //this.InvokeOnMainThread(delegate { pbTotal.Max = (int)maxValue; }); using (Connection sqlConn = new Connection(SQLiteBoostDB.GetDBPath())) { //initialize vars VehicleDB vdb = new VehicleDB(sqlConn); VehicleFeaturesDB vfdb = new VehicleFeaturesDB(sqlConn); DamageDB ddb = new DamageDB(sqlConn); TireDB tdb = new TireDB(sqlConn); PaintDB pdb = new PaintDB(sqlConn); int vehCounter = 0; foreach (UploadDealerVehiclesList dealerVehicles in listDealerVehicles) { mobileUploadID = 0; PauseUpload(); uploader.GetMobileUploadID(userId, dealerVehicles.DealershipID); pauseEvent.WaitOne(Timeout.Infinite); if (stopEvent.WaitOne(0)) { return; } if (mobileUploadID <= 0) { Upload_Failed("Unable to retrieve a valid upload key."); return; } foreach (int vehicleId in dealerVehicles.VehicleIDs) { pauseEvent.WaitOne(Timeout.Infinite); if (stopEvent.WaitOne(0)) { return; } //initialize variables for next vehicle skipVehicle = false; mobileVehicleId = 0; dupeResponse = null; vehCounter++; Vehicle vehicle = vdb.GetVehicle(vehicleId); //reset progress for images and set the vehicle counter this.InvokeOnMainThread(delegate { nbUpload.TopItem.Title = "Uploading Vehicle " + vehCounter + "/" + totalVehicleCount; }); //check if vehicle already exists if (!overwriteAll && (!string.IsNullOrEmpty(vehicle.StockNumber) || !string.IsNullOrEmpty(vehicle.VIN))) { PauseUpload(); uploader.GetDuplicateData(dealerVehicles.DealershipID, vehicle.StockNumber, vehicle.VIN); pauseEvent.WaitOne(Timeout.Infinite); if (stopEvent.WaitOne(0)) { return; } if (dupeResponse != null && dupeResponse.TotalDuplicates > 0) { CheckSkipVehicle(dupeResponse); //wait until the user responds pauseEvent.WaitOne(Timeout.Infinite); if (skipVehicle) { continue; } } } //Upload vehicle data PauseUpload(); uploader.UploadVehicleData(mobileUploadID, vehicle); //wait for upload of data to complete pauseEvent.WaitOne(Timeout.Infinite); if (stopEvent.WaitOne(0)) { return; } if (skipVehicle || mobileVehicleId <= 0) { continue; } //update the progress for the vehicle data upload updateTotalProgress(10240); //upload feature data PauseUpload(); uploader.UploadFeatureData(mobileVehicleId, vfdb.GetSelectedFeatures(vehicle.ID)); //wait for upload of features to complete pauseEvent.WaitOne(Timeout.Infinite); if (stopEvent.WaitOne(0)) { return; } if (skipVehicle) { continue; } //update the progress for the features data upload updateTotalProgress(10240); //damages PauseUpload(); uploader.UploadDamageData(mobileVehicleId, ddb.GetDamageList(vehicle.ID)); pauseEvent.WaitOne(Timeout.Infinite); //wait for upload of damages to complete if (stopEvent.WaitOne(0)) { return; } if (skipVehicle) { continue; } updateTotalProgress(10240); //add damage progress //paint PauseUpload(); uploader.UploadPaintData(mobileVehicleId, pdb.GetPaintList(vehicle.ID)); pauseEvent.WaitOne(Timeout.Infinite); //wait for upload of paint to complete if (stopEvent.WaitOne(0)) { return; } if (skipVehicle) { continue; } updateTotalProgress(10240); //add paint progress //tires PauseUpload(); uploader.UploadTireData(mobileVehicleId, tdb.GetTireList(vehicle.ID)); pauseEvent.WaitOne(Timeout.Infinite); //wait for upload of tires to complete if (stopEvent.WaitOne(0)) { return; } if (skipVehicle) { continue; } updateTotalProgress(10240); //add tire progress //loop images to upload if (listOfImagesToUpload != null && listOfImagesToUpload.Count > 0) { List <ImageForUpload> listOfImagesForVehicle = listOfImagesToUpload.Where(i => i.vehicleId == vehicleId && i.dealershipId == dealerVehicles.DealershipID).ToList(); int imgCounter = 0; foreach (ImageForUpload img in listOfImagesForVehicle) { pauseEvent.WaitOne(Timeout.Infinite); if (stopEvent.WaitOne(0)) { return; } //initialize image variables imgCounter++; currentFileSize = (int)img.fileSize; this.InvokeOnMainThread(delegate { pbCurrentVehicle.Progress = 0f; //pbIVtotal.Max = (int)img.fileSize; maxImageSize = (int)img.fileSize; lblCurrentVehicle.Text = "Uploading image " + imgCounter + " of " + listOfImagesForVehicle.Count() + " for this vehicle."; }); if (img.damageId > 0) { pauseEvent.Reset(); //don't want to pause the "uploader" object, only local - don't use "PauseUpload()" uploader.UploadDamageFile(mobileUploadID, mobileVehicleId, img.damageId, File.ReadAllBytes(img.filePath)); pauseEvent.WaitOne(Timeout.Infinite); if (stopEvent.WaitOne(0)) { return; } if (skipVehicle) { break; } continue; } pauseEvent.Reset(); //don't want to pause the "uploader" object, only local - don't use "PauseUpload()" uploader.UploadFile(mobileUploadID, mobileVehicleId, img.fileNumber, File.ReadAllBytes(img.filePath)); pauseEvent.WaitOne(Timeout.Infinite); if (stopEvent.WaitOne(0)) { return; } if (skipVehicle) { break; } //insert image to database PauseUpload(); uploader.UploadImageData(mobileVehicleId, img.fileNumber); pauseEvent.WaitOne(Timeout.Infinite); if (stopEvent.WaitOne(0)) { return; } if (skipVehicle) { break; } //update the progress for the image update updateTotalProgress(10240); } } if (stopEvent.WaitOne(0)) //check if the upload has been cancelled before committing data { return; } if (skipVehicle) //check if the vehicle is skipped { continue; } //commit vehicle PauseUpload(); uploader.CommitVehicle(mobileVehicleId); pauseEvent.WaitOne(Timeout.Infinite); if (stopEvent.WaitOne(0)) { return; } if (skipVehicle) { continue; } //Delete the vehicle from the device vdb.DeleteVehicle(vehicle.ID); //update the progress for the commit updateTotalProgress(10240); } } } if (!stopEvent.WaitOne(0)) { Upload_Complete(); } }