/// <summary>
        /// Projects the item added.
        /// </summary>
        /// <param name="projectItemService">The project item service.</param>
        internal void ProjectItemAdded(IProjectItemService projectItemService)
        {
            TraceService.WriteLine("BaseController::ProjectItemAdded");

            bool saveFile = false;

            if (projectItemService.IsCSharpFile())
            {
                if (this.SettingsService.RemoveDefaultComments)
                {
                    projectItemService.RemoveComments();
                    saveFile = true;
                }

                if (this.SettingsService.RemoveDefaultFileHeaders)
                {
                    projectItemService.RemoveHeader();
                    saveFile = true;
                }
            }

            if (saveFile)
            {
                this.VisualStudioService.DTEService.SaveAll();
            }
        }
示例#2
0
        #pragma warning restore 67

        public OpenTestFile(
            IProjectItemService projectItemService,
            ITestFileNameEvaluator testFileNameEvaluator)
        {
            _projectItemService    = projectItemService;
            _testFileNameEvaluator = testFileNameEvaluator;
        }
        /// <summary>
        /// Applies the code snippet.
        /// </summary>
        /// <param name="visualStudioService">The visual studio service.</param>
        /// <param name="codeSnippet">The code snippet.</param>
        /// <returns>The messages.</returns>
        internal IEnumerable <string> ApplyCodeSnippet(
            IVisualStudioService visualStudioService,
            CodeSnippet codeSnippet)
        {
            TraceService.WriteLine("CodeConfigService::ApplyCodeSnippet");

            List <string> messages = new List <string>();

            //// find the project
            IProjectService projectService = visualStudioService.GetProjectServiceBySuffix(codeSnippet.Project);

            //// find the class
            IProjectItemService projectItemService = projectService?.GetProjectItem(codeSnippet.Class + ".cs");

            //// find the method.
            CodeFunction codeFunction = projectItemService?.GetFirstClass().GetFunction(codeSnippet.Method);

            string code = codeFunction?.GetCode();

            if (code?.Contains(codeSnippet.Code.Trim()) == false)
            {
                codeFunction.InsertCode(codeSnippet.Code, true);

                string message = string.Format(
                    "Code added to project {0} class {1} method {2}.",
                    projectService.Name,
                    codeSnippet.Class,
                    codeSnippet.Method);

                messages.Add(message);
            }

            return(messages);
        }
        public DocumentMetadataManager(
            ICollectionViewGenerator collectionViewGenerator,
            IDocumentMetadataEqualityService metadataEqualityService,
            IDocumentMetadataFactory documentMetadataFactory,
            INormalizedUsageOrderService normalizedUsageOrderService,
            IProjectItemService projectItemService,
            ITimeProvider timeProvider,
            IUpdateReactionManager updateReactionManager,
            IUserPreferences userPreferences)
        {
            _activeDocumentMetadata  = new ObservableCollection <DocumentMetadata>();
            _collectionViewGenerator = collectionViewGenerator;

            ActiveDocumentMetadata = InitializeActiveDocumentMetadata();
            PinnedDocumentMetadata = InitializePinnedDocumentMetadata();

            _metadataEqualityService     = metadataEqualityService;
            _documentMetadataFactory     = documentMetadataFactory;
            _normalizedUsageOrderService = normalizedUsageOrderService;
            _projectItemService          = projectItemService;
            _timeProvider    = timeProvider;
            _userPreferences = userPreferences;

            updateReactionManager.Initialize(ActiveDocumentMetadata);
        }
        /// <summary>
        /// Updates the test method attribute.
        /// </summary>
        /// <param name="projectItemService">The project item service.</param>
        public void UpdateTestMethodAttribute(IProjectItemService projectItemService)
        {
            TraceService.WriteLine("MsTestTestingService::UpdateTestMethodAttribute");

            projectItemService.ReplaceText(
                TestingConstants.NUnit.MethodAttribute,
                TestingConstants.MsTest.MethodAttribute);
        }
        /// </summary>
        /// <param name="projectItemService">The project item service.</param>
        public void UpdateTestClassAttribute(IProjectItemService projectItemService)
        {
            TraceService.WriteLine("XUnitTestingService::UpdateTestClassAttribute");

            projectItemService.ReplaceText(
                TestingConstants.NUnit.ClassAttribute,
                TestingConstants.XUnit.ClassAttribute);
        }

        /// <summary>
        /// <summary>
        /// Updates the test method attribute.
        /// </summary>
        /// <param name="projectItemService">The project item service.</param>
        public void UpdateTestMethodAttribute(IProjectItemService projectItemService)
        {
            TraceService.WriteLine("MsTestTestingService::UpdateTestMethodAttribute");

            projectItemService.ReplaceText(
                TestingConstants.NUnit.MethodAttribute,
                TestingConstants.MsTest.MethodAttribute);
        }
