예제 #1
0
 // Save Logs
 /// <summary>
 /// Calls the LogSystem.Save method.
 /// </summary>
 /// <param name="filePath">The path to where the file will be written.</param>
 public void saveCurrentLog(string filePath)
 {
     LogSystem.SaveLog(filePath);
 }
예제 #2
0
        /// <summary>
        ///  Removes the log Input from the LogSystem and the list view.
        /// </summary>
        /// <param name="selected"> Unique variable name of list View Item.</param>
        public void DeleteListItem(string selected)
        {
            LogInput logInput = LogSystem.getLogInput(selected);

            LogSystem.removeLogInput(selected, logInput.getServerDatabase());
        }
예제 #3
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 });
        }
예제 #4
0
        /// <summary>
        ///  Common calls of getting Data from AFServer
        /// </summary>
        /// <param name="server_database">String representing the server and database</param>
        /// <param name="AttributeName"> name of the attribute</param>
        /// <param name="MatlabName">variable name for the Matlab Workspace</param>
        /// <param name="start">Start time of data collection.</param>
        /// <param name="end">End time of the data collection.</param>
        /// <param name="afobject"> AF object - AFAttribute, AFEventFrame, or PIPoint</param>
        /// <param name="addToListView"> Whether to add to the Listview (generally true)</param>
        public static void getData(string server_database, string AttributeName, string MatlabName, string start, string end, Object afobject, bool addToListView)
        {
            MatlabName = MatlabAccess.modifyMatlabName(MatlabName);
            LogInput    logInput = null;
            AFValues    Values   = new AFValues();
            AFAttribute attribute;

            object[] vals;
            double[] dbVals;
            double[] timestamps = null;
            int[]    statuses;
            int      baddata;

            //TIME RANGE
            AFTimeRange aftr;

            try { aftr = checkAFTimeRange(start, end); }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw ex;
            }

            /// Get Object
            Type   type       = afobject.GetType();
            string typestring = type.ToString();

            //  LogInput logInput = new LogInput(MatlabName, Element.Name, attribute.Name, path, aftr);
            switch (type.ToString())
            {
            case "OSIsoft.AF.Asset.AFAttribute":
                attribute = (AFAttribute)afobject;
                logInput  = new LogInput(MatlabName, attribute.Element.Name, attribute.Name, attribute.Element.GetPath(), aftr);
                if (attribute.PIPoint == null)         // Constant Value
                {
                    aftr = new AFTimeRange("*", "*");
                    logInput.setAFTimeRange(aftr);
                    Values = attribute.GetValues(aftr, dataPref, null);
                }
                else         // PI Point - Time Matters!!
                {
                    /* Summary: Attribute.GetValues - Important Call!
                     * Parameter Int32 => DataPref
                     *          = 0 :  All Values returned
                     *          < 0 :  Evenly spaced values, including start and end
                     *          > 0 :  # of intervals, for each interval 5 points are given (first, last, high, low, and exceptional)
                     */
                    Values = attribute.GetValues(aftr, dataPref, null);         // FULLY UNDERSTAND THIS !!! Important Call!!!!
                }
                break;

            case "OSIsoft.AF.EventFrame.AFEventFrame":
                AFEventFrame frame = (AFEventFrame)afobject;
                logInput  = new LogInput(MatlabName, frame.Name, frame.Attributes[AttributeName].Name, frame.GetPath(), aftr);
                attribute = frame.Attributes[AttributeName];
                logInput.setAFTimeRange(aftr);
                AFValue val = attribute.GetValue(aftr);
                Values = new AFValues()
                {
                    val
                };
                break;

            case "OSIsoft.AF.PI.PIPoint":
                PIPoint piPoint = (PIPoint)afobject;
                string  path    = piPoint.GetPath();
                logInput = new LogInput(MatlabName, "PI.Point", piPoint.Name, "PI.Point", aftr);
                Values   = piPoint.RecordedValues(aftr, AFBoundaryType.Interpolated, "", true, Int32.MaxValue);
                break;
            }



            //Determine if AFTIME Absolute String
            isAbsoluteTimeString(start, end, logInput);

            logInput.setAttributeGetValueFormat(dataPref);
            logInput.setTimespaceFormat(dataFormat);

            ConvertAFValues.GetValuesArray(Values, false, out vals, out timestamps, out statuses, out baddata);
            try
            {
                MatlabAccess.sendDataToMatlab(MatlabName, AFValuesToArray(vals));

                if (Timestamp)
                {
                    MatlabAccess.sendDataToMatlab(MatlabName + "Time", timestamps);
                }
            }
            catch
            {
                logInput.setServerDatabase(server_database);
                LogSystem.addLogInput(server_database, logInput, addToListView);
                throw new NullReferenceException();
            }

            logInput.setServerDatabase(server_database);
            LogSystem.addLogInput(server_database, logInput, addToListView);
        }