예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PluginManagerModel" /> class.
        /// </summary>
        /// <param name="controller">The controller.</param>
        /// <param name="configurationHelper">The configuration helper.</param>
        /// <param name="notifyManager">The notify manager.</param>
        /// <param name="helper">The helper.</param>
        public PluginManagerModel(
            IPluginController controller,
            IConfigurationHelper configurationHelper,
            INotificationManager notifyManager,
            IVsEnvironmentHelper helper)
        {
            this.notificationManager = notifyManager;
            this.Header = "Plugin Manager";
            this.configurationHelper   = configurationHelper;
            this.controller            = controller;
            this.vshelper              = helper;
            this.userPluginInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "vssonarextension", vshelper.VsVersion(), "plugins");

            if (!Directory.Exists(this.userPluginInstallPath))
            {
                Directory.CreateDirectory(this.userPluginInstallPath);
            }

            this.plugins = new List <IPlugin>();

            this.MenuPlugins         = new List <IMenuCommandPlugin>();
            this.AnalysisPlugins     = new List <IAnalysisPlugin>();
            this.SourceCodePlugins   = new List <ISourceVersionPlugin>();
            this.IssueTrackerPlugins = new List <IIssueTrackerPlugin>();

            var defaultPluginsFolder = Path.Combine(this.controller.ExtensionFolder, "plugins");

            this.InitPluginList(helper, null, defaultPluginsFolder);
            this.InitPluginList(helper, null, this.userPluginInstallPath);
            this.InitCommanding();

            SonarQubeViewModel.RegisterNewViewModelInPool(this);
        }
예제 #2
0
        public void TestAuthorizeForIndexNamedController()
        {
            IoCManager.Instance.Register <IPluginController, TestController>("TestController");
            IPluginController controller = IoCManager.Instance.ResolveIfRegistered <IPluginController>("TestController");

            var actionResult = controller.Index();
        }
예제 #3
0
        public void TestAuthorizeForIndexWithInterfaceResolving()
        {
            IoCManager.Instance.Register <IPluginController, TestController>();
            IPluginController controller = IoCManager.Instance.ResolveIfRegistered <IPluginController>();

            var actionResult = controller.Index();
        }
예제 #4
0
        protected override Type GetControllerType(System.Web.Routing.RequestContext requestContext, string controllerName)
        {
            Type controllerType = base.GetControllerType(requestContext, controllerName);

            if (controllerType != null)
            {
                return(controllerType);
            }

            var controllers = _kernel.GetAll <IController>().ToList();

            var controller = _kernel.TryGet <IController>(controllerName + "Controller");

            if (controller == null)
            {
                return(base.GetControllerType(requestContext, controllerName));
            }
            else if (controller is IPluginController)
            {
                IPluginController pluginController = (IPluginController)controller;
                requestContext.HttpContext.Items[HttpContextItemKeys.PluginFolder] = pluginController.FolderName;
                requestContext.HttpContext.Items.Remove(HttpContextItemKeys.PluginFolder);
            }

            return(controller.GetType());
        }
예제 #5
0
        protected virtual void Initialize(IPluginServiceProvider serviceProvider)
        {
            this.coreForm = serviceProvider.GetService(typeof(Form)) as Form;

            if (serviceProvider.Contains(typeof(IContainerControl)))
            {
                this.mdiUIContainer = serviceProvider.GetService(typeof(IContainerControl)) as Control;
            }

            this.currentModulePluginController = serviceProvider.GetService(typeof(IPluginController <>)) as IPluginController <TPluginItem>;

            this.modulePluginManager = serviceProvider.GetService(typeof(IPluginManager <>)) as IPluginManager <TPluginItem>;

            this.currentAppModulePluginItem = this.currentModulePluginController.PluginItem;

            if (this.mdiUIContainer == null)
            {
                throw new InfrastructureException("The container which is used to load this UI screen cannot be null. Please specify a container which inherits control. E.g. panel or form.");
            }

            if (this.mdiUIContainer != null &&
                !this.mdiUIContainer.Controls.Contains(this))
            {
                this.mdiUIContainer.SuspendLayout();

                this.Dock = DockStyle.Fill;

                this.mdiUIContainer.Controls.Add(this);
                this.mdiUIContainer.ResumeLayout();
            }

            this.Focus();

            this.Hide();
        }
