fdeserres

PI Notification creation c# and AFSDK

Discussion created by fdeserres Employee on Jul 23, 2014
Latest reply on Oct 8, 2014 by Mike Zboray

Hi,

 

I'm currently trying to create a new PI Notification in AFSDK and I get stuck at the AFAnalysisRule creation. I've followed the example found in the PI Notifications Programmer's Guide and the trigger (a simple comparison) just won't get created in the notifcations... here's the code I've created so far for this:

 

 

 
//Create Analysis
            AFAnalysis NotifAnalysis = new AFAnalysis(SelectedDatabase, "TestAnalysis");
            NotifAnalysis.Target = TestOSIsoft;

            string Guid1 = Guid.NewGuid().ToString();
            string Guid2 = Guid.NewGuid().ToString();

            //Create Root Analysis Rule
            NotifAnalysis.AnalysisRulePlugIn = SelectedPISystem.AnalysisRulePlugIns["ConditionGroup"];
            AFAnalysisRule conditionGroup = NotifAnalysis.AnalysisRule;


            //Create Analysis Rule
           
            AFAnalysisRule firstCondition = SelectedPISystem.AnalysisRulePlugIns["Sequential"].CreateAnalysisRuleInstance(NotifAnalysis, null);    
            conditionGroup.AnalysisRules.Add(firstCondition);            
            firstCondition.ConfigString = string.Concat("mappednames=", Guid1, "|", Guid2);            
            AFAnalysisRule comparisonRule = SelectedPISystem.AnalysisRulePlugIns["Comparison"].CreateAnalysisRuleInstance(NotifAnalysis, null);          
            firstCondition.AnalysisRules.Add(comparisonRule);          
            comparisonRule.ConfigString = "Deadband=0;Operator=LessThan;TargetValue=50;Targetvaluetype=Numeric;";           
            comparisonRule.MapVariable("Input", "TestAttribute");
            comparisonRule.MapVariable("Output", Guid1);
            AFAnalysisRule timeTrue = SelectedPISystem.AnalysisRulePlugIns["TimeTrue"].CreateAnalysisRuleInstance(NotifAnalysis, null);
            firstCondition.AnalysisRules.Add(timeTrue);
            timeTrue.ConfigString = "EvaluationOption=Clock;TimeTrueValue=0";
            timeTrue.MapVariable("Input", Guid1);
            timeTrue.MapVariable("Output", Guid2);
            AFAnalysisRule stateRule = SelectedPISystem.AnalysisRulePlugIns["StateAndPriority"].CreateAnalysisRuleInstance(NotifAnalysis, null);
            firstCondition.AnalysisRules.Add(stateRule);
            stateRule.ConfigString = "code=1; priority=Normal";
            stateRule.MapVariable("Input", Guid2);

            //Setup Time Rule
            NotifAnalysis.ApplyChanges();
            NotifAnalysis.TimeRulePlugIn = SelectedPISystem.AnalysisRulePlugIns["Natural"];

            //Create the Test Notification
            AFNotification TestNotification = new AFNotification(SelectedDatabase,"TestNotification");
            TestNotification.Analysis = NotifAnalysis;

            //Checkin Everything
            TestNotification.CheckIn();
            NotifAnalysis.CheckIn();
            SelectedDatabase.CheckIn();

Any help would be greatly appreciate!

 

thanks,

 

Félix

Outcomes