/// <summary>
        /// Translates the specified from.
        /// </summary>
        /// <param name="from">From.</param>
        /// <returns></returns>
        public CustomRenderers Translate(string from)
        {
            TraceService.WriteLine("CustomRenderers::Translate " + from);

            CustomRenderers customRenderers = new CustomRenderers();

            try
            {
                XDocument doc = XDocument.Load(@from);

                if (doc.Root != null)
                {
                    TraceService.WriteDebugLine(doc.Root.Value);

                    customRenderers.HelpLink = this.GetHelpLink(doc.Root);
                    customRenderers.Groups   = this.GetGroups(doc.Root);
                }
            }
            catch (Exception exception)
            {
                TraceService.WriteError(exception);
            }

            return(customRenderers);
        }
Example #2
0
        /// <summary>
        /// Translates the specified from.
        /// </summary>
        /// <param name="from">The translation source..</param>
        /// <returns>A collection of Plugins.</returns>
        public Plugins Translate(string from)
        {
            try
            {
                XDocument doc = XDocument.Load(from);

                if (doc.Root != null)
                {
                    TraceService.WriteDebugLine(doc.Root.Value);

                    IEnumerable <XElement> elements = doc.Root.Elements("Plugin");

                    List <Plugin> items = elements.Select(element => this.translator.Translate(element)).ToList();

                    Plugins plugins = new Plugins {
                        Items = items
                    };

                    return(plugins);
                }

                return(null);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        /// <summary>
        /// Gets the project item.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <returns>The project item.</returns>
        public static ProjectItem GetProjectItem(
            this Project instance,
            string fileName)
        {
            TraceService.WriteDebugLine("ProjectExtensions::GetProjectItem project=" + instance.Name + " fileName=" + fileName);

            ProjectItem projectItem = instance.GetCSharpProjectItems().FirstOrDefault(x => x.Name.StartsWith(fileName));

            //// try all the sub-folders!
            if (projectItem == null)
            {
                IEnumerable <ProjectItem> projectItems = instance.GetProjectItems();

                foreach (ProjectItem item in projectItems)
                {
                    if (item.Name.StartsWith(fileName))
                    {
                        return(item);
                    }

                    IEnumerable <ProjectItem> subProjectItems = item.GetSubProjectItems();

                    foreach (ProjectItem subItem in subProjectItems
                             .Where(subItem => subItem.Name.StartsWith(fileName)))
                    {
                        return(subItem);
                    }
                }
            }

            return(projectItem);
        }
        /// <summary>
        /// Processes the command.
        /// </summary>
        /// <param name="fileOperation">The file operation.</param>
        public void ProcessCommand(FileOperation fileOperation)
        {
            TraceService.WriteLine("FileOperationService::ProcessCommand");

            TraceService.WriteDebugLine("Platform=" + fileOperation.PlatForm);
            TraceService.WriteDebugLine("CommandType=" + fileOperation.CommandType);
            TraceService.WriteDebugLine("Directory=" + fileOperation.Directory);
            TraceService.WriteDebugLine("File=" + fileOperation.File);
            TraceService.WriteDebugLine("From=" + fileOperation.From);
            TraceService.WriteDebugLine("To=" + fileOperation.To);

            IProjectService projectService = this.visualStudioService.GetProjectServiceBySuffix(fileOperation.PlatForm);

            if (projectService != null)
            {
                IEnumerable <IProjectItemService> fileItemServices = this.GetFileItems(fileOperation, projectService);

                foreach (IProjectItemService projectItemService in fileItemServices)
                {
                    if (fileOperation.CommandType == "ReplaceText")
                    {
                        this.ReplaceText(fileOperation, projectService, projectItemService);
                    }
                    else if (fileOperation.CommandType == "Properties")
                    {
                        this.UpdateProperty(fileOperation, projectItemService);
                    }
                }
            }
            else
            {
                TraceService.WriteLine("Platform " + fileOperation.PlatForm + " not found");
            }
        }
Example #5
0
        /// <summary>
        /// Translates the specified from.
        /// </summary>
        /// <param name="from">Translate Source.</param>
        /// <returns>A Commands List.</returns>
        public CommandsList Translate(string @from)
        {
            TraceService.WriteLine("CommandsList::Translate " + @from);

            try
            {
                XDocument doc = XDocument.Load(from);

                if (doc.Root != null)
                {
                    TraceService.WriteDebugLine(doc.Root.Value);

                    return(new CommandsList
                    {
                        Commands = this.commandsTranslator.Translate(doc.Root),
                        FileOperations = this.fileOperationsTranslator.Translate(doc.Root)
                    });
                }

                return(null);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        /// <summary>
        /// Gets the project references.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <returns>The project references.</returns>
        public static IEnumerable <Reference> GetProjectReferences(this Project instance)
        {
            TraceService.WriteDebugLine("ProjectExtensions::GetProjectReferences project=" + instance.Name);

            VSProject project = instance.Object as VSProject;

            return(project?.References.Cast <Reference>());
        }
        /// <summary>
        /// Attempts to resolve a type.
        /// </summary>
        /// <typeparam name="TResolveType">Type to resolve</typeparam>
        /// <returns>Instance of type</returns>
        public TResolveType Resolve <TResolveType>()
            where TResolveType : class
        {
            TraceService.WriteDebugLine("ResolverService::Resolve type=" + typeof(TResolveType));
            TinyIoCContainer container = TinyIoCContainer.Current;

            return(container.Resolve <TResolveType>());
        }
Example #8
0
        /// <summary>
        /// Writes the debug message.
        /// </summary>
        /// <param name="message">The message.</param>
        protected void WriteDebugMessage(string message)
        {
            TraceService.WriteDebugLine(message);

            if (this.SettingsService.ExtendedLogging)
            {
                this.Messages.Add(message);
            }
        }
 /// <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**");
     }
 }
        /// <summary>
        /// Adds the project reference.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="referencedProject">The referenced project.</param>
        /// <returns>The reference.</returns>
        public static Reference AddProjectReference(
            this Project instance,
            Project referencedProject)
        {
            TraceService.WriteDebugLine("ProjectExtensions::AddProjectReference project=" + instance.Name + " referenced project=" + referencedProject.Name);

            VSProject project = (VSProject)instance.Object;

            return(project.References.AddProject(referencedProject));
        }
        /// <summary>
        /// Removes the reference.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="value">The value.</param>
        public static void RemoveReferences(
            this Project instance,
            string value)
        {
            TraceService.WriteDebugLine("ProjectExtensions::RemoveReference project=" + instance.Name);

            instance.GetProjectReferences()
            .Where(x => x.Name.Contains(value))
            .ToList()
            .ForEach(y => y.Remove());
        }
        /// <summary>
        /// Gets the reference path.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="referenceName">Name of the reference.</param>
        /// <returns>The path of the reference.</returns>
        public static string GetReferencePath(
            this Project instance,
            string referenceName)
        {
            TraceService.WriteDebugLine("ProjectExtensions::GetReferencePath project=" + instance.Name);

            IEnumerable <Reference> references = instance.GetProjectReferences();

            foreach (Reference reference in references
                     .Where(reference => reference.Name == referenceName))
            {
                return(reference.Path);
            }

            return(string.Empty);
        }
        /// <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);
        }
        /// <summary>
        /// Gets the folder.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="folderName">Name of the folder.</param>
        /// <returns>The folder.</returns>
        public static ProjectItem GetFolder(
            this Project instance,
            string folderName)
        {
            TraceService.WriteDebugLine("ProjectExtensions::GetFolder project=" + instance.Name + " folderName=" + folderName);

            try
            {
                List <ProjectItem> projectItems = instance.ProjectItems?.Cast <ProjectItem>().ToList();

                return(projectItems?.Where(projectItem => projectItem.Kind == VSConstants.VsProjectItemKindPhysicalFolder)
                       .FirstOrDefault(projectItem => projectItem.Name == folderName));
            }
            catch (Exception exception)
            {
                TraceService.WriteError("exception=" + exception.Message);
                return(null);
            }
        }
Example #15
0
        /// <summary>
        /// Adds the project.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="projectInfo">The project info.</param>
        internal void TryToAddProject(
            string path,
            ProjectTemplateInfo projectInfo)
        {
            TraceService.WriteLine("ProjectsService::TryToAddProject  project=" + projectInfo.Name);

            //// Project may actually already exist - if so just skip it!

            string projectPath = $@"{path}\{projectInfo.Name}\";

            if (this.FileSystem.Directory.Exists(projectPath) == false)
            {
                TraceService.WriteDebugLine(projectInfo.Name + " " + projectPath + " added to the solution.");

                this.AddProject(projectInfo, projectPath);
            }
            else
            {
                TraceService.WriteError("Directory " + projectPath + " not empty");
            }
        }
        /// <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>
        /// Translates the specified from.
        /// </summary>
        /// <param name="from">From.</param>
        /// <returns></returns>
        public IEnumerable <ProjectTemplateInfo> Translate(string from)
        {
            List <ProjectTemplateInfo> projectTemplateInfos = new List <ProjectTemplateInfo>();

            try
            {
                XDocument doc = XDocument.Load(@from);

                if (doc.Root != null)
                {
                    TraceService.WriteDebugLine(doc.Root.Value);

                    IEnumerable <XElement> projectElements = doc.Root.Elements("Project");

                    projectTemplateInfos.AddRange(projectElements.Select(projectElement => this.translator.Translate(projectElement)));
                }
            }
            catch (Exception exception)
            {
                TraceService.WriteError("Failed to load project templates document=" + from + " exception=" + exception.StackTrace);
            }

            return(projectTemplateInfos);
        }
 /// <summary>
 /// For when yous need to save some values that can't be directly bound to UI elements.
 /// Not called when moving previous (see WizardViewModel.MoveToNextStep).
 /// </summary>
 /// <returns>
 /// An object that may modify the route
 /// </returns>
 public override RouteModifier OnNext()
 {
     this.settingsService.SelectedMvvmCrossiOSViewType = this.SelectedMvvmCrossiOSViewType;
     TraceService.WriteDebugLine("ViewsViewModel::OnNext SelectedMvvmCrossiOSViewType=" + this.settingsService.SelectedMvvmCrossiOSViewType);
     return(base.OnNext());
 }
        /// <summary>
        /// Gets the c# project items.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <returns>The project items.</returns>
        public static IEnumerable <ProjectItem> GetCSharpProjectItems(this Project instance)
        {
            TraceService.WriteDebugLine("ProjectExtensions::GetCSharpProjectItems project=" + instance.Name);

            return(instance.ProjectItems.Cast <ProjectItem>().Where(x => x.Name.EndsWith(".cs")).ToList());
        }
        /// <summary>
        /// Gets the project items.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <returns>The project items.</returns>
        public static IEnumerable <ProjectItem> GetProjectItems(this Project instance)
        {
            TraceService.WriteDebugLine("ProjectExtensions::GetProjectItems project=" + instance.Name);

            return(instance.ProjectItems?.Cast <ProjectItem>().ToList());
        }