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 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("Exception while serializing the query:\r\n{0}", ex.Message));
                return;
            }

            IDbConnection conn = dataContext.Connection;

            formatter.Serialize(outgoingData, conn == null ? "" : conn.ConnectionString);
        }
        /// <summary>
        /// This method is called from the general Query Visualizer.
        /// It reads the query data from the stream, sets the corresponding fields in the
        /// QueryVisualizerFrom and displays it.
        /// </summary>
        /// <param name="windowService">Used to show the visualizer dialog</param>
        /// <param name="rawStream">The query data sent from the provider / visualizer proxy</param>
        public 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);
        }
        /// <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 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("Exception while serializing the query:\r\n{0}", ex.Message));
                return;
            }

            IDbConnection conn = dataContext.Connection;
            formatter.Serialize(outgoingData, conn==null ? "" : conn.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;
 }