예제 #1
0
 public static ProjectElementContainer DeepClone(ProjectElementContainer xml, ProjectRootElement factory, ProjectElementContainer parent) => ProjectElementContainer.DeepClone(xml, factory, parent);
예제 #2
0
        public static ProjectElementContainer DeepClone(this IProjectElementContainerLinkHelper xml, ProjectRootElement factory, ProjectElementContainer parent)
        {
            var factoryRemote = xml.Linker.Export <ProjectElement, MockProjectRootElementLinkRemoter>(factory);
            var parentRemote  = (MockProjectElementContainerLinkRemoter)xml.Linker.ExportElement(parent);
            var result        = xml.ContainerProxy.DeepClone(factoryRemote, parentRemote);

            return((ProjectElementContainer)result.Import(xml.Linker));
        }
예제 #3
0
 public static void AddInitialChild(ProjectElementContainer xml, ProjectElement child) => xml.AddInitialChild(child);
예제 #4
0
 public abstract ProjectElementContainer DeepClone(ProjectRootElement factory, ProjectElementContainer parent);
예제 #5
0
        private static void VerifyProjectElementContainerView(ProjectElementContainer viewXml, ProjectElementContainer realXml, ValidationContext context = null)
        {
            if (viewXml == null && realXml == null)
            {
                return;
            }
            VerifyProjectElementViewInternal(viewXml, realXml, context);

            Assert.Equal(realXml.Count, viewXml.Count);

            VerifyNotLinked(realXml.FirstChild);
            VerifyLinked(viewXml.FirstChild);

            VerifyNotLinked(realXml.LastChild);
            VerifyLinked(viewXml.LastChild);

            var realChild = realXml.FirstChild;
            var viewChild = viewXml.FirstChild;

            while (realChild != null)
            {
                Assert.NotNull(viewChild);
                Assert.Same(realChild.Parent, realXml);

                if (!object.ReferenceEquals(viewChild.Parent, viewXml))
                {
                    var lm = LinkedObjectsFactory.GetLink(viewXml) as ILinkMock;
                    lm.Linker.ValidateNoDuplicates();
                }

                Assert.Same(viewChild.Parent, viewXml);

                if (realChild is ProjectElementContainer realChildContainer)
                {
                    Assert.True(viewChild is ProjectElementContainer);

                    VerifyProjectElementContainerView((ProjectElementContainer)viewChild, realChildContainer, context);
                }
                else
                {
                    Assert.False(viewChild is ProjectElementContainer);
                    VerifyProjectElementViewInternal(viewChild, realChild, context);
                }

                realChild = realChild.NextSibling;
                viewChild = viewChild.NextSibling;
            }

            Assert.Null(viewChild);
        }
예제 #6
0
        public void RemoveItem(VSProjectItem item)
        {
            ProjectElementContainer parent = ((ProjectElement)item.InternalProjectItem).Parent;

            parent.RemoveChild((ProjectElement)item.InternalProjectItem);
        }
