public async Task <bool> AddNewFileAsync(AvContent avContent, StorageToken storageToken)
        {
            try
            {
                var sasUri = new Uri(storageToken.SasUri);

                var blockBlob = new CloudBlockBlob(sasUri);

                blockBlob.Metadata [StorageToken.ContentIdParam] = avContent.Id;

                blockBlob.Metadata ["displayName"] = avContent.Name.SplitOnLast('.').FirstOrDefault() ?? avContent.Name;

                await blockBlob.UploadFromFileAsync(avContent.LocalInboxPath);

                Log.Debug($"Finished uploading new file.");

                return(true);
            }
            catch (Exception ex)
            {
                Log.Debug($"{ex.Message}");

                return(false);
            }
        }
Пример #2
0
        public async Task <bool> AddNewFileAsync(AvContent avContent, StorageToken storageToken)
        {
            try
            {
                Log.Debug(storageToken?.ToString());

                var sasUri = new Uri(storageToken.SasUri);

                var blockBlob = new CloudBlockBlob(sasUri);

                blockBlob.Metadata [DocumentUpdatedMessage.DocumentIdKey] = avContent.Id;

                blockBlob.Metadata [DocumentUpdatedMessage.CollectionIdKey] = typeof(AvContent).Name;

                NetworkIndicator.ToggleVisibility(true);

                await blockBlob.UploadFromFileAsync(avContent.LocalInboxPath);

                Log.Debug($"Finished uploading new file.");

                return(true);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(false);
            }
            finally
            {
                NetworkIndicator.ToggleVisibility(false);
            }
        }
Пример #3
0
        public static void Run(
            [QueueTrigger(MessageQueues.AvContent)] ContentEncodedMessage contentMessage,
            [DocumentDB(nameof(Content), nameof(AvContent), Id = "{documentId}")] AvContent avContent,
            [Queue(MessageQueues.DocumentUpdate)] out DocumentUpdatedMessage updatedMessage, TraceWriter log)
        {
            try
            {
                log.Info(contentMessage.ToString());

                FunctionExtensions.HasValueOrThrow(avContent?.Id, "avContent", $"Unable to find record with Id: {contentMessage?.DocumentId}");

                FunctionExtensions.HasValueOrThrow(contentMessage?.RemoteAssetUri, "RemoteAssetUri");

                avContent.RemoteAssetUri = contentMessage.RemoteAssetUri;

                updatedMessage = new DocumentUpdatedMessage(contentMessage.DocumentId, contentMessage.CollectionId, contentMessage.NotificationTags)
                {
                    Title   = $"New {avContent.ContentType}!",
                    Message = avContent.DisplayName
                };
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                throw;
            }
        }
Пример #4
0
        public async Task DeleteAvContent(AvContent item)
        {
            if (AvContent [item.PublishedTo].Remove(item))
            {
                AvContentChanged?.Invoke(this, item.PublishedTo);
            }

            var deletedItem = await Delete(item);
        }
Пример #5
0
        public void SetData(AvContent content)
        {
            initializedVeiw = false;

            avContent = content;

            //filePath = url;

            //utiData = filePath.GetAvUtiConformance ();
        }
Пример #6
0
        public async Task <AvContent> CreateAvContent(AvContent item)
        {
            var newItem = await Create(item);

            AvContent [newItem.PublishedTo].Insert(0, newItem);

            AvContentChanged?.Invoke(this, newItem.PublishedTo);

            return(newItem);
        }
        /// Returns an Asset pointing to a file on disk if it exists.
        public MusicAsset LocalMusicAsset(AvContent music)
        {
            var localPath = localFilePath(music.Id);

            if (localPath != null)
            {
                return(new MusicAsset(music, new AVUrlAsset(localPath)));
            }

            return(null);
        }
Пример #8
0
        /// Returns an Asset pointing to a file on disk if it exists.
        public MusicAsset LocalMusicAsset(AvContent music)
        {
            //var localPath = localFilePath (music.Id);

            //if (localPath != null)
            //{
            //	return new MusicAsset (music, new AVUrlAsset (localPath));
            //}

            return(null);
        }
