コード例 #1
0
        public VSTemplateDirectory CreateSubDirectory(string subPath)
        {
            var subPathStripped = subPath.RemoveSurroundingSlashes();
            var parts           = subPathStripped.Split('\\').Where(s => s.Length > 0);
            var path            = parts.First();
            var subDir          = FindSubDirectory(path);

            if (subDir != null)
            {
                subDir.CreateSubDirectory(subPathStripped.RemoveStart(path).RemoveSurroundingSlashes());
            }
            else
            {
                var subPathSub = string.Empty;

                subPathSub = subPathStripped.RemoveStart(path).RemoveSurroundingSlashes();
                subDir     = new VSTemplateDirectory(path);

                if (subPathSub.Split('\\').Where(s => s.Length > 0).Count() > 0)
                {
                    subDir.CreateSubDirectory(subPathSub.RemoveSurroundingSlashes());
                }

                subDir.ParentDirectory = this;
            }

            return(FindSubDirectory(subPath));
        }
コード例 #2
0
        public VSItemTemplateDirectory(RegistryKey key, VSTemplateDirectory projectDirectory, VSProjectFactoryProject specialProject) : base()
        {
            var directoryKey = key.ToIndexable();

            if (projectDirectory != null)
            {
                this.Package = projectDirectory.Package;
            }
            else
            {
                this.Package = specialProject.Package;
            }

            this.SubDirectories   = new List <VSTemplateDirectory>();
            this.Guid             = Guid.Parse(directoryKey.SubName);
            this.ProjectDirectory = projectDirectory;
            this.SpecialProject   = specialProject;

            var keys = key.Enumerate();

            if (keys.Count() == 1)
            {
                var subKey = key.Enumerate().First();

                ProcessSubKey(subKey, false);
            }
            else
            {
                foreach (var subKey in keys)
                {
                    ProcessSubKey(subKey, true);
                }
            }
        }
コード例 #3
0
ファイル: VSConfigProvider.cs プロジェクト: CloudIDEaaS/hydra
        private static void ProcessTemplateDirectories(VSConfigIndexOptions options = null)
        {
            var stopWatch = new Stopwatch();

            RaiseOnIndexingStatus("Processing template directories started");
            stopWatch.Start();

            var dirs = projectTemplateDirectories.Values.OrderBy(d => d.SortPriority);

            projectTemplateDirectories.Values.ToList().ForEach(d =>
            {
                Action <int, VSTemplateDirectory> recurse = null;

                recurse = (int indent, VSTemplateDirectory dir) =>
                {
                    // search based on TemplateDir in directory entry (most likely finds none)

                    if (dir.AllTemplateDirs != null)
                    {
                        dir.AllTemplateDirs.ForEach(td =>
                        {
                            var dirTemplates = projectTemplates.Values.Where(t => t.TemplateLocation.StartsWith(td.FullName));

                            if (dirTemplates.Count() > 0)
                            {
                                dirTemplates.ToList().ForEach(t =>
                                {
                                    dir.AllTemplates.Add(t);
                                });
                            }
                        });
                    }

                    // search based on project type

                    if (dir.ProjectType != null)
                    {
                        var dirTemplates2 = projectTemplates.Values.Where(t => t.ProjectTypeName == dir.ProjectType);

                        if (dirTemplates2.Count() > 0)
                        {
                            dirTemplates2.ToList().ForEach(t =>
                            {
                                dir.AllTemplates.Add(t);
                            });
                        }

                        dir.BuildOut();
                        dir.SubDirectories.ForEach(d2 => recurse(indent + 1, d2));
                    }
                };

                recurse(0, d);
            });

            if (options.IndexItemTemplates)
            {
                var generalDirectory = new VSTemplateDirectory("General");

                foreach (var itemTemplate in VSConfigProvider.ItemTemplates.Values.Where(t => string.IsNullOrEmpty(t.TemplateGroupID)).OrderBy(t => t.Name))
                {
                    generalDirectory.AllTemplates.Add(itemTemplate);
                }

                generalDirectory.BuildOut();

                itemTemplateDirectories.Add(generalDirectory.Name, generalDirectory);

                var groups = VSConfigProvider.ItemTemplates.Values.Where(t => !string.IsNullOrEmpty(t.TemplateGroupID)).Select(t => t.TemplateGroupID).Distinct();

                foreach (var group in groups)
                {
                    var groupDirectory = new VSTemplateDirectory(group);

                    foreach (var itemTemplate in VSConfigProvider.ItemTemplates.Values.Where(t => !string.IsNullOrEmpty(t.TemplateGroupID) && t.TemplateGroupID == group).OrderBy(t => t.Name))
                    {
                        groupDirectory.AllTemplates.Add(itemTemplate);
                    }

                    groupDirectory.BuildOut();

                    itemTemplateDirectories.Add(groupDirectory.Name, groupDirectory);
                }
            }

            stopWatch.Stop();
            RaiseOnIndexingStatus("Processing template directories complete in " + stopWatch.Elapsed.Seconds.ToString() + " seconds.");

            directoriesEvent.Set();
        }
