Beispiel #1
0
        internal virtual int AddColInfo(int col, Cursor c)
        {
            String tform = null;

            if (types[col] == typeof(String))
            {
                tform = "A" + lengths[col];
            }
            else if (types[col] == typeof(int) || types[col] == typeof(long))
            {
                tform = "I" + lengths[col];
            }
            else if (types[col] == typeof(float))
            {
                tform = "E" + lengths[col] + ".0";
            }
            else if (types[col] == typeof(double))
            {
                tform = "D" + lengths[col] + ".0";
            }
            String key;

            key = "TFORM" + (col + 1);
            c.Add(key, new HeaderCard(key, tform, null));
            key = "TBCOL" + (col + 1);
            c.Add(key, new HeaderCard(key, offsets[col] + 1, null));

            return(lengths[col]);
        }
Beispiel #2
0
        /// <summary>Fill in a header with information that points to this data.</summary>
        internal override void FillHeader(Header hdr)
        {
            try
            {
                hdr.Xtension = "TABLE";
                hdr.Bitpix   = 8;
                hdr.Naxes    = 2;
                hdr.SetNaxis(1, rowLen);
                hdr.SetNaxis(2, nRows);
                Cursor c = (Cursor)hdr.GetEnumerator();
                c.Key = "NAXIS2";
                c.MoveNext();
                c.Add("PCOUNT", new HeaderCard("PCOUNT", 0, "No group data"));
                c.Add("GCOUNT", new HeaderCard("GCOUNT", 1, "One group"));
                c.Add("TFIELDS", new HeaderCard("TFIELDS", nFields, "Number of fields in table"));

                for (int i = 0; i < nFields; i += 1)
                {
                    AddColInfo(i, c);
                }
            }
            catch (HeaderCardException e)
            {
                Console.Error.WriteLine("ImpossibleException in fillHeader:" + e);
            }
        }
Beispiel #3
0
        public void RdMfWt()
        {
            Transaction txn = paramEnv.BeginTransaction();
            Cursor      dbc = paramDB.Cursor(txn);

            try
            {
                LockingInfo lck = new LockingInfo();
                lck.ReadModifyWrite = true;

                // Read record.
                cursorFunc(dbc, lck);

                // Block the current thread until event is set.
                signal.WaitOne();

                // Write new records into database.
                DatabaseEntry key = new DatabaseEntry(
                    BitConverter.GetBytes(55));
                DatabaseEntry data = new DatabaseEntry(
                    BitConverter.GetBytes(55));
                dbc.Add(new KeyValuePair <DatabaseEntry,
                                          DatabaseEntry>(key, data));

                dbc.Close();
                txn.Commit();
            }
            catch (DeadlockException)
            {
                dbc.Close();
                txn.Abort();
            }
        }
        public void TestRewrite()
        {
            Fits f = null;

            try
            {
                // Should be rewriteable until we add enough cards to
                // start a new block.
                f = new Fits(TestFileSetup.GetTargetFilename("ht1.fits"));
                ImageHDU hdu = (ImageHDU)f.GetHDU(0);
                Header   hdr = hdu.Header;
                Cursor   c   = hdr.GetCursor();
                c.MoveNext();

                int nc = hdr.NumberOfCards;
                int nb = (nc - 1) / 36;

                while (hdr.Rewriteable)
                {
                    int nbx = (hdr.NumberOfCards - 1) / 36;
                    Assert.AreEqual(nb == nbx, hdr.Rewriteable);
                    c.Add(new HeaderCard("DUMMY" + nbx, null, null));
                }
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
Beispiel #5
0
 void iPersonsService.add(PersonMessage msg)
 {
     using (var sess = sessionPool.GetSession())
         using (var trans = sess.BeginTransaction())
         {
             Cursor <Person> cur = sess.Cursor <Person>();
             cur.Add(msg.toRecord());
             trans.Commit();
         }
 }
Beispiel #6
0
        /// <summary>Create a new folder</summary>
        /// <param name="cur"></param>
        /// <param name="idParent">Parent folder ID</param>
        /// <param name="name">Folder name</param>
        /// <returns></returns>
        public static EfsEntry CreateFolder(Cursor <EfsEntry> cur, int idParent, string name)
        {
            if (name.IndexOfAny(s_PathSplitCharacters) >= 0)
            {
                throw new IOException("Invalid name");
            }
            var ne = EfsEntry.NewFolder(idParent, name);

            cur.Add(ne);
            return(ne);
        }
Beispiel #7
0
        public static EfsEntry CreateFolderEx(Cursor <EfsEntry> cur, int idParent, string path)
        {
            DirectoryInfo di = new DirectoryInfo(path);

            if (!di.Exists)
            {
                throw new FileNotFoundException();
            }
            var ne = EfsEntry.NewFolder(idParent, di);

            cur.Add(ne);
            return(ne);
        }
    void DeployPlayers()
    {
        int   teamSize      = 4;
        float playerSpacing = 1.2f;

        for (int i = 0; i < teamSize; i++)
        {
            Vector2    position = new Vector2(4, (teamSize - 1) / 2f - i * playerSpacing);
            GameObject o        = Instantiate(playerPrefab, players.transform);
            o.transform.localPosition = position;
            cursor.Add(o.GetComponent <Entity>());
        }
    }
Beispiel #9
0
        public static void AddOneByCursor(Database db, Cursor cursor)
        {
            DatabaseEntry key, data;
            KeyValuePair <DatabaseEntry, DatabaseEntry> pair;

            // Add a record to db via cursor.
            key  = new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("key"));
            data = new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("data"));
            pair = new KeyValuePair <DatabaseEntry, DatabaseEntry>(key, data);
            cursor.Add(pair);

            // Confirm that the record has been put to the database.
            Assert.IsTrue(db.Exists(key));
        }
