/// <summary>
        /// Adds the plugin.
        /// </summary>
        /// <param name="projectService">The project service.</param>
        /// <param name="plugin">The plugin.</param>
        /// <param name="folderName">Name of the folder.</param>
        /// <param name="extensionName">Name of the extension.</param>
        /// <returns>True or false.</returns>
        public bool AddPlugin(
            IProjectService projectService,
            Plugin plugin,
            string folderName,
            string extensionName)
        {
            TraceService.WriteLine("PluginService::AddPlugin " + plugin.FriendlyName);

            bool added = false;

            string projectPath = projectService.GetProjectPath();
            string source = plugin.Source;
            string destination = string.Format(@"{0}\Lib\{1}", projectPath, plugin.FileName);

            CodeConfig codeConfig = this.codeConfigService.GetCodeConfig(projectService, plugin.FriendlyName, false);

            //// we need to work out if the user has requested that the plugin is added from nuget
            //// and also if the plugin can be added from nuget - currently not all can!
            bool addPluginFromLocalDisk = this.codeConfigService.UseLocalDiskCopy(codeConfig);

            //// at this moment we only want ot do the core as this plugin might not be
            //// supported in the ui project.
            if (extensionName == Settings.Core ||
                extensionName == Settings.CoreTests)
            {
                added = this.AddCorePlugin(
                    projectService,
                    plugin,
                    codeConfig,
                    addPluginFromLocalDisk,
                    destination,
                    source);
            }
            else
            {
                //// now if we are not the core project we need to add the platform specific assemblies
                //// and the bootstrap item templates!

                string extensionSource = this.GetSourcePath(plugin, extensionName);

                string extensionDestination = this.GetPluginPath(extensionName, destination);

                if (this.fileSystem.File.Exists(extensionSource))
                {
                    //// if the plugin is supported add in the core library.

                    added = this.AddUIPlugin(
                        projectService,
                        plugin.FriendlyName,
                        source,
                        destination,
                        extensionSource,
                        extensionDestination,
                        addPluginFromLocalDisk);
                }
            }

            return added;
        }
