Exemple #1
0
        private bool LoadFile(string path)
        {
            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(AutoVisualizer));
                if (!File.Exists(path))
                {
                    _process.WriteOutput(String.Format(CultureInfo.CurrentCulture, ResourceStrings.FileNotFound, path));
                    return(false);
                }
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.IgnoreComments = true;
                settings.IgnoreProcessingInstructions = true;
                settings.IgnoreWhitespace             = true;
                settings.XmlResolver = null;

                using (var stream = new System.IO.FileStream(path, FileMode.Open, FileAccess.Read))
                    using (var reader = XmlReader.Create(stream, settings))
                    {
                        AutoVisualizer autoVis = null;
                        autoVis = serializer.Deserialize(reader) as AutoVisualizer;
                        if (autoVis != null)
                        {
                            FileInfo f = new FileInfo(autoVis);
                            if (autoVis.Items == null)
                            {
                                return(false);
                            }
                            foreach (var o in autoVis.Items)
                            {
                                if (o is VisualizerType)
                                {
                                    VisualizerType v = (VisualizerType)o;
                                    TypeName       t = TypeName.Parse(v.Name);
                                    if (t != null)
                                    {
                                        lock (_typeVisualizers)
                                        {
                                            f.Visualizers.Add(new TypeInfo(t, v));
                                        }
                                    }
                                    // add an entry for each alternative name too
                                    if (v.AlternativeType != null)
                                    {
                                        foreach (var a in v.AlternativeType)
                                        {
                                            t = TypeName.Parse(a.Name);
                                            if (t != null)
                                            {
                                                lock (_typeVisualizers)
                                                {
                                                    f.Visualizers.Add(new TypeInfo(t, v));
                                                }
                                            }
                                        }
                                    }
                                }
                                else if (o is AliasType)
                                {
                                    AliasType a = (AliasType)o;
                                    TypeName  t = TypeName.Parse(a.Name);
                                    if (t != null)
                                    {
                                        lock (_typeVisualizers)
                                        {
                                            f.Aliases.Add(new AliasInfo(t, a));
                                        }
                                    }
                                }
                            }
                            _typeVisualizers.Add(f);
                        }
                        return(autoVis != null);
                    }
            }
            catch (Exception exception)
            {
                // don't allow natvis failures to stop debugging
                _process.WriteOutput(String.Format(CultureInfo.CurrentCulture, ResourceStrings.ErrorReadingFile, exception.Message, path));
                return(false);
            }
        }
Exemple #2
0
        private bool LoadFile(string path)
        {
            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(AutoVisualizer));
                if (!File.Exists(path))
                {
                    _process.WriteOutput(String.Format(CultureInfo.CurrentCulture, ResourceStrings.FileNotFound, path));
                    return(false);
                }
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.IgnoreComments = true;
                settings.IgnoreProcessingInstructions = true;
                settings.IgnoreWhitespace             = true;

                // set XmlResolver via reflection, if it exists. This is required for desktop CLR, as otherwise the XML reader may
                // attempt to hit untrusted external resources.
                var xmlResolverProperty = settings.GetType().GetProperty("XmlResolver", BindingFlags.Public | BindingFlags.Instance);
                xmlResolverProperty?.SetValue(settings, null);

                using (var stream = new System.IO.FileStream(path, FileMode.Open, FileAccess.Read))
                    using (var reader = XmlReader.Create(stream, settings))
                    {
                        AutoVisualizer autoVis = null;
                        autoVis = serializer.Deserialize(reader) as AutoVisualizer;
                        if (autoVis != null)
                        {
                            FileInfo f = new FileInfo(autoVis);
                            if (autoVis.Items == null)
                            {
                                return(false);
                            }
                            foreach (var o in autoVis.Items)
                            {
                                if (o is VisualizerType)
                                {
                                    VisualizerType v = (VisualizerType)o;
                                    TypeName       t = TypeName.Parse(v.Name, _process.Logger);
                                    if (t != null)
                                    {
                                        lock (_typeVisualizers)
                                        {
                                            f.Visualizers.Add(new TypeInfo(t, v));
                                        }
                                    }
                                    // add an entry for each alternative name too
                                    if (v.AlternativeType != null)
                                    {
                                        foreach (var a in v.AlternativeType)
                                        {
                                            t = TypeName.Parse(a.Name, _process.Logger);
                                            if (t != null)
                                            {
                                                lock (_typeVisualizers)
                                                {
                                                    f.Visualizers.Add(new TypeInfo(t, v));
                                                }
                                            }
                                        }
                                    }
                                }
                                else if (o is AliasType)
                                {
                                    AliasType a = (AliasType)o;
                                    TypeName  t = TypeName.Parse(a.Name, _process.Logger);
                                    if (t != null)
                                    {
                                        lock (_typeVisualizers)
                                        {
                                            f.Aliases.Add(new AliasInfo(t, a));
                                        }
                                    }
                                }
                            }
                            _typeVisualizers.Add(f);
                        }
                        return(autoVis != null);
                    }
            }
            catch (Exception exception)
            {
                // don't allow natvis failures to stop debugging
                _process.WriteOutput(String.Format(CultureInfo.CurrentCulture, ResourceStrings.ErrorReadingFile, exception.Message, path));
                return(false);
            }
        }
Exemple #3
0
 public FileInfo(AutoVisualizer env)
 {
     Environment = env;
     Visualizers = new List <TypeInfo>();
     Aliases     = new List <AliasInfo>();
 }
 public FileInfo(AutoVisualizer env, string filename)
 {
     Environment = env;
     Visualizers = new List <TypeInfo>();
     Filename    = filename;
 }