コード例 #1
0
        private static bool CreateTodaysClassIfNeeded()
        {
            var day                = ForceDay ?? DateTime.Now.Day;
            var year               = DateTime.Now.Year;
            var className          = GetClassName();
            var projectDirectory   = GetBaseDirectory();
            var classFilename      = $"{className}.cs";
            var classFileFullPath  = Path.Combine(projectDirectory, classFilename);
            var puzzleFilename     = $"input{day:00}.txt";
            var puzzleFileFullPath = Path.Combine(projectDirectory, puzzleFilename);

            if (File.Exists(classFileFullPath))
            {
                return(false);
            }

            Console.WriteLine($"{classFilename} not found, will create.");
            var classContempt = DayTemplate.Replace("#day#", $"{day:00}");

            File.WriteAllText(classFileFullPath, classContempt);
            AddToGit(projectDirectory, classFilename);
            Console.WriteLine($"{classFilename} created and added to git");

            Console.Write($"Fetching puzzle input...");
            try
            {
                var puzzleContent = GetPuzzleInput(year, day);
                Console.WriteLine($" done.");
                File.WriteAllText(puzzleFileFullPath, puzzleContent.Trim());
                AddToGit(projectDirectory, puzzleFilename);
                Console.WriteLine($"{puzzleFilename} created and added to git");
            }
            catch (Exception e)
            {
                Console.WriteLine($" failed: {e.Message}");
                File.WriteAllText(puzzleFileFullPath, "");
                AddToGit(projectDirectory, puzzleFilename);
                Console.WriteLine($"Created empty {puzzleFilename} and added to git");
            }

            var projectFile = Path.Combine(projectDirectory, "AdventOfCode2020.csproj");

            var p = new Microsoft.Build.Evaluation.Project(projectFile);

            p.AddItem("Compile", classFilename);
            var kvp = new KeyValuePair <string, string>("CopyToOutputDirectory", "PreserveNewest");

            p.AddItem("Content", puzzleFilename, new [] { kvp });
            p.Save();

            Console.WriteLine($"Class and data files created. Execution halted. Please edit {classFilename} and then run again.");

            return(true);
        }
コード例 #2
0
        public void AddDocument(string filePath, string logicalPath = null)
        {
            var relativePath = FilePathUtilities.GetRelativePath(_loadedProject.DirectoryPath, filePath);

            Dictionary <string, string> metadata = null;

            if (logicalPath != null && relativePath != logicalPath)
            {
                metadata = new Dictionary <string, string>();
                metadata.Add("link", logicalPath);
                relativePath = filePath; // link to full path
            }

            _loadedProject.AddItem("Compile", relativePath, metadata);
        }
