private void mnuFileOpen_Click(object sender, EventArgs e)
        {
            string path     = null;
            string password = null;

            if (AlbumController.OpenAlbumDialog(ref path, ref password))
            {
                if (!SaveAndCloseAlbum())
                {
                    return;
                }

                try
                {
                    // Open the new album
                    Manager = new AlbumManager(path, password);
                }
                catch (AlbumStorageException aex)
                {
                    string msg = String.Format("Unable to open album file {0}\n({1})",
                                               path, aex.Message);
                    MessageBox.Show(msg, "Unable to Open");
                    Manager = new AlbumManager();
                }
                DisplayAlbum();
            }
        }
Exemplo n.º 2
0
        protected void AlbumList_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow row     = AlbumList.Rows[AlbumList.SelectedIndex];
            string      albumID = (row.FindControl("AlbumID") as Label).Text;

            MessageUserControl.TryRun(
                () =>
            {
                AlbumController controller = new AlbumController();
                Album album = controller.GetAlbum(int.Parse(albumID));
                if (album == null)
                {
                    ClearControls();
                    throw new Exception("Record no longer exists on file.");
                }
                else
                {
                    EditAlbumID.Text = album.AlbumId.ToString();
                    EditTitle.Text   = album.Title;
                    EditAlbumArtistList.SelectedValue = album.ArtistId.ToString();
                    EditReleaseYear.Text  = album.ReleaseYear.ToString();
                    EditReleaseLabel.Text = album.ReleaseLabel ?? "";
                    //EditReleaseLabel.Text = album.ReleaseLabel == null ? "" : album.ReleaseLabel;
                }
            }, "Find Album", "Album found"    //success messages
                );
        }
Exemplo n.º 3
0
        protected void Remove_Click(object sender, EventArgs e)
        {
            string editID  = EditAlbumID.Text;
            int    albumID = 0;

            if (string.IsNullOrEmpty(editID))
            {
                MessageUserControl.ShowInfo("Error", "Must have album to edit.");
            }
            else if (!int.TryParse(editID, out albumID))
            {
                MessageUserControl.ShowInfo("Error", "Invalid album ID");
            }
            else
            {
                MessageUserControl.TryRun(() =>
                {
                    AlbumController controller = new AlbumController();
                    int rows = controller.Album_Delete(albumID);

                    if (rows > 0)
                    {
                        AlbumList.DataBind();
                        EditAlbumID.Text = "";
                    }
                    else
                    {
                        throw new Exception("No album found. Try again.");
                    }
                }, "Sucessful!", "Album deleted.");
            }
        }
Exemplo n.º 4
0
        private void DeleteUserAlbum()
        {
            if (String.IsNullOrEmpty(this.txtNewUserUserName.Text))
            {
                return;
            }

            if (GallerySettings.EnableUserAlbum)
            {
                IAlbum album = null;

                try
                {
                    IUserGalleryProfile profile = ProfileController.GetProfileForGallery(this.txtNewUserUserName.Text.Trim(), GalleryId);

                    if (profile != null)
                    {
                        album = AlbumController.LoadAlbumInstance(profile.UserAlbumId, false);
                    }
                }
                catch (InvalidAlbumException)
                {
                    return;
                }

                if (album != null)
                {
                    AlbumController.DeleteAlbum(album);
                }
            }
        }
        public AlbumControllerTests()
        {
            mapper      = CreateMapperProfile();
            mockService = new Mock <IAlbumService>();

            controller = new AlbumController(mapper, mockService.Object);
            AddIdentity(controller, userId);
        }
 public AlbumsController(AlbumController albumController, GalleryObjectController galleryObjectController, UserController userController, ExceptionController exController, IAuthorizationService authorizationService)
 {
     _albumController         = albumController;
     _galleryObjectController = galleryObjectController;
     _userController          = userController;
     _exController            = exController;
     _authorizationService    = authorizationService;
 }
Exemplo n.º 7
0
 private void Start()
 {
     _instance = this;
     ShowList();
     //if (Settings.playerLevel < 2)
     //{
     //    Settings.playerLevel++;
     //}
 }
Exemplo n.º 8
0
    public void Set(UnitAlbumPanel parentPanel, AlbumController.EAlbumType albumType)
    {
        _parentPanel = parentPanel;
        _type        = albumType;

        Text.text = AlbumController.GetAlbumTypeName(_type);

        onEnable();
    }
        public void Can_Create_Album()
        {
            var movieRepo = new AlbumRepository(null);
            var underTest = new AlbumController(movieRepo);

            var result = underTest.Create();

            Assert.IsType <ViewResult>(result);
        }
