Beispiel #1
0
        /// <summary>
        ///  Opens a LogInput Editor Dialog. Can change the times and the variable name.
        /// </summary>
        /// <param name="selected"> The unique variable name of the seleced List View item.</param>
        private void EditDialog(string selected)
        {
            LogInput       log = LogSystem.getLogInput(selected);
            LogInputDialog lid = new LogInputDialog(this, log);

            lid.Show();
        }
 /// <summary>
 /// Constructor of the LogInputDialog for Editting of LogInputs.
 /// </summary>
 /// <param name="parentForm"> The LogDialog that made this dialog</param>
 /// <param name="loginput"> The LogInput to be edited.</param>
 public LogInputDialog(LogDialog parentForm, LogInput loginput)
 {
     this.parentForm = parentForm;
     this.logInput   = loginput;
     InitializeComponent();
     tb_MatlabName.Enabled = true;
 }
        private static bool isRelativeTimeString(string start, string end, LogInput logInput)
        {
            //Determine if AFTIME Relative String
            DateTime DTstart, DTend;

            string[] stringTime;
            if (!DateTime.TryParse(start, out DTstart) || !DateTime.TryParse(end, out DTend))
            {
                stringTime = new string[] { start, end };
                logInput.setRelativeTime(stringTime);
                return(true);
            }
            return(false);
        }