Beispiel #10
0
        public static void AddOneByCursor(Database db, Cursor cursor)
        {
            DatabaseEntry key, data;
            KeyValuePair<DatabaseEntry, DatabaseEntry> pair;

            // Add a record to db via cursor.
            key = new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("key"));
            data = new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("data"));
            pair = new KeyValuePair<DatabaseEntry,DatabaseEntry>(key, data);
            cursor.Add(pair);

            // Confirm that the record has been put to the database.
            Assert.IsTrue(db.Exists(key));
        }
Beispiel #11
0
        public void TestCursor()
        {
            HashedList h1 = new HashedList();

            h1.Add("key 1", "Row 1");
            h1.Add("Row 3");
            h1.Add("key 4", "Row 4");
            h1.Add("Row 5");

            Cursor j = (Cursor)h1.GetCursor(0);

            Assertion.AssertEquals("n1xv", "Row 1", (String)((DictionaryEntry)j.Current).Value);
            j.MoveNext();
            Assertion.AssertEquals("n1xv", "Row 3", (String)((DictionaryEntry)j.Current).Value);

            Assertion.AssertEquals("No Row 2", false, h1.ContainsKey("key 2"));
            Assertion.AssertEquals("No Row 2", false, h1.ContainsValue("Row 2"));
            j.Key = "key 1";
            Assertion.AssertEquals("setKey()", "Row 1", (String)((DictionaryEntry)j.Current).Value);
            j.MoveNext();
            j.Add("key 2", "Row 2");
            Assertion.AssertEquals("has Row 2", true, h1.ContainsValue("Row 2"));
            Assertion.AssertEquals("after add", "Row 3", (String)((DictionaryEntry)j.Current).Value);


            j.Key = "key 4";
            Assertion.AssertEquals("setKey(1)", "Row 4", (String)((DictionaryEntry)j.Current).Value);
            j.MoveNext();
            Assertion.AssertEquals("setKey(2)", "Row 5", (String)((DictionaryEntry)j.Current).Value);
            Assertion.AssertEquals("setKey(3)", false, j.MoveNext());


            j.Key = "key 2";
            Assertion.AssertEquals("setKey(4)", "Row 2", (String)((DictionaryEntry)j.Current).Value);
            j.MoveNext();
            Assertion.AssertEquals("setKey(5)", "Row 3", (String)((DictionaryEntry)j.Current).Value);
            j.Add("Row 3.5");
            j.Add("Row 3.6");
            Assertion.AssertEquals("After add", 7, h1.Count);

            j = h1.GetCursor("key 2");
            j.Add("Row 1.5");
            j.Add("key 1.7", "Row 1.7");
            j.Add("Row 1.9");
            Assertion.AssertEquals("next() after adds", "Row 2", (String)((DictionaryEntry)j.Current).Value);
            j.Key = "key 1.7";
            Assertion.AssertEquals("next() after adds", "Row 1.7", (String)((DictionaryEntry)j.Current).Value);
            j.MoveNext();
            j.MovePrevious();
            Assertion.AssertEquals("prev(1)", "Row 1.7", (String)((DictionaryEntry)j.Current).Value);
            j.MovePrevious();
            Assertion.AssertEquals("prev(2)", "Row 1.5", (String)((DictionaryEntry)j.Current).Value);
            Assertion.AssertEquals("prev(3)", true, j.MovePrevious());
            Assertion.AssertEquals("prev(4)", "Row 1", (String)((DictionaryEntry)j.Current).Value);
            Assertion.AssertEquals("prev(5)", false, j.MovePrevious());
        }
