public CommandViewTest(ICommandAndViewPlugin commandView, IFactoryClientCommand factoryClientCommand)
        {
            _factory = factoryClientCommand.Factory;
            try
            {
                _factory.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var clientCommand = (FactoryCommand)Activator.CreateInstance(factoryClientCommand.FactoryCommandType);

            try
            {
                clientCommand.Initialize(_factory);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var administrationCommand =
                (Orcus.Administration.Plugins.CommandViewPlugin.Command)Activator.CreateInstance(commandView.Command);

            Initialize(clientCommand, administrationCommand,
                       (ICommandView)Activator.CreateInstance(commandView.CommandView),
                       (FrameworkElement)Activator.CreateInstance(commandView.View));
        }
 public CommandViewTest(ICommandAndViewPlugin commandView, Type command)
 {
     Initialize((Command)Activator.CreateInstance(command),
                (Orcus.Administration.Plugins.CommandViewPlugin.Command)Activator.CreateInstance(commandView.Command),
                (ICommandView)Activator.CreateInstance(commandView.CommandView),
                (FrameworkElement)Activator.CreateInstance(commandView.View));
 }
Example #3
0
        public FactoryCommandPlugin(string path, PluginInfo pluginInfo, BitmapImage thumbnail,
                                    ICommandAndViewPlugin plugin, uint commandId)
        {
            Path       = path;
            PluginInfo = pluginInfo;
            Thumbnail  = thumbnail;
            Plugin     = plugin;
            CommandId  = commandId;

            using (var fs = new FileStream(Path, FileMode.Open, FileAccess.Read))
                using (var archive = new ZipArchive(fs, ZipArchiveMode.Read))
                    using (var zipStream = archive.GetEntry(PluginInfo.Library2).Open())
                        using (var ms = new MemoryStream())
                        {
                            using (var gzip = new GZipStream(ms, CompressionMode.Compress, true))
                            {
                                zipStream.CopyTo(gzip);
                            }
                            Size = ms.Length;
                        }
        }
Example #4
0
        private bool TestCommandView(ICommandAndViewPlugin commandView, Orcus.Plugins.Command command)
        {
            if (commandView.Command == null)
            {
                TestResultEntries.Add(new TestResultEntry {
                    Message = "Command is null", Failed = true
                });
                return(false);
            }

            if (commandView.CommandView == null)
            {
                TestResultEntries.Add(new TestResultEntry {
                    Message = "CommandView is null", Failed = true
                });
                return(false);
            }

            if (commandView.View == null)
            {
                TestResultEntries.Add(new TestResultEntry {
                    Message = "View is null", Failed = true
                });
                return(false);
            }

            Command adminCommand;

            try
            {
                var test = Activator.CreateInstance(commandView.Command);
                test.ToString();
                adminCommand = test as Command;
                if (adminCommand == null)
                {
                    TestResultEntries.Add(new TestResultEntry
                    {
                        Message =
                            $"\"{commandView.Command.FullName}\" doesn't inherit Orcus.Administration.Plugins.Command",
                        Failed = true
                    });
                    return(false);
                }

                if (adminCommand.Identifier != command.Identifier)
                {
                    TestResultEntries.Add(new TestResultEntry
                    {
                        Message =
                            $"The ids of the commands are not equal: Administration Command ID: {adminCommand.Identifier}, Client Command ID: {command.Identifier}",
                        Failed = true
                    });
                    return(false);
                }
            }
            catch (Exception ex)
            {
                TestResultEntries.Add(new TestResultEntry
                {
                    Message       = $"Instance of Command ({commandView.Command.FullName}) could not be created",
                    Failed        = true,
                    FullErrorText = ex.ToString()
                });
                return(false);
            }
            TestResultEntries.Add(new TestResultEntry
            {
                Message = $"Instance of Command ({commandView.Command.FullName}) successfully created"
            });
            try
            {
                adminCommand.Dispose();
            }
            catch (Exception ex)
            {
                TestResultEntries.Add(new TestResultEntry
                {
                    Message       = "Exception when trying to dispose the administration command",
                    Failed        = true,
                    FullErrorText = ex.ToString()
                });
                return(false);
            }

            try
            {
                var test = Activator.CreateInstance(commandView.CommandView);
                test.ToString();

                if (!(test is ICommandView))
                {
                    TestResultEntries.Add(new TestResultEntry
                    {
                        Message =
                            $"\"{commandView.CommandView.FullName}\" doesn't implement Orcus.Administration.Plugins.ICommandView",
                        Failed = true
                    });
                    return(false);
                }
            }
            catch (Exception ex)
            {
                TestResultEntries.Add(new TestResultEntry
                {
                    Message       = $"Instance of CommandView ({commandView.CommandView.FullName}) could not be created",
                    Failed        = true,
                    FullErrorText = ex.ToString()
                });
                return(false);
            }
            TestResultEntries.Add(new TestResultEntry
            {
                Message = $"Instance of CommandView ({commandView.CommandView.FullName}) successfully created"
            });

            try
            {
                var test = Activator.CreateInstance(commandView.View);
                test.ToString();
                if (!(test is FrameworkElement))
                {
                    TestResultEntries.Add(new TestResultEntry
                    {
                        Message =
                            $"\"{commandView.CommandView.FullName}\" doesn't inherit System.Windows.FrameworkElement",
                        Failed = true
                    });
                    return(false);
                }
            }
            catch (Exception ex)
            {
                TestResultEntries.Add(new TestResultEntry
                {
                    Message       = $"Instance of View ({commandView.CommandView.FullName}) could not be created",
                    Failed        = true,
                    FullErrorText = ex.ToString()
                });
                return(false);
            }
            TestResultEntries.Add(new TestResultEntry
            {
                Message =
                    $"Instance of CommandView ({commandView.CommandView.FullName}) successfully created; inherits FrameworkElement"
            });

            if (command.Identifier <= 1000)
            {
                TestResultEntries.Add(new TestResultEntry
                {
                    Message = $"Command ID is lower than or equal to 1000 ({command.Identifier})",
                    Failed  = true
                });
                return(false);
            }

            try
            {
                command.Dispose();
            }
            catch (Exception ex)
            {
                TestResultEntries.Add(new TestResultEntry
                {
                    Message       = "Exception when trying to dispose the client command",
                    Failed        = true,
                    FullErrorText = ex.ToString()
                });
                return(false);
            }

            return(true);
        }