Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        public static void CreateElementTemplate(AFDatabase database)
        {
            if (database == null)
            {
                throw new ArgumentNullException(nameof(database));
            }
            Console.WriteLine("Creating the element template: FeederTemplate");
            string            templateName = "FeederTemplate";
            AFElementTemplate feederTemplate;

            if (database.ElementTemplates.Contains(templateName))
            {
                return;
            }
            else
            {
                feederTemplate = database.ElementTemplates.Add(templateName);
            }

            AFAttributeTemplate cityAttributeTemplate = feederTemplate.AttributeTemplates.Add("City");

            cityAttributeTemplate.Type = typeof(string);

            AFAttributeTemplate power = feederTemplate.AttributeTemplates.Add("Power");

            power.Type = typeof(Single);

            power.DefaultUOM          = database.PISystem.UOMDatabase.UOMs["watt"];
            power.DataReferencePlugIn = database.PISystem.DataReferencePlugIns["PI Point"];

            database.CheckIn();
        }
        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);
        }
        public void CreateAttributeTemplateTest()
        {
            string path = Constants.AF_ATTRIBUTE_TEMPLATE_PATH;
            PIAttributeTemplate template = new PIAttributeTemplate()
            {
                Name                = "Water(2008)",
                Description         = "2008 Water Use",
                Type                = "Int32",
                TypeQualifier       = "",
                DefaultValue        = 0,
                DataReferencePlugIn = "Table Lookup",
                ConfigString        = "SELECT [Water Use] FROM [Energy Use 2008] WHERE [Asset ID] = '%Element%'",
                IsConfigurationItem = false,
                IsExcluded          = false,
                IsHidden            = false,
                IsManualDataEntry   = false,
                TraitName           = "LimitLoLo"
            };

            instance.CreateAttributeTemplate(webId, template);
            AFAttributeTemplate myAttributeTemplate = AFObject.FindObject(path) as AFAttributeTemplate;

            myAttributeTemplate.ElementTemplate.Refresh();
            Assert.IsTrue(myAttributeTemplate.AttributeTemplates.Count == 4);
        }
Exemplo n.º 5
0
        private static void CreateMeterAdvancedTemplate(AFElementTemplate meterBasicTemplate)
        {
            AFDatabase        database = meterBasicTemplate.Database;
            AFElementTemplate meterAdvancedTemplate = database.ElementTemplates["MeterAdvanced"];

            if (meterAdvancedTemplate == null)
            {
                database.ElementTemplates.Add("MeterAdvanced");
            }

            AFCategory       tsDataA     = database.AttributeCategories["Time-Series Data"];
            AFEnumerationSet mStatusEnum = database.EnumerationSets["Meter Status"];

            meterAdvancedTemplate.BaseTemplate = meterBasicTemplate;

            AFAttributeTemplate statusAttrTemp = meterAdvancedTemplate.AttributeTemplates["Status"];

            if (statusAttrTemp == null)
            {
                meterAdvancedTemplate.AttributeTemplates.Add("Status");
            }
            statusAttrTemp.TypeQualifier = mStatusEnum;
            if (!statusAttrTemp.Categories.Contains(tsDataA))
            {
                statusAttrTemp.Categories.Add(tsDataA);
            }
            statusAttrTemp.DataReferencePlugIn = database.PISystem.DataReferencePlugIns["PI Point"];
            statusAttrTemp.ConfigString        = @"\\%@\Configuration|PIDataArchiveName%\%Element%.%Attribute%";
        }
        static void Main(string[] args)
        {
            AFDatabase db = ConnectionHelper.GetDatabase("PISRV01", "Feeder Voltage Monitoring");

            AFAttributeTemplate attrTemp = db.ElementTemplates["Feeder"].AttributeTemplates["Reactive Power"];

            AssetRankProvider rankProvider = new AssetRankProvider(attrTemp);

            rankProvider.Start();

            // Get top 3 Feeders every 5 seconds. Do this 10 times.
            foreach (int i in Enumerable.Range(0, 10))
            {
                IList <AFRankedValue> rankings = rankProvider.GetTopNElements(3);
                foreach (var r in rankings)
                {
                    Console.WriteLine($"{r.Ranking} {r.Value.Attribute.Element.Name} {r.Value.Timestamp} {r.Value.Value}");
                }
                Console.WriteLine();
                Thread.Sleep(5000);
            }

            // Remove unmanaged resources and server-side signup.
            rankProvider.Dispose();

            Console.WriteLine("Press any key to quit");
            Console.ReadKey();
        }
        static void convertAttribute(AFAttributeTemplate attr)
        {
            foreach (var child in attr.AttributeTemplates)
            {
                convertAttribute(child);
            }

            try
            {
                attr.DefaultUOM = convert(attr.DefaultUOM);
            }
            // occurs for example when trying to change the UOMs of Location attributes.
            catch (System.InvalidOperationException)
            {
            }
            if (attr.DataReferencePlugIn != null)
            {
                if (attr.DataReferencePlugIn.Name == "PI Point")
                {
                    attr.DataReference.UOM = convert(attr.DataReference.UOM);
                }

                if (attr.DataReferencePlugIn.Name == "Table Lookup")
                {
                    // Create a table look object and use its method to grab the uom
                }
            }
            attr.ElementTemplate.CheckIn();
        }