Beispiel #12
0
        public void TestCursor()
        {
            HashedList h1 = new HashedList();

            h1.Add("key 1", "Row 1");
            h1.Add("Row 3");
            h1.Add("key 4", "Row 4");
            h1.Add("Row 5");

            Cursor j = (Cursor)h1.GetCursor(0);

            Assert.AreEqual("Row 1", (String)((DictionaryEntry)j.Current).Value);
            j.MoveNext();
            Assert.AreEqual("Row 3", (String)((DictionaryEntry)j.Current).Value);

            Assert.AreEqual(false, h1.ContainsKey("key 2"));
            Assert.AreEqual(false, h1.ContainsValue("Row 2"));
            j.Key = "key 1";
            Assert.AreEqual("Row 1", (String)((DictionaryEntry)j.Current).Value);
            j.MoveNext();
            j.Add("key 2", "Row 2");
            Assert.AreEqual(true, h1.ContainsValue("Row 2"));
            Assert.AreEqual("Row 3", (String)((DictionaryEntry)j.Current).Value);

            j.Key = "key 4";
            Assert.AreEqual("Row 4", (String)((DictionaryEntry)j.Current).Value);
            j.MoveNext();
            Assert.AreEqual("Row 5", (String)((DictionaryEntry)j.Current).Value);
            Assert.AreEqual(false, j.MoveNext());

            j.Key = "key 2";
            Assert.AreEqual("Row 2", (String)((DictionaryEntry)j.Current).Value);
            j.MoveNext();
            Assert.AreEqual("Row 3", (String)((DictionaryEntry)j.Current).Value);
            j.Add("Row 3.5");
            j.Add("Row 3.6");
            Assert.AreEqual(7, h1.Count);

            j = h1.GetCursor("key 2");
            j.Add("Row 1.5");
            j.Add("key 1.7", "Row 1.7");
            j.Add("Row 1.9");
            Assert.AreEqual("Row 2", (String)((DictionaryEntry)j.Current).Value);
            j.Key = "key 1.7";
            Assert.AreEqual("Row 1.7", (String)((DictionaryEntry)j.Current).Value);
            j.MoveNext();
            j.MovePrevious();
            Assert.AreEqual("Row 1.7", (String)((DictionaryEntry)j.Current).Value);
            j.MovePrevious();
            Assert.AreEqual("Row 1.5", (String)((DictionaryEntry)j.Current).Value);
            Assert.AreEqual(true, j.MovePrevious());
            Assert.AreEqual("Row 1", (String)((DictionaryEntry)j.Current).Value);
            Assert.AreEqual(false, j.MovePrevious());
        }