コード例 #3
0
        private static void AddStepDefinitonToIntelliSenseProject(List <NodeFeature> features, string pathToFeatureFile, string pathToIntelliSenseProject)
        {
            foreach (var feature in features)
            {
                List <StepInstance> si = new List <StepInstance>();
                var steps = new List <NodeStep>();
                feature.Scenarios.ForEach(s => steps.AddRange(s.Steps));
                var uniqueSteps = GeneratorHelper.FindUniqueSteps(new List <NodeStep>(), steps);

                foreach (var step in uniqueSteps)
                {
                    StepDefinitionType    type;
                    StepDefinitionKeyword keyword;
                    string stepNameWithoutType;

                    if (step.Name.StartsWith("Given"))
                    {
                        type                = StepDefinitionType.Given;
                        keyword             = StepDefinitionKeyword.Given;
                        stepNameWithoutType = step.Name.Substring("Given".Length);
                    }
                    else if (step.Name.StartsWith("When"))
                    {
                        type                = StepDefinitionType.When;
                        keyword             = StepDefinitionKeyword.When;
                        stepNameWithoutType = step.Name.Substring("When".Length);
                    }
                    else
                    {
                        type                = StepDefinitionType.Then;
                        keyword             = StepDefinitionKeyword.Then;
                        stepNameWithoutType = step.Name.Substring("Then".Length);
                    }
                    string scenarioName = feature.Scenarios.First(scenario => scenario.Steps.Contains(step)).Name;
                    si.Add(new StepInstance(type, keyword, stepNameWithoutType, stepNameWithoutType, new StepContext(feature.Name, scenarioName, new List <string>(), CultureInfo.CurrentCulture)));
                }

                var stepDefSkeleton = new StepDefinitionSkeletonProvider(new SpecFlowCSkeletonTemplateProvider(), new StepTextAnalyzer());
                var template        = stepDefSkeleton.GetBindingClassSkeleton(TechTalk.SpecFlow.ProgrammingLanguage.CSharp, si.ToArray(), "CppUnitTest", feature.Name, StepDefinitionSkeletonStyle.MethodNamePascalCase, CultureInfo.CurrentCulture);

                string basePathToFeatures            = Path.GetDirectoryName(pathToFeatureFile);
                string basePathToIntelliSenseProject = Path.GetDirectoryName(pathToIntelliSenseProject);
                _csProj = _csProj ?? GetUnloadedProject(pathToIntelliSenseProject);

                var stepDefinitionDirPathInProj = string.Format("Steps\\{0}\\", PROJECT_NAME);
                var stepDefinitionDirPath       = string.Format("{0}\\{1}", basePathToIntelliSenseProject, stepDefinitionDirPathInProj);

                var filePathInProjFile = string.Format("{0}{1}_step.cs", stepDefinitionDirPathInProj, feature.Name);
                var filePath           = string.Format("{0}{1}_step.cs", stepDefinitionDirPath, feature.Name);

                if (!_csProj.GetItems("Compile").Any(item => item.UnevaluatedInclude == filePathInProjFile))
                {
                    Console.WriteLine(string.Format("Generating Step Definition file for IntelliSense support: {0}", filePathInProjFile));
                    Directory.CreateDirectory(stepDefinitionDirPath);
                    File.WriteAllText(filePath, template);
                    _csProj.AddItem("Compile", filePathInProjFile);
                    _isDirtyCsProj = true;
                }
            }
        }
コード例 #4
0
        public ArrayList SetCompileItems(ArrayList L)
        {
            Microsoft.Build.Evaluation.Project pc = new Microsoft.Build.Evaluation.Project(FileName);

            if (pc == null)
            {
                return(L);
            }

            string s = Path.GetDirectoryName(FileName);

            ArrayList R = GetItems(pc, "Compile", false);

            foreach (string p in L)
            {
                string refs = GetRelativePath(s, p);

                int i = R.IndexOf(refs);

                if (i < 0)
                {
                    pc.AddItem("Compile", refs);
                }
            }

            pc.Save(FileName);

            pc.ProjectCollection.UnloadAllProjects();

            return(L);
        }
