// Create the folder in the DB private EfsEntry CreateFolder(int idParent) { EfsEntry ne; using (var trans = sess.BeginTransaction()) { string strNameBase = "New folder"; string strName = strNameBase; if (EFS.FindFile(rs, idParent, strName).HasValue) { for (int i = 2; true; i++) { strName = String.Format("{0} {1}", strNameBase, i); if (!EFS.FindFile(rs, idParent, strName).HasValue) { break; } } } ne = EFS.CreateFolder(rs.cursor, idParent, strName); trans.Commit(); } return(ne); }
private void tree_BeforeExpand(object sender, TreeViewCancelEventArgs e) { var nodes = e.Node.Nodes; if (!isFakeNode(nodes[0])) { return; } nodes.Clear(); int idParent = (int)e.Node.Tag; using (var trans = sess.BeginTransaction()) foreach (var fsEntry in EFS.ListChildrenFolders(rs, idParent)) { var nodeNewReal = newNode(fsEntry); nodes.Add(nodeNewReal); nodeNewReal.Nodes.Add(getFakeNode()); } if (0 == nodes.Count) { e.Cancel = true; } }
public ActionResult CheckDetails(string id) { using (var ECheck = new EFS(_applicationServicesSetup)) { return(Json(ECheck.getMoneyCodeDetails(id), JsonRequestBehavior.AllowGet)); } }
public long Write(Stream sInput, string pathDestFile) { using (var sOutput = new FileStream(pathDestFile, FileMode.CreateNew, FileAccess.Write)) { EFS.CopyStream(sInput, sOutput); return(sOutput.Length); } }
public long Read(Stream sOutput, string pathSourceFile) { using (var sInput = new FileStream(pathSourceFile, FileMode.Open, FileAccess.Read)) { EFS.CopyStream(sInput, sOutput); return(sInput.Length); } }
// Rename the file in the DB. void RenameFile(int idFile, string strNewName) { using (var trans = sess.BeginTransaction()) { EFS.MoveFile(rs, idFile, EFS.GetParent(rs, idFile), strNewName); trans.Commit(); } }
void DisplayFolder(int idFolder) { list.Items.Clear(); using (var trans = sess.BeginTransaction()) foreach (var e in EFS.ListChildren(rs, idFolder)) { list.Items.Add(newItem(e)); } }
private void pasteToolStripMenuItem_Click(object sender, EventArgs e) { if (!Clipboard.ContainsFileDropList()) { return; } int?idWhere = this.idCurrentFolder; if (!idWhere.HasValue) { return; } int nFiles = 0; long nBytes = 0; Cursor.Current = Cursors.WaitCursor; Stopwatch swAll = new Stopwatch(); List <EfsEntry> newEntries = new List <EfsEntry>(); swAll.Start(); using (var trans = sess.BeginTransaction()) { foreach (string strPath in Clipboard.GetFileDropList().Cast <string>()) { EfsEntry ne = null; if (File.Exists(strPath)) // Single file { nFiles++; long len; ne = EFS.AddFile(rs, idWhere.Value, fileIo, strPath, out len); nBytes += len; trans.LazyCommitAndReopen(); } else if (Directory.Exists(strPath)) { ne = AddFolder(trans, idWhere.Value, strPath, ref nFiles, ref nBytes); } if (null != ne) { newEntries.Add(ne); } } trans.Commit(); swAll.Stop(); } Cursor.Current = Cursors.Default; newEntries.ForEach(ne => this.AddUiItem(ne)); string msg = FormatCopyRateSummary(nFiles, nBytes, swAll.Elapsed); MessageBox.Show(this, msg, "Paste Complete", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { using (var trans = sess.BeginTransaction()) { foreach (var idFile in getSelectedItems()) { EFS.DeleteFile(rs, idFile); RemoveUiItem(idFile); } trans.Commit(); } }
/// <summary>Copy a file from EFS to the specified System.Stream.</summary> /// <remarks>Unlike the rest of the code in this class, this method is safe to call from any thread.</remarks> /// <param name="sOutput"></param> /// <param name="idFile"></param> void CopyFileToStream(Stream sOutput, int idFile) { using (var s = pool.GetSession()) using (var trans = s.BeginTransaction()) { var e = EFS.byId(rs, idFile); if (null == e) { throw new FileNotFoundException(); } using (var sInput = e.data.Read(rs.cursor)) EFS.CopyStream(sInput, sOutput); } }
// This one is the real. public Form1(SessionPool _pool) { InitializeComponent(); pool = _pool; sess = pool.GetSession(); rs = sess.Recordset <EfsEntry>(); EFS.Initialize(rs); fileIo = new FileIoThread(); // fileIo = new TrivialFileIo(); InitFoldersView(); }
EfsEntry AddFolder(iSerializerTransaction trans, int idParent, string strPath, ref int nFiles, ref long cbTotalBytes) { string name = Path.GetFileName(strPath); int? idFile = EFS.FindFile(rs, idParent, name); if (idFile.HasValue) { EFS.DeleteFile(rs, idFile.Value); trans.LazyCommitAndReopen(); } EfsEntry res = EFS.CreateFolder(rs.cursor, idParent, name); idParent = res.id; // Inspired by http://stackoverflow.com/questions/2085452/fast-lowlevel-method-to-recursively-process-files-in-folders/2085872#2085872 var pending = new Queue <Tuple <string, int> >(); pending.Enqueue(Tuple.Create(strPath, idParent)); string[] tmp; while (pending.Count > 0) { Tuple <string, int> p = pending.Dequeue(); tmp = Directory.GetDirectories(p.Item1); foreach (var childFolder in tmp) { name = Path.GetFileName(childFolder); idParent = EFS.CreateFolder(rs.cursor, p.Item2, name).id; pending.Enqueue(Tuple.Create(childFolder, idParent)); trans.LazyCommitAndReopen(); } tmp = Directory.GetFiles(p.Item1); foreach (var filePath in tmp) { nFiles++; long len; EFS.AddFile(rs, p.Item2, fileIo, filePath, out len); cbTotalBytes += len; trans.LazyCommitAndReopen(); } } return(res); }
/// <summary>Iterate over the selected files and folders.</summary> /// <param name="itemIds">Selected item IDs.</param> /// <param name="actFile">Will be called for every file in the selection, including the files in a sumbolders.</param> /// <param name="actFolder">Will be called for every folder in the selection.</param> void IterateSelection(IEnumerable <int> itemIds, Action <EfsEntry, string> actFile, Action <EfsEntry, string> actFolder) { foreach (int idFile in itemIds) { EfsEntry ee = EFS.byId(rs, idFile); if (ee.isDirectory) { actFolder(ee, ee.name); var pending = new Queue <Tuple <string, int> >(); pending.Enqueue(Tuple.Create(ee.name, ee.id)); while (pending.Count > 0) { var p = pending.Dequeue(); foreach (EfsEntry eChild in EFS.ListChildren(rs, p.Item2)) { string path = Path.Combine(p.Item1, eChild.name); if (eChild.isDirectory) { pending.Enqueue(Tuple.Create(path, eChild.id)); actFolder(eChild, path); } else { actFile(eChild, path); } } } } else { actFile(ee, ee.name); } } }
private void list_MouseDoubleClick(object sender, MouseEventArgs e) { var fi = list.FocusedItem; if (null == fi || null == fi.Tag) { return; } int idFile = (int)(fi.Tag); EfsEntry eFile = EFS.byId(rs, idFile); if (eFile.isDirectory) { if (!nodeCurrent.IsExpanded) { nodeCurrent.Expand(); } tree.SelectedNode = nodeCurrent.Nodes.All() .Where(n => n.Tag != null && (int)n.Tag == idFile) .FirstOrDefault(); } }
public Message() { SFS = new SFS(); FcsCoverage = new FCSCoverage(); EFS = new EFS(); }