コード例 #1
0
        public void ResizePhotoForUpload(PhotoFile photo, out Stream resizedPhotoStream)
        {
            using (var bitmap = Image.FromFile(photo.FilePath))
            {
                if (bitmap.Width <= MAX_SIZE && bitmap.Height <= MAX_SIZE)
                {
                    resizedPhotoStream = File.OpenRead(photo.FilePath);
                    return;
                }

                var size         = CalculateBestPhotoSize(bitmap);
                var resizedPhoto = GetThumbnailImage(bitmap, size);

                var encoderParameters = new EncoderParameters(1)
                {
                    Param =
                    {
                        [0] = new EncoderParameter(Encoder.Quality, JPEG_QUALITY)
                    }
                };

                resizedPhotoStream = new MemoryStream();
                resizedPhoto.Save(resizedPhotoStream, _jpegEncoder, encoderParameters);
                resizedPhotoStream.Seek(0, SeekOrigin.Begin);
            }
        }
コード例 #2
0
        //点击进入
        private void AdaptiveGridViewControl_ItemClick(object sender, ItemClickEventArgs e)
        {
            PhotoFile pf = e.ClickedItem as PhotoFile;

            if (pf.isAdd == Visibility.Visible)
            {
                AddContentDialog.ShowAsync();//Add:添加
            }
            else
            {
                try
                {
                    var xdoc = XDocument.Load(pf.Path);

                    App.Model.Name = pf.Name;//重命名

                    //宽高
                    App.Model.Width  = (int)xdoc.Descendants("Width").Single();
                    App.Model.Height = (int)xdoc.Descendants("Height").Single();

                    MainBottom(xdoc);

                    App.Model.StartVisibility = Visibility.Collapsed;
                }
                catch (Exception)
                {
                }
            }
        }
コード例 #3
0
        //查询提交
        private void AutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
        {
            if (args.ChosenSuggestion != null)
            {
                PhotoFile pf = args.ChosenSuggestion as PhotoFile;

                if (pf.isAdd == Visibility.Visible)
                {
                    AddContentDialog.ShowAsync();//Add:添加
                }
                else
                {
                    string path = pf.Path;
                    var    xdoc = XDocument.Load(path);

                    MainBottom(xdoc);
                    App.Model.StartVisibility = Visibility.Collapsed;
                }
            }
            else
            {
                // Do a fuzzy search on the query text
                //模糊搜索查询文本吗
                //    var matchingContacts = GetMatchingContacts(args.QueryText);

                // Choose the first match, or clear the selection if there are no matches.
                //选择第一个匹配,或明确的选择如果没有匹配。
                //SelectContact(matchingContacts.FirstOrDefault());
            }
        }
コード例 #4
0
        public void CloseEditor()
        {
            _isOpen = false;
            NotifyOfPropertyChange(() => IsOpen);

            _currentItem = null;
        }
コード例 #5
0
        public async Task <IActionResult> OnPost()
        {
            using var ms1 = new MemoryStream();
            await PhotoFile.CopyToAsync(ms1);

            ms1.Position = 0;

            var model = new Application.Posts.Models.PostAddModel
            {
                Body   = this.Body,
                UserId = ""
            };

            var postId = await _postService.Create(model);

            var userId = User.GetUserId();

            #region Upload to Vega

            var channel = new Grpc.Core.Channel("localhost:5005", SslCredentials.Insecure);
            var client  = new Servers.Vega.FileService.FileServiceClient(channel);

            var result2 = client.UploadFile(new UploadRequest
            {
                Content     = ByteString.CopyFrom(ms1.ToArray()),
                ContentType = PhotoFile.ContentType,
                Name        = PhotoFile.FileName,
                PostId      = postId,
                UserId      = User.GetUserId()
            });
            #endregion

            return(RedirectToPage("/index"));
        }
