Example #1
0
        private List <string> getFtpDirectoryListing(firedumpdbDataSet.backup_locationsRow location, string path)
        {
            List <string>        filesindir = new List <string>();
            FTPCredentialsConfig ftpConfig  = new FTPCredentialsConfig();

            ftpConfig.id       = location.id;
            ftpConfig.host     = location.host;
            ftpConfig.port     = (int)location.port;
            ftpConfig.username = location.username;
            ftpConfig.password = location.password;
            if (location.usesftp == 1)
            {
                ftpConfig.useSFTP = true;
                ftpConfig.SshHostKeyFingerprint = location.ssh_key_fingerprint;
            }
            if (!string.IsNullOrEmpty(location.ssh_key))
            {
                ftpConfig.usePrivateKey  = true;
                ftpConfig.privateKeyPath = location.ssh_key;
            }
            FTPUtils ftputils = new FTPUtils(ftpConfig);

            ftputils.startSession();
            List <WinSCP.RemoteFileInfo> dirList = ftputils.getDirectoryListing(path, false, false);

            ftputils.disposeSession();
            foreach (WinSCP.RemoteFileInfo info in dirList)
            {
                filesindir.Add(info.FullName);
            }
            return(filesindir);
        }
Example #2
0
        public DropboxForm(LocationSwitchboard locswitch, bool isedit, firedumpdbDataSet.backup_locationsRow row)
        {
            InitializeComponent();
            isEditor       = isedit;
            this.locswitch = locswitch;
            this.row       = row;

            Console.WriteLine(row.access_token);
            tbtoken.Text    = row.access_token;
            tbfilename.Text = row.filename;
            tbsavename.Text = row.name;
            path            = row.path;
            init();

            if (String.IsNullOrEmpty(tbtoken.Text))
            {
                MessageBox.Show("Must fill token field, visit https://www.dropbox.com/developers/apps to create app and get the token");
                return;
            }
            //save token

            if (!backgroundWorker1.IsBusy)
            {
                this.UseWaitCursor = true;
                token = tbtoken.Text;
                backgroundWorker1.RunWorkerAsync();
            }
        }
 internal void cancelSaveLocation(firedumpdbDataSet.backup_locationsRow tag)
 {
     if (locations.Contains((Int32)tag.id))
     {
         locations.Remove((Int32)tag.id);
         currentProgress += 100;
     }
 }
Example #4
0
        private void addToGridView(object tag)
        {
            DataGridViewRow dataRow = (DataGridViewRow)dataGridView1.Rows[0].Clone();

            dataRow.Tag = tag;
            firedumpdbDataSet.backup_locationsRow row = (firedumpdbDataSet.backup_locationsRow)tag;
            dataRow.Cells[0].Value = row.name;
            dataGridView1.Invoke((MethodInvoker) delegate()
            {
                dataGridView1.Rows.Add(dataRow);
            });
        }
Example #5
0
        public void add(object tag)
        {
            firedumpdbDataSet.backup_locationsRow row = (firedumpdbDataSet.backup_locationsRow)tag;
            ProgressItemLoc progItemloc = new ProgressItemLoc();

            progItemloc.Tag = tag;
            progItemloc.initProgressBar();
            progItemloc.setLabelText(row.name);
            progItemloc.Pos      = pos;
            progItemloc.Location = new Point(0, heigth);
            heigth += 30;
            pos++;
            panel1.Controls.Add(progItemloc);
        }
Example #6
0
        public void addToLbSaveLocation(BackupLocation loc)
        {
            firedumpdbDataSet.backup_locationsRow row = (firedumpdbDataSet.backup_locationsRow)loc.Tag;
            //row.service_type 0=local,1=ftp,2=dropbox,3=googledrive
            ListViewItem item = new ListViewItem(row.name, (int)row.service_type);

            item.SubItems.Add(loc.path);
            item.Tag = (firedumpdbDataSet.backup_locationsRow)loc.Tag;
            if (lbSaveLocations.Items.Contains(findItemSaveLoc(loc)))
            {
                return;
            }
            lbSaveLocations.Items.Add(item);
        }
