async void photo_Completed(object sender, PhotoResult e)
        {
            (sender as CameraCaptureTask).Completed -= photo_Completed;
            var stream = e.ChosenPhoto;

            if (stream == null)
            {
                return;
            }

            IsBusy = true;

            var fileName = string.Format("{0}{1}{2}", StateService.CurrentAddress.UPRN, _currentQuestion.Question_Ref,
                                         (cmb1.SelectedItem as Option).OptionId);

            using (var iso = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var file = iso.OpenFile(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                {
                    await stream.CopyToAsync(file);

                    file.Flush();
                }
            }

            var media = new RichMedia
            {
                CustomerID       = _currentQuestion.CustomerID,
                CustomerSurveyID = _currentQuestion.CustomerSurveyID,
                Comments         = tbComment.Text,
                FileName         = fileName,
                Question_Ref     = _currentQuestion.Question_Ref,
                Option_ID        = (cmb1.SelectedItem as Option).OptionId,
                ID   = Guid.NewGuid().ToString(),
                UPRN = StateService.CurrentAddress.UPRN,
                IsCreatedOnClient = true
            };

            media.Identity = media.ID;


            await new DbService().Save(media, ESyncStatus.NotSynced);

            IsBusy = false;

            tbImage.Visibility = Visibility.Visible;
        }
Beispiel #2
0
        static async Task UploadMediaFile(RichMedia media)
        {
#if IMPORT
            await new DataLoaderService().SaveRichMedias(new List <RichMedia>()
            {
                media
            });
            return;
#endif

            using (var iso = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var file = iso.OpenFile(media.FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                {
                    var data = new byte[file.Length];
                    await file.ReadAsync(data, 0, data.Length);


                    var uploadResult = await
                                       new DataLoaderService().UploadFile(data, media.FileName, media.IsCreatePDF,
                                                                          media.PDFFileName, media.WatermarkText);

                    if (uploadResult.IsSuccess)
                    {
                        media.CloudPath = uploadResult.Data;
                        await new DataLoaderService().SaveRichMedias(new List <RichMedia>()
                        {
                            media
                        });
                    }
                    else
                    {
                        media.HasError     = true;
                        media.ErrorMessage = uploadResult.Data;

                        await UploadToCloud(data, media.UPRN, media.Question_Ref);

                        await new DbService().Save(media, ESyncStatus.NotSynced);
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// To upload rich media, attach the media as multipart/form-data. Currently, only jpeg and png formats are supported. The media file size should be under 10 MB for all file types. All image files have a pixel restriction of 40,000,000, and you may only upload one media object per API call.
        /// </summary>
        /// <param name="filePath">Path to jpeg or png file</param>
        /// <returns>The location of uploaded rich media (Location property of <c>RichMedia</c> class</returns>
        public async Task <RichMedia> UploadRichMediaAsync(string filePath)
        {
            CheckTokenThenAddToHeaders();
            var content = new MultipartFormDataContent();

            using (var file = new FileStream(path: filePath, mode: FileMode.Open))
            {
                content.Add(new StreamContent(file), "fileupload");
                var response = await _client.PostAsync($"{_apiHost}media/upload", content);

                var responseJson = await response.Content.ReadAsStringAsync();

                if (!response.IsSuccessStatusCode)
                {
                    throw new ApiException(ExceptionModel.FromJson(responseJson));
                }

                return(RichMedia.FromJson(responseJson));
            }
        }
Beispiel #4
0
        async void photo_Completed(object sender, PhotoResult e)
        {
            (sender as CameraCaptureTask).Completed -= photo_Completed;
            var stream = e.ChosenPhoto;

            if (stream == null)
            {
                return;
            }

            IsBusy = true;
            var addQAText = "";

            if (StateService.IsQA)
            {
                addQAText = "_QA";
            }

            var optionId = "";

            if (cmb1.SelectedItem != null)
            {
                optionId = (cmb1.SelectedItem as Option).Id.ToString();
            }

            var fileName = string.Format("{0}_{1}{2}{3}.jpg", StateService.CurrentAddress.UPRN, _currentQuestion.Question_Ref,
                                         optionId != (Guid.Empty).ToString() ? ("_" + optionId) : "", addQAText);

            using (var iso = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var file = iso.OpenFile(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                {
                    await stream.CopyToAsync(file);

                    file.Flush();
                }
            }

            await SaveToMediaLibrary(fileName, stream);

            var option = (cmb1.SelectedItem as Option);

            var media = new RichMedia
            {
                CustomerID        = _currentQuestion.CustomerID,
                CustomerSurveyID  = _currentQuestion.CustomerSurveyID,
                Comments          = tbComment.Text,
                FileName          = fileName,
                Question_Ref      = _currentQuestion.Question_Ref,
                Option_ID         = option.Id != Guid.Empty ? (Guid?)option.Id : null,
                UPRN              = StateService.CurrentAddress.UPRN,
                IsCreatedOnClient = true,
                IsCreatePDF       = _currentQuestion.createPDF || option.createPDF,
                WatermarkText     = string.Format("{0}[@n@]{1}[@n@]{2}", StateService.CurrentAddress.UPRN, _currentQuestion.Question_Heading, DateTime.Now.ToString("dd MMM yyyy HH:mm:ss"))
            };

            media.PDFFileName = media.IsCreatePDF ?
                                string.Format("{0}_{1}_{2}.pdf", StateService.CurrentAddress.UPRN, "HUNT",
                                              DateTime.Now.ToString("ddMMyyyyHHmmss"))
                    : "";


            await new DbService().Save(media, ESyncStatus.NotSynced);

            IsBusy = false;

            tbImage.Visibility = Visibility.Visible;
        }