private void btnImportUpdates_Click(object sender, EventArgs e)
        {
            Logger.EnteringMethod();

            this.Cursor = Cursors.WaitCursor;

            if (dgvSubscriptions.SelectedRows != null && dgvSubscriptions.SelectedRows.Count == 1)
            {
                CatalogSubscription tempSubscription = new CatalogSubscription();
                string catalogFullPath = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\" + _subscribedCatalogsFolder + "\\" + txtBxFileName.Text;

                tempSubscription.Address     = txtBxAddress.Text;
                tempSubscription.CatalogName = txtBxFileName.Text;

                if (!File.Exists(catalogFullPath))
                {
                    try
                    {
                        tempSubscription.DownloadFile(catalogFullPath);
                    }
                    catch (Exception ex)
                    {
                        Logger.Write("**** " + ex.Message);
                        System.Windows.Forms.MessageBox.Show(resMan.GetString("UnableToDownloadTheFile"));
                        this.Cursor = Cursors.Default;
                        return;
                    }
                }
                FrmImportCatalog frmImportCatalog = new FrmImportCatalog(catalogFullPath);
                frmImportCatalog.ShowDialog();
            }
            this.Cursor = Cursors.Default;
        }
        private void btnLoadCatalog_Click(object sender, EventArgs e)
        {
            Logger.EnteringMethod();

            DirectoryInfo folderToSearch = new DirectoryInfo(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\" + _sharedCatalogsFolder);

            if (!folderToSearch.Exists)
            {
                folderToSearch.Create();
            }
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.AddExtension     = true;
            openFile.CheckFileExists  = true;
            openFile.CheckPathExists  = true;
            openFile.DefaultExt       = ".xml";
            openFile.FileName         = "";
            openFile.Filter           = "Xml files|*.xml";
            openFile.InitialDirectory = folderToSearch.FullName;
            openFile.Multiselect      = false;
            openFile.ValidateNames    = true;
            if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                CatalogSubscription sharedCatalog = GetCatalogSubscription(new FileInfo(openFile.FileName));
                AddCatalogToDataGridView(sharedCatalog);
                _catalogSubscriptions.Add(sharedCatalog);
            }
        }
        private void btnModify_Click(object sender, EventArgs e)
        {
            Logger.EnteringMethod();
            CatalogSubscription newCatalog = new CatalogSubscription();
            DataGridViewRow     row        = dgvSubscriptions.SelectedRows[0];

            newCatalog.Address     = txtBxAddress.Text;
            newCatalog.CatalogName = txtBxFileName.Text;
            newCatalog.CheckEvery  = (int)nupCheckEvery.Value;

            if (cmbBxCheckEvery.SelectedItem.ToString() == resMan.GetString("Days"))
            {
                newCatalog.Unit = CatalogSubscription.CheckingUnits.Days;
            }
            if (cmbBxCheckEvery.SelectedItem.ToString() == resMan.GetString("Weeks"))
            {
                newCatalog.Unit = CatalogSubscription.CheckingUnits.Weeks;
            }
            if (cmbBxCheckEvery.SelectedItem.ToString() == resMan.GetString("Months"))
            {
                newCatalog.Unit = CatalogSubscription.CheckingUnits.Months;
            }

            row.Cells["Address"].Value      = txtBxAddress.Text;
            row.Cells["FileName"].Value     = txtBxFileName.Text;
            row.Cells["CheckEvery"].Value   = nupCheckEvery.Value.ToString();
            row.Cells["Unit"].Value         = cmbBxCheckEvery.SelectedItem.ToString();
            row.Cells["Subscription"].Value = newCatalog;
        }
        private void btnRemove_Click(object sender, EventArgs e)
        {
            Logger.EnteringMethod();
            if (dgvSubscriptions.SelectedRows != null && dgvSubscriptions.SelectedRows.Count == 1)
            {
                if (MessageBox.Show(resMan.GetString("DeletionCannotBeCancel"), string.Empty, MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                {
                    CatalogSubscription subscriptionToDelete = (CatalogSubscription)dgvSubscriptions.SelectedRows[0].Cells["Subscription"].Value;
                    string folder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\" + _subscribedCatalogsFolder;

                    subscriptionToDelete.DeleteFromDisk(folder);
                    _catalogSubscriptions.Remove(subscriptionToDelete);
                    dgvSubscriptions.Rows.Remove(dgvSubscriptions.SelectedRows[0]);
                }
            }
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            Logger.EnteringMethod();

            string folder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\" + _subscribedCatalogsFolder + "\\MetaData";

            foreach (DataGridViewRow row in dgvSubscriptions.Rows)
            {
                CatalogSubscription subscriptionToSave = (CatalogSubscription)row.Cells["Subscription"].Value;

                subscriptionToSave.IsActive = (bool)row.Cells["Active"].Value;
                subscriptionToSave.Save(folder);
            }

            this.Close();
        }
        private void AddCatalogToDataGridView(CatalogSubscription catalogToAdd)
        {
            int             index = dgvSubscriptions.Rows.Add();
            DataGridViewRow row   = dgvSubscriptions.Rows[index];

            row.Cells["Active"].Value       = catalogToAdd.IsActive;
            row.Cells["Address"].Value      = catalogToAdd.Address;
            row.Cells["FileName"].Value     = catalogToAdd.CatalogName;
            row.Cells["CheckEvery"].Value   = catalogToAdd.CheckEvery.ToString();
            row.Cells["Unit"].Value         = resMan.GetString(catalogToAdd.Unit.ToString());
            row.Cells["Subscription"].Value = catalogToAdd;

            dgvSubscriptions.ClearSelection();
            row.Selected = true;

            ValidateData();
        }
예제 #7
0
        private void cmbBxCatalog_SelectedIndexChanged(object sender, EventArgs e)
        {
            ClearDisplay();
            cmbBxDeletedUpdates.Items.Clear();
            cmbBxAddedUpdates.Items.Clear();

            if (cmbBxCatalog.SelectedIndex != -1 && cmbBxCatalog.SelectedItem != null)
            {
                _displayedCatalog = (CatalogSubscription)cmbBxCatalog.SelectedItem;
                foreach (CatalogUpdate deletedUpdate in _displayedCatalog.DeletedUpdates)
                {
                    cmbBxDeletedUpdates.Items.Add(deletedUpdate);
                }
                foreach (CatalogUpdate addedUpdate in _displayedCatalog.AddedUpdates)
                {
                    cmbBxAddedUpdates.Items.Add(addedUpdate);
                }
            }
        }
        private void btnTest_Click(object sender, EventArgs e)
        {
            Logger.EnteringMethod();

            this.Cursor = Cursors.WaitCursor;

            try
            {
                btnAdd.Enabled    = false;
                btnModify.Enabled = false;
                btnRemove.Enabled = false;
                btnTest.Enabled   = false;
                btnCancel.Enabled = false;
                btnOk.Enabled     = false;

                CatalogSubscription subscription = new CatalogSubscription();

                subscription.Address     = txtBxAddress.Text;
                subscription.CatalogName = txtBxFileName.Text;

                Logger.Write("Will test : " + subscription.Address + "/" + subscription.CatalogName);

                if (subscription.TestConnectivity())
                {
                    MessageBox.Show(resMan.GetString("Succeeded"));
                }
                else
                {
                    MessageBox.Show(resMan.GetString("Failed"));
                }
            }
            catch (Exception ex)
            {
                Logger.Write("**** " + ex.Message);
                MessageBox.Show(resMan.GetString("Failed"));
            }

            ValidateData();
            btnCancel.Enabled = true;
            btnOk.Enabled     = true;
            this.Cursor       = Cursors.Default;
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            Logger.EnteringMethod();
            CatalogSubscription newCatalog = new CatalogSubscription();

            newCatalog.Address     = txtBxAddress.Text;
            newCatalog.CatalogName = txtBxFileName.Text;
            newCatalog.CheckEvery  = (int)nupCheckEvery.Value;

            if (cmbBxCheckEvery.SelectedItem.ToString() == resMan.GetString("Days"))
            {
                newCatalog.Unit = CatalogSubscription.CheckingUnits.Days;
            }
            if (cmbBxCheckEvery.SelectedItem.ToString() == resMan.GetString("Weeks"))
            {
                newCatalog.Unit = CatalogSubscription.CheckingUnits.Weeks;
            }
            if (cmbBxCheckEvery.SelectedItem.ToString() == resMan.GetString("Months"))
            {
                newCatalog.Unit = CatalogSubscription.CheckingUnits.Months;
            }

            AddCatalogToDataGridView(newCatalog);
            _catalogSubscriptions.Add(newCatalog);

            if (chkBxShareCatalogAddress.Checked)
            {
                string   tempFileName = Tools.Utilities.GetTempFolder() + txtBxFileName.Text + ".txt";
                FileInfo fileToUpload = new FileInfo(tempFileName);
                if (fileToUpload.Exists)
                {
                    fileToUpload.Delete();
                }
                StreamWriter writer = fileToUpload.CreateText();
                writer.WriteLine(txtBxAddress.Text);
                writer.WriteLine(txtBxFileName.Text);
                writer.Flush();
                writer.Close();
                System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(this.ShareCatalog));
                t.Start(tempFileName);
            }
        }
        /// <summary>
        /// Parse the XML file and create a CatalogSubscription object.
        /// </summary>
        /// <param name="subscriptionFile">The file with informations to create the CatalogSubscription object.</param>
        /// <returns>If the file contains all informations for creating the CatalogSubscription, return this CatalogSubscription. Otherwise return an Default CatalogSubscription.</returns>
        private CatalogSubscription GetCatalogSubscription(FileInfo subscriptionFile)
        {
            Logger.EnteringMethod(subscriptionFile.FullName);

            CatalogSubscription catalogSubscription = new CatalogSubscription();

            StreamReader streamReader = null;

            try
            {
                streamReader = new StreamReader(subscriptionFile.FullName);
                XmlReader reader = XmlReader.Create(streamReader);

                if (reader.ReadToFollowing("CatalogSubscription"))
                {
                    if (reader.ReadToFollowing("IsActive"))
                    {
                        catalogSubscription.IsActive = Convert.ToBoolean(reader.ReadString());
                    }
                    if (reader.ReadToFollowing("Address"))
                    {
                        catalogSubscription.Address = reader.ReadString();
                    }
                    if (reader.ReadToFollowing("CheckEvery"))
                    {
                        catalogSubscription.CheckEvery = reader.ReadElementContentAsInt();
                    }
                    if (reader.ReadToFollowing("Unit"))
                    {
                        catalogSubscription.Unit = (CatalogSubscription.CheckingUnits)Enum.Parse(typeof(CatalogSubscription.CheckingUnits), reader.ReadString(), true);
                    }
                    if (reader.ReadToFollowing("LastCheck"))
                    {
                        catalogSubscription.LastCheckDate = Convert.ToDateTime(reader.ReadString());
                    }
                    if (reader.ReadToFollowing("LastCheckResult"))
                    {
                        catalogSubscription.LastCheckResult = Convert.ToBoolean(reader.ReadString());
                    }
                    if (reader.ReadToFollowing("CatalogName"))
                    {
                        catalogSubscription.CatalogName = reader.ReadString();
                    }
                    if (reader.ReadToFollowing("Hash"))
                    {
                        catalogSubscription.Hash = reader.ReadString();
                    }
                    if (reader.ReadToFollowing("LastDownloadDate"))
                    {
                        catalogSubscription.LastDownloadDate = Convert.ToDateTime(reader.ReadString());
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Write("**** " + ex.Message);
            }
            finally
            {
                if (streamReader != null)
                {
                    streamReader.Close();
                }
            }

            return(catalogSubscription);
        }