예제 #6
0
 /// <summary>
 /// Initializes the plugin.  This is where a plugin's constructor logic should go.
 /// </summary>
 /// <param name="controller">A reference to an ICE controller instance.</param>
 /// <param name="pluginWrapper">A reference to the plugin controller (or the plugin itself for derived types), which contains other methods specific to plugins (such as setting up default name=value properties).</param>
 /// <returns>True if initialization was successful.</returns>
 public virtual void Initialize(ICEController controller, IPluginController pluginWrapper)
 {
     if (_Plugin != null && _Plugin != this)
     {
         _Plugin.Initialize(controller, pluginWrapper);
     }
     throw new NotImplementedException("You must implement an 'IPlugin.Initialize()' method in your own type, or override the existing one for derived types.");
 }
 public IPluginInteractionLink CreateInteractionLink(IPluginDescriptor pluginDescriptor, 
     IPlugin pluginRawInstance, IPluginController pluginController, IPluginInstance pluginManagedInstance)
 {
     return new StandardPluginInteractionLink(pluginDescriptor,
         pluginRawInstance,
         pluginController,
         pluginManagedInstance);
 }
예제 #8
0
        public void Init()
        {
            //Register controller with name and set interception behavior
            IoCManager.Container.RegisterType <IPluginController, TestController>("TestController",
                                                                                  new Interceptor <InterfaceInterceptor>(),
                                                                                  new InterceptionBehavior <PluginAuthorizationBehavior>());

            //Resolve
            _controller = IoCManager.Instance.ResolveIfRegistered <IPluginController>("TestController");

            IoCManager.Instance.Register <IUserClaimsManager, UserClaimsManager>();
        }
예제 #9
0
        private INativeHandleContract LoadPluginCore(string assembly, string typeName)
        {
            var objectHandle = Activator.CreateInstance(assembly, typeName);

            pluginController = (IPluginController)objectHandle.Unwrap();
            pluginController.Initialize();
            var view      = pluginController.CreateMainView();
            var contract  = FrameworkElementAdapters.ViewToContractAdapter((FrameworkElement)view);
            var insulator = new NativeHandleContractInsulator(contract);

            return(insulator);
        }
예제 #10
0
        public object GetRegistryValue(IPluginController source, string name, object defaultValue)
        {
            string sourceTypeName = source.GUID;

            RegistryKey libRegKey = Registry.LocalMachine.OpenSubKey("Software\\ICE\\" + sourceTypeName);

            if (libRegKey == null)
            {
                return(null);
            }

            return(libRegKey.GetValue(name, defaultValue));
        }
예제 #11
0
        public void Initialize(ICEController controller, IPluginController pluginWrapper)
        {
            _Controller = controller;

            // ... get/set some default properties ...

            //object propVals = fSerivce.GetRegistryValue(fPluginWrapper, "Properties", null);
            //if (propVals != null)
            //    fPluginWrapper.ImportNameValues(propVals.ToString());

            //fTickDuration = fPluginWrapper.GetSetValue("TickDuration", fTickDuration);

            //if (propVals == null)
            //    fSerivce.SetRegistryValue(fPluginWrapper, "Properties", fPluginWrapper.ExportNameValues());
        }
