private long CalculateMaxProgressValue(List <ImageForUpload> listImages) { long retval = 0; using (Connection sqlConn = new Connection(SQLiteBoostDB.GetDBPath())) { DamageDB ddb = new DamageDB(sqlConn); TireDB tdb = new TireDB(sqlConn); PaintDB pdb = new PaintDB(sqlConn); foreach (UploadDealerVehiclesList dealerVehicles in listDealerVehicles) { foreach (int VehicleId in dealerVehicles.VehicleIDs) { //add 20kB for each car (ws call to insert vehicle 10k + ws call to commit vehicle 10k + ws call to insert features 10k) retval += 30720; //30k - 30*1024 //only 1 service call is made for tires/paint/damages - add 10k for each if (ddb.GetDamageCount(VehicleId) >= 1) { retval += 10240; } if (tdb.GetTireCount(VehicleId) >= 1) { retval += 10240; } if (pdb.GetPaintCount(VehicleId) >= 1) { retval += 10240; } List <ImageForUpload> listImagesForVehicle = listImages.Where(i => i.vehicleId == VehicleId).ToList(); foreach (ImageForUpload ifu in listImagesForVehicle) { //add 10kB for each image (ws call to insert image) retval += 10240; //10k - 10*1024 retval += ifu.fileSize; } } } } return(retval); }
private void SavePaint() { using (Connection sqlConn = new Connection(SQLiteBoostDB.GetDBPath())) { PaintDB pdb = new PaintDB(sqlConn); string leftHood = GetEditItemValue("Left Hood"); if (!string.IsNullOrWhiteSpace(leftHood) && leftHood.ToDecimal() != 0) { pdb.AddPaint(new BoostIT.Models.Paint() { VehicleID = vehicleid, PaintAreaID = 1, Depth = leftHood.ToDecimal() }); } string leftFender = GetEditItemValue("Left Fender"); if (!string.IsNullOrWhiteSpace(leftFender) && leftFender.ToDecimal() != 0) { pdb.AddPaint(new BoostIT.Models.Paint() { VehicleID = vehicleid, PaintAreaID = 3, Depth = leftFender.ToDecimal() }); } string leftFrontDoor = GetEditItemValue("Left Front Door"); if (!string.IsNullOrWhiteSpace(leftFrontDoor) && leftFrontDoor.ToDecimal() != 0) { pdb.AddPaint(new BoostIT.Models.Paint() { VehicleID = vehicleid, PaintAreaID = 5, Depth = leftFrontDoor.ToDecimal() }); } string leftQuarterPanel = GetEditItemValue("Left 1/4 Panel"); if (!string.IsNullOrWhiteSpace(leftQuarterPanel) && leftQuarterPanel.ToDecimal() != 0) { pdb.AddPaint(new BoostIT.Models.Paint() { VehicleID = vehicleid, PaintAreaID = 11, Depth = leftQuarterPanel.ToDecimal() }); } string leftRearDoor = GetEditItemValue("Left Rear Door"); if (!string.IsNullOrWhiteSpace(leftRearDoor) && leftRearDoor.ToDecimal() != 0) { pdb.AddPaint(new BoostIT.Models.Paint() { VehicleID = vehicleid, PaintAreaID = 7, Depth = leftRearDoor.ToDecimal() }); } string leftRoof = GetEditItemValue("Left Roof"); if (!string.IsNullOrWhiteSpace(leftRoof) && leftRoof.ToDecimal() != 0) { pdb.AddPaint(new BoostIT.Models.Paint() { VehicleID = vehicleid, PaintAreaID = 9, Depth = leftRoof.ToDecimal() }); } string leftTrunk = GetEditItemValue("Left Trunk"); if (!string.IsNullOrWhiteSpace(leftTrunk) && leftTrunk.ToDecimal() != 0) { pdb.AddPaint(new BoostIT.Models.Paint() { VehicleID = vehicleid, PaintAreaID = 13, Depth = leftTrunk.ToDecimal() }); } string rightFender = GetEditItemValue("Right Fender"); if (!string.IsNullOrWhiteSpace(rightFender) && rightFender.ToDecimal() != 0) { pdb.AddPaint(new BoostIT.Models.Paint() { VehicleID = vehicleid, PaintAreaID = 4, Depth = rightFender.ToDecimal() }); } string rightFrontDoor = GetEditItemValue("Right Front Door"); if (!string.IsNullOrWhiteSpace(rightFrontDoor) && rightFrontDoor.ToDecimal() != 0) { pdb.AddPaint(new BoostIT.Models.Paint() { VehicleID = vehicleid, PaintAreaID = 6, Depth = rightFrontDoor.ToDecimal() }); } string rightHood = GetEditItemValue("Right Hood"); if (!string.IsNullOrWhiteSpace(rightHood) && rightHood.ToDecimal() != 0) { pdb.AddPaint(new BoostIT.Models.Paint() { VehicleID = vehicleid, PaintAreaID = 2, Depth = rightHood.ToDecimal() }); } string rightQuarterPanel = GetEditItemValue("Right 1/4 Panel"); if (!string.IsNullOrWhiteSpace(rightQuarterPanel) && rightQuarterPanel.ToDecimal() != 0) { pdb.AddPaint(new BoostIT.Models.Paint() { VehicleID = vehicleid, PaintAreaID = 12, Depth = rightQuarterPanel.ToDecimal() }); } string rightRearDoor = GetEditItemValue("Right Rear Door"); if (!string.IsNullOrWhiteSpace(rightRearDoor) && rightRearDoor.ToDecimal() != 0) { pdb.AddPaint(new BoostIT.Models.Paint() { VehicleID = vehicleid, PaintAreaID = 8, Depth = rightRearDoor.ToDecimal() }); } string rightRoof = GetEditItemValue("Right Roof"); if (!string.IsNullOrWhiteSpace(rightRoof) && rightRoof.ToDecimal() != 0) { pdb.AddPaint(new BoostIT.Models.Paint() { VehicleID = vehicleid, PaintAreaID = 10, Depth = rightRoof.ToDecimal() }); } string rightTrunk = GetEditItemValue("Right Trunk"); if (!string.IsNullOrWhiteSpace(rightTrunk) && rightTrunk.ToDecimal() != 0) { pdb.AddPaint(new BoostIT.Models.Paint() { VehicleID = vehicleid, PaintAreaID = 14, Depth = rightTrunk.ToDecimal() }); } } Controls.OkDialog("Success", "Paint Saved Successfully", Done); }
private void setElementValues() { //load paint values using (Connection sqlConn = new Connection(SQLiteBoostDB.GetDBPath())) { PaintDB pdb = new PaintDB(sqlConn); List <BoostIT.Models.Paint> listPaint = pdb.GetPaintList(vehicleid); foreach (BoostIT.Models.Paint paint in listPaint) { if (paint.PaintAreaID == 3) { SetEditItemValue("Left Fender", paint.Depth.ToString()); } if (paint.PaintAreaID == 5) { SetEditItemValue("Left Front Door", paint.Depth.ToString()); } if (paint.PaintAreaID == 1) { SetEditItemValue("Left Hood", paint.Depth.ToString()); } if (paint.PaintAreaID == 11) { SetEditItemValue("Left 1/4 Panel", paint.Depth.ToString()); } if (paint.PaintAreaID == 7) { SetEditItemValue("Left Rear Door", paint.Depth.ToString()); } if (paint.PaintAreaID == 9) { SetEditItemValue("Left Roof", paint.Depth.ToString()); } if (paint.PaintAreaID == 13) { SetEditItemValue("Left Trunk", paint.Depth.ToString()); } if (paint.PaintAreaID == 4) { SetEditItemValue("Right Fender", paint.Depth.ToString()); } if (paint.PaintAreaID == 6) { SetEditItemValue("Right Front Door", paint.Depth.ToString()); } if (paint.PaintAreaID == 2) { SetEditItemValue("Right Hood", paint.Depth.ToString()); } if (paint.PaintAreaID == 12) { SetEditItemValue("Right 1/4 Panel", paint.Depth.ToString()); } if (paint.PaintAreaID == 8) { SetEditItemValue("Right Rear Door", paint.Depth.ToString()); } if (paint.PaintAreaID == 10) { SetEditItemValue("Right Roof", paint.Depth.ToString()); } if (paint.PaintAreaID == 14) { SetEditItemValue("Right Trunk", paint.Depth.ToString()); } } } }
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(); } }