Ejemplo n.º 1
0
 public ProjectItemImplementation(
     [NotNull] DteImplementation implementation,
     [NotNull] ProjectItemModel projectItemModel
     )
 {
     Implementation   = implementation;
     ProjectItemModel = projectItemModel;
 }
 public ActionResult Delete(ProjectItemModel pim, int id)
 {
     if (pib.RemoveProjectItem(id))
     {
         return(RedirectToAction("index", "ProjectItem"));
     }
     else
     {
         return(View(pim));
     }
 }
Ejemplo n.º 3
0
 public GenerationItem(ProjectItemModel source, SyntaxNode sourceSymbol, ProjectItems targetProjectItems, string targetPath, HashSet <TargetAsset> requiredAssets, HashSet <IReferencedAssembly> assemblyReferences, Func <string, string> namespaceTransform, IGenerationOptions options)
 {
     _options           = options ?? throw new ArgumentNullException(nameof(options));
     Source             = source ?? throw new ArgumentNullException(nameof(source));
     SourceSymbol       = sourceSymbol;
     TargetProjectItems = targetProjectItems;
     _targetPath        = targetPath;
     RequiredAssets     = requiredAssets ?? throw new ArgumentNullException(nameof(requiredAssets));
     NamespaceTransform = namespaceTransform ?? throw new ArgumentNullException(nameof(namespaceTransform));
     AssemblyReferences = assemblyReferences ?? throw new ArgumentNullException(nameof(assemblyReferences));
 }
 public ActionResult Edit(ProjectItemModel pim)
 {
     if (pib.ModifyProjectItem(pim))
     {
         return(RedirectToAction("index", "ProjectItem"));
     }
     else
     {
         var projects = pb.GetProjects();
         ViewBag.ProjectID = new SelectList(projects, "ID", "ProjectName", pim.ProjectID);
         var newpim = pib.GetProjectItem(pim.ID);
         return(View(newpim));
     }
 }
 public ActionResult Create(ProjectItemModel pim)
 {
     if (pib.AddProjectItem(pim))
     {
         return(RedirectToAction("index", "ProjectItem"));
     }
     else
     {
         ModelState.AddModelError("Error", "添加项目子项失败!");
         var projects = pb.GetProjects();
         ViewBag.ProjectID = new SelectList(projects, "ID", "ProjectName");
         return(View());
     }
 }
Ejemplo n.º 6
0
        private static void RecentFileCmd_Execute(object sender, CommandRunArgs args)
        {
            ProjectItemModel dataItem = args.DataItem as ProjectItemModel;

            if (!File.Exists(dataItem.LocalPath))
            {
                MessageBox.Show("该项目不存在", (Window)null, (string)null, MessageBoxImage.Info);
                Services.RecentFileService.ReloadRecentFiles();
            }
            else
            {
                GlobalCommand.OpenCmd.RaiseExecute((object)dataItem.LocalPath);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取项目子项
        /// </summary>
        /// <param name="id">项目子项ID</param>
        /// <returns></returns>
        public ProjectItemModel GetProjectItem(int id)
        {
            var pi = PRDB.ProjectItems.SingleOrDefault(pis => pis.ID == id);

            if (pi != null)
            {
                var pim = new ProjectItemModel();
                pim.ID = pi.ID;
                pim.ProjectItemName = pi.ItemName;
                pim.ProjectID       = pi.ProjectID;
                pim.Grade           = pi.Grade;
                pim.ProjectName     = pi.Project.ProjectName;
                return(pim);
            }
            return(null);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 按项目ID获取项目子项
        /// </summary>
        /// <param name="projectid">项目ID</param>
        /// <returns></returns>
        public List <ProjectItemModel> GetProjectItems(int projectid)
        {
            var pros = new List <ProjectItemModel>();

            foreach (var pi in PRDB.ProjectItems.Where(pi => pi.ProjectID == projectid).OrderBy(ite => ite.ID))
            {
                var pim = new ProjectItemModel();
                pim.ID = pi.ID;
                pim.ProjectItemName = pi.ItemName;
                pim.ProjectID       = pi.ProjectID;
                pim.Grade           = pi.Grade;
                pim.ProjectName     = pi.Project.ProjectName;
                pros.Add(pim);
            }
            return(pros);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 添加项目子项
 /// </summary>
 /// <param name="pim">项目子项</param>
 /// <returns></returns>
 public bool AddProjectItem(ProjectItemModel pim)
 {
     try
     {
         var pi = new ProjectItem();
         pi.ItemName  = pim.ProjectItemName;
         pi.Grade     = pim.Grade;
         pi.ProjectID = pim.ProjectID;
         PRDB.ProjectItems.Add(pi);
         PRDB.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 修改项目子项
 /// </summary>
 /// <param name="pim">项目子项</param>
 /// <returns></returns>
 public bool ModifyProjectItem(ProjectItemModel pim)
 {
     try
     {
         var pi = PRDB.ProjectItems.SingleOrDefault(pis => pis.ID == pim.ID);
         if (pi != null)
         {
             pi.ItemName  = pim.ProjectItemName;
             pi.Grade     = pim.Grade;
             pi.ProjectID = pim.ProjectID;
             PRDB.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         return(false);
     }
 }
#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);
        }