Exemplo n.º 8
0
        private AFElementTemplate CreateEventFrameTemplate(AFDatabase db)
        {
            AFElementTemplate evTemplate = db.ElementTemplates[Constants.AF_EVENT_FRAME_TEMPLATE_NAME];

            if (evTemplate == null)
            {
                evTemplate              = db.ElementTemplates.Add("TankEventFrameTemplate");
                evTemplate.Description  = "Tank Event Frame Template!";
                evTemplate.InstanceType = typeof(AFEventFrame);

                AFAttributeTemplate Level = evTemplate.AttributeTemplates.Add("Level");
                Level.Type = typeof(double);
                Level.DataReferencePlugIn = Level.PISystem.DataReferencePlugIns["PI Point"];
                Level.ConfigString        = @".\Elements[.]|Level";
                Level.Description         = "Level of the tank";
                Level.DefaultUOM          = _piSystem.UOMDatabase.UOMClasses["Ratio"].UOMs["percent"];


                AFAttributeTemplate Pressure = evTemplate.AttributeTemplates.Add("Pressure");
                Pressure.Type = typeof(double);
                Pressure.DataReferencePlugIn = Level.PISystem.DataReferencePlugIns["PI Point"];
                Pressure.ConfigString        = @".\Elements[.]|Pressure;TimeRangeMethod=StartTime";
                Pressure.Description         = "Pressure of the tank";
                Pressure.DefaultUOM          = _piSystem.UOMDatabase.UOMClasses["Pressure"].UOMs["pascal"];

                evTemplate.DefaultAttribute = Level;
            }
            return(evTemplate);
        }
Exemplo n.º 9
0
        static void CreateElementTemplate(AFDatabase database)
        {
            string            templateName = "FeederTemplate";
            AFElementTemplate feederTemplate;

            if (database.ElementTemplates.Contains(templateName))
            {
                return;
            }
            else
            {
                feederTemplate = database.ElementTemplates.Add(templateName);
            }

            AFAttributeTemplate cityattributeTemplate = feederTemplate.AttributeTemplates.Add("City");

            cityattributeTemplate.Type = typeof(string);

            AFAttributeTemplate power = feederTemplate.AttributeTemplates.Add("Power");

            power.Type = typeof(Single);

            power.DefaultUOM          = database.PISystem.UOMDatabase.UOMs["watt"];
            power.DataReferencePlugIn = database.PISystem.DataReferencePlugIns["PI Point"];

            database.CheckIn();
        }
        private void AddAttributeTemplate(AFElementTemplate template, string name, Type type, bool hasPiPointDr, UOM uom, string categoryName)
        {
            if (template.AttributeTemplates[name] == null)
            {
                AFAttributeTemplate attributeTemplate = template.AttributeTemplates.Add(name);
                attributeTemplate.Type       = type;
                attributeTemplate.DefaultUOM = uom;

                if (hasPiPointDr == true)
                {
                    attributeTemplate.DataReferencePlugIn = piSystem.DataReferencePlugIns["PI Point"];
                    if (attributeTemplate.DefaultUOM == null)
                    {
                        attributeTemplate.ConfigString = @"\\" + piServer.Name + @"\CityBikes_%@..\|Id%_%@Id%_%Attribute%";
                    }
                    else
                    {
                        attributeTemplate.ConfigString = @"\\" + piServer.Name + @"\CityBikes_%@..\|Id%_%@Id%_%Attribute%;UOM=" + attributeTemplate.DefaultUOM.Abbreviation;
                    }
                }
                else
                {
                    attributeTemplate.DataReferencePlugIn = null;
                }

                if (string.IsNullOrEmpty(categoryName) == false)
                {
                    attributeTemplate.Categories.Add(categoryName);
                }
            }
        }
