static AFElementTemplate CreateEventFrameTemplate(AFDatabase database) { AFElementTemplate eventFrameTemplate = database.ElementTemplates["Daily Usage"]; if (eventFrameTemplate != null) { return(eventFrameTemplate); } eventFrameTemplate = database.ElementTemplates.Add("Daily Usage"); eventFrameTemplate.InstanceType = typeof(AFEventFrame); eventFrameTemplate.NamingPattern = @"%TEMPLATE%-%ELEMENT%-%STARTTIME:yyyy-MM-dd%-EF*"; AFAttributeTemplate usage = eventFrameTemplate.AttributeTemplates.Add("Average Energy Usage"); usage.Type = typeof(Single); usage.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(); usage.ConfigString = @".\Elements[.]|Energy Usage;TimeRangeMethod=Average"; usage.DefaultUOM = database.PISystem.UOMDatabase.UOMs["kilowatt hour"]; if (database.IsDirty) { database.CheckIn(); } return(eventFrameTemplate); }
private void AddAttributes(AFDatabase afDatabase, AFEventFrame eventFrame) { try { // random number generator, to create different attributes for each event frames var randomGen = new Random(DateTime.Now.Millisecond); // creates an int attribute on the event frame var attribute = eventFrame.Attributes.Add("Value1"); attribute.Type = typeof(int); attribute.SetValue(new AFValue(randomGen.Next(10, 1000))); // double attribute attribute = eventFrame.Attributes.Add("Value2"); attribute.Type = typeof(double); attribute.SetValue(new AFValue(randomGen.Next(10, 1000))); // here we are adding a tag that is normally present on all PI Data Archive Servers. // to show how to add a PIPoint data reference attribute attribute = eventFrame.Attributes.Add("Value3"); attribute.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(afDatabase.PISystem); attribute.ConfigString = @"\\optimus\sinusoid"; } catch (Exception ex) { Logger.Warn("Error when adding demonstration attributes to the event frame.", ex); } }
private void CreateTemplates(AFDatabase afDatabase) { AFElementTemplate elemTemplate = afDatabase.ElementTemplates.Add("BasicBoilerTemplate"); AFAttributeTemplate attrTemplate_Temperature = elemTemplate.AttributeTemplates.Add("Temperature"); AFAttributeTemplate attrTemplate_Pressure = elemTemplate.AttributeTemplates.Add("Pressure"); AFAttributeTemplate attrTemplate_Limit = elemTemplate.AttributeTemplates.Add("Limit"); AFAttributeTemplate attrTemplate_Mode = elemTemplate.AttributeTemplates.Add("Mode"); attrTemplate_Temperature.Type = typeof(float); attrTemplate_Pressure.Type = typeof(float); attrTemplate_Limit.Type = typeof(string); AFEnumerationSet modes = afDatabase.EnumerationSets["Modes"]; attrTemplate_Mode.TypeQualifier = modes; attrTemplate_Temperature.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(afDatabase.PISystem); attrTemplate_Pressure.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(afDatabase.PISystem); attrTemplate_Mode.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(afDatabase.PISystem); attrTemplate_Temperature.ConfigString = @"%Database%.%..\Element%.%Element%.%Attribute%;ptclassname=classic;pointtype=float32;"; attrTemplate_Pressure.ConfigString = @"%Database%.%..\Element%.%Element%.%Attribute%;ptclassname=classic;pointtype=float32;"; attrTemplate_Mode.ConfigString = @"%Database%.%..\Element%.%Element%.%Attribute%;ptclassname=classic;pointtype=digital;digitalset=modes;"; // Do a bulk check in of all changes made so far. afDatabase.CheckIn(); }
public static void CreateTags(AFElement element) { var newTags = AFDataReference.CreateConfig(element, true, (obj, afProgressEventArgs) => { // here report progess if needed }); Logger.InfoFormat("{1} Tags Created for new element {0}", element.Name, newTags); }
public static AFAttributeTemplate AddTimeSeries(this AFElementTemplate template, Resolution resolution, ValueType valueType) { var name = GetAttributeName(resolution, valueType); var attribute = template.AttributeTemplates.Add(name); attribute.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(template.Database.PISystem); attribute.ConfigString = $@"\\%Server%\%Element%.{name}"; attribute.Type = typeof(float); return(attribute); }
/// <summary> /// Method that creates an AF Attribute on an AF Element /// </summary> /// <param name="element">AFElement object</param> /// <param name="type">Type of attribute to create</param> /// <param name="name">name of the new attribute that will be created</param> /// <param name="value">Depending on the type of attribute created, the value can be either a scalar value or the ConfigString Value</param> public void CreateAttribute(AFElement element, AttributeTypeEnum type, string name, string value) { var piSystem = element.PISystem; var attribute = element.Attributes.Add(name); Logger.InfoFormat("Creating attribute {0}", (name)); switch (type) { // AFCreateAttribute -e \\tst-srv\db1\AFSDKExamples\CreateAttributes -n Attribute1 -v 10 -t AttDouble case AttributeTypeEnum.AttDouble: attribute.Type = typeof(double); attribute.SetValue(new AFValue(double.Parse(value))); break; // AFCreateAttribute -e \\tst-srv\db1\AFSDKExamples\CreateAttributes -n Attribute2 -v \\tst-srv\sinusoid -t AttPIPoint case AttributeTypeEnum.AttPIPoint: attribute.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(piSystem); attribute.ConfigString = value; break; // AFCreateAttribute -e \\tst-srv\db1\AFSDKExamples\CreateAttributes -n Attribute2 -v "SELECT Name FROM Info WHERE Version = 1.5" -t AttTableLookup case AttributeTypeEnum.AttTableLookup: attribute.DataReferencePlugIn = piSystem.DataReferencePlugIns["Table Lookup"]; attribute.Type = typeof(string); // if a specific type is needed, you'll need to pass it and set it here. attribute.ConfigString = value; break; // AFCreateAttribute -e \\tst-srv\db1\AFSDKExamples\CreateAttributes -n Attribute2 -v "\\optimus\CDT158|sinusoid" -t AttPIPointArray case AttributeTypeEnum.AttPIPointArray: attribute.DataReferencePlugIn = piSystem.DataReferencePlugIns["PI Point Array"]; attribute.ConfigString = value; break; // AFCreateAttribute -e \\tst-srv\db1\AFSDKExamples\CreateAttributes -n Attribute2 -v "B=double;[B*10]" -t AttFormula case AttributeTypeEnum.AttFormula: attribute.DataReferencePlugIn = piSystem.DataReferencePlugIns["Formula"]; attribute.ConfigString = value; break; // AFCreateAttribute -e \\tst-srv\db1\AFSDKExamples\CreateAttributes -n Attribute2 -v "Hello ;World" -t AttStringBuilder case AttributeTypeEnum.AttStringBuilder: attribute.DataReferencePlugIn = piSystem.DataReferencePlugIns["String Builder"]; attribute.ConfigString = value; break; } Logger.Info("Checking in the changes"); element.CheckIn(); Logger.Info("Attibute Created"); }
private void CreatePIPoints(AFDatabase afDatabase) { AFElementTemplate elemTemplate = afDatabase.ElementTemplates["BasicBoilerTemplate"]; AFNamedCollectionList <AFBaseElement> baseElements = elemTemplate.FindInstantiatedElements( includeDerived: false, sortField: AFSortField.Name, sortOrder: AFSortOrder.Ascending, maxCount: 1000); foreach (AFBaseElement baseElement in baseElements) { int numModified = AFDataReference.CreateConfig(baseElement, false, null); Console.WriteLine("Modified or created: {0}", numModified); } }
private void CreateEventFrameTemplate(AFDatabase afDatabase) { AFElementTemplate efTemplate = afDatabase.ElementTemplates.Add("BasicEventFrameTemplate"); // Specify that this is an Event Frame Template. efTemplate.InstanceType = typeof(AFEventFrame); AFAttributeTemplate tempAttr = efTemplate.AttributeTemplates.Add("Maximum temperature"); tempAttr.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(afDatabase.PISystem); AFAttributeTemplate pressAttr = efTemplate.AttributeTemplates.Add("Maximum pressure"); pressAttr.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(afDatabase.PISystem); tempAttr.ConfigString = @".\Elements[.]|Temperature;TimeMethod=NotSupported;TimeRangeMethod=Maximum"; pressAttr.ConfigString = @".\Elements[.]|Pressure;TimeMethod=NotSupported;TimeRangeMethod=Maximum"; // Do a bulk check in of all changes made so far. afDatabase.CheckIn(); }
//'<filename:Constructor> public DataReferenceConfigUI(AFDataReference dataReference, bool bReadOnly) : base() { // Required for Windows Form Designer support InitializeComponent(); // save for persistence this.dataReference = dataReference; if (bReadOnly) { btnOK.Visible = false; btnOK.Enabled = false; btnCancel.Left = (btnOK.Left + btnCancel.Left) / 2; btnCancel.Text = "Close"; this.AcceptButton = btnCancel; // Set ReadOnly stuff // txtMW.ReadOnly = true; } // Initialize the text field(s) of the Configuration Dialog // this.txtMW.Text = dataReference.MolecularWeight.ToString(CultureInfo.CurrentCulture); }
/// <summary> /// Create the AF Database, Element Templates, and Attribute Templates. /// </summary> private void CreateAFTemplates() { // Check if PI System exists. PISystem targetPISystem = new PISystems()[_conf.AFServerName]; if (targetPISystem == null) { Console.WriteLine("AF server does not exist"); Environment.Exit(0); } // Check if AF Database exists. If so, delete it and recreate it to start anew. _afContext = new AFContext(); _afContext.Database = targetPISystem.Databases[_conf.AFDatabaseName]; if (_afContext.Database != null) { Console.Write(string.Format(@"AF Database {0} already exists. " + @"Press Y to remove and recreate the database, " + @"N to quit the program and specify a different database name : ", _conf.AFDatabaseName)); while (true) { ConsoleKeyInfo result = Console.ReadKey(); Console.WriteLine("\n"); if ((result.KeyChar == 'Y') || (result.KeyChar == 'y')) { targetPISystem.Databases.Remove(_afContext.Database); break; } else if ((result.KeyChar == 'N') || (result.KeyChar == 'n')) { Environment.Exit(0); } Console.Write("Invalid input, try again (Y/N) : "); } } _afContext.Database = targetPISystem.Databases.Add(_conf.AFDatabaseName); // Create the Enumeration Set. AFEnumerationSet modes = _afContext.Database.EnumerationSets.Add("Modes"); modes.Add("Manual", 0); modes.Add("Auto", 1); modes.Add("Cascade", 2); modes.Add("Program", 3); modes.Add("Prog-Auto", 4); // Create element templates for SubTree and Branch elements. AFElementTemplate subTree_ElemTmp = _afContext.Database.ElementTemplates.Add(Constants.SUBTREE); AFElementTemplate branch_ElemTmp = _afContext.Database.ElementTemplates.Add(Constants.BRANCH); AFAttributeTemplate subtree_Rollup_AttrTmp = subTree_ElemTmp.AttributeTemplates.Add(Constants.ROLLUP_SUM_ATTRIBUTE); AFAttributeTemplate branch_Rollup_AttrTmp = branch_ElemTmp.AttributeTemplates.Add(Constants.ROLLUP_SUM_ATTRIBUTE); AFAttributeTemplate threshold_AttrTmp = branch_ElemTmp.AttributeTemplates.Add(Constants.THRESHOLD_ATTRIBUTE); subtree_Rollup_AttrTmp.Type = typeof(float); branch_Rollup_AttrTmp.Type = typeof(float); threshold_AttrTmp.Type = typeof(int); AFPlugIn _piPointDR = AFDataReference.GetPIPointDataReference(targetPISystem); subtree_Rollup_AttrTmp.DataReferencePlugIn = _piPointDR; branch_Rollup_AttrTmp.DataReferencePlugIn = _piPointDR; string serverPath = @"\\" + _conf.PIServerName + @"\"; subtree_Rollup_AttrTmp.ConfigString = serverPath + @"HighAsset_%Element%_Total"; branch_Rollup_AttrTmp.ConfigString = serverPath + @"HighAsset_%Element%_Total"; threshold_AttrTmp.SetValue(_conf.ThresholdValue, null); // Create element templates for Leaf elements. _afContext.BaseLeafTemplate = _afContext.Database.ElementTemplates.Add(Constants.LEAF); _afContext.SinusoidLeafTemplate = _afContext.Database.ElementTemplates.Add(Constants.LEAF_SIN); _afContext.RandomLeafTemplate = _afContext.Database.ElementTemplates.Add(Constants.LEAF_RAND); _afContext.SinusoidLeafTemplate.BaseTemplate = _afContext.BaseLeafTemplate; _afContext.RandomLeafTemplate.BaseTemplate = _afContext.BaseLeafTemplate; // Add attribute templates for base leaf Element Templates. AFAttributeTemplate subtree_AttrTmp = _afContext.BaseLeafTemplate.AttributeTemplates.Add(Constants.SUBTREE); AFAttributeTemplate branch_AttrTmp = _afContext.BaseLeafTemplate.AttributeTemplates.Add(Constants.BRANCH); AFAttributeTemplate ID_AttrTmp = _afContext.BaseLeafTemplate.AttributeTemplates.Add(Constants.LEAF_ID); AFAttributeTemplate value_AttrTmp = _afContext.BaseLeafTemplate.AttributeTemplates.Add("Value"); AFAttributeTemplate mode_AttrTmp = _afContext.BaseLeafTemplate.AttributeTemplates.Add("Mode"); subtree_AttrTmp.Type = typeof(string); branch_AttrTmp.Type = typeof(string); ID_AttrTmp.Type = typeof(string); value_AttrTmp.Type = typeof(float); value_AttrTmp.DataReferencePlugIn = _piPointDR; mode_AttrTmp.DataReferencePlugIn = _piPointDR; mode_AttrTmp.TypeQualifier = modes; mode_AttrTmp.SetValue(modes["Manual"], null); mode_AttrTmp.ConfigString = serverPath + @"HighAsset_%Element%_Mode; ptclassname=classic; pointtype=digital; digitalset=modes; pointsource=R; location1=0; location4=3; location5=1"; // Add attribute templates for sinusoid leaf Element Templates. AFAttributeTemplate value_sinusoid_AttrTmp = _afContext.SinusoidLeafTemplate.AttributeTemplates.Add("Value"); value_sinusoid_AttrTmp.Type = typeof(double); value_sinusoid_AttrTmp.DataReferencePlugIn = _piPointDR; value_sinusoid_AttrTmp.ConfigString = serverPath + @"HighAsset_%Element%_Sinusoid; ptclassname=classic; pointtype=float32; pointsource=R; location1=0; location4=3; location5=0"; // Add attribute templates for random leaf Element Templates. AFAttributeTemplate value_random_AttrTmp = _afContext.RandomLeafTemplate.AttributeTemplates.Add("Value"); value_random_AttrTmp.Type = typeof(double); value_random_AttrTmp.DataReferencePlugIn = _piPointDR; value_random_AttrTmp.ConfigString = serverPath + @"HighAsset_%Element%_Random; ptclassname=classic; pointtype=float32; pointsource=R; location1=0; location4=3; location5=1"; // Create container element under which all leaf elements will be stored. _afContext.Database.Elements.Add("LeafElements"); // Do a bulk checkin of all changes made so far. _afContext.Database.CheckIn(AFCheckedOutMode.ObjectsCheckedOutThisThread); }