Exemplo n.º 10
0
        private bool btnOkClicked()
        {
            // User clicked 'Delete selected objects'.
            string[] selectedItems = RetrieveUserSelections();

            if (selectedItems.Length == 0)
            {
                // No objects were selected. Inform user and exit function.
                ucUserMessage.MessageTitle  = Resources.GalleryServerPro.Task_No_Objects_Selected_Hdr;
                ucUserMessage.MessageDetail = Resources.GalleryServerPro.Task_No_Objects_Selected_Dtl;
                ucUserMessage.Visible       = true;

                return(false);
            }

            if (!ValidateBeforeObjectDeletion(selectedItems))
            {
                return(false);
            }

            try
            {
                HelperFunctions.BeginTransaction();

                // Convert the string array of IDs to integers. Also assign whether each is an album or media object.
                // (Determined by the first character of each id's string: a=album; m=media object)
                foreach (string selectedItem in selectedItems)
                {
                    int  id     = Convert.ToInt32(selectedItem.Substring(1), CultureInfo.InvariantCulture);
                    char idType = Convert.ToChar(selectedItem.Substring(0, 1), CultureInfo.InvariantCulture);                     // 'a' or 'm'

                    if (idType == 'm')
                    {
                        IGalleryObject go = Factory.LoadMediaObjectInstance(id);
                        go.Delete();
                    }

                    if (idType == 'a')
                    {
                        IAlbum go = Factory.LoadAlbumInstance(id, false);
                        AlbumController.DeleteAlbum(go);
                    }
                }

                HelperFunctions.CommitTransaction();
            }
            catch
            {
                HelperFunctions.RollbackTransaction();
                throw;
            }

            HelperFunctions.PurgeCache();

            return(true);
        }
Exemplo n.º 11
0
        private void ShowTreeview()
        {
            rptr.Visible = false;

            tvUC.Visible = true;

            // Find out if the objects we are transferring consist of only media objects, only albums, or both.
            // We use this knowledge to set the RequiredSecurityPermission property on the treeview user control
            // so that only albums where the user has permission are available for selection.
            bool            hasAlbums       = false;
            bool            hasMediaObjects = false;
            SecurityActions securityActions = 0;

            foreach (string id in (string[])ViewState["ids"])
            {
                if (id.StartsWith("a", StringComparison.Ordinal))
                {
                    securityActions = (((int)securityActions == 0) ? SecurityActions.AddChildAlbum : securityActions | SecurityActions.AddChildAlbum);
                    hasAlbums       = true;
                }
                if (id.StartsWith("m", StringComparison.Ordinal))
                {
                    securityActions = (((int)securityActions == 0) ? SecurityActions.AddMediaObject : securityActions | SecurityActions.AddMediaObject);
                    hasMediaObjects = true;
                }
                if (hasAlbums && hasMediaObjects)
                {
                    break;
                }
            }

            tvUC.RequiredSecurityPermissions = securityActions;

            if (UserCanAdministerSite || UserCanAdministerGallery)
            {
                // Show all galleries the current user can administer. This allows them to move/copy objects between galleries.
                tvUC.RootAlbumPrefix = String.Concat(Resources.GalleryServerPro.Site_Gallery_Text, " '{GalleryDescription}': ");
                tvUC.Galleries       = UserController.GetGalleriesCurrentUserCanAdminister();
            }

            IAlbum albumToSelect = this.GetAlbum();

            if (!IsUserAuthorized(SecurityActions.AddChildAlbum, albumToSelect))
            {
                albumToSelect = AlbumController.GetHighestLevelAlbumWithAddPermission(hasAlbums, hasMediaObjects, GalleryId);
            }

            if (albumToSelect == null)
            {
                tvUC.BindTreeView();
            }
            else
            {
                tvUC.BindTreeView(albumToSelect);
            }
        }
Exemplo n.º 12
0
        public void Get_ShouldReturnOkResult()
        {
            _albumService = new Mock <IAlbumService>();
            _albumService.Setup(a => a.Albums).Returns(_albums);
            var controller = new AlbumController(_albumService.Object, _mapper, _userManager.Object);

            var result = controller.Get().Result;

            Assert.IsInstanceOf <OkObjectResult>(result);
        }
Exemplo n.º 13
0
        protected void Delete_Click(object sender, EventArgs e)
        {
            LinkButton      btn     = (LinkButton)sender;
            int             AlbumID = int.Parse(btn.CommandArgument);
            AlbumController dc      = new AlbumController();

            dc.DeleteAlbum(AlbumID);
            rptAlbums.DataSource = dc.GetAlbums();
            rptAlbums.DataBind();
        }