Beispiel #13
0
        /// <summary>
        /// writes the header to fits file
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="filename"></param>
        /// <param name="writeMode"></param>
        /// <param name="stringTruncationLength"></param>
        /// <param name="padStringsLeft"></param>
        /// <param name="stringPadChar"></param>
        public static void Write(IDataReader reader, String filename,
                                 StreamedBinaryTableHDU.StringWriteMode writeMode, int stringTruncationLength,
                                 bool padStringsLeft, char stringPadChar)
        {
            Header header = new Header();

            header.Simple = true;
            header.Bitpix = 8;
            header.Naxes  = 0;

            Cursor c = header.GetCursor();

            // move to the end of the header cards
            for (c.MoveNext(); c.MoveNext();)
            {
                ;
            }
            // we know EXTEND isn't there yet
            c.Add("EXTEND", new HeaderCard("EXTEND", true, null));

            ImageHDU hdu1 = new ImageHDU(header, null);

            StreamedBinaryTableHDU hdu2 =
                new StreamedBinaryTableHDU(new DataReaderAdapter(reader), 4096,
                                           writeMode, stringTruncationLength, padStringsLeft, stringPadChar);

            Fits fits = new Fits();

            fits.AddHDU(hdu1);
            fits.AddHDU(hdu2);

            Stream s = null;

            try
            {
                s = new FileStream(filename, FileMode.Create);
                fits.Write(s);
                s.Close();
            }
            catch (Exception e)
            {
                s.Close();
                throw (e);
            }
        }
Beispiel #14
0
        /*
         * Move the cursor to current existing record. The returning
         * value should be true.
         */
        public void MoveCursorToCurrentRec(Cursor dbc,
                                           LockingInfo lck)
        {
            // Add a record to the database.
            KeyValuePair <DatabaseEntry, DatabaseEntry> pair;

            pair = new KeyValuePair <DatabaseEntry, DatabaseEntry>(
                new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("key")),
                new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("key")));
            dbc.Add(pair);

            if (lck == null)
            {
                dbc.Refresh();
            }
            else
            {
                dbc.Refresh(lck);
            }

            Assert.IsNotNull(dbc.Current.Key);
        }
Beispiel #15
0
        public void TestRewrite()
        {
            // Should be rewriteable until we add enough cards to
            // start a new block.

            Fits     f   = new Fits("testdocs\\ht1.fits");
            ImageHDU hdu = (ImageHDU)f.GetHDU(0);
            Header   hdr = hdu.Header;
            Cursor   c   = hdr.GetCursor();

            c.MoveNext();

            int nc = hdr.NumberOfCards;
            int nb = (nc - 1) / 36;

            while (hdr.Rewriteable)
            {
                int nbx = (hdr.NumberOfCards - 1) / 36;
                Assertion.AssertEquals("Rewrite:" + nbx, nb == nbx, hdr.Rewriteable);
                c.Add(new HeaderCard("DUMMY" + nbx, null, null));
            }
            f.Close();
        }
Beispiel #16
0
        /*
         * Move the cursor to current existing record. The returning
         * value should be true.
         */
        public void MoveCursorToCurrentRec(Cursor dbc, 
		    LockingInfo lck)
        {
            // Add a record to the database.
            KeyValuePair<DatabaseEntry, DatabaseEntry> pair;
            pair = new KeyValuePair<DatabaseEntry,DatabaseEntry>(
                new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("key")),
                new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("key")));
            dbc.Add(pair);

            if (lck == null)
                dbc.Refresh();
            else
                dbc.Refresh(lck);

            Assert.IsNotNull(dbc.Current.Key);
        }
