示例#1
0
        /******************************\
         * Fill FileExplorer ListView *
        \******************************/
        private void FillFileExplorerListView()
        {
            DataSet fileDataSet = new DataSet(); ; // result of DB request (get download dates).

            /* If not parent directory, add "Parent directory" */
            if (_CurrentDirectory.Get_IsRoot() == false)
            {
                ListViewItem item = new ListViewItem();

                item.SubItems[0].Text = "Parent Directory";
                item.SubItems.Add("-");
                item.SubItems.Add("-");
                item.SubItems.Add("-");
                item.ImageIndex = 2;

                FileExplorerListView.Items.AddRange(new ListViewItem[] { item });
            }

            /* Fill Directories */
            foreach (Directory dir in _CurrentDirectory.Get_FoldersList())
            {
                ListViewItem item = new ListViewItem();

                item.SubItems[0].Text = dir.Get_Name().Replace("%20"," ");
                item.SubItems.Add("-");
                item.SubItems.Add("-");
                item.SubItems.Add("-");
                item.ImageIndex = 1;

                FileExplorerListView.Items.AddRange(new ListViewItem[] { item });
            }

            /* Get eventual modification date of files */
            try
            {
                FTPWebService.ftpSoapClient service = new FTPWebService.ftpSoapClient();
                int regionID = service.Get_region_id(_ConnectedRegion.Get_RegionName());
                fileDataSet = service.Get_files_download_date(regionID);
                service.Close();
            }

            catch (Exception ex) { KryptonMessageBox.Show(ex.ToString()); }

            /* Fill files */
            foreach (File file in _CurrentDirectory.Get_FilesList())
            {
                Boolean downloaded = false;

                /* Set Name, size, date of modification */
                ListViewItem item = new ListViewItem();
                item.SubItems[0].Text = file.Get_Name().Replace("%20", " ");
                item.SubItems.Add(file.Get_Size().ToString() + " Ko");
                item.SubItems.Add(file.Get_Timestamp().ToString());

                /* Set icon */
                if (file.Get_Name().Contains(".xlsx") || file.Get_Name().Contains(".xls"))
                    item.ImageIndex = 4;
                else if (file.Get_Name().Replace(".ZIP",".zip").Contains(".zip") || file.Get_Name().Contains(".tar") || file.Get_Name().Contains(".7z"))
                    item.ImageIndex = 5;
                else if (file.Get_Name().Contains(".rar"))
                    item.ImageIndex = 6;
                else item.ImageIndex = 0;

                /* Check if file (with it's associated region) has already been downloaded. If yes, color it. */
                foreach (DataRow row in fileDataSet.Tables[0].Rows)
                {
                    if (row["name"].ToString().Equals(file.Get_Name()))
                    {
                        item.SubItems.Add(row["max(download_date)"].ToString());
                        item.BackColor = Color.LemonChiffon;
                        downloaded = true;
                        break;
                    }
                }
                if (!downloaded)
                    item.SubItems.Add("-");

                FileExplorerListView.Items.AddRange(new ListViewItem[] { item });
            }

            /* Sort by modification date */
            //FileExplorerListView.ListViewItemSorter = new ListViewItemComparer(e.Column, FileExplorerListView.Sorting);

            FileExplorerListView.Sorting = SortOrder.Descending;
            FileExplorerListView.SetSortIcon(2, SortOrder.Descending);
            FileExplorerListView.ListViewItemSorter = new ListViewItemComparer(2, FileExplorerListView.Sorting);
        }
