Ejemplo n.º 1
0
        public async Task Upload_Empty_Photo(KnownChains apiName)
        {
            var request  = new UploadMediaModel(Users[apiName], new MemoryStream(), ".jpg");
            var response = await Api[apiName].UploadMedia(request, CancellationToken.None);

            Assert.IsTrue(response.Error.Message.StartsWith("The submitted file is empty."));
        }
Ejemplo n.º 2
0
        public async Task <OperationResult <MediaModel> > UploadMedia(UploadMediaModel model, CancellationToken ct)
        {
            if (!EnableRead)
            {
                return(null);
            }

            var results = Validate(model);

            if (results.Any())
            {
                return(new OperationResult <MediaModel>(new ValidationError(results)));
            }

            var trxResp = await _ditchClient.GetVerifyTransaction(model, ct);

            if (!trxResp.IsSuccess)
            {
                return(new OperationResult <MediaModel>(trxResp.Error));
            }

            model.VerifyTransaction = JsonConverter.Serialize(trxResp.Result);

            var endpoint = $"{BaseUrl}/{GatewayVersion.V1P1}/media/upload";

            return(await Gateway.UploadMedia(endpoint, model, ct));
        }
Ejemplo n.º 3
0
        public async Task <OperationResult <MediaModel> > UploadMedia(string url, UploadMediaModel model,
                                                                      CancellationToken token)
        {
            var fTitle = Guid.NewGuid().ToString();

            var file = new StreamContent(model.File);

            file.Headers.ContentType = MediaTypeHeaderValue.Parse(model.ContentType);
            var multiContent = new MultipartFormDataContent
            {
                { new StringContent(model.VerifyTransaction), "trx" },
                { file, "file", fTitle },
                { new StringContent(model.GenerateThumbnail.ToString()), "generate_thumbnail" }
            };

            var response = await _client.PostAsync(url, multiContent, token);

            var result = await CreateResult <MediaModel>(response, token);

            if (result.IsSuccess && result.Result == null)
            {
                result.Error = new AppError(LocalizationKeys.ServeUnexpectedError);
            }

            return(result);
        }
Ejemplo n.º 4
0
        private async Task <OperationResult <MediaModel> > UploadPhoto(string path)
        {
            System.IO.Stream stream          = null;
            FileInputStream  fileInputStream = null;

            try
            {
                var photo = new Java.IO.File(path);
                fileInputStream = new FileInputStream(photo);
                stream          = new StreamConverter(fileInputStream, null);

                var request      = new UploadMediaModel(AppSettings.User.UserInfo, stream, System.IO.Path.GetExtension(path));
                var serverResult = await Presenter.TryUploadMedia(request);

                return(serverResult);
            }
            catch (Exception ex)
            {
                AppSettings.Reporter.SendCrash(ex);
                return(new OperationResult <MediaModel>(new AppError(LocalizationKeys.PhotoProcessingError)));
            }
            finally
            {
                fileInputStream?.Close(); // ??? change order?
                stream?.Flush();
                fileInputStream?.Dispose();
                stream?.Dispose();
            }
        }
Ejemplo n.º 5
0
        public async Task <OperationResult <MediaModel> > UploadMedia(UploadMediaModel model, CancellationToken ct)
        {
            if (!EnableRead)
            {
                return(null);
            }

            var results = Validate(model);

            if (results.Any())
            {
                return(new OperationResult <MediaModel>(new ValidationError(results)));
            }

            var trxResp = await _ditchClient.GetVerifyTransaction(model, ct);

            if (!trxResp.IsSuccess)
            {
                return(new OperationResult <MediaModel>(trxResp.Error));
            }

            model.VerifyTransaction = trxResp.Result;

            return(await Gateway.UploadMedia(GatewayVersion.V1P1, "media/upload", model, ct));
        }
Ejemplo n.º 6
0
        private async Task <OperationResult <MediaModel> > UploadPhoto()
        {
            Stream stream = null;

            try
            {
                var compression    = 1f;
                var maxCompression = 0.1f;
                int maxFileSize    = _photoSize * 1024;

                var byteArray = ImageAsset.AsJPEG(compression);

                while (byteArray.Count() > maxFileSize && compression > maxCompression)
                {
                    compression -= 0.1f;
                    byteArray    = ImageAsset.AsJPEG(compression);
                }

                stream = byteArray.AsStream();
                var request = new UploadMediaModel(BasePresenter.User.UserInfo, stream, ImageExtension);
                return(await _presenter.TryUploadMedia(request));
            }
            catch (Exception ex)
            {
                AppSettings.Reporter.SendCrash(ex);
                return(new OperationResult <MediaModel>(new AppError(LocalizationKeys.PhotoProcessingError)));
            }
            finally
            {
                stream?.Flush();
                stream?.Dispose();
            }
        }