Пример #9
0
        public override void ViewDidDisappear(bool animated)
        {
            utiData          = null;
            filePath         = null;
            avContent        = null;
            initializedVeiw  = false;
            isValidMediaItem = false;

            // TODO: make sure this isn't called whien displaying a dialog

            base.ViewDidDisappear(animated);
        }
Пример #10
0
        /// Returns an Asset given a specific name if that Asset is asasociated with an active download.
        public MusicAsset ActiveMusicAsset(AvContent music)
        {
            //foreach (var item in activeDownloadsMap)
            //{
            //	if (item.Value.Id == music.Id)
            //	{
            //		return item.Value;
            //	}
            //}

            return(null);
        }
        /// Returns an Asset given a specific name if that Asset is asasociated with an active download.
        public MusicAsset ActiveMusicAsset(AvContent music)
        {
            foreach (var item in activeDownloadsMap)
            {
                if (item.Value.Id == music.Id)
                {
                    return(item.Value);
                }
            }

            return(null);
        }
Пример #12
0
        public async Task UpdateItemAsync(AvContent avContent, bool waitOnSync = false)
        {
            if (waitOnSync)
            {
                await azureClient.SaveRemoteAsync(avContent);
            }
            else
            {
                await azureClient.SaveAsync(avContent);
            }

            await refreshAvContentAsync();
        }
Пример #13
0
        [HttpGet]         // GET api/GetStorageToken
        public async Task <StorageToken> GetAsync()
        {
            AvContent avContent = null;

            var contentId = getContentIdParamater(Request);

            using (DbContextTransaction transaction = context.Database.BeginTransaction())
            {
                try
                {
                    avContent = await context.AvContents.FindAsync(contentId);
                }
                catch (Exception)
                {
                    transaction.Rollback();

                    avContent = null;
                }
            }


            if (avContent == null)
            {
                throw new HttpResponseException(Request.CreateBadRequestResponse("No item in database matching the contentId paramater {0}", contentId));
            }


            // Errors creating the storage container result in a 500 Internal Server Error
            var container = BlobClient.GetContainerReference(containerName);

            await container.CreateIfNotExistsAsync();


            // TODO: Check if there's already a blob with a name matching the Id


            var sasUri = getBlobSasUri(container, avContent.Name);

            return(new StorageToken
            {
                ContentId = avContent.Id,
                SasUri = sasUri
            });
        }
Пример #14
0
        public void SetData(AvContent music)
        {
            TextLabel.Text       = music.DisplayName;
            DetailTextLabel.Text = music.Description;

            switch (music.ContentType)
            {
            case AvContentTypes.Audio:
                ImageView.Image = UIImage.FromBundle("i_content_audio");
                break;

            case AvContentTypes.Video:
                ImageView.Image = UIImage.FromBundle("i_content_video");
                break;

            case AvContentTypes.Unknown:
                ImageView.Image = null;
                break;
            }
        }
Пример #15
0
        static void avContentEvent(string eventName, AvContent content, bool includeDownloaded = true)
        {
            if (content != null)
            {
                var props = new Dictionary <string, string>
                {
                    { "Name", content.Name },
                    { "Display Name", content.DisplayName },
                    { "Media Type", content.ContentType.ToString() },
                    { "Published To", content.PublishedTo.ToString() }
                };

                if (includeDownloaded)
                {
                    props.Add("Downloaded", content.HasLocalAssetUri ? "True" : "False");
                }

                Event(eventName, props);
            }
        }
Пример #16
0
        public async Task <StorageToken> SaveNewItemAsync(AvContent avContent)
        {
            await AzureClient.Shared.SaveRemoteAsync(avContent);

            if (avContent?.HasId ?? false)
            {
                //AvContent [UserRoles.Producer].Add (avContent);

                await refreshAvContentAsync();

                var paramDictionary = new Dictionary <string, string> {
                    { StorageToken.ContentIdParam, avContent.Id }
                };

                var storageToken = await azureClient.MobileServiceClient.InvokeApiAsync <StorageToken> (StorageToken.RequestApiName, HttpMethod.Get, paramDictionary);

                return(storageToken);
            }

            return(null);
        }
