aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Messages/ForcedUpdateMessage.cs
blob: 54b43c6d38bd64372ba24c274b8c683be4167df8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.MachineStudio.Common.Web;

namespace Tango.MachineStudio.UI.Messages
{
    public class ForcedUpdateMessage
    {
        public CheckForUpdatesResponse UpdateResponse { get; set; }
    }
}
ht: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tango.PPC.Shared.SQL
{
    /// <summary>
    /// Represents remote database query result composed of rows and columns.
    /// </summary>
    /// <example>
    /// <para>
    /// <i>
    /// The following example demonstrates how to set the connected machine's demo state and query for the connected machine's jobs.
    /// </i>
    /// </para>
    /// <code lang="C#" source="../Tango.FSE.Procedures/Examples/Sql/Program.cs" title="Remote SQL" region="Example" />
    /// </example>
    public class RemoteSqlDataSet
    {
        /// <summary>
        /// Gets or sets the dataset columns.
        /// </summary>
        public RemoteSqlColumnCollection Columns { get; set; }

        private ObservableCollection<RemoteSqlRow> _rows;
        /// <summary>
        /// Gets or sets the dataset rows.
        /// </summary>
        public ObservableCollection<RemoteSqlRow> Rows
        {
            get { return _rows; }
            set { _rows = value; OnRowsChanged(); }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="RemoteSqlDataSet"/> class.
        /// </summary>
        public RemoteSqlDataSet()
        {
            Columns = new RemoteSqlColumnCollection();
            Rows = new ObservableCollection<RemoteSqlRow>();
        }

        private void OnRowsChanged()
        {
            if (Rows != null)
            {
                Rows.CollectionChanged -= Rows_CollectionChanged;
                Rows.CollectionChanged += Rows_CollectionChanged;

                InitRows();
            }
        }

        private void Rows_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            InitRows();
        }

        private void InitRows()
        {
            if (Rows != null)
            {
                foreach (var row in Rows.ToList())
                {
                    row.Init(
                        (key) =>
                        {
                            return row.Values[Columns.GetIndexOf(key)];
                        },
                        (index) =>
                        {
                            return row.Values[index];
                        });
                }
            }
        }

        /// <summary>
        /// Creates a new <see cref="RemoteSqlDataSet"/> using the specified <see cref="SqlDataReader"/>.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        public static Task<RemoteSqlDataSet> Load(SqlDataReader reader)
        {
            return Task.Factory.StartNew<RemoteSqlDataSet>(() =>
            {
                bool columnsRead = false;
                RemoteSqlDataSet dataSet = new RemoteSqlDataSet();

                try
                {
                    while (reader.Read())
                    {
                        RemoteSqlRow row = new RemoteSqlRow();

                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            if (!columnsRead)
                            {
                                dataSet.Columns.Add(new RemoteSqlColumn()
                                {
                                    Name = reader.GetName(i)
                                });
                            }

                            row.Values.Add(reader.GetValue(i));
                        }

                        columnsRead = true;
                        dataSet.Rows.Add(row);
                    }
                }
                finally
                {
                    reader.Close();
                }

                return dataSet;
            });
        }

        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return String.Join(", ", Columns.Select(x => x.Name)) + "\n" + String.Join(Environment.NewLine, Rows.Select(x => x.ToString()));
        }

        /// <summary>
        /// Formats this dataset as a string with columns and rows.
        /// </summary>
        /// <returns></returns>
        public String ToTableString()
        {
            Dictionary<int, int> columnsMaxLength = new Dictionary<int, int>();

            for (int i = 0; i < Columns.Count; i++)
            {
                columnsMaxLength.Add(i, Columns[i].Name.Length);
            }

            foreach (var row in Rows)
            {
                for (int i = 0; i < row.Values.Count; i++)
                {
                    int valueLength = row.Values[i].ToStringSafe().Length;

                    if (valueLength > columnsMaxLength[i])
                    {
                        columnsMaxLength[i] = valueLength;
                    }
                }
            }

            String str = String.Empty;

            for (int i = 0; i < Columns.Count; i++)
            {
                str += $"{Columns[i].Name.PadRight(columnsMaxLength[i])}{(i < Columns.Count - 1 ? " | " : "")}";
            }

            int width = str.Length;
            str += Environment.NewLine + String.Empty.PadRight(width, '-');

            foreach (var row in Rows)
            {
                str += Environment.NewLine;

                for (int i = 0; i < row.Values.Count; i++)
                {
                    str += $"{row.Values[i].ToStringSafe().PadRight(columnsMaxLength[i])}{(i < Columns.Count - 1 ? " | " : "")}";
                }
            }

            return str;
        }
    }
}