예제 #1
0
        static void CreateFeederElements(AFDatabase database)
        {
            AFElementTemplate template = database.ElementTemplates["FeederTemplate"];

            AFElement feeders = database.Elements["Feeders"];

            if (template == null || feeders == null)
            {
                return;
            }

            if (feeders.Elements.Contains("Feeder001"))
            {
                return;
            }
            AFElement feeder001 = feeders.Elements.Add("Feeder001", template);

            AFAttribute district = feeder001.Attributes["District"];

            if (district != null)
            {
                district.SetValue(new AFValue("Hogwarts"));
            }

            AFAttribute power = feeder001.Attributes["Power"];

            power.ConfigString = @"\\PISRV01\SINUSOID";

            database.CheckIn();
        }
예제 #2
0
        static void CreateFeederElements(AFDatabase database)
        {
            AFElementTemplate template = database.ElementTemplates["FeederTemplate"];

            AFElement feeders = database.Elements["Feeders"];

            if (template == null || feeders == null)
            {
                return;
            }

            if (feeders.Elements.Contains("Feeder001"))
            {
                return;
            }
            AFElement feeder001 = feeders.Elements.Add("Feeder001", template);

            AFAttribute city = feeder001.Attributes["City"];

            if (city != null)
            {
                city.SetValue(new AFValue("London"));
            }

            AFAttribute power = feeder001.Attributes["Power"];

            power.ConfigString = @"%@\Configuration|PIDataArchiveName%\SINUSOID";

            if (database.IsDirty)
            {
                database.CheckIn();
            }
        }
예제 #3
0
        // Writing Data to the AFServer
        /// <summary>
        /// Writes to AF, and checks in the element.
        /// </summary>
        /// <param name="element"> AFElement being written to.</param>
        /// <param name="attribute"> AFAttribute being changed.</param>
        /// <param name="value"> The new value being imported.</param>
        public static void writeToAF(AFElement element, AFAttribute attribute, double value)
        {
            AFValue input = new AFValue(attribute, value, AFTime.Now);

            attribute.SetValue(input);
            element.CheckIn();
        }
예제 #4
0
        public void CreateAttribute()
        {
            AFElement element = new AFElement();

            string name = "Test Element 1";

            element.Name = name;
            Assert.Equals(element.Name, name);

            string desc = "Lazy PI Unit Test Element";

            element.Description = desc;
            Assert.Equals(element.Description, desc);

            Console.WriteLine("Test element creation.");

            Assert.IsTrue(_db.CreateElement(element), "Assert creation passed");

            element = _db.Elements[element.Name];

            //Check that the the element can be found through the AFDB
            Assert.IsNotNull(element, "Check AFDB element collection for new element.");

            AFAttribute attr = new AFAttribute();

            attr.Name        = "Test Attribute";
            attr.Description = "Created by WebAPI tests";

            element.Attributes.Add(attr);
            element.CheckIn();

            Assert.Equals(element.Attributes.Count, 1);
            attr = element.Attributes[attr.Name];

            Assert.IsNotNull(attr);
            Assert.IsNotNull(attr.ID);
            Assert.IsNotNull(attr.Name);
            Assert.IsNotNull(attr.Description);
            Assert.IsNotNull(attr.Path);

            string val = "Test string";

            // Test set and get of AFValue object
            attr.SetValue(new AFValue(val));
            AFValue valObj = attr.GetValue();

            Assert.Equals(valObj.Value, val);

            element.Delete();
            Assert.IsTrue(element.IsDeleted);

            element.CheckIn();
            Assert.IsNull(AFElement.Find(_conn, element.WebID));
        }
예제 #5
0
        public void Cleanup()
        {
            configElement.Database.Refresh();
            if (configElement.Attributes[Constants.PIWEBAPI_CONFIGURATION_CORSMETHODS] == null)
            {
                AFAttribute corsMethodsAttr = configElement.Attributes.Add("CorsMethods");
                corsMethodsAttr.Type = typeof(String);
                corsMethodsAttr.SetValue(new AFValue(corsMethods));
            }

            configElement.Attributes[Constants.PIWEBAPI_CONFIGURATION_CORSEACHSCANINTERVALS].SetValue(new AFValue(scanSearchInterval));
            configElement.Database.CheckIn(AFCheckedOutMode.ObjectsCheckedOutThisSession);
        }
예제 #6
0
        private static void CreateElements(AFDatabase database)
        {
            if (database == null)
            {
                return;
            }

            // here we create the configuration element
            // we do a small exception creating an attribute in this method.
            AFElement configuration;

            if (!database.Elements.Contains("Configuration"))
            {
                configuration = database.Elements.Add("Configuration");
                AFAttribute name = configuration.Attributes.Add("PIDataArchiveName");
                name.SetValue(new AFValue(database.DefaultPIServerName));
            }

            AFElement meters = database.Elements["Meters"];

            if (meters == null)
            {
                meters = database.Elements.Add("Meters");
            }

            AFElementTemplate basic    = database.ElementTemplates["MeterBasic"];
            AFElementTemplate advanced = database.ElementTemplates["MeterAdvanced"];

            foreach (int i in Enumerable.Range(1, 12))
            {
                string name = "Meter" + i.ToString("D3");
                if (!meters.Elements.Contains(name))
                {
                    AFElementTemplate eTemp = i <= 8 ? basic : advanced;
                    meters.Elements.Add(name, eTemp);
                }
            }

            if (database.IsDirty)
            {
                database.CheckIn();
            }
        }