Example #7
0
 public void updateProgress(int progress, string locationName)
 {
     for (int i = 0; i < panel1.Controls.Count; i++)
     {
         if (panel1.Controls[i] is ProgressItemLoc)
         {
             ProgressItemLoc loc = (ProgressItemLoc)panel1.Controls[i];
             firedumpdbDataSet.backup_locationsRow row = (firedumpdbDataSet.backup_locationsRow)loc.Tag;
             if (row.name == locationName)
             {
                 ((ProgressItemLoc)panel1.Controls[i]).updateProgress(progress);
             }
         }
     }
 }
Example #8
0
 private void updateGridView(int progress)
 {
     for (int i = 0; i < dataGridView1.RowCount; i++)
     {
         firedumpdbDataSet.backup_locationsRow row = (firedumpdbDataSet.backup_locationsRow)dataGridView1.Rows[i].Tag;
         if (row.name == locationName)
         {
             dataGridView1.Invoke((MethodInvoker) delegate()
             {
                 dataGridView1.Rows[i].Cells[1].Value = progress + "% ";
             });
             break;
         }
     }
 }
Example #9
0
        private firedumpdbDataSet.backup_locationsRow findRow(int id)
        {
            int  i         = 0;
            bool foundflag = false;

            firedumpdbDataSet.backup_locationsRow row = firedumpdbDataSet.backup_locations[0];
            while (!foundflag && i < firedumpdbDataSet.backup_locations.Count)
            {
                firedumpdbDataSet.backup_locationsRow temprow = firedumpdbDataSet.backup_locations[i];
                if (temprow.id == id)
                {
                    row       = temprow;
                    foundflag = true;
                }
                i++;
            }
            return(row);
        }
Example #10
0
 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     //click on the cancel button
     if (e.ColumnIndex == 2)
     {
         if ((string)dataGridView1.Rows[e.RowIndex].Cells[1].Value != "Cancelled")
         {
             firedumpdbDataSet.backup_locationsRow row = (firedumpdbDataSet.backup_locationsRow)dataGridView1.Rows[e.RowIndex].Tag;
             if (row != null)
             {
                 if (!adapterLocation.isLocationFinished(row))
                 {
                     adapterLocation.cancelSaveLocation(row);
                     dataGridView1.Rows[e.RowIndex].Cells[1].Value = "Cancelled";
                 }
             }
             dataGridView1.Rows[e.RowIndex].Cells[1].Value = "Cancelled";
         }
     }
 }
Example #11
0
        private ListViewItem findItemSaveLoc(BackupLocation loc)
        {
            ListViewItem item      = new ListViewItem();
            int          i         = 0;
            bool         foundflag = false;


            while (!foundflag && i < lbSaveLocations.Items.Count)
            {
                firedumpdbDataSet.backup_locationsRow tag = (firedumpdbDataSet.backup_locationsRow)lbSaveLocations.Items[i].Tag;
                tag.BeginEdit();
                if (tag.id == loc.id)
                {
                    item      = lbSaveLocations.Items[i];
                    foundflag = true;
                }
                i++;
                tag.CancelEdit();
            }
            return(item);
        }
Example #12
0
        public void addToLbSaveLocation(BackupLocation loc)
        {
            firedumpdbDataSet.backup_locationsRow row = (firedumpdbDataSet.backup_locationsRow)loc.Tag;
            int imageindex;

            switch (row.service_type)
            {
            case 0:     //local
                imageindex = 0;
                break;

            case 1:     //ftp
                imageindex = 1;
                break;

            case 2:     //dropbox
                imageindex = 2;
                break;

            case 3:     //google drive
                imageindex = 3;
                break;

            default:
                imageindex = 0;
                break;
            }
            ListViewItem item = new ListViewItem(row.name, imageindex);

            item.SubItems.Add(loc.path);
            item.Tag = (firedumpdbDataSet.backup_locationsRow)loc.Tag;
            ListViewItem saveItem = findItemSaveLoc(loc);

            if (lbSaveLocations.Items.Contains(saveItem))
            {
                return;
            }
            lbSaveLocations.Items.Add(item);
        }
 internal bool isLocationRunning(firedumpdbDataSet.backup_locationsRow row)
 {
     return(adapter.isLocationRunning(row.id));
 }
 internal bool isLocationFinished(firedumpdbDataSet.backup_locationsRow row)
 {
     return(!locations.Contains((int)row.id) && !adapter.isLocationRunning((int)row.id));
 }