コード例 #6
0
        private void ShareShareButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            //删光临时文件夹
            IEnumerable <StorageFile> DelelteFiles = ApplicationData.Current.TemporaryFolder.GetFilesAsync().AsTask().Result;

            foreach (var file in DelelteFiles)
            {
                file.DeleteAsync();
            }


            //遍历网格列表
            foreach (Object photoFile in AdaptiveGridViewControl.SelectedItems)
            {
                PhotoFile pf   = photoFile as PhotoFile;
                var       XDoc = XDocument.Load(pf.Path);

                string Name = pf.Name;

                //宽高
                int Width  = (int)XDoc.Descendants("Width").Single();
                int Height = (int)XDoc.Descendants("Height").Single();

                //读取数据
                string Target = XDoc.Descendants("MainRenderTarget").Single().Value;
                byte[] bytes  = Convert.FromBase64String(Target);

                //保存图片
                switch (ShareIndex)
                {
                case 0:
                    App.Model.SecondTopRenderTarget = new CanvasRenderTarget(App.Model.VirtualControl, Width, Height);
                    App.Model.SecondTopRenderTarget.SetPixelBytes(bytes);
                    App.Model.SecondBottomRenderTarget = new CanvasRenderTarget(App.Model.VirtualControl, Width, Height);
                    using (var ds = App.Model.SecondBottomRenderTarget.CreateDrawingSession())
                    {
                        ds.Clear(Colors.White);
                        ds.DrawImage(App.Model.SecondTopRenderTarget);
                    }
                    修图.Library.Image.SaveJpeg(ApplicationData.Current.TemporaryFolder, App.Model.SecondBottomRenderTarget, Name);
                    break;

                case 1: 修图.Library.Image.SavePng(ApplicationData.Current.TemporaryFolder, bytes, Width, Height, Name); break;

                case 2: 修图.Library.Image.SaveBmp(ApplicationData.Current.TemporaryFolder, bytes, Width, Height, Name); break;;

                case 3: 修图.Library.Image.SaveGif(ApplicationData.Current.TemporaryFolder, bytes, Width, Height, Name); break;

                case 4: 修图.Library.Image.SaveTiff(ApplicationData.Current.TemporaryFolder, bytes, Width, Height, Name); break;

                default: break;
                }
            }


            //Share:分享
            dataTransferManager.DataRequested += OnDataRequested;
            DataTransferManager.ShowShareUI();
        }
コード例 #7
0
ファイル: WorkerDto.cs プロジェクト: jiangyimin/Clc
 public void Normalize()
 {
     if (PhotoFile != null)
     {
         Photo = new byte[PhotoFile.Length];
         PhotoFile.OpenReadStream().Read(Photo, 0, (int)PhotoFile.Length);
     }
 }
コード例 #8
0
 private void FillUpDimensions(PhotoFile photoFile, PhotoInfo photoInfo)
 {
     using (var bitmap = Image.FromFile(photoFile.FilePath))
     {
         photoInfo.Height = bitmap.Height;
         photoInfo.Width  = bitmap.Width;
     }
 }
コード例 #9
0
        /**
         * Execute DeleteCommand
         * Delete the corresponding photo file
         * @param parameter Parameter object; here it is is a PhotoFile object
         */
        public async void Execute(object parameter)
        {
            PhotoFile file = (PhotoFile)parameter;
            await file.File.DeleteAsync();

            viewModel.FileList.Remove(file);
            viewModel.UpdateFileList();
        }
