Beispiel #1
0
        /// <summary>
        ///     Displays the user interface for the visualizer.
        /// </summary>
        /// <param name="windowService">
        ///     An object of type Microsoft.VisualStudio.DebuggerVisualizers.IDialogVisualizerService,
        ///     which provides methods that a visualizer can use to display Windows forms, controls, and dialogs.
        /// </param>
        /// <param name="objectProvider">
        ///     An object of type Microsoft.VisualStudio.DebuggerVisualizers.IVisualizerObjectProvider.
        ///     This object provides communication from the debugger side of the visualizer
        ///     to the object source (Microsoft.VisualStudio.DebuggerVisualizers.VisualizerObjectSource)
        ///     on the debuggee side.
        /// </param>
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            // Get the object to display a visualizer for.
            try
            {
                //TargetObject = (object)objectProvider.GetObject();
                //_targetObjectType = TargetObject.GetType();
                using (var streamReader = new StreamReader(objectProvider.GetData()))
                {
                    var targetObjectType = streamReader.ReadLine();
                    _targetObjectType = Type.GetType(targetObjectType);

                    TargetObject = Serializer.Deserialize(_targetObjectType, streamReader.ReadToEnd());
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(string.Format(Resources.DeserializationOfXmlFailed, exception.Message));
                return;
            }

            //Display the view of the object.
            using (var displayForm = new frmVisualizerDialog(this))
            {
                windowService.ShowDialog(displayForm);

                if (IsUpdateRequired)
                {
                    if (objectProvider.IsObjectReplaceable)
                    {
                        //objectProvider.ReplaceObject(TargetObject);
                        //If the object is replaceable and it has been updated then
                        //replace the target object with the updated version.
                        using (var outgoingData = new MemoryStream())
                        {
                            using (var writer = new StreamWriter(outgoingData))
                            {
                                writer.WriteLine(TargetObject.GetType().AssemblyQualifiedName);
                                writer.WriteLine(Serializer.Serialize(TargetObject));
                                writer.Flush();
                                objectProvider.ReplaceData(outgoingData);
                            }
                        }
                    }
                }
            }
        }