示例#1
0
        private async Task LoadImg()
        {
            if (UserManagement.UserSession.Type == false)
            {
                return;
            }
            IEnumerable <Movies> lstMovie = new List <Movies>();
            ImageList            imgList, imgListAll;
            List <Movies>        lstExists = new List <Movies>();

            if (cbResetData.Checked)
            {
                List <string> validFolders = await getFolderContainMovies();

                if (validFolders == null)
                {
                    return;
                }
                bool isDelete = await rpMovie.DeleteAllMovie();

                if (isDelete == false)
                {
                    return;
                }
                List <Movies> lstBase64 = await Video.createPreviewFolder(validFolders);

                if (lstBase64 != null && lstBase64.Any())
                {
                    var insertTasks = new List <Task>();
                    foreach (Movies mv in lstBase64)
                    {
                        if (mv.Name.ToLower().Contains("sakura miura"))
                        {
                            string s = mv.Name;
                        }
                        var exist = await rpMovie.GetByFullPath(mv.FullPath);

                        if (exist == null || !exist.Any())
                        {
                            insertTasks.Add(rpMovie.Insert(mv));
                        }
                        else
                        {
                            lstExists.Add(mv);
                        }
                    }
                    await Task.WhenAll(insertTasks);
                }
                var temps = lstBase64.Where(p => p.FullPath.Contains("358"));
            }

            imgList    = new ImageList();
            imgListAll = new ImageList();

            List <Movies> moviesBySearch = new List <Movies>();

            var query = metroTextBox1.Text != null?metroTextBox1.Text.Trim() : string.Empty;

            if (string.IsNullOrWhiteSpace(query))
            {
                lstMovie = await rpMovie.GetAllMovie();
            }
            else
            {
                lstMovie = await rpMovie.Search(query);
            }

            if (lstMovie != null)
            {
                foreach (var mv in lstMovie)
                {
                    try
                    {
                        var img = await Base64ToImage(mv.Image);

                        imgList.ImageSize = new Size(90, 90);
                        imgList.Images.Add(img);
                    }
                    catch (Exception ex)
                    {
                    }
                }
                await addtoListView(imgList, lstMovie.ToList());
            }
            cbResetData.Checked = false;
            await deleteFolder();
        }