Exemplo n.º 11
0
        private AFAttributeValueQuery GetAfAttributeValueQuery(string templateName, string attributeName, object value)
        {
            AFAttributeTemplate attributeTemplate =
                _afDatabase.ElementTemplates[templateName].AttributeTemplates[attributeName];
            var afAttributeValueQuery = new AFAttributeValueQuery(attributeTemplate, AFSearchOperator.Equal, value);

            return(afAttributeValueQuery);
        }
Exemplo n.º 12
0
        // Define other instance members here

        public AssetRankProvider(AFAttributeTemplate attrTemplate)
        {
            AttributeTemplate = attrTemplate;
            DataPipe          = new AFDataPipe();

            // Your code here
            // 1. Initialize an internal data structure to store the latest values keyed by element
        }
Exemplo n.º 13
0
        static void convertAttribute(AFAttributeTemplate attr)
        {
            foreach (var child in attr.AttributeTemplates)
            {
                convertAttribute(child);
            }

            var oldUOM    = attr.DefaultUOM;
            var newUOM    = convert(attr.DefaultUOM);
            var condition = attr.IsConfigurationItem && oldUOM != newUOM;

            var existingValues = new Dictionary <AFElement, Double>();

            if (condition)
            {
                var elements = attr.ElementTemplate.FindInstantiatedElements(true, AFSortField.Name, AFSortOrder.Ascending, Int32.MaxValue);
                foreach (var element in elements)
                {
                    var value = element.Attributes[attr.Name].GetValue().ValueAsDouble();

                    //element.Attributes[attr.Name].Data.UpdateValue(new AFValue(value * rate, oldUOM), OSIsoft.AF.Data.AFUpdateOption.Insert);
                    existingValues[(AFElement)element] = value * rate;
                }
                attr.Database.CheckIn();
            }
            attr.DefaultUOM = newUOM;
            attr.ElementTemplate.CheckIn();
            if (condition)
            {
                var elements = attr.ElementTemplate.FindInstantiatedElements(true, AFSortField.Name, AFSortOrder.Ascending, Int32.MaxValue);
                foreach (var element in elements)
                {
                    var newValue = existingValues[(AFElement)element];

                    element.Attributes[attr.Name].Data.UpdateValue(new AFValue(newValue, newUOM), OSIsoft.AF.Data.AFUpdateOption.Insert);
                }
                attr.Database.CheckIn();
            }
            ;


            //attr.DefaultUOM = convert(attr.DefaultUOM);

            if (attr.DataReferencePlugIn != null)
            {
                if (attr.DataReferencePlugIn.Name == "PI Point")
                {
                    attr.DataReference.UOM = convert(attr.DataReference.UOM);
                }

                if (attr.DataReferencePlugIn.Name == "Table Lookup")
                {
                    // Create a table look object and use its method to grab the uom
                }
            }
            attr.ElementTemplate.CheckIn();
        }
Exemplo n.º 14
0
        public static void AddAnalysis(this AFAttributeTemplate template, string equation, int frequency)
        {
            var at = template.ElementTemplate.AnalysisTemplates.Add(template.Name);

            at.ExtendedProperties.Add("AutoRecalculationEnabled", true);
            at.AnalysisRulePlugIn           = at.Database.PISystem.AnalysisRulePlugIns["PerformanceEquation"];
            at.AnalysisRule.VariableMapping = $"Variable1||{template.Name};";
            at.AnalysisRule.ConfigString    = $"Variable1:={equation};Variable2:=";
            at.TimeRulePlugIn        = at.Database.PISystem.TimeRulePlugIns["Periodic"];
            at.TimeRule.ConfigString = $"Frequency={frequency}";
        }
