Ejemplo n.º 1
0
        private void SaveDamage()
        {
            using (Connection sqlConn = new Connection(SQLiteBoostDB.GetDBPath())) {
                DamageDB ddb = new DamageDB(sqlConn);
                if (damageid > 0)
                {
                    ddb.UpdateDamage(damage);
                }
                else
                {
                    ddb.AddDamage(damage);
                }
            }

            Controls.OkDialog("Success", "Damage Saved Successfully", Done);
        }
Ejemplo n.º 2
0
        private List <ImageForUpload> CalculateMaxForPrepageImages()
        {
            List <ImageForUpload> list = new List <ImageForUpload>();

            using (Connection sqlConn = new Connection(SQLiteBoostDB.GetDBPath())) {
                VehicleImagesDB vidb = new VehicleImagesDB(sqlConn);
                DamageDB        ddb  = new DamageDB(sqlConn);

                foreach (UploadDealerVehiclesList dealerVehicles in listDealerVehicles)
                {
                    foreach (int VehicleId in dealerVehicles.VehicleIDs)
                    {
                        List <Image>  listOfImages            = vidb.GetImagesList(VehicleId);
                        List <Damage> listOfDamagesWithImages = ddb.GetDamagesWithImages(VehicleId);

                        if ((listOfImages == null || listOfImages.Count <= 0) && (listOfDamagesWithImages == null || listOfDamagesWithImages.Count <= 0))
                        {
                            continue;
                        }

                        foreach (Image image in listOfImages)
                        {
                            if (!image.FileName.Contains("http://"))
                            {
                                list.Add(new ImageForUpload()
                                {
                                    vehicleId = VehicleId, dealershipId = dealerVehicles.DealershipID, fileNumber = image.FileNumber, filePath = image.FileName, damageId = 0
                                });
                            }
                        }

                        foreach (Damage dmg in listOfDamagesWithImages)
                        {
                            if (!dmg.FileName.Contains("http://"))
                            {
                                list.Add(new ImageForUpload()
                                {
                                    vehicleId = VehicleId, dealershipId = dealerVehicles.DealershipID, filePath = dmg.FileName, damageId = dmg.ID
                                });
                            }
                        }
                    }
                }
            }
            return(list);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public DamageDB(DamageDB damageDB)
 {
     DamageControlRating = damageDB.DamageControlRating;
 }
Ejemplo n.º 5
0
 public override bool CanCast()
 {
     Target = TargetSelector.GetTarget(Range + 150, DamageDB.GetDamageType(Player.Instance.Hero));
     return(false);
 }
Ejemplo n.º 6
0
        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();
            }
        }