Ejemplo n.º 1
0
        private void AddStreamAdapter(Type adapterType, VisualizationLogWriter logWriter, string assemblyPath)
        {
            logWriter.WriteLine("Loading StreamAdapter {0} from {1}...", adapterType.Name, assemblyPath);
            StreamAdapterMetadata streamAdapterMetadata = StreamAdapterMetadata.Create(adapterType, logWriter);

            if (streamAdapterMetadata != null)
            {
                this.streamAdapters.Add(streamAdapterMetadata);
            }
        }
Ejemplo n.º 2
0
        private void AddSummarizer(Type summarizerType, VisualizationLogWriter logWriter, string assemblyPath)
        {
            logWriter.WriteLine("Loading Summarizer {0} from {1}...", summarizerType.Name, assemblyPath);
            SummarizerMetadata summarizerMetadata = SummarizerMetadata.Create(summarizerType, logWriter);

            if (summarizerMetadata != null)
            {
                this.summarizers[summarizerType] = summarizerMetadata;
            }
        }
Ejemplo n.º 3
0
        private void AddVisualizer(Type visualizationObjectType, VisualizationLogWriter logWriter, string assemblyPath)
        {
            // Add both a "Visualize" and a "Visualize in new panel" command metadata
            logWriter.WriteLine("Loading Visualizer {0} from {1}...", visualizationObjectType.Name, assemblyPath);
            List <VisualizerMetadata> visualizerMetadata = VisualizerMetadata.Create(visualizationObjectType, this.summarizers, this.streamAdapters, logWriter);

            if (visualizerMetadata != null)
            {
                this.visualizers.AddRange(visualizerMetadata);
            }
        }
Ejemplo n.º 4
0
        private void DiscoverVisualizerObjects(List <string> assemblies, string visualizerLoadLogFilename)
        {
            bool hasErrors = false;

            // Create the log writer
            using (FileStream fileStream = File.Create(visualizerLoadLogFilename))
            {
                using (VisualizationLogWriter logWriter = new VisualizationLogWriter(fileStream))
                {
                    // Log preamble
                    logWriter.WriteLine("Loading PsiStudio Visualizers ({0})", DateTime.Now.ToString("G"));
                    logWriter.WriteLine("----------------------------------------------------");
                    logWriter.WriteLine();

                    foreach (string assembly in assemblies)
                    {
                        logWriter.WriteLine("Search Assembly: {0}...", assembly);
                    }

                    logWriter.WriteLine();

                    // Note: Visualization object types depend on both summarizer types and stream adapter types,
                    // so we need to make sure those types have all been loaded before we try to load the
                    // visualization object types.
                    Dictionary <Type, string> visualizationObjectTypes = new Dictionary <Type, string>();

                    foreach (string assemblyPath in assemblies)
                    {
                        // Get the list of types in the assembly
                        Type[] types = this.GetTypesFromAssembly(assemblyPath, logWriter);

                        // Look for attributes denoting visualziation objects, summarizers, and stream adapters.
                        foreach (Type type in types)
                        {
                            if (type.GetCustomAttribute <VisualizationObjectAttribute>() != null)
                            {
                                // Don't load these yet, wait until we've loaded the summarizers and adapters.
                                visualizationObjectTypes[type] = assemblyPath;
                            }

                            if (type.GetCustomAttribute <SummarizerAttribute>() != null)
                            {
                                this.AddSummarizer(type, logWriter, assemblyPath);
                            }

                            if (type.GetCustomAttribute <StreamAdapterAttribute>() != null)
                            {
                                this.AddStreamAdapter(type, logWriter, assemblyPath);
                            }
                        }
                    }

                    // Load all of the visualization object types that were found earlier
                    Dictionary <Type, string> .Enumerator visualizationObjectTypesEnumerator = visualizationObjectTypes.GetEnumerator();
                    while (visualizationObjectTypesEnumerator.MoveNext())
                    {
                        this.AddVisualizer(visualizationObjectTypesEnumerator.Current.Key, logWriter, visualizationObjectTypesEnumerator.Current.Value);
                    }

                    // Log complete
                    logWriter.WriteLine();
                    logWriter.WriteLine("PsiStudio visualizer loading has completed. ({0})", DateTime.Now.ToString("G"));

                    hasErrors = logWriter.HasErrors;
                }
            }

            // If there were any errors while loading the visualizers etc, inform the user and allow him to view the log.
            if (hasErrors)
            {
                MessageBoxWindow dlg = new MessageBoxWindow(
                    Application.Current.MainWindow,
                    "Visualizers Load Errors",
                    "One or more visualizers were not loaded because they contained errors.\r\n\r\nWould you like to see the visualizer load log?",
                    "Yes",
                    "No");

                if (dlg.ShowDialog() == true)
                {
                    // Display the log file in the default application for text files.
                    Process.Start(visualizerLoadLogFilename);
                }
            }
        }