public void TestAssociationWithSolution()
        {
            this.mocks    = new MockRepository();
            this.service  = this.mocks.Stub <ISonarRestService>();
            this.vshelper = this.mocks.Stub <IVsEnvironmentHelper>();
            var resource = new Resource {
                Key = "KEY"
            };
            var resources = new List <Resource> {
                resource
            };

            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.service.GetResourcesData(Arg <ISonarConfiguration> .Is.Anything, Arg <string> .Is.Equal("KEY"))).Return(resources);
                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");
                SetupResult.For(this.vshelper.ActiveSolutionName()).Return("Solution");
                SetupResult.For(this.vshelper.ReadOptionFromApplicationData("Solution", "PROJECTKEY")).Return("KEY");
            }

            var model = new ExtensionDataModel(this.service, this.vshelper, null, null);

            model.AssociateProjectToSolution();
            Assert.AreEqual("Selected Project: KEY", model.AssociatedProjectKey);
            model.AssociateProjectToSolution();
            Assert.AreEqual("Selected Project: KEY", model.AssociatedProjectKey);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="VsEvents"/> class.
        /// </summary>
        /// <param name="environment">
        ///     The environment.
        /// </param>
        /// <param name="dte2">
        ///     The dte 2.
        /// </param>
        /// <param name="vsSonarExtensionPackage"></param>
        public VsEvents(IVsEnvironmentHelper environment, DTE2 dte2, VsSonarExtensionPackage vsSonarExtensionPackage)
        {
            this.dte2               = dte2;
            this.package            = vsSonarExtensionPackage;
            this.environment        = environment;
            this.SolutionEvents     = dte2.Events;
            this.visualStudioEvents = dte2.Events.DTEEvents;
            this.buildEvents        = dte2.Events.BuildEvents;
            this.DocumentsEvents    = this.SolutionEvents.DocumentEvents;

            this.SolutionEvents.SolutionEvents.Opened        += this.SolutionOpened;
            this.SolutionEvents.SolutionEvents.AfterClosing  += this.SolutionClosed;
            this.SolutionEvents.WindowEvents.WindowActivated += this.WindowActivated;
            this.SolutionEvents.WindowEvents.WindowClosing   += this.WindowClosed;
            this.DocumentsEvents.DocumentSaved        += this.DoumentSaved;
            this.visualStudioEvents.OnStartupComplete += this.CloseToolWindows;
            this.buildEvents.OnBuildProjConfigDone    += this.ProjectHasBuild;

            VSColorTheme.ThemeChanged += this.VSColorTheme_ThemeChanged;

            var extensionRunningPath = Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", "").ToString();

            var uniqueId = this.dte2.Version;

            if (extensionRunningPath.ToLower().Contains(this.dte2.Version + "exp"))
            {
                uniqueId += "Exp";
            }

            SonarQubeViewModelFactory.StartupModelWithVsVersion(uniqueId, this.package).AnalysisModeHasChange += this.AnalysisModeHasChange;
            SonarQubeViewModelFactory.SQViewModel.VSonarQubeOptionsViewData.GeneralConfigurationViewModel.ConfigurationHasChanged +=
                this.AnalysisModeHasChange;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ServerViewModel" /> class.
        /// </summary>
        /// <param name="vsenvironmenthelper">The vsenvironmenthelper.</param>
        /// <param name="configurationHelper">The configuration helper.</param>
        /// <param name="restservice">The restservice.</param>
        /// <param name="notificationManager">The notification manager.</param>
        /// <param name="translator">The translator.</param>
        public ServerViewModel(
            IVsEnvironmentHelper vsenvironmenthelper,
            IConfigurationHelper configurationHelper,
            ISonarRestService restservice,
            INotificationManager notificationManager,
            ISQKeyTranslator translator)
        {
            this.notificationMan     = notificationManager;
            this.vsenvironmenthelper = vsenvironmenthelper;
            this.configurationHelper = configurationHelper;
            this.restservice         = restservice;

            this.Header = "Server Analysis";
            this.AvailableActionPlans = new ObservableCollection <SonarActionPlan>();
            this.AlreadyOpenDiffs     = new SortedSet <string>();
            this.IssuesGridView       = new IssueGridViewModel(true, "ServerView", true, this.configurationHelper, this.restservice, this.notificationMan, translator);
            this.IssuesGridView.ShowLeftFlyoutEvent += this.ShowHideLeftFlyout;
            this.InitCommanding();

            this.ForeGroundColor = Colors.Black;
            this.BackGroundColor = Colors.White;
            this.SizeOfFlyout    = 0;
            // register model
            AssociationModel.RegisterNewModelInPool(this);
        }
Пример #4
0
 /// <summary>
 /// The update services.
 /// </summary>
 /// <param name="vsenvironmenthelperIn">The vsenvironmenthelper in.</param>
 /// <param name="statusBar">The status bar.</param>
 /// <param name="provider">The provider.</param>
 public void UpdateServices(
     IVsEnvironmentHelper vsenvironmenthelperIn,
     IVSSStatusBar statusBar,
     IServiceProvider provider)
 {
     // does not access vs services
 }
        /// <summary>The extension data viewModel update.</summary>
        /// <param name="restServiceIn">The rest service in.</param>
        /// <param name="vsenvironmenthelperIn">The vsenvironmenthelper in.</param>
        /// <param name="statusBar">The status bar.</param>
        /// <param name="provider">The provider.</param>
        /// <param name="extensionFolder">The extension Folder.</param>
        public void InitModelFromPackageInitialization(
            ISonarRestService restServiceIn,
            IVsEnvironmentHelper vsenvironmenthelperIn,
            IVSSStatusBar statusBar,
            IServiceProvider provider,
            string extensionFolder)
        {
            this.ServiceProvider     = provider;
            this.SonarRestConnector  = restServiceIn;
            this.VsHelper            = vsenvironmenthelperIn;
            this.StatusBar           = statusBar;
            this.ExtensionFolder     = extensionFolder;
            this.NotificationManager = new NotifyCationManager(this, this.VsHelper);

            this.VSonarQubeOptionsViewData.InitPuginSystem(vsenvironmenthelperIn, this.PluginControl, this.NotificationManager);

            this.InitMenus();
            this.InitViews();
            this.InitConnection();

            this.UpdateTheme(Colors.Black, Colors.White);

            foreach (IAnalysisViewModelBase view in this.SonarQubeViews)
            {
                view.UpdateServices(restServiceIn, vsenvironmenthelperIn, this.configurationHelper, statusBar, provider);
            }

            this.VSonarQubeOptionsViewData.UpdateServices(restServiceIn, vsenvironmenthelperIn, statusBar, provider);
            foreach (IOptionsViewModelBase view in this.VSonarQubeOptionsViewData.AvailableOptions)
            {
                view.UpdateServices(restServiceIn, vsenvironmenthelperIn, this.configurationHelper, statusBar, provider);
            }
        }
        /// <summary>
        /// The get connection configuration.
        /// </summary>
        /// <param name="properties">
        /// The properties.
        /// </param>
        /// <param name="service">
        /// The service.
        /// </param>
        /// <returns>
        /// The <see cref="ConnectionConfiguration"/>.
        /// </returns>
        public static ConnectionConfiguration GetConnectionConfiguration(IVsEnvironmentHelper properties, ISonarRestService service)
        {
            ErrorMessage = string.Empty;

            var userName = "******";
            var userPassword = "******";
            var hostname = "http://localhost:9000";
            if (properties != null)
            {
                userName = properties.ReadSavedOption("Sonar Options", "General", "SonarUserName");
                userPassword = properties.ReadSavedOption("Sonar Options", "General", "SonarUserPassword");
                hostname = properties.ReadSavedOption("Sonar Options", "General", "SonarHost");
            }

            if (string.IsNullOrEmpty(hostname))
            {
                ErrorMessage = "User Configuration is Invalid, Check Tools > Options > Sonar Options";
                return null;
            }

            var userConf = new ConnectionConfiguration(hostname, userName, userPassword);
            if (!service.AuthenticateUser(userConf))
            {
                ErrorMessage = "Authentication Failed, Check User, Password and Hostname";
                return null;
            }

            return userConf;
        }
        public IPlugin IstallNewPlugin(string fileName,
                                       ISonarConfiguration conf,
                                       IConfigurationHelper helper,
                                       INotificationManager manager,
                                       IVsEnvironmentHelper vshelper,
                                       string pluginsFolder)
        {
            var assembliesInFile       = this.UnzipFiles(fileName, this.TempInstallPathFolder);
            var assembliesToTempFolder = this.GetAssembliesInTempFolder();
            var plugin = this.LoadPlugin(
                assembliesInFile.ToArray(),
                this.TempInstallPathFolder,
                conf, helper, manager, vshelper);

            if (plugin != null)
            {
                Directory.Delete(this.TempInstallPathFolder, true);
                this.UnzipFiles(fileName, pluginsFolder);
            }

            foreach (string path in assembliesInFile)
            {
                var file = Path.GetFileName(path);
                plugin.SetDllLocation(Path.Combine(pluginsFolder, file));
            }

            return(plugin);
        }
Пример #8
0
        /// <summary>
        /// The extension data viewModel update.
        /// </summary>
        /// <param name="vsenvironmenthelperIn">The vsenvironmenthelper in.</param>
        /// <param name="statusBar">The status bar.</param>
        /// <param name="provider">The provider.</param>
        /// <param name="extensionFolder">The extension Folder.</param>
        public void InitModelFromPackageInitialization(
            IVsEnvironmentHelper vsenvironmenthelperIn,
            IVSSStatusBar statusBar,
            IServiceProvider provider,
            string extensionFolder)
        {
            this.ServiceProvider = provider;
            this.VsHelper        = vsenvironmenthelperIn;
            this.StatusBar       = statusBar;
            this.ExtensionFolder = extensionFolder;

            // register notificaton manager, since all messages will be show also for initialization
            (this.notificationManager as IModelBase).UpdateServices(this.VsHelper, this.StatusBar, this.ServiceProvider);
            this.VSonarQubeOptionsViewData.InitPuginSystem(vsenvironmenthelperIn, this.pluginController, this.notificationManager);
            this.InitMenus();
            this.InitViewsAndModels();

            // start association module after all models are started
            this.AssociationModule = new AssociationModel(
                this.notificationManager,
                this.sonarRestConnector,
                this.configurationHelper,
                this.sonarKeyTranslator,
                this.VSonarQubeOptionsViewData.PluginManager,
                this);

            this.AssociationModule.UpdateServicesInModels(this.VsHelper, this.StatusBar, this.ServiceProvider);
            this.UpdateTheme(Colors.Black, Colors.White);

            // try to connect to start to sonar if on start is on
            if (this.VSonarQubeOptionsViewData.GeneralConfigurationViewModel.IsConnectAtStartOn)
            {
                this.OnConnectToSonar(false);
            }
        }
Пример #9
0
 /// <summary>
 /// The update services.
 /// </summary>
 /// <param name="vsenvironmenthelperIn">The vsenvironmenthelper in.</param>
 /// <param name="statusBar">The status bar.</param>
 /// <param name="provider">The provider.</param>
 public void UpdateServices(
     IVsEnvironmentHelper vsenvironmenthelperIn,
     IVSSStatusBar statusBar,
     IServiceProvider provider)
 {
     this.vsenvironmenthelper = vsenvironmenthelperIn;
 }
Пример #10
0
 /// <summary>
 /// Updates the services.
 /// </summary>
 /// <param name="vsenvironmenthelperIn">The vsenvironmenthelper in.</param>
 /// <param name="statusBar">The status bar.</param>
 /// <param name="provider">The provider.</param>
 public void UpdateServicesInModels(IVsEnvironmentHelper vsenvironmenthelperIn, IVSSStatusBar statusBar, IServiceProvider provider)
 {
     this.vshelper = vsenvironmenthelperIn;
     foreach (IModelBase model in modelPool)
     {
         model.UpdateServices(vsenvironmenthelperIn, statusBar, provider);
     }
 }
Пример #11
0
 /// <summary>
 /// The update services.
 /// </summary>
 /// <param name="vsenvironmenthelperIn">The vsenvironmenthelper in.</param>
 /// <param name="statusBarIn">The status bar in.</param>
 /// <param name="provider">The provider.</param>
 public void UpdateServices(
     IVsEnvironmentHelper vsenvironmenthelperIn,
     IVSSStatusBar statusBarIn,
     IServiceProvider provider)
 {
     this.visualStudioHelper = vsenvironmenthelperIn;
     this.statusBar          = statusBarIn;
     this.serviceProvier     = provider;
 }
Пример #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SearchComponenetDialog" /> class.
        /// </summary>
        /// <param name="conf">The conf.</param>
        /// <param name="rest">The rest.</param>
        /// <param name="availableProjects">The available projects.</param>
        /// <param name="listofSaveComp">The listof save comp.</param>
        /// <param name="vshelper">The vshelper.</param>
        public SearchComponenetDialog(ISonarConfiguration conf,
                                      ISonarRestService rest,
                                      List <Resource> availableProjectsIn,
                                      List <Resource> listofSaveComp,
                                      IVsEnvironmentHelper vshelper)
        {
            this.selectedItems     = new ObservableCollection <Resource>();
            this.availableProjects = new ObservableCollection <Resource>(availableProjectsIn);
            this.componentList     = new ObservableCollection <Resource>();

            this.conf     = conf;
            this.rest     = rest;
            this.vshelper = vshelper;

            InitializeComponent();

            this.Projects.ItemsSource         = this.availableProjects;
            this.SelectedDataGrid.ItemsSource = this.selectedItems;
            this.SearchDataGrid.ItemsSource   = this.componentList;

            if (listofSaveComp != null)
            {
                foreach (var item in listofSaveComp)
                {
                    try
                    {
                        IEnumerable <Resource> resourcesWithSameKey =
                            from resource in this.availableProjects
                            where this.CompareKeysInProjects(resource, item.Key)
                            select resource;

                        var element = resourcesWithSameKey.First();

                        if (element.BranchResources.Count != 0)
                        {
                            element = element.BranchResources.First(x => x.Key.Equals(item.Key));
                        }

                        element.Qualifier = "TRK";

                        this.selectedItems.Add(element);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Failed to import project: ", ex.Message);
                    }
                }

                this.SearchDataGrid.Items.Refresh();
            }


            this.MouseLeftButtonDown += this.MouseLeftButtonDownPressed;
            this.SearchData.KeyDown  += new KeyEventHandler(this.KeyboardKeyDown);
        }
        /// <summary>Initializes a new instance of the <see cref="SolutionEventsListener"/> class.</summary>
        public SolutionEventsListener(IVsEnvironmentHelper helper)
        {
            this.environment = helper;
            this.InitNullEvents();

            this.solution = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution;

            if (this.solution != null)
            {
                this.solution.AdviseSolutionEvents(this, out this.solutionEventsCookie);
            }
        }
        /// <summary>Initializes a new instance of the <see cref="SolutionEventsListener"/> class.</summary>
        public SolutionEventsListener(IVsEnvironmentHelper helper)
        {
            this.environment = helper;
            this.InitNullEvents();

            this.solution = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution;

            if (this.solution != null)
            {
                this.solution.AdviseSolutionEvents(this, out this.solutionEventsCookie);
            }
        }
 public void Setup()
 {
     this.mocks    = new MockRepository();
     this.service  = this.mocks.Stub <ISonarRestService>();
     this.vshelper = this.mocks.Stub <IVsEnvironmentHelper>();
     using (this.mocks.Record())
     {
         SetupResult.For(this.service.GetServerInfo(Arg <ISonarConfiguration> .Is.Anything)).Return(3.5);
         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");
     }
 }
 public void Setup()
 {
     this.mocks = new MockRepository();
     this.service = this.mocks.Stub<ISonarRestService>();
     this.vshelper = this.mocks.Stub<IVsEnvironmentHelper>();
     using (this.mocks.Record())
     {
         SetupResult.For(this.service.GetServerInfo(Arg<ConnectionConfiguration>.Is.Anything)).Return(3.5);
         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");
     }
 }
        /// <summary>
        /// The init plugin list.
        /// </summary>
        /// <param name="visualStudioHelper">The visual studio helper.</param>
        /// <param name="files">The files.</param>
        /// <returns>true on ok</returns>
        private bool InitPluginList(IVsEnvironmentHelper visualStudioHelper, IEnumerable <string> files)
        {
            bool loaded = false;

            foreach (var plugin in this.controller.LoadPluginsFromPluginFolder(this.notificationManager, this.configurationHelper, visualStudioHelper, files))
            {
                var plugindata = plugin as IAnalysisPlugin;
                if (plugindata != null)
                {
                    this.AnalysisPlugins.Add(plugindata);
                    this.PluginList.Add(plugindata.GetPluginDescription());
                    this.plugins.Add(plugin);
                    loaded = true;
                    continue;
                }

                var pluginMenu = plugin as IMenuCommandPlugin;
                if (pluginMenu != null)
                {
                    this.MenuPlugins.Add(pluginMenu);
                    this.PluginList.Add(pluginMenu.GetPluginDescription());
                    this.plugins.Add(plugin);
                    loaded = true;
                    continue;
                }

                var pluginSourceControl = plugin as ISourceVersionPlugin;
                if (pluginSourceControl != null)
                {
                    this.SourceCodePlugins.Add(pluginSourceControl);
                    this.PluginList.Add(pluginSourceControl.GetPluginDescription());
                    this.plugins.Add(plugin);
                    loaded = true;
                    continue;
                }

                var pluginIssueTracker = plugin as IIssueTrackerPlugin;
                if (pluginIssueTracker != null)
                {
                    this.IssueTrackerPlugins.Add(pluginIssueTracker);
                    this.PluginList.Add(pluginIssueTracker.GetPluginDescription());
                    this.plugins.Add(plugin);
                    loaded = true;
                    continue;
                }
            }

            return(loaded);
        }
        /// <summary>
        /// Starts the solution listeners.
        /// </summary>
        /// <param name="helper">The helper.</param>
        private void StartSolutionListeners(IVsEnvironmentHelper helper)
        {
            this.listener = new SolutionEventsListener(helper);
            var triedOnceAlready = false;

            this.listener.OnAfterOpenProject += () =>
            {
                if (!SonarQubeViewModelFactory.SQViewModel.AssociationModule.IsAssociated && !triedOnceAlready)
                {
                    triedOnceAlready = true;
                    string solutionName = this.visualStudioInterface.ActiveSolutionName();
                    string solutionPath = this.visualStudioInterface.ActiveSolutionPath();

                    SonarQubeViewModelFactory.SQViewModel.Logger.WriteMessage("Solution Opened: " + solutionName + " : " + solutionPath);
                    SonarQubeViewModelFactory.SQViewModel.OnSolutionOpen(solutionName, solutionPath, string.Empty);
                }
            };
        }
        /// <summary>
        /// The load plugin using dedicated domain.
        /// </summary>
        /// <param name="assemblies">
        /// The assemblies.
        /// </param>
        /// <param name="refAssemblies">
        /// The ref assemblies.
        /// </param>
        /// <param name="basePath">
        /// The base path.
        /// </param>
        /// <param name="conf">
        /// The conf.
        /// </param>
        /// <returns>
        /// The <see cref="PluginDescription"/>.
        /// </returns>
        public IPlugin LoadPlugin(
            string[] assemblies,
            string basePath,
            ISonarConfiguration conf,
            IConfigurationHelper helper,
            INotificationManager manager,
            IVsEnvironmentHelper vshelper)
        {
            try
            {
                var loader = PluginSandBoxLoader.Sandbox(AppDomain.CurrentDomain, assemblies, this.CurrentDomainAssemblyResolve);
                try
                {
                    var pluginDesc = loader.LoadPlugin(conf, helper, manager, vshelper);

                    foreach (string assembly in assemblies)
                    {
                        File.Delete(assembly);
                    }

                    return(pluginDesc);
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null)
                    {
                        this.ErrorMessage = "Cannot Load Plugin: " + ex.InnerException.Message + " : " + ex.InnerException.StackTrace;
                    }
                    else
                    {
                        this.ErrorMessage = "Cannot Load Plugin: " + ex.Message + " : " + ex.StackTrace;
                    }

                    Debug.WriteLine(ex.Message + " " + ex.StackTrace);
                }
            }
            catch (Exception ex)
            {
                this.ErrorMessage = "Cannot Create Domain: " + ex.Message + " : " + ex.StackTrace;
            }

            return(null);
        }