コード例 #4
0
ファイル: VSConfigProvider.cs プロジェクト: CloudIDEaaS/hydra
        private static void PackageIndexerThread()
        {
            var stopWatch = new Stopwatch();

            RaiseOnIndexingStatus("Package indexer started");
            stopWatch.Start();

            var templateDirsKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\VisualStudio\10.0_Config\NewProjectTemplates\TemplateDirs");
            var packagesKey     = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\VisualStudio\10.0_Config\Packages");
            var projectsKey     = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\VisualStudio\10.0_Config\Projects");
            var servicesKey     = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\VisualStudio\10.0_Config\Services");

            VSTemplateDirectory.LoadParentDirectory += (Guid parentGuid, out VSTemplateDirectory parent) =>
            {
                var pseudoFolderKey = Registry.CurrentUser.OpenSubKey(string.Format(@"Software\Microsoft\VisualStudio\10.0_Config\NewProjectTemplates\PseudoFolders\{{{0}}}", parentGuid.ToString()));
                var keyIndexable    = pseudoFolderKey.ToIndexable();
                var packageGuid     = Guid.Parse((string)keyIndexable["Package"]);

                if (projectTemplateDirectories.ContainsKey(parentGuid))
                {
                    parent = projectTemplateDirectories[parentGuid];
                }
                else
                {
                    var packageKey = Registry.CurrentUser.OpenSubKey(string.Format(@"Software\Microsoft\VisualStudio\10.0_Config\Packages\{{{0}}}", packageGuid));
                    var package    = new VSPackage(packageGuid, packageKey);

                    parent = new VSTemplateDirectory(pseudoFolderKey, package, true);

                    projectTemplateDirectories.Add(parent.Guid, parent);
                }
            };

            foreach (var packageKey in packagesKey.Enumerate())
            {
                try
                {
                    var package = new VSPackage(new Guid(packageKey.SubName), packageKey.Key);

                    packages.Add(package.PackageGuid, package);
                }
                catch
                {
                }
            }

            foreach (var dirKey in templateDirsKey.Enumerate())
            {
                var packageKey  = Registry.CurrentUser.OpenSubKey(string.Format(@"Software\Microsoft\VisualStudio\10.0_Config\Packages\{0}", dirKey.SubName));
                var package     = packages[new Guid(dirKey.SubName)];
                var templateDir = new VSTemplateDirectory(dirKey.Key, package);

                package.TemplateDirectory = templateDir;

                projectTemplateDirectories.Add(templateDir.Guid, templateDir);
            }

            VSProjectFactoryProject.LoadPackage += (Guid guid, out VSPackage package) =>
            {
                package = packages[guid];
            };

            VSProjectFactoryProject.LoadDirectory += (Guid guid, out VSTemplateDirectory directory) =>
            {
                if (projectTemplateDirectories.ContainsKey(guid))
                {
                    directory = projectTemplateDirectories[guid];
                }
                else
                {
                    directory = null;
                }
            };

            foreach (var projectKey in projectsKey.Enumerate())
            {
                var project = new VSProjectFactoryProject(new Guid(projectKey.SubName), projectKey.Key);

                factoryProjects.Add(project.ProjectGuid, project);
            }

            foreach (var serviceKey in servicesKey.Enumerate())
            {
                var service = new VSPackageService(new Guid(serviceKey.SubName), serviceKey.Key);

                if (service.PackageGuid != Guid.Empty)
                {
                    service.Package = packages[service.PackageGuid];

                    services.Add(service.ServiceGuid, service);
                }
            }

            packageIndexerEvent.Set();

            stopWatch.Stop();
            RaiseOnIndexingStatus("Package indexer complete in " + stopWatch.Elapsed.Seconds.ToString() + " seconds.");
        }
