Announcement

Collapse
No announcement yet.

Returning a List(Of Structure) to a Feature Page

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Returning a List(Of Structure) to a Feature Page

    I'm struggling to get a consistent result returning a list of custom structures to a feature page from my plugin.

    I put this code together to try to demonstrate the issue:
    Code:
    <Serializable()> Public Structure TestStructure
            Dim element1 As String
            Dim element2 As String
            Dim element3 As String
            Dim element4 As String
            Dim element5 As String
    End Structure
    
    Public Function ext_TestStructure(ByVal NumElements As String) As List(Of TestStructure)
            Console.WriteLine("ext_TestStructure...")
    
            Dim RetList As New List(Of TestStructure)
    
            For n As Integer = 1 To CInt(NumElements)
                Dim TestVar As New TestStructure
    
                TestVar.element1 = "Element1" & n.ToString & ")"
                TestVar.element2 = "Element2" & n.ToString & ")"
                TestVar.element3 = "Element3" & n.ToString & ")"
                TestVar.element4 = "Element4(" & n.ToString & ")"
                TestVar.element5 = "Element5(" & n.ToString & ")"
    
                RetList.Add(TestVar)
            Next
    
            Console.WriteLine("ext_TestStructure... returning " & RetList.Count.ToString & " items")
    
            Return RetList
        End Function
    When I call the function from an html feature page with:
    Code:
    [B]{{[/B]list=plugin_function 'drhsIR' 'ext_TestStructure' ['5'][B]}}[/B]
    [B]{{[/B][B]for[/B] item in list[B]}}[/B]
    [B]{{[/B]item.element1[B]}}[/B] [B]{{[/B]item.element2[B]}}[/B] [B]{{[/B]item.element3[B]}}[/B] [B]{{[/B]item.element4[B]}}[/B] [B]{{[/B]item.element5[B]}}[/B]
    [B]{{[/B]end[B]}}[/B]
    On some pages I get some of the elements, on others I get none of the elements and in some cases, the page causes HomeSeer to hang and I have to kill the plugin's .exe.

    What am I missing? Is there a recommended way to return a custom list to a feature page?

    -David


    #2
    Further troubleshooting has only made me even more confused. I'm missing something but I don't know what! Two seemingly identical functions. One works as expected, the other causes Homeseer to get stuck trying to load the feature page.
    Code:
     <Serializable()> Public Structure St_IR_Code
            Dim Name As String
            Dim Code As String
        End Structure
    
     <Serializable()> Public Structure TestStructure
            Dim Name As String
            Dim Code As String
        End Structure
    
    Public Function ext_Test01() As List(Of St_IR_Code)
        Dim TestVar As New St_IR_Code
        TestVar.Code = "code"
        TestVar.Name = "name"
        Dim RetStruct As New List(Of St_IR_Code)
        RetStruct.Add(TestVar)
        Return RetStruct
    End Function
    
    Public Function ext_Test02() As List(Of TestStructure)
        Dim TestVar As New TestStructure
        TestVar.Code = "code"
        TestVar.Name = "name"
        Dim RetStruct As New List(Of TestStructure)
        RetStruct.Add(TestVar)
        Return RetStruct
    End Function
    This html works (displays a single "Hello World"):
    Code:
    [B]{{[/B] list=plugin_function 'drhsIR' 'ext_Test01' [] [B]}}[/B]
    [B]{{[/B] [B]for[/B] item in list [B]}}[/B]
            Hello world
    [B]{{[/B] end [B]}}[/B]
    This html doesn't work (browser waits indefinitely unable to load page):
    Code:
    [B]{{[/B] list=plugin_function 'drhsIR' 'ext_Test02' [] [B]}}[/B]
    [B]{{[/B] [B]for[/B] item in list [B]}}[/B]
            Hello world
    [B]{{[/B] end [B]}}[/B]
    It's making my head hurt!
    -David

    Comment


      #3
      have you tried to only use lowercase ? Seem to recall something with liquid tags and how it does this funny conversion of uppercase characters,

      Comment


        #4
        Originally posted by dcorsus View Post
        have you tried to only use lowercase ? Seem to recall something with liquid tags and how it does this funny conversion of uppercase characters,
        Thanks for the suggestion. I just tried switching to all lowercase but still get the same result. :-( The function ext_test01 works but ext_test02 does not. Very puzzling!

        Comment


          #5
          The only difference I can see is that you are using underscores in Test01. Have you tried changing to something without?
          Jon

          Comment


            #6
            Originally posted by jon00 View Post
            The only difference I can see is that you are using underscores in Test01. Have you tried changing to something without?
            Thanks Jon! Test01 with the underscores is the one that is working. I just tried removing the underscores and it broke - restored the underscores and it works again. Adding underscores to Test02 didn't make any difference, it doesn't work either way.

            For more testing, I'm putting together a simple plugin that will have nothing except a feature page. I.e., stripped out of all the other functions that are in the plugin I am working on. Will report back shortly.

            Comment


              #7
              I turned everything in lower caps, including structure name and all its fields. I think the fact that the underscore makes it work or breaks it, I would think it is your hint. Seem to recall that an uppercase gets converted to a lower case and underscore ....

              Comment


                #8
                OK, testing with a simple plugin that only has a Feature Page and nothing else. So far, case and underscores don't seem to be critical, although I think I'm going to stick with all lowercase and no underscores from now on anyway.

                What I have discovered is that if I start with a Structure that has for instance, two elements, it all runs fine. If I add a third element, the webpage sits there indefinitely waiting to load. Stopping and restarting the plugin makes no difference but if I stop and restart Homeseer, then the plugin and the webpage load OK, with all three elements. It seems so far, that if I change the size of the structure, I have to restart Homeseer, not just the plugin.

                I need to test this with the original plugin next...

                BTW, I'm running HS 4.0.5.0, on Raspbian Buster, with Mono 6.8.0.105. Happy to share the source code of my simple test plugin.

                Thanks for the help! I think I'm almost at the bottom of this now.

                -David

                Comment


                  #9
                  Thanks everybody for the help, hints and suggestions. I'm back in business. Case sensitivity is an issue, sort of.

                  This doesn't work:
                  Code:
                  <Serializable()> Public Structure TestStructure
                          Dim IpAddress As String
                          Dim IpPort As String
                      End Structure
                  but this does:
                  Code:
                  <Serializable()> Public Structure TestStructure
                          Dim Ipaddress As String
                          Dim Ipport As String
                      End Structure
                  The case of the initial letter of the element doesn't matter but the other letters must all be lowercase. The case used in the structure's name isn't important.

                  What got me tied in knots was that when switching from example one to example two, it is not enough to restart the plugin, you have to restart Homeseer. If you only restart the plugin, the feature page will not load and Homeseer will become unresponsive. Same applies if you add or remove elements from the structure, you must restart Homeseer. Presumably something gets cached the first time you load the feature page?

                  -David

                  Comment


                    #10
                    I tried this out earlier and it caused me all kinds of problems in development, because once HS loaded the assembly, it wouildn't let it go without a restart, so iterative testing was a massive PITA. So I switched to always using a native type (I used KeyValuePair, with value being a delimited string that I could split with the liquid tags).

                    Comment

                    Working...
                    X