Ejemplo n.º 7
0
        public async Task <OperationResult <MediaModel> > GetLastPost(HttpManager client, DebugAsset debugAsset, CancellationToken token)
        {
            //https://www.instagram.com/developer/authentication/ < how to get access_token (OAuth skiped. hardcoded key used instead... time time..)v
            var fullUrl = GetRecentMediaUrl + debugAsset.InsagramAccessToken;

            if (!string.IsNullOrEmpty(debugAsset.LastLoadedMediaId))
            {
                fullUrl += "&MIN_ID=" + debugAsset.LastLoadedMediaId;
            }
            var responce = await client.GetRequest <InstagramResult>(fullUrl, token);

            if (responce.IsError)
            {
                throw new NotImplementedException(responce.Error.Msg);
            }

            var media = responce.Result.data.FirstOrDefault();

            if (debugAsset.LastLoadedMediaId != null && debugAsset.LastLoadedMediaId.Equals(media.id))
            {
                return(null);
            }

            debugAsset.LastLoadedMediaId = media.id;

            //save image to IPFS
            var model = new UploadMediaModel
            {
                VerifyTransaction = debugAsset.AuthorizationTransactionJson,
                Url = media.images.standard_resolution.url
            };

            return(await client.UploadMedia("https://steepshot.org/api/v1_1/media/upload", model, token));
        }
Ejemplo n.º 8
0
        private async Task <OperationResult <UUIDModel> > UploadMedia(GalleryMediaModel model)
        {
            model.UploadState = UploadState.UploadStart;
            System.IO.Stream stream          = null;
            FileInputStream  fileInputStream = null;

            try
            {
                var photo = new Java.IO.File(model.TempPath);
                fileInputStream = new FileInputStream(photo);
                stream          = new StreamConverter(fileInputStream, null);

                var request      = new UploadMediaModel(AppSettings.User.UserInfo, stream, System.IO.Path.GetExtension(model.TempPath));
                var serverResult = await Presenter.TryUploadMedia(request);

                model.UploadState = UploadState.UploadEnd;
                return(serverResult);
            }
            catch (Exception ex)
            {
                model.UploadState = UploadState.UploadError;
                await AppSettings.Logger.Error(ex);

                return(new OperationResult <UUIDModel>(new InternalException(LocalizationKeys.PhotoUploadError, ex)));
            }
            finally
            {
                fileInputStream?.Close(); // ??? change order?
                stream?.Flush();
                fileInputStream?.Dispose();
                stream?.Dispose();
            }
        }
Ejemplo n.º 9
0
        public async Task <OperationResult <MediaModel> > UploadMedia(string url, UploadMediaModel model, CancellationToken token)
        {
            var fTitle = Guid.NewGuid().ToString();

            MemoryStream stream;

            using (WebClient client = new WebClient())
            {
                var bytes = client.DownloadData(new Uri(model.Url));
                stream = new MemoryStream(bytes);
            }

            var file = new StreamContent(stream);

            file.Headers.ContentType = MediaTypeHeaderValue.Parse(model.ContentType);
            var multiContent = new MultipartFormDataContent
            {
                { new StringContent(model.VerifyTransaction), "trx" },
                { file, "file", fTitle },
                { new StringContent(model.GenerateThumbnail.ToString()), "generate_thumbnail" }
            };

            var response = await _client.PostAsync(url, multiContent, token);

            var result = await CreateResult <MediaModel>(response, token);

            if (result.IsError && result.Result == null)
            {
                result.Error = new ErrorBase("Can`t upload image!");
            }

            return(result);
        }
Ejemplo n.º 10
0
        public override async Task <OperationResult <string> > GetVerifyTransaction(UploadMediaModel model, CancellationToken ct)
        {
            if (!TryReconnectChain(ct))
            {
                return(new OperationResult <string>(new ApplicationError(Localization.Errors.EnableConnectToBlockchain)));
            }

            var keys = ToKeyArr(model.PostingKey);

            if (keys == null)
            {
                return(new OperationResult <string>(new ApplicationError(Localization.Errors.WrongPrivatePostingKey)));
            }

            return(await Task.Run(() =>
            {
                var op = new FollowOperation(model.Login, "steepshot", DitchFollowType.Blog, model.Login);
                var properties = new DynamicGlobalPropertyObject
                {
                    HeadBlockId = Hex.ToString(_operationManager.ChainId),
                    Time = DateTime.Now,
                    HeadBlockNumber = 0
                };
                var tr = _operationManager.CreateTransaction(properties, keys, ct, op);
                return new OperationResult <string>()
                {
                    Result = JsonConverter.Serialize(tr)
                };
            }, ct));
        }