Exemplo n.º 15
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);
        }
        /// <summary>
        /// Create or update PI point data reference for an AF attribute in a list of AF elements
        /// </summary>
        /// <param name="at"></param>
        /// <param name="elist"></param>
        /// <param name="updateProgress"></param>
        private static void ProcessAttributeTemplate(AFAttributeTemplate at, IList<AFElement> elist, EventHandler<AFProgressEventArgs> updateProgress = null)
        {
            if (at.DataReference == null || !at.DataReference.Name.Equals("PI Point", StringComparison.OrdinalIgnoreCase))
                return;

            // Load attributes
            IList<AFAttributeTemplate> ats = new List<AFAttributeTemplate>();
            ats.Add(at);
            AFElement.LoadAttributes(elist, ats);

            ProcessAttributes(elist.Select(elm => elm.Attributes[at.Name]).ToList(), updateProgress);
        }
        public void DeleteTest()
        {
            instance.Delete(webId);
            AFDatabase db = StandardPISystem.Databases[Constants.AF_DATABASE_NAME];

            db.Refresh();
            AFAttributeTemplate attributeTemplate = AFObject.FindObject(Constants.AF_ATTRIBUTE_TEMPLATE_PATH) as AFAttributeTemplate;

            Assert.IsNull(attributeTemplate);
            DeleteSampleDatabaseForTests();
            CreateSampleDatabaseForTests();
        }