示例#2
0
        /*******************************\
         * Add download historic on DB *
        \*******************************/
        public void AddDownloadLog()
        {
            int regionID = 0;
            int fileID = 0;

            try
            {
                /* Create service */
                FTPWebService.ftpSoapClient service = new FTPWebService.ftpSoapClient();

                /* Create Timestamp of download date */
                System.DateTime dateOfDownload = System.DateTime.Now;
                string dateOfDownloadTreated = dateOfDownload.ToString("yyyy-MM-dd HH':'mm':'ss");

                /* Get region_id of downloaded file */
                regionID = service.Get_region_id(_ConnectedRegion.Get_RegionName());
                if (regionID == 0)
                    throw new Exception("Region doesn't exist !");

                foreach (File downloadedFile in _FilesToDownload)
                {
                    /* Check if file (with it's associated region) already exists, if not, create one and get its ID. */
                    fileID = service.Get_file_id(downloadedFile.Get_Name(), regionID);
                    if (fileID == 0)
                    {
                        service.Add_file(regionID, downloadedFile.Get_Name());
                        fileID = service.Get_file_id(downloadedFile.Get_Name(), regionID);
                    }

                    /* Add historic in DB */
                    service.Add_download_per_region(regionID, fileID, dateOfDownloadTreated);
                }

                /* Update FileExplorer ListView */
                FileExplorerListView.Items.Clear();
                FillFileExplorerListView();

                /* Close service */
                service.Close();

                /* Reset targets paths & set labels*/
                _FtpAPI.Reset_DownloadedFilesTarget();
                DirFileCounterLabel.Text = _CurrentDirectory.Get_FoldersList().Count + " dir / " + _CurrentDirectory.Get_FilesList().Count + " files";
                FTPBrowserHeaderGroup.ValuesPrimary.Heading = "FTP Browser (" + _ConnectedRegion.Get_RegionName() + ") :";
            }

            catch (Exception ex) { KryptonMessageBox.Show(ex.ToString()); }
        }
示例#3
0
        /****************************************\
         * Duplicate contextMenuItemClick event *
         *    - Duplicate selected region       *
        \****************************************/
        private void DuplicateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (FTPTreeView.SelectedNode != null && FTPTreeView.SelectedNode.Nodes.Count == 0)
            {
                Region duplicatedRegion = new Region();

                /* Create service */
                FTPWebService.ftpSoapClient service = new FTPWebService.ftpSoapClient();

                /* Get region to duplicate */
                Region regionToDuplicate = new Region();
                foreach (Region element in _RegionsList)
                {
                    if (element.Get_RegionName().Equals(FTPTreeView.SelectedNode.Text.ToString())) //if (element.Get_RegionName().Equals(FTPListDataGridView.CurrentCell.Value))
                    {
                        regionToDuplicate = element;
                        break;
                    }
                }

                /* Clone it */
                duplicatedRegion.Clone(regionToDuplicate);
                duplicatedRegion.Set_RegionNameForClone();

                /* Add it to the list of regions */
                _RegionsList.Add(duplicatedRegion);

                /* Add it in DB */
                int serverID = service.Get_server_id(duplicatedRegion.Get_Provider(), duplicatedRegion.Get_FtpHost(), duplicatedRegion.Get_Login(), duplicatedRegion.Get_Password());
                int idFrequency;
                int idDay;
                switch (duplicatedRegion.Get_RecoveryFrequency())
                {
                    case "None": idFrequency = 5; break;
                    case "Daily": idFrequency = 1; break;
                    case "Weekly": idFrequency = 2; break;
                    case "Monthly": idFrequency = 3; break;
                    case "Yearly": idFrequency = 4; break;
                    default: idFrequency = 5; break;
                }
                switch (duplicatedRegion.Get_RecoveryDay())
                {
                    case "None": idDay = 8; break;
                    case "Monday": idDay = 1; break;
                    case "Tuesday": idDay = 2; break;
                    case "Wednesday": idDay = 3; break;
                    case "Thursday": idDay = 4; break;
                    case "Friday": idDay = 5; break;
                    case "Saturday": idDay = 6; break;
                    case "Sunday": idDay = 7; break;
                    default: idDay = 8; break;
                }
                service.Add_region(serverID, duplicatedRegion.Get_RegionName(), duplicatedRegion.Get_FileMask(), duplicatedRegion.Get_TargetDirectory(), idFrequency, idDay);

                /* Refresh List of FTP */
                //FTPListDataGridView.DataSource = null;
                FillFTPTreeView(); //FillFtpListDataGridView();
                FTPTreeView.SelectedNode = null; //FTPListDataGridView.ClearSelection();

                /* Display result */
                KryptonMessageBox.Show("Region Duplicated !", "Cloned",
                     MessageBoxButtons.OK,
                     MessageBoxIcon.Information);

                /* Close service */
                service.Close();
            }
        }