コード例 #10
0
        private async void SaveSaveButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            LoadingControl.IsLoading = true;//Con:加载控件

            foreach (Object photoFile in AdaptiveGridViewControl.SelectedItems)
            {
                PhotoFile pf   = photoFile as PhotoFile;
                var       XDoc = XDocument.Load(pf.Path);

                string Name = pf.Name;

                //宽高
                int Width  = (int)XDoc.Descendants("Width").Single();
                int Height = (int)XDoc.Descendants("Height").Single();

                //读取数据
                string Target = XDoc.Descendants("MainRenderTarget").Single().Value;
                byte[] bytes  = Convert.FromBase64String(Target);

                //保存图片
                switch (SaveIndex)
                {
                case 0:
                    App.Model.SecondTopRenderTarget = new CanvasRenderTarget(App.Model.VirtualControl, Width, Height);
                    App.Model.SecondTopRenderTarget.SetPixelBytes(bytes);
                    App.Model.SecondBottomRenderTarget = new CanvasRenderTarget(App.Model.VirtualControl, Width, Height);
                    using (var ds = App.Model.SecondBottomRenderTarget.CreateDrawingSession())
                    {
                        ds.Clear(Colors.White);
                        ds.DrawImage(App.Model.SecondTopRenderTarget);
                    }
                    修图.Library.Image.SaveJpeg(KnownFolders.SavedPictures, App.Model.SecondBottomRenderTarget, Name);
                    break;

                case 1: 修图.Library.Image.SavePng(KnownFolders.SavedPictures, bytes, Width, Height, Name); break;

                case 2: 修图.Library.Image.SaveBmp(KnownFolders.SavedPictures, bytes, Width, Height, Name); break;;

                case 3: 修图.Library.Image.SaveGif(KnownFolders.SavedPictures, bytes, Width, Height, Name); break;

                case 4: 修图.Library.Image.SaveTiff(KnownFolders.SavedPictures, bytes, Width, Height, Name); break;

                default: break;
                }
            }
            InAppNotificationDismiss(SaveInAppNotification);//Notification:通知驳回

            await Task.Delay(1000);

            LoadingControl.IsLoading = false;//Con:加载控件

            string path = "Icon/Clutter/OK.png";

            修图.Library.Toast.ShowToastNotification(path, "已保存到本地相册");
        }
コード例 #11
0
        private void SwitchSelection(PhotoFile currentItem, PhotoFile previousItem)
        {
            if (currentItem != null)
            {
                currentItem.IsSelected = true;
            }

            if (previousItem != null)
            {
                previousItem.IsSelected = false;
            }
        }
コード例 #12
0
        public async Task <IActionResult> Edit(int?id, [FromForm] ServiceModelEditSerializer model)
        {
            if (id == null)
            {
                return(BadRequest());
            }
            User user = await _userManager.FindByEmailAsync(_userManager.GetUserId(HttpContext.User));

            Service serviceDb = _db.Services.Find(id);

            if (serviceDb.UserId != user.Id)
            {
                return(BadRequest());
            }
            if (serviceDb == null)
            {
                return(NotFound());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (model.Describing != null)
            {
                serviceDb.Describing = model.Describing;
            }
            if (model.Header != null)
            {
                serviceDb.Header = model.Header;
            }
            if (model.Location != null)
            {
                serviceDb.Location = model.Location;
            }
            if (model.Price != 0)
            {
                serviceDb.Price = model.Price;
            }
            if (model.PhotoFile != null)
            {
                //delete old photo
                string    path     = Path.Combine(_environment.WebRootPath, "images");
                PhotoFile photo    = _db.PhotoFiles.Find(serviceDb.PhotoFileId);
                string    filePath = Path.Combine(path, photo.Path);
                System.IO.File.Delete(filePath);
                //upload new and update
                serviceDb.PhotoFileId = UploadFile(model.PhotoFile);
                _db.PhotoFiles.Remove(photo);
            }
            _db.Services.Update(serviceDb);
            _db.SaveChanges();
            return(Ok(serviceDb));
        }
コード例 #13
0
        /**
         * Initialize the photo viewer page
         */
        internal async Task InitViewerAsync()
        {
            FileList.Clear();

            IReadOnlyList <StorageFile> files = await KnownFolders.SavedPictures.GetFilesAsync();

            foreach (StorageFile file in files)
            {
                PhotoFile newPhotoFile = await PhotoFile.GeneratePhotoFile(file);

                FileList.Add(newPhotoFile);
            }
        }
コード例 #14
0
        public override async Task ProcessRequestAsync(HttpContext context)
        {
            //get the id of the photo object
            int photoID;

            if (!Int32.TryParse(context.Request.QueryString["ID"], out photoID))
            {
                context.Response.StatusCode = 400;
                return;
            }

            var dataContext = new DataContext();
            //retrieve the object metadata from the database. Not that the call is async so it does not block the thread while waiting for the database to respond
            PhotoInfo photoInfo = await dataContext.PhotoInfos.SingleOrDefaultAsync(pi => pi.BusinessCardID == photoID);

            //if the object is not found return the appropriate status code
            if (photoInfo == null)
            {
                context.Response.StatusCode = 404;
                return;
            }

            DateTime clientLastModified;

            //check if the image has been modified since it was last served
            //if not return 304 status code
            if (DateTime.TryParse(context.Request.Headers["If-Modified-Since"], out clientLastModified) &&
                clientLastModified.AddSeconds(CacheDateEpsilonSeconds) >= photoInfo.LastModifiedDate)
            {
                context.Response.StatusCode        = 304;
                context.Response.StatusDescription = "Not Modified";
                return;
            }

            //set various cache options
            context.Response.Cache.SetCacheability(HttpCacheability.Private);
            context.Response.Cache.VaryByParams["d"] = true;
            context.Response.Cache.SetLastModified(photoInfo.LastModifiedDate);
            context.Response.Cache.SetMaxAge(new TimeSpan(365, 0, 0, 0));
            context.Response.Cache.SetOmitVaryStar(true);
            context.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(365));
            context.Response.Cache.SetValidUntilExpires(true);

            //Get the actual file data. Again note the async IO call
            PhotoFile file = await dataContext.PhotoFiles.SingleAsync(pf => pf.BusinessCardID == photoID);

            //serve the image with the appropriate MIME type. In this case the MIME type is determined when saving in the database
            context.Response.ContentType = photoInfo.MimeType;
            context.Response.BinaryWrite(file.PhotoData);
        }