Exemplo n.º 18
0
        /// <summary>
        /// Create or update PI point data reference for an AF attribute in a list of AF elements
        /// </summary>
        /// <param name="at"></param>
        /// <param name="elist"></param>
        /// <param name="updateProgress"></param>
        private static void ProcessAttributeTemplate(AFAttributeTemplate at, IList <AFElement> elist, EventHandler <AFProgressEventArgs> updateProgress = null)
        {
            if (at.DataReference == null || !at.DataReference.Name.Equals("PI Point", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            // Load attributes
            IList <AFAttributeTemplate> ats = new List <AFAttributeTemplate>();

            ats.Add(at);
            AFElement.LoadAttributes(elist, ats);

            ProcessAttributes(elist.Select(elm => elm.Attributes[at.Name]).ToList(), updateProgress);
        }
Exemplo n.º 19
0
 static void getAllUOMUsed(AFAttributeTemplate attr, DataTable dt)
 {
     foreach (var child in attr.AttributeTemplates)
     {
         getAllUOMUsed(child, dt);
     }
     if (attr.DefaultUOM != null)
     {
         insert(attr.DefaultUOM, dt);
     }
     if (attr.DataReference != null && attr.DataReference.UOM != null)
     {
         insert(attr.DataReference.UOM, dt);
     }
 }
Exemplo n.º 20
0
        private static void CreateCityTemplate(AFDatabase database)
        {
            AFElementTemplate cityTemplate = database.ElementTemplates["City"];

            if (cityTemplate != null)
            {
                return;
            }

            AFAttributeTemplate cityEnergyUsageAttrTemp = cityTemplate.AttributeTemplates.Add("Energy Usage");

            cityEnergyUsageAttrTemp.Type                = typeof(Single);
            cityEnergyUsageAttrTemp.DefaultUOM          = database.PISystem.UOMDatabase.UOMs["kilowatt hour"];
            cityEnergyUsageAttrTemp.DataReferencePlugIn = database.PISystem.DataReferencePlugIns["PI Point"];
            cityEnergyUsageAttrTemp.ConfigString        = @"\\%@\Configuration|PIDataArchiveName%\%Element%.%Attribute%";
        }
Exemplo n.º 21
0
        /// <summary>
        /// Slims an AF SDK AFAttributeTemplate
        /// </summary>
        /// <param name="fat">The template to be slimmed</param>
        /// <param name="instance">Optional element instance to provide data reference information if not set on the template</param>
        /// <returns></returns>
        public static AFAttributeTemplateSlim ToSlim(this AFAttributeTemplate fat, AFAttribute instance = null)
        {
            AFAttributeTemplateSlim slim = new AFAttributeTemplateSlim()
            {
                Id            = fat.ID,
                FullName      = fat.GetPath(fat.ElementTemplate),
                Name          = fat.Name,
                Description   = fat.Description,
                IsTopLevel    = fat.Parent == null,
                TypeName      = fat.Type.Name,
                TypeQualifier = fat.TypeQualifier is IAFNamedObject ? ((IAFNamedObject)fat.TypeQualifier).Name : null,
                IsHidden      = fat.IsHidden, //requires AF Client 2.7 or higher
                IsStatic      = fat.DataReferencePlugIn == null && instance?.DataReferencePlugIn == null,
                HasChildren   = fat.AttributeTemplates != null && fat.AttributeTemplates.Count > 0,
                CategoryNames = fat.Categories.Select(c => c.Name).ToList()
            };

            return(slim);
        }
        public AssetRankProvider(AFAttributeTemplate attrTemplate)
        {
            if (attrTemplate.Type != typeof(double) &&
                attrTemplate.Type != typeof(float) &&
                attrTemplate.Type != typeof(Int32))
            {
                throw new ArgumentException("Cannot rank attributes with value type {0}", attrTemplate.Type.Name);
            }

            AttributeTemplate = attrTemplate;

            _afValueComparer = new Comparison <AFValue>(CompareAFValue);

            DataPipe    = new AFDataPipe();
            _lastValues = new Dictionary <AFElement, AFValue>();

            _tokenSource = new CancellationTokenSource();
            _ct          = _tokenSource.Token;
        }
Exemplo n.º 23
0
        public static void CreateAttributeTemplate(string name, AFElementTemplate elementTemplate, Type attributeType, UOM attributeUOM)
        {
            AFAttributeTemplate myAttributeTemplate = elementTemplate.AttributeTemplates[name];

            if (myAttributeTemplate == null)
            {
                myAttributeTemplate = elementTemplate.AttributeTemplates.Add(name);
            }
            myAttributeTemplate.DataReferencePlugIn = myPISystem.DataReferencePlugIns["PI Point"];
            myAttributeTemplate.Type       = attributeType;
            myAttributeTemplate.DefaultUOM = attributeUOM;
            if (myAttributeTemplate.DefaultUOM == null)
            {
                myAttributeTemplate.ConfigString = @"\\" + PIServerName + @"\%Element%_%Attribute%;";
            }
            else
            {
                myAttributeTemplate.ConfigString = @"\\" + PIServerName + @"\%Element%_%Attribute%;UOM=" + myAttributeTemplate.DefaultUOM.Abbreviation;
            }
        }
        public void Run()
        {
            PISystems piSystems = new PISystems();
            PISystem  piSystem  = piSystems["<AFSERVER>"];

            AFDatabase afDatabase = piSystem.Databases["Basic-AFSDK-Sample"];

            AFElement boilerA = afDatabase.Elements["Region_0"].Elements["BoilerA"];

            AFElementTemplate   elementTemplate         = afDatabase.ElementTemplates["BasicBoilerTemplate"];
            AFAttributeTemplate temperatureAttrTemplate = elementTemplate.AttributeTemplates["Temperature"];
            AFAttributeTemplate modeAttrTemplate        = elementTemplate.AttributeTemplates["Mode"];

            AFElement.LoadAttributes(new[] { boilerA }, new[] { temperatureAttrTemplate, modeAttrTemplate });

            AFEnumerationSet digSet = afDatabase.EnumerationSets["Modes"];

            IList <AFValue> valuesToWrite = new List <AFValue>();

            for (int i = 0; i < 10; i++)
            {
                AFTime time = new AFTime(new DateTime(2015, 1, 1, i, 0, 0, DateTimeKind.Local));

                AFValue afValueFloat = new AFValue(i, time);
                // Associate the AFValue to an attribute so we know where to write to.
                afValueFloat.Attribute = boilerA.Attributes["Temperature"];

                AFEnumerationValue digSetValue    = i % 2 == 0 ? digSet["Auto"] : digSet["Manual"];
                AFValue            afValueDigital = new AFValue(digSetValue, time);
                afValueDigital.Attribute = boilerA.Attributes["Mode"];

                valuesToWrite.Add(afValueFloat);
                valuesToWrite.Add(afValueDigital);
            }

            // Perform a bulk write. Use a single local call to PI Buffer Subsystem if possible.
            // Otherwise, make a single call to the PI Data Archive.
            // We use no compression just so we can check all the values are written.
            // AFListData is the class that provides the bulk write method.
            AFListData.UpdateValues(valuesToWrite, AFUpdateOption.InsertNoCompression, AFBufferOption.BufferIfPossible);
        }
Exemplo n.º 25
0
        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();
        }
Exemplo n.º 26
0
        private AFElementTemplate CreateElementTemplate(AFDatabase db)
        {
            AFElementTemplate elTmpl = db.ElementTemplates[Constants.AF_ELEMENT_TEMPLATE_NAME];

            if (elTmpl == null)
            {
                elTmpl = db.ElementTemplates.Add(Constants.AF_ELEMENT_TEMPLATE_NAME);
            }

            AFAttributeTemplate attributeTemplate = elTmpl.AttributeTemplates[Constants.AF_ATTRIBUTE_TEMPLATE_NAME];

            if (attributeTemplate == null)
            {
                attributeTemplate                     = elTmpl.AttributeTemplates.Add(Constants.AF_ATTRIBUTE_TEMPLATE_NAME);
                attributeTemplate.Type                = typeof(Double);
                attributeTemplate.DefaultUOM          = _piSystem.UOMDatabase.UOMClasses["Temperature"].UOMs["degree Celsius"];
                attributeTemplate.DataReferencePlugIn = _piSystem.DataReferencePlugIns["PI Point"];
                var childAttTmpl1 = attributeTemplate.AttributeTemplates.Add((Constants.AF_ATTRIBUTE_TEMPLATE_NAME + "Child1"));
                var childAttTmpl2 = attributeTemplate.AttributeTemplates.Add((Constants.AF_ATTRIBUTE_TEMPLATE_NAME + "Child2"));
                var childAttTmpl3 = attributeTemplate.AttributeTemplates.Add((Constants.AF_ATTRIBUTE_TEMPLATE_NAME + "Child3"));
            }
            AFAttributeTemplate attributeTemplate2 = elTmpl.AttributeTemplates["Pressure"];

            if (attributeTemplate2 == null)
            {
                attributeTemplate2      = elTmpl.AttributeTemplates.Add("Pressure");
                attributeTemplate2.Type = typeof(Double);
                attributeTemplate2.DataReferencePlugIn = _piSystem.DataReferencePlugIns["PI Point"];
            }
            AFAttributeTemplate attributeTemplate3 = elTmpl.AttributeTemplates["Level"];

            if (attributeTemplate3 == null)
            {
                attributeTemplate3      = elTmpl.AttributeTemplates.Add("Level");
                attributeTemplate3.Type = typeof(Double);
                attributeTemplate3.DataReferencePlugIn = _piSystem.DataReferencePlugIns["PI Point"];
            }
            return(elTmpl);
        }
        public void UpdateTest()
        {
            string path = Constants.AF_ATTRIBUTE_TEMPLATE_PATH;
            PIAttributeTemplate template = instance.Get(webId, null);

            template.WebId       = null;
            template.Id          = null;
            template.Links       = null;
            template.Path        = null;
            template.HasChildren = null;
            template.Description = "This is the new attribute template swagger description";
            instance.Update(webId, template);

            StandardPISystem.Refresh();
            AFAttributeTemplate myAttributeTemplate = AFObject.FindObject(path) as AFAttributeTemplate;

            myAttributeTemplate.ElementTemplate.Refresh();
            myAttributeTemplate = AFObject.FindObject(path) as AFAttributeTemplate;

            if (myAttributeTemplate != null)
            {
                Assert.IsTrue(myAttributeTemplate.Description == template.Description);
            }
        }
Exemplo n.º 28
0
        static void translateAttribute(AFElementTemplate elem, AFAttributeTemplate attr, DataTable dt)
        {
            AFVariableMappingData variableMapping            = null;
            AFAnalysisTemplate    analysisTargetingAttribute = null;

            foreach (AFAnalysisTemplate analysis in elem.AnalysisTemplates)
            {
                analysis.AnalysisRule.VariableMap.TryGetMapping(attr.Name, out variableMapping);
                if (variableMapping != null)
                {
                    analysisTargetingAttribute = analysis;
                    break;
                }
            }

            attr.Name        = translate(dt, attr.Name, "Japanese");
            attr.Description = translate(dt, attr.Description, "Japanese");
            elem.CheckIn();
            if (analysisTargetingAttribute != null)
            {
                //analysisTargetingAttribute.AnalysisRule.VariableMap.SetMapping(attr.Name, variableMapping);
                analysisTargetingAttribute.AnalysisRule.VariableMap.RefreshMappings(elem);
            }
        }
Exemplo n.º 29
0
        static AFEventFrameCriteria queryToCriteria(OSIsoft.AF.Search.AFEventFrameSearch query)
        {
            AFEventFrameCriteria criteria = new AFEventFrameCriteria();

            criteria.Database = query.Database;
            IList <AFSearchToken> starts;

            query.TryFindSearchTokens(OSIsoft.AF.Search.AFSearchFilter.Start, out starts);
            IList <AFSearchToken> ends;

            query.TryFindSearchTokens(OSIsoft.AF.Search.AFSearchFilter.End, out ends);
            AFSearchToken templatename;

            query.TryFindSearchToken(OSIsoft.AF.Search.AFSearchFilter.Template, out templatename);
            IList <AFSearchToken> values;

            query.TryFindSearchTokens(OSIsoft.AF.Search.AFSearchFilter.Value, out values);

            if (values.Count != 0)
            {
                AFAttributeValueQuery[] queries = new AFAttributeValueQuery[values.Count];
                criteria.AttributeValueQueries = new AFAttributeValueQuery[values.Count];
                criteria.TemplateName          = templatename.Value;
                for (int i = 0; i < values.Count; i++)
                {
                    AFSearchToken       value             = values[i];
                    string              attributeName     = value.Path.TrimStart(new char[] { '|' });
                    AFElementTemplate   template          = query.Database.ElementTemplates[templatename.Value];
                    AFAttributeTemplate templateAttribute = template.AttributeTemplates[attributeName];
                    queries[i] = new AFAttributeValueQuery(templateAttribute, value.Operator, value.Value, templateAttribute.DefaultUOM);
                    criteria.AttributeValueQueries[i] = new AFAttributeValueQuery(templateAttribute, value.Operator, value.Value, templateAttribute.DefaultUOM);
                }

                //criteria.AttributeValueQueries = queries;
                //criteria.ValueQueryString = value.ToString();
                //criteria.
            }
            if (ends.Count == 2)
            {
                criteria.SearchType = OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.EndingBetween;
                criteria.StartTime  = ends[0].Value;
                criteria.EndTime    = ends[1].Value;
            }
            else if (starts.Count == 2)
            {
                criteria.SearchType = OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.StartingBetween;
                criteria.StartTime  = starts[0].Value;
                criteria.EndTime    = starts[1].Value;
            }
            else if (starts.Count == 1 && ends.Count == 1)
            {
                AFSearchToken start = starts[0];
                AFSearchToken end   = ends[0];
                if (start.Operator == AFSearchOperator.LessThanOrEqual && end.Operator == AFSearchOperator.GreaterThanOrEqual)
                {
                    criteria.SearchType = OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.ActiveBetween;
                    criteria.StartTime  = end.Value;
                    criteria.EndTime    = start.Value;
                }
                else if (start.Operator == AFSearchOperator.GreaterThanOrEqual && end.Operator == AFSearchOperator.LessThanOrEqual)
                {
                    criteria.SearchType = OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.EntirelyBetween;
                    criteria.StartTime  = start.Value;
                    criteria.EndTime    = end.Value;
                }
            }
            else if (starts.Count == 1)
            {
                AFSearchToken start = starts[0];
                if (start.Operator == AFSearchOperator.GreaterThanOrEqual)
                {
                    criteria.SearchType = OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.StartingAfter;
                }
                else
                {
                    criteria.SearchType = OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.StartingBefore;
                }
                criteria.AFStartTimeString = start.Value;
            }
            else if (ends.Count == 1)
            {
                AFSearchToken end = ends[0];
                if (end.Operator == AFSearchOperator.GreaterThanOrEqual)
                {
                    criteria.SearchType = OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.EndingAfter;
                }
                else
                {
                    criteria.SearchType = OSIsoft.AF.UI.Search.AFBaseEventFrameCriteria.EventFrameSearchType.EndingBefore;
                }
                criteria.AFStartTimeString = end.Value;
            }

            criteria.LastFullSearchString = stripTokens(query);
            return(criteria);
        }
Exemplo n.º 30
0
        private static void CreateTemplates(AFDatabase database)
        {
            if (database == null)
            {
                return;
            }

            UOM uom = database.PISystem.UOMDatabase.UOMs["kilowatt hour"];

            AFCategory mEnergyE = database.ElementCategories["Measures Energy"];
            AFCategory sStatusE = database.ElementCategories["Shows Status"];

            AFCategory bInfoA    = database.AttributeCategories["Building Info"];
            AFCategory locationA = database.AttributeCategories["Location"];
            AFCategory tsDataA   = database.AttributeCategories["Time-Series Data"];

            AFEnumerationSet bTypeNum    = database.EnumerationSets["Building Type"];
            AFEnumerationSet mStatusEnum = database.EnumerationSets["Meter Status"];

            // Create MeterBasic Element Template

            AFElementTemplate meterBasicTemplate;

            if (!database.ElementTemplates.Contains("MeterBasic"))
            {
                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 districtAttrTemp = meterBasicTemplate.AttributeTemplates.Add("District");
                districtAttrTemp.Type = typeof(string);
                districtAttrTemp.Categories.Add(locationA);

                AFAttributeTemplate energyUsageAttrTemp = meterBasicTemplate.AttributeTemplates.Add("Energy Usage");
                energyUsageAttrTemp.Type = typeof(double);
                energyUsageAttrTemp.Categories.Add(tsDataA);
                energyUsageAttrTemp.DefaultUOM          = uom;
                energyUsageAttrTemp.DataReferencePlugIn = database.PISystem.DataReferencePlugIns["PI Point"];
                energyUsageAttrTemp.ConfigString        = @"\\%Server%\%Element%.%Attribute%;UOM=kWh";
            }
            else
            {
                meterBasicTemplate = database.ElementTemplates["MeterBasic"];
            }

            // Create MeterAdvanced Element Template

            if (!database.ElementTemplates.Contains("MeterAdvanced"))
            {
                AFElementTemplate meterAdvancedTemplate = database.ElementTemplates.Add("MeterAdvanced");
                meterAdvancedTemplate.BaseTemplate = meterBasicTemplate;

                AFAttributeTemplate statusAttrTemp = meterAdvancedTemplate.AttributeTemplates.Add("Status");
                statusAttrTemp.TypeQualifier = mStatusEnum;
                statusAttrTemp.Categories.Add(tsDataA);
                statusAttrTemp.DataReferencePlugIn = database.PISystem.DataReferencePlugIns["PI Point"];
                statusAttrTemp.ConfigString        = @"\\%Server%\%Element%.%Attribute%";

                // Create District Element Template

                AFElementTemplate districtTemplate = database.ElementTemplates.Add("District");

                AFAttributeTemplate districtEnergyUsageAttrTemp = districtTemplate.AttributeTemplates.Add("Energy Usage");
                districtEnergyUsageAttrTemp.Type                = typeof(double);
                districtEnergyUsageAttrTemp.DefaultUOM          = uom;
                districtEnergyUsageAttrTemp.DataReferencePlugIn = database.PISystem.DataReferencePlugIns["PI Point"];
                districtEnergyUsageAttrTemp.ConfigString        = @"\\%Server%\%Element%.%Attribute%";
            }

            // Do a checkin at the end instead of one-by-one.

            database.CheckIn();
        }
Exemplo n.º 31
0
 private static IEnumerable <AFAttributeTemplate> GetAllAttributeTemplatesAndChildren(AFAttributeTemplate attributeTemplate)
 {
     return(attributeTemplate.AttributeTemplates
            .Concat(attributeTemplate.AttributeTemplates
                    .OfType <AFAttributeTemplate>()
                    .SelectMany(a => GetAllAttributeTemplatesAndChildren(a))));
 }