public MediaItemModel GetOne(string id) { // Parse the connection string and return a reference to the storage account. CloudStorageAccount storageAccount = CloudStorageAccount.Parse( _configuration.StorageConnectionString); // Get a reference to the container that we use for storage. CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(containerName); container.CreateIfNotExists(); CloudBlockBlob blockBlob = container.GetBlockBlobReference(id.ToString()); blockBlob.FetchAttributes(); MemoryStream blobContents = new MemoryStream(); blockBlob.DownloadToStream(blobContents); // Create the stored object which we will return. var storedMediaItem = new MediaItemModel(); storedMediaItem.Data = blobContents; storedMediaItem.Data.Seek(0, SeekOrigin.Begin); PopulateStoredMediaItemFromCloudBlockBlob(storedMediaItem, blockBlob); return(storedMediaItem); }
public void Play(MediaItemModel mediaItem) { if (!string.IsNullOrEmpty(mediaItem?.Entity?.Path)) { this.PlayerHost.SendMessage(PlayerMessage.OpenFileName, mediaItem.Entity.Path); } }
public async Task AddItemToGalleryAsync(string galleryId, MediaItemModel item) { var query = (from g in _docDbClient.CreateDocumentQuery <MediaGalleryContentDocument>( _config.SiteContentCollectionUrl) where g.Id == galleryId select g).AsDocumentQuery(); var galleryFeed = await query.ExecuteNextAsync <MediaGalleryContentDocument>().ConfigureAwait(false); var gallery = galleryFeed.FirstOrDefault(); //copy the list of items and insert the new item List <MediaItem> items = new List <MediaItem>(gallery.Items); var mappedNewItem = _map.Mapper.Map <MediaItem>(item); items.Add(mappedNewItem); //copy the list back to the array gallery.SetPropertyValue("items", items.ToArray()); try { var upsertResponse = await _docDbClient.UpsertDocumentAsync(_config.SiteContentCollectionUrl, gallery).ConfigureAwait(false); } catch (Exception ex) { throw new ApplicationException("Failed to update the gallery metadata", ex); } }
public static string GetVideoId(MediaItemModel item) { var url = new Uri(item.Location); var result = HttpUtility.ParseQueryString(url.Query) .Get("v"); return(result); }
private void PopulateStoredMediaItemFromCloudBlockBlob(MediaItemModel mediaItem, CloudBlockBlob blockBlob) { mediaItem.Id = blockBlob.Name; mediaItem.Name = blockBlob.Metadata["name"]; mediaItem.OrderItemNodeId = Convert.ToInt32(blockBlob.Metadata["orderItemNodeId"]); mediaItem.Url = _configuration.BaseUrl + "umbraco/surface/MediaItemSurface/GetMediaItem/" + mediaItem.Id; mediaItem.CreateDate = Convert.ToDateTime(blockBlob.Metadata["createDate"]); mediaItem.ContentType = blockBlob.Properties.ContentType; }
public Task AddItemToGalleryAsync(string galleryId, MediaItemModel item) { ContentModelBase gallery; if (_content.TryGetValue(galleryId, out gallery)) { ((MediaGalleryContent)gallery).Items.Add(item); } return(Task.FromResult(0)); }
public UrlParseResult(ILoggingService log, MediaItemModel item, ParseResultType type) : this(log, type) { MediaItems = new List <MediaItemModel>() { item }; Log(); }
public MediaItemModel GetOne(string id) { MediaItemModel res = null; var media = _mediaService.GetById(Convert.ToInt32(id)); if (media != null) { res = new MediaItemModel(); res.Id = media.Id.ToString(); res.Name = media.Name; res.CreateDate = media.CreateDate; res.OrderItemNodeId = media.GetValue <int>("orderItemNodeId"); res.Url = media.GetValue("file").ToString(); res.Data = new MemoryStream(System.IO.File.ReadAllBytes(HostingEnvironment.MapPath(media.GetValue("file").ToString()))); } return(res); }
public MediaItemModel CreateMediaItem(string name, int orderItemNodeId, string orderId, Stream data, string contentType) { MediaItemModel res = null; var mainFolder = _mediaService.GetChildren(-1).First(m => m.Name == ConfigurationManager.AppSettings["umbracoOrderItemAttachmentsMediaFolderName"]); using (Semaphore semLock = new Semaphore(0, 1)) { TypedEventHandler <IMediaService, SaveEventArgs <IMedia> > handler = (sender, e) => { semLock.Release(e.SavedEntities.Count()); }; try { MediaService.Saved += handler; if (String.IsNullOrEmpty(name)) { throw new Exception("Not a valid document."); } else { var media = _mediaService.CreateMedia(orderId + "-" + name, mainFolder, "OrderItemAttachment"); media.SetValue("file", name, data); media.SetValue("orderItemNodeId", orderItemNodeId); // Save the media and wait until it is finished so that we can retrieve the link to the item. _mediaService.Save(media); semLock.WaitOne(); res = new MediaItemModel(); res.CreateDate = media.CreateDate; res.Id = media.Id.ToString(); res.Name = name; res.OrderItemNodeId = orderItemNodeId; res.Url = media.GetValue("file").ToString(); res.Data = data; } } finally { MediaService.Saved -= handler; } } return(res); }
public MediaItemModel CreateMediaItem(string name, int orderItemNodeId, string orderId, Stream data, string contentType) { // Generate a UUID which we will use as identifier for the stored object. var id = Guid.NewGuid(); // Parse the connection string and return a reference to the storage account. CloudStorageAccount storageAccount = CloudStorageAccount.Parse( _configuration.StorageConnectionString); // Get a reference to the container that we use for storage. CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(containerName); container.CreateIfNotExists(); CloudBlockBlob blockBlob = container.GetBlockBlobReference(id.ToString()); // Store the object. data.Position = 0; blockBlob.UploadFromStream(data); // Store the metadata. var createDate = DateTime.Now; blockBlob.FetchAttributes(); blockBlob.Metadata["name"] = Uri.EscapeUriString(name); blockBlob.Metadata["orderItemNodeId"] = orderItemNodeId.ToString(); blockBlob.Metadata["createDate"] = createDate.ToString("o"); blockBlob.SetMetadata(); blockBlob.Properties.ContentType = contentType; blockBlob.SetProperties(); // Create the stored object which we will return. var storedMediaItem = new MediaItemModel(); PopulateStoredMediaItemFromCloudBlockBlob(storedMediaItem, blockBlob); return(storedMediaItem); }
public MediaItem Get(MediaItemModel mediaitem) { return(new MediaItem(mediaitem, _validator, _messenger)); }
private MediaItem CreateMediaItem(MediaItemModel model, IContainer container) { var mapper = container.Resolve <IMediaItemMapper>(); return(mapper.Get(model)); }
public void SystemCommandExecuteAction(SystemCommand key, UICommandParameter <SystemCommand> param) { switch (key) { case SystemCommand.OpenMenu: break; case SystemCommand.Minimized: break; case SystemCommand.Normal: break; case SystemCommand.Maximized: break; case SystemCommand.Close: break; case SystemCommand.FullScreen: break; case SystemCommand.FullScreenCancel: break; case SystemCommand.MediaCenter: break; case SystemCommand.Player: break; case SystemCommand.Recommend: break; case SystemCommand.Collection: break; case SystemCommand.SpecialTopic: break; case SystemCommand.VideoLibrary: break; case SystemCommand.ShowItemDetail: break; case SystemCommand.ItemPlay: { MediaItemModel mediaItem = param.Parameter as MediaItemModel; if (mediaItem != null && mediaItem.Entity != null) { switch ((FileType)mediaItem.Entity.ItemType) { case FileType.Audio: case FileType.Video: MusicBar.Instance.Play(mediaItem); break; default: MusicBar.Instance.Stop(); break; } } } break; case SystemCommand.Last: break; } }
public static MediaItem CreateMediaItem(this IContainer container, MediaItemModel model) { var mapper = container.Resolve <IMediaItemMapper>(); return(mapper.Get(model)); }
public async Task <IActionResult> AddItem([FromHeader] string authorization, [FromBody] QuickBaseQuestionAnswerItem item) { try { var tokenModel = TokenConvert.DeserializeEncryptedToken <WebhookTokenModel>(authorization, _config.GetValue <string>("EncodingKey") ?? "whoops"); var authApi = new AuthenticationApi("https://cms.voicify.com"); // sign in with api user creds to get token var tokenResponse = await authApi.AuthenticateAsync(tokenModel.VoicifyOrganizationId, tokenModel.VoicifyOrganizationSecret, "password", tokenModel.VoicifyApiUserName, tokenModel.VoicifyApiUserSecret); var voicifyConfig = new Configuration { BasePath = "https://cms.voicify.com", DefaultHeader = new Dictionary <string, string> { { "Authorization", $"Bearer {tokenResponse.AccessToken}" } } }; var featureApi = new FeatureApi(voicifyConfig); var questionAnswerApi = new QuestionAnswerApi(voicifyConfig); var mediaItemApi = new MediaItemApi(voicifyConfig); MediaItemModel mediaItem = null; if (!string.IsNullOrEmpty(item?.ForegroundImageUrl) && Uri.TryCreate(item.ForegroundImageUrl, UriKind.Absolute, out var imageUri)) { // TODO: once voicify allows external urls through this api, send it up //mediaItem = await mediaItemApi.CreateMediaItem_0Async(tokenModel.VoicifyApplicationId, new NewMediaItemRequest(item.ForegroundImageUrl, item.ForegroundImageUrl, item.ForegroundImageUrl, "")); } // get root feature of app var features = await featureApi.GetFeaturesForApplicationAsync(tokenModel.VoicifyApplicationId); var rootFeature = features.FirstOrDefault(af => string.IsNullOrEmpty(af.ParentId)); // add question answer to root feature var faq = await questionAnswerApi.CreateFullContentItemAsync(new QuestionAnswerModel( applicationFeatureId : rootFeature.Id, applicationId : rootFeature.ApplicationId, isLive : true, title : item.Question, questionSet : new List <QuestionModel> { new QuestionModel(content : item.Question) }, responses : new List <AnswerModel> { new AnswerModel( content : item.Answer, largeImage : mediaItem, followUp : string.IsNullOrEmpty(item.FollowUpPrompt) ? null : new FollowUpModel(applicationId : tokenModel.VoicifyApplicationId, content : item.FollowUpPrompt)) })); } catch (Exception ex) { Console.WriteLine(ex); } return(Ok()); }