Beispiel #17
0
        /*
         * Move the cursor to current existing record. The returning
         * value should be true.
         */
        public void MoveCursorToCurrentRec(Cursor dbc,
		    uint kOffset, uint kLen,
		    uint dOffset, uint dLen, LockingInfo lck)
        {
            DatabaseEntry key, data;

            // Add a record to the database.
            KeyValuePair<DatabaseEntry, DatabaseEntry> pair;
            key = new DatabaseEntry(
                ASCIIEncoding.ASCII.GetBytes("key"));
            data = new DatabaseEntry(
                ASCIIEncoding.ASCII.GetBytes("data"));
            pair = new KeyValuePair<DatabaseEntry,
                DatabaseEntry>(key, data);
            dbc.Add(pair);

            if (lck == null)
                Assert.IsTrue(dbc.Refresh());
            else
            Assert.IsTrue(dbc.Refresh(lck));
            Assert.AreEqual(key.Data, dbc.Current.Key.Data);
            Assert.AreEqual(data.Data, dbc.Current.Value.Data);

            key = new DatabaseEntry(kOffset, kLen);
            data = new DatabaseEntry(dOffset, dLen);
            if (lck == null)
                Assert.IsTrue(dbc.Refresh(key, data));
            else
                Assert.IsTrue(dbc.Refresh(key, data, lck));
            CheckPartial(dbc.Current.Key, kOffset, kLen,
                dbc.Current.Value, dOffset, dLen);
        }
Beispiel #18
0
        /// <summary>Ensure that the header has exactly one END keyword in
        /// the appropriate location.</summary>
        internal void CheckEnd()
        {
            // Ensure we have an END card only at the end of the header.
            cursor = GetCursor();
            HeaderCard card;

            while(cursor.MoveNext())
            {
                card = (HeaderCard)((DictionaryEntry)cursor.Current).Value;
                if(!card.KeyValuePair && card.Key.Equals("END"))
                {
                    cursor.Remove();
                }
            }
            try
            {
                cursor.Add(new HeaderCard("END", null, null));
            }
            catch(HeaderCardException)
            {
            }
        }
Beispiel #19
0
        /// <summary> Update the header to reflect the details of a given column.</summary>
        internal void FillForColumn(Header h, int col, Cursor cursor)
        {
            String tform;

            // .99.1 changes: new method for condition check
            if (IsVarCol(col))
            {
                if (IsLongVary(col))
                {
                    tform = "1Q";
                }
                else
                {
                    tform = "1P";
                }
            }
            else
            {
                tform = "" + sizes[col];
            }
            if (bases[col] == typeof(int))
            {
              tform += "J";
            }
            //else if (bases[col] == typeof(short) || bases[col] == typeof(char))
            else if (bases[col] == typeof(short))// || bases[col] == typeof(char))
            {
              tform += "I";
            }
            else if (bases[col] == typeof(byte))
            {
              tform += "B";
            }
            else if (bases[col] == typeof(float))
            {
              tform += "E";
            }
            else if (bases[col] == typeof(double))
            {
              tform += "D";
            }
            else if (bases[col] == typeof(long))
            {
              tform += "K";
            }
            else if (bases[col] == typeof(bool))
            {
              tform += "L";
            }
            else if (bases[col] == typeof(char) || bases[col] == typeof(String))
            {
              tform += "A";
            }
            else
            {
              throw new FitsException("Invalid column data class:" + bases[col]);
            }

            String key = "TFORM" + (col + 1);
            cursor.Add(key, new HeaderCard(key, tform, null));

            // .99.1 changes: new method for condition check
            if (dimens[col].Length > 0 && ((!IsVarCol(col))))
            {
                System.Text.StringBuilder tdim = new System.Text.StringBuilder();
                char comma = '(';
                for (int i = dimens[col].Length - 1; i >= 0; i -= 1)
                {
                    tdim.Append(comma);
                    tdim.Append(dimens[col][i]);
                    comma = ',';
                }
                tdim.Append(')');
                key = "TDIM" + (col + 1);
                cursor.Add(key, new HeaderCard(key, new String(tdim.ToString().ToCharArray()), null));
            }
        }
Beispiel #20
0
        internal virtual int AddColInfo(int col, Cursor c)
        {
            String tform = null;
            if (types[col] == typeof(String))
            {
                tform = "A" + lengths[col];
            }
            else if (types[col] == typeof(int) || types[col] == typeof(long))
            {
                tform = "I" + lengths[col];
            }
            else if (types[col] == typeof(float))
            {
                tform = "E" + lengths[col] + ".0";
            }
            else if (types[col] == typeof(double))
            {
                tform = "D" + lengths[col] + ".0";
            }
            String key;
            key = "TFORM" + (col + 1);
            c.Add(key, new HeaderCard(key, tform, null));
            key = "TBCOL" + (col + 1);
            c.Add(key, new HeaderCard(key, offsets[col] + 1, null));

              return lengths[col];
        }
