5 Replies Latest reply on May 31, 2017 8:14 PM by Gael

    Custom DR and context object is null

    Gael

      Hello PI Square,

       

      I am developing a custom DR and I get the following problem:

      • the context object is null in "
        public override AFAttributeList GetInputs(object context)
      • both objects timecontext and context are null in:

       

       override AFValue GetValue(object context, object timeContext, AFAttributeList inputAttributes, AFValues inputValues)
      

       

       

       

       

      I have overridden the following procedure:

       

      public override AFDataReferenceContext SupportedContexts
      
      {get
      {return AFDataReferenceContext.All;}
      }
      

       

      Any help and inputs will be very appreciated.

      Gael

       

        • Re: Custom DR and context object is null
          Rick Davin

          Hello Gael,

           

          It's acceptable for the contexts to be nulls.  Can you describe the behavior that is causing you an issue?  Is there an error message, or are you just not getting the right values back?

           

          It would help to know your AF SDK version as well as language, so we can maybe give C# or VB.NET examples if need be.

           

          It may help to share some of your code, if possible.

            • Re: Custom DR and context object is null
              Gael

              Hello Rick,

               

              Thanks for the support. I am using AF SDK 2.7.5.7166 (2015 R2), developed in C#.

               

              I was expecting that the timecontext would be an AFTime matching the date passed to the getvalue.

              If the timecontext is null, does this mean "Current Time"?

               

              thanks

                • Re: Custom DR and context object is null
                  Gael

                  Ok Rick, I got my answer.

                   

                  I have launched PSE using the debug and change a query date. The timecontext is then correctly set to a AFTime.

                   

                  Sorry for my misunderstanding.

                  gael

                  • Re: Custom DR and context object is null
                    Rick Davin

                    A null timeContext means what you want it to mean.  But yes, typically, you would most likely want it to mean Current Time.

                     

                    With my DR's I typically considered 3 possibilities for the timeContext:

                    1. A null
                    2. An AFTimeRange
                    3. An AFTime

                     

                    Here again you have the decision to make on how to treat a time range for your GetValue() to return a value at ONE timestamp.  Do you want to use the StartTime or EndTime?  Your call.  Here's a snippet of code:

                     

                    AFTime timestamp;
                    if (timeContext is AFTime)
                      timestamp = (AFTime)timeContext;
                    else if (timeContext is AFTimeRange)
                      timestamp = ((AFTimeRange)timeContext).EndTime;
                    else // null or otherwise
                      timestamp = AFTime.Now.ToPIPrecision();
                    // Your DR should output value at timestamp
                    
                    1 of 1 people found this helpful