コード例 #1
0
        /// <summary>Add a status message to the explorer window</summary>
        /// <param name="message">The message.</param>
        /// <param name="errorLevel">The error level.</param>
        public void ShowMessage(string message, Simulation.ErrorLevel errorLevel)
        {
            Gtk.Application.Invoke(delegate
            {
                StatusWindow.Visible = message != null;
                StatusWindow.Buffer.Clear();

                if (message != null)
                {
                    string tagName;
                    // Output the message
                    if (errorLevel == Simulation.ErrorLevel.Error)
                    {
                        tagName = "error";
                    }
                    else if (errorLevel == Simulation.ErrorLevel.Warning)
                    {
                        tagName = "warning";
                    }
                    else
                    {
                        tagName = "normal";
                    }
                    message             = message.TrimEnd("\n".ToCharArray());
                    message             = message.Replace("\n", "\n                      ");
                    message            += "\n";
                    TextIter insertIter = StatusWindow.Buffer.StartIter;
                    StatusWindow.Buffer.InsertWithTagsByName(ref insertIter, message, tagName);
                }

                //this.toolTip1.SetToolTip(this.StatusWindow, message);
                progressBar.Visible = false;
                stopButton.Visible  = false;
            });
        }
コード例 #2
0
ファイル: MainView.cs プロジェクト: Scicrop/ApsimX
        /// <summary>Add a status message to the explorer window</summary>
        /// <param name="message">The message.</param>
        /// <param name="errorLevel">The error level.</param>
        public void ShowMessage(string message, Simulation.ErrorLevel errorLevel, bool overwrite = true, bool addSeparator = false, bool withButton = true)
        {
            Application.Invoke(delegate
            {
                statusWindow.Visible = message != null;
                if (overwrite || message == null)
                {
                    numberOfButtons = 0;
                    statusWindow.Buffer.Clear();
                }

                if (message != null)
                {
                    string tagName;
                    // Output the message
                    if (errorLevel == Simulation.ErrorLevel.Error)
                    {
                        tagName = "error";
                    }
                    else if (errorLevel == Simulation.ErrorLevel.Warning)
                    {
                        tagName = "warning";
                    }
                    else
                    {
                        tagName = "normal";
                    }
                    message  = message.TrimEnd(Environment.NewLine.ToCharArray());
                    message += Environment.NewLine;
                    TextIter insertIter;
                    if (overwrite)
                    {
                        insertIter = statusWindow.Buffer.StartIter;
                    }
                    else
                    {
                        insertIter = statusWindow.Buffer.EndIter;
                    }

                    statusWindow.Buffer.InsertWithTagsByName(ref insertIter, message, tagName);
                    if (errorLevel == Simulation.ErrorLevel.Error && withButton)
                    {
                        AddButtonToStatusWindow("More Information", numberOfButtons++);
                    }
                    if (addSeparator)
                    {
                        insertIter = statusWindow.Buffer.EndIter;
                        statusWindow.Buffer.InsertWithTagsByName(ref insertIter, Environment.NewLine + "----------------------------------------------" + Environment.NewLine, tagName);
                    }
                }

                //this.toolTip1.SetToolTip(this.StatusWindow, message);
                progressBar.Visible = false;
                stopButton.Visible  = false;
            });
            while (GLib.MainContext.Iteration())
            {
                ;
            }
        }
コード例 #3
0
        /// <summary>
        /// Add a status message. A message of null will clear the status message.
        /// For error messages, use <see cref="ShowError(Exception)"/>.
        /// </summary>
        /// <param name="message">The message test</param>
        /// <param name="errorLevel">The error level value</param>
        public void ShowMessage(string message, Simulation.MessageType messageType)
        {
            Simulation.ErrorLevel errorType = Simulation.ErrorLevel.Information;

            if (messageType == Simulation.MessageType.Information)
            {
                errorType = Simulation.ErrorLevel.Information;
            }
            else if (messageType == Simulation.MessageType.Warning)
            {
                errorType = Simulation.ErrorLevel.Warning;
            }

            this.view.ShowMessage(message, errorType);
        }