Beispiel #21
0
        public void TestHashedList()
        {
            HashedList h1 = new HashedList();
            HashedList h2 = new HashedList();

            Cursor i = h1.GetCursor(-1);
            Cursor j;

            // Add a few unkeyed rows.
            h1.Add("Row 1");
            h1.Add("Row 2");
            h1.Add("Row 3");

            System.Console.Out.WriteLine("***** Collection methods *****\n");
            show("Three unkeyed elements", h1);
            h1.RemoveUnkeyedObject("Row 2");
            show("Did we remove Row 2?", h1);

            h1.Clear();
            show("Cleared", h1);

            // Insert Rows with Keys.
            h1.Add("key 1", "Row 1");
            h1.Add("key 2", "Row 2");
            h1.Add("key 3", "Row 3");

            show("Three keyed elements", h1);
            h1.Remove("key 2");
            show("Did we remove Row 2 using a key?", h1);
            h1.Clear();
            show("Cleared", h1);

            // Again insert Rows with Keys.
            h1.Add("key 1", "Row 1");
            h1.Add("key 2", "Row 2");
            h1.Add("key 3", "Row 3");
            show("Three elements again!", h1);
            Console.Out.WriteLine("Check contains (true):" + h1.ContainsValue("Row 2"));

            // Inserting Rows in h2.
            h2.Add("key 4", "Row 4");
            h2.Add("key 5", "Row 5");
            Console.Out.WriteLine("Check containsAll (false):" + h1.ContainsAll(h2));

            h1.AddAll(h2);
            show("Should have 5 elements now", h1);
            Console.Out.WriteLine("Check containsAll (true):" + h1.ContainsAll(h2));
            Console.Out.WriteLine("Check contains (true):" + h1.ContainsKey("key 4"));

            h1.RemoveValue("Row 4");
            show("Dropped Row 4:", h1);
            Console.Out.WriteLine("Check containsAll (false):" + h1.ContainsAll(h2));
            Console.Out.WriteLine("Check contains (false):" + h1.ContainsKey("Row 4"));

            Console.Out.WriteLine("Check isEmpty (false):" + h1.Empty);
            h1.RemoveValue("Row 1");
            h1.RemoveValue("Row 2");
            h1.RemoveValue("Row 3");
            h1.RemoveValue("Row 5");
            show("Removed all elements", h1);
            Console.Out.WriteLine("Check isEmpty (true):" + h1.Empty);

            h1.Add("Row 1");
            h1.Add("Row 2");
            h1.Add("Row 3");
            h1.AddAll(h2);
            show("Back to 5", h1);
            h1.RemoveAll(h2);
            show("Testing removeAll back to 3?", h1);
            h1.AddAll(h2);
            h1.RetainAll(h2);
            show("Testing retainAll now just 2?", h1);

            Console.Out.WriteLine("\n\n**** Test Cursor **** \n");

            j = h1.GetCursor();
            while (j.MoveNext())
            {
                Console.Out.WriteLine("Cursor got: [" + ((DictionaryEntry)j.Current).Key + "] \"" +
                                      ((DictionaryEntry)j.Current).Value + "\"");
            }

            h1.Clear();
            h1.Add("key 1", "Row 1");
            h1.Add("key 2", "Row 2");
            h1.Add("Row 3");
            h1.Add("key 4", "Row 4");
            h1.Add("Row 5");
            j = h1.GetCursor();
            j.MoveNext();
            j.MoveNext();
            j.Remove(); // Should get rid of second row
            show("Removed second row with cursor", h1);
            Console.Out.WriteLine("Cursor should still be OK:" + j.MoveNext() + " [" +
                                  ((DictionaryEntry)j.Current).Key + "] \"" +
                                  ((DictionaryEntry)j.Current).Value + "\"");
            Console.Out.WriteLine("Cursor should still be OK:" + j.MoveNext() + " [" +
                                  ((DictionaryEntry)j.Current).Key + "] \"" +
                                  ((DictionaryEntry)j.Current).Value + "\"");
            Console.Out.WriteLine("Cursor should be done:" + j.MoveNext());

            Console.Out.WriteLine("\n\n**** HashedListCursor ****\n");
            i = h1.GetCursor(-1);
            Console.Out.WriteLine("Cursor should still be OK:" + i.MoveNext() + " [" +
                                  ((DictionaryEntry)i.Current).Key + "] \"" +
                                  ((DictionaryEntry)i.Current).Value + "\"");
            Console.Out.WriteLine("Cursor should still be OK:" + i.MoveNext() + " [" +
                                  ((DictionaryEntry)i.Current).Key + "] \"" +
                                  ((DictionaryEntry)i.Current).Value + "\"");
            Console.Out.WriteLine("Cursor should still be OK:" + i.MoveNext() + " [" +
                                  ((DictionaryEntry)i.Current).Key + "] \"" +
                                  ((DictionaryEntry)i.Current).Value + "\"");
            Console.Out.WriteLine("Cursor should still be OK:" + i.MoveNext() + " [" +
                                  ((DictionaryEntry)i.Current).Key + "] \"" +
                                  ((DictionaryEntry)i.Current).Value + "\"");
            Console.Out.WriteLine("Cursor should be done:" + i.MoveNext());

            i.Key = "key 1";
            i.MoveNext();
            i.Add("key 2", "Row 2");
            Console.Out.WriteLine("Cursor should still be OK:" + " [" +
                                  ((DictionaryEntry)i.Current).Key + "] \"" +
                                  ((DictionaryEntry)i.Current).Value + "\"");
            i.MoveNext();
            Console.Out.WriteLine("Cursor should still be OK:" + " [" +
                                  ((DictionaryEntry)i.Current).Key + "] \"" +
                                  ((DictionaryEntry)i.Current).Value + "\"");
            i.MoveNext();
            Console.Out.WriteLine("Cursor should still be OK:" + " [" +
                                  ((DictionaryEntry)i.Current).Key + "] \"" +
                                  ((DictionaryEntry)i.Current).Value + "\"");
            Console.Out.WriteLine("Cursor should be done:" + i.MoveNext());

            i.Key = "key 4";
            Console.Out.WriteLine("Cursor should still be OK:" + " [" +
                                  ((DictionaryEntry)i.Current).Key + "] \"" +
                                  ((DictionaryEntry)i.Current).Value + "\"");
            i.MoveNext();
            Console.Out.WriteLine("Cursor should still be OK:" + " [" +
                                  ((DictionaryEntry)i.Current).Key + "] \"" +
                                  ((DictionaryEntry)i.Current).Value + "\"");
            Console.Out.WriteLine("Cursor should be done:" + i.MoveNext());

            i.Key = "key 2";
            i.MoveNext();
            i.MoveNext();
            i.Add("Row 3.5");
            i.Add("Row 3.6");
            show("Added some rows... should be 7", h1);

            i = h1.GetCursor("key 2");
            i.Add("Row 1.5");
            i.Add("key 1.7", "Row 1.7");
            i.Add("Row 1.9");
            Console.Out.WriteLine("Cursor should point to 2:" +
                                  ((DictionaryEntry)i.Current).Key);
            i.Key = "key 1.7";
            Console.Out.WriteLine("Cursor should point to 1.7:" +
                                  ((DictionaryEntry)i.Current).Key);
        }