예제 #12
0
        protected virtual void StopCurrentRunningPluginController()
        {
            IPluginController <TPluginItem> currentRunningPluginController =
                this.pluginManager.PluginControllers.RunningPluginController;

            if (currentRunningPluginController == null)
            {
                return;
            }

            if (this.PluginInstance.Lifetime == LifetimeMode.KeepAlive)
            {
                currentRunningPluginController.Unload(false);
            }
        }
        public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            //Method name
            var methodBase = input.MethodBase;

            //Plugin Controller Name
            var pluginControllerType = input.Target.GetType();
            IPluginController pluginControllerInstance = Activator.CreateInstance(pluginControllerType) as PluginControllerBase;

            if (pluginControllerInstance == null)
            {
                throw new InvalidCastException("Couldn't cast to IPluginController");
            }
            //var pluginControllerName = pluginControllerInstance.AssemblyName;
            var pluginControllerName = pluginControllerType.Name;

            //Plugin Name
            var pluginType = pluginControllerInstance.PluginType;
            var pluginName = pluginType.Name;

            //Create claim
            //TODO : Add method ?? InterceptionBehavior cause problem, searches for get_title claim
            string claim = pluginName + "/" + pluginControllerName;// + "/" + methodBase.Name;

            //Check claim
            if (!_userClaimsManager.CheckUserClaim(claim))
            {
                throw new NotAuthorizedException("User doesn't have " + claim + " claim.");
            }

            // Invoke the next behavior in the chain.
            var result = getNext()(input, getNext);


            // After invoking the method on the original target.
            if (result.Exception != null)
            {
                var temp = result.Exception.Message;
            }
            else
            {
                var temp = result.ReturnValue;
            }

            return(result);
        }
            public void Setup()
            {
                this.mocks            = new MockRepository();
                this.service          = this.mocks.Stub <ISonarRestService>();
                this.vshelper         = this.mocks.Stub <IVsEnvironmentHelper>();
                this.pluginController = this.mocks.Stub <IPluginController>();
                this.analysisPlugin   = this.mocks.Stub <IAnalysisPlugin>();

                using (this.mocks.Record())
                {
                    SetupResult.For(this.service.GetServerInfo(Arg <ISonarConfiguration> .Is.Anything)).Return(3.6);
                    SetupResult.For(this.service.AuthenticateUser(Arg <ISonarConfiguration> .Is.Anything)).Return(true);
                    SetupResult.For(this.vshelper.ReadSavedOption("Sonar Options", "General", "SonarHost")).Return("serveraddr");
                    SetupResult.For(this.vshelper.ReadSavedOption("Sonar Options", "General", "SonarUserPassword")).Return("password");
                    SetupResult.For(this.vshelper.ReadSavedOption("Sonar Options", "General", "SonarUserName")).Return("login");
                }
            }
예제 #15
0
        public void TestAuthorizeForUpdateWithInterfaceResolving()
        {
            try
            {
                IoCManager.Instance.Register <IPluginController, TestController>();
                IPluginController controller = IoCManager.Instance.ResolveIfRegistered <IPluginController>();

                //TODO : Test another action that user doesn't have claim
                var actionResult = controller.Index();

                Assert.IsTrue(false, "Update should throw NotAuthorizedException exception");
            }
            catch (NotAuthorizedException ex)
            {
                Assert.IsTrue(true);
            }
        }
예제 #16
0
        // -------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Sets a registry value based on the calling object (example: an ITask).
        /// </summary>
        /// <param name="source"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        public void SetRegistryValue(IPluginController source, string name, object value)
        {
            string sourceTypeName = source.GUID;

            RegistryKey libRegKey = Registry.LocalMachine.OpenSubKey("Software\\ICE\\" + sourceTypeName);

            if (libRegKey == null)
            {
                libRegKey = Registry.LocalMachine.CreateSubKey("Software\\ICE\\" + sourceTypeName);
                libRegKey.SetValue("Name", source.Name, RegistryValueKind.String);
            }

            RegistryValueKind type = RegistryValueKind.String;

            if (Utilities.IsInt(value.GetType()))
            {
                type = RegistryValueKind.DWord;
            }

            libRegKey.SetValue(name, value, type);
        }