Ejemplo n.º 11
0
        public async Task <OperationResult <UUIDModel> > UploadMedia(string url, UploadMediaModel model, CancellationToken token)
        {
            var fTitle = Guid.NewGuid().ToString();

            var file = new StreamContent(model.File);

            file.Headers.ContentType = MediaTypeHeaderValue.Parse(model.ContentType);
            var multiContent = new MultipartFormDataContent
            {
                { file, "file", fTitle },
                { new StringContent(model.Thumbnails.ToString()), "thumbnails" },
                { new StringContent(model.AWS.ToString()), "aws" },
                { new StringContent(model.IPFS.ToString()), "ipfs" }
            };

            var response = await PostAsync(url, multiContent, token);

            var result = await CreateResult <UUIDModel>(response, token);

            if (result.IsSuccess && result.Result == null)
            {
                result.Exception = new ValidationException(LocalizationKeys.ServeUnexpectedError);
            }

            return(result);
        }
Ejemplo n.º 12
0
        public async Task UploadMediaTest(KnownChains apiName)
        {
            var user = Users[apiName];

            // 1) Create new post
            var path             = GetTestImagePath();
            var stream           = new FileStream(GetTestImagePath(), FileMode.Open);
            var uploadImageModel = new UploadMediaModel(user, stream, Path.GetExtension(path));
            var servResp         = await Api[apiName].UploadMedia(uploadImageModel, CancellationToken.None);

            AssertResult(servResp);
        }
        private async Task <OperationResult <MediaModel> > UploadPhoto(UIImage photo, NSDictionary metadata)
        {
            Stream stream = null;

            try
            {
                var compression    = 1f;
                var maxCompression = 0.1f;
                int maxFileSize    = _photoSize * 1024;

                var byteArray = photo.AsJPEG(compression);

                while (byteArray.Count() > maxFileSize && compression > maxCompression)
                {
                    compression -= 0.1f;
                    byteArray    = photo.AsJPEG(compression);
                }

                if (metadata != null)
                {
                    //exif setup
                    var editedExifData       = RemakeMetadata(metadata, photo);
                    var newImageDataWithExif = new NSMutableData();
                    var imageDestination     = CGImageDestination.Create(newImageDataWithExif, "public.jpeg", 0);
                    imageDestination.AddImage(new UIImage(byteArray).CGImage, editedExifData);
                    imageDestination.Close();
                    stream = newImageDataWithExif.AsStream();
                }
                else
                {
                    stream = byteArray.AsStream();
                }

                var request = new UploadMediaModel(AppSettings.User.UserInfo, stream, ImageExtension);
                return(await _presenter.TryUploadMedia(request));
            }
            catch (Exception ex)
            {
                AppSettings.Reporter.SendCrash(ex);
                return(new OperationResult <MediaModel>(new AppError(LocalizationKeys.PhotoProcessingError)));
            }
            finally
            {
                stream?.Flush();
                stream?.Dispose();
            }
        }
Ejemplo n.º 14
0
        public async Task <OperationResult <UUIDModel> > UploadMedia(UploadMediaModel model, CancellationToken ct)
        {
            if (!EnableRead)
            {
                return(null);
            }

            var results = Validate(model);

            if (results != null)
            {
                return(new OperationResult <UUIDModel>(results));
            }

            var endpoint = $"https://media.steepshot.org/api/v1/upload";

            return(await HttpClient.UploadMedia(endpoint, model, ct));
        }
        private async Task <OperationResult <MediaModel> > UploadPhoto()
        {
            Stream stream = null;

            try
            {
                stream = ImageAsset.AsJpegStream();
                var request = new UploadMediaModel(BasePresenter.User.UserInfo, stream, ImageExtension);
                return(await _presenter.TryUploadMedia(request));
            }
            catch (Exception ex)
            {
                AppSettings.Reporter.SendCrash(ex);
                return(new OperationResult <MediaModel>(new ApplicationError(Localization.Errors.PhotoProcessingError)));
            }
            finally
            {
                stream?.Flush();
                stream?.Dispose();
            }
        }