示例#8
0
        /// <summary>
        /// Updates the test method attribute.
        /// </summary>
        /// <param name="projectItemService">The project item service.</param>
        public void UpdateTestMethodAttribute(IProjectItemService projectItemService)
        {
            TraceService.WriteLine("NUnitTestingService::UpdateTestMethodAttribute");

            //// Currently we dont do anything as the snippets
            //// are written in nunit format - this may change at some point
            //// in the future.
        }
示例#9
0
        /// <summary>
        /// Updates the test class attribute.
        /// </summary>
        /// <param name="projectItemService">The project item service.</param>
        public void UpdateTestClassAttribute(IProjectItemService projectItemService)
        {
            TraceService.WriteLine("XUnitTestingService::UpdateTestClassAttribute");

            projectItemService.ReplaceText(
                TestingConstants.NUnit.ClassAttribute,
                TestingConstants.XUnit.ClassAttribute);
        }
        /// <summary>
        /// Updates the test method attribute.
        /// </summary>
        /// <param name="projectItemService">The project item service.</param>
        public void UpdateTestMethodAttribute(IProjectItemService projectItemService)
        {
            TraceService.WriteLine("NUnitTestingService::UpdateTestMethodAttribute");

            //// Currently we dont do anything as the snippets
            //// are written in nunit format - this may change at some point
            //// in the future.
        }
 /// <summary>
 /// Updates the property.
 /// </summary>
 /// <param name="fileOperation">The file operation.</param>
 /// <param name="projectItemService">The project item service.</param>
 private void UpdateProperty(
     FileOperation fileOperation,
     IProjectItemService projectItemService)
 {
     if (projectItemService.ProjectItem != null)
     {
         projectItemService.ProjectItem.Properties.Item(fileOperation.From).Value = fileOperation.To;
         TraceService.WriteDebugLine("**Properties Updates**");
     }
 }