Exemplo n.º 14
0
        public void AlbumExists()
        {
            AlbumController ctrl   = new AlbumController(new MockSixteenBarsDb());
            var             result = ctrl.AlbumExists(" Because the internet", "childish Gambino ");

            Assert.AreEqual(true, result, "Because the Internet from Childish Gambino should exists.");

            result = ctrl.AlbumExists(" Because the internet", "Jay-z ");
            Assert.AreEqual(false, result, "Because the Internet from Jay-Z should not exists.");
        }
Exemplo n.º 15
0
    //
    public void Set(int albumId)
    {
        if (false == AlbumController.IsValid(albumId))
        {
            Log.Error(string.Format("invalid album id; {0}", albumId));
            return;
        }

        AlbumId = albumId;
    }
Exemplo n.º 16
0
        /// <summary>
        /// Starts a synchronization on a background thread for the album specified in <paramref name="syncOptions" />.
        /// </summary>
        /// <param name="syncOptions">The synchronization options.</param>
        /// <param name="password">The password that allows remote access to the synchronization API.</param>
        private static void StartRemoteSync(SyncOptions syncOptions, string password)
        {
            IAlbum album = AlbumController.LoadAlbumInstance(syncOptions.AlbumIdToSynchronize);

            if (!ValidateRemoteSync(album, password))
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
            }

            Task.Factory.StartNew(() => GalleryController.BeginSync(syncOptions), TaskCreationOptions.LongRunning);
        }
Exemplo n.º 17
0
        public void TestAddPhotoGet_Should_RedirectToPhotoController()
        {
            var albumController = new AlbumController(null, null, null);

            var result = albumController.AddPhoto(1) as RedirectToRouteResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(result.RouteValues["action"], "Create");
            Assert.AreEqual(result.RouteValues["controller"], "Photo");
            Assert.AreEqual(result.RouteValues["albumId"], 1);
        }
Exemplo n.º 18
0
        private void SaveAsAlbum()
        {
            string path = null;

            if (AlbumController.SaveAlbumDialog(ref path))
            {
                SaveAlbum(path);
                // Update title bar to include new name
                SetTitleBar();
            }
        }
Exemplo n.º 19
0
        public void GetById_IfNull_ShouldReturnNotFoundResult()
        {
            int id = 1;

            _albumService = new Mock <IAlbumService>();
            var controller = new AlbumController(_albumService.Object, _mapper, _userManager.Object);

            var result = controller.GetById(id);

            Assert.IsInstanceOf <NotFoundResult>(result.Result);
        }
Exemplo n.º 20
0
        public void TestAlbumDeleteItem()
        {
            //Arrange
            var SqlLiteDataMock = new Mock <IMusicData>();
            var AlbumController = new AlbumController(SqlLiteDataMock.Object);

            //Act
            ActionResult actionResult = AlbumController.AlbumDeleteItem(-1);

            // Assert
            Assert.IsType <NotFoundObjectResult>(actionResult);
        }
Exemplo n.º 21
0
        public void PutAsyncTest()
        {
            using (var dataAccess = Substitute.For <IDataAccess>())
            {
                dataAccess.ExecuteSqlWithParametersAsync(Arg.Any <string>(), Arg.Any <List <SQLiteParameter> >()).Returns(1);

                using (var albumController = new AlbumController(dataAccess))
                {
                    albumController.PutAsync(0, new Album(0, 1, 2, "name", 1999)).Wait();
                }
            }
        }
Exemplo n.º 22
0
        public void PutAsyncExceptionTest()
        {
            using (var dataAccess = Substitute.For <IDataAccess>())
            {
                dataAccess.ExecuteSqlWithParametersAsync(Arg.Any <string>(), Arg.Any <List <SQLiteParameter> >()).Returns(0);

                using (var albumController = new AlbumController(dataAccess))
                {
                    Assert.That(async() => await albumController.PutAsync(0, new Album(0, 1, 2, "name", 1999)), Throws.InstanceOf <SQLiteException>());
                }
            }
        }
Exemplo n.º 23
0
        public void GetById_IfNotNull_ShouldReturnOkResult()
        {
            int id = 1;

            _albumService = new Mock <IAlbumService>();
            _albumService.Setup(a => a.GetAlbumById(id)).Returns(_albums.ElementAt(id));
            var controller = new AlbumController(_albumService.Object, _mapper, _userManager.Object);

            var result = controller.GetById(id);

            Assert.IsInstanceOf <OkObjectResult>(result.Result);
        }
