public static void CaptureValues(AFDatabase database, AFElementTemplate eventFrameTemplate)
        {
            if (database == null)
            {
                throw new ArgumentNullException(nameof(database));
            }
            if (eventFrameTemplate == null)
            {
                throw new ArgumentNullException(nameof(eventFrameTemplate));
            }

            // Formulate search constraints on time and template
            AFTime startTime   = DateTime.Today.AddDays(-7);
            string queryString = $"template:\"{eventFrameTemplate.Name}\"";

            using (AFEventFrameSearch eventFrameSearch = new AFEventFrameSearch(database, "EventFrame Captures", AFEventFrameSearchMode.ForwardFromStartTime, startTime, queryString))
            {
                eventFrameSearch.CacheTimeout = TimeSpan.FromMinutes(5);
                int count = 0;
                foreach (AFEventFrame item in eventFrameSearch.FindObjects())
                {
                    item.CaptureValues();
                    if ((count++ % 500) == 0)
                    {
                        database.CheckIn();
                    }
                }

                if (database.IsDirty)
                {
                    database.CheckIn();
                }
            }
        }
        static void CreateEventFrames(AFDatabase database, AFElementTemplate eventFrameTemplate)
        {
            string queryString = "Template:MeterBasic";

            {
                // This method returns the collection of AFBaseElement objects that were created with this template.
                using (AFElementSearch elementQuery = new AFElementSearch(database, "Meters", queryString))
                {
                    DateTime timeReference = DateTime.Today.AddDays(-7);
                    int      count         = 0;
                    foreach (AFElement meter in elementQuery.FindElements())
                    {
                        foreach (int day in Enumerable.Range(1, 7))
                        {
                            AFTime       startTime = new AFTime(timeReference.AddDays(day - 1));
                            AFTime       endTime   = new AFTime(startTime.LocalTime.AddDays(1));
                            AFEventFrame ef        = new AFEventFrame(database, "*", eventFrameTemplate);
                            ef.SetStartTime(startTime);
                            ef.SetEndTime(endTime);
                            ef.PrimaryReferencedElement = meter;
                            // It is good practice to periodically check in the database
                            if (++count % 500 == 0)
                            {
                                database.CheckIn();
                            }
                        }
                    }
                }
            }
            if (database.IsDirty)
            {
                database.CheckIn();
            }
        }
        static void SwitchToJapanese(AFDatabase db)
        {
            AFTable translations = createOrReturnTranslationLibrary(db);

            // Get all elements and all attributes
            foreach (AFElement element in db.Elements)
            {
                translateElementAndChild(element, translations.Table);
                db.CheckIn();
            }
            // Get all tables
            foreach (AFTable table in db.Tables)
            {
                if (table != translations)
                {
                    translateTableHeaders(table, translations.Table);
                }
            }
            db.CheckIn();
            foreach (AFElementTemplate elementTemplate in db.ElementTemplates)
            {
                translateElementTemplate(elementTemplate, translations.Table, db);
                //insert(translations.Table, elemtemplate.NamingPattern);
                db.CheckIn();
            }
        }
예제 #4
0
 public void WriteAllQuery(Dictionary <string, Query> results)
 {
     foreach (Query q in results.Values)
     {
         WriteQuery(q);
     }
     db.CheckIn();
 }
예제 #5
0
        private static void CreateWeakReferences(AFDatabase database)
        {
            if (database == null)
            {
                return;
            }

            AFReferenceType   weakRefType  = database.ReferenceTypes["Weak Reference"];
            AFElement         meters       = database.Elements["Meters"];
            AFElement         locations    = database.Elements["Geographical Locations"];
            AFElementTemplate cityTemplate = database.ElementTemplates["City"];

            foreach (AFElement meter in meters.Elements)
            {
                string cityName = meter.Attributes["City"].GetValue().ToString();
                if (string.IsNullOrEmpty(cityName))
                {
                    continue;
                }
                AFElement city = locations.Elements[cityName];
                if (city == null)
                {
                    locations.Elements.Add(cityName, cityTemplate);
                }
                if (!city.Elements.Contains(meter.Name))
                {
                    city.Elements.Add(meter, weakRefType);
                }
            }
            if (database.IsDirty)
            {
                database.CheckIn();
            }
        }