예제 #7
0
        private void Parse(bool includeHiddenItems = false)
        {
            var stream              = File.OpenRead(projectFileName);
            var reader              = XmlReader.Create(stream);
            var cache               = s_ProjectRootElementCache.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).First().Invoke(new object[] { true });
            var fileInfo            = new FileInfo(projectFileName);
            var addPropertyElements = new List <VSProjectProperty>();

            this.includeHiddenItems = includeHiddenItems;

            this.Hash = fileInfo.GetHash();

            if (s_ProjectRootElement.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).Any(c => c.GetParameters().Count() == 4 && c.GetParameters().First().ParameterType.Name == "XmlReader" && c.GetParameters().ElementAt(1).ParameterType.Name == "ProjectRootElementCache"))
            {
                rootElement = (ProjectRootElement)s_ProjectRootElement.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).Where(c => c.GetParameters().Count() >= 2 && c.GetParameters().First().ParameterType.Name == "XmlReader" && c.GetParameters().ElementAt(1).ParameterType.Name == "ProjectRootElementCache").First().Invoke(new object[] { reader, cache, true, true });
            }
            else if (s_ProjectRootElement.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).Any(c => c.GetParameters().Count() == 2 && c.GetParameters().First().ParameterType.Name == "XmlReader" && c.GetParameters().ElementAt(1).ParameterType.Name == "ProjectRootElementCache"))
            {
                rootElement = (ProjectRootElement)s_ProjectRootElement.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).Where(c => c.GetParameters().Count() == 2 && c.GetParameters().First().ParameterType.Name == "XmlReader" && c.GetParameters().ElementAt(1).ParameterType.Name == "ProjectRootElementCache").First().Invoke(new object[] { reader, cache });
            }
            else
            {
                throw new Exception("Unable to find constructor in ProjectRootElementCache for VSProject parser");
            }

            if (rootElement.Properties.Count(p => p.Name == "AssemblyName") == 1)
            {
                var assemblyName = rootElement.Properties.SingleOrDefault(p => p.Name == "AssemblyName");
                ProjectPropertyElement outputPathElement;

                if (assemblyName != null)
                {
                    var    configuration            = rootElement.Properties.Single(p2 => p2.Name == "Configuration").Value;
                    var    platform                 = rootElement.Properties.SingleOrDefault(p2 => p2.Name == "Platform");
                    var    isSilverlightAppProperty = rootElement.Properties.SingleOrDefault(p2 => p2.Name == "SilverlightApplication");
                    string platformValue            = string.Empty;

                    if (this.name == null)
                    {
                        this.name = assemblyName.Value;
                    }

                    if (isSilverlightAppProperty != null)
                    {
                        IsSilverlightApplication = bool.Parse(isSilverlightAppProperty.Value);

                        if (IsSilverlightApplication)
                        {
                            var xapFileNameProperty = rootElement.Properties.SingleOrDefault(p2 => p2.Name == "XapFilename");

                            if (xapFileNameProperty != null)
                            {
                                XAPFilename = xapFileNameProperty.Value;
                            }
                        }
                    }

                    if (platform == null)
                    {
                        platformValue = rootElement.Properties.First(p2 => p2.Name == "PlatformTarget").Value;
                    }
                    else
                    {
                        platformValue = platform.Value;
                    }

                    outputPathElement = rootElement.Properties.SingleOrDefault(p =>
                    {
                        if (p.Name == "OutputPath")
                        {
                            var condition = Regex.Replace(p.Parent.Condition, @"\s", "");

                            if (condition == string.Format("'$(Configuration)|$(Platform)'=='{0}|{1}'", configuration, platformValue))
                            {
                                return(true);
                            }
                            else if (platformValue == "AnyCPU")
                            {
                                var pattern = string.Format(@"'\$\(Configuration\)\|\$\(Platform\)'=='{0}\|\w+?'", configuration);

                                return(Regex.IsMatch(condition, pattern));
                            }

                            return(false);
                        }
                        else
                        {
                            return(false);
                        }
                    });

                    if (outputPathElement != null)
                    {
                        OutputPath = outputPathElement.Value;
                    }

                    var    outputType = rootElement.Properties.SingleOrDefault(p => p.Name == "OutputType").Value;
                    string outputExt  = string.Empty;

                    switch (outputType)
                    {
                    case "Library":
                        outputExt = ".dll";
                        break;

                    case "Exe":
                        outputExt = ".exe";
                        break;

                    case "WinExe":
                        outputExt = ".exe";
                        break;

                    default:
                        Debugger.Break();
                        break;
                    }

                    if (OutputPath != null)
                    {
                        var directory = new FileInfo(this.projectFileName).DirectoryName;

                        this.OutputFile = Path.GetFullPath(Path.Combine(directory, OutputPath, assemblyName.Value + outputExt));
                    }
                }
            }
            else
            {
                var targetFramework = rootElement.Properties.SingleOrDefault(p => p.Name == "TargetFramework");
                var directory       = new FileInfo(this.projectFileName).DirectoryName;
                var outputDirectory = new DirectoryInfo(Path.Combine(directory, $"bin\\Debug\\{ targetFramework.Value }"));
                ProjectPropertyElement propertyElement;

                // kn todo - assuming debug and dll

                this.name       = Path.GetFileNameWithoutExtension(projectFileName);
                this.OutputPath = outputDirectory.FullName;
                this.OutputFile = Path.Combine(outputDirectory.FullName, this.name + ".dll");

                propertyElement = rootElement.CreatePropertyElement("RootNamespace");

                propertyElement.Value = this.name;

                addPropertyElements.Add(new VSProjectProperty(this, propertyElement));

                Debug.WriteLine("Project '{0}' has either zero or more than one assembly output section.  Assembly related properties will be indeterminant and set to null.", this.Name);
            }

            rootElementContainer = (ProjectElementContainer)rootElement;

            stream.Close();

            itemCollection = (ICollection)s_ProjectRootElement_Items.GetValue(rootElement, null);

            if (!loadOnDemand)
            {
                // will force the iteration

                GetProperties().ToList();
                GetItems().ToList();

                foreach (var properyElement in addPropertyElements)
                {
                    properties.Add(properyElement);
                }
            }
        }