Ejemplo n.º 16
0
        private async Task <OperationResult <MediaModel> > UploadPhoto(Stream photoStream)
        {
            try
            {
                photoStream.Position = 0;
                var request      = new UploadMediaModel(BasePresenter.User.UserInfo, photoStream, Path.GetExtension(".jpg"));
                var serverResult = await Presenter.TryUploadMedia(request);

                return(serverResult);
            }
            catch (Exception ex)
            {
                AppSettings.Reporter.SendCrash(ex);
                return(new OperationResult <MediaModel>(new AppError(LocalizationKeys.PhotoProcessingError)));
            }
            finally
            {
                photoStream?.Close();
                photoStream?.Dispose();
            }
        }
Ejemplo n.º 17
0
        private void UploadTest(StringBuilder sb, int num)
        {
            sb.Append($"{num}) UploadTest : ");
            StepFinished?.Invoke(sb.ToString());

            var cat = "/9j/4AAQSkZJRgABAQEAwADAAAD/4QBqRXhpZgAATU0AKgAAAAgAAwESAAMAAAABAAEAAAExAAIAAAAQAAAAModpAAQAAAABAAAAQgAAAABTaG90d2VsbCAwLjIyLjAAAAKgAgAJAAAAAQAAAMKgAwAJAAAAAQAAAMIAAAAAAAD/4Qn0aHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/Pg0KPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNC40LjAtRXhpdjIiPg0KCTxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+DQoJCTxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOmV4aWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20vZXhpZi8xLjAvIiB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyIgZXhpZjpQaXhlbFhEaW1lbnNpb249IjE5NCIgZXhpZjpQaXhlbFlEaW1lbnNpb249IjE5NCIgdGlmZjpJbWFnZVdpZHRoPSIxOTQiIHRpZmY6SW1hZ2VIZWlnaHQ9IjE5NCIvPg0KCTwvcmRmOlJERj4NCjwveDp4bXBtZXRhPg0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDw/eHBhY2tldCBlbmQ9J3cnPz7/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCABkAGQDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg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9ndHO+IvGMLapITIvOT973NFVbe3+1vM7LDjzCq7kGcDA/mDRXtLY/PZZbK/xH2N4b8Vah4Svm1DTbuazvNPVpIpI26nHIYdGU9CpG0jgg19VeFtQh/aC0vw/rfiqws9SvtLhW/tWcPiF2TJX72SmYYyFYkDA7BQCivFwO6P1jjynF0otrW58sfC2/lT44eJizFv+J7qpXPGwNJDJgEYPDOxHcV9oz+INQ174U6Zrsl/fQ6lBDBIHhuXQM07XKSEjPUm0STjHzySk5DAAor9s4UX+y0X/ekfzHxk28VO/wDKjPn8UXk3w/1G6ZozdeHdYtL60mEYV983mCQMR94HyYzzzlRzXG/H6+k0X4q61Nb4jkh1F7lfZsiT8sk/hRRX6JR/ifI/Peh82fDm4fwx418SaPZsY7GS9NqV/iEcUssaqG6jjGcdcenFcLq8p1LxLqU0m3et0YeFAGxOAP1J+poor8l8QW+b7j9v8LIp42N10YuoW62y7oy6sp7MeaxZtRkvIoRIFLTLudgNrHAJA46j2NFFfj/VH9Lxej9Dn/EkjWhhYfMTMcbudowWx+YB5z0rjfEczWmlxrGcBpfOPfLBGI/UZ+uaKK9KmfH5xs/Q5C2untLC3VecoTz/ALxH9KKKK9OOx+ey+I//2Q==";

            byte[]       byteArray = Encoding.ASCII.GetBytes(cat);
            MemoryStream stream    = new MemoryStream(byteArray);

            var request = new UploadMediaModel(_user, stream, ".jpg")
            {
                GenerateThumbnail = false,
            };
            var mediaResponse = _api.UploadMedia(request, CancellationToken.None).Result;

            if (!mediaResponse.IsSuccess)
            {
                sb.AppendLine($"fail. Reason:{Environment.NewLine} {mediaResponse.Error.Message}");
                return;
            }

            var model = new PreparePostModel(_user, AppSettings.AppInfo.GetModel())
            {
                Tags  = new[] { "spam" },
                Title = "Upload test",
                Media = new[] { mediaResponse.Result },
            };

            var response = _api.CreateOrEditPost(model, CancellationToken.None).Result;

            if (!response.IsSuccess)
            {
                sb.AppendLine($"fail. Reason:{Environment.NewLine} {response.Error.Message}");
                return;
            }
            sb.AppendLine("pass.");
        }
 public abstract Task <OperationResult <string> > GetVerifyTransaction(UploadMediaModel model, CancellationToken ct);
