Пример #1
0
        /// <summary>
        /// 画像をアップロードする
        /// </summary>
        /// <param name="tokenSuffix">アップロードするアカウント番号</param>
        /// <param name="filePaths">ファイルパス</param>
        /// <returns></returns>
        public async Task <bool> ImageUpload(int tokenSuffix, IReadOnlyCollection <string> filePaths)
        {
            if (this.IsUploaded)
            {
                this.Clear();
            }

            if (filePaths == null || filePaths.Count() == 0)
            {
                return(false);
            }

            if (filePaths.Count() > 4 - this.Source.Count)
            {
                CommonMethods.Notify("画像ファイルは4枚までです", NotificationType.Error);
                return(false);
            }

            foreach (var filePath in filePaths)
            {
                var media = await AccountTokens.ImageUploadAsync(tokenSuffix, filePath);

                if (media != null && media.Size != 0)
                {
                    if (this.Ids == null)
                    {
                        this.Ids = media.MediaId.ToString();
                    }
                    else
                    {
                        this.Ids += "," + media.MediaId.ToString();
                    }

                    this.IsEnabled = true;
                    CommonMethods.Notify("画像アップロード完了", NotificationType.Success);
                    this.Source.Add(new Uri(filePath));
                    this.Type = MediaType.Image;
                }
                else
                {
                    CommonMethods.Notify("画像アップロード失敗", NotificationType.Error);
                    return(false);
                }
            }

            this.IsUploaded = true;
            return(true);
        }