Пример #17
0
        async Task PublishUpdate(AvContent newItem, UserRoles?oldRole = null)
        {
            if (oldRole.HasValue)
            {
                if (oldRole.Value < newItem.PublishedTo)
                {
                    // moved to more restricted send silent notificaiton to remove from list
                    await ProducerClient.Shared.Publish(newItem, oldRole);
                }
                else if (oldRole.Value > newItem.PublishedTo && newItem.PublishedTo < UserRoles.Producer)                 // published to more users
                {
                    var groupName = newItem.PublishedTo != UserRoles.General ? $" ({newItem.PublishedTo})" : string.Empty;

                    await ProducerClient.Shared.Publish(newItem, newItem.DisplayName, $"New {newItem.ContentType}!{groupName}");
                }
            }
            else             // not adding to or removing from any group, silently update
            {
                await ProducerClient.Shared.Publish(newItem);
            }
        }
Пример #18
0
        public async Task UpdateAvContent(AvContent item, UserRoles?oldRole = null, bool publish = true)
        {
            if (oldRole.HasValue && AvContent [oldRole.Value].Remove(item))
            {
                // specify old role if role is what changed
                AvContentChanged?.Invoke(this, oldRole.Value);
            }
            else if (AvContent [item.PublishedTo].Remove(item))
            {
                AvContentChanged?.Invoke(this, item.PublishedTo);
            }

            var newItem = await Replace(item);

            AvContent [newItem.PublishedTo].Add(newItem);

            AvContentChanged?.Invoke(this, newItem.PublishedTo);

            if (publish)
            {
                await PublishUpdate(newItem, oldRole);
            }
        }
Пример #19
0
        internal async Task RetrieveApiList()
        {
            if (Camera != null)
            {
                // DSC-QX10 firmware v3.00 has a bug in the response of getMethodTypes
                var methods = (await Camera.GetMethodTypesAsync().ConfigureAwait(false))
                              .Where(method => !(method.Name == "setFocusMode" && ProductType == ProductType.DSC_QX10)).ToList();
                Capability.AddSupported(methods);
            }
            if (System != null)
            {
                Capability.AddSupported(await System.GetMethodTypesAsync().ConfigureAwait(false));
            }
            if (AvContent != null)
            {
                Capability.AddSupported(await AvContent.GetMethodTypesAsync().ConfigureAwait(false));
            }

            if (SupportedApisUpdated != null)
            {
                SupportedApisUpdated.Invoke(this, new SupportedApiEventArgs(Capability.SupportedApis));
            }
        }
Пример #20
0
 public static void Download(AvContent content) => avContentEvent("Downloads", content, false);
Пример #21
0
        partial void createButtonClicked(NSObject sender)
        {
            createButton.Enabled             = false;
            fileNameTextField.Enabled        = false;
            fileDisplayNameTextField.Enabled = false;
            descriptionTextField.Enabled     = false;


            if (avContent != null)             // editing existing item
            {
                if (updateAvContentItem())
                {
                    //Settings.LastAvContentDescription = avContent.Description ?? string.Empty;

                    Task.Run(async() =>
                    {
                        await ProducerClient.Shared.UpdateItemAsync(avContent);

                        BeginInvokeOnMainThread(() => NavigationController.PopViewController(true));
                    });
                }
            }
            else             // creating new draft
            {
                avContent = new AvContent
                {
                    Name        = fileNameTextField.Text,
                    DisplayName = fileDisplayNameTextField.Text,
                    Description = descriptionTextField.Text,
                    ProducerId  = "admin",                    // TODO: fix this
                    ContentType = utiData.Item1 == UTType.Audio ? AvContentTypes.Audio : utiData.Item1 == UTType.Movie ? AvContentTypes.Video : AvContentTypes.Unknown
                };

                UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;


                Task.Run(async() =>
                {
                    var storageToken = await ProducerClient.Shared.SaveNewItemAsync(avContent);

                    if (storageToken != null)
                    {
                        // store the inbox path incase upload fails, is interrupted, app
                        // crashes, etc. and we need to reinitialize the upload later
                        avContent.LocalInboxPath = filePath.Path;

                        var success = await AzureStorageClient.Shared.AddNewFileAsync(avContent, storageToken);

                        BeginInvokeOnMainThread(() =>
                        {
                            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;

                            if (success)
                            {
                                Settings.LastAvContentDescription = avContent.Description ?? string.Empty;

                                NavigationController.PopViewController(true);

                                // TODO: Remove this file once we get a successful streaming url
                                //NSError error;

                                //NSFileManager.DefaultManager.Remove (filePath.Path, out error);

                                //if (error != null)
                                //{
                                //	System.Diagnostics.Debug.WriteLine ($"{error}");
                                //	System.Diagnostics.Debug.WriteLine ($"Error trying to get resource attributes\n\t{error.Code}\n\t{error.Domain}\n\t{error.Description}");
                                //}
                            }
                            else
                            {
                                // TODO: show failed/retry alert
                            }

                            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
                        });
                    }
                    else
                    {
                        BeginInvokeOnMainThread(() => { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; });
                    }
                });
            }
        }