コード例 #15
0
        //加载完成
        private async void AdaptiveGridViewControl_Loaded(object sender, RoutedEventArgs e)
        {
            //Blank:空白添加
            AddPhotoFile = new PhotoFile()
            {
                Name     = App.resourceLoader.GetString("/Home/Blank_"),
                Describe = App.resourceLoader.GetString("/Home/BlankDescribe_"),
                Uri      = new Uri("ms-appx:///Icon/Clutter/Add.png"),
                isAdd    = Visibility.Visible
            };

            AdaptiveGridViewControl.ItemsSource = PhotoFileList;
            GridViewLoaded();
        }
コード例 #16
0
        private bool FileSizeIsValid()
        {
            using (var memoryStream = new MemoryStream())
            {
                PhotoFile.CopyTo(memoryStream);

                // if less than 2 MB
                if (memoryStream.Length < 2097152)
                {
                    Photo64 = memoryStream.ToArray();
                    return(true);
                }
                return(false);
            }
        }
コード例 #17
0
        public PhotoInfo CreatePhotoInfoFromFile(PhotoFile photoFile)
        {
            var uri = new System.Uri(photoFile.FilePath);

            var info = new Models.PhotoInfo {
                Title        = photoFile.Name,
                WebUrl       = uri.AbsoluteUri,
                Small320Url  = uri.AbsoluteUri,
                Medium640Url = uri.AbsoluteUri,
                Medium800Url = uri.AbsoluteUri,
                LargeUrl     = uri.AbsoluteUri
            };

            FillUpDimensions(photoFile, info);

            return(info);
        }
コード例 #18
0
        public IList <PhotoFile> GetPhotoNames(out IList <string> unparseableFiles, string prefix = "")
        {
            var list = new List <PhotoFile>();

            using (var client = CreateAmazonS3Client()) {
                var response = client.ListObjects(new ListObjectsRequest().WithBucketName(_bucket.BucketName).WithPrefix(Folders.Photos + "/" + prefix));
                unparseableFiles = new List <string>();
                foreach (var s3Object in response.S3Objects)
                {
                    var fileName = s3Object.Key;
                    var pos      = fileName.LastIndexOf('/') + 1;
                    fileName = fileName.Substring(pos);
                    pos      = fileName.LastIndexOf(".jpg", StringComparison.Ordinal);
                    if (pos <= 0)
                    {
                        unparseableFiles.Add(s3Object.Key);
                    }
                    else
                    {
                        if (fileName[1] != '-')
                        {
                            unparseableFiles.Add(s3Object.Key);
                        }
                        else
                        {
                            try {
                                var  type     = (byte)(fileName[0] - 48);
                                var  guidText = fileName.Substring(2, fileName.Length - 6);
                                Guid guid;
                                if (Guid.TryParse(guidText, out guid))
                                {
                                    unparseableFiles.Add(s3Object.Key);
                                }
                                var photoFile = new PhotoFile {
                                    PhotoType = type, Guid = guid
                                };
                                list.Add(photoFile);
                            } catch {
                                unparseableFiles.Add(fileName);
                            }
                        }
                    }
                }
            }
            return(list);
        }
