protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            if (windowService == null)
            {
                throw new ArgumentNullException("windowService");
            }
            if (objectProvider == null)
            {
                throw new ArgumentNullException("objectProvider");
            }

            DataTable dt = objectProvider.GetObject() as DataTable;

            if (dt != null)
            {
                using (FormMainDataSet main = new FormMainDataSet())
                {
                    main.Init(dt, objectProvider.IsObjectReplaceable, "DataRow Visualizer");

                    DialogResult dr = windowService.ShowDialog(main);

                    if (objectProvider.IsObjectReplaceable && dr == DialogResult.OK)
                    {
                        /// DataRow is not serializable, so we serialize the item array
                        /// in the TransferData override of the DataRowVisualizerObjectSource we deserialize the itemArray
                        /// and update the values on the original DataRow
                        objectProvider.TransferData(StreamSerializer.ObjectToStream(null, dt.Rows[0].ItemArray));
                    }
                }
            }
        }
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            if (windowService == null)
            {
                throw new ArgumentNullException("windowService");
            }
            if (objectProvider == null)
            {
                throw new ArgumentNullException("objectProvider");
            }
            DataTable dt = objectProvider.GetObject() as DataTable;

            if (dt != null)
            {
                using (FormMainDataSet main = new FormMainDataSet())
                {
                    main.Init(dt, objectProvider.IsObjectReplaceable, "DataRowCollection Visualizer");

                    DialogResult dr = windowService.ShowDialog(main);

                    if (objectProvider.IsObjectReplaceable && dr == DialogResult.OK)
                    {
                        objectProvider.TransferData(StreamSerializer.ObjectToStream(null, dt));
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Convert non-serializable DataRow, DataView, DataRowView, DataRowCollection to a DataTable
        /// and send it to <see cref="StreamSerializer.ObjectToStream(Stream, object)"/> to create a 
        /// serializable Stream.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="outgoingData"></param>
        public override void GetData(object target, Stream outgoingData)
        {
            if (target != null)
            {
                ///////////// DataRow ///////////////////////
                if (target is DataRow)
                {
                    DataRow row = target as DataRow;
                    DataTable table;

                    if (row.Table == null)
                    {
                        table = new DataTable("DataRowDebuggerTableObjectSource");

                        for (int i = 0; i < row.ItemArray.Length; i++)
                        {
                            table.Columns.Add(string.Format("Col{o}", i.ToString()), typeof(string));
                        }
                    }
                    else
                    {
                        table = row.Table.Clone();
                    }
                }
                ///////////// DataView ///////////////////////
                else if (target is DataView)
                {
                    DataView view = target as DataView;
                    DataTable table;

                    table = view.Table.Clone();

                    foreach (DataRow row in view.Table.Rows)
                    {
                        table.LoadDataRow(row.ItemArray, true);
                    }
                    StreamSerializer.ObjectToStream(outgoingData, table);
                }
                ///////////// DataRowView ///////////////////////
                else if (target is DataRowView)
                {
                    DataRowView view = target as DataRowView;
                    DataTable table = table = view.Row.Table.Clone();

                    table.LoadDataRow(view.Row.ItemArray, true);

                    StreamSerializer.ObjectToStream(outgoingData, table);
                }
                ///////////// DataRowCollection ///////////////////////
                else if (target is DataRowCollection)
                {
                    DataRowCollection rows = target as DataRowCollection;
                    DataTable table = null;

                    if (rows != null && rows.Count > 0)
                    {
                        if (rows[0].Table == null)
                        {
                            table = new DataTable("DataRowDebuggerTableObjectSource");

                            for (int i = 0; i < rows[0].ItemArray.Length; i++)
                            {
                                table.Columns.Add(string.Format("Col{o}", i.ToString()), typeof(string));
                            }
                        }
                        else
                        {
                            table = rows[0].Table.Clone();
                        }
                        foreach (DataRow row in rows)
                        {
                            table.LoadDataRow(row.ItemArray, true);
                        }
                    }
                    StreamSerializer.ObjectToStream(outgoingData, table);
                } // else if
            } // if (target == null)
        } // getdata