Ejemplo n.º 19
0
        private async Task <OperationResult <MediaModel> > UploadPhoto(UIImage photo, NSDictionary metadata)
        {
            Stream stream = null;

            try
            {
                var compression    = 1f;
                var maxCompression = 0.1f;
                int maxFileSize    = _photoSize * 1024;

                var byteArray = photo.AsJPEG(compression);

                while (byteArray.Count() > maxFileSize && compression > maxCompression)
                {
                    compression -= 0.1f;
                    byteArray    = photo.AsJPEG(compression);
                }

                if (metadata != null)
                {
                    //exif setup
                    var editedExifData       = RemakeMetadata(metadata, photo);
                    var newImageDataWithExif = new NSMutableData();
                    var imageDestination     = CGImageDestination.Create(newImageDataWithExif, "public.jpeg", 0);
                    imageDestination.AddImage(new UIImage(byteArray).CGImage, editedExifData);
                    imageDestination.Close();
                    stream = newImageDataWithExif.AsStream();
                }
                else
                {
                    stream = byteArray.AsStream();
                }

                var request      = new UploadMediaModel(AppSettings.User.UserInfo, stream, ImageExtension);
                var serverResult = await _presenter.TryUploadMedia(request);

                if (!serverResult.IsSuccess)
                {
                    return(new OperationResult <MediaModel>(serverResult.Exception));
                }

                var uuidModel = serverResult.Result;
                var done      = false;
                do
                {
                    var state = await _presenter.TryGetMediaStatus(uuidModel);

                    if (state.IsSuccess)
                    {
                        switch (state.Result.Code)
                        {
                        case UploadMediaCode.Done:
                            done = true;
                            break;

                        case UploadMediaCode.FailedToProcess:
                        case UploadMediaCode.FailedToUpload:
                        case UploadMediaCode.FailedToSave:
                            return(new OperationResult <MediaModel>(new Exception(state.Result.Message)));

                        default:
                            await Task.Delay(3000);

                            break;
                        }
                    }
                } while (!done);

                return(await _presenter.TryGetMediaResult(uuidModel));
            }
            catch (Exception ex)
            {
                return(new OperationResult <MediaModel>(new InternalException(LocalizationKeys.PhotoProcessingError, ex)));
            }
            finally
            {
                stream?.Flush();
                stream?.Dispose();
            }
        }
Ejemplo n.º 20
0
 private async Task <OperationResult <MediaModel> > UploadMedia(UploadMediaModel model, CancellationToken ct)
 {
     return(await Api.UploadMedia(model, ct));
 }
Ejemplo n.º 21
0
        private async Task <OperationResult <MediaModel> > UploadPhoto(string url, CancellationToken token)
        {
            MemoryStream stream = null;
            WebClient    client = null;

            try
            {
                client = new WebClient();
                var bytes = client.DownloadData(new Uri(url));

                stream = new MemoryStream(bytes);
                var request      = new UploadMediaModel(User.UserInfo, stream, Path.GetExtension(MimeTypeHelper.Jpg));
                var serverResult = await Client.UploadMedia(request, token);

                if (!serverResult.IsSuccess)
                {
                    return(new OperationResult <MediaModel>(serverResult.Exception));
                }

                var uuidModel = serverResult.Result;
                var done      = false;
                do
                {
                    if (token.IsCancellationRequested)
                    {
                        return(new OperationResult <MediaModel>(new OperationCanceledException()));
                    }

                    var state = await Client.GetMediaStatus(uuidModel, token);

                    if (state.IsSuccess)
                    {
                        switch (state.Result.Code)
                        {
                        case UploadMediaCode.Done:
                            done = true;
                            break;

                        case UploadMediaCode.FailedToProcess:
                        case UploadMediaCode.FailedToUpload:
                        case UploadMediaCode.FailedToSave:
                            return(new OperationResult <MediaModel>(new Exception(state.Result.Message)));

                        default:
                            await Task.Delay(5000);

                            break;
                        }
                    }
                } while (!done);

                return(await Client.GetMediaResult(uuidModel, token));
            }
            catch (Exception ex)
            {
                return(new OperationResult <MediaModel>(new InternalException(LocalizationKeys.PhotoUploadError, ex)));
            }
            finally
            {
                stream?.Flush();
                client?.Dispose();
                stream?.Dispose();
            }
        }
Ejemplo n.º 22
0
 public async Task <OperationResult <MediaModel> > TryUploadMedia(UploadMediaModel model)
 {
     return(await TryRunTask <UploadMediaModel, MediaModel>(UploadMedia, OnDisposeCts.Token, model));
 }