Exemple #1
0
        public int CopyAll(DirectoryInfo source, DirectoryInfo target)
        {
            try {
                using (new NetworkConnection(@ScannerLocation(_branch), username, password))
                {
                    Directory.CreateDirectory(target.FullName);
                    foreach (FileInfo fi in source.GetFiles())
                    {
                        Console.WriteLine(@"Copying {0}\{1}", target.FullName, fi.Name);

                        fi.MoveTo(Path.Combine(target.FullName, fi.Name));
                        try
                        {
                            Efiling table = new Efiling();
                            table.Created         = DateTime.Now;
                            table.Directory       = target.FullName.ToString();
                            table.FilePassword    = (_HasPassword) ? System.Web.Security.Membership.GeneratePassword(12, 2) : null; //password
                            table.PIN             = _pin;
                            table.FileName        = fi.Name;
                            db.Entry(table).State = System.Data.Entity.EntityState.Added;

                            //protect with password
                            //https://www.nuget.org/packages/Syncfusion.Pdf.WinForms
                            //https://www.syncfusion.com/kb/9503/how-to-protect-a-pdf-with-the-password-using-c-and-vb-net

                            Log logs = new Log();
                            logs.Pin              = _pin;
                            logs.Location         = Path.Combine(target.FullName, fi.Name);
                            logs.OriginalLocation = fi.FullName;
                            logs.Action           = "Copied";
                            logs.Created          = DateTime.Now;
                            db.Entry(logs).State  = System.Data.Entity.EntityState.Added;
                            db.SaveChanges();
                        }
                        catch (Exception e) {
                            continue;
                        }
                    }

                    // Copy each subdirectory using recursion.
                    foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
                    {
                        DirectoryInfo nextTargetSubDir =
                            target.CreateSubdirectory(diSourceSubDir.Name);
                        CopyAll(diSourceSubDir, nextTargetSubDir);
                    }
                }
            } catch (Exception e) {
                return(1);
            }

            return(0);
        }
Exemple #2
0
        //move folder from original destination to new destination
        public bool MoveBackupFolder(string pin, string ReplaceWith, string branch_id)
        {
            try
            {
                string _origin         = (Math.Floor(Convert.ToInt32(pin) / 5000.0) * 5000).ToString();         // GetRange
                string _ReplaceWith    = (Math.Floor(Convert.ToInt32(ReplaceWith) / 5000.0) * 5000).ToString(); // GetRange
                string _originFullPath = Path.Combine(@BackupLocation(branch_id), _origin.PadLeft(6, '0'), pin);
                string _targetFullPath = Path.Combine(@BackupLocation(branch_id), _ReplaceWith.PadLeft(6, '0'), ReplaceWith);

                //initialize
                _pin         = ReplaceWith;
                _branch      = branch_id;
                _HasPassword = false;

                var diSource = new DirectoryInfo(@_originFullPath);
                var diTarget = new DirectoryInfo(@_targetFullPath);

                Efiling table = new Efiling();
                table.Created         = DateTime.Now;
                table.Directory       = _targetFullPath;
                table.FilePassword    = (_HasPassword) ?  System.Web.Security.Membership.GeneratePassword(12, 4) : null;
                table.PIN             = ReplaceWith;
                table.FileName        = "*";
                db.Entry(table).State = System.Data.Entity.EntityState.Added;

                //Protect with password
                //https://www.nuget.org/packages/Syncfusion.Pdf.WinForms
                //https://www.syncfusion.com/kb/9503/how-to-protect-a-pdf-with-the-password-using-c-and-vb-net

                // If Success. Save the Changes.
                db.SaveChanges();

                Log logs = new Log();
                logs.Pin              = pin;
                logs.Location         = _targetFullPath;
                logs.OriginalLocation = _originFullPath;
                logs.Action           = "MoveFolder";
                logs.Created          = DateTime.Now;
                db.Entry(logs).State  = System.Data.Entity.EntityState.Added;
                db.SaveChanges();

                CopyAll(diSource, diTarget);

                return(true);
            }
            catch (Exception e) {
                Console.Write(e.Message.ToString());
                return(false);
            }
        }
Exemple #3
0
        public bool MoveBackupFile(string _originPin, string _originFileName, string _targetPin, string _targetFileName, string branch_id)
        {
            try
            {
                string _origin         = (Math.Floor(Convert.ToInt32(_originPin) / 5000.0) * 5000).ToString(); // GetRange
                string _ReplaceWith    = (Math.Floor(Convert.ToInt32(_targetPin) / 5000.0) * 5000).ToString(); // GetRange
                string _originFullPath = Path.Combine(BackupLocation(branch_id), _origin.PadLeft(6, '0'), _originFileName);
                string _targetFullPath = Path.Combine(BackupLocation(branch_id), _ReplaceWith.PadLeft(6, '0'), _targetPin, _targetFileName);
                // To move a file or folder to a new location:
                // System.IO.File.Move(_originFullPath, _targetFullPath);
                Efiling table = new Efiling();
                table.Created         = DateTime.Now;
                table.Directory       = _targetFullPath;
                table.FilePassword    = (_HasPassword) ? System.Web.Security.Membership.GeneratePassword(12, 4) : null;
                table.PIN             = _targetPin;
                table.FileName        = _targetFileName;
                db.Entry(table).State = System.Data.Entity.EntityState.Added;

                Log logs = new Log();
                logs.Pin              = _originPin;
                logs.Location         = _targetFullPath;
                logs.OriginalLocation = _originFullPath;
                logs.Action           = "MoveFile";
                logs.Created          = DateTime.Now;
                db.Entry(logs).State  = System.Data.Entity.EntityState.Added;
                db.SaveChanges();

                System.IO.File.Move(_originFullPath, _targetFullPath);

                return(true);
            }
            catch (Exception e)
            {
                Console.Write(e.Message.ToString());
                return(false);
            }
        }