コード例 #5
0
        protected void ProcessSubKey(RegistryKeyIndexable subKey, bool isSubDirectory)
        {
            var nameKey           = (string)subKey.Default;
            var name              = string.Empty;
            var folder            = (string)subKey["Folder"];
            var developerActivity = (string)subKey["DeveloperActivity"];
            var templatesDir      = (string)subKey["TemplatesDir"];
            var sortPriority      = (int)((int?)subKey["SortPriority"] ?? 3000);
            var parentDirectory   = (VSTemplateDirectory)null;

            if (Package.SatelliteDll != null && nameKey.StartsWith("#"))
            {
                name = ResourceLoader.LoadStringFrom(Package.SatelliteDll.FullName, nameKey);
            }
            else
            {
                name = nameKey;
            }

            if (folder != null)
            {
                var guid = Guid.Parse(folder);

                LoadParentDirectory(guid, out parentDirectory);
            }

            var directory = (VSTemplateDirectory)null;

            if (isSubDirectory)
            {
                var subDirectory = new VSTemplateDirectory
                {
                    ParentDirectory   = parentDirectory,
                    Name              = name,
                    DeveloperActivity = developerActivity,
                    TemplatesDir      = templatesDir,
                    SortPriority      = sortPriority
                };

                directory = subDirectory;

                SubDirectories.Add(subDirectory);
            }
            else
            {
                this.Name              = name;
                this.ParentDirectory   = parentDirectory;
                this.DeveloperActivity = developerActivity;
                this.TemplatesDir      = templatesDir;
                this.SortPriority      = sortPriority;

                directory = this;
            }

            directory.AllTemplateDirs = new List <DirectoryInfo>();

            templatesDir = templatesDir.Expand();

            if (templatesDir.Contains(@"\.\") || templatesDir.Contains(@"\..\"))
            {
                var index    = templatesDir.IndexOf(@"\.\");
                var subIndex = index + @"\.\".Length;

                if (index == -1)
                {
                    index    = templatesDir.IndexOf(@"\..\");
                    subIndex = index + @"\..\".Length;
                }

                var templatesRoot = templatesDir.Substring(0, index);
                var subDirFind    = templatesDir.Substring(subIndex);
                Action <DirectoryInfo> recurseFind = null;

                recurseFind = (d) =>
                {
                    if (d.FullName.EndsWith(subDirFind))
                    {
                        directory.AllTemplateDirs.Add(d);
                    }

                    d.GetDirectories().ToList().ForEach(d2 => recurseFind(d2));
                };

                if (templatesRoot.Length > 0)
                {
                    var root = new DirectoryInfo(templatesRoot);

                    if (root.Exists)
                    {
                        recurseFind(root);
                    }
                }
            }
            else
            {
                if (templatesDir == @"\\")
                {
                }
                else
                {
                    directory.AllTemplateDirs.Add(new DirectoryInfo(templatesDir));
                }
            }
        }