This project is read-only.
1
Vote

Converting to VB.NET

description

Hi,
 
I've tried to convert the code to VB, but it seems I missed something.
When I try to store a file, only the first 5Kb is stored.
 
I think the problem is situated in this function:
Public Shared Function GetNewDataPage(ByVal basePage As DataPage, ByVal engine As Engine) As DataPage
    If basePage.NextPageID <> UInteger.MaxValue Then
        PageFactory.WriteToFile(basePage, engine.Writer)
        ' Salvo a pagina antiga em disco
        Dim dataPage As DataPage = PageFactory.GetDataPage(basePage.NextPageID, engine.Reader, False)
        '*var dataPage = engine.GetPageData(basePage.NextPageID);
 
        engine.Header.FreeDataPageID = dataPage.NextPageID
 
        If engine.Header.FreeDataPageID = UInteger.MaxValue Then
            engine.Header.LastFreeDataPageID = UInteger.MaxValue
        End If
 
        Return dataPage
    Else
        Dim pageID As Integer = System.Threading.Interlocked.Increment(CType(engine.Header.LastPageID, Integer))
        Dim newPage As New DataPage(CType(pageID, UInteger))
        basePage.NextPageID = newPage.PageID
        PageFactory.WriteToFile(basePage, engine.Writer)
        ' Salvo a pagina antiga em disco
        Return newPage
    End If
End Function
 
 
Maybe on this line :
VB.NET : Dim pageID As Integer = System.Threading.Interlocked.Increment(CType(engine.Header.LastPageID, Integer))
C# : var pageID = ++engine.Header.LastPageID;
 
In your code in C#:
 
    // Take a new data page on sequence and update the last
    public static DataPage GetNewDataPage(DataPage basePage, Engine engine)
    {
        if (basePage.NextPageID != uint.MaxValue)
        {
            PageFactory.WriteToFile(basePage, engine.Writer); // Write last page on disk
 
            var dataPage = PageFactory.GetDataPage(basePage.NextPageID, engine.Reader, false);
 
            engine.Header.FreeDataPageID = dataPage.NextPageID;
 
            if (engine.Header.FreeDataPageID == uint.MaxValue)
                engine.Header.LastFreeDataPageID = uint.MaxValue;
 
            return dataPage;
        }
        else
        {
            var pageID = ++engine.Header.LastPageID;
            DataPage newPage = new DataPage(pageID);
            basePage.NextPageID = newPage.PageID;
            PageFactory.WriteToFile(basePage, engine.Writer); // Write last page on disk
            return newPage;
        }
    }
 
Could you have a look at this? I've uploaded the VB code as a patch.
 
Any help would be much appreciated!!
 
Greetz Kraeven

comments