コード例 #19
0
        private async Task Save()
        {
            foreach (Object photoFile in AdaptiveGridViewControl.SelectedItems)
            {
                PhotoFile pf   = photoFile as PhotoFile;
                var       XDoc = XDocument.Load(pf.Path);

                string Name = pf.Name;

                //宽高
                int Width  = (int)XDoc.Descendants("Width").Single();
                int Height = (int)XDoc.Descendants("Height").Single();

                //读取数据
                string Target = XDoc.Descendants("MainRenderTarget").Single().Value;
                byte[] bytes  = Convert.FromBase64String(Target);

                //保存图片
                switch (SaveIndex)
                {
                case 0:
                    App.Model.SecondTopRenderTarget = new CanvasRenderTarget(App.Model.VirtualControl, Width, Height);
                    App.Model.SecondTopRenderTarget.SetPixelBytes(bytes);
                    App.Model.SecondBottomRenderTarget = new CanvasRenderTarget(App.Model.VirtualControl, Width, Height);
                    using (var ds = App.Model.SecondBottomRenderTarget.CreateDrawingSession())
                    {
                        ds.Clear(Colors.White);
                        ds.DrawImage(App.Model.SecondTopRenderTarget);
                    }
                    await 修图.Library.Image.SaveJpeg(KnownFolders.SavedPictures, App.Model.SecondBottomRenderTarget, Name);

                    break;

                case 1: await 修图.Library.Image.SavePng(KnownFolders.SavedPictures, bytes, Width, Height, Name); break;

                case 2: await 修图.Library.Image.SaveBmp(KnownFolders.SavedPictures, bytes, Width, Height, Name); break;;

                case 3: await 修图.Library.Image.SaveGif(KnownFolders.SavedPictures, bytes, Width, Height, Name); break;

                case 4: await 修图.Library.Image.SaveTiff(KnownFolders.SavedPictures, bytes, Width, Height, Name); break;

                default: break;
                }
            }
        }
コード例 #20
0
        private void CopyMenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (RightPhotoFile != null)
            {
                var NewName = Named(RightPhotoFile.Name);
                //复制文件
                var    xDoc = XDocument.Load(RightPhotoFile.Path);
                string path = ApplicationData.Current.LocalFolder.Path + "/" + NewName + ".photo"; //将XML文件加载进来
                xDoc.Save(path);


                //6、缩略图 (裁切成宽高最大256的图片)

                //宽高
                int Width  = (int)xDoc.Descendants("Width").Single();
                int Height = (int)xDoc.Descendants("Height").Single();

                //渲染目标
                string Target = xDoc.Descendants("MainRenderTarget").Single().Value;
                byte[] bytes  = Convert.FromBase64String(Target); App.Model.MainRenderTarget = new CanvasRenderTarget(App.Model.VirtualControl, Width, Height);
                App.Model.MainRenderTarget.SetPixelBytes(bytes);

                //缩略图缩放比例
                float scale = Width < Height ? 256.0f / Width : 256.0f / Height;

                //缩放后宽高并确定左右上下偏移
                float W = scale * Width;
                float H = scale * Height;

                CanvasRenderTarget crt = new CanvasRenderTarget(App.Model.VirtualControl, W, H);
                using (CanvasDrawingSession ds = crt.CreateDrawingSession())
                {
                    //绘制缩略图
                    ds.DrawImage(new ScaleEffect
                    {
                        Source = App.Model.MainRenderTarget,
                        Scale  = new Vector2(scale)
                    });
                }
                Library.Image.SavePng(ApplicationData.Current.LocalFolder, crt, NewName);

                GridViewLoaded();
            }
            RightPhotoFile = null;
        }
コード例 #21
0
        public async Task <IActionResult> OnPost()
        {
            using var ms1 = new MemoryStream();
            await PhotoFile.CopyToAsync(ms1);

            ms1.Position = 0;

            var model = new Application.Posts.Models.PostAddModel
            {
                Body     = this.Body,
                Content  = ms1.ToArray(),
                MimeType = PhotoFile.ContentType,
                UserId   = ""
            };

            await _postService.Create(model);

            return(RedirectToPage("/index"));
        }
