8 Replies Latest reply: Jan 12, 2015 12:58 AM by Lars-Goran Book RSS

    Help converting Engine API Request to .NET API

      Hi all,

       

      Let's say I have the following engine API request:

       

      {
        "jsonrpc": "2.0",
        "id": 1,
        "method": "CreateSessionObject",
        "handle": 1,
        "params": [
          {
            "meta": {
              "data": "this is the data",
              "qValueExpression": "=COUNT(CategoryName)"
            },
            "qInfo": {
              "qId": "",
              "qType": "Listbox"
            },
            "qListObjectDef": {
              "qInitialDataFetch": [
                {
                  "qTop": 0,
                  "qLeft": 1,
                  "qHeight": 1,
                  "qWidth": 1
                }
              ]
            }
          }
        ]
      }
      

       

      How could I do something similar with the .NET SDK?  I've got an open session, and an IApp instance

       

      Thanks and regards,

      Shane.

        • Re: Help converting Engine API Request to .NET API

          Can anyone help me with this one please?  Thanks, and a Happy New Year to you all.

          • Re: Help converting Engine API Request to .NET API
            Lars-Goran Book

            Hi Shane,

            The App object has a method CreateGenericSessionObject which you can use to create session objects. It takes a parameter of GenericObjectProperties. I would suggest that you create a set of classes for your object :

            MyObjectProperties, MyObjectLayout and MyObject.

             

            The MyObjectProperties should inherit from GenericObjectProperties and to this object you can add your custom properties.

            public class MyObjectProperties : Qlik.Engine.GenericObjectProperties
            {
              public Qlik.Engine.ListObjectDef qListObjectDef
              {
                get { return this.Get<Qlik.Engine.ListObjectDef>("qListObjectDef"); }
                set { this.Set("qListObjectDef", value); }
              }
            }

             

            The MyObjectLayout should inherit from GenericObjectLayout which describes the rendered object (layout).

            public class MyObjectLayout : Qlik.Engine.GenericObjectLayout
            {
              public Qlik.Engine.ListObject qListObject
              {
                get { return this.Get<Qlik.Engine.ListObject>("qListObject"); }
                set { this.Set("qListObject", value); }
              }
            }

             

            The MyObject should inherit from GenericObject, this class holds properties and layout for the object. To this class you can later add support for paging, selections etc.

            public class MyObject : Qlik.Engine.GenericObject, System.IDisposable
            {
              public MyObject(int handle) : base(handle)
              {
              }

              public new MyObjectProperties Properties
              {
                get { return ((MyObjectProperties)(base.Properties)); }
                set { base.Properties = value; }
              }

              protected new MyObjectLayout Layout
              {
                get { return ((MyObjectLayout)(base.Layout)); }
              }

              private bool _disposed;
              #region IDisposable methods
              protected override void Dispose(bool disposing)
              {
                if (this._disposed)
                {
                  return;
                }
                this._disposed = true;
                base.Dispose(disposing);
              }
              #endregion

             

             

            }

             

            To create a object create your properties and call CreateGenericSessionObject.

            var prop = new MyObjectProperties
            {
              Info = { Id = "TheBest", Type = "mylistbox" },
              qListObjectDef = new ListObjectDef
              {
                Def = new NxInlineDimensionDef { FieldDefs = new string[] { "Dim2" } },
                InitialDataFetch = new NxPage[] {new NxPage{ Height = 100, Left = 0, Top = 0, Width = 1}}
              }
            };
            var mylb = (MyObject)App.CreateGenericSessionObject(prop);

             

            On the created object call GetLayout to get the rendered information

            var l = (MyObjectLayout)mylb.GetLayout();

            And now you can access the the data/properties within the object
            var datapages = l.qListObject.DataPages

             

            Best regards

            Lars-Göran Book