예제 #6
0
        private static void CreateCategories(AFDatabase database)
        {
            if (database == null)
            {
                return;
            }
            var items = new List <string>
            {
                "Measures Energy",
                "Shows Status",
                "Building Info",
                "Location",
                "Time - Series Data"
            };

            foreach (var item in items)
            {
                if (!database.ElementCategories.Contains(item))
                {
                    database.ElementCategories.Add(item);
                }
            }
            if (database.IsDirty)
            {
                database.CheckIn();
            }
        }
예제 #7
0
        private static void CreateEnumerationSets(AFDatabase database)
        {
            if (database == null)
            {
                return;
            }

            if (!database.EnumerationSets.Contains("Building Type"))
            {
                AFEnumerationSet bTypeEnum = database.EnumerationSets.Add("Building Type");
                bTypeEnum.Add("Residential", 0);
                bTypeEnum.Add("Business", 1);
            }

            if (!database.EnumerationSets.Contains("Meter Status"))
            {
                AFEnumerationSet mStatusEnum = database.EnumerationSets.Add("Meter Status");
                mStatusEnum.Add("Good", 0);
                mStatusEnum.Add("Bad", 1);
            }
            if (database.IsDirty)
            {
                database.CheckIn();
            }
        }
예제 #8
0
        private static void CreateElements(AFDatabase database)
        {
            if (database == null)
            {
                return;
            }

            AFElement meters;

            if (!database.Elements.Contains("Meters"))
            {
                meters = database.Elements.Add("Meters");
            }
            else
            {
                meters = database.Elements["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;
                    AFElement         e     = meters.Elements.Add(name, eTemp);
                }
            }

            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 NotificationRuleResendWebServiceTest()
        {
            AFDatabase db                   = AFFixture.AFDatabase;
            var        elementName          = $"{NotificationsFixture.TestPrefix}_{NotificationsFixture.TestInfix}_{nameof(NotificationRuleResendWebServiceTest)}";
            var        notificationRuleName = $"{NotificationsFixture.TestPrefix}_{NotificationsFixture.TestInfix}_NotificationRule1";
            var        eventFrameName       = $"{NotificationsFixture.TestPrefix}_{NotificationsFixture.TestInfix}_EventFrame1";
            var        resendInterval       = TimeSpan.FromMinutes(1);

            AFFixture.RemoveElementIfExists(elementName, Output);
            Guid?eventFrameId = null;

            try
            {
                Output.WriteLine($"Create element [{elementName}] with notification rule [{notificationRuleName}].");
                var element          = db.Elements.Add(elementName);
                var notificationRule = element.NotificationRules.Add(notificationRuleName);
                notificationRule.Criteria       = $"Name:{NotificationsFixture.TestPrefix}*";
                notificationRule.ResendInterval = resendInterval;
                var format = notificationRule.DeliveryFormats.Add("testFormat", WebServicePlugIn);
                NotificationsFixture.SetFormatProperties(format.Properties, nameof(NotificationRuleResendWebServiceTest));

                var webServiceEndpoint = NotificationsFixture.GetSoapWebServiceEndpoint();
                var subscriber         = notificationRule.Subscribers.Add(webServiceEndpoint);
                subscriber.DeliveryFormat = format;
                notificationRule.SetStatus(AFStatus.Enabled);
                db.CheckIn();

                Output.WriteLine("Waiting for notification to startup.");
                Thread.Sleep(TimeSpan.FromSeconds(10));

                var eventFrame = new AFEventFrame(db, eventFrameName)
                {
                    PrimaryReferencedElement = element,
                };

                Output.WriteLine($"Create event frame [{eventFrameName}].");
                eventFrame.SetStartTime(AFTime.Now);
                eventFrame.CheckIn();
                eventFrameId = eventFrame.ID;

                var msg = NotificationsFixture.Service.WaitForMessage(resendInterval);
                Assert.True(notificationRule.ID == msg.NotificationRuleId, "Notification rule is not set properly.");
                Assert.True(msg.Content == nameof(NotificationRuleResendWebServiceTest), "The message content is not set properly.");

                // Waiting for resend
                Output.WriteLine("Verify notification is resent.");
                Thread.Sleep(resendInterval);
                msg = NotificationsFixture.Service.WaitForMessage(resendInterval);
                Assert.True(notificationRule.ID == msg.NotificationRuleId, "Notification rule is not set properly.");
                Assert.True(msg.Content == nameof(NotificationRuleResendWebServiceTest), "The message content is not set properly.");
            }
            finally
            {
                AFFixture.RemoveElementIfExists(elementName, Output);
                if (eventFrameId != null)
                {
                    AFFixture.RemoveEventFrameIfExists(eventFrameId.GetValueOrDefault(), Output);
                }
            }
        }
예제 #11
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();
        }
