Пример #1
0
        //public VsHelper(BaseCustomTool host)
        //{
        //    solution = host.GetSolution();
        //    project = host.GetProject();
        //}

        //internal Solution GetSolution()
        //{
        //    Solution solution = (Solution)_host.GetService(typeof(Solution));
        //    Debug.Assert(solution != null);
        //    return solution;
        //}

        //public Project GetProject()
        //{
        //    // TODO fix, this does not work
        //    //DTE2 dte2 = (DTE2) Microsoft.VisualBasic.Interaction.CreateObject("VisualStudio.DTE.9.0", String.Empty);
        //    //object dteObject = Marshal.GetActiveObject("VisualStudio.DTE.9.0");
        //    //string dteName = Information.TypeName(dteObject);
        //    //DTE dte = dteObject as DTE;
        //    //DTE2 dte2 = dteObject as DTE2;

        //    Solution solution = (Solution) this.GetService(typeof(Solution));
        //    Debug.Assert(solution != null);
        //    foreach (object obj in solution.Projects)
        //    {
        //        string typeName = Information.TypeName(obj);
        //        Console.WriteLine(typeName);
        //        EnvDTE.Project proj = (EnvDTE.Project)obj;
        //        Console.WriteLine(proj.FullName);
        //    }
        //    Project project = solution.Projects.Item(1).ProjectItems.ContainingProject;
        //    Debug.Assert(project != null);
        //    return project;
        //}

        /// <summary>
        /// Gets a list of the assemblies referenced by the project
        /// </summary>
        /// <param name="isInclusive">Include assemblies from C:\Windows or not</param>
        /// <returns></returns>
        public Assembly[] GetReferencedAssemblies(bool isInclusive)
        {
            List <Assembly> assemblies = new List <Assembly>();
            VSProject2      vsProject2 = project.Object as VSProject2;

            foreach (object obj in vsProject2.References)
            {
                try
                {
                    string     windir = Environment.GetEnvironmentVariable("windir");
                    Reference3 ref3   = obj as Reference3;
                    if (ref3 != null)
                    {
                        // filter out the standard assemblies (isInclusive)
                        if (isInclusive || (!isInclusive && !ref3.Path.StartsWith(windir)))
                        {
                            Assembly assembly = AssemblyHelper.LoadAssembly(ref3.Path);
                            assemblies.Add(assembly);
                        }
                    }
                }
                catch
                {
                    // TODO show an alert with the error message
                    throw;
                }
            }
            return(assemblies.ToArray());
        }
Пример #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            Reference3 reference3 = db.Reference3.Find(id);

            db.Reference3.Remove(reference3);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #3
0
        public void Item_SystemXmlProjectHasSystemXmlReference_OneReference3Returned()
        {
            CreateReferences();
            msbuildProject.AddReference("System.Xml");

            Reference3 reference = references.Item("System.Xml") as Reference3;

            Assert.AreEqual("System.Xml", reference.Name);
        }
Пример #4
0
 public ActionResult Edit([Bind(Include = "Id,Name")] Reference3 reference3)
 {
     if (ModelState.IsValid)
     {
         db.Entry(reference3).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(reference3));
 }
Пример #5
0
        public ActionResult Create([Bind(Include = "Id,Name")] Reference3 reference3)
        {
            if (ModelState.IsValid)
            {
                db.Reference3.Add(reference3);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(reference3));
        }
Пример #6
0
        // GET: Reference3/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Reference3 reference3 = db.Reference3.Find(id);

            if (reference3 == null)
            {
                return(HttpNotFound());
            }
            return(View(reference3));
        }
Пример #7
0
        private bool IsReferenceResolved(Reference3 reference, Common.ILogger logger)
        {
            _threadingService.ThrowIfNotOnUIThread();

            try
            {
                // Verify that this is a valid and resolved reference
                return(reference != null && reference.Resolved);
            }
            catch (Exception ex)
            {
                logger.LogDebug(ex.ToString());
            }

            return(false);
        }
Пример #8
0
        private bool IsProjectReference(Reference3 reference, Common.ILogger logger)
        {
            _threadingService.ThrowIfNotOnUIThread();

            try
            {
                // Verify that this is a project reference
                return(reference != null && reference.SourceProject != null);
            }
            catch (Exception ex)
            {
                logger.LogDebug(ex.ToString());
            }

            return(false);
        }
Пример #9
0
        /// <summary>
        /// Removes reference according to given <see cref="Reference3"/>.
        /// </summary>
        /// <param name="reference">The reference.</param>
        private void removeReference(Reference3 reference)
        {
            var sourceProject = reference.SourceProject;

            if (sourceProject == null)
            {
                //there is not source project for the reference
                //we has to add reference according to path
                RemoveReference(reference.Path);
            }
            else
            {
                //we can add reference through referenced source project
                RemoveReference(sourceProject);
            }
        }
