Example #1
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            int maxSubmissions = AllServices.Count;
            List <ServiceSheetViewModel> updatedSubmissions = new List <ServiceSheetViewModel>();
            string downloadUrl;

            string customerSignatureUrl;
            string image1Url;
            string image2Url;
            string image3Url;
            string image4Url;
            string image5Url;

            foreach (ServiceSheetViewModel currentSubmission in AllServices.ToList())
            {
                downloadUrl = currentSubmission.MttEngSignatureUrl;
                ImageSource imgEngSignature = CanvasDataReader.downloadImage(downloadUrl, CanvasUser, FullUrl);

                //If there has been an error with the image download, then return an empty collection
                if (imgEngSignature == null)
                {
                    updatedSubmissions = null;
                    return;
                }

                currentSubmission.MttEngineerSignature = imgEngSignature;
                currentSubmission.MttEngineerSignature.Freeze();


                //Download the customer signature
                customerSignatureUrl = currentSubmission.CustomerSignatureUrl;
                if (!customerSignatureUrl.Equals(""))
                {
                    ImageSource imgCustSignature = CanvasDataReader.downloadImage(customerSignatureUrl, CanvasUser, FullUrl);

                    //If there has been an error with the image download, then return an empty collection
                    if (imgCustSignature == null)
                    {
                        updatedSubmissions = null;
                        return;
                    }

                    currentSubmission.CustomerSignature = imgCustSignature;
                    currentSubmission.CustomerSignature.Freeze();
                }

                //Download all the images, if they exist
                image1Url = currentSubmission.Image1Url;
                if (!image1Url.Equals(""))
                {
                    ImageSource img1 = CanvasDataReader.downloadImage(image1Url, CanvasUser, FullUrl);

                    //If there has been an error with the image download, then return an empty collection
                    if (img1 == null)
                    {
                        updatedSubmissions = null;
                        return;
                    }

                    currentSubmission.Image1 = img1;
                    currentSubmission.Image1.Freeze();
                }

                image2Url = currentSubmission.Image2Url;
                if (!image2Url.Equals(""))
                {
                    ImageSource img2 = CanvasDataReader.downloadImage(image2Url, CanvasUser, FullUrl);

                    //If there has been an error with the image download, then return an empty collection
                    if (img2 == null)
                    {
                        updatedSubmissions = null;
                        return;
                    }

                    currentSubmission.Image2 = img2;
                    currentSubmission.Image2.Freeze();
                }

                image3Url = currentSubmission.Image3Url;
                if (!image3Url.Equals(""))
                {
                    ImageSource img3 = CanvasDataReader.downloadImage(image3Url, CanvasUser, FullUrl);

                    //If there has been an error with the image download, then return an empty collection
                    if (img3 == null)
                    {
                        updatedSubmissions = null;
                        return;
                    }

                    currentSubmission.Image3 = img3;
                    currentSubmission.Image3.Freeze();
                }

                image4Url = currentSubmission.Image4Url;
                if (!image4Url.Equals(""))
                {
                    ImageSource img4 = CanvasDataReader.downloadImage(image4Url, CanvasUser, FullUrl);

                    //If there has been an error with the image download, then return an empty collection
                    if (img4 == null)
                    {
                        updatedSubmissions = null;
                        return;
                    }

                    currentSubmission.Image4 = img4;
                    currentSubmission.Image4.Freeze();
                }

                image5Url = currentSubmission.Image5Url;
                if (!image5Url.Equals(""))
                {
                    ImageSource img5 = CanvasDataReader.downloadImage(image5Url, CanvasUser, FullUrl);

                    //If there has been an error with the image download, then return an empty collection
                    if (img5 == null)
                    {
                        updatedSubmissions = null;
                        return;
                    }

                    currentSubmission.Image5 = img5;
                    currentSubmission.Image5.Freeze();
                }

                updatedSubmissions.Add(currentSubmission);
                CurrentStatus = CurrentStatus + 1;
                (sender as BackgroundWorker).ReportProgress(CurrentStatus);
            }

            //Return the list of submissions with the images
            e.Result = updatedSubmissions;
        }