public void RequestPlaying(string filename) { TagModel model = DocNode.Create <TagModel>(); model.FileNameFull = filename; try { int tagSize = TagUtils.TagSizeV2(new FileInfo(filename)); using (Stream stream = VirtualDrive.OpenInStream(filename)) { stream.Seek(tagSize, SeekOrigin.Begin); model.Bitrate.Value = ID3MediaFileHeader.MP3Header.ReadBitrate( stream, VirtualDrive.FileLength(filename)); } } catch (Exception) { } FileInfo fileInfo = new FileInfo(filename); FileTreeModel.ExpandAndSelect(fileInfo.DirectoryName, true); RequestPlaying(model); }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { FileTreeModel model = values[0] as FileTreeModel; Func <FileTreeModel, bool> predicate = values[1] as Func <FileTreeModel, bool>; return(predicate?.Invoke(model) ?? true); }
public JsonResult GetTreeData(string rootFolder, string dir) { if (string.IsNullOrEmpty(rootFolder)) { rootFolder = KentConfiguration.MediaPath; } if (string.IsNullOrWhiteSpace(dir)) { var rootNode = new FileTreeModel { attr = new FileTreeAttribute { Id = rootFolder.ToIdString(), Rel = "home", Path = rootFolder }, state = "open", data = rootFolder.Replace("/", "").CamelFriendly().ToUpper() }; _mediaService.PopulateTree(rootFolder, rootNode); return(Json(rootNode)); } return(Json(_mediaService.PopulateChild(dir))); }
private void OnAfterBatch(object sender, EventArgs e) { if (!Editor.Transaction.HasId) { Debug.Assert(!Editor.RefreshFlank.Value); FileTreeModel.Refresh(); } else { try { History.Instance.ExecuteInTransaction( delegate() { FileTreeModel.Refresh(); Editor.RepairPath(); Editor.RefreshFlank.Value = false; }, Editor.Transaction.CurrentId, "Document.OnBatchFinished"); } finally { Editor.Transaction.End(); } } IsBatchActive.Value = false; }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { FileTreeModel model = values[0] as FileTreeModel; Func <FileTreeModel, bool> predicate = values[1] as Func <FileTreeModel, bool>; bool result = predicate?.Invoke(model) ?? true; for (int i = 2; result && i < values.Length; ++i) { predicate = values[i] as Func <FileTreeModel, bool>; if (predicate != null) { result &= !predicate(model); } else if (values[i] is bool) { result &= !(bool)values[i]; } else { break; } } return(result ? System.Convert.ToDouble(parameter) : 1); }
/// <summary> /// 获取照片目录集合 /// </summary> /// <param name="dir"></param> /// <param name="d"></param> /// <returns></returns> public List <FileTreeModel> GetAllFiles(DirectoryInfo dir, FileTreeModel d) { List <FileTreeModel> FileList = new List <FileTreeModel>(); FileInfo[] allFile = dir.GetFiles(); total = allFile.Count(); foreach (FileInfo fi in allFile) { d.Subitem.Add(new FileTreeModel() { FileName = fi.Name, FilePath = fi.FullName, FileType = (int)FieleTypeEnum.Picture, Icon = "../refresh/picture.ico" }); } DirectoryInfo[] allDir = dir.GetDirectories(); foreach (DirectoryInfo dif in allDir) { FileTreeModel fileDir = new FileTreeModel() { FileName = dif.Name, FilePath = dif.FullName, FileType = (int)FieleTypeEnum.Folder, Icon = "../refresh/folder.ico" }; GetAllFiles(dif, fileDir); fileDir.SubitemCount = string.Format($"({total})"); FileList.Add(fileDir); } return(FileList); }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { FileTreeModel model = values[0] as FileTreeModel; Func <FileTreeModel, bool> predicate = values[1] as Func <FileTreeModel, bool>; bool result = predicate?.Invoke(model) ?? true; for (int i = 2; !result && i < values.Length; ++i) { predicate = values[i] as Func <FileTreeModel, bool>; if (predicate != null) { result |= predicate(model); } else if (values[i] is bool) { result |= (bool)values[i]; } else { break; } } return(result ? Visibility.Visible : Visibility.Collapsed); }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values == null || values.Length != 4 || !(values[0] is FileTreeModel) || !(values[1] is double) || !(values[2] is double) || !(values[3] is DependencyObject)) { return(null); } int x = (int)(double)values[1]; int y = (int)(double)values[2]; if (x < 1) { x = 1; } if (y < 1) { y = 1; } FileTreeModel model = (FileTreeModel)values[0]; if (!model.IsFile) { bool isExpanded = model.IsExpanded; ImageMoniker moniker = isExpanded ? KnownMonikers.FolderOpened : KnownMonikers.FolderClosed; return(WpfUtil.ThemeImage((DependencyObject)values[3], WpfUtil.GetIconForImageMoniker(moniker, x, y))); } string name = model.Name; bool isThemeIcon; ImageSource source = WpfUtil.GetIconForFile((DependencyObject)values[3], name, out isThemeIcon); return(source); }
/// <summary> /// 查找女优的头像地址 /// </summary> /// <param name="name">女优姓名</param> /// <param name="cancelationToken"></param> /// <returns></returns> public async Task <string> FindAsync(string name, CancellationToken cancelationToken) { await locker.WaitAsync(cancelationToken); try { if (tree == null || (DateTime.Now - last).TotalHours > 1) { var json = await client.GetStringAsync("Filetree.json"); tree = _jsonSerializer.DeserializeFromString <FileTreeModel>(json); last = DateTime.Now; tree.Content = tree.Content.OrderBy(o => o.Key).ToDictionary(o => o.Key, o => o.Value); } } catch (Exception ex) { log.Error(ex.Message); } finally { locker.Release(); } if (tree?.Content?.Any() != true) { return(null); } return(tree.Find(name)); }
private void ItemDoubleClicked(object sender, MouseButtonEventArgs e) { TreeViewItem item = sender as TreeViewItem; FileTreeModel model = item?.DataContext as FileTreeModel; model?.ItemDoubleClicked(sender, e); this._closeAction?.Invoke(); }
private void OnPathChanged(Object sender, PropertyChangedEventArgs e) { string selectedPath = FileTreeModel.SelectedPathString(); if (!FileUtils.ArePathsEqual(selectedPath, Editor.Path.Value)) { FileTreeModel.ExpandAndSelect(Editor.Path.Value, false); } }
/// <summary> /// Populate master tree /// </summary> /// <param name="relativePath"></param> /// <param name="node"></param> public void PopulateTree(string relativePath, FileTreeModel node) { var physicalPath = HttpContext.Current.Server.MapPath(relativePath); if (node.children == null) { node.children = new List <FileTreeModel>(); } var directory = new DirectoryInfo(physicalPath); //Loop through each subdirectory foreach (var d in directory.GetDirectories().Where(d => !d.Name.Equals(FrameworkConstants.ResizedFolder))) { var mediaPath = string.Format("{0}/{1}", relativePath, d.Name); var t = new FileTreeModel { attr = new FileTreeAttribute { Id = mediaPath.ToIdString(), Path = mediaPath, Rel = "folder" }, data = d.Name, state = "closed" }; node.children.Add(t); } //Loop through each file in master directory foreach (var f in directory.GetFiles()) { var mediaPath = string.Format("{0}/{1}", relativePath, f.Name); var t = new FileTreeModel { attr = new FileTreeAttribute { Id = mediaPath.ToIdString(), Path = mediaPath, Class = "jstree-leaf" }, data = f.Name, state = "open", }; if (f.FullName.IsImage()) { t.attr.Rel = "image"; t.attr.IsImage = true; } else { t.attr.Rel = "file"; } node.children.Add(t); } }
protected override void OnViewLoaded(object view) { base.OnViewLoaded(view); ManualsLogic logic = new ManualsLogic(Settings.ManualFolder); Tree = logic.Tree; // TODO finish this part ShowManualCommand = new RelayCommand <string>(ShowManual, CanUseSelectedFile); OpenFolderCommand = new RelayCommand <string>(OpenFolder, CanUseSelectedFolder); }
private void OnKeyUp(object sender, KeyEventArgs e) { if (IsSupportedKey(e.Key)) { FileTreeModel model = DataContext as FileTreeModel; TreeNode node = model.SearchTreeNode(MakeStringFromKey(e.Key)); if (!Object.ReferenceEquals(node, null)) { node.IsSelected = true; ScrollTo(node); } } }
public JsonResult GetTreeData(string dir) { if (string.IsNullOrWhiteSpace(dir)) { var rootNode = new FileTreeModel { attr = new FileTreeAttribute { Id = _mediaServices.MediaDefaultPath, Rel = "home" }, state = "open", data = "MEDIA" }; var physicalPath = _mediaServices.MediaDefaultPath; _mediaServices.PopulateTree(physicalPath, rootNode); return(Json(rootNode)); } return(Json(_mediaServices.PopulateChild(dir))); }
private void OnSelectedItemChanged( object obj, RoutedPropertyChangedEventArgs <object> args) { if (SelectedItem is TreeNode) { FileTreeModel fileTreeModel = DataContext as FileTreeModel; TreeNode newSelectedItem = SelectedItem as TreeNode; TreeNode oldSelectedItem = fileTreeModel.SelectedTreeNode; if (!Object.ReferenceEquals(newSelectedItem, oldSelectedItem)) { fileTreeModel.SelectedTreeNode = newSelectedItem; } } }
public Document() { Preferences = Preferences.LoadPreferences(); FileTreeModel = new FileTreeModel(); FileTreeModel.PropertyChanged += OnTreeNodeSelectionChanged; FileTreeModel.Help = new LocalizedText("FileTreeModelHelp"); Editor = DocNode.Create <TagModelEditor>(); Editor.Path.PropertyChanged += OnPathChanged; IsBatchActive = new DocObj <bool>(); VisibleTab = new DocObj <int>(); PlayerModel = DocNode.Create <PlayerModel>(); Playlist = DocNode.Create <Playlist>(); Playlist.Player = PlayerModel; PlaylistRouter = new PlaylistRouter(); PlaylistRouter.Playlist = Playlist.Items; PlaylistRouter.EditorList = Editor.TagModelList.Items; PlaylistRouter.PlayerModel = PlayerModel; PlaylistRouter.VisibleTab = VisibleTab; PlayerController = DocNode.Create <PlayerController>(); PlayerCommands = new PlayerCommands(PlayerController, PlaylistRouter, PlaylistRouter); IsPlayingUpdater = new PlayerModelIsPlayingUpdater(); IsPlayingUpdater.Model = PlayerModel; IsPlayingUpdater.Items = Editor.TagModelList.Items; FileTreeModel.CommandsProvider += CommandsForNode; try { InitLibrary(); } catch (Exception ex) { CoreUtils.CrashDumpWriter.DumpException(ex, "PureMp3", "*****@*****.**"); } IsWorkerThreadActive = new DocObj <bool>(); IsWorkerThreadActive.Help = new LocalizedText("IsWorkerThreadActive"); //XmlUtils.DumpXml(this.ToXmlDump()); }
/// <summary> /// Get files / folders from directory /// </summary> /// <param name="relativePath"></param> /// <returns></returns> public List <FileTreeModel> PopulateChild(string relativePath) { var physicalPath = HttpContext.Current.Server.MapPath(relativePath); var directory = new DirectoryInfo(physicalPath); var children = directory.GetDirectories().Where(d => !d.Name.Equals(FrameworkConstants.ResizedFolder)) .Select(d => new FileTreeModel { attr = new FileTreeAttribute { Id = string.Format("{0}/{1}", relativePath, d.Name).ToIdString(), Path = string.Format("{0}/{1}", relativePath, d.Name), Rel = "folder" }, data = d.Name, state = "closed" }).ToList(); foreach (var f in directory.GetFiles()) { var t = new FileTreeModel { attr = new FileTreeAttribute { Id = string.Format("{0}/{1}", relativePath, f.Name).ToIdString(), Path = string.Format("{0}/{1}", relativePath, f.Name), Class = "jstree-leaf" }, data = f.Name, state = "open" }; if (f.FullName.IsImage()) { t.attr.Rel = "image"; t.attr.IsImage = true; } else { t.attr.Rel = "file"; } children.Add(t); } return(children); }
/// <summary> /// Initializes a new instance of the <see cref="WarcraftGameContext"/> class. /// </summary> /// <param name="version">The game version of the context.</param> /// <param name="assets">The location of the assets relevant to the context.</param> /// <param name="fileTree">The file tree relevant to the context.</param> /// <exception cref="ArgumentNullException">Thrown if the assets or the file tree are null.</exception> public WarcraftGameContext(WarcraftVersion version, PackageGroup assets, FileTreeModel fileTree) { if (assets == null) { throw new ArgumentNullException(nameof(assets)); } if (fileTree == null) { throw new ArgumentNullException(nameof(fileTree)); } this.Version = version; this.Assets = assets; this.FileTree = fileTree; this.Database = new ClientDatabaseProvider(this.Version, this.Assets); }
/// <summary> /// 文件树选中事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void departmentTree_PreviewMouseUp(object sender, MouseButtonEventArgs e) { try { if (departmentTree.SelectedItem != null) { FileTreeModel selectedTnh = departmentTree.SelectedItem as FileTreeModel; viewModel.Model.SelectFileleName = selectedTnh.FileName; if (selectedTnh.FileType == (int)FieleTypeEnum.Picture) { BitmapImage imagesouce = new BitmapImage(); imagesouce = new BitmapImage(new Uri(selectedTnh.FilePath));//Uri("图片路径") MyImage.Source = imagesouce.Clone(); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private bool DeleteFolder(FileTreeModel treenode, ServiceInfo client) { try { DirectoryNode parentnode = treenode.Node as DirectoryNode; foreach (var child in treenode.Children) { var node = (child.Node as DirectoryNode); if (child.IsChecked) { if (node.IsFile) { client.FileAction(node.Path, true); } else { DeleteFolder(child, client); } } } if (client.FolderEmpty(parentnode.Path)) client.FolderAction(parentnode.Path, true); } catch (Exception e) { MessageBox.Show(e.Message); return false; } return true; }
public ActionResult Index(FormCollection Postpath) { ConvertMD5 objMD5 = new ConvertMD5(); int _contFolder = 0; int _contFile = 0; string realPath; // string path = HttpUtility.UrlDecode(Postpath["dir"]); string path = Postpath["dir"]; string _diretorioBaseUsuario = null; string _usuarioId = PhotoCloud.Models.CryptographyRepository.Descriptografar(HttpContext.Request.Cookies[objMD5.getMD5Hash("UserCookieAuthentication")][objMD5.getMD5Hash("USUIDLOGD")].ToString()); int IDUsuario; if (int.TryParse(_usuarioId, out IDUsuario)) { photocloudEntities ContextoUsuario = new photocloudEntities(); var Consulta = (from usuario in ContextoUsuario.pho_usuarios where usuario.usu_id == IDUsuario select usuario).SingleOrDefault(); _diretorioBaseUsuario = Consulta.usu_diretoriobase; } Encoding iso = Encoding.GetEncoding("ISO-8859-1"); path = HttpUtility.UrlDecode(path, iso); realPath = Server.MapPath("~/pho_fotos/" + _diretorioBaseUsuario + "/" + path); if (System.IO.File.Exists(realPath)) { return(base.File(realPath, "application/octet-stream")); } else if (System.IO.Directory.Exists(realPath)) { try { //cria objeto dirListModel do tipo lista do model DirModel (FileTreeModel) List <DiretorioModel> dirListModel = new List <DiretorioModel>(); IEnumerable <string> dirList = Directory.EnumerateDirectories(realPath); foreach (string dir in dirList) { DirectoryInfo objdiretorio = new DirectoryInfo(dir); DiretorioModel dirModel = new DiretorioModel(); dirModel.DirBase = _diretorioBaseUsuario; dirModel.Dir = "/" + path + Path.GetFileName(dir) + "/"; dirModel.DirName = Path.GetFileName(dir); dirModel.DirAccessed = objdiretorio.LastAccessTime; dirListModel.Add(dirModel); _contFolder++; } List <FileModel> fileListModel = new List <FileModel>(); IEnumerable <string> fileList = Directory.EnumerateFiles(realPath); foreach (string file in fileList) { FileInfo f = new FileInfo(file); FileModel fileModel = new FileModel(); if (f.Extension.ToLower() != "php" && f.Extension.ToLower() != "aspx" && f.Extension.ToLower() != "asp") { if (path == "") { path = "/"; fileModel.FileDirectory = "/"; } else { string _pastaPai = path.Substring(1, path.LastIndexOf("/") - 1); fileModel.FileDirectory = _pastaPai.Substring(_pastaPai.LastIndexOf("/") + 1); } fileModel.FileName = Path.GetFileName(file); fileModel.FileDirectoryName = "pho_fotos/" + _diretorioBaseUsuario + path + Path.GetFileName(file); fileModel.FileAccessed = f.LastAccessTime; fileModel.FileSizeText = (f.Length < 1024) ? f.Length.ToString() + " B" : f.Length / 1024 + " KB"; fileModel.FileExtension = f.Extension.Replace(@".", @"").ToLower(); fileListModel.Add(fileModel); _contFile++; } } if (_contFolder == 0 && _contFile == 0) { if (path == "") { ViewBag.MessageError = "Para iniciar crie suas pastas e faça upload de suas imagens e vídeos."; } else { if (_contFile == 0) { ViewBag.MessageError = "Pasta vazia."; } } return(PartialView()); } FileTreeModel explorerModel = new FileTreeModel(dirListModel, fileListModel); return(PartialView(explorerModel)); } catch (Exception ex) { ViewBag.MessageError = realPath; return(PartialView()); } } else { // ViewBag.MessageError = "O parâmetro de entrada " + path + " não é um arquivo ou diretório válido."; ViewBag.MessageError = realPath + ": não é um arquivo ou diretório válido."; return(PartialView()); // return Content(path + " não é um arquivo ou diretório válido."); } }
private void SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { if (!this.ViewModel.SyncToSolutionExplorer) { return; } FileTreeModel selected = e.NewValue as FileTreeModel; if (selected != null) { UIHierarchy solutionExplorer = (UIHierarchy)IgnorePackage.DTE.Windows.Item(Constants.vsext_wk_SProjectWindow).Object; UIHierarchyItem rootNode = solutionExplorer.UIHierarchyItems.Item(1); Stack <Tuple <UIHierarchyItems, int, bool> > parents = new Stack <Tuple <UIHierarchyItems, int, bool> >(); ProjectItem targetItem = IgnorePackage.DTE.Solution.FindProjectItem(selected.FullPath); if (targetItem == null) { return; } UIHierarchyItems collection = rootNode.UIHierarchyItems; int cursor = 1; bool oldExpand = collection.Expanded; while (cursor <= collection.Count || parents.Count > 0) { while (cursor > collection.Count && parents.Count > 0) { collection.Expanded = oldExpand; Tuple <UIHierarchyItems, int, bool> parent = parents.Pop(); collection = parent.Item1; cursor = parent.Item2; oldExpand = parent.Item3; } if (cursor > collection.Count) { break; } UIHierarchyItem result = collection.Item(cursor); ProjectItem item = result.Object as ProjectItem; if (item == targetItem) { result.Select(vsUISelectionType.vsUISelectionTypeSelect); return; } ++cursor; bool oldOldExpand = oldExpand; oldExpand = result.UIHierarchyItems.Expanded; result.UIHierarchyItems.Expanded = true; if (result.UIHierarchyItems.Count > 0) { parents.Push(Tuple.Create(collection, cursor, oldOldExpand)); collection = result.UIHierarchyItems; cursor = 1; } } } }
private FileTreeModel FormatDirectoryNode(DirectoryNode node, FileTreeModel parent) { FileTreeModel tree = new FileTreeModel(); tree.Node = node; tree.Id = node.Path; tree.Name = node.Name; tree.IsFolder = !node.IsFile; if(node.IsFile) { tree.Icon = GetIconByFileType(node.Extension, false); } else { tree.Icon = GetIconByFileType("folder", false); } tree.Parent = parent; if (node.Children != null) { foreach (var child in node.Children) { tree.Children.Add(FormatDirectoryNode(child, tree)); } } return tree; }
private bool DownloadFolderAction(FileTreeModel treenode, string localpath, ServiceInfo client,bool selectcheck) { try { DirectoryNode parentnode = treenode.Node as DirectoryNode; CreateDirectory(localpath); foreach (var child in treenode.Children) { var node = (child.Node as DirectoryNode); string childpath = localpath + "\\" + node.Name; if ((selectcheck && child.IsChecked) || !selectcheck) { if (node.IsFile) { DownloadFileAction(node.Path, childpath, client); } else { DownloadFolderAction(child, childpath, client, selectcheck); } } } } catch(Exception e) { MessageBox.Show(e.Message); return false; } return true; }
private bool DownloadFolderAction(FileTreeModel treenode, string localpath, ServiceInfo client) { return DownloadFolderAction(treenode, localpath, client, false); }
private FileTreeModel DeepSelectFolder(FileTreeModel node) { var tmp = node.Children.Where(c => c.IsChecked); if (tmp.Count() == 1 && !(tmp as DirectoryNode).IsFile) return DeepSelectFolder(tmp.FirstOrDefault()); else return node; }
public void FileTreeSelected(object obj) { CurrentSelectFileNode = (obj as FileTreeModel); CurrentSelectFile = (CurrentSelectFileNode.Node as DirectoryNode); if (CurrentServer == null) return; using (var client = Client(CurrentServer.EndPoint as EndpointAddress)) { if (client != null) { FileInfo = new ObservableCollection<FileInfoItemModel>(); foreach (var itm in client.GetFileInfo(CurrentSelectFile.Path, CurrentSelectFile.IsFile)) { FileInfo.Add(new FileInfoItemModel(itm.Name,itm.Value)); }//.Items; } } }
public ManualsViewModel() { ManualsLogic logic = new ManualsLogic(Settings.ManualFolder); Tree = logic.Tree; }