Пример #2
0
 /// <summary>
 /// Adds the plugin.
 /// </summary>
 /// <param name="plugin">The plugin.</param>
 public void AddPlugin(Plugin plugin)
 {
     this.listView.Items.Add(new ListViewItem
     {
         Text = plugin.FriendlyName,
         ImageIndex = 0,
         Tag = plugin,
     });
 }
        /// <summary>
        /// Requests the bootstrap file.
        /// </summary>
        /// <param name="projectService">The project service.</param>
        /// <param name="plugin">The plugin.</param>
        internal void RequestBootstrapFile(
            IProjectService projectService,
            Plugin plugin)
        {
            TraceService.WriteLine("PluginService::RequestBootstrapFile plugin=" + plugin.FriendlyName);

            CodeConfig codeConfig = this.codeConfigFactory.GetPluginConfig(plugin);

            string bootstrapFileName = this.codeConfigService.GetBootstrapFileName(codeConfig, plugin.FriendlyName);

            //// check if the file already exists

            IProjectItemService projectItemService = projectService.GetProjectItem(bootstrapFileName);

            if (projectItemService == null)
            {
                //// get the currently requested plugins.
                string currentPlugins = this.settingsService.PluginsToAdd;

                string newPlugins = currentPlugins + "+" + bootstrapFileName;

                //// and now save the new requested plugins.
                this.settingsService.PluginsToAdd = newPlugins;

                TraceService.WriteLine("***plugins for" + projectService.Name + " " + newPlugins);
            }
        }
        /// <summary>
        /// Updates the plugin via nuget.
        /// </summary>
        /// <param name="projectService">The project service.</param>
        /// <param name="plugin">The plugin.</param>
        /// <returns>True if updated via nuget.</returns>
        internal string GetProjectNugetCommand(
            IProjectService projectService,
            Plugin plugin)
        {
            TraceService.WriteLine("PluginService::UpdateViaNuget plugin=" + plugin.FriendlyName);

            CodeConfig codeConfig = this.codeConfigFactory.GetPluginConfig(plugin);

            return this.codeConfigService.GetProjectNugetCommand(codeConfig, projectService);
        }
        /// <summary>
        /// Adds the core.
        /// </summary>
        /// <param name="projectService">The project service.</param>
        /// <param name="plugin">The plugin.</param>
        /// <param name="codeConfig">The code config.</param>
        /// <param name="addPluginFromLocalDisk">if set to <c>true</c> [add plugin from local disk].</param>
        /// <param name="destination">The destination.</param>
        /// <param name="source">The source.</param>
        /// <returns>True or false.</returns>
        internal bool AddCorePlugin(
            IProjectService projectService,
            Plugin plugin,
            CodeConfig codeConfig,
            bool addPluginFromLocalDisk,
            string destination,
            string source)
        {
            TraceService.WriteLine("PluginService::AddCorePlugin plugin=" + plugin.FriendlyName);

            //// inform the user that we cant install from nuget.
            if (this.codeConfigService.NugetRequestedAndNotSupported(codeConfig))
            {
                this.Messages.Add(
                    plugin.FriendlyName
                    + " plugin does not support being installed via Nuget and has been installed from the local machine.");
            }

            //// don't need to add reference if we are going to use nuget.
            if (addPluginFromLocalDisk)
            {
                //// only do if destination file doesn't exist
                if (this.fileSystem.File.Exists(destination) == false)
                {
                    projectService.AddReference(
                        "Lib",
                        destination,
                        source,
                        this.settingsService.IncludeLibFolderInProjects,
                        this.settingsService.CopyAssembliesToLibFolder);
                }
            }

            return true;
        }
        /// <summary>
        /// Adds the non core plugin.
        /// </summary>
        /// <param name="projectService">The project service.</param>
        /// <param name="plugin">The plugin.</param>
        /// <param name="source">The source.</param>
        /// <param name="destination">The destination.</param>
        /// <param name="extensionSource">The extension source.</param>
        /// <param name="extensionDestination">The extension destination.</param>
        /// <param name="addPluginFromLocalDisk">if set to <c>true</c> [add plugin from local disk].</param>
        /// <returns>
        /// True or false.
        /// </returns>
        public bool AddUIPlugin(
            IProjectService projectService,
            Plugin plugin,
            string source,
            string destination,
            string extensionSource,
            string extensionDestination,
            bool addPluginFromLocalDisk)
        {
            TraceService.WriteLine("PluginService::AddUIPlugin plugin=" + plugin.FriendlyName);

            bool added = false;

            string[] projectNameParts = projectService.Name.Split('.');

            //// we need to look for the ui specific config file,
            Plugin uiPlugin = new Plugin
                              {
                                  FriendlyName = plugin.FriendlyName + "." + projectNameParts[1]
                              };

            CodeConfig codeConfig = this.codeConfigFactory.GetPluginConfig(uiPlugin);

            this.codeConfigService.ProcessCodeConfig(
                projectService,
                codeConfig,
                extensionSource,
                extensionDestination);

            //// only do if destination file doesn't exist
            if (this.fileSystem.File.Exists(destination) == false)
            {
                if (addPluginFromLocalDisk)
                {
                    projectService.AddReference(
                        "Lib",
                        destination,
                        source,
                        this.settingsService.IncludeLibFolderInProjects,
                        this.settingsService.CopyAssembliesToLibFolder);
                }
            }

            //// only do if extensionDestination file doesn't exist
            if (this.fileSystem.File.Exists(extensionDestination) == false)
            {
                if (addPluginFromLocalDisk)
                {
                    projectService.AddReference(
                        "Lib",
                        extensionDestination,
                        extensionSource,
                        this.settingsService.IncludeLibFolderInProjects,
                        this.settingsService.CopyAssembliesToLibFolder);
                }

                added = true;

                this.RequestBootstrapFile(
                    projectService,
                    plugin);
            }

            return added;
        }
        /// <summary>
        /// Adds the project plugin.
        /// </summary>
        /// <param name="projectService">The project service.</param>
        /// <param name="folderName">Name of the folder.</param>
        /// <param name="extensionName">Name of the extension.</param>
        /// <param name="plugin">The plugin.</param>
        /// <returns>Returns true if plugin added.</returns>
        public bool AddProjectPlugin(
            IProjectService projectService,
            string folderName,
            string extensionName,
            Plugin plugin)
        {
            TraceService.WriteLine("PluginService::AddProjectPlugin folder=" + folderName);

            this.Messages.Clear();

            string message = string.Format("Ninja Coder is adding {0} plugin to {1} project.", plugin.FriendlyName, projectService.Name);
            projectService.WriteStatusBarMessage(message);

            bool added = this.AddPlugin(projectService, plugin, extensionName);

            if (added)
            {
                //// if we want to add via nuget then generate the command.
                if (this.settingsService.UseNugetForPlugins)
                {
                    string command = this.GetProjectNugetCommand(projectService, plugin);

                    if (string.IsNullOrEmpty(command) == false)
                    {
                        if (this.settingsService.UsePreReleaseNugetPackages)
                        {
                            command += " " + NugetConstants.UsePreReleaseOption;
                        }

                        plugin.NugetCommands.Add(command);
                    }
                }

                this.Messages.Add(plugin.FriendlyName + " plugin added to project " + projectService.Name + ".");
            }

            return added;
        }
        public void TestGetSourcePathUserPlugin()
        {
            SettingsService settingsService = new SettingsService();

            Plugin plugin = new Plugin
            {
                Source = settingsService.MvvmCrossAssembliesPath + @"\Cirrious.MvvmCross.Plugins.Accelerometer.dll",
                FileName = @"\Cirrious.MvvmCross.Plugins.Accelerometer.dll"
            };

            this.mockSettingsService.SetupGet(x => x.MvvmCrossAssembliesOverrideDirectory)
                .Returns(settingsService.MvvmCrossAssembliesOverrideDirectory);

            this.mockFileInfo.FileName = "adrian.wpf";

            this.mockFileInfo.FileExists = true;

            string path = this.service.GetSourcePath(plugin, "wpf");

            Assert.IsTrue(path == @"adrian.wpf");
        }