예제 #17
0
        public IActionResult Execute(string pluginKey, string route, Stream requestBody,
                                     IPluginController pluginController, MethodInfo method)
        {
            pluginController.PluginKey = pluginKey;

            route = GetRoute(route);

            var pluginControllerRoute = method.GetCustomAttribute <PluginControllerRouteAttribute>();

            var values = GetValues(GetRoute(pluginControllerRoute.Template), route);

            object[] parameters = GetParameters(method, requestBody, values);

            var result = method.Invoke(pluginController, parameters);

            if (result is IActionResult actionResult)
            {
                return(actionResult);
            }

            return(new ObjectResult(result));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PluginManagerModel" /> class.
        /// </summary>
        /// <param name="controller">The controller.</param>
        /// <param name="configurationHelper">The configuration helper.</param>
        /// <param name="notifyManager">The notify manager.</param>
        /// <param name="helper">The helper.</param>
        public PluginManagerModel(
            IPluginController controller,
            IConfigurationHelper configurationHelper,
            INotificationManager notifyManager,
            IVsEnvironmentHelper helper)
        {
            this.notificationManager = notifyManager;
            this.Header = "Plugin Manager";
            this.configurationHelper = configurationHelper;
            this.controller          = controller;
            this.vshelper            = helper;

            this.plugins             = new List <IPlugin>();
            this.MenuPlugins         = new List <IMenuCommandPlugin>();
            this.AnalysisPlugins     = new List <IAnalysisPlugin>();
            this.SourceCodePlugins   = new List <ISourceVersionPlugin>();
            this.IssueTrackerPlugins = new List <IIssueTrackerPlugin>();

            this.InitPluginList(helper, null);
            this.InitCommanding();

            SonarQubeViewModel.RegisterNewViewModelInPool(this);
        }
예제 #19
0
        protected virtual void OnRibbonButtonClickCommand(object sender, EventArgs e)
        {
            RibbonButton ribbonButton = sender as RibbonButton;

            if (ribbonButton == null)
            {
                return;
            }

            string modulePluginItemName = ribbonButton.Name;

            this.tickedControllerToBeExecuted = this.PluginManager.PluginControllers[modulePluginItemName];

            this.tickedControllerToBeExecuted.Loading -= new CancelEventHandler(this.OnTickedControllerToBeExecutedLoading);

            this.tickedControllerToBeExecuted.Loading += new CancelEventHandler(this.OnTickedControllerToBeExecutedLoading);

            if (!this.tickedControllerToBeExecuted.Running)
            {
                this.tickedControllerToBeExecuted.Load();
            }

            this.SetRibbonButtonStyleOnModulePluginLoaded(ribbonButton);
        }
예제 #20
0
        /// <summary>
        /// Controllers recursion creation.
        /// </summary>
        protected virtual void CreatePluginControllers(IEnumerable <TPluginItem> pluginItems)
        {
            if (pluginItems == null)
            {
                return;
            }

            foreach (TPluginItem pluginItem in pluginItems)
            {
                if (!this.OnPluginAdding(pluginItem))
                {
                    IPluginController <TPluginItem> pluginController = this.CreatePluginController(pluginItem);

                    if (pluginController != null)
                    {
                        this.PluginControllers.Add(pluginController);

                        this.OnPluginAdded(pluginItem);
                    }
                }

                this.CreatePluginControllers(pluginItem.SubItems);
            }
        }
            public void Setup()
            {
                this.mocks = new MockRepository();
                this.service = this.mocks.Stub<ISonarRestService>();
                this.vshelper = this.mocks.Stub<IVsEnvironmentHelper>();
                this.pluginController = this.mocks.Stub<IPluginController>();
                this.plugin = this.mocks.Stub<IPlugin>();

                using (this.mocks.Record())
                {
                    SetupResult.For(this.service.GetServerInfo(Arg<ConnectionConfiguration>.Is.Anything)).Return(3.6);
                    SetupResult.For(this.service.AuthenticateUser(Arg<ConnectionConfiguration>.Is.Anything)).Return(true);
                    SetupResult.For(this.vshelper.ReadSavedOption("Sonar Options", "General", "SonarHost")).Return("serveraddr");
                    SetupResult.For(this.vshelper.ReadSavedOption("Sonar Options", "General", "SonarUserPassword")).Return("password");
                    SetupResult.For(this.vshelper.ReadSavedOption("Sonar Options", "General", "SonarUserName")).Return("login");
                }
            }
예제 #22
0
        protected virtual void OnTickedControllerToBeExecutedLoading(object sender, CancelEventArgs e)
        {
            IPluginController <RibbonModulePluginItem> currentRunningModulePluginController =
                this.PluginManager.PluginControllers.RunningPluginController;

            // If the current running plugin is UI screen based on user control or popup overlay form
            if (currentRunningModulePluginController != null &&
                currentRunningModulePluginController.PluginInstance != null &&
                currentRunningModulePluginController.PluginInstance is IView)
            {
                IView currentRunningModulePluginView = (IView)currentRunningModulePluginController.PluginInstance;

                IPluginUnloadingContextAction pluginUnloadingContextAction = null;

                if (currentRunningModulePluginView is IPluginUnloadingContextAction)
                {
                    pluginUnloadingContextAction = currentRunningModulePluginView as IPluginUnloadingContextAction;

                    if (pluginUnloadingContextAction != null)
                    {
                        pluginUnloadingContextAction.ExecuteActionBeforeUnloading(e);

                        if (e.Cancel)
                        {
                            return;
                        }
                    }
                }

                if (currentRunningModulePluginView is IEditableView)
                {
                    IEditableView currentRunningModulePluginEditableView = (IEditableView)currentRunningModulePluginView;

                    if (currentRunningModulePluginEditableView.ViewChanged)
                    {
                        DialogResult confirmationResult = MessageBox.Show(
                            @"You have not saved your changes on this screen yet.  
                             If you go to another screeb before saving your changes they will be discarded. 
                             Do you wish to save them now?", Application.ProductName,
                            MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

                        if (confirmationResult == DialogResult.Yes)
                        {
                            //Execute save
                        }
                        else if (confirmationResult == DialogResult.No)
                        {
                            // to do...
                        }
                        else if (confirmationResult == DialogResult.Cancel)
                        {
                            e.Cancel = true;

                            if (pluginUnloadingContextAction != null)
                            {
                                pluginUnloadingContextAction.ExecuteActionAfterUnloadCancelled();
                            }
                        }
                    }
                }
            }

            if (!e.Cancel)
            {
                // Havn't executed debug yet.

                //IPluginLoadingContextAction<XpressModulePluginItem> viewLoadingContextAction =
                //    EAppRuntime.Instance.App.ObjectContainer.Resolve<IPluginLoadingContextAction<XpressModulePluginItem>>
                //    (this.tickedControllerToBeExecuted.PluginItem.Name);

                //if (viewLoadingContextAction != null)
                //{
                //    viewLoadingContextAction.ExecuteActionOnLoading(currentRunningModulePluginController, this.tickedControllerToBeExecuted, e);

                //    if (e.Cancel)
                //    {
                //        return;
                //    }
                //}

                if (currentRunningModulePluginController != null)
                {
                    DetachSubPluginItems(currentRunningModulePluginController.PluginItem);
                }

                this.AttachSubPluginItems(this.tickedControllerToBeExecuted.PluginItem);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PluginManagerModel" /> class.
        /// </summary>
        /// <param name="controller">The controller.</param>
        /// <param name="configurationHelper">The configuration helper.</param>
        /// <param name="notifyManager">The notify manager.</param>
        /// <param name="helper">The helper.</param>
        public PluginManagerModel(
            IPluginController controller,
            IConfigurationHelper configurationHelper,
            INotificationManager notifyManager,
            IVsEnvironmentHelper helper)
        {
            this.notificationManager = notifyManager;
            this.Header = "Plugin Manager";
            this.configurationHelper = configurationHelper;
            this.controller = controller;
            this.vshelper = helper;

            this.plugins = new List<IPlugin>();
            this.MenuPlugins = new List<IMenuCommandPlugin>();
            this.AnalysisPlugins = new List<IAnalysisPlugin>();
            this.SourceCodePlugins = new List<ISourceVersionPlugin>();
            this.IssueTrackerPlugins = new List<IIssueTrackerPlugin>();

            this.InitPluginList(helper, null);
            this.InitCommanding();

            SonarQubeViewModel.RegisterNewViewModelInPool(this);
        }