Пример #10
0
        public int GetEqualityHashCode()
        {
            // WARNING: Do not add Bucket to this change detection.  It will interfer with finding transactions and duplicate detection.
            unchecked
            {
                var result = 37; // prime
                result += Account.GetType().GetHashCode();
                result *= 397;   // also prime
                result += Amount.GetHashCode();
                result *= 397;
                result += Date.GetHashCode();
                result *= 397;

                if (!string.IsNullOrWhiteSpace(Description))
                {
                    result += Description.GetHashCode();
                }
                result *= 397;

                if (!string.IsNullOrWhiteSpace(Reference1))
                {
                    result += Reference1.GetHashCode();
                }
                result *= 397;

                if (!string.IsNullOrWhiteSpace(Reference2))
                {
                    result += Reference2.GetHashCode();
                }
                result *= 397;

                if (!string.IsNullOrWhiteSpace(Reference3))
                {
                    result += Reference3.GetHashCode();
                }
                result *= 397;

                result += TransactionType.GetHashCode();
                result *= 397;

                return(result);
            }
        }
        /// <summary>
        /// Create project reference. In some cases the Visual Studio returns incorrect project output path.
        /// </summary>
        /// <param name="projectRef">The project reference.</param>
        /// <returns>Returns project reference assembly.</returns>
        private ProjectReference CreateProjectReference(Reference3 projectRef)
        {
            if (projectRef.SourceProject == null)
            {
                return(BuildProjectReference(projectRef.Name, projectRef.Identity,
                                             projectRef.Path, projectRef.Version,
                                             projectRef.Culture, projectRef.PublicKeyToken));
            }

            if (!File.Exists(projectRef.Path))
            {
                return(null);
            }

            var activeConfiguration = Project.DTE.Solution.SolutionBuild.ActiveConfiguration.Name;

            var assemblyName = Path.GetFileName(projectRef.Path);
            var pattern      = string.Format(@"\\(obj|bin)\\(?<Configuration>(Release|Debug))\\{0}", assemblyName);
            var regex        = Regex.Match(projectRef.Path, pattern);

            if (regex.Success)
            {
                var projectRefConfiguration = regex.Groups["Configuration"].Value.ToString();
                if (projectRefConfiguration.Equals(activeConfiguration, StringComparison.Ordinal) &&
                    File.Exists(projectRef.Path))
                {
                    return(BuildProjectReference(projectRef.Name, projectRef.Identity,
                                                 projectRef.Path, projectRef.Version,
                                                 projectRef.Culture, projectRef.PublicKeyToken));
                }
            }

            var wrapper     = DTEHelper.CreateProjectWrapper(projectRef.SourceProject);
            var assemblyDef = wrapper.AssemblyDefinition;

            return(BuildProjectReference(projectRef.Name, projectRef.Identity,
                                         wrapper.GetOutputAssemblyPath(), assemblyDef.Name.Version.ToString(),
                                         assemblyDef.Name.Culture, _tokenConverter.ConvertFrom(assemblyDef.Name.PublicKeyToken)));
        }
Пример #12
0
 public ReferenceWrapper(Reference3 reference, Lazy <PackageReferences> packageReferences)
 {
     this.reference         = reference;
     this.packageReferences = packageReferences;
 }
Пример #13
0
 void CreateReference(Project project, ReferenceProjectItem referenceProjectItem)
 {
     reference = new Reference3(project, referenceProjectItem);
 }
Пример #14
0
        public string GetSolutionDetails()
        {
            StringBuilder code = new StringBuilder();

            VSProject2    vsProject2  = project.Object as VSProject2;
            FileInfo      projectFile = new FileInfo(project.FileName);
            DirectoryInfo projectDir  = projectFile.Directory;

            code.AppendLine("/************/");
            code.AppendLine("/* Solution */");
            code.AppendLine("/************/");
            code.AppendLine("/* FileName: " + project.DTE.Solution.FileName + " */");
            code.AppendLine(String.Empty);

            code.AppendLine("/***********/");
            code.AppendLine("/* Project */");
            code.AppendLine("/***********/");
            code.AppendLine("/* Name: " + project.Name + " */");
            code.AppendLine("/* FileName: " + project.FileName + " */");
            code.AppendLine("/* FullName: " + project.FullName + " */");
            code.AppendLine("/* UniqueName: " + project.UniqueName + " */");
            code.AppendLine("/* FullName: " + projectDir.FullName + " */");
            code.AppendLine("/* TypeName: " + Information.TypeName(project.Object) + " */");
            code.AppendLine(String.Empty);

            if (vsProject2 != null)
            {
                code.AppendLine("/**************/");
                code.AppendLine("/* VSProject2 */");
                code.AppendLine("/**************/");
                code.AppendLine("/* VSProject2: " + vsProject2.ToString() + " */");
                code.AppendLine(String.Empty);

                code.AppendLine("/**************/");
                code.AppendLine("/* References */");
                code.AppendLine("/**************/");
                foreach (object obj in vsProject2.References)
                {
                    try
                    {
                        string     windir = Environment.GetEnvironmentVariable("windir");
                        Reference3 ref3   = obj as Reference3;
                        if (ref3 != null)
                        {
                            // filter out the standard assemblies
                            if (!ref3.Path.StartsWith(windir))
                            {
                                code.AppendLine("/* TypeName: " + Information.TypeName(obj) + " */");
                                code.AppendLine("/* Name: " + ref3.Name + " */");
                                code.AppendLine("/* Path: " + ref3.Path + " */");
                                code.AppendLine("/* AutoReferenced: " + ref3.AutoReferenced + " */");
                                code.AppendLine("/* Description: " + ref3.Description + " */");
                                code.AppendLine("/* Resolved: " + ref3.Resolved + " */");
                                code.AppendLine("/* Version: " + ref3.Version + " */");

                                code.AppendLine(AssemblyHelper.GetAssemblyDetails(ref3.Path));
                                code.AppendLine(String.Empty);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        code.AppendLine("/* Exception: " + ex.Message + " */");
                    }
                }
            }

            return(code.ToString());
        }