Esempio n. 1
0
        // Import Saved Log
        /// <summary>
        /// Imports a saved file into Matlab.
        /// </summary>
        /// <param name="path"> The path to the importe File.</param>
        /// <returns></returns>
        public string[] importLog(string path)
        {
            try
            {
                string[] lines = LogSystem.ImportLog(path);
                foreach (string line in lines)
                {
                    if (line != string.Empty)
                    {
                        string[] info = Regex.Split(line, @"=");
                        mainForm.Status("Importing: " + info[1] + " as " + info[0]);

                        if (info.Length == 2)
                        {
                            _curServer   = info[0];
                            _curDatabase = info[1];
                        }
                        else if (info.Length == 6) //Absolute Time
                        {
                            if (info[5] != string.Empty)
                            {
                                mainForm.dataPrefDialog.setupDataPreferences(info[5]);
                            }
                            string srv_db = "'" + _curServer + "'_'" + _curDatabase + "'";
                            if (info[2] == "PI.Point")
                            {
                                getPIData(info[1], _curServer, info[0], info[3], info[4], true);
                            }
                            else
                            {
                                getAFData(srv_db, info[1], info[0], info[2], info[3], info[4], true);
                            }
                        }
                        else // Dates
                        {
                            string[] time = Regex.Split(info[3], @"-");
                            if (info[4] != string.Empty)
                            {
                                mainForm.dataPrefDialog.setupDataPreferences(info[4]);
                            }
                            string srv_db = "'" + _curServer + "'_'" + _curDatabase + "'";
                            if (info[2] == "PI.Point")
                            {
                                getPIData(info[1], _curServer, info[0], time[0], time[1], true);
                            }
                            else
                            {
                                try
                                {
                                    List <string> paths = new List <string>()
                                    {
                                        info[2]
                                    };
                                    AFKeyedResults <string, AFEventFrame> frames = AFEventFrame.FindEventFramesByPath(paths, null);

                                    int          i     = frames.Count;
                                    AFEventFrame frame = frames[paths[0]];
                                    AFAccess.getEventFrameData(srv_db, info[1], info[0], frame, true);
                                }
                                catch
                                {
                                    getAFData(srv_db, info[1], info[0], info[2], time[0], time[1], true);
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                mainForm.Status("ERROR: Invalid import file. Please choose a different file.");
            }
            return(new string[] { _curServer, _curDatabase });
        }
Esempio n. 2
0
        public void AFReadWriteTest()
        {
            var elementName     = "OSIsoftTestElement";
            var elementNameEdit = $"{elementName}2";

            Fixture.Client.Headers.Add(HttpRequestHeader.CacheControl, "no-cache");

            // Get Database object from PI Web API to extract its WebId
            var databaseWebIdRequestUrl = $"{Fixture.HomePageUrl}/assetdatabases?path=\\\\{Settings.AFServer}\\{Settings.AFDatabase}";

            Output.WriteLine($"Get database object for [{Settings.AFDatabase}] from Web API at Url [{databaseWebIdRequestUrl}].");
            var databaseData  = JObject.Parse(Fixture.Client.DownloadString(databaseWebIdRequestUrl));
            var databaseWebId = (string)databaseData["WebId"];

            // Skip Write/Update portion of test if writes are disabled
            if (Fixture.DisableWrites)
            {
                Output.WriteLine($"Writes are disabled, skipping that portion of the test.");
                return;
            }

            // Create test Element object under test Database
            var createUrl   = $"{Fixture.HomePageUrl}/assetdatabases/{databaseWebId}/elements";
            var elementJson = $"{{\"Name\": \"{elementName}\"}}";

            Output.WriteLine($"Create element [{elementName}] under [{Settings.AFDatabase}] through Web API using [{elementJson}] at Url [{createUrl}].");
            Fixture.Client.UploadString(createUrl, "POST", elementJson);

            // Check Element exists in AF
            Output.WriteLine($"Verify element object [{elementName}] exists through Web API.");
            var path          = $"\\\\{Settings.AFServer}\\{Settings.AFDatabase}\\{elementName}";
            var foundElements = AFElement.FindElementsByPath(new string[] { path }, Fixture.AFFixture.PISystem);
            var element       = foundElements.FirstOrDefault();

            Assert.True(element != null, $"Test Element [{elementName}] was not found in AF.");
            var elementEditJson = $"{{\"Name\": \"{elementNameEdit}\"}}";
            var location        = string.Empty;

            try
            {
                // Extract new Element URL off create response headers
                location = Fixture.Client.ResponseHeaders["Location"];

                // Change Element name
                Output.WriteLine($"Rename element object [{elementName}] to [{elementNameEdit}] through Web API.");
                Fixture.Client.UploadString(location, "PATCH", elementEditJson);

                // Check Element was renamed in AF
                element.Refresh();
                Assert.True(element.Name == elementNameEdit, $"Test Element [{elementName}] was not renamed to [{elementNameEdit}] in AF.");

                // Request full Element object from PI Web API to test read, check name value
                Output.WriteLine($"Read full element object [{elementName}] from Web API.");
                var readData = JObject.Parse(Fixture.Client.DownloadString(location));
                Assert.True(string.Equals((string)readData["Name"], elementNameEdit, StringComparison.OrdinalIgnoreCase),
                            $"Test Element [{elementName}] was not renamed to [{elementNameEdit}] in read data.");

                // Create Attribute
                var createAttributeUrl = $"{location}/attributes";
                var attributeJson      = $"{{\"Name\":\"Attribute\"}}";
                Output.WriteLine($"Create attribute object 'Attribute' through Web API using [{attributeJson}] at Url [{createAttributeUrl}].");
                Fixture.Client.UploadString(createAttributeUrl, "POST", attributeJson);

                // Check Attribute was added in AF
                element.Refresh();
                Assert.True(element.Attributes.Count == 1, $"Test Attribute 'Attribute' was not created in AF.");
            }
            finally
            {
                // Delete test Element
                Fixture.Client.UploadString(location, "DELETE", string.Empty);
            }

            // Create test Event Frame object under test Database
            createUrl = $"{Fixture.HomePageUrl}/assetdatabases/{databaseWebId}/eventframes";
            Output.WriteLine($"Create event frame object [{element}] through Web API using [{elementJson}] at Url [{createUrl}].");
            Fixture.Client.UploadString(createUrl, "POST", elementJson);

            // Check Event Frame exists in AF
            path = $"\\\\{Settings.AFServer}\\{Settings.AFDatabase}\\EventFrames[{elementName}]";
            var foundEvents = AFEventFrame.FindEventFramesByPath(new string[] { path }, Fixture.AFFixture.PISystem);
            var eventFrame  = foundEvents.FirstOrDefault();

            Assert.True(eventFrame != null, $"Test Event Frame [{elementName}] was not found in AF.");

            try
            {
                // Extract new Event Frame URL off create response headers
                location = Fixture.Client.ResponseHeaders["Location"];

                // Change Event Frame name
                Output.WriteLine($"Rename event frame object [{elementName}] to [{elementEditJson}] through Web API.");
                Fixture.Client.UploadString(location, "PATCH", elementEditJson);

                // Check Event Frame was renamed in AF
                eventFrame.Refresh();
                Assert.True(eventFrame.Name == elementNameEdit, $"Test Event Frame [{elementName}] was not renamed to [{elementNameEdit}] in AF.");

                // Request full Event Frame object from PI Web API to test read, check name value
                Output.WriteLine($"Read full event frame object [{elementName}] from Web API.");
                var readData = JObject.Parse(Fixture.Client.DownloadString(location));
                Assert.True(string.Equals((string)readData["Name"], elementNameEdit, StringComparison.OrdinalIgnoreCase),
                            $"Test Event Frame [{elementName}] was not renamed to [{elementNameEdit}] in read data.");
            }
            finally
            {
                // Delete test Event Frame
                Fixture.Client.UploadString(location, "DELETE", string.Empty);
            }

            Fixture.Client.Headers.Remove(HttpRequestHeader.CacheControl);
        }