コード例 #22
0
        public override async Task ProcessRequestAsync(HttpContext context)
        {
            int photoID;

            if (!Int32.TryParse(context.Request.QueryString["ID"], out photoID))
            {
                context.Response.StatusCode = 400;
                return;
            }

            var dataContext = new DataContext();

            PhotoInfo photoInfo = await dataContext.PhotoInfos.SingleOrDefaultAsync(pi => pi.BusinessCardID == photoID);

            if (photoInfo == null)
            {
                context.Response.StatusCode = 404;
                return;
            }

            DateTime clientLastModified;

            if (DateTime.TryParse(context.Request.Headers["If-Modified-Since"], out clientLastModified) &&
                clientLastModified.AddSeconds(CacheDateEpsilonSeconds) >= photoInfo.LastModifiedDate)
            {
                context.Response.StatusCode        = 304;
                context.Response.StatusDescription = "Not Modified";
                return;
            }

            context.Response.Cache.SetCacheability(HttpCacheability.Private);
            context.Response.Cache.VaryByParams["d"] = true;
            context.Response.Cache.SetLastModified(photoInfo.LastModifiedDate);
            context.Response.Cache.SetMaxAge(new TimeSpan(365, 0, 0, 0));
            context.Response.Cache.SetOmitVaryStar(true);
            context.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(365));
            context.Response.Cache.SetValidUntilExpires(true);

            PhotoFile file = await dataContext.PhotoFiles.SingleAsync(pf => pf.BusinessCardID == photoID);

            context.Response.ContentType = photoInfo.MimeType;
            context.Response.BinaryWrite(file.PhotoData);
        }
コード例 #23
0
ファイル: PhotoService.cs プロジェクト: pro100maksua/MySkype
        public async Task <PhotoFile> DownloadAsync(Photo photo)
        {
            var path = GetFilePath(photo.FileName);

            var memoryStream = new MemoryStream();

            using (var stream = new FileStream(path, FileMode.Open))
            {
                await stream.CopyToAsync(memoryStream);
            }

            memoryStream.Position = 0;
            var photoStream = new PhotoFile
            {
                MemoryStream = memoryStream,
                ContentType  = "image/" + Path.GetExtension(photo.FileName)
            };

            return(photoStream);
        }
コード例 #24
0
        private int UploadFile(IFormFile uploadedFile)
        {
            if (uploadedFile != null)
            {
                string uploadsFolder  = Path.Combine(_environment.WebRootPath, "images");
                string uniqueFileName = Guid.NewGuid().ToString() + "_" + uploadedFile.FileName;
                string filePath       = Path.Combine(uploadsFolder, uniqueFileName);

                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    uploadedFile.CopyTo(fileStream);
                }
                PhotoFile file = new PhotoFile {
                    Path = filePath
                };
                _db.PhotoFiles.Add(file);
                _db.SaveChanges();
                return(file.Id);
            }
            return(0);
        }
コード例 #25
0
        private void AdaptiveGridViewControl_RightTapped(object sender, RightTappedRoutedEventArgs e)
        {
            AdaptiveGridView agv = sender as AdaptiveGridView;

            if (agv.SelectionMode == ListViewSelectionMode.None)  //GridView:多选
            {
                if (e.OriginalSource is FrameworkElement element) //获取控件元素
                {
                    if (element.DataContext is PhotoFile file)
                    {
                        if (file.isAdd == Visibility.Collapsed)
                        {
                            RightPhotoFile = file;

                            Point p = e.GetPosition(agv);
                            GridView_MenuFlyout.ShowAt(agv, p);//显示
                        }
                    }
                }
            }
        }
コード例 #26
0
        private async void DeleteMenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (RightPhotoFile != null)
            {
                //遍历,删除
                IReadOnlyList <StorageFile> FileList = await ApplicationData.Current.LocalFolder.GetFilesAsync();

                foreach (StorageFile file in FileList)
                {
                    //删除右键文件
                    if (file.DisplayName == RightPhotoFile.Name)
                    {
                        await file.DeleteAsync();
                    }
                }

                //移除右键项目
                PhotoFileList.Remove(RightPhotoFile);
            }
            RightPhotoFile = null;
        }