예제 #12
0
        public static void CreateWeakReference(AFDatabase database)
        {
            if (database == null)
            {
                throw new ArgumentNullException(nameof(database));
            }

            Console.WriteLine("Adding a weak reference of the Feeder001 under London");
            AFReferenceType weakRefType = database.ReferenceTypes["Weak Reference"];

            AFElement london     = database.Elements["Geographical Locations"].Elements["London"];
            AFElement feeder0001 = database.Elements["Feeders"].Elements["Feeder001"];

            if (london == null || feeder0001 == null)
            {
                return;
            }

            if (!london.Elements.Contains(feeder0001))
            {
                london.Elements.Add(feeder0001, weakRefType);
            }
            if (database.IsDirty)
            {
                database.CheckIn();
            }
        }
예제 #13
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();
        }
예제 #14
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();
        }
예제 #15
0
        private static void CreateWeakReferences(AFDatabase database)
        {
            if (database == null)
            {
                return;
            }

            AFReferenceType weakRefType = database.ReferenceTypes["Weak Reference"];

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

            AFElement hogwarts = database.Elements["Wizarding World"].Elements["Hogwarts"];

            hogwarts.Elements.Add(meters.Elements["Meter001"], weakRefType);
            hogwarts.Elements.Add(meters.Elements["Meter002"], weakRefType);
            hogwarts.Elements.Add(meters.Elements["Meter003"], weakRefType);
            hogwarts.Elements.Add(meters.Elements["Meter004"], weakRefType);

            AFElement diagonAlley = database.Elements["Wizarding World"].Elements["Diagon Alley"];

            diagonAlley.Elements.Add(meters.Elements["Meter005"], weakRefType);
            diagonAlley.Elements.Add(meters.Elements["Meter006"], weakRefType);
            diagonAlley.Elements.Add(meters.Elements["Meter007"], weakRefType);
            diagonAlley.Elements.Add(meters.Elements["Meter008"], weakRefType);

            AFElement hogsmeade = database.Elements["Wizarding World"].Elements["Hogsmeade"];

            hogsmeade.Elements.Add(meters.Elements["Meter009"], weakRefType);
            hogsmeade.Elements.Add(meters.Elements["Meter010"], weakRefType);
            hogsmeade.Elements.Add(meters.Elements["Meter011"], weakRefType);
            hogsmeade.Elements.Add(meters.Elements["Meter012"], weakRefType);

            database.CheckIn();
        }
예제 #16
0
        private static void CreateCategories(AFDatabase database)
        {
            if (database == null)
            {
                return;
            }

            if (!database.ElementCategories.Contains("Measures Energy"))
            {
                database.ElementCategories.Add("Measures Energy");
            }

            if (!database.ElementCategories.Contains("Shows Status"))
            {
                database.ElementCategories.Add("Shows Status");
            }

            if (!database.AttributeCategories.Contains("Building Info"))
            {
                database.AttributeCategories.Add("Building Info");
            }

            if (!database.AttributeCategories.Contains("Location"))
            {
                database.AttributeCategories.Add("Location");
            }

            if (!database.AttributeCategories.Contains("Time-Series Data"))
            {
                database.AttributeCategories.Add("Time-Series Data");
            }

            database.CheckIn();
        }
예제 #17
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();
            }
        }