Пример #20
0
        /// <summary>
        /// The init plugin system.
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="plugincontroller">The plugin controller.</param>
        /// <param name="manager">The manager.</param>
        public void InitPuginSystem(IVsEnvironmentHelper helper, PluginController plugincontroller, INotificationManager manager)
        {
            this.PluginManager = new PluginManagerModel(
                plugincontroller,
                this.configurationHelper,
                manager,
                helper);

            this.RoslynModel     = new RoslynManagerModel(this.PluginManager.AnalysisPlugins, manager, this.configurationHelper, this.restService);
            this.RoslynViewModel = new RoslynManagerViewModel(this.RoslynModel);

            this.AvailableOptionsViews.Add(this.PluginManager);
            this.AvailableOptionsViews.Add(this.RoslynViewModel);

            this.AvailableOptionsModels.Add(this.PluginManager);
            this.AvailableOptionsModels.Add(this.RoslynModel);

            // sync checks to plugins
            this.RoslynModel.SyncDiagnosticsInPlugins();
        }
        /// <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);
        }
Пример #22
0
        /// <summary>
        /// Searches the components.
        /// </summary>
        /// <param name="conf">The conf.</param>
        /// <param name="rest">The rest.</param>
        /// <param name="availableProjects">The available projects.</param>
        /// <param name="listofSaveComp">The listof save comp.</param>
        /// <returns>returns saved component list</returns>
        public static List <Resource> SearchComponents(
            ISonarConfiguration conf,
            ISonarRestService rest,
            List <Resource> availableProjects,
            List <Resource> listofSaveComp,
            IVsEnvironmentHelper helper)
        {
            var savedList = new List <Resource>();

            foreach (var item in listofSaveComp)
            {
                savedList.Add(item);
            }


            try
            {
                var searchComponenetDialog = new SearchComponenetDialog(conf, rest, availableProjects, listofSaveComp, helper);
                searchComponenetDialog.ShowDialog();

                if (searchComponenetDialog.DialogResult == true)
                {
                    return(searchComponenetDialog.SelectedDataGrid.Items.OfType <Resource>().ToList());
                }
                else
                {
                    return(savedList);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ups Something wrong has happened. Please Report : " + ex.Message + " -> " + ex.StackTrace);
            }

            return(new List <Resource>());
        }
        /// <summary>
        /// Loads the plugin.
        /// </summary>
        /// <param name="assembly">The assembly.</param>
        /// <param name="manager">The manager.</param>
        /// <param name="helper">The helper.</param>
        /// <param name="vshelper">The vshelper.</param>
        /// <param name="userConfig">The user configuration.</param>
        /// <returns></returns>
        public IPlugin LoadPlugin(Assembly assembly, INotificationManager manager, IConfigurationHelper helper, IVsEnvironmentHelper vshelper, ISonarConfiguration userConfig)
        {
            var types2 = assembly.GetTypes();
            foreach (var type in types2)
            {
                Debug.WriteLine("Type In Assembly:" + type.FullName);

                try
                {
                    if (typeof(IAnalysisPlugin).IsAssignableFrom(type))
                    {
                        Debug.WriteLine("Can Cast Type In Assembly To: " + typeof(IAnalysisPlugin).FullName);
                        var obj = type.GetConstructor(new[] { typeof(INotificationManager), typeof(IConfigurationHelper), typeof(ISonarRestService), typeof(IVsEnvironmentHelper) });
                        if (obj != null)
                        {
                            object[] lobject = new object[] { manager, helper, new SonarRestService(new JsonSonarConnector()), vshelper };
                            return (IPlugin)obj.Invoke(lobject);
                        }
                        else
                        {
                            return (IPlugin)Activator.CreateInstance(type);
                        }
                    }

                    if (typeof(IMenuCommandPlugin).IsAssignableFrom(type))
                    {
                        Debug.WriteLine("Can Cast Type In Assembly To: " + typeof(IMenuCommandPlugin).FullName);
                        var obj = type.GetConstructor(new[] { typeof(ISonarRestService) });
                        if (obj != null)
                        {
                            object[] lobject = { new SonarRestService(new JsonSonarConnector()) };
                            return (IPlugin)obj.Invoke(lobject);
                        }
                    }

                    if (typeof(ISourceVersionPlugin).IsAssignableFrom(type))
                    {
                        Debug.WriteLine("Can Cast Type In Assembly To: " + typeof(ISourceVersionPlugin).FullName);
                        var obj = type.GetConstructor(new[] { typeof(INotificationManager) });
                        if (obj != null)
                        {
                            object[] lobject = { manager };
                            return (IPlugin)obj.Invoke(lobject);
                        }
                    }

                    if (typeof(IIssueTrackerPlugin).IsAssignableFrom(type))
                    {
                        Debug.WriteLine("Can Cast Type In Assembly To: " + typeof(IIssueTrackerPlugin).FullName);
                        var obj = type.GetConstructor(new[] { typeof(INotificationManager) });
                        if (obj != null)
                        {
                            object[] lobject = { manager };
                            return (IPlugin)obj.Invoke(lobject);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(
                        "Cannot Cast Type: " + ex.Message + "\r\n" + ex.StackTrace);
                    Debug.WriteLine(ex.InnerException.Message + " : " + ex.InnerException.StackTrace);
                }
            }

            return null;
        }
        public List<IPlugin> LoadPluginsFromPluginFolder(INotificationManager manager, IConfigurationHelper helper, IVsEnvironmentHelper vshelper, IEnumerable<string> files)
        {
            var folder = this.PluginsFolder;
            var pluginsData = new List<IPlugin>();

            var assemblies = new Dictionary<string, Assembly>();
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            var filesToUse = Directory.GetFiles(folder);

            if (files != null && files.Any())
            {
                filesToUse = files.ToArray();
            }

            foreach (var file in filesToUse)
            {
                if (file.EndsWith(".dll"))
                {
                    try
                    {
                        assemblies.Add(file, AppDomain.CurrentDomain.Load(File.ReadAllBytes(file)));
                    } catch (Exception ex) {
                        System.Diagnostics.Debug.WriteLine("CannotLoad: " + file + " : " +  ex.Message);
                    }
                }
            }

            foreach (var assembly in assemblies)
            {
                try
                {
                    var plugin = this.LoadPlugin(assembly.Value, manager, helper, vshelper, AuthtenticationHelper.AuthToken);

                    if (plugin != null)
                    {
                        var references = assembly.Value.GetReferencedAssemblies();

                        foreach (var assemblyref in references)
                        {
                            var fileName = assemblyref.Name + ".dll";
                            var file = Path.Combine(this.PluginsFolder, fileName);

                            if (File.Exists(file))
                            {
                                plugin.SetDllLocation(file);
                            }
                        }

                        plugin.SetDllLocation(assembly.Key);
                        pluginsData.Add(plugin);
                    }
                }
                catch (Exception ex)
                {
                    if (ex is System.Reflection.ReflectionTypeLoadException)
                    {
                        var typeLoadException = ex as ReflectionTypeLoadException;
                        var loaderExceptions = typeLoadException.LoaderExceptions;
                        foreach (var loadingException in loaderExceptions)
                        {
                            Debug.WriteLine(loadingException.Message);
                            Debug.WriteLine(loadingException.InnerException);
                        }

                    }

                    File.Delete(assembly.Key);
                }
            }

            return pluginsData;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ServerViewModel" /> class.
        /// </summary>
        /// <param name="vsenvironmenthelper">The vsenvironmenthelper.</param>
        /// <param name="configurationHelper">The configuration helper.</param>
        /// <param name="restservice">The restservice.</param>
        /// <param name="notificationManager">The notification manager.</param>
        /// <param name="translator">The translator.</param>
        public ServerViewModel(
            IVsEnvironmentHelper vsenvironmenthelper,
            IConfigurationHelper configurationHelper,
            ISonarRestService restservice,
            INotificationManager notificationManager,
            ISQKeyTranslator translator)
        {
            this.notificationMan = notificationManager;
            this.vsenvironmenthelper = vsenvironmenthelper;
            this.configurationHelper = configurationHelper;
            this.restservice = restservice;

            this.Header = "Server Analysis";
            this.AvailableActionPlans = new ObservableCollection<SonarActionPlan>();
            this.AlreadyOpenDiffs = new SortedSet<string>();
            this.IssuesGridView = new IssueGridViewModel(true, "ServerView", true, this.configurationHelper, this.restservice, this.notificationMan, translator);
            this.IssuesGridView.ShowLeftFlyoutEvent += this.ShowHideLeftFlyout;
            this.InitCommanding();

            this.ForeGroundColor = Colors.Black;
            this.BackGroundColor = Colors.White;
            this.SizeOfFlyout = 0;
            // register model
            AssociationModel.RegisterNewModelInPool(this);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ProjectDuplicationTrackerModel"/> class.
 /// </summary>
 public ProjectDuplicationTrackerModel()
 {
     this.UserIsLoggedIn = false;
     this.conf = new ConnectionConfiguration("http://localhost", "admin", "admin");
     this.vshelper = null;
     this.Login();
     this.IsIdle = true;
 }
        /// <summary>
        /// The update configuration.
        /// </summary>
        /// <param name="configuration">
        /// The configuration.
        /// </param>
        /// <param name="project">
        /// The project.
        /// </param>
        /// <param name="vsenvironmentHelper">
        /// The vs environment helper.
        /// </param>
        public void UpdateConfiguration(ISonarConfiguration configuration, Resource project, IVsEnvironmentHelper vsenvironmentHelper)
        {
            this.conf = configuration;
            if (this.conf != null)
            {
                this.Login();
            }

            this.SelectMainResource(project);
            this.vshelper = vsenvironmentHelper;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="OpenInSonarCommand"/> class.
 /// </summary>
 /// <param name="model">
 /// The model.
 /// </param>
 /// <param name="restService">
 /// The rest service.
 /// </param>
 /// <param name="vsenvironmenthelper">
 /// The vsenvironmenthelper.
 /// </param>
 public OpenInSonarCommand(ExtensionDataModel model, ISonarRestService restService, IVsEnvironmentHelper vsenvironmenthelper)
 {
     this.model = model;
     this.vsenvironmenthelper = vsenvironmenthelper;
     this.restService = restService;
 }
        /// <summary>
        /// The extension data viewModel update.
        /// </summary>
        /// <param name="vsenvironmenthelperIn">The vsenvironmenthelper in.</param>
        /// <param name="statusBar">The status bar.</param>
        /// <param name="provider">The provider.</param>
        /// <param name="extensionFolder">The extension Folder.</param>
        public void InitModelFromPackageInitialization(
            IVsEnvironmentHelper vsenvironmenthelperIn,
            IVSSStatusBar statusBar,
            IServiceProvider provider,
            string extensionFolder)
        {
            this.ServiceProvider = provider;
            this.VsHelper = vsenvironmenthelperIn;
            this.StatusBar = statusBar;
            this.ExtensionFolder = extensionFolder;

            // register notificaton manager, since all messages will be show also for initialization
            (this.notificationManager as IModelBase).UpdateServices(this.VsHelper, this.StatusBar, this.ServiceProvider);
            this.VSonarQubeOptionsViewData.InitPuginSystem(vsenvironmenthelperIn, this.pluginController, this.notificationManager);
            this.InitMenus();
            this.InitViewsAndModels();

            // start association module after all models are started
            this.AssociationModule = new AssociationModel(
                this.notificationManager,
                this.sonarRestConnector,
                this.configurationHelper,
                this.sonarKeyTranslator,
                this.VSonarQubeOptionsViewData.PluginManager,
                this);

            this.AssociationModule.UpdateServicesInModels(this.VsHelper, this.StatusBar, this.ServiceProvider);
            this.UpdateTheme(Colors.Black, Colors.White);

            // try to connect to start to sonar if on start is on
            if (this.VSonarQubeOptionsViewData.GeneralConfigurationViewModel.IsConnectAtStartOn)
            {
                this.OnConnectToSonar(false);
            }
        }
 /// <summary>
 /// Updates the services.
 /// </summary>
 /// <param name="vsenvironmenthelperIn">The vsenvironmenthelper in.</param>
 /// <param name="statusBar">The status bar.</param>
 /// <param name="provider">The provider.</param>
 public void UpdateServicesInModels(IVsEnvironmentHelper vsenvironmenthelperIn, IVSSStatusBar statusBar, IServiceProvider provider)
 {
     this.vshelper = vsenvironmenthelperIn;
     foreach (IModelBase model in modelPool)
     {
         model.UpdateServices(vsenvironmenthelperIn, statusBar, provider);
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ExtensionDataModel"/> class.
        /// </summary>
        /// <param name="restService">
        /// The rest Service.
        /// </param>
        /// <param name="vsenvironmenthelper">
        /// The vsenvironmenthelper.
        /// </param>
        /// <param name="associatedProj">
        /// The associated Proj.
        /// </param>
        public ExtensionDataModel(ISonarRestService restService, IVsEnvironmentHelper vsenvironmenthelper, Resource associatedProj)
        {
            this.RestService = restService;
            this.Vsenvironmenthelper = vsenvironmenthelper;

            // commands
            this.InitCommanding();
            this.UserTextControlsHeight = new GridLength(0);
            this.UserControlsHeight = new GridLength(0);
            this.RestoreUserSettingsInIssuesDataGrid();
            this.RestoreUserFilteringOptions();
            this.AnalysisTrigger = false;

            ConnectionConfiguration conf = this.UserConfiguration;
            if (conf == null)
            {
                return;
            }

            // start some data
            List<User> usortedList = restService.GetUserList(conf);
            if (usortedList != null && usortedList.Count > 0)
            {
                this.UsersList = new List<User>(usortedList.OrderBy(i => i.Login));
            }

            List<Resource> projects = restService.GetProjectsList(conf);
            if (projects != null && projects.Count > 0)
            {
                this.ProjectResources = new List<Resource>(projects.OrderBy(i => i.Name));
            }

            this.AssociatedProject = associatedProj;
            var plugins = this.PluginControl.GetPlugins();
            if (plugins != null)
            {
                this.ExtensionOptionsData = new ExtensionOptionsModel(this.PluginControl, this);
                this.LocalAnalyserModule = new SonarLocalAnalyser.SonarLocalAnalyser(new List<IPlugin>(plugins), this.RestService, this.vsenvironmenthelper);
                this.LocalAnalyserModule.StdOutEvent += this.UpdateOutputMessagesFromPlugin;
                this.LocalAnalyserModule.LocalAnalysisCompleted += this.UpdateLocalIssues;

                this.ExtensionOptionsData.Vsenvironmenthelper = this.Vsenvironmenthelper;
                this.ExtensionOptionsData.ResetUserData();

                foreach (var plugin in plugins)
                {
                    var configuration = ConnectionConfigurationHelpers.GetConnectionConfiguration(this.Vsenvironmenthelper);
                    var controloption = plugin.GetPluginControlOptions(configuration);
                    if (controloption == null)
                    {
                        continue;
                    }

                    var pluginKey = plugin.GetKey(ConnectionConfigurationHelpers.GetConnectionConfiguration(this.Vsenvironmenthelper));
                    var options = this.Vsenvironmenthelper.ReadAllAvailableOptionsInSettings(pluginKey);
                    controloption.SetOptions(options);
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AssociateCommand"/> class.
 /// </summary>
 /// <param name="model">
 /// The model.
 /// </param>
 /// <param name="vsenvironmenthelper">
 /// The vsenvironmenthelper.
 /// </param>
 public AssociateCommand(ExtensionDataModel model, IVsEnvironmentHelper vsenvironmenthelper)
 {
     this.model = model;
     this.vsenvironmenthelper = vsenvironmenthelper;
 }
        private void StartSolutionListeners(IVsEnvironmentHelper helper)
        {
            listener = new SolutionEventsListener(helper);
            var triedOnceAlready = false;

            listener.OnAfterOpenProject += () =>
            {
                if (!SonarQubeViewModelFactory.SQViewModel.AssociationModule.IsAssociated && !triedOnceAlready)
                {
                    triedOnceAlready = true;
                    string solutionName = this.visualStudioInterface.ActiveSolutionName();
                    string solutionPath = this.visualStudioInterface.ActiveSolutionPath();

                    SonarQubeViewModelFactory.SQViewModel.Logger.WriteMessage("Solution Opened: " + solutionName + " : " + solutionPath);
                    SonarQubeViewModelFactory.SQViewModel.AssociateProjectToSolution(solutionName, solutionPath);
                }
            };
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PluginsOptionsModel"/> class.
 /// </summary>
 /// <param name="vsenvironmenthelper">
 /// The vsenvironmenthelper.
 /// </param>
 public PluginsOptionsModel(IVsEnvironmentHelper vsenvironmenthelper)
 {
     this.ControlCommand = new UserSelectControl(this);
     this.Vsenvironmenthelper = vsenvironmenthelper;
 }
        /// <summary>
        /// The load plugin using dedicated domain.
        /// </summary>
        /// <param name="assemblies">
        /// The assemblies.
        /// </param>
        /// <param name="refAssemblies">
        /// The ref assemblies.
        /// </param>
        /// <param name="basePath">
        /// The base path.
        /// </param>
        /// <param name="conf">
        /// The conf.
        /// </param>
        /// <returns>
        /// The <see cref="PluginDescription"/>.
        /// </returns>
        public IPlugin LoadPlugin(
            string[] assemblies,
            string basePath,
            ISonarConfiguration conf,
            IConfigurationHelper helper,
            INotificationManager manager,
            IVsEnvironmentHelper vshelper)
        {
            try
            {
                var loader = PluginSandBoxLoader.Sandbox(AppDomain.CurrentDomain, assemblies, this.CurrentDomainAssemblyResolve);
                try
                {
                    var pluginDesc = loader.LoadPlugin(conf, helper, manager, vshelper);

                    foreach (string assembly in assemblies)
                    {
                        File.Delete(assembly);
                    }

                    return pluginDesc;
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null)
                    {
                        this.ErrorMessage = "Cannot Load Plugin: " + ex.InnerException.Message + " : " + ex.InnerException.StackTrace;
                    }
                    else
                    {
                        this.ErrorMessage = "Cannot Load Plugin: " + ex.Message + " : " + ex.StackTrace;
                    }

                    Debug.WriteLine(ex.Message + " " + ex.StackTrace);
                }
            }
            catch (Exception ex)
            {
                this.ErrorMessage = "Cannot Create Domain: " + ex.Message + " : " + ex.StackTrace;
            }

            return null;
        }
        /// <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);
        }
 /// <summary>
 /// Updates the services.
 /// </summary>
 /// <param name="vsenvironmenthelperIn">The vs environment helper in.</param>
 /// <param name="statusBar">The status bar.</param>
 /// <param name="provider">The provider.</param>
 public void UpdateServices(IVsEnvironmentHelper vsenvironmenthelperIn, IVSSStatusBar statusBar, IServiceProvider provider)
 {
     // does not access visual studio services
 }
        /// <summary>
        /// The init plugin list.
        /// </summary>
        /// <param name="visualStudioHelper">The visual studio helper.</param>
        /// <param name="files">The files.</param>
        /// <returns>true on ok</returns>
        private bool InitPluginList(IVsEnvironmentHelper visualStudioHelper, IEnumerable<string> files)
        {
            bool loaded = false;

            foreach (var plugin in this.controller.LoadPluginsFromPluginFolder(this.notificationManager, this.configurationHelper, visualStudioHelper, files))
            {
                var plugindata = plugin as IAnalysisPlugin;
                if (plugindata != null)
                {
                    this.AnalysisPlugins.Add(plugindata);
                    this.PluginList.Add(plugindata.GetPluginDescription());
                    this.plugins.Add(plugin);
                    loaded = true;
                    continue;
                }

                var pluginMenu = plugin as IMenuCommandPlugin;
                if (pluginMenu != null)
                {
                    this.MenuPlugins.Add(pluginMenu);
                    this.PluginList.Add(pluginMenu.GetPluginDescription());
                    this.plugins.Add(plugin);
                    loaded = true;
                    continue;
                }

                var pluginSourceControl = plugin as ISourceVersionPlugin;
                if (pluginSourceControl != null)
                {
                    this.SourceCodePlugins.Add(pluginSourceControl);
                    this.PluginList.Add(pluginSourceControl.GetPluginDescription());
                    this.plugins.Add(plugin);
                    loaded = true;
                    continue;
                }

                var pluginIssueTracker = plugin as IIssueTrackerPlugin;
                if (pluginIssueTracker != null)
                {
                    this.IssueTrackerPlugins.Add(pluginIssueTracker);
                    this.PluginList.Add(pluginIssueTracker.GetPluginDescription());
                    this.plugins.Add(plugin);
                    loaded = true;
                    continue;
                }
            }

            return loaded;
        }
        /// <summary>
        /// The init plugin system.
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="plugincontroller">The plugin controller.</param>
        /// <param name="manager">The manager.</param>
        public void InitPuginSystem(IVsEnvironmentHelper helper, PluginController plugincontroller, INotificationManager manager)
        {
            this.PluginManager = new PluginManagerModel(
                plugincontroller,
                this.configurationHelper,
                manager,
                helper);

            this.RoslynModel = new RoslynManagerModel(this.PluginManager.AnalysisPlugins, manager, this.configurationHelper, this.restService);
            this.RoslynViewModel = new RoslynManagerViewModel(this.RoslynModel);

            this.AvailableOptionsViews.Add(this.PluginManager);
            this.AvailableOptionsViews.Add(this.RoslynViewModel);

            this.AvailableOptionsModels.Add(this.PluginManager);
            this.AvailableOptionsModels.Add(this.RoslynModel);

            // sync checks to plugins
            this.RoslynModel.SyncDiagnosticsInPlugins();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ExtensionDataModel"/> class.
        /// </summary>
        /// <param name="restService">
        /// The rest Service.
        /// </param>
        /// <param name="vsenvironmenthelper">
        /// The vsenvironmenthelper.
        /// </param>
        /// <param name="associatedProj">
        /// The associated Proj.
        /// </param>
        public ExtensionDataModel(
            ISonarRestService restService, 
            IVsEnvironmentHelper vsenvironmenthelper, 
            Resource associatedProj)
        {
            this.RestService = restService;
            this.Vsenvironmenthelper = vsenvironmenthelper;

            // commands
            this.InitCommanding();

            // cache data
            this.cachedIssuesList = new Dictionary<string, List<Issue>>();
            this.cachedIssuesListObs = new List<string>();
            this.allSourceData = new Dictionary<string, Source>();
            this.allSourceCoverageData = new Dictionary<string, SourceCoverage>();
            this.allResourceData = new Dictionary<string, Resource>();

            // start some data
            var usortedList = restService.GetUserList(this.UserConfiguration);
            if (usortedList != null && usortedList.Count > 0)
            {
                this.UsersList = new List<User>(usortedList.OrderBy(i => i.Login));
            }

            var projects = restService.GetProjectsList(this.UserConfiguration);
            if (projects != null && projects.Count > 0)
            {
                this.ProjectResources = new List<Resource>(projects.OrderBy(i => i.Name));
            }

            this.AssociatedProject = associatedProj;

            this.UserTextControlsHeight = new GridLength(0);
            this.UserControlsHeight = new GridLength(0);
            this.IssuesFilterWidth = new GridLength(0);
            this.ServerAnalysis = AnalysesType.Off;

            this.RestoreUserSettingsInIssuesDataGrid();
            this.RestoreUserFilteringOptions();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ProjectDuplicationTrackerModel"/> class.
 /// </summary>
 /// <param name="conf">
 /// The conf.
 /// </param>
 /// <param name="vshelper">
 /// The vshelper.
 /// </param>
 public ProjectDuplicationTrackerModel(ISonarConfiguration conf, IVsEnvironmentHelper vshelper)
 {
     this.vshelper = vshelper;
     this.UserIsLoggedIn = false;
     this.conf = conf;
     this.Login();
     this.IsIdle = true;
 }
        /// <summary>
        /// The extension data model update.
        /// </summary>
        /// <param name="restServiceIn">
        /// The rest service in.
        /// </param>
        /// <param name="vsenvironmenthelperIn">
        /// The vsenvironmenthelper in.
        /// </param>
        /// <param name="associatedProj">
        /// The associated proj.
        /// </param>
        public void ExtensionDataModelUpdate(ISonarRestService restServiceIn, IVsEnvironmentHelper vsenvironmenthelperIn, Resource associatedProj)
        {
            this.RestService = restServiceIn;
            this.Vsenvironmenthelper = vsenvironmenthelperIn;

            this.InitCommanding();

            // start some data
            var usortedList = restServiceIn.GetUserList(this.UserConfiguration);
            if (usortedList != null)
            {
                this.UsersList = new List<User>(usortedList.OrderBy(i => i.Login));
                this.UsersList.Add(new User());
            }

            var projects = restServiceIn.GetProjectsList(this.UserConfiguration);
            if (projects != null)
            {
                this.ProjectResources = new List<Resource>(projects.OrderBy(i => i.Name));
            }

            this.AssociatedProject = associatedProj;

            this.UserTextControlsHeight = new GridLength(0);
            this.UserControlsHeight = new GridLength(0);
            this.CommentsWidth = new GridLength(0);

            this.RestoreUserSettingsInIssuesDataGrid();
            this.RestoreUserFilteringOptions();
        }
        public IPlugin IstallNewPlugin(string fileName, 
            ISonarConfiguration conf,
            IConfigurationHelper helper,
            INotificationManager manager,
            IVsEnvironmentHelper vshelper)
        {
            var assembliesInFile = this.UnzipFiles(fileName, this.TempInstallPathFolder);
            var assembliesToTempFolder = this.GetAssembliesInTempFolder();
            var plugin = this.LoadPlugin(
                assembliesInFile.ToArray(),
                this.TempInstallPathFolder,
                conf, helper, manager, vshelper);

            if (plugin != null)
            {
                Directory.Delete(this.TempInstallPathFolder, true);
                this.UnzipFiles(fileName, this.PluginsFolder);
            }

            foreach (string path in assembliesInFile)
            {
                var file = Path.GetFileName(path);
                plugin.SetDllLocation(Path.Combine(this.PluginsFolder, file));
            }

            return plugin;
        }
 /// <summary>
 /// Updates the services.
 /// </summary>
 /// <param name="vsenvironmenthelperIn">The vsenvironmenthelper in.</param>
 /// <param name="statusBar">The status bar.</param>
 /// <param name="provider">The provider.</param>
 public void UpdateServices(IVsEnvironmentHelper vsenvironmenthelperIn, IVSSStatusBar statusBar, IServiceProvider provider)
 {
     // menu not accessing services
 }
 public PluginDescription GetPluginDescription(IVsEnvironmentHelper vsinter)
 {
     throw new System.NotImplementedException();
 }
 /// <summary>
 /// The update services.
 /// </summary>
 /// <param name="vsenvironmenthelperIn">The vsenvironmenthelper in.</param>
 /// <param name="statusBarIn">The status bar in.</param>
 /// <param name="provider">The provider.</param>
 public void UpdateServices(
     IVsEnvironmentHelper vsenvironmenthelperIn,
     IVSSStatusBar statusBarIn,
     IServiceProvider provider)
 {
     this.vsenvironmenthelper = vsenvironmenthelperIn;
     this.statusBar = statusBarIn;
     this.serviceProvier = provider;
 }
 /// <summary>
 /// Updates the services.
 /// </summary>
 /// <param name="vsenvironmenthelperIn">The vsenvironmenthelper in.</param>
 /// <param name="statusBar">The status bar.</param>
 /// <param name="provider">The provider.</param>
 public void UpdateServices(IVsEnvironmentHelper vsenvironmenthelperIn, IVSSStatusBar statusBar, IServiceProvider provider)
 {
     this.visualStudioHelper = vsenvironmenthelperIn;
 }
 internal void UpdateServices(IVsEnvironmentHelper visualStudioHelper)
 {
     this.vshelper = visualStudioHelper;
 }
        public List <IPlugin> LoadPluginsFromPluginFolder(INotificationManager manager, IConfigurationHelper helper, IVsEnvironmentHelper vshelper, IEnumerable <string> files)
        {
            var folder      = this.PluginsFolder;
            var pluginsData = new List <IPlugin>();

            var assemblies = new Dictionary <string, Assembly>();

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            var filesToUse = Directory.GetFiles(folder);

            if (files != null && files.Any())
            {
                filesToUse = files.ToArray();
            }

            foreach (var file in filesToUse)
            {
                if (file.EndsWith(".dll"))
                {
                    try
                    {
                        assemblies.Add(file, AppDomain.CurrentDomain.Load(File.ReadAllBytes(file)));
                    } catch (Exception ex) {
                        System.Diagnostics.Debug.WriteLine("CannotLoad: " + file + " : " + ex.Message);
                    }
                }
            }

            foreach (var assembly in assemblies)
            {
                try
                {
                    var plugin = this.LoadPlugin(assembly.Value, manager, helper, vshelper);

                    if (plugin != null)
                    {
                        var references = assembly.Value.GetReferencedAssemblies();

                        foreach (var assemblyref in references)
                        {
                            var fileName = assemblyref.Name + ".dll";
                            var file     = Path.Combine(this.PluginsFolder, fileName);

                            if (File.Exists(file))
                            {
                                plugin.SetDllLocation(file);
                            }
                        }

                        plugin.SetDllLocation(assembly.Key);
                        pluginsData.Add(plugin);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    File.Delete(assembly.Key);
                }
            }

            return(pluginsData);
        }
 /// <summary>
 /// The init model.
 /// </summary>
 /// <param name="configuration">
 /// The configuration.
 /// </param>
 /// <param name="project">
 /// The project.
 /// </param>
 /// <param name="vshelper">
 /// The vshelper.
 /// </param>
 private void InitModel(ISonarConfiguration configuration, Resource project, IVsEnvironmentHelper vshelper)
 {
     if (this.model == null)
     {
         this.model = new ProjectDuplicationTrackerModel(configuration, vshelper);
         this.model.Login();
         this.model.SelectMainResource(project);
     }
 }
        public IPlugin LoadPlugin(Assembly assembly, INotificationManager manager, IConfigurationHelper helper, IVsEnvironmentHelper vshelper)
        {
            var types2 = assembly.GetTypes();

            foreach (var type in types2)
            {
                Debug.WriteLine("Type In Assembly:" + type.FullName);

                try
                {
                    if (typeof(IAnalysisPlugin).IsAssignableFrom(type))
                    {
                        Debug.WriteLine("Can Cast Type In Assembly To: " + typeof(IAnalysisPlugin).FullName);
                        var obj = type.GetConstructor(new[] { typeof(INotificationManager), typeof(IConfigurationHelper), typeof(ISonarRestService), typeof(IVsEnvironmentHelper) });
                        if (obj != null)
                        {
                            object[] lobject = new object[] { manager, helper, new SonarRestService(new JsonSonarConnector()), vshelper };
                            return((IPlugin)obj.Invoke(lobject));
                        }
                        else
                        {
                            return((IPlugin)Activator.CreateInstance(type));
                        }
                    }

                    if (typeof(IMenuCommandPlugin).IsAssignableFrom(type))
                    {
                        Debug.WriteLine("Can Cast Type In Assembly To: " + typeof(IMenuCommandPlugin).FullName);
                        var obj = type.GetConstructor(new[] { typeof(ISonarRestService) });
                        if (obj != null)
                        {
                            object[] lobject = { new SonarRestService(new JsonSonarConnector()) };
                            return((IPlugin)obj.Invoke(lobject));
                        }
                    }

                    if (typeof(ISourceVersionPlugin).IsAssignableFrom(type))
                    {
                        Debug.WriteLine("Can Cast Type In Assembly To: " + typeof(ISourceVersionPlugin).FullName);
                        var obj = type.GetConstructor(new[] { typeof(INotificationManager) });
                        if (obj != null)
                        {
                            object[] lobject = { manager };
                            return((IPlugin)obj.Invoke(lobject));
                        }
                    }

                    if (typeof(IIssueTrackerPlugin).IsAssignableFrom(type))
                    {
                        Debug.WriteLine("Can Cast Type In Assembly To: " + typeof(IIssueTrackerPlugin).FullName);
                        var obj = type.GetConstructor(new[] { typeof(INotificationManager) });
                        if (obj != null)
                        {
                            object[] lobject = { manager };
                            return((IPlugin)obj.Invoke(lobject));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(
                        "Cannot Cast Type: " + ex.Message + "\r\n" + ex.StackTrace);
                    Debug.WriteLine(ex.InnerException.Message + " : " + ex.InnerException.StackTrace);
                }
            }

            return(null);
        }
        public void TestAssociationWithSolution()
        {
            this.mocks = new MockRepository();
            this.service = this.mocks.Stub<ISonarRestService>();
            this.vshelper = this.mocks.Stub<IVsEnvironmentHelper>();
            var resource = new Resource { Key = "KEY" };
            var resources = new List<Resource> { resource };

            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.service.GetResourcesData(Arg<ISonarConfiguration>.Is.Anything, Arg<string>.Is.Equal("KEY"))).Return(resources);
                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");
                SetupResult.For(this.vshelper.ActiveSolutionName()).Return("Solution");
                SetupResult.For(this.vshelper.ReadOptionFromApplicationData("Solution", "PROJECTKEY")).Return("KEY");
            }

            var model = new ExtensionDataModel(this.service, this.vshelper, null, null);

            model.AssociateProjectToSolution();
            Assert.AreEqual("Selected Project: KEY", model.AssociatedProjectKey);
            model.AssociateProjectToSolution();
            Assert.AreEqual("Selected Project: KEY", model.AssociatedProjectKey);
        }