Пример #1
0
        private static AFElementTemplate CreateMeterBasicTemplate(AFDatabase database)
        {
            AFElementTemplate meterBasicTemplate = database.ElementTemplates["MeterBasic"];

            if (meterBasicTemplate != null)
            {
                return(meterBasicTemplate);
            }

            UOM              uom       = database.PISystem.UOMDatabase.UOMs["kilowatt hour"];
            AFCategory       mEnergyE  = database.ElementCategories["Measures Energy"];
            AFCategory       bInfoA    = database.AttributeCategories["Building Info"];
            AFCategory       locationA = database.AttributeCategories["Location"];
            AFCategory       tsDataA   = database.AttributeCategories["Time-Series Data"];
            AFEnumerationSet bTypeNum  = database.EnumerationSets["Building Type"];
            AFPlugIn         PIPoint   = database.PISystem.DataReferencePlugIns["PI Point"];

            meterBasicTemplate = database.ElementTemplates.Add("MeterBasic");
            meterBasicTemplate.Categories.Add(mEnergyE);

            AFAttributeTemplate substationAttrTemp = meterBasicTemplate.AttributeTemplates.Add("Substation");

            substationAttrTemp.Type = typeof(string);

            AFAttributeTemplate usageLimitAttrTemp = meterBasicTemplate.AttributeTemplates.Add("Usage Limit");

            usageLimitAttrTemp.Type       = typeof(string);
            usageLimitAttrTemp.DefaultUOM = uom;

            AFAttributeTemplate buildingAttrTemp = meterBasicTemplate.AttributeTemplates.Add("Building");

            buildingAttrTemp.Type = typeof(string);
            buildingAttrTemp.Categories.Add(bInfoA);

            AFAttributeTemplate bTypeAttrTemp = meterBasicTemplate.AttributeTemplates.Add("Building Type");

            bTypeAttrTemp.TypeQualifier = bTypeNum;
            bTypeAttrTemp.Categories.Add(bInfoA);

            AFAttributeTemplate cityAttrTemp = meterBasicTemplate.AttributeTemplates.Add("City");

            cityAttrTemp.Type = typeof(string);
            cityAttrTemp.Categories.Add(locationA);

            AFAttributeTemplate energyUsageAttrTemp = meterBasicTemplate.AttributeTemplates.Add("Energy Usage");

            energyUsageAttrTemp.Type = typeof(Single);
            energyUsageAttrTemp.Categories.Add(tsDataA);
            energyUsageAttrTemp.DefaultUOM          = uom;
            energyUsageAttrTemp.DataReferencePlugIn = PIPoint;
            energyUsageAttrTemp.ConfigString        = @"\\%@\Configuration|PIDataArchiveName%\%Element%.%Attribute%;UOM=kWh";

            return(meterBasicTemplate);
        }
Пример #2
0
        private void CreateAttribute_Button_Click(object sender, EventArgs e)
        {
            String AttributeName = Attribute_TextBox.Text.Trim();

            if (AttributeName == "")
            {
                MessageBox.Show("No Attribute Name defined");
            }
            else
            {
                if (afTreeView1.AFSelectedPath == afTreeView1.AFRootPath)
                {
                    MessageBox.Show("You have not selected an element", "Exception");
                }
                else
                {
                    try
                    {
                        if (TagList.SelectedIndices.Count < 1)
                        {
                            //tag is not selected
                            MessageBox.Show("There is no selected tag");
                            //myElement = myAFDatabase.Elements[afTreeView1.AFSelectedPath];
                            //myElement.Attributes.Add(AttributeName);
                        }
                        else
                        {
                            //one or more tag is selected
                            myElement = myAFDatabase.Elements[afTreeView1.AFSelectedPath];
                            AFAttribute myAttribute = myElement.Attributes.Add(AttributeName);
                            AFPlugIn    PI_Point    = myAFDatabase.PISystem.DataReferencePlugIns["PI Point"];
                            myAttribute.DataReferencePlugIn = PI_Point;
                            myAttribute.ConfigString        = @"\\" + myPIServer.Name + @"\" + TagList.SelectedItems[0].Text;
                        }
                        myElement.CheckIn();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }
Пример #3
0
        /// <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);
        }