コード例 #4
0
        /// <summary>
        /// Displays several messages, with a separator between them.
        /// For error messages, use <see cref="ShowError(List{Exception})"/>.
        /// </summary>
        /// <param name="messages">Messages to be displayed.</param>
        /// <param name="messageType"></param>
        public void ShowMessage(List <string> messages, Simulation.MessageType messageType)
        {
            Simulation.ErrorLevel errorType = Simulation.ErrorLevel.Information;

            if (messageType == Simulation.MessageType.Information)
            {
                errorType = Simulation.ErrorLevel.Information;
            }
            else if (messageType == Simulation.MessageType.Warning)
            {
                errorType = Simulation.ErrorLevel.Warning;
            }

            foreach (string msg in messages)
            {
                view.ShowMessage(msg, errorType, false, true, false);
            }
        }
コード例 #5
0
ファイル: MainView.cs プロジェクト: MarkLieffering/ApsimX
        /// <summary>Add a status message to the explorer window</summary>
        /// <param name="message">The message.</param>
        /// <param name="errorLevel">The error level.</param>
        public void ShowMessage(string message, Simulation.ErrorLevel errorLevel)
        {
            MethodInvoker messageUpdate = delegate
            {
                StatusWindow.Visible = message != null;

                // Output the message
                if (errorLevel == Simulation.ErrorLevel.Error)
                {
                    StatusWindow.ForeColor = Color.Red;
                }
                else if (errorLevel == Simulation.ErrorLevel.Warning)
                {
                    StatusWindow.ForeColor = Color.Brown;
                }
                else
                {
                    StatusWindow.ForeColor = Color.Blue;
                }
                message           = message.TrimEnd("\n".ToCharArray());
                message           = message.Replace("\n", "\n                      ");
                message          += "\n";
                StatusWindow.Text = message;
                this.toolTip1.SetToolTip(this.StatusWindow, message);
                progressBar.Visible = false;
            };

            if (InvokeRequired)
            {
                this.BeginInvoke(new Action(messageUpdate));
            }
            else
            {
                messageUpdate();
            }
        }
コード例 #6
0
ファイル: Summary.cs プロジェクト: nastaranch/ApsimX
        /// <summary>
        /// Create a message table ready for writing.
        /// </summary>
        /// <param name="storage">The data store</param>
        /// <param name="simulationName">The simulation name to get messages for</param>
        /// <returns>The filled message table</returns>
        private static DataTable GetMessageTable(IStorageReader storage, string simulationName)
        {
            DataTable messageTable = new DataTable();
            DataTable messages     = storage.GetData(simulationName: simulationName, tableName: "_Messages");

            if (messages != null && messages.Rows.Count > 0)
            {
                messageTable.Columns.Add("Date", typeof(string));
                messageTable.Columns.Add("Message", typeof(string));
                string previousCol1Text = null;
                string previousMessage  = null;
                foreach (DataRow row in messages.Rows)
                {
                    // Work out the column 1 text.
                    string modelName = (string)row["ComponentName"];

                    string col1Text;
                    if (row["Date"].GetType() == typeof(DateTime))
                    {
                        DateTime date = (DateTime)row["Date"];
                        col1Text = date.ToString("yyyy-MM-dd") + " " + modelName;
                    }
                    else
                    {
                        col1Text = row["Date"].ToString();
                    }

                    // If the date and model name have changed then write a row.
                    if (col1Text != previousCol1Text)
                    {
                        if (previousCol1Text != null)
                        {
                            messageTable.Rows.Add(new object[] { previousCol1Text, previousMessage });
                        }

                        previousMessage  = string.Empty;
                        previousCol1Text = col1Text;
                    }
                    else
                    {
                        col1Text = null;
                    }

                    string message = (string)row["Message"];
                    Simulation.ErrorLevel errorLevel = (Simulation.ErrorLevel)Enum.Parse(typeof(Simulation.ErrorLevel), row["MessageType"].ToString());

                    if (errorLevel == Simulation.ErrorLevel.Error)
                    {
                        previousMessage += "FATAL ERROR: " + message;
                    }
                    else if (errorLevel == Simulation.ErrorLevel.Warning)
                    {
                        previousMessage += "WARNING: " + message;
                    }
                    else
                    {
                        previousMessage += message;
                    }

                    previousMessage += "\r\n";
                }
                if (previousMessage != null)
                {
                    messageTable.Rows.Add(new object[] { previousCol1Text, previousMessage });
                }
            }

            return(messageTable);
        }
コード例 #7
0
 /// <summary>
 /// Add a status message. A message of null will clear the status message.
 /// </summary>
 /// <param name="message"></param>
 public void ShowMessage(string message, Simulation.ErrorLevel errorLevel)
 {
     view.ShowMessage(message, errorLevel);
 }