Esempio n. 1
0
        /// <summary>
        ///     This method will be called by SqlRace framework.
        /// </summary>
        /// <param name="functionManager"></param>
        public void Initialize(IFunctionManager functionManager)
        {
            // create the function definition
            var functionDefinition = functionManager.CreateFunctionDefinition(DotNetFunctionConstants.UniqueId, FunctionMode.Instantaneous, CalculationModeInfoDefinition.EachSamplePoint());

            //var functionDefinition = functionManager.CreateFunctionDefinition(DotNetFunctionConstants.UniqueId);
            functionDefinition.CalculateOverWholeSession = false;
            functionDefinition.InterpolateBetweenSamples = false;
            functionDefinition.JoinGapsAroundNull        = false;
            functionDefinition.Name           = FunctionName;
            functionDefinition.StoreInSession = false;

            // set the implementation
            var implementationDefinition = (DotNetFunctionImplementationDefinition)functionDefinition.ImplementationDefinition;

            implementationDefinition.Function = this;

            // create the single output parameter
            functionDefinition.OutputParameterDefinitions.Add(
                new FunctionOutputParameterDefinition
            {
                ApplicationName = ApplicationName,
                ByteOrder       = ByteOrderType.BigEndian,
                Description     = "HelloDotNet.vCarDoubled",
                FormatOverride  = @"%5.2f",
                Name            = ParameterName,
                Units           = "km/h",
                MaximumValue    = "800",
                MinimumValue    = "0",
                ShowInBrowser   = true
            });

            functionDefinition.InputParameterIdentifiers.Add("vCar:Chassis");

            // build the function
            var buildResults = functionManager.Build(functionDefinition);

            // make sure we have no build errors
            if (buildResults.Errors.Count > 0)
            {
                Console.WriteLine($"Error building DotNet function '{FunctionName}': {buildResults.Errors.FirstOrDefault()?.ErrorText}.");
            }
            else
            {
                Console.WriteLine($"DotNet function '{FunctionName}' created successfully.");
            }
        }
        public static IFunctionDefinition CreateFdlFunctionDefinition(IFunctionManager functionManager, FunctionMode functionMode = FunctionMode.Instantaneous)
        {
            //Create function
            const string CarSpeedDoubledInFdl = "return ($vCar:Chassis * 2)";

            var functionDefinition = functionManager.CreateFunctionDefinition(FdlFunctionConstants.UniqueId);

            // The implementation of a function is completely agnostic. We requested a function definition from
            // the FDL runtime, so the generic function implementation definition in the definition returned can
            // be safely cast to the more specific FDL implementation definition.
            var fdlFunctionImplementationDefinition = (IFdlFunctionImplementationDefinition)functionDefinition.ImplementationDefinition;

            fdlFunctionImplementationDefinition.FunctionCode = CarSpeedDoubledInFdl;

            // FDL doesn't define the output for a single parameter - it's simply the return value of the
            // function - so we have to tell the function executor what to do with the output it generates
            var outputParameter = FunctionOutputParameterDefinition
                                  .Create("vCarDoubled", "FunctionParameters", "Double car speed!")
                                  .Units("kph")
                                  .FormatOverride("%.2f")
                                  .MinimumValue("0.0")
                                  .MaximumValue("700.0");

            functionDefinition.OutputParameterDefinitions.Add(outputParameter);

            // Functions in ATLAS 9 have a number of different properties that define how, where, when and on
            // what a function executes. ATLAS 10 will add more of these properties. Each value here is the
            // default for its property, shown for illustration.
            functionDefinition.Name         = $"DoubleCarSpeed_{Environment.TickCount}";
            functionDefinition.FunctionMode = functionMode;
            functionDefinition.CalculationModeInfoDefinition.Mode = CalculationMode.EachSamplePoint;
            functionDefinition.InterpolateBetweenSamples          = false;
            functionDefinition.JoinGapsAroundNull        = true;
            functionDefinition.CalculateOverWholeSession = false;
            functionDefinition.StoreInSession            = false;
            functionDefinition.ShouldHide    = false;
            functionDefinition.ShouldPersist = false;

            return(functionDefinition);
        }