Example #1
0
        public static SqlQueryInfo deserialize(Stream stream)
        {
            SqlQueryInfo    result    = new SqlQueryInfo();
            BinaryFormatter formatter = new BinaryFormatter();
            int             nQueries  = (int)formatter.Deserialize(stream);

            result.queries = new SqlQueryText[nQueries];
            for (int i = 0; i < nQueries; i++)
            {
                SqlQueryText query;
                query.Text = (string)formatter.Deserialize(stream);
                int nParams = (int)formatter.Deserialize(stream);
                query.Params = new ParameterText[nParams];
                for (int j = 0; j < nParams; j++)
                {
                    ParameterText p;
                    p.Name          = (string)formatter.Deserialize(stream);
                    p.Value         = (string)formatter.Deserialize(stream);
                    p.SqlType       = (string)formatter.Deserialize(stream);
                    query.Params[j] = p;
                }
                result.Queries[i] = query;
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// Этот метод вызывается из визуализатора запросов общего назначения.
        /// Он считывает из потока данные запроса, задает соответствующие поля в
        /// QueryVisualizerFrom и отображает его.
        /// </summary>
        /// <param name="windowService">Используется для отображения диалогового окна визуализатора</param>
        /// <param name="rawStream">Данные запроса, отправленные поставщиком или прокси визуализатора</param>
        public static void Display(IDialogVisualizerService windowService, Stream rawStream)
        {
            BinaryFormatter formatter  = new BinaryFormatter();
            string          expression = (string)formatter.Deserialize(rawStream);

            SqlQueryInfo qi = SqlQueryInfo.deserialize(rawStream);

            SqlQueryText[] infos = qi.Queries;

            string connectionString = (string)formatter.Deserialize(rawStream);

            QueryVisualizerForm form = new QueryVisualizerForm();

            form.SetTexts(expression, infos, connectionString);
            windowService.ShowDialog(form);
        }
Example #3
0
        /// <summary>
        /// Этот метод вызывается из QueryVisualizer для копирования в поток следующих данных:
        /// 1. Выражение запроса как строки
        /// 2. Параметры и текст запроса SQL
        /// 3. Строку подключения
        /// </summary>
        /// <param name="query"> Выражение запроса для визуализации </param>
        /// <param name="outgoingData"> Поток, используемый для  маршалирования данных в визуализатор </param>
        ///
        public static void StreamQueryInfo(DataContext dataContext, IQueryable query, Stream outgoingData)
        {
            BinaryFormatter formatter = new BinaryFormatter();

            if (dataContext == null)
            {
                formatter.Serialize(outgoingData, "None");
                formatter.Serialize(outgoingData, "No datacontext provided.");
                return;
            }
            Expression expr = query.Expression;

            if (expr == null)
            {
                formatter.Serialize(outgoingData, "None");
                formatter.Serialize(outgoingData, "Expression of the query is empty.");
                return;
            }
            formatter.Serialize(outgoingData, expr.ToString());

            try {
                SqlQueryInfo qi = new SqlQueryInfo(GetFullQueryInfo(dataContext, query));
                qi.serialize(outgoingData);
            } catch (Exception ex) {
                outgoingData.Position = 0;
                formatter.Serialize(outgoingData, "None");
                formatter.Serialize(outgoingData, string.Format(CultureInfo.CurrentUICulture, "Exception while serializing the query:\r\n{0}", ex.Message));
                return;
            }

            IDbConnection conn             = dataContext.Connection;
            string        connectionString = conn.ConnectionString;

            //Необходим для проверки лексемы |DataDirectory| в строке подключения и замены на абсолютный путь, чтобы
            if (connectionString.Contains("|DataDirectory|"))
            {
                connectionString = conn.ConnectionString.Replace(@"|DataDirectory|\", AppDomain.CurrentDomain.BaseDirectory);
            }
            //визуализатор запросов Linq To Sql мог использовать ту же строку подключения.
            formatter.Serialize(outgoingData, connectionString);
        }
Example #4
0
        /// <summary>
        /// This method is called from the QueryVisualizer to copy the following data to the stream:
        /// 1. The query expression as string
        /// 2. SQL query text(s) / parameters
        /// 3. Connection string
        /// </summary>
        /// <param name="query"> The query exression to visualize </param>
        /// <param name="outgoingData"> The stream used for marshalling to the visualizer </param>
        ///
        public static void StreamQueryInfo(DataContext dataContext, IQueryable query, Stream outgoingData)
        {
            BinaryFormatter formatter = new BinaryFormatter();

            if (dataContext == null)
            {
                formatter.Serialize(outgoingData, "None");
                formatter.Serialize(outgoingData, "No datacontext provided.");
                return;
            }
            Expression expr = query.Expression;

            if (expr == null)
            {
                formatter.Serialize(outgoingData, "None");
                formatter.Serialize(outgoingData, "Expression of the query is empty.");
                return;
            }
            formatter.Serialize(outgoingData, expr.ToString());

            try {
                SqlQueryInfo qi = new SqlQueryInfo(GetFullQueryInfo(dataContext, query));
                qi.serialize(outgoingData);
            } catch (Exception ex) {
                outgoingData.Position = 0;
                formatter.Serialize(outgoingData, "None");
                formatter.Serialize(outgoingData, string.Format(CultureInfo.CurrentUICulture, "Exception while serializing the query:\r\n{0}", ex.Message));
                return;
            }

            IDbConnection conn             = dataContext.Connection;
            string        connectionString = conn.ConnectionString;

            //Need to check for |DataDirectory| token in the connection string and replace with absolute path to allow
            if (connectionString.Contains("|DataDirectory|"))
            {
                connectionString = conn.ConnectionString.Replace(@"|DataDirectory|\", AppDomain.CurrentDomain.BaseDirectory);
            }
            //the Linq To Sql Query Visualizer to use the same connection string.
            formatter.Serialize(outgoingData, connectionString);
        }
        /// <summary>
        /// 从 QueryVisualizer 调用此方法可将以下数据复制到流:
        /// 1. 字符串形式的查询表达式
        /// 2. SQL 查询文本/参数
        /// 3. 连接字符串
        /// </summary>
        /// <param name="query"> 要可视化的查询字符串 </param>
        /// <param name="outgoingData"> 用于封送到可视化工具的流 </param>
        ///
        public static void StreamQueryInfo(DataContext dataContext, IQueryable query, Stream outgoingData)
        {
            BinaryFormatter formatter = new BinaryFormatter();

            if (dataContext == null)
            {
                formatter.Serialize(outgoingData, "None");
                formatter.Serialize(outgoingData, "No datacontext provided.");
                return;
            }
            Expression expr = query.Expression;

            if (expr == null)
            {
                formatter.Serialize(outgoingData, "None");
                formatter.Serialize(outgoingData, "Expression of the query is empty.");
                return;
            }
            formatter.Serialize(outgoingData, expr.ToString());

            try {
                SqlQueryInfo qi = new SqlQueryInfo(GetFullQueryInfo(dataContext, query));
                qi.serialize(outgoingData);
            } catch (Exception ex) {
                outgoingData.Position = 0;
                formatter.Serialize(outgoingData, "None");
                formatter.Serialize(outgoingData, string.Format(CultureInfo.CurrentUICulture, "Exception while serializing the query:\r\n{0}", ex.Message));
                return;
            }

            IDbConnection conn             = dataContext.Connection;
            string        connectionString = conn.ConnectionString;

            //需要检查连接字符串中的 |DataDirectory| 标记并替换为绝对路径,以允许
            if (connectionString.Contains("|DataDirectory|"))
            {
                connectionString = conn.ConnectionString.Replace(@"|DataDirectory|\", AppDomain.CurrentDomain.BaseDirectory);
            }
            // Linq To Sql 查询可视化工具使用相同的连接字符串。
            formatter.Serialize(outgoingData, connectionString);
        }
        /// <summary>
        /// 从 QueryVisualizer 调用此方法可将以下数据复制到流:
        /// 1. 字符串形式的查询表达式
        /// 2. SQL 查询文本/参数
        /// 3. 连接字符串
        /// </summary>
        /// <param name="query"> 要可视化的查询字符串 </param>
        /// <param name="outgoingData"> 用于封送到可视化工具的流 </param>
        /// 
        public static void StreamQueryInfo(DataContext dataContext, IQueryable query, Stream outgoingData)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            if (dataContext == null) {
                formatter.Serialize(outgoingData, "None");
                formatter.Serialize(outgoingData, "No datacontext provided.");
                return;
            }
            Expression expr = query.Expression;
            if (expr == null) {
                formatter.Serialize(outgoingData, "None");
                formatter.Serialize(outgoingData, "Expression of the query is empty.");
                return;
            }
            formatter.Serialize(outgoingData, expr.ToString());

            try {
                SqlQueryInfo qi = new SqlQueryInfo(GetFullQueryInfo(dataContext, query));
                qi.serialize(outgoingData);
            } catch (Exception ex) {
                outgoingData.Position = 0;
                formatter.Serialize(outgoingData, "None");
                formatter.Serialize(outgoingData, string.Format(CultureInfo.CurrentUICulture, "Exception while serializing the query:\r\n{0}", ex.Message));
                return;
            }

            IDbConnection conn = dataContext.Connection;
            string connectionString = conn.ConnectionString;
            //需要检查连接字符串中的 |DataDirectory| 标记并替换为绝对路径,以允许
            if (connectionString.Contains("|DataDirectory|")) {
                connectionString = conn.ConnectionString.Replace(@"|DataDirectory|\", AppDomain.CurrentDomain.BaseDirectory);
            }
            // Linq To Sql 查询可视化工具使用相同的连接字符串。
            formatter.Serialize(outgoingData, connectionString);
        }
 public static SqlQueryInfo deserialize(Stream stream)
 {
     SqlQueryInfo result = new SqlQueryInfo();
     BinaryFormatter formatter = new BinaryFormatter();
     int nQueries = (int) formatter.Deserialize(stream);
     result.queries = new SqlQueryText[nQueries];
     for (int i=0; i<nQueries; i++) {
         SqlQueryText query;
         query.Text = (string)formatter.Deserialize(stream);
         int nParams = (int)formatter.Deserialize(stream);
         query.Params = new ParameterText[nParams];
         for (int j = 0; j < nParams; j++) {
             ParameterText p;
             p.Name = (string) formatter.Deserialize(stream);
             p.Value = (string)formatter.Deserialize(stream);
             p.SqlType = (string)formatter.Deserialize(stream);
             query.Params[j] = p;
         }
         result.Queries[i] = query;
     }
     return result;
 }
        /// <summary>
        /// This method is called from the QueryVisualizer to copy the following data to the stream:
        /// 1. The query expression as string
        /// 2. SQL query text(s) / parameters
        /// 3. Connection string
        /// </summary>
        /// <param name="query"> The query exression to visualize </param>
        /// <param name="outgoingData"> The stream used for marshalling to the visualizer </param>
        /// 
        public static void StreamQueryInfo(DataContext dataContext, IQueryable query, Stream outgoingData)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            if (dataContext == null) {
                formatter.Serialize(outgoingData, "None");
                formatter.Serialize(outgoingData, "No datacontext provided.");
                return;
            }
            Expression expr = query.Expression;
            if (expr == null) {
                formatter.Serialize(outgoingData, "None");
                formatter.Serialize(outgoingData, "Expression of the query is empty.");
                return;
            }
            formatter.Serialize(outgoingData, expr.ToString());

            try {
                SqlQueryInfo qi = new SqlQueryInfo(GetFullQueryInfo(dataContext, query));
                qi.serialize(outgoingData);
            } catch (Exception ex) {
                outgoingData.Position = 0;
                formatter.Serialize(outgoingData, "None");
                formatter.Serialize(outgoingData, string.Format(CultureInfo.CurrentUICulture, "Exception while serializing the query:\r\n{0}", ex.Message));
                return;
            }

            IDbConnection conn = dataContext.Connection;
            string connectionString = conn.ConnectionString;
            //Need to check for |DataDirectory| token in the connection string and replace with absolute path to allow
            if (connectionString.Contains("|DataDirectory|")) {
                connectionString = conn.ConnectionString.Replace(@"|DataDirectory|\", AppDomain.CurrentDomain.BaseDirectory);
            }
            //the Linq To Sql Query Visualizer to use the same connection string.
            formatter.Serialize(outgoingData, connectionString);
        }