/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void Execute(object sender, EventArgs e) { Attempt.Action( () => { ThreadHelper.ThrowIfNotOnUIThread(); var options = _package.Options; var source = SolutionUtilities.GetSelectedFiles(_dte, false, options.GenerationOptions).FirstOrDefault(ProjectItemModel.IsSupported); if (source == null) { throw new InvalidOperationException("Cannot go to tests for this item because no supported files were found"); } var status = TargetFinder.FindExistingTargetItem(source, options.GenerationOptions, out var targetItem); switch (status) { case FindTargetStatus.FileNotFound: case FindTargetStatus.FolderNotFound: throw new InvalidOperationException("No unit tests were found for the selected file."); case FindTargetStatus.ProjectNotFound: throw new InvalidOperationException("Cannot go to tests for this item because there is no project '" + source.TargetProjectName + "'"); } VsProjectHelper.ActivateItem(targetItem); }, _package); }
public void RunFinished() { VsProjectHelper prjHelperInstance = VsProjectHelper.GetInstance; Project prj = null; DTE dte = this.projectTizen.DTE; string projectName = Path.GetFileNameWithoutExtension(this.projectTizen.UniqueName); Property property = dte.Solution.Properties.Item("StartupProject"); if (property != null) { property.Value = projectName; } if (!(String.IsNullOrEmpty(tData.Selected_project_name)) && tData.Selected_project_name != "Empty") { prj = prjHelperInstance.GetCurrentProjectFromName(tData.Selected_project_name); if (prj.Kind != prjHelperInstance.SharedProject) { (projectTizen.Object as VSLangProj.VSProject)?.References.AddProject(prj); } else { List <string> importPath_list = prjHelperInstance.GetImportList(prj); foreach (string importPath in importPath_list) { string rel_importPath = prjHelperInstance.ChangeToRelativeFromFull(importPath, projectTizen.FullName); prjHelperInstance.SetImportPath(rel_importPath, projectTizen); } } } }
public void Can_Apply(string scenario, string json, string xproj) { using (ApprovalResults.ForScenario(scenario)) { // arrange var upgradeActions = new List <IProjectUpgradeAction>(); var testXProj = VsProjectFactory.LoadTestProject(xproj); var testFileUpgradeContext = new TestJsonBaseProjectUpgradeContext(json, testXProj, null); // updates the sdk version in global json. var runtimeUpgradeAction = new MigrateProjectImportsFromDnxToDotNet(); upgradeActions.Add(runtimeUpgradeAction); // Apply these actions to the project.json file. foreach (var upgradeAction in upgradeActions) { upgradeAction.Apply(testFileUpgradeContext); } // save the changes. testFileUpgradeContext.SaveChanges(); var projContents = VsProjectHelper.ToString(testFileUpgradeContext.VsProjectFile); Approvals.VerifyXml(projContents); // assert. //var modifiedContents = testFileUpgradeContext.ModifiedJsonContents; //Approvals.VerifyJson(modifiedContents); // Approvals.VerifyAll(); } }
public AbstractSessionConfiguration(Project project) { Project = project; ProjectHostPath = Path.GetDirectoryName(Project.FullName); VsProjectHelper prjHelper = VsProjectHelper.Instance; ProjectPackageVersion = prjHelper.GetManifestVersion(project); ProjectPackageName = prjHelper.GetManifestPackage(project); }
private void RestoreClone() { if (_projectJsonClone == null) { throw new InvalidOperationException("must call clone first"); } ProjectJsonObject = _projectJsonClone; LaunchSettingsObject = _launchSettingsJsonClone; if (VsProjectFile != null) { VsProjectFile = VsProjectHelper.LoadTestProject(_xprojBackup.ToString()); } }
public void Can_Rollback_If_Error(string scenario, string json, string xproj, string launchSettingsJson) { using (ApprovalResults.ForScenario(scenario + "_project_json")) { // arrange var testXProj = VsProjectHelper.LoadTestProject(xproj); var testFileUpgradeContext = new TestJsonBaseProjectUpgradeContext(json, testXProj, launchSettingsJson); var migrator = new ProjectMigrator(testFileUpgradeContext); var options = new ProjectMigrationOptions(ReleaseVersion.RTM); // options.UpgradeToPreview1 = true; // project.json files will be updated to the preview 1 schema. // options.UpgradePackagesToRc2 = true; // rc1 packages will be migrated to rc2 packages, including commands (migrated to tools). options.AddNetStandardTargetForLibraries = true; // libraries will have the netStandard TFM added (and dependency). options.AddNetCoreTargetForApplications = true; // applications will have the netCore app TFM added (and dependency) // add an upgrade that throws an exception.. var additionalUpgrades = new List <IProjectUpgradeAction>(); additionalUpgrades.Add(new ExceptionuringUpgradeAction()); try { // migrate migrator.Apply(options, additionalUpgrades); testFileUpgradeContext.SaveChanges(); } catch (Exception e) { // throw; } // assert. var modifiedContents = testFileUpgradeContext.ProjectJsonObject.ToString(); Approvals.Verify(modifiedContents); using (ApprovalResults.ForScenario(scenario + "_xproj")) { var projContents = VsProjectHelper.ToString(testFileUpgradeContext.VsProjectFile); Approvals.VerifyXml(projContents); } using (ApprovalResults.ForScenario(scenario + "_launchSettings")) { var modifiedLaunchSettingsContents = testFileUpgradeContext.LaunchSettingsObject.ToString(); Approvals.Verify(modifiedLaunchSettingsContents); } } }
public void Can_Apply(string scenario, string json, string xproj, string launchSettings, ReleaseVersion version) { using (ApprovalResults.ForScenario(scenario + "_project_json")) { // arrange var testXProj = VsProjectHelper.LoadTestProject(xproj); var testFileUpgradeContext = new TestJsonBaseProjectUpgradeContext(json, testXProj, launchSettings, new [] { "appSettings.json" }); var migrator = new ProjectMigrator(testFileUpgradeContext); var options = new ProjectMigrationOptions(version); // options.UpgradeToPreview1 = true; // project.json files will be updated to the preview 1 schema. // options.UpgradePackagesToRc2 = true; // rc1 packages will be migrated to rc2 packages, including commands (migrated to tools). options.AddNetStandardTargetForLibraries = true; // libraries will have the netStandard TFM added (and dependency). options.AddNetCoreTargetForApplications = true; // applications will have the netCore app TFM added (and dependency) // migrate migrator.Apply(options); // save the changes. testFileUpgradeContext.SaveChanges(); // assert. var modifiedContents = testFileUpgradeContext.ModifiedProjectJsonContents; Approvals.Verify(modifiedContents); // Approvals.VerifyJson(modifiedContents); using (ApprovalResults.ForScenario(scenario + "_xproj")) { var projContents = VsProjectHelper.ToString(testFileUpgradeContext.VsProjectFile); Approvals.VerifyXml(projContents); } using (ApprovalResults.ForScenario(scenario + "_launchSettings")) { var modifiedLaunchSettingsContents = testFileUpgradeContext.ModifiedLaunchSettingsJsonContents; Approvals.Verify(modifiedLaunchSettingsContents); } } }
private bool NeedToInstall(SDBDeviceInfo device, string pathTpkFile, bool forceInstall) { string fileInstall = Path.GetFileNameWithoutExtension(pathTpkFile) + ".tpi"; string pathInstall = Path.Combine(Path.GetDirectoryName(pathTpkFile), fileInstall); //check whether the package is installed on target/emulator or not. var sdbLauncher = SDBLauncher.Create(outputPane); VsProjectHelper projectHelper = VsProjectHelper.GetInstance; if (!sdbLauncher.ConnectBridge()) { return(false); } string curPkgId = projectHelper.GetPackageId(pathTpkFile);//.GetAppId(curProject); if (forceInstall || !sdbLauncher.IsPackageDetected(device, curPkgId)) { ClearInstallCheckFile(pathInstall); } if (!File.Exists(pathInstall)) { TouchInstallCheckFile(pathInstall); return(true); } DateTime tpkTime = File.GetLastWriteTime(pathTpkFile); DateTime insTime = File.GetLastWriteTime(pathInstall); if (tpkTime <= insTime) { return(false); } TouchInstallCheckFile(pathInstall); return(true); }
public ProfileSessionConfiguration(Project project, GeneralOptions go) : base(project) { SleepTime = go.SleepTime; Arguments = ""; profilingSettings = new ProfilingSettings(); profilingPreset = ProfilingPresets.FirstOrDefault(); if (profilingPreset != null) { profilingSettings = profilingPreset.ProfilingSettings.Copy(); } ReadProjectConfiguration(); ProjectHostBinPath = Path.Combine(ProjectHostPath, ProjectOutputPath); ProjectTargetPath = "/opt/usr/home/owner"; VsProjectHelper prjHelper = VsProjectHelper.Instance; TargetDll = ProjectTargetPath + "/apps_rw/" + prjHelper.GetManifestPackage(project) + "/bin/" + prjHelper.GetManifestAppExec(project); ParseLaunchSettings(); }
#pragma warning restore VSTHRD010 private void Execute(bool withRegeneration) { GenerationItem generationItem; Attempt.Action( () => { ThreadHelper.ThrowIfNotOnUIThread(); var textView = GetTextView(); if (textView == null) { throw new InvalidOperationException("Could not find the text view"); } var caretPosition = textView.Caret.Position.BufferPosition; var document = caretPosition.Snapshot.GetOpenDocumentInCurrentContextWithChanges(); var messageLogger = new AggregateLogger(); messageLogger.Initialize(); var item = VsProjectHelper.GetProjectItem(document.FilePath); var options = _package.Options; var source = new ProjectItemModel(item, options.GenerationOptions); var projectItem = source.Item; var nameParts = VsProjectHelper.GetNameParts(projectItem); if (source.TargetProject == null && options.GenerationOptions.CreateProjectAutomatically) { var testProject = SolutionUtilities.CreateTestProjectInCurrentSolution(_dte, source.Project, options.GenerationOptions); ReferencesHelper.AddNugetPackagesToProject(testProject, StandardReferenceHelper.GetReferencedNugetPackages(options), messageLogger.LogMessage, _package); } var targetProject = source.TargetProject; if (targetProject == null && !options.GenerationOptions.AllowGenerationWithoutTargetProject) { throw new InvalidOperationException("Cannot create tests for '" + Path.GetFileName(source.FilePath) + "' because there is no project '" + source.TargetProjectName + "'"); } var projectDictionary = new Dictionary <EnvDTE.Project, Tuple <HashSet <TargetAsset>, HashSet <IReferencedAssembly> > >(); var set = new HashSet <TargetAsset>(); var assemblyReferences = new HashSet <IReferencedAssembly>(); if (targetProject != null) { projectDictionary[targetProject] = Tuple.Create(set, assemblyReferences); } var targetProjectItems = TargetFinder.FindTargetFolder(targetProject, nameParts, true, out var targetPath); if (targetProjectItems == null && !options.GenerationOptions.AllowGenerationWithoutTargetProject) { // we asked to create targetProjectItems - so if it's null we effectively had a problem getting to the target project throw new InvalidOperationException("Cannot create tests for '" + Path.GetFileName(source.FilePath) + "' because there is no project '" + source.TargetProjectName + "'"); } _package.JoinableTaskFactory.RunAsync( () => Attempt.ActionAsync( async() => { var methodSymbol = await GetTargetSymbolAsync(textView).ConfigureAwait(true); if (methodSymbol != null) { var sourceNameSpaceRoot = VsProjectHelper.GetProjectRootNamespace(source.Project); Func <string, string> namespaceTransform; if (source.TargetProject != null) { var targetNameSpaceRoot = VsProjectHelper.GetProjectRootNamespace(source.TargetProject); namespaceTransform = NamespaceTransform.Create(sourceNameSpaceRoot, targetNameSpaceRoot); } else { namespaceTransform = x => x + ".Tests"; } generationItem = new GenerationItem(source, methodSymbol.Item1, targetProjectItems, targetPath, set, assemblyReferences, namespaceTransform, options.GenerationOptions); await CodeGenerator.GenerateCodeAsync(new[] { generationItem }, withRegeneration, _package, projectDictionary, messageLogger).ConfigureAwait(true); } }, _package)); }, _package); }
public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams) { // Get SDK path tpath = ToolsPathInfo.ToolsRootPath; if (string.IsNullOrEmpty(tpath)) { RegistryKey kpath = Registry.CurrentUser.OpenSubKey(kname); tpath = kpath?.GetValue("ToolsPath") as string; if (!string.IsNullOrEmpty(tpath)) { tpath = tpath.Substring(16); // Remove System.String prefix } } if (string.IsNullOrEmpty(tpath)) { MessageBox.Show("Tizen SDK path is undefined"); throw new WizardCancelledException(); } PrepareListOfTemplates(); if (nativeTemplates.Count <= 0) { MessageBox.Show("Tizen SDK template list is empty. Check toolchains."); throw new WizardCancelledException(); } VsProjectHelper.Initialize(); VsProjectHelper prjHelperInstance = VsProjectHelper.GetInstance; string solutionDirectory = replacementsDictionary["$solutiondirectory$"]; destinationDirectory = replacementsDictionary["$destinationdirectory$"]; ProjectWizardViewTizenNative nWizard = new ProjectWizardViewTizenNative(replacementsDictionary["$projectname$"], solutionDirectory, nativeTemplates); if (nWizard.ShowDialog() == false) { EnvDTE80.DTE2 dte2 = VsProjectHelper.GetInstance.GetDTE2(); if (replacementsDictionary["$exclusiveproject$"] == "True") { Directory.Delete(solutionDirectory, true); dte2.ExecuteCommand("File.NewProject"); } else { Directory.Delete(destinationDirectory, true); dte2.ExecuteCommand("File.AddNewProject"); } throw new WizardCancelledException(); } // Fix values replacementsDictionary["$tizen_profile$"] = nWizard.data.profile; replacementsDictionary["$tizen_toolset$"] = nWizard.data.toolset; replacementsDictionary["$tizen_api$"] = nWizard.data.tizenApi; replacementsDictionary["$tizen_project_type$"] = nWizard.data.projectType; replacementsDictionary["$tizen_template_name$"] = nWizard.data.projectType; string safename = replacementsDictionary["$safeprojectname$"]; replacementsDictionary["$tizen_name$"] = safename.ToLower(); replacementsDictionary["$tizen_output$"] = "lib" + replacementsDictionary["$tizen_name$"] + ".so"; // At this moment project directory exists but empty, remove and regenerate it Directory.Delete(replacementsDictionary["$destinationdirectory$"]); Process process = getTizenBatProcess(); process.StartInfo.Arguments = $"create native-project -n {safename} -p {nWizard.data.profile}-{nWizard.data.tizenApi} -t {nWizard.data.projectType}"; process.StartInfo.WorkingDirectory = solutionDirectory; //debug //process.StartInfo.Arguments = " /A/K " + process.StartInfo.FileName + " " + process.StartInfo.Arguments; //process.StartInfo.FileName = "cmd.exe"; //process.StartInfo.CreateNoWindow = false; //process.StartInfo.RedirectStandardInput= false; //process.StartInfo.RedirectStandardError = false; //process.StartInfo.RedirectStandardOutput = false; process.Start(); process.WaitForExit(); int code = process.ExitCode; process.Close(); if (code != 0) { MessageBox.Show("Template generation fail for {safename}"); throw new WizardCancelledException(); } // Parse files using (StreamReader input = new StreamReader(Path.Combine(destinationDirectory, "project_def.prop"))) { string line; while ((line = input.ReadLine()) != null) { var match = keywords.Match(line); if (match.Success) { string key = match.Groups[1].Value; string value = match.Groups[2].Value; switch (key) { case "APPNAME": replacementsDictionary["$tizen_name$"] = value; break; case "type": fixType(replacementsDictionary, value); break; } } } } }
#pragma warning restore VSTHRD010 private void Execute(bool withRegeneration) { var generationItems = new List <GenerationItem>(); var projectDictionary = new Dictionary <Project, Tuple <HashSet <TargetAsset>, HashSet <IReferencedAssembly> > >(); var messageLogger = new AggregateLogger(); messageLogger.Initialize(); Attempt.Action( () => { ThreadHelper.ThrowIfNotOnUIThread(); #pragma warning disable VSTHRD010 if (!IsAvailable) { throw new InvalidOperationException("Cannot generate unit tests for this item because no supported files were found"); } var options = _package.Options; var sources = SolutionUtilities.GetSelectedFiles(_dte, true, options.GenerationOptions).Where(ProjectItemModel.IsSupported).ToList(); var targetProjects = new Dictionary <Project, Project>(); foreach (var source in sources) { if (targetProjects.ContainsKey(source.Project)) { continue; } if (source.TargetProject == null && options.GenerationOptions.CreateProjectAutomatically) { var testProject = SolutionUtilities.CreateTestProjectInCurrentSolution(_dte, source.Project, options.GenerationOptions); ReferencesHelper.AddNugetPackagesToProject(testProject, StandardReferenceHelper.GetReferencedNugetPackages(options), messageLogger.LogMessage, _package); } var targetProject = source.TargetProject; if (targetProject == null && !options.GenerationOptions.AllowGenerationWithoutTargetProject) { throw new InvalidOperationException("Cannot create tests for '" + Path.GetFileName(source.FilePath) + "' because there is no project '" + source.TargetProjectName + "'"); } if (targetProject != null) { targetProjects[source.Project] = targetProject; projectDictionary[targetProject] = Tuple.Create(new HashSet <TargetAsset>(), new HashSet <IReferencedAssembly>()); } } foreach (var source in sources) { var projectItem = source.Item; if (!withRegeneration && TargetFinder.FindExistingTargetItem(source, options.GenerationOptions, out _) == FindTargetStatus.Found) { if (sources.Count == 1) { throw new InvalidOperationException("Cannot create tests for '" + Path.GetFileName(source.FilePath) + "' because tests already exist. If you want to re-generate tests for this item, hold down the left Shift key and right-click the item."); } continue; } var nameParts = VsProjectHelper.GetNameParts(projectItem); targetProjects.TryGetValue(source.Project, out var targetProject); var targetProjectItems = TargetFinder.FindTargetFolder(targetProject, nameParts, true, out var targetPath); if (targetProjectItems == null && !options.GenerationOptions.AllowGenerationWithoutTargetProject) { // we asked to create targetProjectItems - so if it's null we effectively had a problem getting to the target project throw new InvalidOperationException("Cannot create tests for '" + Path.GetFileName(source.FilePath) + "' because there is no project '" + source.TargetProjectName + "'"); } var sourceNameSpaceRoot = VsProjectHelper.GetProjectRootNamespace(source.Project); HashSet <TargetAsset> requiredAssets; HashSet <IReferencedAssembly> referencedAssemblies; if (targetProject != null && projectDictionary.TryGetValue(targetProject, out var targetProjectEntry)) { requiredAssets = targetProjectEntry.Item1; referencedAssemblies = targetProjectEntry.Item2; } else { requiredAssets = new HashSet <TargetAsset>(); referencedAssemblies = new HashSet <IReferencedAssembly>(); } Func <string, string> namespaceTransform; if (source.TargetProject != null) { var targetNameSpaceRoot = VsProjectHelper.GetProjectRootNamespace(source.TargetProject); namespaceTransform = NamespaceTransform.Create(sourceNameSpaceRoot, targetNameSpaceRoot); } else { namespaceTransform = x => x + ".Tests"; } generationItems.Add(new GenerationItem(source, null, targetProjectItems, targetPath, requiredAssets, referencedAssemblies, namespaceTransform, options.GenerationOptions)); } #pragma warning restore VSTHRD010 }, _package); if (generationItems.Any()) { _package.JoinableTaskFactory.RunAsync(() => Attempt.ActionAsync(() => CodeGenerator.GenerateCodeAsync(generationItems, withRegeneration, _package, projectDictionary, messageLogger), _package)); } }
public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams) { VsProjectHelper.Initialize(); VsProjectHelper prjHelperInstance = VsProjectHelper.GetInstance; List <string> prjlist = new List <string>(); Project prj = null; prjlist.Add("Empty"); IEnumerator prjEnum = prjHelperInstance.GetProjects().GetEnumerator(); while (prjEnum.MoveNext()) { prj = (Project)prjEnum.Current; prjlist.Add(prj.Name); } ProjectWizardViewTizenCrossPlatform nWizard = new ProjectWizardViewTizenCrossPlatform(replacementsDictionary["$projectname$"], replacementsDictionary["$solutiondirectory$"], Trans_boolean(replacementsDictionary["$hasCommon$"]), Trans_boolean(replacementsDictionary["$hasMobile$"]), Trans_boolean(replacementsDictionary["$hasTV$"]), Trans_boolean(replacementsDictionary["$hasWearable$"]), Trans_boolean(replacementsDictionary["$hasSharedLib$"]), prjlist); if (nWizard.ShowDialog() == false) { EnvDTE80.DTE2 dte2 = VsProjectHelper.GetInstance.GetDTE2(); if (replacementsDictionary["$exclusiveproject$"] == "True") { Directory.Delete(replacementsDictionary["$solutiondirectory$"], true); dte2.ExecuteCommand("File.NewProject"); } else { Directory.Delete(replacementsDictionary["$destinationdirectory$"], true); dte2.ExecuteCommand("File.AddNewProject"); } throw new WizardCancelledException(); } else { replacementsDictionary["$select_common$"] = nWizard.manifestData.Select_common.ToString().ToLower(); replacementsDictionary["$select_mobile$"] = nWizard.manifestData.Select_mobile.ToString().ToLower(); replacementsDictionary["$select_tv$"] = nWizard.manifestData.Select_tv.ToString().ToLower(); replacementsDictionary["$select_wearable$"] = nWizard.manifestData.Select_wearable.ToString().ToLower(); if (nWizard.manifestData.Shared_library) { replacementsDictionary["$hasSharedLib$"] = "true"; } else { replacementsDictionary["$hasSharedLib$"] = nWizard.manifestData.Selected_project_name; } } // Project Name change int idx = replacementsDictionary["$safeprojectname$"].IndexOf("Tizen"); string prjName = replacementsDictionary["$safeprojectname$"]; replacementsDictionary["$namespace$"] = prjName; replacementsDictionary["$lib_prjName$"] = prjName; if (idx != -1)// && Trans_boolean(replacementsDictionary["$hasSharedLib$"])) { if (replacementsDictionary["$hasSharedLib$"] != "true") { replacementsDictionary["$common_prjName$"] = prjName; } else { replacementsDictionary["$common_prjName$"] = prjName + ".Tizen"; } replacementsDictionary["$mobile_prjName$"] = prjName + ".Mobile"; replacementsDictionary["$tv_prjName$"] = prjName + ".TV"; replacementsDictionary["$wearable_prjName$"] = prjName + ".Wearable"; } else { replacementsDictionary["$common_prjName$"] = prjName + ".Tizen"; replacementsDictionary["$mobile_prjName$"] = prjName + ".Tizen.Mobile"; replacementsDictionary["$tv_prjName$"] = prjName + ".Tizen.TV"; replacementsDictionary["$wearable_prjName$"] = prjName + ".Tizen.Wearable"; } }