Exemplo n.º 1
0
        public void GetModelTypesTest()
        {
            PluginFactory.LoadPlugins(pluginPath);
            var actual = PluginFactory.GetModelTypes();

            Assert.IsTrue(actual.Length >= 1);
        }
Exemplo n.º 2
0
        public void LoadPluginsTest()
        {
            PluginFactory.LoadPlugins(pluginPath);

            Assert.IsTrue(PluginFactory.Info.Count >= 1, "Expected one info at path " + pluginPath);
            Assert.IsTrue(PluginFactory.ParserFactories.Count >= 1, "Expected one parser at path " + pluginPath);
            Assert.IsTrue(PluginFactory.PanelFactories.Count >= 1, "Expected one panel at path " + pluginPath);
        }
Exemplo n.º 3
0
        public void FindLogFileParserTest()
        {
            PluginFactory.Reset();
            PluginFactory.LoadPlugins(pluginPath);

            IParserFactory lfp = PluginFactory.FindLogFileParser("dummy.csv");

            IsTypenameSame(lfp.GetType(), typeof(Sample_Crunch.StandardPanels.CsvParserFactory));
        }
Exemplo n.º 4
0
        public void FindParserTest()
        {
            PluginFactory.Reset();
            PluginFactory.LoadPlugins(pluginPath);
            Type           factoryType = typeof(Sample_Crunch.StandardPanels.CsvParserFactory);
            IParserFactory lfp         = PluginFactory.FindParser(factoryType.FullName);

            IsTypenameSame(lfp.GetType(), factoryType);
        }
Exemplo n.º 5
0
 public static void AssemblyInitialize(TestContext context)
 {
     pluginPath = System.IO.Path.Combine(Environment.CurrentDirectory);
     // Init plugin reader
     PluginFactory.LoadPlugins(pluginPath);
     if (File.Exists(filename))
     {
         File.Delete(filename);
     }
 }
Exemplo n.º 6
0
        public void FindPanelFactoryTest()
        {
            PluginFactory.Reset();
            PluginFactory.LoadPlugins(pluginPath);
            Type          factoryType = typeof(Sample_Crunch.StandardPanels.TimePlotFactory);
            var           factory     = PluginFactory.CreatePanelFactory(factoryType);
            var           model       = factory.CreateModel();
            IPanelFactory lfp         = PluginFactory.FindPanelFactory(model);

            IsTypenameSame(lfp.GetType(), factoryType);
        }
Exemplo n.º 7
0
        public void RegisterModelTypeTest()
        {
            PluginFactory.LoadPlugins(pluginPath);

            var beforeLength = PluginFactory.GetModelTypes().Length;

            PluginFactory.RegisterModelType(typeof(PluginFactoryTests));

            var actual = PluginFactory.GetModelTypes();

            CollectionAssert.Contains(actual, typeof(PluginFactoryTests));
            Assert.IsTrue(actual.Length == beforeLength + 1);
        }
Exemplo n.º 8
0
        public void SaveAndOpenFailures()
        {
            PluginFactory.Reset();
            PluginFactory.LoadPlugins(pluginPath);
            Assert.IsFalse(File.Exists(filename), "Project file should not exist");
            ProjectData testProj = new ProjectData();

            testProj.Files.Add(new FileModel());
            testProj.Save(filename);

            Assert.IsTrue(File.Exists(filename), "No project file written");
            ProjectData openedProj = ProjectData.Open(filename); // Should fail since there is no file in filetopic

            ProjectViewModel projVM = new ProjectViewModel(openedProj);
        }