Beispiel #22
0
        public void TestCursor()
        {
            Fits     f   = new Fits("testdocs\\ht1.fits");
            ImageHDU hdu = (ImageHDU)f.GetHDU(0);
            Header   hdr = hdu.Header;
            Cursor   c   = hdr.GetCursor();

            c.Key = "XXX";
            c.Add("CTYPE1", new HeaderCard("CTYPE1", "GLON-CAR", "Galactic Longitude"));
            c.Add("CTYPE2", new HeaderCard("CTYPE2", "GLAT-CAR", "Galactic Latitude"));

            c.Key = "CTYPE1";  // Move before CTYPE1
            c.Add("CRVAL1", new HeaderCard("CRVAL1", 0f, "Longitude at reference"));

            c.Key = "CTYPE2"; // Move before CTYPE2
            c.Add("CRVAL2", new HeaderCard("CRVAL2", -90f, "Latitude at reference"));

            c.Key = "CTYPE1";  // Just practicing moving around!!
            c.Add("CRPIX1", new HeaderCard("CRPIX1", 150.0, "Reference Pixel X"));

            c.Key = "CTYPE2";
            c.Add("CRPIX2", new HeaderCard("CRPIX2", 0f, "Reference pixel Y"));
            c.Add("INV2", new HeaderCard("INV2", true, "Invertible axis"));
            c.Add("SYM2", new HeaderCard("SYM2", "YZ SYMMETRIC", "Symmetries..."));

            Assertion.AssertEquals("CTYPE1", "GLON-CAR", hdr.GetStringValue("CTYPE1"));
            Assertion.AssertEquals("CRPIX2", 0f, hdr.GetDoubleValue("CRPIX2", -2f));


            c.Key = "CRVAL1";
            HeaderCard hc = (HeaderCard)((DictionaryEntry)c.Current).Value;

            c.MoveNext();
            Assertion.AssertEquals("CRVAL1_c", "CRVAL1", hc.Key);

            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            c.MoveNext();
            Assertion.AssertEquals("CRPIX1_c", "CRPIX1", hc.Key);

            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            c.MoveNext();
            Assertion.AssertEquals("CTYPE1_c", "CTYPE1", hc.Key);

            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            c.MoveNext();
            Assertion.AssertEquals("CRVAL2_c", "CRVAL2", hc.Key);

            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            c.MoveNext();
            Assertion.AssertEquals("CRPIX2_c", "CRPIX2", hc.Key);

            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            c.MoveNext();
            Assertion.AssertEquals("INV2_c", "INV2", hc.Key);

            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            c.MoveNext();
            Assertion.AssertEquals("SYM2_c", "SYM2", hc.Key);

            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            c.MoveNext();
            Assertion.AssertEquals("CTYPE2_c", "CTYPE2", hc.Key);


            hdr.FindCard("CRPIX1");
            hdr.AddValue("INTVAL1", 1, "An integer value");
            hdr.AddValue("LOG1", true, "A true value");
            hdr.AddValue("LOGB1", false, "A false value");
            hdr.AddValue("FLT1", 1.34, "A float value");
            hdr.AddValue("FLT2", -1.234567890e-134, "A very long float");
            hdr.AddValue("COMMENT", null, "Comment after flt2");


            c.Key = "INTVAL1";

            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            c.MoveNext();
            Assertion.AssertEquals("INTVAL1", "INTVAL1", hc.Key);

            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            c.MoveNext();
            Assertion.AssertEquals("LOG1", "LOG1", hc.Key);

            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            c.MoveNext();
            Assertion.AssertEquals("LOGB1", "LOGB1", hc.Key);

            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            c.MoveNext();
            Assertion.AssertEquals("FLT1", "FLT1", hc.Key);

            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            c.MoveNext();
            Assertion.AssertEquals("FLT2", "FLT2", hc.Key);

            c.MoveNext(); // Skip comment
            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            c.MoveNext();
            Assertion.AssertEquals("CRPIX1x", "CRPIX1", hc.Key);

            Assertion.AssertEquals("FLT1", 1.34, hdr.GetDoubleValue("FLT1", 0));


            c.Key = "FLT1";
            c.Remove();
            Assertion.AssertEquals("FLT1", 0f, hdr.GetDoubleValue("FLT1", 0));


            c.Key = "LOGB1";
            hc    = (HeaderCard)((DictionaryEntry)c.Current).Value;
            Assertion.AssertEquals("AftDel1", "LOGB1", hc.Key);
            c.MoveNext();

            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            Assertion.AssertEquals("AftDel2", "FLT2", hc.Key);
            c.MoveNext();

            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            Assertion.AssertEquals("AftDel3", "Comment after flt2", hc.Comment);
            c.MoveNext();

            f.Close();
        }