Exemple #1
0
        /// <summary>
        /// Returns a <see cref="MetaMediaObject"/> given the XElement that contains the data.
        /// </summary>
        private MetaMediaObject ParseMetaMediaObject(XElement ele)
        {
            var memberList = ele.Element("value").Element("struct").Elements("member");

            var name = memberList.SingleOrDefault(m => m.Element("name").Value == "name");
            var type = memberList.SingleOrDefault(m => m.Element("name").Value == "type");
            var bits = memberList.SingleOrDefault(m => m.Element("name").Value == "bits");

            var mediaObj = new MetaMediaObject
            {
                Name = name?.Element("value").Value,
                Type = type?.Element("value").Value,
                Bits = Convert.FromBase64String(bits == null ? string.Empty : bits.Element("value").Value)
            };

            _logger.LogDebug("ParseMetaMediaObject {@MetaMediaObject}", mediaObj);
            return(mediaObj);
        }
        public async Task <MetaMediaInfo> NewMediaObjectAsync(string blogId, string userName, string password, MetaMediaObject mediaObject, HttpContext request)
        {
            var user = await ValidUserAsync(userName, password);

            try
            {
                var userId = user.Id;
                var media  = await _blogSvc.UploadImageAsync(new MemoryStream(mediaObject.Bits),
                                                             userId, mediaObject.Name, mediaObject.Type, EUploadedFrom.MetaWeblog);

                return(new MetaMediaInfo()
                {
                    Url = _blogSvc.GetImageUrl(media, EImageSize.Original)
                });
            }
            catch (Exception ex)
            {
                throw new MetaWeblogException(EMetaWeblogCode.NewMediaObject, ex.Message);
            }
        }