コード例 #5
0
        /// <summary>
        /// Adds new category after clicking a button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddNewCategoryButton_Click(object sender, RoutedEventArgs e)
        {
            string polishNameOfCategory  = PolishNameTextBox.Text;
            string englishNameOfCategory = EnglishNameTextBox.Text;

            if (polishNameOfCategory == "Polska" || polishNameOfCategory == null || englishNameOfCategory == "Angielska" || englishNameOfCategory == null)
            {
                MessageBox.Show("Nie zostały podane wszystkie potrzebne dane.");
            }
            else
            {
                string nameOfTextFile = englishNameOfCategory.ToLower() + ".txt";
                string foo            = "..\\..\\";
                string pathToTextFile = foo + nameOfTextFile;

                try
                {
                    FileStream fileStream = new FileStream(@pathToTextFile, FileMode.CreateNew, FileAccess.Write);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                if (File.Exists(@pathToTextFile))
                {
                    var build = new Microsoft.Build.Evaluation.Project(@"..\\..\\Fiszki.csproj");
                    build.AddItem("Resource", nameOfTextFile);
                    build.Save();

                    Directory.CreateDirectory(@"..\\..\\Photos\\" + englishNameOfCategory);

                    FileStream fileStream = new FileStream(@"..\\..\\myOwnCategories.txt", FileMode.Open, FileAccess.ReadWrite);
                    try
                    {
                        using (StreamWriter sw = new StreamWriter(fileStream))
                        {
                            sw.BaseStream.Seek(0, SeekOrigin.End);
                            sw.WriteLine(polishNameOfCategory + " " + englishNameOfCategory);
                            sw.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }
            MessageBoxResult result = MessageBox.Show("Dodano kategorię o nazwie: " + polishNameOfCategory + ". Jeśli chcesz dodać następną kategorię, naciśnij tak, a jeśli chcesz wrócić do menu, naciśnij nie.", "Fiszki", MessageBoxButton.YesNo, MessageBoxImage.Information, MessageBoxResult.Yes);

            if (result == MessageBoxResult.Yes)
            {
                setPage = new SetPage(5, MessageBoxResult.Yes);
            }
            else
            {
                PolishNameTextBox.Name  = "Polska";
                EnglishNameTextBox.Name = "Angielska";
            }
        }
コード例 #6
0
ファイル: class.cs プロジェクト: izikf89/web.api2_angular2
        public static void AngularExist()
        {
            pathToAngularProject = Directory.GetDirectories(rootFolderPath + "/angular/")[0];
            projectAngularName   = pathToAngularProject.Remove(0, pathToAngularProject.LastIndexOf('/') + 1);
            pathToIndexFile      = pathToAngularProject + "/dist/index.html";

            string csproj = File.ReadAllText(rootFolderPath + "/" + webProjectName + ".csproj");

            if (!csproj.Contains(@"angular\" + webProjectName + @"\dist\*.*"))
            {
                var p = new Microsoft.Build.Evaluation.Project(rootFolderPath + "/" + webProjectName + ".csproj");
                p.AddItem("Content", @"angular\" + webProjectName + @"\dist\*.*");
                p.Save();
            }

            watcherDist.Path = pathToAngularProject;
            watcherDist.EnableRaisingEvents = true;

            if (Directory.Exists(pathToAngularProject + "/dist"))
            {
                if (File.Exists(pathToIndexFile))
                {
                    CopyIndex();
                }
            }
        }
コード例 #7
0
        public void GenerateUnitTestsLogic(List <string> projClasses)
        {
            var dte = (DTE2)Microsoft.VisualStudio.Shell.ServiceProvider
                      .GlobalProvider.GetService(typeof(EnvDTE.DTE));
            var selectedProjectName = GetSelectedProjectName(dte);
            var unitTestProjectName = string.Format("{0}_Tests", selectedProjectName);

            // discover solution/project types and create an object factory
            var solutionFullPath = GetSolutionFullPath(dte);

            // generate unit tests for the analyzed project
            var    generatedTestClassesDirectory = CreateUnitTestsProject(dte, unitTestProjectName);
            string packagesPath = GetSolutionPackagesFolder(dte);

            var unitTestGenerator = new UnitTestGenerator(generatedTestClassesDirectory,
                                                          packagesPath, selectedProjectName);
            List <string> testClasses = unitTestGenerator.GenerateUnitTestsForClass(solutionFullPath,
                                                                                    unitTestProjectName, projClasses);

            // add test classes to project
            string csprojPath = string.Format(@"{0}\\{1}\\{2}{3}", GetSolutionPath(dte),
                                              unitTestProjectName, unitTestProjectName, ".csproj");

            var p = new Microsoft.Build.Evaluation.Project(csprojPath);

            foreach (string generatedTestClass in testClasses)
            {
                p.AddItem("Compile", generatedTestClass);
            }
            p.Save();
        }
コード例 #8
0
        public void CreateFolder(string folder, VSProjectItem ps)
        {
            Microsoft.Build.Evaluation.Project pc = new Microsoft.Build.Evaluation.Project(FileName);

            if (pc == null)
            {
                return;
            }

            string s = Path.GetDirectoryName(FileName);

            ArrayList R = GetItems(pc, "Folder", false);

            if (ps == null || ps.ItemType != "Folder")
            {
                string refs = GetRelativePath(s, folder);

                int i = R.IndexOf(refs);

                if (i < 0)
                {
                    pc.AddItem("Folder", refs);
                }
            }
            else
            {
                string g = ps.Include;

                g = g + "\\" + folder;

                string refs = GetRelativePath(s, g);

                int i = R.IndexOf(refs);

                if (i < 0)
                {
                    pc.AddItem("Folder", refs);
                }
            }

            pc.Save(FileName);

            pc.ProjectCollection.UnloadAllProjects();
        }
        private static void Test_Microsoft_Build_Evaluation()
        {
            var p = new Microsoft.Build.Evaluation.Project
                    (
                //"/Projects/hw-tools/SampleProjectKreator/samples/App.XamarinAndroid/App.XamarinAndroid.csproj"
                "/Projects/hw-tools/SampleProjectKreator/samples/Bindings.Sample.Project.Kreator.App.Console.Mono/Bindings.Sample.Project.Kreator.App.Console.Mono.csproj"
                    );

            p.AddItem("Compile", @"C:\folder\file.cs");
            p.Save();
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: SCRUMdifferent/specflowC
 private static void AddFeatureFileLinkToIntelliSenseProject(string featureFilePath, string featureDir, string pathToIntelliSenseProject)
 {
     _csProj = _csProj ?? GetUnloadedProject(pathToIntelliSenseProject);
     featureFilePath = MakeLinkRelativeToIntelliSenseProject(featureFilePath, featureDir);
     var featureFileLink = featureFilePath.Replace(@"..\", string.Empty);
     if (!_csProj.Items.Any(item => item.GetMetadataValue("Link") == featureFileLink))
     {
         _csProj.AddItem("None", featureFilePath, new Dictionary<string, string> { { "Link", featureFileLink } });
         _isDirtyCsProj = true;
     }
 }
コード例 #11
0
        private static void AddFileToProject(string workingDirectory, string generatedClassFileName)
        {
            // todo: get csproj file name dynamically
            // Error in Microsoft.Build: InternalErrorException: https://github.com/Microsoft/msbuild/issues/1889 --> Solution: Install-Package Microsoft.Build.Utilities.Core -Version 15.1.1012
            var project = new Microsoft.Build.Evaluation.Project(Path.Combine(workingDirectory, "XmlToCode.csproj"));

            if (project.Items.FirstOrDefault(i => i.EvaluatedInclude == generatedClassFileName) == null)
            {
                project.AddItem("Compile", generatedClassFileName);
                project.Save();
            }
        }
コード例 #12
0
        private static void AddFilesToCppProject(string pathToFile, string featureDir, string pathToCppProject)
        {
            _cppProj = _cppProj ?? GetUnloadedProject(pathToCppProject);

            pathToFile = MakeFeatureDirRelativeToCppProject(pathToFile, featureDir);

            string type = CppFileType(pathToFile);

            if (!_cppProj.GetItems(type).Any(item => item.UnevaluatedInclude == pathToFile))
            {
                _cppProj.AddItem(type, pathToFile);
                _isDirtyCppProj = true;
            }
        }
コード例 #13
0
        private static void AddFeatureFileLinkToIntelliSenseProject(string featureFilePath, string featureDir, string pathToIntelliSenseProject)
        {
            _csProj         = _csProj ?? GetUnloadedProject(pathToIntelliSenseProject);
            featureFilePath = MakeLinkRelativeToIntelliSenseProject(featureFilePath, featureDir);
            var featureFileLink = featureFilePath.Replace(@"..\", string.Empty);

            if (!_csProj.Items.Any(item => item.GetMetadataValue("Link") == featureFileLink))
            {
                _csProj.AddItem("None", featureFilePath, new Dictionary <string, string> {
                    { "Link", featureFileLink }
                });
                _isDirtyCsProj = true;
            }
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: SCRUMdifferent/specflowC
        private static void AddFilesToCppProject(string pathToFile, string featureDir, string pathToCppProject)
        {
            _cppProj = _cppProj ?? GetUnloadedProject(pathToCppProject);

            pathToFile = MakeFeatureDirRelativeToCppProject(pathToFile, featureDir);

            string type = CppFileType(pathToFile);

            if (!_cppProj.GetItems(type).Any(item => item.UnevaluatedInclude == pathToFile))
            {
                _cppProj.AddItem(type, pathToFile);
                _isDirtyCppProj = true;
            }
        }
コード例 #15
0
        private void AddFileToProject(Microsoft.Build.Evaluation.Project project, string filePath)
        {
            try
            {
                LogAndDisplay("Adding new files to project: " + project.DirectoryPath + Environment.NewLine + filePath);

                project.AddItem("Compile", filePath);
                project.Save();
            }
            catch (Exception ex)
            {
                LogAndDisplay("Failed to add file to project:" + Environment.NewLine + project.DirectoryPath + Environment.NewLine + filePath);
                LogError(ex.Message);
            }
        }
コード例 #16
0
 internal static void CreateJsonFile(string jsonToWrite, string jsonFileName)
 {
     try
     {
         var jsonFile = Path.Combine(DirectoryHandler.DirectoryCreation(Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName,
                                                                                     "UFHtmlExtractor")), jsonFileName + ".json");
         File.WriteAllText(jsonFile, jsonToWrite, Encoding.UTF8);
         var projFilePath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
         var p1           = new Microsoft.Build.Evaluation.Project(Path.Combine(projFilePath,
                                                                                Path.GetFileName(projFilePath.TrimEnd(Path.DirectorySeparatorChar)) + ".csproj"));
         p1.AddItem("None", Path.Combine("UFHtmlExtractor", jsonFileName + ".json"));
         p1.Save();
     }
     catch (Exception ex)
     {
         Console.WriteLine("Creation of Json File, Failed!");
     }
 }
コード例 #17
0
 public static void Finalise()
 {
     //AutomateAddFile.IncludeInProject(FilesToInclude);
     if (FilesToInclude != null && FilesToInclude.Count > 0)
     {
         var projFilePath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
         var p1           = new Microsoft.Build.Evaluation.Project(Path.Combine(projFilePath,
                                                                                Path.GetFileName(System.Reflection.Assembly.GetCallingAssembly().Location).Replace(".dll", "") + ".csproj"));
         foreach (string filePath in FilesToInclude)
         {
             p1.AddItem("Compile", filePath + ".cs");
         }
         p1.Save();
     }
     else
     {
         Console.WriteLine("Either Unified Code Generation Intiate functionality was not used or no files were generated to include in Project");
     }
 }
コード例 #18
0
        public void Add(IEnumerable <TypingsFile> files)
        {
            var updated = false;
            var project = new Microsoft.Build.Evaluation.Project(_projectFileFullPath);

            foreach (var file in files)
            {
                var relativePath = GetRelativePath(file);
                if (project.Items.FirstOrDefault(i => i.EvaluatedInclude == relativePath) == null)
                {
                    updated = true;
                    project.AddItem("TypeScriptCompile", relativePath);
                }
            }
            if (updated)
            {
                project.Save();
            }
        }
コード例 #19
0
        public void IncludeProject()
        {
            var projFile = new Microsoft.Build.Evaluation.Project(ProjFile);

            foreach (string file in System.IO.Directory.GetFiles(Directory, "*.feature", SearchOption.AllDirectories))
            {
                var fileName         = Path.GetFileName(file);
                var relativeFilePath = MakeRelative(file, ProjFile).Replace("/", "\\");
                var projectItem      = projFile.Items.FirstOrDefault(i => i.EvaluatedInclude == relativeFilePath);
                if (projectItem == null)
                {
                    projFile.AddItem("None", relativeFilePath, new[]
                    {
                        new KeyValuePair <string, string>("Generator", "SpecFlowSingleFileGenerator"),
                        new KeyValuePair <string, string>("LastGenOutput", $"{fileName}.cs")
                    });
                }
            }
            projFile.Save();
        }
コード例 #20
0
        //---------------------------------------------------------------------------

        public bool AddFile(string source, string destination)
        {
            try
            {
                if (!string.IsNullOrEmpty(source) && !source.Equals(destination))
                {
                    File.Copy(source, Path.Combine(RootPath, destination));
                }

                string path    = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\", "EvershockGame/EvershockGame.csproj"));
                var    project = new Microsoft.Build.Evaluation.Project(@path);
                project.AddItem("Content", string.Format(@"Content\{0}", destination.Replace('/', '\\')), new List <KeyValuePair <string, string> > {
                    new KeyValuePair <string, string>("CopyToOutputDirectory", "PreserveNewest")
                });
                project.Save();
                return(true);
            }
            catch (Exception e) { }
            return(false);
        }
コード例 #21
0
        public void WriteFile(string solutionFilePath)
        {
            var    projectFileLocation = $"{solutionFilePath}\\{_projectFolderName}";
            string fileName            = $"{ClassUnderTest}Test.cs";
            string filePath            = Path.Combine(projectFileLocation, fileName);

            if (File.Exists(filePath))
            {
                var sb = AppendMethodToFile(filePath);
                File.WriteAllText(filePath, sb.ToString());
            }
            else
            {
                var p = new Microsoft.Build.Evaluation.Project($"{projectFileLocation}\\{_projectName}.csproj");
                p.AddItem("Compile", $"{projectFileLocation}\\{fileName}");
                p.Save();
                var pageContent = TransformText();
                File.WriteAllText(filePath, pageContent);
            }
        }
コード例 #22
0
ファイル: ProjectFile.cs プロジェクト: zuckerthoben/roslyn
        public void AddDocument(string filePath, string logicalPath = null)
        {
            var relativePath = PathUtilities.GetRelativePath(_loadedProject.DirectoryPath, filePath);

            Dictionary <string, string> metadata = null;

            if (logicalPath != null && relativePath != logicalPath)
            {
                metadata = new Dictionary <string, string>
                {
                    { MetadataNames.Link, logicalPath }
                };

                relativePath = filePath; // link to full path
            }

            _loadedProject.AddItem(ItemNames.Compile, relativePath, metadata);
        }
コード例 #23
0
        /// <summary>
        /// Adds the users image.
        /// </summary>
        private void AddUsersImage()
        {
            nameOfCategory = ((ComboBoxItem)CategoryComboBox.SelectedItem).Name;
            string foo     = "..\\..\\Photos\\";
            string newPath = foo + nameOfCategory + "\\" + imageName;

            System.IO.File.Copy(@pathToImage, @newPath);

            string     foo1           = "..\\..\\";
            string     pathToTextFile = foo1 + nameOfCategory.ToLower() + ".txt";
            Encoding   enc            = Encoding.Default;
            FileStream file           = new FileStream(pathToTextFile, FileMode.Open, FileAccess.Write);

            try
            {
                using (StreamWriter stream = new StreamWriter(file, enc))
                {
                    stream.BaseStream.Seek(0, SeekOrigin.End);
                    stream.WriteLine(polishWord + " " + englishWord + " " + newPath);
                    stream.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            var build = new Microsoft.Build.Evaluation.Project(@"..\\..\\Fiszki.csproj");

            build.AddItem("Resource", "Photos\\" + nameOfCategory + "\\" + imageName);
            build.Save();

            MessageBox.Show("Dodano słowo " + polishWord + " do kategorii " + nameOfCategory + " , ścieżka zdjęcia: " + newPath);
            MainPage mainPage = new MainPage();

            Application.Current.MainWindow.Content = mainPage;
        }
コード例 #24
0
        public static void InterpretCommand(string input)
        {
            switch (input.ToLower())
            {
            case "compile":
                System.Diagnostics.Process.Start("Compiler.bat");
                Environment.Exit(0);
                break;

            case "test":
                Test.MainMethod();
                break;
            }

            string[] args = input.Split(' ');
            if (input.ToLower().StartsWith("edit"))
            {
                if (args.Length > 1)
                {
                    if (File.Exists(ProjectPath + args[1]))
                    {
                        string[] code = File.ReadAllLines(ProjectPath + args[1]);
                        Editor.LoadCode(ProjectPath + args[1], code);
                        Editor.Show();
                    }
                }
            }
            else if (input.ToLower().StartsWith("create"))
            {
                if (args.Length > 1)
                {
                    if (!File.Exists(ProjectPath + args[1]))
                    {
                        File.Create(ProjectPath + args[1]);
                        var p = new Microsoft.Build.Evaluation.Project(ProjectPath + "Hal.csproj");
                        p.AddItem("Compile", ProjectPath + args[1]);
                        p.Save();
                    }
                }
            }
            else if (input.ToLower().StartsWith("remove"))
            {
                if (args.Length > 1)
                {
                    if (File.Exists(ProjectPath + args[1]))
                    {
                        List <string> csproj = new List <string>(File.ReadAllLines(ProjectPath + "Hal.csproj"));

                        string line = "<Compile Include=\"" + ProjectPath + args[1] + "\" />";
                        for (int i = 0; i < csproj.Count; i++)
                        {
                            if (csproj[i].Contains(line))
                            {
                                csproj.RemoveAt(i);
                            }
                        }

                        File.Delete(ProjectPath + args[1]);

                        File.WriteAllLines(ProjectPath + "Hal.csproj", csproj.ToArray());
                    }
                }
            }
        }
コード例 #25
0
ファイル: Program.cs プロジェクト: SCRUMdifferent/specflowC
        private static void AddStepDefinitonToIntelliSenseProject(List<NodeFeature> features, string pathToFeatureFile, string pathToIntelliSenseProject)
        {
            foreach (var feature in features)
            {
                List<StepInstance> si = new List<StepInstance>();
                var steps = new List<NodeStep>();
                feature.Scenarios.ForEach(s => steps.AddRange(s.Steps));
                var uniqueSteps = GeneratorHelper.FindUniqueSteps(new List<NodeStep>(), steps);

                foreach (var step in uniqueSteps)
                {
                    StepDefinitionType type;
                    StepDefinitionKeyword keyword;
                    string stepNameWithoutType;

                    if (step.Name.StartsWith("Given"))
                    {
                        type = StepDefinitionType.Given;
                        keyword = StepDefinitionKeyword.Given;
                        stepNameWithoutType = step.Name.Substring("Given".Length);
                    }
                    else if (step.Name.StartsWith("When"))
                    {
                        type = StepDefinitionType.When;
                        keyword = StepDefinitionKeyword.When;
                        stepNameWithoutType = step.Name.Substring("When".Length);
                    }
                    else
                    {
                        type = StepDefinitionType.Then;
                        keyword = StepDefinitionKeyword.Then;
                        stepNameWithoutType = step.Name.Substring("Then".Length);
                    }
                    string scenarioName = feature.Scenarios.First(scenario => scenario.Steps.Contains(step)).Name;
                    si.Add(new StepInstance(type, keyword, stepNameWithoutType, stepNameWithoutType, new StepContext(feature.Name, scenarioName, new List<string>(), CultureInfo.CurrentCulture)));
                }

                var stepDefSkeleton = new StepDefinitionSkeletonProvider(new SpecFlowCSkeletonTemplateProvider(), new StepTextAnalyzer());
                var template = stepDefSkeleton.GetBindingClassSkeleton(TechTalk.SpecFlow.ProgrammingLanguage.CSharp, si.ToArray(), "CppUnitTest", feature.Name, StepDefinitionSkeletonStyle.MethodNamePascalCase, CultureInfo.CurrentCulture);

                string basePathToFeatures = Path.GetDirectoryName(pathToFeatureFile);
                string basePathToIntelliSenseProject = Path.GetDirectoryName(pathToIntelliSenseProject);
                _csProj = _csProj ?? GetUnloadedProject(pathToIntelliSenseProject);

                var stepDefinitionDirPathInProj = string.Format("Steps\\{0}\\", PROJECT_NAME);
                var stepDefinitionDirPath = string.Format("{0}\\{1}", basePathToIntelliSenseProject, stepDefinitionDirPathInProj);

                var filePathInProjFile = string.Format("{0}{1}_step.cs", stepDefinitionDirPathInProj, feature.Name);
                var filePath = string.Format("{0}{1}_step.cs", stepDefinitionDirPath, feature.Name);

                if (!_csProj.GetItems("Compile").Any(item => item.UnevaluatedInclude == filePathInProjFile))
                {
                    Console.WriteLine(string.Format("Generating Step Definition file for IntelliSense support: {0}", filePathInProjFile));
                    Directory.CreateDirectory(stepDefinitionDirPath);
                    File.WriteAllText(filePath, template);
                    _csProj.AddItem("Compile", filePathInProjFile);
                    _isDirtyCsProj = true;
                }
            }
        }