示例#4
0
        /****************************************\
         * Delete FTP button click event        *
         *    - Delete selected region from DB. *
        \****************************************/
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            /* Create service */
            FTPWebService.ftpSoapClient service = new FTPWebService.ftpSoapClient();

            /* Delete region from DB */
            service.Delete_region(FTPTreeView.SelectedNode.Text.ToString()); //service.Delete_region(FTPListDataGridView.CurrentCell.Value.ToString());

            /* Delete region in list of region */
            foreach (Region element in _RegionsList)
            {
                if (element.Get_RegionName().Equals(FTPTreeView.SelectedNode.Text.ToString())) //if (element.Get_RegionName().Equals(FTPListDataGridView.CurrentCell.Value.ToString()))
                {
                    _RegionsList.Remove(element);
                    break;
                }
            }

            /* Refresh DataGridView */
            //FTPListDataGridView.DataSource = null;
            FillFTPTreeView();//FillFtpListDataGridView();
            FTPTreeView.SelectedNode = null;//FTPListDataGridView.ClearSelection();

            /* CLose service */
            service.Close();

            /* Display result */
            KryptonMessageBox.Show("Region Deleted !", "Deleted",
                 MessageBoxButtons.OK,
                 MessageBoxIcon.Information);
        }
示例#5
0
        /********************************************************\
         * Create FTP (OK button click)                         *
         * - Create/Edit FTP (depending on the context)         *
         * - CheckFields : check if mandatory fields are filled *
        \********************************************************/
        private void OkPictureBox_Click(object sender, EventArgs e)
        {
            /* Check if fields are OK */
            if (CheckFields())
            {
                /* Create service */
                FTPWebService.ftpSoapClient service = new FTPWebService.ftpSoapClient();

                /* CASE 1 : CREATION */
                if (((string)OkPictureBox.Tag).Equals(""))
                {
                    /* Check if server exists (Provider|Server Adress|Login|Password) */
                    int serverID = service.Get_server_id(ProviderTextBox.Text, ServerAddressTextBox.Text, LoginTextBox.Text, PasswordTextBox.Text);
                    if (serverID == 0)
                    {
                        /* Create server if not exists then get id_server */
                        service.Add_server(ProviderTextBox.Text, ServerAddressTextBox.Text, LoginTextBox.Text, PasswordTextBox.Text);
                        serverID = service.Get_server_id(ProviderTextBox.Text, ServerAddressTextBox.Text, LoginTextBox.Text, PasswordTextBox.Text);
                    }

                    /* Set idFrequency and idDay */
                    int idFrequency;
                    int idDay;
                    string frequency;
                    string day;
                    switch (RecoveryFrequencyComboBox.Text)
                    {
                        case "None": idFrequency = 5; frequency = "None"; break;
                        case "Daily": idFrequency = 1; frequency = "Daily"; break;
                        case "Weekly": idFrequency = 2; frequency = "Weekly"; break;
                        case "Monthly": idFrequency = 3; frequency = "Monthly"; break;
                        case "Yearly": idFrequency = 4; frequency = "Yearly"; break;
                        default: idFrequency = 5; frequency = "None"; break;
                    }
                    switch (RecoveryDayComboBox.Text)
                    {
                        case "None": idDay = 8; day = "None"; break;
                        case "Monday": idDay = 1; day = "Monday"; break;
                        case "Tuesday": idDay = 2; day = "Tuesday"; break;
                        case "Wednesday": idDay = 3; day = "Wednesday"; break;
                        case "Thursday": idDay = 4; day = "Thursday"; break;
                        case "Friday": idDay = 5; day = "Friday"; break;
                        case "Saturday": idDay = 6; day = "Saturday"; break;
                        case "Sunday": idDay = 7; day = "Sunday"; break;
                        default: idDay = 8; day = "None"; break;
                    }

                    /* Insert region */
                    service.Add_region(serverID, RegionNameTextBox.Text, FileMaskTextBox.Text, _TargetPathTooltip.GetToolTip(TargetDirectoryButton), idFrequency, idDay);

                    /* Add new region to the list */
                    _RegionsList.Add(new Region(ProviderTextBox.Text, ServerAddressTextBox.Text, LoginTextBox.Text, PasswordTextBox.Text, RegionNameTextBox.Text, _TargetPathTooltip.GetToolTip(TargetDirectoryButton), FileMaskTextBox.Text, frequency, day));

                    /* Refresh List of FTP */
                    //FTPListDataGridView.DataSource = null;
                    FillFTPTreeView();//FillFtpListDataGridView();

                    /* Display result */
                    KryptonMessageBox.Show("FTP Created !", "Saved",
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Information);
                }

                /* CASE 2 : EDIT */
                else if (!((string)OkPictureBox.Tag).Equals(""))
                {
                    /* Check if server exists (Provider|Server Adress|Login|Password) */
                    int serverID = service.Get_server_id(ProviderTextBox.Text, ServerAddressTextBox.Text, LoginTextBox.Text, PasswordTextBox.Text);
                    if (serverID == 0)
                    {
                        /* Create server if not exists then get id_server */
                        service.Add_server(ProviderTextBox.Text, ServerAddressTextBox.Text, LoginTextBox.Text, PasswordTextBox.Text);
                        serverID = service.Get_server_id(ProviderTextBox.Text, ServerAddressTextBox.Text, LoginTextBox.Text, PasswordTextBox.Text);
                    }

                    /* Set idFrequency and idDay */
                    int idFrequency;
                    int idDay;
                    switch (RecoveryFrequencyComboBox.Text)
                    {
                        case "None": idFrequency = 5; break;
                        case "Daily": idFrequency = 1; break;
                        case "Weekly": idFrequency = 2; break;
                        case "Monthly": idFrequency = 3; break;
                        case "Yearly": idFrequency = 4; break;
                        default: idFrequency = 5; break;
                    }
                    switch (RecoveryDayComboBox.Text)
                    {
                        case "None": idDay = 8; break;
                        case "Monday": idDay = 1; break;
                        case "Tuesday": idDay = 2; break;
                        case "Wednesday": idDay = 3; break;
                        case "Thursday": idDay = 4; break;
                        case "Friday": idDay = 5; break;
                        case "Saturday": idDay = 6; break;
                        case "Sunday": idDay = 7; break;
                        default: idDay = 8; break;
                    }

                    /* Update region */
                    service.Update_region((string)OkPictureBox.Tag, serverID, RegionNameTextBox.Text, FileMaskTextBox.Text, _TargetPathTooltip.GetToolTip(TargetDirectoryButton), idFrequency, idDay);

                    /* Remove old region from the list */
                    foreach (Region element in _RegionsList)
                    {
                        if (element.Get_RegionName().Equals((string)OkPictureBox.Tag))
                        {
                            _RegionsList.Remove(element);
                            break;
                        }
                    }

                    /* Add new one */
                    _RegionsList.Add(new Region(ProviderTextBox.Text, ServerAddressTextBox.Text, LoginTextBox.Text, PasswordTextBox.Text, RegionNameTextBox.Text, _TargetPathTooltip.GetToolTip(TargetDirectoryButton), FileMaskTextBox.Text, RecoveryFrequencyComboBox.Text, RecoveryDayComboBox.Text));

                    /* Refresh List of FTP */
                    //FTPListDataGridView.DataSource = null;
                    FillFTPTreeView();//FillFtpListDataGridView();

                    /* Display result */
                    KryptonMessageBox.Show("FTP updated !", "Updated",
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Information);
                }

                /* Finally, End Edit */
                EndEdit();

                /* Close service */
                service.Close();
            }
        }
示例#6
0
        /*************************************\
         * Get all regions from DB           *
         *   - Query for getting all regions *
         *   - instanciate region objects    *
        \*************************************/
        private void GetRegions()
        {
            try
            {
                FTPWebService.ftpSoapClient service = new FTPWebService.ftpSoapClient();
                _RegionsList.Clear();
                DataSet dataSet = service.Get_all_regions();
                service.Close();

                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    _RegionsList.Add(new Region(row["provider"].ToString(),
                                                row["server_address"].ToString(),
                                                row["login"].ToString(),
                                                row["password"].ToString(),
                                                row["name"].ToString(),
                                                row["target_directory"].ToString(),
                                                row["file_mask"].ToString(),
                                                row["type"].ToString(),
                                                row["day"].ToString()));
                }
            }

            catch (Exception ex) { KryptonMessageBox.Show(ex.ToString()); }
        }