예제 #7
0
        public static void CreateFeederElements(AFDatabase database)
        {
            if (database == null)
            {
                throw new ArgumentNullException(nameof(database));
            }

            Console.WriteLine("Creating a feeder element under the Feeders Element");
            AFElementTemplate template = database.ElementTemplates["FeederTemplate"];

            AFElement feeders = database.Elements["Feeders"];

            if (template == null || feeders == null)
            {
                return;
            }

            if (feeders.Elements.Contains("Feeder001"))
            {
                return;
            }
            AFElement feeder001 = feeders.Elements.Add("Feeder001", template);

            AFAttribute city = feeder001.Attributes["City"];

            if (city != null)
            {
                city.SetValue(new AFValue("London"));
            }

            AFAttribute power = feeder001.Attributes["Power"];

            power.ConfigString = @"%@\Configuration|PIDataArchiveName%\SINUSOID";

            if (database.IsDirty)
            {
                database.CheckIn();
            }
        }
예제 #8
0
        static void CreateFeederElements(AFDatabase database, String FeederName)
        {
            Console.WriteLine("Creating new element using feeder template..");

            AFElementTemplate template = database.ElementTemplates["Feeders"];

            AFElement feeder = database.Elements["Feeders"];


            if (template == null || feeder == null)
            {
                Console.WriteLine("Feeder template and parent missing");
                return;
            }

            if (feeder.Elements.Contains(FeederName))
            {
                return;
            }
            AFElement feeder01 = feeder.Elements.Add(FeederName, template);

            AFAttribute city = feeder01.Attributes["City"];

            if (city != null)
            {
                city.SetValue(new AFValue("London"));
            }

            AFAttribute power = feeder01.Attributes["Power"];

            power.ConfigString = @"\\PU-PIDARCDEV01\SINUSOID";

            if (database.IsDirty)
            {
                database.CheckIn();
            }
        }
예제 #9
0
        private AFElement CreateElementAndAttributes(AFDatabase db, AFCategory elementCategory, AFCategory attributeCategory)
        {
            AFElement el2 = db.Elements[Constants.AF_ELEMENT_NAME + "2"];

            if (el2 == null)
            {
                el2 = db.Elements.Add(Constants.AF_ELEMENT_NAME + "2");
            }


            AFElement el = db.Elements[Constants.AF_ELEMENT_NAME];

            if (el == null)
            {
                el = db.Elements.Add(Constants.AF_ELEMENT_NAME);
                el.Elements.Add(Constants.AF_ELEMENT_NAME + "Child1");
                el.Elements.Add(Constants.AF_ELEMENT_NAME + "Child2");
                el.Categories.Add(elementCategory);
            }


            AFAttribute tempAvg = el.Attributes["Temperature Average"];

            if (tempAvg == null)
            {
                tempAvg            = el.Attributes.Add("Temperature Average");
                tempAvg.Type       = typeof(Double);
                tempAvg.DefaultUOM = _piSystem.UOMDatabase.UOMClasses["Temperature"].UOMs["degree Celsius"];
            }

            AFAttribute temp = el.Attributes["Temperature"];

            if (temp == null)
            {
                temp      = el.Attributes.Add("Temperature");
                temp.Type = typeof(Double);
                temp.DataReferencePlugIn = _piSystem.DataReferencePlugIns["PI Point"];
                temp.ConfigString        = @"\\" + Constants.PI_DATA_SERVER_NAME + @"\sinusoid";
                temp.DefaultUOM          = _piSystem.UOMDatabase.UOMClasses["Temperature"].UOMs["degree Celsius"];
                AFAttribute limitHiAttr = temp.Attributes.Add(AFAttributeTrait.LimitHi.Abbreviation);
                limitHiAttr.Trait = AFAttributeTrait.LimitHi;
                limitHiAttr.SetValue(100, temp.DefaultUOM);
            }


            AFAttribute attribute = el.Attributes[Constants.AF_ATTRIBUTE_NAME];

            if (attribute == null)
            {
                attribute            = el.Attributes.Add(Constants.AF_ATTRIBUTE_NAME);
                attribute.Type       = typeof(Double);
                attribute.DefaultUOM = _piSystem.UOMDatabase.UOMClasses["Temperature"].UOMs["degree Celsius"];
                attribute.Categories.Add(attributeCategory);
                AFAttribute childAttribute  = attribute.Attributes.Add(Constants.AF_ATTRIBUTE_NAME + "Child1");
                AFAttribute childAttribute2 = attribute.Attributes.Add(Constants.AF_ATTRIBUTE_NAME + "Child2");
                AFAttribute limitHiAttr     = attribute.Attributes.Add(AFAttributeTrait.LimitHi.Abbreviation);
                limitHiAttr.Trait = AFAttributeTrait.LimitHi;
                limitHiAttr.SetValue(100, temp.DefaultUOM);
            }

            return(el);
        }
예제 #10
0
 // Writing Data to the AFServer
 /// <summary>
 /// Writes to AF, and checks in the element.
 /// </summary>
 /// <param name="element"> AFElement being written to.</param>
 /// <param name="attribute"> AFAttribute being changed.</param>
 /// <param name="value"> The new value being imported.</param>
 public static void writeToAF(AFElement element, AFAttribute attribute, double value)
 {
     AFValue input = new AFValue(attribute, value, AFTime.Now);
     attribute.SetValue(input);
     element.CheckIn();
 }