Esempio n. 1
0
        public void CreateAnalysisTest()
        {
            string     path     = Constants.AF_ELEMENT_PATH;
            PIAnalysis analysis = new PIAnalysis()
            {
                Name                   = "MyNewAnalysis",
                Description            = "",
                AnalysisRulePlugInName = "PerformanceEquation",
                GroupId                = 0,
                MaximumQueueSize       = 0,
                OutputTime             = "",
                Priority               = "High",
                PublishResults         = false,
                Status                 = "Disabled",
                TemplateName           = "",
                TimeRulePlugInName     = "Periodic"
            };

            instance.CreateAnalysis(webId, analysis);

            AFElement myElement = AFObject.FindObject(path) as AFElement;

            myElement.Refresh();

            if (myElement != null)
            {
                Assert.IsNotNull(myElement.Analyses[analysis.Name]);
            }
        }
Esempio n. 2
0
        public void CreateAttributeTest()
        {
            string      path      = Constants.AF_ELEMENT_PATH;
            PIAttribute attribute = new PIAttribute()
            {
                Name                = "Water1",
                Description         = "2008 Water Use",
                Type                = "Int32",
                TypeQualifier       = "",
                DataReferencePlugIn = "Table Lookup",
                ConfigString        = "SELECT [Water Use] FROM [Energy Use 2008] WHERE [Asset ID] = '%Element%'",
                IsConfigurationItem = false,
                IsHidden            = false,
                IsManualDataEntry   = false,
            };

            instance.CreateAttribute(webId, attribute);

            AFElement myElement = AFObject.FindObject(path) as AFElement;

            myElement.Refresh();

            if (myElement != null)
            {
                Assert.IsNotNull(myElement.Attributes["Water1"]);
            }
        }
Esempio n. 3
0
        public void DeleteTest()
        {
            string key = Constants.PIWEBAPI_CONFIGURATION_CORSMETHODS;

            instance.Delete(key);
            try
            {
                instance.Delete(key);
                Assert.IsTrue(false);
            }
            catch (Exception)
            {
            }
            configElement.Refresh();
            Assert.IsNull(configElement.Attributes[key]);
        }
        public void Init()
        {
            base.CommonInit();
            instance = client.StreamSet;
            base.CreateSampleDatabaseForTests();
            webIds = new List <string>();
            webIds.Add(client.Point.GetByPath(Constants.DATA_SERVER_PATH + @"\sinusoid").WebId);
            webIds.Add(client.Point.GetByPath(Constants.DATA_SERVER_PATH + @"\sinusoidu").WebId);
            webIds.Add(client.Point.GetByPath(Constants.DATA_SERVER_PATH + @"\cdt158").WebId);
            AFElement element = AFObject.FindObject(Constants.AF_ELEMENT_STREAMSET_PATH) as AFElement;

            element.Refresh();
            Assert.IsTrue(element.Attributes.Count == 3);
            webId      = client.Element.GetByPath(Constants.AF_ELEMENT_STREAMSET_PATH).WebId;
            attr1webId = client.Attribute.GetByPath(Constants.AF_ELEMENT_STREAMSET_PATH + "|sinusoid").WebId;
            attr2webId = client.Attribute.GetByPath(Constants.AF_ELEMENT_STREAMSET_PATH + "|sinusoidu").WebId;
            attr3webId = client.Attribute.GetByPath(Constants.AF_ELEMENT_STREAMSET_PATH + "|cdt158").WebId;
        }
Esempio n. 5
0
        public void CreateElementTest()
        {
            string    path    = Constants.AF_ELEMENT_PATH;
            PIElement element = new PIElement()
            {
                Name               = "B-210",
                Description        = "Boiler B-210",
                ExtendedProperties = new Dictionary <string, PIValue>()
            };

            element.ExtendedProperties.Add("Property", new PIValue(12.3));

            instance.CreateElement(webId, element);
            AFElement myElement = AFObject.FindObject(path) as AFElement;

            myElement.Refresh();

            if (myElement != null)
            {
                Assert.IsNotNull(myElement.Elements["B-210"]);
            }
        }
Esempio n. 6
0
        public void UpdateTest()
        {
            string    path    = Constants.AF_ELEMENT_PATH;
            PIElement element = instance.GetByPath(path, null);

            element.Id          = null;
            element.Description = "New element description";
            element.Links       = null;
            element.Path        = null;
            element.WebId       = null;
            element.HasChildren = null;
            instance.Update(webId, element);

            StandardPISystem.Refresh();
            AFElement myElement = AFObject.FindObject(path) as AFElement;

            myElement.Refresh();

            if (myElement != null)
            {
                Assert.IsTrue(myElement.Description == element.Description);
            }
        }
Esempio n. 7
0
        public async Task WriteAndRefreshDeadlock()
        {
            using (CancellationTokenSource cts = new CancellationTokenSource())
            {
                Task refresh = Task.Run(() =>
                {
                    cts.Token.Register(Thread.CurrentThread.Abort);

                    for (int i = 0; i < 100; i++)
                    {
                        myElement.Refresh();
                    }
                });

                Task writer = Task.Run(() =>
                {
                    cts.Token.Register(Thread.CurrentThread.Abort);

                    for (int i = 0; i < 100; i++)
                    {
                        myElement.Elements.Add("Child Element " + i);
                        myElement.CheckIn();
                    }
                });

                Task timeout = Task.Delay(TimeSpan.FromSeconds(10));

                await Task.WhenAny(refresh, writer, timeout);

                Assert.True(timeout.IsCompleted);
                Assert.False(refresh.IsCompleted);
                Assert.False(writer.IsCompleted);

                cts.Cancel();
            }
        }