예제 #18
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();
        }
        public void EventFrameTest()
        {
            AFDatabase db = Fixture.AFDatabase;

            const string EventFrameName   = "OSIsoftTests_AF_InitEF#1A";
            const string EventFrameRename = "OSIsoftTests_AF_EventFrameTest_NewName";

            var testData = new EventFrameTestConfiguration(EventFrameName);

            try
            {
                Output.WriteLine($"Create Event Frame [{EventFrameName}].");
                var evtfr1 = FullEventFrameCreate(db, testData);
                db.CheckIn();

                Output.WriteLine("Confirm Event Frame created and found.");
                db     = Fixture.ReconnectToDB(); // This operation clears AFSDK cache and assures retrieval from AF server
                evtfr1 = AFEventFrame.FindEventFrame(db.PISystem, evtfr1.ID);
                FullEventFrameVerify(db, evtfr1.ID, testData, Output);

                Output.WriteLine($"Rename Event Frame to [{EventFrameRename}].");
                evtfr1.Name = EventFrameRename;
                db.CheckIn();

                // Update test data with new name
                testData.Name = EventFrameRename;

                Output.WriteLine($"Verify Event Frame [{EventFrameRename}] found on reread.");
                db     = Fixture.ReconnectToDB();
                evtfr1 = AFEventFrame.FindEventFrame(db.PISystem, evtfr1.ID);
                FullEventFrameVerify(db, evtfr1.ID, testData, Output);

                Output.WriteLine($"Delete Event Frame [{EventFrameRename}].");
                evtfr1.Delete();
                db.CheckIn();

                Output.WriteLine($"Confirm Event Frame deleted.");
                db = Fixture.ReconnectToDB();
                var deletedEFSearch = AFEventFrame.FindEventFrame(db.PISystem, evtfr1.ID);
                Assert.True(deletedEFSearch == null, $"Event Frame [{EventFrameRename}] was not deleted as expected.");
            }
            finally
            {
                Fixture.RemoveElementIfExists(testData.EventFrameElementName, Output);
            }
        }
예제 #20
0
        public static AFDatabase createDB(PISystem system, string xml, string name)
        {
            AFDatabase db = system.Databases.Add(name);

            system.ImportXml(db, PIImportMode.AllowCreate, xml);
            db.CheckIn();
            return(db);
        }
예제 #21
0
 public static void CloseDowntimeEvents(AFDatabase afdb, IEnumerable <AFEventFrame> events)
 {
     foreach (var item in events)
     {
         item.SetEndTime(DateTime.Now);
         Console.WriteLine($"Event Close {item.Name}, time: {item.StartTime} - {item.EndTime} Duration: {item.Duration}");
     }
     afdb.CheckIn(AFCheckedOutMode.ObjectsCheckedOutThisSession);
 }
 static void translateElementTemplate(AFElementTemplate elem, DataTable dt, AFDatabase db)
 {
     elem.Name        = translate(dt, elem.Name, "Japanese");
     elem.Description = translate(dt, elem.Description, "Japanese");
     foreach (AFAttributeTemplate attribute in elem.AttributeTemplates)
     {
         translateAttribute(elem, attribute, dt);
         db.CheckIn();
     }
 }
예제 #23
0
        static void CreateFeedersRootElement(AFDatabase database)
        {
            if (database.Elements.Contains("Feeders"))
            {
                return;
            }

            database.Elements.Add("Feeders");
            database.CheckIn();
        }
 static void CreateFeedersRootElement(AFDatabase database)
 {
     if (database.Elements.Contains("Feeders"))
         return;
     else
     {
         database.Elements.Add("Feeders");
     }
     database.CheckIn();
 }
        static void CreateFeedersRootElement(AFDatabase database)
        {
            Console.WriteLine("Creating the Feeders root Element");
            if (database.Elements.Contains("Feeders"))
            {
                return;
            }

            database.Elements.Add("Feeders");
            database.CheckIn();
        }