コード例 #27
0
        public static void ImageOpened(PhotoFile photoFile)
        {
            var tuple = _imagesCache.LastOrDefault(x => x.Item1 == photoFile);

            _imagesCache.Remove(tuple);
            if (tuple != null)
            {
                var image = tuple.Item2;
                image.Opacity = 0.0;
                var storyboard = new Storyboard();

                var opacityImageAniamtion = new DoubleAnimationUsingKeyFrames();
                opacityImageAniamtion.KeyFrames.Add(new EasingDoubleKeyFrame {
                    KeyTime = TimeSpan.FromSeconds(0.5), Value = 1.0
                });
                Storyboard.SetTarget(opacityImageAniamtion, image);
                Storyboard.SetTargetProperty(opacityImageAniamtion, new PropertyPath("Opacity"));
                storyboard.Children.Add(opacityImageAniamtion);

                storyboard.Begin();
            }
        }
コード例 #28
0
        public IList <PhotoFile> GetPhotoNames(out IList <string> unparseableFiles, string prefix = "")
        {
            unparseableFiles = new List <string>();
            var list  = new List <PhotoFile>();
            var files = Directory.GetFiles(_baseFolderName + "\\" + Folders.Photos, prefix + "*.jpg");

            foreach (var fn in files)
            {
                var pos      = fn.LastIndexOf('\\');
                var fileName = fn.Substring(pos);
                pos = fileName.LastIndexOf(".jpg", StringComparison.Ordinal);
                if (pos <= 0)
                {
                    unparseableFiles.Add(fileName);
                }
                else
                {
                    if (fileName[1] != '-')
                    {
                        unparseableFiles.Add(fileName);
                    }
                    else
                    {
                        try {
                            var type      = (byte)(fileName[0] - 48);
                            var guid      = fileName.Substring(2, fileName.Length - 6);
                            var photoFile = new PhotoFile {
                                PhotoType = type, Guid = Guid.Parse(guid)
                            };
                            list.Add(photoFile);
                        } catch {
                            unparseableFiles.Add(fileName);
                        }
                    }
                }
            }
            return(list);
        }
コード例 #29
0
        public void Delete(PhotoFile file)
        {
            var index = Items.IndexOf(file);

            if (index == -1)
            {
                return;
            }
            Items.RemoveAt(index);
            if (CurrentItem == file)
            {
                if (Items.Count > 1)
                {
                    if (Items.Count > index + 1)
                    {
                        CurrentItem = Items[index];
                    }
                    else
                    {
                        CurrentItem = Items[index - 1];
                    }
                }
                else
                {
                    CurrentItem = null;
                }
            }

            IsDoneEnabled = Items.FirstOrDefault(x => !x.IsButton) != null;
            NotifyOfPropertyChange(() => IsDeleteEnabled);

            if (Items.Count == 1)
            {
                _isOpen = false;
                NotifyOfPropertyChange(() => IsOpen);
            }
        }
コード例 #30
0
        public void SelectMessage(PhotoFile file)
        {
            if (file.IsButton)
            {
#if WP81
                ((App)Application.Current).ChooseFileInfo = new ChooseFileInfo(DateTime.Now);
                var fileOpenPicker = new FileOpenPicker();
                fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                fileOpenPicker.ViewMode = PickerViewMode.Thumbnail;
                fileOpenPicker.FileTypeFilter.Clear();
                fileOpenPicker.FileTypeFilter.Add(".bmp");
                fileOpenPicker.FileTypeFilter.Add(".png");
                fileOpenPicker.FileTypeFilter.Add(".jpeg");
                fileOpenPicker.FileTypeFilter.Add(".jpg");
                fileOpenPicker.ContinuationData.Add("From", "DialogDetailsView");
                fileOpenPicker.ContinuationData.Add("Type", "Image");
                fileOpenPicker.PickMultipleFilesAndContinue();
#endif
            }
            else
            {
                CurrentItem = file;
            }
        }