/// <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;
        }
        /// <summary>
        ///     The test window.
        /// </summary>
        public void TestWindow()
        {
            var mocks = new MockRepository();
            var mockHttpReq = mocks.Stub<IHttpSonarConnector>();
            var mockVsHelpers = mocks.Stub<IVsEnvironmentHelper>();
            var config = new ConnectionConfiguration("serveraddr", "login", "password");

            // set expectations
            using (mocks.Record())
            {
                SetupResult.For(mockHttpReq.HttpSonarGetRequest(config, "/api/issues/search?components=resource"))
                    .Return(File.ReadAllText("TestData/issuessearchbycomponent.txt"));
                SetupResult.For(mockHttpReq.HttpSonarGetRequest(config, "/api/users/search")).Return(File.ReadAllText("TestData/userList.txt"));
            }

            ISonarRestService service = new SonarRestService(mockHttpReq);
            var issues = service.GetIssuesInResource(config, "resource");
            var associatedProject = new Resource { Key = "core:Common" };

            this.model = new ExtensionDataModel(service, mockVsHelpers, associatedProject);
            var t = new Thread(this.Threadprc);
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            t.Join();
        }
        public void RunsLocalAnalysisWithDummyFile()
        {
            var serviceStub = new Mock<IAnalysisPlugin>();
            var optionsStub = new Mock<IPluginsOptions>();
            var resource = new Resource() { Lang = "c++" };
            var configuration = new ConnectionConfiguration();
            serviceStub.Setup(control => control.GetPluginControlOptions(configuration)).Returns(optionsStub.Object);
            optionsStub.Setup(control => control.GetOptions()).Returns(this.options);

            var localextension = new CxxLocalExtension(serviceStub.Object, configuration);
            localextension.LocalAnalysisCompleted += this.AnalysisCompleted;
            var vsitem = new VsProjectItem(string.Empty, this.fileToAnalyse, string.Empty, string.Empty, string.Empty, string.Empty);
            var thread = localextension.GetFileAnalyserThread(vsitem, resource, new Profile(), string.Empty, false);
            thread.Start();
            thread.Join();
        }
        /// <summary>
        /// The get plugin to run resource.
        /// </summary>
        /// <param name="configuration">
        /// The configuration.
        /// </param>
        /// <param name="project">
        /// The project.
        /// </param>
        /// <returns>
        /// The <see cref="IPlugin"/>.
        /// </returns>
        public IPlugin GetPluginToRunResource(ConnectionConfiguration configuration, Resource project)
        {
            if (this.loadedPlugins == null)
            {
                return null;
            }

            var pluginsToUse = this.loadedPlugins.Where(plugin => plugin.IsSupported(configuration, project)).ToList();

            return this.PickPluginFromMultipleSupportedPlugins(new ReadOnlyCollection<IPlugin>(pluginsToUse));
        }
        /// <summary>
        /// The get menu command plugin to run command.
        /// </summary>
        /// <param name="configuration">
        /// The configuration.
        /// </param>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <returns>
        /// The <see cref="IMenuCommandPlugin"/>.
        /// </returns>
        public IMenuCommandPlugin GetMenuCommandPluginToRunCommand(ConnectionConfiguration configuration, string key)
        {
            if (this.menuCommandPlugins == null)
            {
                return null;
            }

            return (from plugin in this.menuPlugins where plugin.Value.GetHeader().Equals(key) select plugin.Value).FirstOrDefault();
        }
        /// <summary>
        /// The button test connection click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void ButtonTestConnectionClick(object sender, EventArgs e)
        {
            try
            {
                var userConf = new ConnectionConfiguration(this.textBoxSonarHost.Text, this.textBoxUserName.Text, this.textBoxPassword.Text);
                ISonarRestService restService = new SonarRestService(new JsonSonarConnector());
                var versionDouble = restService.GetServerInfo(userConf);

                if (versionDouble < 3.3)
                {
                    MessageBox.Show("Authentication Ok");
                    return;
                }

                MessageBox.Show(restService.AuthenticateUser(userConf)
                                                         ? "Authentication Ok"
                                                         : "Authentication Failed, Check Host/Password/User");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Cannot Authenticate" + ex.StackTrace + " Messsage: " + ex.Message);
            }
        }
 /// <summary>
 /// The is supported.
 /// </summary>
 /// <param name="configuration">
 /// The configuration.
 /// </param>
 /// <param name="project">
 /// The project.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 public bool IsSupported(ConnectionConfiguration configuration, Resource project)
 {
     return true;
 }
 /// <summary>
 /// The get plugin control options.
 /// </summary>
 /// <param name="configuration">
 /// The configuration.
 /// </param>
 /// <param name="project">
 /// The project.
 /// </param>
 /// <returns>
 /// The <see cref="IPluginsOptions"/>.
 /// </returns>
 public IPluginsOptions GetPluginControlOptions(ConnectionConfiguration configuration, Resource project)
 {
     return null;
 }
 public IPluginsOptions GetPluginControlOptions(ConnectionConfiguration configuration)
 {
     throw new System.NotImplementedException();
 }
 /// <summary>
 /// The get local analysis extension.
 /// </summary>
 /// <param name="configuration">
 /// The configuration.
 /// </param>
 /// <param name="project">
 /// The project.
 /// </param>
 /// <param name="sonarVersion">
 /// The sonar version.
 /// </param>
 /// <returns>
 /// The <see cref="ILocalAnalyserExtension"/>.
 /// </returns>
 public ILocalAnalyserExtension GetLocalAnalysisExtension(ConnectionConfiguration configuration, Resource project, double sonarVersion)
 {
     return null;
 }
 public ILocalAnalyserExtension GetLocalAnalysisExtension(ConnectionConfiguration configuration, Resource project)
 {
     throw new System.NotImplementedException();
 }
 /// <summary>
 /// The get licenses.
 /// </summary>
 /// <param name="configuration">
 /// The configuration.
 /// </param>
 /// <returns>
 /// The <see>
 ///         <cref>Dictionary</cref>
 ///     </see>
 ///     .
 /// </returns>
 public Dictionary<string, VsLicense> GetLicenses(ConnectionConfiguration configuration)
 {
     return null;
 }
 /// <summary>
 /// The get key.
 /// </summary>
 /// <param name="configuration">
 /// The configuration.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 public string GetKey(ConnectionConfiguration configuration)
 {
     return string.Empty;
 }
 /// <summary>
 /// The generate token id.
 /// </summary>
 /// <param name="configuration">
 /// The configuration.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 public string GenerateTokenId(ConnectionConfiguration configuration)
 {
     return string.Empty;
 }
 public void SetUserConfiguration(ConnectionConfiguration configuration)
 {
     throw new NotImplementedException();
 }
 public Dictionary<string, VsLicense> GetLicenses(ConnectionConfiguration configuration)
 {
     throw new NotImplementedException();
 }