Beispiel #4
0
        /// <summary>
        ///  Resulting Action of editting the List View.
        ///  1) Edit the List Item
        ///  2) Re-log the item
        ///  3) Edit the Matlab workspace.
        /// </summary>
        /// <param name="name"> The new variable name. (or the same)</param>
        /// <param name="start"> The new start time. (or the same)</param>
        /// <param name="end"> The new end time. (or the same)</param>
        /// <param name="previous"></param>
        public void EditLog(string name, string start, string end, LogInput previous)
        {
            MatlabAccess.removeMatlabVariable(previous.getKeyVariableName());
            if (previous.getKeyVariableName() != name)
            {
                name = MatlabAccess.modifyMatlabName(name);
            }
            if (name == string.Empty)
            {
                name = previous.getKeyVariableName();
            }
            string attName = previous.getAttribute();
            string path    = previous.getPath();
            string elem    = previous.getElement();

            //EDIT LIST VIEW
            if (AFAccess.isAbsoluteTimeString(start, end, previous))
            {
                lv_LogDialog.SelectedItems[0].SubItems[3].Text = start + " = " + end;
                lv_LogDialog.SelectedItems[0].Text             = name;
            }
            else
            {
                AFTimeRange range = new AFTimeRange(start, end);
                lv_LogDialog.SelectedItems[0].SubItems[3].Text = range.ToString();
                lv_LogDialog.SelectedItems[0].Text             = name;
            }


            //EDIT ACTUAL LOG
            LogSystem.removeLogInput(previous.getKeyVariableName(), previous.getServerDatabase());

            //Workspace Edit - remove variable, getNewData
            if (path == "PI.Point")
            {
                string[] info = Regex.Split(previous.getServerDatabase(), "'");
                control.getPIData(attName, info[1], name, start, end, false);
            }
            else
            {
                control.getAFData(previous.getServerDatabase(), attName, name, path, start, end, false);
            }
        }
        //TODO add time reliance to getPIData
        public static void getPIData(string MatlabName, string server, string point, string start, string end)
        {
            LogInput logInput; //LOG DATA

            AFTimeRange aftr;  //TIMERANGE

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

            PISDK.PISDKClass _pisdk = new PISDK.PISDKClass();
            PISDK.PIPoint    pt     = _pisdk.Servers[server].PIPoints[point];                                                                             // Add the correct SERVER NAME & PI Points
            PISDK.PIValues   values = pt.Data.RecordedValues(start, end,
                                                             PISDK.BoundaryTypeConstants.btAuto, "", PISDK.FilteredViewConstants.fvRemoveFiltered, null); //Get Values

            logInput = new LogInput(MatlabName, "PI.Point", point, "PI.Point", aftr);
            isRelativeTimeString(start, end, logInput);

            double[] timeStamp = new double[values.Count];
            int      i         = 0;

            foreach (PISDK.PIValue val in values)
            {
                DateTime UTCTime = val.TimeStamp.LocalDate;
                timeStamp[i] = UTCTime.ToOADate() + 693960;
                i++;
            }

            logInput.setAttributeGetValueFormat(0);
            logInput.setTimespaceFormat("ts0");

            string server_database = "'" + server + "'-'PI.Point'";

            logInput.setServerDatabase(server_database);
            LogSystem.addLogInput(server_database, logInput, true);

            MatlabAccess.sendDataToMatlab(MatlabName, PIValuesToArray(values)); //Export
            MatlabAccess.sendDataToMatlab(MatlabName + "Time", timeStamp);
        }
        /// <summary>
        /// Log the new export of Matlab data
        /// Steps: 1) Check for the Server_database key
        ///        2) Add variable name to server list and logs.
        ///        3) Add to the ListView - doesn't add to ListView when editting.
        /// </summary>
        /// <param name="keySrv_Db"> The string representing the server and database</param>
        /// <param name="logInput"> The LogInput entry.</param>
        /// <param name="addToListView"> true: adds a ListViewItem to the ListView (generally true, false when editting)</param>
        public static void addLogInput(string keySrv_Db, LogInput logInput, bool addToListView)
        {
            if (!isServer_DatabasesInLogSystem(keySrv_Db))
            {
                servers_databases.Add(keySrv_Db, new List <string>()
                {
                    logInput.getKeyVariableName()
                });
            }
            else
            {
                servers_databases[keySrv_Db].Add(logInput.getKeyVariableName());
            }

            logs.Add(logInput.getKeyVariableName(), logInput);

            if (addToListView)
            {
                Log.Items.Add(logInput.ToListViewItem());
            }
        }
        //TODO add time reliance to getPIData
        public static void getPIData(string MatlabName, string server, string point, string start, string end)
        {
            LogInput logInput; //LOG DATA

            AFTimeRange aftr; //TIMERANGE
            try { aftr = checkAFTimeRange(start, end); }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            PISDK.PISDKClass _pisdk = new PISDK.PISDKClass();
            PISDK.PIPoint pt = _pisdk.Servers[server].PIPoints[point]; // Add the correct SERVER NAME & PI Points
            PISDK.PIValues values = pt.Data.RecordedValues(start, end,
            PISDK.BoundaryTypeConstants.btAuto, "", PISDK.FilteredViewConstants.fvRemoveFiltered, null); //Get Values

            logInput = new LogInput(MatlabName, "PI.Point", point, "PI.Point", aftr);
            isRelativeTimeString(start, end, logInput);

            double[] timeStamp = new double[values.Count];
            int i= 0;
            foreach(PISDK.PIValue val in values)
            {
                DateTime UTCTime = val.TimeStamp.LocalDate;
                timeStamp[i] = UTCTime.ToOADate() + 693960;
                i++;
            }

            logInput.setAttributeGetValueFormat(0);
            logInput.setTimespaceFormat("ts0");

            string server_database = "'" + server + "'-'PI.Point'";
            logInput.setServerDatabase(server_database);
            LogSystem.addLogInput(server_database, logInput, true);

            MatlabAccess.sendDataToMatlab(MatlabName, PIValuesToArray(values)); //Export
            MatlabAccess.sendDataToMatlab(MatlabName + "Time", timeStamp);
        }
        /// <summary>
        ///  Resulting Action of editting the List View.
        ///  1) Edit the List Item
        ///  2) Re-log the item 
        ///  3) Edit the Matlab workspace.
        /// </summary>
        /// <param name="name"> The new variable name. (or the same)</param>
        /// <param name="start"> The new start time. (or the same)</param>
        /// <param name="end"> The new end time. (or the same)</param>
        /// <param name="previous"></param>
        public void EditLog(string name, string start, string end, LogInput previous)
        {
            MatlabAccess.removeMatlabVariable(previous.getKeyVariableName());
            if(previous.getKeyVariableName() != name)
                name = MatlabAccess.modifyMatlabName(name);
            if (name == string.Empty)
                name = previous.getKeyVariableName();
            string attName = previous.getAttribute();
            string path = previous.getPath();
            string elem = previous.getElement();

            //EDIT LIST VIEW
            if (AFAccess.isAbsoluteTimeString(start, end, previous))
            {
                lv_LogDialog.SelectedItems[0].SubItems[3].Text = start + " = " + end;
                lv_LogDialog.SelectedItems[0].Text = name;
            }
            else
            {
                AFTimeRange range = new AFTimeRange(start, end);
                lv_LogDialog.SelectedItems[0].SubItems[3].Text = range.ToString();
                lv_LogDialog.SelectedItems[0].Text = name;
            }

            //EDIT ACTUAL LOG
            LogSystem.removeLogInput(previous.getKeyVariableName(), previous.getServerDatabase());

            //Workspace Edit - remove variable, getNewData
            if (path == "PI.Point")
            {
                string[] info = Regex.Split(previous.getServerDatabase(), "'");
                control.getPIData(attName, info[1], name, start, end,false);
            }
            else
                control.getAFData(previous.getServerDatabase(), attName, name, path, start, end, false);
        }
        static Dictionary<string, List<string>> servers_databases = new Dictionary<string,List<string>>(); //"server_database" Key

        #endregion Fields

        #region Methods

        /// <summary>
        /// Log the new export of Matlab data
        /// Steps: 1) Check for the Server_database key
        ///        2) Add variable name to server list and logs.
        ///        3) Add to the ListView - doesn't add to ListView when editting.
        /// </summary>
        /// <param name="keySrv_Db"> The string representing the server and database</param>
        /// <param name="logInput"> The LogInput entry.</param>
        /// <param name="addToListView"> true: adds a ListViewItem to the ListView (generally true, false when editting)</param>
        public static void addLogInput(string keySrv_Db, LogInput logInput, bool addToListView)
        {
            if (!isServer_DatabasesInLogSystem(keySrv_Db))
               servers_databases.Add(keySrv_Db, new List<string>() { logInput.getKeyVariableName() });
               else
               servers_databases[keySrv_Db].Add(logInput.getKeyVariableName());

               logs.Add(logInput.getKeyVariableName(), logInput);

               if(addToListView)
                Log.Items.Add(logInput.ToListViewItem());
        }
        /// <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);
        }
 /// <summary>
 /// Determines if the inputted strings are in PI Absolute Time.
 /// </summary>
 /// <param name="start">The string of the start time.</param>
 /// <param name="end">The string of the end time.</param>
 /// <param name="logInput">Adds the Absolute time to this logInput.</param>
 /// <returns></returns>
 public static bool isAbsoluteTimeString(string start, string end, LogInput logInput)
 {
     //Determine if AFTIME Absolute Time String
     DateTime DTstart, DTend;
     string[] stringTime;
     if (!DateTime.TryParse(start, out DTstart) || !DateTime.TryParse(end, out DTend))
     {
         stringTime = new string[] { start, end };
         logInput.setAbsoluteTime(stringTime);
         return true;
     }
     return false;
 }
Beispiel #12
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());
        }
        /// <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);
        }