Пример #22
0
 /// Returns the Active, Local, or a new Asset
 public MusicAsset GetMusicAsset(AvContent music) => ActiveMusicAsset(music) ?? LocalMusicAsset(music) ?? new MusicAsset(music, new AVUrlAsset(new NSUrl(music.RemoteAssetUri)));
Пример #23
0
 public static void Favorite(AvContent content) => avContentEvent("Favorites", content);
        public void SetData(AvContent music, MusicAssetDownloadState downloadState)
        {
            TextLabel.Text       = music.DisplayName;
            DetailTextLabel.Text = music.Description;

            switch (music.ContentType)
            {
            case AvContentTypes.Audio:
                ImageView.Image = UIImage.FromBundle("i_content_audio");
                break;

            case AvContentTypes.Video:
                ImageView.Image = UIImage.FromBundle("i_content_video");
                break;

            case AvContentTypes.Unknown:
                ImageView.Image = null;
                break;
            }

            switch (downloadState)
            {
            case MusicAssetDownloadState.Downloaded:

                //DetailTextLabel.Text = null; //music.DurationString;

                accessoryProgressView.Hidden = true;

                accessoryButton.Hidden = true;

                AccessoryView = null;

                break;

            case MusicAssetDownloadState.Downloading:

                //DetailTextLabel.Text = null;

                accessoryButton.Hidden = true;

                AccessoryView = accessoryProgressView;

                accessoryProgressView.Hidden = false;

                accessoryProgressView.StartIndeterminate();

                break;

            case MusicAssetDownloadState.NotDownloaded:

                //DetailTextLabel.Text = null;

                accessoryProgressView.Hidden = true;

                var audio = music.ContentType == AvContentTypes.Audio;

                AccessoryView = audio ? accessoryButton : null;

                accessoryButton.Hidden = !audio;

                // Set the tag to use during click event
                accessoryButton.Tag = Tag;

                break;
            }

            isPlaying = false;

            if (playingTag == Tag)
            {
                SetPlaying(true);
            }
        }
Пример #25
0
 /// <summary>
 /// Returns the Active, Local, or a new Asset
 /// </summary>
 /// <returns>The music asset.</returns>
 /// <param name="music">Music.</param>
 public MusicAsset GetMusicAsset(AvContent music) => ActiveMusicAsset(music) ?? LocalMusicAsset(music) ?? new MusicAsset(music, music.RemoteAssetUri);
Пример #26
0
 public MusicAsset(AvContent music, AVUrlAsset urlAsset)
 {
     Music    = music;
     UrlAsset = urlAsset;
 }
 /// Returns the Active, Local, or a new Asset
 public MusicAsset GetMusicAsset(AvContent music) => ActiveMusicAsset(music) ?? LocalMusicAsset(music) ?? new MusicAsset(music, new AVUrlAsset(new NSUrl(music.StorageUrl)));
Пример #28
0
 public MusicAssetDownloadProgressChangeArgs(AvContent music, double progress)
 {
     Music    = music;
     Progress = progress;
 }
Пример #29
0
 public MusicAssetDownloadStateChangeArgs(AvContent music, MusicAssetDownloadState state)
 {
     Music = music;
     State = state;
 }
Пример #30
0
 public MusicAssetDownloadStateChangeArgs(AvContent music)
 {
     Music = music;
 }