예제 #26
0
        private void CleanEventFrames(DateTime startTime, DateTime endTime, string template)
        {
            this.Enabled = false;
            try {
                var efTemplate = _afDb.ElementTemplates[template];
                if (efTemplate == null)
                {
                    throw new Exception(string.Format("{0} not found", template));
                }

                int count = 0;
                while (true)
                {
                    var frames = AFEventFrame.FindEventFrames(_afDb, null, AFSearchMode.Overlapped, startTime, endTime, "*", "*", null,
                                                              efTemplate, null, false, AFSortField.StartTime, AFSortOrder.Ascending, 0, 1000);

                    if (frames.Count <= 0)
                    {
                        break;
                    }

                    progressBar1.Maximum = frames.Count;
                    progressBar1.Step    = 1;
                    progressBar1.Value   = 0;

                    foreach (AFEventFrame frame in frames)
                    {
                        double ts = frame.EndTime.UtcSeconds - frame.StartTime.UtcSeconds;

                        if (ts < 1.0 && string.Equals(frame.Template.Name, template))
                        {
                            try {
                                frame.Delete();
                                count++;

                                if (count >= 1000)
                                {
                                    _afDb.CheckIn(AFCheckedOutMode.ObjectsCheckedOutThisThread);
                                    count = 0;
                                }
                            } catch (Exception) {
                                // event frames may be locked by users
                            }
                        }

                        progressBar1.PerformStep();
                        Application.DoEvents();
                    }
                }
            } finally {
                this.Enabled = true;
                MessageBox.Show("Cleaning finished");
            }
        }
        static void CreateEventFrames(AFDatabase database, AFElementTemplate eventFrameTemplate)
        {
            const int pageSize   = 1000;
            int       startIndex = 0;
            int       totalCount;

            do
            {
                AFNamedCollectionList <AFBaseElement> results = database.ElementTemplates["MeterBasic"].FindInstantiatedElements(
                    includeDerived: true,
                    sortField: AFSortField.Name,
                    sortOrder: AFSortOrder.Ascending,
                    startIndex: startIndex,
                    maxCount: pageSize,
                    totalCount: out totalCount
                    );

                IList <AFElement> meters = results.Select(elm => (AFElement)elm).ToList();

                DateTime timereference = DateTime.Now.AddDays(-7);
                //AFTime startTime = new AFTime(new DateTime(timereference.Year, timereference.Month, timereference.Day, 0, 0, 0, DateTimeKind.Local));
                foreach (AFElement meter in meters)
                {
                    foreach (int day in Enumerable.Range(1, 7))
                    {
                        AFTime       startTime = new AFTime(timereference.AddDays(day - 1));
                        AFTime       endTime   = new AFTime(startTime.LocalTime.AddDays(1));
                        AFEventFrame ef        = new AFEventFrame(database, "*", eventFrameTemplate);
                        ef.SetStartTime(startTime);
                        ef.SetEndTime(endTime);
                        ef.PrimaryReferencedElement = meter;
                    }
                }

                database.CheckIn();

                startIndex += pageSize;
            } while (startIndex < totalCount);

            database.CheckIn();
        }
        static AFTable createOrReturnTranslationLibrary(AFDatabase db)
        {
            AFTable translations = db.Tables["Translations"];

            if (translations == null)
            {
                translations = db.Tables.Add("Translations");
                addLanguageTitles(translations);
                db.CheckIn();
            }
            return(translations);
        }
        static void Main(string[] args)
        {
            PISystem   system = PISystem.CreatePISystem("localhost");
            AFDatabase kitdb  = system.Databases["Database85"];

            SwitchToJapanese(kitdb);

            // Create the translation service.

            kitdb.CheckIn();
            Console.ReadLine();
        }
