Esempio n. 1
0
        protected override void Initialize()
        {
            _dte = GetService(typeof(DTE)) as DTE2;

            Logger.Initialize(this, Vsix.Name);
            Telemetry.Initialize(_dte, Vsix.Version, "e146dff7-f7c5-49ab-a7d8-3557375f6624");

            base.Initialize();

            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                CommandID menuCommandID = new CommandID(PackageGuids.VSTestGeneratorCmdSetGuid, PackageIds.cmdidMyCommand);
                var       menuItem      = new OleMenuCommand(MenuItemCallback, menuCommandID);
                menuItem.BeforeQueryStatus += MenuItem_BeforeQueryStatus;
                mcs.AddCommand(menuItem);

                var settingsFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                                    VSTestGeneratorDirectory, "settings.json");

                var settingsDirectory = Path.GetDirectoryName(settingsFilePath);

                if (!Directory.Exists(settingsDirectory))
                {
                    Directory.CreateDirectory(settingsDirectory);
                }

                if (!File.Exists(settingsFilePath))
                {
                    TemplateMap.CopyDefaultSettingsFile(settingsFilePath);
                }
            }
        }
Esempio n. 2
0
        private static async Task <int> WriteFile(Project project, string file)
        {
            Encoding encoding = new UTF8Encoding(false);
            string   template = await TemplateMap.GetTemplateFilePath(project, file);

            if (!string.IsNullOrEmpty(template))
            {
                int index = template.IndexOf('$');
                template = template.Remove(index, 1);
                File.WriteAllText(file, template, encoding);
                return(index);
            }

            File.WriteAllText(file, string.Empty, encoding);
            return(0);
        }