Exemplo n.º 24
0
        public void TestAlbumGetAllItems()
        {
            //Arrange
            var SqlLiteDataMock = new Mock <IMusicData>();
            var AlbumController = new AlbumController(SqlLiteDataMock.Object);

            //Act
            ActionResult actionResult = AlbumController.AlbumGetAllItems();

            //Assert
            Assert.IsType <OkObjectResult>(actionResult);
        }
 public MediaItemsController(GalleryController galleryController, AlbumController albumController, GalleryObjectController galleryObjectController, FileStreamController streamController, HtmlController htmlController, UrlController urlController, UserController userController, ExceptionController exController, IAuthorizationService authorizationService)
 {
     _galleryController       = galleryController;
     _albumController         = albumController;
     _galleryObjectController = galleryObjectController;
     _streamController        = streamController;
     _htmlController          = htmlController;
     _urlController           = urlController;
     _userController          = userController;
     _exController            = exController;
     _authorizationService    = authorizationService;
 }
Exemplo n.º 26
0
 public AlbumWebEntity UpdateAlbumInfo(AlbumWebEntity albumEntity)
 {
     try
     {
         return(AlbumController.UpdateAlbumInfo(albumEntity));
     }
     catch (Exception ex)
     {
         AppErrorController.LogError(ex);
         throw;
     }
 }
Exemplo n.º 27
0
        private void menuFileSaveAs_Click(object sender, EventArgs e)
        {
            string path = null;

            if (AlbumController.SaveAlbumDialog(ref path))
            {
                // Save the album under the new name
                SaveAlbum(path);
                // Update title bar to include new name
                SetTitleBar();
            }
        }
Exemplo n.º 28
0
        public void Album_Edit()
        {
            ISixteenBarsDb  mockDb      = new MockSixteenBarsDb();
            AlbumController ctrl        = new AlbumController(mockDb);
            AlbumViewModel  editedAlbum = new AlbumViewModel()
            {
                Id          = 1,
                Title       = "Because of the interwebs",
                ReleaseDate = new DateTime(2015, 5, 4),
                ArtistId    = 10
            };

            ctrl.Edit(editedAlbum);
            Assert.AreEqual(editedAlbum.Title, mockDb.Albums.Find(1).Title, "Title not changed to 'Because of the interwebs'.");
            Assert.AreEqual(editedAlbum.ReleaseDate, mockDb.Albums.Find(1).ReleaseDate, "Release date not changed to '5/4/15'.");
            Assert.AreEqual(editedAlbum.ArtistId, mockDb.Albums.Find(1).Artist.Id, "Artist not changed to 'Dr. Dre'.");

            editedAlbum = new AlbumViewModel()
            {
                Id          = 1,
                Title       = ".~`!@#$%^&*()_+-={}|:\"<>?[]\\;',./",
                ReleaseDate = new DateTime(1993, 11, 23),
                ArtistName  = ".~`!@#$%^&*()_+-={}|:\"<>?[]\\;',./"
            };
            ctrl.Edit(editedAlbum);
            Assert.AreEqual(editedAlbum.Title, mockDb.Albums.Find(1).Title, "Title not changed to .~`!@#$%^&*()_+-={}|:\"<>?[]\\;',./");
            Assert.AreEqual(editedAlbum.ReleaseDate, mockDb.Albums.Find(1).ReleaseDate, "Release date not changed to 11/23/93.");
            Assert.AreEqual(editedAlbum.ArtistName, mockDb.Albums.Find(1).Artist.Name, "Artist not chnaged to .~`!@#$%^&*()_+-={}|:\"<>?[]\\;',./");

            editedAlbum = new AlbumViewModel()
            {
                Id          = 1,
                Title       = "The Blueprint2",
                ReleaseDate = new DateTime(2002, 9, 11),
                ArtistId    = 9
            };
            ctrl.Edit(editedAlbum);
            Assert.AreEqual(editedAlbum.Title, mockDb.Albums.Find(1).Title, "Title not changed to The Blueprint2.");
            Assert.AreEqual(editedAlbum.ReleaseDate, mockDb.Albums.Find(1).ReleaseDate, "Release date not changed to 9/11/02.");
            Assert.AreEqual("50 Cent", mockDb.Albums.Find(1).Artist.Name, "Artist not changed to 50 Cent");


            //editedAlbum = new AlbumViewModel()
            //{
            //    Id = 1,
            //    Title = "Because the Internet",
            //    ReleaseDate = new DateTime(2013, 12, 3),
            //    ArtistName = "Childish Gambino"
            //};
            //ctrl.Edit(editedAlbum);
            //Assert.AreEqual(1,mockDb.Artists.f, "Because the Internet was created twice");
        }
        private TreeView GenerateTreeview()
        {
            // We'll use a TreeView instance to generate the appropriate XML structure
            ComponentArt.Web.UI.TreeView tv = new ComponentArt.Web.UI.TreeView();

            string handlerPath = String.Concat(Utils.GalleryRoot, "/handler/gettreeviewxml.ashx");

            IAlbum parentAlbum = AlbumController.LoadAlbumInstance(this._albumId, true);

            string securityActionParm = String.Empty;

            if (SecurityActionEnumHelper.IsValidSecurityAction(this._securityAction))
            {
                securityActionParm = String.Format(CultureInfo.CurrentCulture, "&secaction={0}", (int)this._securityAction);
            }

            foreach (IAlbum childAlbum in parentAlbum.GetChildGalleryObjects(GalleryObjectType.Album, true, !Utils.IsAuthenticated))
            {
                TreeViewNode node = new TreeViewNode();
                node.Text  = Utils.RemoveHtmlTags(childAlbum.Title);
                node.Value = childAlbum.Id.ToString(CultureInfo.InvariantCulture);
                node.ID    = childAlbum.Id.ToString(CultureInfo.InvariantCulture);

                if (!String.IsNullOrEmpty(_navigateUrl))
                {
                    node.NavigateUrl   = Utils.AddQueryStringParameter(_navigateUrl, String.Concat("aid=", childAlbum.Id.ToString(CultureInfo.InvariantCulture)));
                    node.HoverCssClass = "tv0HoverTreeNodeLink";
                }

                bool isUserAuthorized = true;
                if (SecurityActionEnumHelper.IsValidSecurityAction(this._securityAction))
                {
                    isUserAuthorized = Utils.IsUserAuthorized(_securityAction, RoleController.GetGalleryServerRolesForUser(), childAlbum.Id, childAlbum.GalleryId, childAlbum.IsPrivate);
                }
                node.ShowCheckBox = isUserAuthorized && _showCheckbox;
                node.Selectable   = isUserAuthorized;
                if (!isUserAuthorized)
                {
                    node.HoverCssClass = String.Empty;
                }

                if (childAlbum.GetChildGalleryObjects(GalleryObjectType.Album).Count > 0)
                {
                    string handlerPathWithAlbumId = Utils.AddQueryStringParameter(handlerPath, String.Concat("aid=", childAlbum.Id.ToString(CultureInfo.InvariantCulture)));
                    node.ContentCallbackUrl = String.Format(CultureInfo.CurrentCulture, "{0}{1}&sc={2}&nurl={3}", handlerPathWithAlbumId, securityActionParm, node.ShowCheckBox, Utils.UrlEncode(_navigateUrl));
                }

                tv.Nodes.Add(node);
            }

            return(tv);
        }