예제 #30
0
        static AFTable createOrReturnTranslationTable(AFDatabase db)
        {
            AFTable translations = db.Tables[$"Translations_{language}"];

            if (translations == null)
            {
                translations = db.Tables.Add($"Translations_{language}");
                addLanguageTitles(translations);
                db.CheckIn();
            }
            return(translations);
        }
        static public void CaptureValues(AFDatabase database, AFElementTemplate eventFrameTemplate)
        {
            // Formulate search constraints on time and template
            DateTime           timereference    = DateTime.Now.AddDays(-7);
            AFTime             startTime        = new AFTime(new DateTime(timereference.Year, timereference.Month, timereference.Day, 0, 0, 0, DateTimeKind.Local));
            string             query            = string.Format("template:\"{0}\"", eventFrameTemplate.Name);
            AFEventFrameSearch eventFrameSearch = new AFEventFrameSearch(database, "EventFrame Captures", AFEventFrameSearchMode.ForwardFromStartTime, startTime, query);

            int startIndex = 0;

            foreach (AFEventFrame item in eventFrameSearch.FindEventFrames())
            {
                item.CaptureValues();
                if ((startIndex++ % 512) == 0)
                {
                    database.CheckIn();
                }
            }

            database.CheckIn();
        }
        private void CreateEventFrames(AFDatabase afDatabase)
        {
            AFElementTemplate efTemplate = afDatabase.ElementTemplates["BasicEventFrameTemplate"];
            for (int i = 0; i < 5; i++)
            {
                AFEventFrame ef = new AFEventFrame(afDatabase, "EF_" + i, efTemplate);
                ef.SetStartTime(new AFTime(string.Format("t-{0}d", i + 1)));
                ef.SetEndTime(new AFTime(string.Format("t-{0}d", i)));

                AFElement element = afDatabase.Elements["Region_0"].Elements["BoilerA"];
                ef.PrimaryReferencedElement = element;
            }

            // Do a bulk check in of all changes made so far.
            afDatabase.CheckIn();
        }
        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();
        }
        private static void CreateEnumerationSets(AFDatabase database)
        {
            if (database == null) return;

            if (!database.EnumerationSets.Contains("Building Type"))
            {
                AFEnumerationSet bTypeEnum = database.EnumerationSets.Add("Building Type");
                bTypeEnum.Add("Residential", 0);
                bTypeEnum.Add("Business", 1);
            }

            if (!database.EnumerationSets.Contains("Meter Status"))
            {
                AFEnumerationSet mStatusEnum = database.EnumerationSets.Add("Meter Status");
                mStatusEnum.Add("Good", 0);
                mStatusEnum.Add("Bad", 1);
            }

            database.CheckIn();
        }
        static void CreateElementTemplate(AFDatabase database)
        {
            string templateName = "FeederTemplate";
            AFElementTemplate feederTemplate;
            if (database.ElementTemplates.Contains(templateName))
                return;
            else
                feederTemplate = database.ElementTemplates.Add(templateName);

            AFAttributeTemplate district = feederTemplate.AttributeTemplates.Add("District");
            district.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 CreateElements(AFDatabase afDatabase)
        {
            AFElementTemplate elemTemplate = afDatabase.ElementTemplates["BasicBoilerTemplate"];

            for (int i = 0; i < 5; i++)
            {
                AFElement element = afDatabase.Elements.Add("Region_" + i);
            }

            foreach (AFElement element in afDatabase.Elements)
            {
                AFElement childA = element.Elements.Add("BoilerA", elemTemplate);
                AFElement childB = element.Elements.Add("BoilerB", elemTemplate);

                childA.Attributes["Limit"].SetValue(new AFValue("10"));
                childB.Attributes["Limit"].SetValue(new AFValue("50"));
            }

            // Do a bulk check in of all changes made so far.
            afDatabase.CheckIn();
        }
        private static void CreateCategories(AFDatabase database)
        {
            if (database == null) return;

            if (!database.ElementCategories.Contains("Measures Energy"))
                database.ElementCategories.Add("Measures Energy");

            if (!database.ElementCategories.Contains("Shows Status"))
                database.ElementCategories.Add("Shows Status");

            if (!database.AttributeCategories.Contains("Building Info"))
                database.AttributeCategories.Add("Building Info");

            if (!database.AttributeCategories.Contains("Location"))
                database.AttributeCategories.Add("Location");

            if (!database.AttributeCategories.Contains("Time-Series Data"))
                database.AttributeCategories.Add("Time-Series Data");

            database.CheckIn();
        }
        static AFElementTemplate CreateEventFrameTemplate(AFDatabase database)
        {
            AFElementTemplate eventframetemplate = null;
            if (database.ElementTemplates.Contains("Daily Usage"))
            {
                return database.ElementTemplates["Daily Usage"];
            }

            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(double);
            usage.DataReferencePlugIn = AFDataReference.GetPIPointDataReference();
            usage.ConfigString = @".\Elements[.]|Energy Usage;TimeRangeMethod=Average";
            usage.DefaultUOM = database.PISystem.UOMDatabase.UOMs["kilowatt hour"];

            database.CheckIn();
            return eventframetemplate;
        }
        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();
        }
        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();
        }
        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();
        }
        private static void CreateDistrictElements(AFDatabase database)
        {
            if (database == null) return;

            if (!database.Elements.Contains("Wizarding World"))
            {
                AFElement wizardingWorld = database.Elements.Add("Wizarding World");
                AFElementTemplate districtTemplate = database.ElementTemplates["District"];

                wizardingWorld.Elements.Add("Diagon Alley", districtTemplate);
                wizardingWorld.Elements.Add("Hogsmeade", districtTemplate);
                wizardingWorld.Elements.Add("Hogwarts", districtTemplate);
            }

            database.CheckIn();
        }
        private static void CreateElements(AFDatabase database)
        {
            if (database == null) return;

            AFElement meters;
            if (!database.Elements.Contains("Meters"))
                meters = database.Elements.Add("Meters");
            else
                meters = database.Elements["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;
                    AFElement e = meters.Elements.Add(name, eTemp);
                }
            }

            database.CheckIn();
        }
        static void CreateWeakReference(AFDatabase database)
        {
            AFReferenceType weakRefType = database.ReferenceTypes["Weak Reference"];

            AFElement hogwarts = database.Elements["Wizarding World"].Elements["Hogwarts"];
            AFElement feeder0001 = database.Elements["Feeders"].Elements["Feeder001"];
            if (hogwarts == null || feeder0001 == null) return;

            hogwarts.Elements.Add(feeder0001, weakRefType);

            database.CheckIn();
        }
        static public void CaptureValues(AFDatabase database, AFElementTemplate eventFrameTemplate)
        {
            // Formulate search constraints on time and template
            DateTime timereference = DateTime.Now.AddDays(-7);
            AFTime startTime = new AFTime(new DateTime(timereference.Year, timereference.Month, timereference.Day, 0, 0, 0, DateTimeKind.Local));
            string query = string.Format("template:\"{0}\"", eventFrameTemplate.Name);
            AFEventFrameSearch eventFrameSearch = new AFEventFrameSearch(database, "EventFrame Captures", AFEventFrameSearchMode.ForwardFromStartTime, startTime, query);

            int startIndex = 0;
            foreach (AFEventFrame item in eventFrameSearch.FindEventFrames())
            {
                item.CaptureValues();
                if ((startIndex++ % 512) == 0)
                    database.CheckIn();
            }

            database.CheckIn();
        }
        private static void CreateWeakReferences(AFDatabase database)
        {
            if (database == null) return;

            AFReferenceType weakRefType = database.ReferenceTypes["Weak Reference"];

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

            AFElement hogwarts = database.Elements["Wizarding World"].Elements["Hogwarts"];
            hogwarts.Elements.Add(meters.Elements["Meter001"], weakRefType);
            hogwarts.Elements.Add(meters.Elements["Meter002"], weakRefType);
            hogwarts.Elements.Add(meters.Elements["Meter003"], weakRefType);
            hogwarts.Elements.Add(meters.Elements["Meter004"], weakRefType);

            AFElement diagonAlley = database.Elements["Wizarding World"].Elements["Diagon Alley"];
            diagonAlley.Elements.Add(meters.Elements["Meter005"], weakRefType);
            diagonAlley.Elements.Add(meters.Elements["Meter006"], weakRefType);
            diagonAlley.Elements.Add(meters.Elements["Meter007"], weakRefType);
            diagonAlley.Elements.Add(meters.Elements["Meter008"], weakRefType);

            AFElement hogsmeade = database.Elements["Wizarding World"].Elements["Hogsmeade"];
            hogsmeade.Elements.Add(meters.Elements["Meter009"], weakRefType);
            hogsmeade.Elements.Add(meters.Elements["Meter010"], weakRefType);
            hogsmeade.Elements.Add(meters.Elements["Meter011"], weakRefType);
            hogsmeade.Elements.Add(meters.Elements["Meter012"], weakRefType);

            database.CheckIn();
        }
        static void CreateEventFrames(AFDatabase database, AFElementTemplate eventFrameTemplate)
        {
            const int pageSize = 1000;
            int startIndex = 0;
            int totalCount;
            do
            {
                AFNamedCollectionList<AFBaseElement> results = database.ElementTemplates["MeterBasic"].FindInstantiatedElements(
                    includeDerived: true,
                    sortField: AFSortField.Name,
                    sortOrder: AFSortOrder.Ascending,
                    startIndex: startIndex,
                    maxCount: pageSize,
                    totalCount: out totalCount
                    );

                IList<AFElement> meters = results.Select(elm => (AFElement)elm).ToList();

                DateTime timereference = DateTime.Now.AddDays(-7);
                //AFTime startTime = new AFTime(new DateTime(timereference.Year, timereference.Month, timereference.Day, 0, 0, 0, DateTimeKind.Local));
                foreach (AFElement meter in meters)
                {
                    foreach (int day in Enumerable.Range(1, 7))
                    {
                        AFTime startTime = new AFTime(timereference.AddDays(day - 1));
                        AFTime endTime = new AFTime(startTime.LocalTime.AddDays(1));
                        AFEventFrame ef = new AFEventFrame(database, "*", eventFrameTemplate);
                        ef.SetStartTime(startTime);
                        ef.SetEndTime(endTime);
                        ef.PrimaryReferencedElement = meter;
                    }
                }

                database.CheckIn();

                startIndex += pageSize;
            } while (startIndex < totalCount);

            database.CheckIn();
        }