Example #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        /// <param name="locid">-1 for local path or the id of the save location</param>
        /// <returns>List of full paths for all files in the import chain in order</returns>
        public List <string> calculateChain(string path, int locid)
        {
            List <string> filesChain = new List <string>();

            try
            {
                string[] tmp       = StringUtils.splitPath(path);
                string   initpath  = tmp[0];
                string   initfname = tmp[1];

                if (initfname.Contains("_FB_")) //is full backup
                {
                    filesChain.Add(path);
                    return(filesChain);
                }

                if (!initfname.Contains("_FB_") && !initfname.Contains("_IB_") && !initfname.Contains("_IDB_")) // file has no incremental format
                {
                    filesChain.Add(path);
                    return(filesChain);
                }

                string   initfnamecut = tmp[1].Split('_')[0];
                string[] filesindir   = new string[1];
                if (locid != -1)
                {
                    firedumpdbDataSetTableAdapters.backup_locationsTableAdapter adapter = new firedumpdbDataSetTableAdapters.backup_locationsTableAdapter();
                    firedumpdbDataSet.backup_locationsRow location = adapter.GetDataByID(locid)[0];
                    switch (location.service_type)
                    {
                    case 0:     //Local
                        filesindir = Directory.GetFiles(initpath);
                        break;

                    case 1:     //FTP
                        filesindir = getFtpDirectoryListing(location, initpath).ToArray();
                        break;

                    case 2:     //dropbox
                        break;

                    case 3:     //google drive
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    filesindir = Directory.GetFiles(initpath);
                }
                List <string> fnames = new List <string>();
                foreach (string fpath in filesindir)
                {
                    fnames.Add(fpath.Replace(initpath, ""));
                }
                List <string> bpFnames = new List <string>();
                foreach (string fname in fnames)
                {
                    if (fname.Contains(initfnamecut) && fname.Contains("_"))
                    {
                        bpFnames.Add(fname);
                    }
                }

                if (bpFnames.Count() < 2)
                {
                    filesChain.Add("Error:No previous files in chain for incremental backup.");
                    return(filesChain);
                }

                string[] splitinitbpindexes = initfname.Split('_')[2].Split('.'); //0.0.0

                int indexC = Convert.ToInt32(splitinitbpindexes[2]);

                List <int> chainedIndexes = new List <int>();
                int        idx            = StringUtils.indexOfContained(bpFnames, splitinitbpindexes[0] + "." + "0.0");
                if (idx != -1)
                {
                    filesChain.Add(initpath + bpFnames[idx]);
                }
                else
                {
                    filesChain = new List <string>();
                    filesChain.Add("Error:Missing file with version: " + splitinitbpindexes[0] + ".0.0" + " from the incremental chain");
                    return(filesChain);
                }
                if (indexC > 0)
                {
                    for (int i = 0; i <= indexC; i++)
                    {
                        idx = StringUtils.indexOfContained(bpFnames, splitinitbpindexes[0] + "." + splitinitbpindexes[1] + "." + i);
                        if (idx != -1)
                        {
                            filesChain.Add(initpath + bpFnames[idx]);
                        }
                        else
                        {
                            filesChain = new List <string>();
                            filesChain.Add("Error:Missing file with version: " + splitinitbpindexes[0] + "." + splitinitbpindexes[1] + "." + i + " from the incremental chain");
                            return(filesChain);
                        }
                    }
                }
                else
                {
                    filesChain.Add(path);
                }
            }
            catch (Exception ex)
            {
                filesChain.Add("Error");
                filesChain.Add("Excption calculating file chain: " + ex.Message);
                Console.WriteLine(ex.StackTrace);
            }

            return(filesChain);
        }