Exemplo n.º 30
0
        public ActionResult AssignThumbnail(Entity.GalleryItem galleryItem, int albumId)
        {
            // POST /api/albums/assignthumbnail?albumId=99
            try
            {
                var album = AlbumController.AssignThumbnail(galleryItem, albumId);

                return(new ActionResult()
                {
                    Status = ActionResultStatus.Success.ToString(),
                    Title = "Thumbnail Assigned",
                    Message = $"The media asset '{Utils.RemoveHtmlTags(galleryItem.Title)}' has been set as the thumbnail image for the album '{Utils.RemoveHtmlTags(album.Title)}'."
                });
            }
            catch (GallerySecurityException ex)
            {
                return(new ActionResult()
                {
                    Status = ActionResultStatus.Error.ToString(),
                    Title = Resources.GalleryServer.Task_AssignThumbnail_Cannot_Assign_Thumbnail_Msg_Hdr,
                    Message = ex.Message
                });
            }
            catch (InvalidAlbumException ex)
            {
                return(new ActionResult()
                {
                    Status = ActionResultStatus.Error.ToString(),
                    Title = Resources.GalleryServer.Task_AssignThumbnail_Cannot_Assign_Thumbnail_Msg_Hdr,
                    Message = ex.Message
                });
            }
            catch (InvalidMediaObjectException ex)
            {
                return(new ActionResult()
                {
                    Status = ActionResultStatus.Error.ToString(),
                    Title = Resources.GalleryServer.Task_AssignThumbnail_Cannot_Assign_Thumbnail_Msg_Hdr,
                    Message = ex.Message
                });
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = Utils.GetExStringContent(ex),
                    ReasonPhrase = "Server Error"
                });
            }
        }