Exemple #1
0
        // 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);
        }
Exemple #2
0
        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);
        }