Exemplo n.º 9
0
        public void InvalidPlugin()
        {
            StreamWriter sw = File.CreateText(Path.Combine(pluginPath, invalidPlugin));

            sw.WriteLine("Not a valid dll!");
            sw.Close();

            try
            {
                List <Exception> execptions = PluginFactory.LoadPlugins(pluginPath);
                Assert.IsTrue(execptions.Count > 0, "Expect at least one error");
                Assert.IsTrue(execptions[0].ToString().Contains(invalidPlugin));
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected exception" + ex.ToString());
            }

            // Verify that it continued
            Assert.IsTrue(PluginFactory.ParserFactories.Count >= 1, "Expected one plugin at path " + pluginPath);
        }
Exemplo n.º 10
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                var pluginManager = SimpleIoc.Default.GetInstance <ViewModel.PluginManagerViewModel>();

                // Create plugin directory
                if (!Directory.Exists(pluginManager.PluginPath))
                {
                    Directory.CreateDirectory(pluginManager.PluginPath);
                }

                //  Move standard panels dll to plugin directory
                string standardPanelsTargetPath = Path.Combine(pluginManager.PluginPath, "StandardPanels.dll");
                if (!File.Exists(standardPanelsTargetPath))
                {
                    string standardPanelsSourcePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "StandardPanels.dll");
                    File.Copy(standardPanelsSourcePath, standardPanelsTargetPath, true);
                }

                // Load plugins from plugin directory
                List <Exception> errors = PluginFactory.LoadPlugins(pluginManager.PluginPath);

                foreach (var ex in errors)
                {
                    await MainViewModel.DialogService.ShowError(ex.InnerException, ex.Message, "Continue", null);
                }
            }
            catch (Exception ex)
            {
                await MainViewModel.DialogService.ShowError(ex.Message, "Could not load plugins", "Continue", null);

                AppTelemetry.ReportError("Loading", ex);
            }

            // Add local factories which will not be found because they are not in dll's.
            PluginFactory.PanelFactories.Add(PluginFactory.CreatePanelFactory(typeof(Factory.MarkerPanelFactory)));
            PluginFactory.PanelFactories.Add(PluginFactory.CreatePanelFactory(typeof(Factory.ProjectPanelFactory)));

            MainViewModel.PropertyChanged += Main_PropertyChanged;

            foreach (var item in PluginFactory.PanelFactories)
            {
                // Add if it has no attribute set or if the attribute is set check the visible flag
                PanelPluginAttribute attr = item.GetType().GetCustomAttribute <PanelPluginAttribute>(false);
                if (attr == null || attr.Visible)
                {
                    MainViewModel.Windows.Add(item);
                }
            }

            MainViewModel.NewProjectCommand.Execute(null);

            if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments != null && AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null && AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0)
            {
                string filename = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0].ToString();
                try
                {
                    MainViewModel.Project.AddLogFile(filename);
                }
                catch (FileLoadException)
                {
                    MessageBox.Show("There is no available log file reader that can read that file.");
                    return;
                }
            }

            // If this is first run show news
            try
            {
                bool firstrun = Properties.Settings.Default.FirstRun;
                if (firstrun)
                {
                    MainViewModel.ShowWebPageCommand.Execute(@"https://wolkesson.github.io/SampleCrunch/getting-started");
                    Properties.Settings.Default.AppTelemetry = (MessageBox.Show(
                                                                    "Sample Crunch uses volentary telemetry to track usage and find bugs. Do you approve to send annonumous data?",
                                                                    "Allow telemetry?", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes);
                    Properties.Settings.Default.FirstRun = false;
                    Properties.Settings.Default.Save();
                }
            }
            catch (System.Deployment.Application.InvalidDeploymentException)
            {
                // We will end up here if application is not installed, but run locally.
            }

            try
            {
                // Block App telemetry if user has disapproved it
                AppTelemetry.DoNotSend = !Properties.Settings.Default.AppTelemetry;
                if (string.IsNullOrEmpty(Properties.Settings.Default.AppTelemetryUID))
                {
                    AppTelemetry.RegisterUser(CultureInfo.InstalledUICulture.EnglishName, MainViewModel.Version);
                }
            }
            catch
            { }
        }