示例#1
0
        public void AddFieldsSuccessfully()
        {
            // Load file (ignore data)
            file = new AFPFile(testFilePath, false);

            int        oldCount  = file.Fields.Count;
            int        numNew    = 0;
            List <NOP> newFields = new List <NOP>();

            // Add a bunch of NOPs to the beginning
            for (int i = 0; i < 10; i++)
            {
                NOP newNOP = StructuredField.New <NOP>();
                file.AddField(newNOP, 0);
                newFields.Add(newNOP);
                numNew++;
            }

            // Ensure they actually exist
            int newCount = oldCount + numNew;

            Assert.AreEqual(newCount, file.Fields.Count);
            foreach (NOP n in newFields)
            {
                Assert.IsTrue(file.Fields.Contains(n));
            }
        }
示例#2
0
 private void dgvFields_SelectionChanged(object sender, EventArgs e)
 {
     if (dgvFields.CurrentRow != null)
     {
         StructuredField sf = (StructuredField)dgvFields.CurrentRow.DataBoundItem;
         txtDescription.Text = sf.GetFullDescription().Trim();
     }
 }
示例#3
0
        public void Validate()
        {
            // Load the sample file data
            file = new AFPFile(testFilePath, false);

            // Ensure it validates
            Assert.IsTrue(file.EncodeData().Any());

            // Remove the first container information from all fields it contains
            Container c = file.Fields.First(f => f.LowestLevelContainer != null).LowestLevelContainer;

            foreach (DataStructure s in c.Structures)
            {
                s.Containers.Remove(c);
            }

            // it should no longer validate
            Assert.IsFalse(file.EncodeData().Any());

            // Reload data
            file = new AFPFile(testFilePath, false);

            // Surround the file with BPF/EPF tags
            file.AddField(StructuredField.New <BPF>(), 0);
            file.AddField(StructuredField.New <EPF>(), file.Fields.Count);

            // Check it still validates (container info should have been updated)
            Assert.IsTrue(file.EncodeData().Any());

            // Try adding a TLE field to the top of the file
            TLE newTLE = StructuredField.New <TLE>();

            file.AddField(newTLE, 0);

            // Ensure it does not validate
            Assert.IsFalse(file.EncodeData().Any());

            // Delete that field, and add it in a place where it is allowed to be (in this case, after a BPG)
            file.DeleteField(newTLE);
            int newIndex = 0;

            for (int i = 0; i < file.Fields.Count; i++)
            {
                if (file.Fields[i] is BPG)
                {
                    newIndex = i + 1; break;
                }
            }
            file.AddField(newTLE, newIndex);

            Assert.IsTrue(file.EncodeData().Any());
        }
示例#4
0
        private void dgvFields_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            StructuredField sf = (StructuredField)dgvFields.CurrentRow.DataBoundItem;

            if (!string.IsNullOrWhiteSpace(sf.DataHex))
            {
                try
                {
                    // Copy hex data to clipboard
                    Clipboard.SetText(sf.DataHex);
                    MessageBox.Show("Hex values copied to clipboard.", "Hex", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch { }
            }
        }
示例#5
0
        private void UpdateSelectedGridRecord(StructuredField field)
        {
            int oldIndex = dgvFields.SelectedRows[0].Index - dgvFields.FirstDisplayedScrollingRowIndex;

            dgvFields.ClearSelection();
            dgvFields.Rows.Cast <DataGridViewRow>().First(r => r.DataBoundItem == field).Selected = true;

            int newIndex  = dgvFields.SelectedRows[0].Index - dgvFields.FirstDisplayedScrollingRowIndex;
            int newOffset = dgvFields.FirstDisplayedScrollingRowIndex + (newIndex - oldIndex);

            // Only scroll if the new offset is above 0 AND the selected row is not near the top when we're moving down
            if (newOffset >= 0 && !(newIndex < 10 && newIndex - oldIndex > 0))
            {
                dgvFields.FirstDisplayedScrollingRowIndex = newOffset;
            }
        }
示例#6
0
        public void UpdateContainerInfo_WhenFieldIsAddedOrDeleted()
        {
            // Load a file (ignore data), check the first NOP field
            file = new AFPFile(testFilePath, false);
            NOP foundNOP = file.Fields.OfType <NOP>().First();

            // Get the container of this field for future assertions, and delete the field
            Container NOPContainer = foundNOP.LowestLevelContainer;

            file.DeleteField(foundNOP);

            // Ensure that no containers have the deleted structure
            foreach (Container c in file.Fields.Select(f => f.LowestLevelContainer).Distinct())
            {
                Assert.IsFalse(c.Structures.Contains(foundNOP));
            }

            // Create a new NOP field and insert it after the first detected field with a container
            NOP newNOP = StructuredField.New <NOP>();

            // Store the insert index
            int insertIndex = 0;

            for (int i = 0; i < file.Fields.Count; i++)
            {
                if (file.Fields[i].LowestLevelContainer != null)
                {
                    insertIndex = i + 1;
                    break;
                }
            }
            file.AddField(newNOP, insertIndex);

            // Ensure the new field has the expected container
            Assert.AreEqual(NOPContainer, newNOP.LowestLevelContainer);
        }