Ejemplo n.º 1
0
        private void AddFolder(String root, IAddDiskProgress p, bool isRoot, ref long files, bool count, OleDbTransaction sqlTran, long parent, long track)
        {
            DirectoryInfo di = new DirectoryInfo(root);

            if (false == isRoot)
            {
                if (false == count)
                {
                    parent = AddFolder(track, parent, di, sqlTran);
                }
            }
            else
            {
                parent = -1;
            }

            FileInfo[] fiArr = di.GetFiles();

            if (true == count)
            {
                files += fiArr.Length;
            }
            else
            {
                foreach (FileInfo fi in fiArr)
                {
                    AddFile(track, parent, fi, sqlTran);
                    files += 1;
                    p.Progress(files);
                }
            }

            DirectoryInfo[] diArr = di.GetDirectories();

            foreach (DirectoryInfo dri in diArr)
            {
                if (true == count)
                {
                    files++;
                    AddFolder(root + "/" + dri.Name, p, false, ref files, true, null, 0, 0);
                }
                else
                {
                    AddFolder(root + "/" + dri.Name, p, false, ref files, false, sqlTran, parent, track);
                    files += 1;
                    p.Progress(files);
                }
            }
        }
Ejemplo n.º 2
0
Archivo: Box.cs Proyecto: drme/disks-db
        public Disk AddDisk(String name, DiskType type, Image image, string driveLetter, IAddDiskProgress prog, bool addFiles)
        {
            CheckDeleted();

            Disk d = this.idb.AddDisk(name, type, image, this, driveLetter, prog, addFiles);

            if (d != null)
            {
                OnChildAdded(d);
            }

            return d;
        }
Ejemplo n.º 3
0
        public Disk AddDisk(String name, DiskType type, Image image, Box box, String driveLetter, IAddDiskProgress prog, bool addFiles)
        {
            try
            {
                long files = 0;

                if (true == addFiles)
                {
                    AddFolder(driveLetter, prog, true, ref files, true, null, 0, 0);
                }

                prog.Total(files);

                using (OleDbConnection sqlCon = new OleDbConnection(this.DBConString))
                {
                    sqlCon.Open();
                    OleDbTransaction sqlTran = sqlCon.BeginTransaction();

                    OleDbCommand sqlCmd = new OleDbCommand("INSERT INTO [Disks] ([DiskImage], [CDBox], [Name], [Type], [Description]) VALUES(?, ?, ?, ?, ?)", sqlCon, sqlTran);

                    sqlCmd.Parameters.AddWithValue("@image", image.Id);
                    sqlCmd.Parameters.AddWithValue("@box", box.Id);
                    sqlCmd.Parameters.AddWithValue("@name", name);
                    sqlCmd.Parameters.AddWithValue("@type", type.Id);
                    sqlCmd.Parameters.AddWithValue("@desc", "/* TBD */");

                    sqlCmd.ExecuteNonQuery();

                    OleDbCommand oleCmdIdentity = new OleDbCommand("SELECT @@IDENTITY", sqlCon, sqlTran);

                    int rez = (int)oleCmdIdentity.ExecuteScalar();

                    if (true == addFiles)
                    {
                        long diskId = rez;

                        files = 0;

                        prog.Started();

                        AddFolder(driveLetter, prog, true, ref files, false, sqlTran, -1, diskId);
                    }

                    sqlTran.Commit();
                    prog.Finished();

                    return new Disk(this, rez, name, image, type, box);
                }
            }
            catch (Exception ex)
            {
                prog.Failed(ex.Message);
            }

            return null;
        }