示例#12
0
        /// <summary>
        /// Fixes the information p list.
        /// </summary>
        /// <param name="projectTemplateInfo">The project template information.</param>
        public void FixInfoPList(ProjectTemplateInfo projectTemplateInfo)
        {
            TraceService.WriteLine("ApplicationService::FixInfoPlist");

            IProjectService iosProjectService = this.visualStudioService.iOSProjectService;

            if (iosProjectService != null)
            {
                if (projectTemplateInfo != null)
                {
                    IProjectItemService projectItemService = iosProjectService.GetProjectItem("Info.plist");

                    if (projectItemService != null)
                    {
                        XDocument doc = XDocument.Load(projectItemService.FileName);

                        if (doc.Root != null)
                        {
                            XElement element = doc.Root.Element("dict");

                            if (element != null)
                            {
                                //// first look for the elements

                                XElement childElement = element.Elements("key").FirstOrDefault(x => x.Value == "CFBundleDisplayName");

                                if (childElement == null)
                                {
                                    element.Add(new XElement("key", "CFBundleDisplayName"));
                                    element.Add(new XElement("string", iosProjectService.Name));
                                }

                                childElement = element.Elements("key").FirstOrDefault(x => x.Value == "CFBundleVersion");

                                if (childElement == null)
                                {
                                    element.Add(new XElement("key", "CFBundleVersion"));
                                    element.Add(new XElement("string", "1.0"));
                                }

                                childElement = element.Elements("key").FirstOrDefault(x => x.Value == "CFBundleIdentifier");

                                if (childElement == null)
                                {
                                    element.Add(new XElement("key", "CFBundleIdentifier"));
                                    element.Add(new XElement("string", "1"));
                                }
                            }

                            doc.Save(projectItemService.FileName);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Updates the file.
        /// </summary>
        /// <param name="projectItemService">The project item service.</param>
        /// <param name="replacementVariables">The replacement variables.</param>
        public void UpdateFile(
            IProjectItemService projectItemService,
            IEnumerable<KeyValuePair<string, string>> replacementVariables)
        {
            TraceService.WriteLine("BaseTestingService::UpdateFile");

            foreach (KeyValuePair<string, string> replacementVariable in replacementVariables)
            {
                projectItemService.ReplaceText(replacementVariable.Key, replacementVariable.Value);
            }
        }
示例#14
0
        #pragma warning restore 67

        public ActivateWindow(
            DTE2 dte2,
            IDocumentMetadataEqualityService metadataEqualityService,
            IDocumentMetadataManager documentMetadataManager,
            IProjectItemService projectItemService)
        {
            _dte2 = dte2;
            _metadataEqualityService = metadataEqualityService;
            _documentMetadataManager = documentMetadataManager;
            _projectItemService      = projectItemService;
        }
示例#15
0
        /// <summary>
        /// Updates the file.
        /// </summary>
        /// <param name="projectItemService">The project item service.</param>
        /// <param name="replacementVariables">The replacement variables.</param>
        public void UpdateFile(
            IProjectItemService projectItemService,
            IEnumerable <KeyValuePair <string, string> > replacementVariables)
        {
            TraceService.WriteLine("BaseTestingService::UpdateFile");

            foreach (KeyValuePair <string, string> replacementVariable in replacementVariables)
            {
                TraceService.WriteLine("Key=" + replacementVariable.Key + " Value=" + replacementVariable.Value);

                projectItemService.ReplaceText(replacementVariable.Key, replacementVariable.Value);
            }
        }
        private static ActivateWindow CreateActivateWindow(
            DTE2 dte2 = null,
            IDocumentMetadataManager documentMetadataManager = null,
            IProjectItemService projectItemService           = null)
        {
            var command = new ActivateWindow(
                dte2 ?? Mock.Of <DTE2>(),
                new DocumentMetadataEqualityService(),
                documentMetadataManager ?? Mock.Of <IDocumentMetadataManager>(),
                projectItemService ?? Mock.Of <IProjectItemService>());

            return(command);
        }
示例#17
0
        /// <summary>
        /// Adds the plugins.
        /// </summary>
        /// <param name="visualStudioService">The visual studio service.</param>
        /// <param name="plugins">The plugins.</param>
        /// <param name="viewModelName">Name of the view model.</param>
        /// <param name="createUnitTests">if set to <c>true</c> [create unit tests].</param>
        /// <returns>
        /// The messages.
        /// </returns>
        public IEnumerable <string> AddPlugins(
            IVisualStudioService visualStudioService,
            IEnumerable <Plugin> plugins,
            string viewModelName,
            bool createUnitTests)
        {
            TraceService.WriteLine("PluginsService::AddPlugins viewModelName=" + viewModelName);

            IProjectService coreProjectService = visualStudioService.CoreProjectService;

            Plugin[] enumerablePlugins = plugins as Plugin[] ?? plugins.ToArray();

            this.AddProjectPlugins(coreProjectService, enumerablePlugins, Settings.Core, Settings.Core);
            this.AddProjectPlugins(visualStudioService.DroidProjectService, enumerablePlugins, Settings.Droid, Settings.Droid);
            this.AddProjectPlugins(visualStudioService.iOSProjectService, enumerablePlugins, Settings.iOS, "Touch");
            this.AddProjectPlugins(visualStudioService.WindowsPhoneProjectService, enumerablePlugins, Settings.WindowsPhone, Settings.WindowsPhone);
            this.AddProjectPlugins(visualStudioService.WindowsStoreProjectService, enumerablePlugins, Settings.WindowsStore, Settings.WindowsStore);
            this.AddProjectPlugins(visualStudioService.WpfProjectService, enumerablePlugins, Settings.Wpf, Settings.Wpf);

            if (string.IsNullOrEmpty(viewModelName) == false)
            {
                IProjectItemService testProjectItemService = null;
                IProjectItemService projectItemService     = coreProjectService.GetProjectItem(viewModelName);

                if (projectItemService.ProjectItem != null)
                {
                    foreach (Plugin plugin in enumerablePlugins)
                    {
                        testProjectItemService = this.CreateSnippet(
                            visualStudioService,
                            viewModelName,
                            this.settingsService.CodeSnippetsPath + @"\Plugins",
                            createUnitTests,
                            coreProjectService,
                            projectItemService,
                            plugin);
                    }

                    projectItemService.ProjectItem.FixUsingStatements();

                    //// also only do once for the unit test file.
                    if (createUnitTests && testProjectItemService != null)
                    {
                        testProjectItemService.ProjectItem.FixUsingStatements();
                    }
                }
            }

            return(this.Messages);
        }
示例#18
0
        /// <summary>
        /// Creates the snippet.
        /// </summary>
        /// <param name="visualStudioService">The visual studio service.</param>
        /// <param name="viewModelName">Name of the view model.</param>
        /// <param name="codeSnippetsPath">The code snippets path.</param>
        /// <param name="createUnitTests">if set to <c>true</c> [create unit tests].</param>
        /// <param name="coreProjectService">The core project service.</param>
        /// <param name="projectItemService">The project item service.</param>
        /// <param name="plugin">The plugin.</param>
        internal IProjectItemService CreateSnippet(
            IVisualStudioService visualStudioService,
            string viewModelName,
            string codeSnippetsPath,
            bool createUnitTests,
            IProjectService coreProjectService,
            IProjectItemService projectItemService,
            Plugin plugin)
        {
            TraceService.WriteLine("PluginsService::CreateSnippet plugin=" + plugin.FriendlyName + " viewModelName=" + viewModelName);

            string snippetPath = string.Format(@"{0}\Plugins.{1}.xml", codeSnippetsPath, plugin.FriendlyName);
            IProjectItemService testProjectItemService = null;

            CodeSnippet codeSnippet = this.snippetService.GetSnippet(snippetPath);

            if (codeSnippet != null)
            {
                //// add in the reference to the plugin - doing this way means we don't need it in the xml files
                codeSnippet.UsingStatements.Add(Path.GetFileNameWithoutExtension(plugin.FileName));

                projectItemService.ImplementCodeSnippet(codeSnippet);

                this.Messages.Add(plugin.FriendlyName + " plugin code added to " + viewModelName + ".cs in project " + coreProjectService.Name + ".");

                //// do we need to implement any unit tests?
                if (createUnitTests)
                {
                    IProjectItemService itemService = this.CreateUnitTests(
                        visualStudioService.CoreTestsProjectService,
                        plugin,
                        codeSnippetsPath,
                        viewModelName);

                    //// if we actually create some units tests save the pointer to do
                    //// the sort and remove of the using statements later!
                    if (itemService != null)
                    {
                        testProjectItemService = itemService;
                    }
                }
            }

            return(testProjectItemService);
        }
        /// <summary>
        /// Removes the folder item.
        /// </summary>
        /// <param name="folderName">Name of the folder.</param>
        /// <param name="itemName">Name of the item.</param>
        public void RemoveFolderItem(
            string folderName,
            string itemName)
        {
            IProjectItemService projectItemService = this.GetFolder(folderName);

            if (projectItemService != null)
            {
                IEnumerable <ProjectItem> projectItems = projectItemService.GetSubProjectItems();

                ProjectItem projectItem = projectItems.FirstOrDefault(x => x.Name.Contains(itemName));

                if (projectItem != null)
                {
                    projectItem.RemoveAndDelete();
                }
            }
        }
        /// <summary>
        /// Updates the unit test file.
        /// </summary>
        /// <param name="viewModelName">Name of the view model.</param>
        internal void UpdateUnitTestFile(string viewModelName)
        {
            TraceService.WriteLine("ViewModelAndViewsController::UpdateUnitTestFile ViewModelName=" + viewModelName);

            IProjectService testProjectService = this.VisualStudioService.CoreTestsProjectService;

            if (testProjectService != null)
            {
                IProjectItemService projectItemService = testProjectService.GetProjectItem("Test" + viewModelName);

                if (projectItemService != null)
                {
                    projectItemService.ReplaceText("CoreTemplate.", "Core.");
                    projectItemService.ReplaceText("FirstViewModel", viewModelName);
                    projectItemService.ReplaceText("firstViewModel", viewModelName.Substring(0, 1).ToLower() + viewModelName.Substring(1));
                }
            }
        }
        /// <summary>
        /// Gets the file items.
        /// </summary>
        /// <param name="fileOperation">The file operation.</param>
        /// <param name="projectService">The project service.</param>
        /// <returns>The files to have operations on.</returns>
        private IEnumerable <IProjectItemService> GetFileItems(
            FileOperation fileOperation,
            IProjectService projectService)
        {
            TraceService.WriteLine("FileOperationService::GetFileItems");

            List <IProjectItemService> fileItemServices = new List <IProjectItemService>();

            if (string.IsNullOrEmpty(fileOperation.Directory) == false)
            {
                IProjectItemService projectItemService = projectService.GetFolder(fileOperation.Directory);

                if (projectItemService != null)
                {
                    if (string.IsNullOrEmpty(fileOperation.File) == false)
                    {
                        fileItemServices.Add(projectItemService.GetProjectItem(fileOperation.File));
                    }

                    else
                    {
                        IEnumerable <IProjectItemService> projectItemServices = projectItemService.GetCSharpProjectItems();

                        foreach (IProjectItemService childProjectItemService in projectItemServices)
                        {
                            TraceService.WriteDebugLine("FileOperationService::GetFileItems File=" + childProjectItemService.Name);
                            fileItemServices.Add(childProjectItemService);
                        }
                    }
                }
                else
                {
                    TraceService.WriteDebugLine("Directory " + fileOperation.Directory + " not found");
                }
            }
            else
            {
                fileItemServices.Add(projectService.GetProjectItem(fileOperation.File));
            }

            TraceService.WriteDebugLine("FileOperationService::GetFileItems fileItemServicesCount=" + fileItemServices.Count);

            return(fileItemServices);
        }
示例#22
0
        /// <summary>
        /// Replaces the project item text.
        /// </summary>
        /// <param name="projectService">The project service.</param>
        /// <param name="projectItem">The project item.</param>
        /// <param name="text">The text.</param>
        /// <param name="replacementText">The replacement text.</param>
        internal void ReplaceProjectItemText(
            IProjectService projectService,
            string projectItem,
            string text,
            string replacementText)
        {
            TraceService.WriteLine("NugetService::ReplaceProjectItemText");

            if (projectService != null)
            {
                IProjectItemService projectItemService = projectService.GetProjectItem(projectItem);

                if (projectItemService != null)
                {
                    TraceService.WriteLine("Replacing " + text + " with " + replacementText);

                    projectItemService.ReplaceText(text, replacementText);
                }
            }
        }
示例#23
0
        /// <summary>
        /// Builds the source file.
        /// </summary>
        /// <param name="projectService">The project service.</param>
        /// <param name="extensionSource">The extensionSource.</param>
        /// <param name="extensionDestination">The extension destination.</param>
        /// <param name="friendlyName">Name of the friendly.</param>
        internal void BuildSourceFile(
            IProjectService projectService,
            string extensionSource,
            string extensionDestination,
            string friendlyName)
        {
            TraceService.WriteLine("PluginsService::BuildSourceFile " + friendlyName);

            try
            {
                string message = string.Format("BuildSourceFile Project Name={0} friendlyName={1}", projectService.Name, friendlyName);

                TraceService.WriteLine(message);

                string sourceFile = friendlyName + "PluginBootstrap.cs";

                //// now we need to sort out the item template!
                projectService.AddToFolderFromTemplate("Bootstrap", "MvvmCross.Plugin.zip", sourceFile, false);

                this.Messages.Add(string.Format(@"Bootstrap\{0} added to {1} project.", sourceFile, projectService.Name));

                IProjectItemService projectItemService = projectService.GetProjectItem(sourceFile);

                //// if we find the project item replace the text in it.

                if (projectItemService.ProjectItem != null)
                {
                    //// fix ups!

                    projectItemService.ReplaceText("All", friendlyName);
                    projectItemService.ReplaceText("CoreTemplates.Bootstrap", projectService.Name + ".Bootstrap");
                    projectItemService.ReplaceText("class Plugin", "class " + friendlyName + "PluginBootstrap");
                }
            }
            catch (Exception exception)
            {
                TraceService.WriteError("BuildSourceFile " + exception.Message);
            }
        }
        /// <summary>
        /// Replaces the text.
        /// </summary>
        /// <param name="fileOperation">The file operation.</param>
        /// <param name="projectService">The project service.</param>
        /// <param name="projectItemService">The project item service.</param>
        private void ReplaceText(
            FileOperation fileOperation,
            IProjectService projectService,
            IProjectItemService projectItemService)
        {
            if (projectService == null)
            {
                return;
            }

            if (projectItemService == null)
            {
                return;
            }

            string to = fileOperation.To.Replace("$rootnamespace$", projectService.Name);

            to = to.Replace("$CoreProject$", this.settingsService.CoreProjectSuffix.Substring(1));
            to = to.Replace("$FormsProject$", this.settingsService.XamarinFormsProjectSuffix.Substring(1));
            to = to.Replace("$iOSProject$", this.settingsService.iOSProjectSuffix.Substring(1));
            to = to.Replace("$DroidProject$", this.settingsService.DroidProjectSuffix.Substring(1));
            to = to.Replace("$WindosPhonedProject$", this.settingsService.WindowsPhoneProjectSuffix.Substring(1));
            to = to.Replace("$WindosUniversalProject$", this.settingsService.WindowsUniversalProjectSuffix.Substring(1));
            to = to.Replace("$WpfProject$", this.settingsService.WpfProjectSuffix.Substring(1));

            string from = fileOperation.From;

            TraceService.WriteDebugLine("from=" + @from + " to" + to);

            if (@from != to)
            {
                projectItemService.ReplaceText(fileOperation.From, to);
                TraceService.WriteDebugLine("**Replaced**");
            }
            else
            {
                TraceService.WriteDebugLine("No need to replace!");
            }
        }
        /// <summary>
        /// Projects the item added.
        /// </summary>
        /// <param name="projectItemService">The project item service.</param>
        internal void ProjectItemAdded(IProjectItemService projectItemService)
        {
            TraceService.WriteLine("BaseController::ProjectItemAdded");

            bool saveFile = false;

            if (projectItemService.IsCSharpFile())
            {
                if (this.SettingsService.RemoveDefaultComments)
                {
                    projectItemService.RemoveComments();
                    saveFile = true;
                }

                if (this.SettingsService.RemoveDefaultFileHeaders)
                {
                    projectItemService.RemoveHeader();
                    saveFile = true;
                }
            }

            if (saveFile)
            {
                this.VisualStudioService.DTEService.SaveAll();
            }
        }
        /// <summary>
        /// Removes the folder item.
        /// </summary>
        /// <param name="itemName">Name of the item.</param>
        public void RemoveFolderItem(string itemName)
        {
            IEnumerable <IProjectItemService> projectItems = this.GetProjectItems();

            IProjectItemService projectItemService = projectItems.FirstOrDefault(x => x.Name.Contains(itemName));

            if (projectItemService != null)
            {
                projectItemService.RemoveAndDelete();
                return;
            }

            foreach (IProjectItemService subProjectItemService in this.GetProjectItems())
            {
                if (subProjectItemService.Kind == VSConstants.VsProjectItemKindPhysicalFolder)
                {
                    IEnumerable <ProjectItem> items = subProjectItemService.GetSubProjectItems();

                    ProjectItem projectItem = items.FirstOrDefault(x => x.Name.Contains(itemName));

                    if (projectItem != null)
                    {
                        projectItem.RemoveAndDelete();
                        return;
                    }
                }
            }

            /*foreach (IProjectItemService subProjectItemService in projectItems.)
             * {
             *  foreach (var VARIABLE in subProjectItemService)
             *  {
             *
             *  }
             *  ////subProjectItemService.RemoveAndDelete();
             *  ////return;
             * }
             *
             * IEnumerable<IProjectItemService> subProjectItems = this.GetFolderProjectItems();
             *
             * foreach (IProjectItemService subFolderItemService in subProjectItems)
             * {
             *  if (subFolderItemService.Name.Contains(itemName))
             *  {
             *      subFolderItemService.RemoveAndDelete();
             *      return;
             *  }
             * }
             *
             * IEnumerable<IProjectService> subProjectServices = this.GetSubProjects();
             *
             * foreach (IProjectService subProjectService in subProjectServices)
             * {
             *  IEnumerable<IProjectItemService> projectItemServices = subProjectService.GetProjectItems();
             *
             *  foreach (IProjectItemService itemService in projectItemServices)
             *  {
             *      if (itemService.Name.Contains(itemName))
             *      {
             *          itemService.RemoveAndDelete();
             *          return;
             *      }
             *  }
             * }*/
        }
        /// <summary>
        /// Fixes up file.
        /// </summary>
        /// <param name="projectService">The project service.</param>
        /// <param name="friendlyName">Name of the friendly.</param>
        /// <param name="projectItemService">The project item service.</param>
        internal void FixUpFile(
            IProjectService projectService, 
            string friendlyName, 
            IProjectItemService projectItemService)
        {
            TraceService.WriteLine("PluginsService::FixUpFile " + friendlyName);

            projectItemService.ReplaceText("All", friendlyName);
            projectItemService.ReplaceText("CoreTemplates.Bootstrap", projectService.Name + ".Bootstrap");
            projectItemService.ReplaceText("class Plugin", "class " + friendlyName + "PluginBootstrap");

            projectItemService.MoveUsingStatements();

            if (this.SettingsService.RemoveDefaultComments)
            {
                projectItemService.RemoveComments();
            }

            if (this.SettingsService.RemoveDefaultFileHeaders)
            {
                projectItemService.RemoveHeader();
            }
        }
        /// <summary>
        /// Creates the snippet.
        /// </summary>
        /// <param name="visualStudioService">The visual studio service.</param>
        /// <param name="viewModelName">Name of the view model.</param>
        /// <param name="createUnitTests">if set to <c>true</c> [create unit tests].</param>
        /// <param name="projectName">Name of the project.</param>
        /// <param name="projectItemService">The project item service.</param>
        /// <param name="plugin">The plugin.</param>
        /// <returns>
        /// The project item service interface..
        /// </returns>
        internal IProjectItemService CreateSnippet(
            IVisualStudioService visualStudioService, 
            string viewModelName, 
            bool createUnitTests, 
            string projectName, 
            IProjectItemService projectItemService, 
            Plugin plugin)
        {
            TraceService.WriteLine("PluginsService::CreateSnippet plugin=" + plugin.FriendlyName + " viewModelName=" + viewModelName);

            IProjectItemService testProjectItemService = null;

            CodeSnippet codeSnippet = this.codeSnippetFactory.GetPluginSnippet(plugin);

            if (codeSnippet != null)
            {
                //// add in the reference to the plugin - doing this way means we don't need it in the xml files
                codeSnippet.UsingStatements.Add(Path.GetFileNameWithoutExtension(plugin.FileName));

                projectItemService.ImplementCodeSnippet(
                    codeSnippet,
                    this.settingsService.FormatFunctionParameters);

                this.Messages.Add(plugin.FriendlyName + " plugin code added to " + viewModelName + ".cs in project " + projectName + ".");

                //// do we need to implement any unit tests?
                if (createUnitTests)
                {
                    IProjectItemService itemService = this.CreateUnitTests(
                        visualStudioService,
                        visualStudioService.CoreTestsProjectService,
                        plugin,
                        viewModelName);

                    this.Messages.Add(plugin.FriendlyName + " test plugin code added to Test" + viewModelName + ".cs in project " + visualStudioService.CoreTestsProjectService.Name + ".");

                    //// if we actually create some units tests save the pointer to do
                    //// the sort and remove of the using statements later!
                    if (itemService != null)
                    {
                        testProjectItemService = itemService;
                    }
                }
            }

            return testProjectItemService;
        }
        /// <summary>
        /// Creates the snippet.
        /// </summary>
        /// <param name="visualStudioService">The visual studio service.</param>
        /// <param name="viewModelName">Name of the view model.</param>
        /// <param name="codeSnippetsPath">The code snippets path.</param>
        /// <param name="createUnitTests">if set to <c>true</c> [create unit tests].</param>
        /// <param name="coreProjectService">The core project service.</param>
        /// <param name="projectItemService">The project item service.</param>
        /// <param name="itemTemplateInfo">The item template info.</param>
        /// <returns>The project Item service.</returns>
        internal IProjectItemService CreateSnippet(
            IVisualStudioService visualStudioService,
            string viewModelName,
            string codeSnippetsPath,
            bool createUnitTests,
            IProjectService coreProjectService,
            IProjectItemService projectItemService,
            ItemTemplateInfo itemTemplateInfo)
        {
            TraceService.WriteLine("ServicesService::CreateSnippet service=" + itemTemplateInfo.FriendlyName + " viewModelName=" + viewModelName);

            string snippetPath = string.Format(@"{0}\Services.{1}.xml", codeSnippetsPath, itemTemplateInfo.FriendlyName);
            IProjectItemService testProjectItemService = null;

            CodeSnippet codeSnippet = this.snippetService.GetSnippet(snippetPath);

            if (codeSnippet != null)
            {
                //// Do some variable substitution!!!!

                if (this.settingsService.ReplaceVariablesInSnippets)
                {
                    this.snippetService.ApplyGlobals(visualStudioService, codeSnippet);
                }

                projectItemService.ImplementCodeSnippet(codeSnippet, this.settingsService.FormatFunctionParameters);

                this.Messages.Add(itemTemplateInfo.FriendlyName + " service code added to " + viewModelName + ".cs in project " + coreProjectService.Name + ".");

                //// do we need to implement any unit tests?
                if (createUnitTests)
                {
                    string testSnippetPath = string.Format(@"{0}\Services.{1}.Tests.xml", codeSnippetsPath, itemTemplateInfo.FriendlyName);

                    IProjectItemService itemService = this.snippetService.CreateUnitTests(
                            visualStudioService,
                            visualStudioService.CoreTestsProjectService,
                            testSnippetPath,
                            viewModelName,
                            itemTemplateInfo.FriendlyName,
                            string.Empty);

                    //// if we actually create some units tests save the pointer to do
                    //// the sort and remove of the using statements later!
                    if (itemService != null)
                    {
                        testProjectItemService = itemService;
                    }
                }
            }

            return testProjectItemService;
        }
        /// <summary>
        /// Fixes the info plist.
        /// </summary>
        /// <param name="projectItemService">The project item service.</param>
        /// <param name="projectName">Name of the project.</param>
        internal void FixInfoPlist(
            IProjectItemService projectItemService,
            string projectName)
        {
            TraceService.WriteLine("ProjectsController::FixInfoPlist Project=" + projectName);

            XDocument doc = XDocument.Load(projectItemService.FileName);

            if (doc.Root != null)
            {
                XElement element = doc.Root.Element("dict");

                if (element != null)
                {
                    //// first look for the elements

                    XElement childElement = element.Elements("key").FirstOrDefault(x => x.Value == "CFBundleDisplayName");

                    if (childElement == null)
                    {
                        element.Add(new XElement("key", "CFBundleDisplayName"));
                        element.Add(new XElement("string", projectName));
                    }

                    childElement = element.Elements("key").FirstOrDefault(x => x.Value == "CFBundleVersion");

                    if (childElement == null)
                    {
                        element.Add(new XElement("key", "CFBundleVersion"));
                        element.Add(new XElement("string", "1.0"));
                    }

                    childElement = element.Elements("key").FirstOrDefault(x => x.Value == "CFBundleIdentifier");

                    if (childElement == null)
                    {
                        element.Add(new XElement("key", "CFBundleIdentifier"));
                        element.Add(new XElement("string", "1"));
                    }
                }

                doc.Save(projectItemService.FileName);
            }
        }
        /// <summary>
        /// Called when [file added to project].
        /// </summary>
        /// <param name="projectItemService">The project item service.</param>
        internal void OnFileAddedToProject(IProjectItemService projectItemService)
        {
            if (projectItemService.IsCSharpFile())
            {
                this.Messages.Add(projectItemService.GetFolder() + @"\" + projectItemService.Name + " added to project " + projectItemService.ContainingProjectService.Name + ".");

                if (this.settingsService.RemoveDefaultComments)
                {
                    projectItemService.RemoveComments();
                }

                if (this.settingsService.RemoveDefaultFileHeaders)
                {
                    projectItemService.RemoveHeader();
                }
            }
        }
        /// <summary>
        /// Implements the code snippet.
        /// </summary>
        /// <param name="visualStudioService">The visual studio service.</param>
        /// <param name="viewModelName">Name of the view model.</param>
        /// <param name="coreProjectService">The core project service.</param>
        /// <param name="projectItemService">The project item service.</param>
        /// <param name="itemTemplateInfo">The item template info.</param>
        /// <returns>The project Item service.</returns>
        internal void ImplementCodeSnippet(
            IVisualStudioService visualStudioService,
            string viewModelName,
            IProjectService coreProjectService,
            IProjectItemService projectItemService,
            ItemTemplateInfo itemTemplateInfo)
        {
            TraceService.WriteLine("ServicesService::CreateSnippet service=" + itemTemplateInfo.FriendlyName + " viewModelName=" + viewModelName);

            CodeSnippet codeSnippet = this.codeSnippetFactory.GetServiceSnippet(itemTemplateInfo.FriendlyName);

            if (codeSnippet != null)
            {
                projectItemService.ImplementCodeSnippet(
                    codeSnippet,
                    this.settingsService.FormatFunctionParameters);

                this.Messages.Add(itemTemplateInfo.FriendlyName + " service code added to " + viewModelName + ".cs in project " + coreProjectService.Name + ".");
            }
        }
        /// <summary>
        /// Replaces the text.
        /// </summary>
        /// <param name="fileOperation">The file operation.</param>
        /// <param name="projectService">The project service.</param>
        /// <param name="projectItemService">The project item service.</param>
        private void ReplaceText(
            FileOperation fileOperation,
            IProjectService projectService,
            IProjectItemService projectItemService)
        {
            if (projectService == null)
            {
                return;
            }

            if (projectItemService == null)
            {
                return;
            }

            string to = fileOperation.To.Replace("$rootnamespace$", projectService.Name);

            to = to.Replace("$CoreProject$", this.settingsService.CoreProjectSuffix.Substring(1));
            to = to.Replace("$FormsProject$", this.settingsService.XamarinFormsProjectSuffix.Substring(1));
            to = to.Replace("$iOSProject$", this.settingsService.iOSProjectSuffix.Substring(1));
            to = to.Replace("$DroidProject$", this.settingsService.DroidProjectSuffix.Substring(1));
            to = to.Replace("$WindosPhonedProject$", this.settingsService.WindowsPhoneProjectSuffix.Substring(1));
            to = to.Replace("$WindosUniversalProject$", this.settingsService.WindowsUniversalProjectSuffix.Substring(1));
            to = to.Replace("$WpfProject$", this.settingsService.WpfProjectSuffix.Substring(1));

            string from = fileOperation.From;

            TraceService.WriteDebugLine("from=" + @from + " to" + to);

            if (@from != to)
            {
                projectItemService.ReplaceText(fileOperation.From, to);
                TraceService.WriteDebugLine("**Replaced**");
            }
            else
            {
                TraceService.WriteDebugLine("No need to replace!");
            }
        }
 /// <summary>
 /// Updates the property.
 /// </summary>
 /// <param name="fileOperation">The file operation.</param>
 /// <param name="projectItemService">The project item service.</param>
 private void UpdateProperty(
     FileOperation fileOperation, 
     IProjectItemService projectItemService)
 {
     if (projectItemService.ProjectItem != null)
     {
         projectItemService.ProjectItem.Properties.Item(fileOperation.From).Value = fileOperation.To;
         TraceService.WriteDebugLine("**Properties Updates**");
     }
 }
 public ProjectItemController(IProjectItemService serviceProjectItem, IMapper mapperService)
 {
     _serviceProjectItem = serviceProjectItem;
     _mapperService      = mapperService;
 }