Пример #9
0
 /// <summary>
 /// Adds the plugin.
 /// </summary>
 /// <param name="plugin">The plugin.</param>
 public void AddPlugin(Plugin plugin)
 {
     this.mvxListView1.AddPlugin(plugin);
 }
        /// <summary>
        /// Gets the source path.
        /// </summary>
        /// <param name="plugin">The plugin.</param>
        /// <param name="extensionName">Name of the extension.</param>
        /// <returns>The plugin path.</returns>
        internal string GetSourcePath(
            Plugin plugin, 
            string extensionName)
        {
            //// here we are look to see if the user has overridden the file in their own directory.

            string userDirectory = this.settingsService.MvvmCrossAssembliesOverrideDirectory;

            string userFilePath = this.GetPluginPath(extensionName, userDirectory + "\\" + plugin.FileName);

            FileInfoBase userFileInfoBase = this.fileSystem.FileInfo.FromFileName(userFilePath);

            string coreDirectory = this.settingsService.MvvmCrossAssembliesPath;

            FileInfoBase coreFileInfoBase = this.fileSystem.FileInfo.FromFileName(coreDirectory + "\\" + plugin.FileName);

            return userFileInfoBase.Exists ?
                userFileInfoBase.FullName :
                this.GetPluginPath(extensionName, coreFileInfoBase.FullName);
        }
        public void TestGetPluginConfig()
        {
            Plugin plugin = new Plugin { FriendlyName = "File" };

            MockFile mockFile = new MockFile();
            this.mockFileSystem.SetupGet(x => x.File).Returns(mockFile);

            SettingsService settingsService = new SettingsService();

            this.mockSettingsService.SetupGet(x => x.PluginsConfigPath).Returns(settingsService.PluginsConfigPath);
            this.mockSettingsService.SetupGet(x => x.UserCodeConfigPluginsPath).Returns(settingsService.UserCodeConfigPluginsPath);

            this.mockTranslator.Setup(x => x.Translate(It.IsAny<string>())).Returns(new CodeConfig());

            this.factory.GetPluginConfig(plugin);

            this.mockTranslator.Verify(x => x.Translate(It.IsAny<string>()));
        }
        /// <summary>
        /// Gets the plugin test snippet.
        /// </summary>
        /// <param name="plugin">The plugin.</param>
        /// <returns>The code snippet.</returns>
        public CodeSnippet GetPluginTestSnippet(Plugin plugin)
        {
            TraceService.WriteLine("CodeSnippetFactory::GetPluginTestSnippet pluign=" + plugin);

            string fileName = string.Format(@"Plugins.{0}.Tests.xml", plugin.FriendlyName);

            CodeSnippet codeSnippet = this.GetSnippet(
                this.settingsService.PluginsCodeSnippetsPath,
                this.settingsService.UserCodeSnippetsPluginsPath,
                fileName);

            this.BuildTestingSnippet(codeSnippet);

            return codeSnippet;
        }
        /// <summary>
        /// Gets the plugin snippet.
        /// </summary>
        /// <param name="plugin">The plugin.</param>
        /// <returns>
        /// The code snippet.
        /// </returns>
        public CodeSnippet GetPluginSnippet(Plugin plugin)
        {
            TraceService.WriteLine("CodeSnippetFactory::GetPluginSnippet plugin=" + plugin.FriendlyName);

            string fileName = string.Format(@"Plugins.{0}.xml", plugin.FriendlyName);

            return this.GetSnippet(
                this.settingsService.PluginsCodeSnippetsPath,
                this.settingsService.UserCodeSnippetsPluginsPath,
                fileName);
        }
        public void TestAddPluginToCore()
        {
            //// arrange

            Plugin plugin = new Plugin();
            Mock<IProjectService> mockProjectService = new Mock<IProjectService>();

            Mock<Project> mockProject = new Mock<Project>();
            mockProjectService.SetupGet(x => x.Project).Returns(mockProject.Object);

            //// act
            this.service.AddPlugin(
               mockProjectService.Object,
               plugin,
               string.Empty,
               Settings.Core);

            //// assert
            mockProjectService.Verify(x => x.AddReference(
                It.IsAny<string>(),
                It.IsAny<string>(),
                It.IsAny<string>(),
                It.IsAny<bool>()));
        }
        /// <summary>
        /// Adds the plugin.
        /// </summary>
        /// <param name="plugin">The plugin.</param>
        /// <param name="project">The project.</param>
        /// <param name="folderName">Name of the folder.</param>
        /// <param name="extensionName">Name of the extension.</param>
        internal void AddPlugin(
            Plugin plugin,
            Project project, 
            string folderName, 
            string extensionName)
        {
            string projectPath = project.GetProjectPath();
            string source = plugin.Source;
            string destination = string.Format(@"{0}\Lib\{1}", projectPath, plugin.FileName);

            //// at this moment we only want ot do the core as this plugin might not be
            //// supported in the ui project.
            if (extensionName == "Core")
            {
                this.AddReference(project, destination, source);
            }
            else
            {
                //// now if we are not the core project we need to add the platform specific assemblies
                //// and the bootstrap item templates!

                string extensionSource = this.GetExtensionSource(folderName, extensionName, source);

                string extensionDestination = this.GetExtensionDestination(folderName, extensionName, destination);

                if (File.Exists(extensionSource))
                {
                    //// if the plugin is supported add in the core library.

                    //// only do if destination file doesnt exist
                    if (File.Exists(destination) == false)
                    {
                        this.AddReference(project, destination, source);
                    }

                    //// only do if extensionDestination file doesnt exist
                    if (File.Exists(extensionDestination) == false)
                    {
                        this.AddReference(project, extensionDestination, extensionSource);
                        this.BuildSourceFile(project, extensionSource, extensionDestination, plugin.FriendlyName);
                    }
                }
            }
        }
        public void TestAddPluginToNonCore()
        {
            //// arrange

            Plugin plugin = new Plugin { Source = "Here I am" };

            Mock<IProjectService> mockProjectService = new Mock<IProjectService>();

            Mock<Project> mockProject = new Mock<Project>();
            mockProjectService.SetupGet(x => x.Project).Returns(mockProject.Object);

            this.mockFile.FileExists = true;

            //// act
            this.service.AddPlugin(
               mockProjectService.Object,
               plugin,
               "Test.Droid",
               Settings.Droid);

            //// assert
            mockProjectService.Verify(
                x => x.AddReference(
                It.IsAny<string>(),
                It.IsAny<string>(),
                It.IsAny<string>(),
                It.IsAny<bool>()),
                Times.Never());
        }
        /// <summary>
        /// Gets the plugin config.
        /// </summary>
        /// <param name="plugin">The plugin.</param>
        /// <returns>The code config.</returns>
        public CodeConfig GetPluginConfig(Plugin plugin)
        {
            TraceService.WriteLine("CodeConfigFactory::GetPluginConfig plugin=" + plugin.FriendlyName);

            string fileName = string.Format(@"Config.Plugin.{0}.xml", plugin.FriendlyName);

            return this.GetConfig(
                this.settingsService.PluginsConfigPath,
                this.settingsService.UserCodeConfigPluginsPath,
                fileName);
        }
        public void TestGetPluginTestSnippet()
        {
            Plugin plugin = new Plugin();

            MockFile mockFile = new MockFile { FileExists = true };
            this.mockFileSystem.SetupGet(x => x.File).Returns(mockFile);

            SettingsService settingsService = new SettingsService();

            this.mockSettingsService.SetupGet(x => x.PluginsCodeSnippetsPath).Returns(settingsService.PluginsCodeSnippetsPath);
            this.mockSettingsService.SetupGet(x => x.UserCodeSnippetsPluginsPath).Returns(settingsService.UserCodeSnippetsPluginsPath);

            this.mockTranslator.Setup(x => x.Translate(It.IsAny<string>())).Returns(new CodeSnippet());

            this.factory.GetPluginTestSnippet(plugin);

            this.mockTranslator.Verify(x => x.Translate(It.IsAny<string>()));
        }
        public void TestGetSourcePath()
        {
            SettingsService settingsService = new SettingsService();

            Plugin plugin = new Plugin
                                {
                                    Source = settingsService.MvvmCrossAssembliesPath + @"\Cirrious.MvvmCross.Plugins.Accelerometer.dll",
                                    FileName = @"\Cirrious.MvvmCross.Plugins.Accelerometer.dll"
                                };

            this.mockSettingsService.SetupGet(x => x.MvvmCrossAssembliesOverrideDirectory)
                .Returns(settingsService.MvvmCrossAssembliesOverrideDirectory);

            this.mockFileInfo.FileExists = false;

            string path = this.service.GetSourcePath(plugin, "wpf");

            Assert.IsTrue(path == @"C:\Program Files (x86)\Scorchio Limited\Ninja Coder for MvvmCross\MvvmCross\Assemblies\\Cirrious.MvvmCross.Plugins.Accelerometer.wpf.dll");
        }