private void openWithExploererTsmi_Click(object sender, System.EventArgs e) { NavigatePanelNode node = treeView.SelectedNode as NavigatePanelNode; if (node == null) { return; } if (node is FolderNode) { Data.Folder folder = (node as FolderNode).Folder; if (folder == null || folder.Project == null) { return; } System.Diagnostics.Process.Start("EXPLORER.EXE", folder.Project.GetAbsolutePath(folder.RelativePath)); } else if (node is FileNode) { Data.File file = (node as FileNode).FileItem; if (file == null || file.Project == null) { return; } System.Diagnostics.Process.Start("EXPLORER.EXE", "/select,\"" + file.Project.GetAbsolutePath(file.RelativePath) + "\""); } }
public UIFileDisplay(Data.File file) { File = file; FileInfo = File.FileInfo; if (file.IsFolder) { Glyph = FolderGlyph; } else { string ext = System.IO.Path.GetExtension(file.Name).ToLower().TrimStart('.'); FileType type = FileType.FileTypes.FirstOrDefault(p => p.Extensions.Contains(ext)); if (type != null) { Glyph = type.Glyph; } } if (DebugSwitch.OnDisplayPropertyChanged) { PropertyChanged += (p1, p2) => { System.Diagnostics.Debug.WriteLine("Display Prop Changed: " + p2.PropertyName); }; } }
public FileNode(Data.File file) : base(file) { if (FileNodeCreated != null) { FileNodeCreated(this); } }
public void TestNameWithoutPathWithNullName() { Data.File file = new Data.File { Name = null }; Assert.AreEqual(null, file.NameWithoutPath); }
public void TestNameWithoutPathWithEmptyName() { Data.File file = new Data.File { Name = string.Empty }; Assert.AreEqual(string.Empty, file.NameWithoutPath); }
public void TestFileProgressWithSizeOfZero() { Data.File file = new Data.File { Downloaded = 345, Size = 0 }; int progress = file.Progress; Assert.AreEqual(0, progress); }
public void TestNameWithoutPath() { Data.File file = new Data.File { Name = "/azerty/qwerty/file.txt" }; const string expected = "file.txt"; Assert.AreEqual(expected, file.NameWithoutPath); }
public void TestFileProgress() { const long d = 354; const long s = 424; Data.File file = new Data.File {Downloaded = d, Size = s}; int progress = file.Progress; const double x = d / (double)s; const int expected = (int)(x * 100); Assert.AreEqual(expected, progress); }
private bool Callback(double per, Data.File file) { if (stopping) { Dispatcher.Invoke(() => { working = false; Close(); }); return(false); } Percentage = per; Message = $"正在处理({100 * per:N2}%):" + file.GetAbsolutePath(); return(true); }
public void TestFileProgress() { const long d = 354; const long s = 424; Data.File file = new Data.File { Downloaded = d, Size = s }; int progress = file.Progress; const double x = d / (double)s; const int expected = (int)(x * 100); Assert.AreEqual(expected, progress); }
public static ReturnObject Upload(HttpContext context, string parent_type, long parent_id) { var file = context.Request.Files["file"]; string path = context.Server.MapPath("~/upload/" + parent_type + "/" + parent_id.ToString() + "/"); if( !Directory.Exists(path) ) Directory.CreateDirectory(path); string ext = Path.GetExtension(file.FileName); string fn = Guid.NewGuid().ToString()+ext; while( File.Exists(Path.Combine(path,fn)) ) fn = Guid.NewGuid().ToString() + ext; fn = Path.Combine(path,fn); file.SaveAs( fn ); var item = new Data.File(); item.ParentType = parent_type; item.ParentID = parent_id; item.Path = fn; item.Name = file.FileName; item.ContentType = file.ContentType; item.Save(); var ret = new ReturnObject() { Result = MapPathReverse(fn), Growl = new ReturnGrowlObject() { Type = "default", Vars = new ReturnGrowlVarsObject() { text = "You have successfully uploaded a file.", title = "File Uploaded" } } }; return ret; }
private void fsTimer_Tick(object sender, System.EventArgs e) { lock (fileSystemEvents) { while (fileSystemEvents.Count != 0) { System.IO.FileSystemEventArgs fs = fileSystemEvents.Values.FirstOrDefault(); fileSystemEvents.Remove(fs.FullPath); { Controller.AppendLog(fs.Name + " changed"); string relativePath = GetRelativePath(fs.FullPath); Data.File file = GetItem(relativePath) as Data.File; if (file == null) { return; } Data.ITextFile textFile = file as Data.ITextFile; if (textFile == null) { return; } if (textFile.Dirty) { Controller.AppendLog(fs.FullPath + " conflict!"); } else { DateTime lastWriteTime = System.IO.File.GetLastWriteTime(fs.FullPath); if (textFile.LoadedFileLastWriteTime != lastWriteTime) { textFile.LoadFormFile(); textFile.Update(); } } } } // fsTimer.Enabled = false; } }
/// <summary> /// Creates the <see cref="File"/> base on <see cref="FileInfo"/>. /// </summary> /// <param name="info">The file info.</param> /// <param name="parent">The parent</param> /// <returns>The result file.</returns> /// <remarks> /// It can't be merged with <see cref="DirectoryExtensions.ToDirectory"/>, /// because <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> have different hierarchy. /// </remarks> public static Data.File ToFile(this FileInfo info, Data.Directory parent) { var file = new Data.File { Name = info.FullName, Parent = parent, CreationDate = info.CreationTime, LastAccessDate = info.LastAccessTime, ModificationDate = info.LastWriteTime, Size = info.Length }; var access = info.GetAccessControl(); try { file.Owner = access.GetOwner(typeof(System.Security.Principal.NTAccount)).Value; } catch (Exception) { file.Owner = "N/A"; } file.Attributes = EnumUtil.GetNameValue <FileAttributes>().Where(o => (info.Attributes & o.Value) > 0).Select(o => o.Key).ToArray(); file.UserRights = new[] { "N/A" }; var currentUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name; foreach (FileSystemAccessRule rule in access.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount))) { if (rule.IdentityReference.Value == currentUser) { file.UserRights = EnumUtil.GetNameValue <FileSystemRights>().Where(o => (rule.FileSystemRights & o.Value) > 0).Select(o => o.Key).ToArray(); break; } } return(file); }
protected void btnAddFile_Click(object sender, EventArgs evArgs) { Data.File f = new Data.File(); f.name = fileName.Text; if (String.IsNullOrWhiteSpace(f.name)) f.name = "New file"; f.date_created = DateTime.Now; f.owner = Data.UserManager.GetUser().id; f.is_public = f.name.Length % 2; if (null != fileAdd.PostedFile) { try { f.filename = fileAdd.PostedFile.FileName; Data.FileManager.AddFile(f); } catch (Exception e) { } } }
public void TestNameWithoutPathWithEmptyName() { Data.File file = new Data.File {Name = string.Empty}; Assert.AreEqual(string.Empty, file.NameWithoutPath); }
private void ShowProgressMessage(Data.File file) { Dispatcher.Invoke(() => MainWindow.Current.SetProcessRingMessage( "正在导出" + Environment.NewLine + Path.Combine(file.Dir, file.Name))); }
public void TestFileProgressWithSizeOfZero() { Data.File file = new Data.File {Downloaded = 345, Size = 0}; int progress = file.Progress; Assert.AreEqual(0, progress); }
public void TestNameWithoutPath() { Data.File file = new Data.File {Name = "/azerty/qwerty/file.txt"}; const string expected = "file.txt"; Assert.AreEqual(expected, file.NameWithoutPath); }
public void TestNameWithoutPathWithNullName() { Data.File file = new Data.File {Name = null}; Assert.AreEqual(null, file.NameWithoutPath); }