コード例 #1
0
        internal void VerifyResolvedConsistency()
        {
            if (this.Deleted)
            {
                CompilerException.ThrowInternalError("Internal resolved consistency violation: Item was deleted.");
            }

            if (this.Parent != null && this.Parent.Deleted)
            {
                CompilerException.ThrowInternalError("Internal resolved consistency violation: Parent was deleted.");
            }

            if (this.Group != null && this.Group.Deleted)
            {
                CompilerException.ThrowInternalError("Internal resolved consistency violation: Group was deleted.");
            }

            if (!this.resolved)
            {
                CompilerException.ThrowInternalError("Internal resolved consistency violation: Item was not resolved.");
            }

            if (this.resolving)
            {
                CompilerException.ThrowInternalError("Internal resolved consistency violation: Item was still resolving.");
            }

            if (!this.resolvedGroup)
            {
                CompilerException.ThrowInternalError("Internal resolved consistency violation: Item did not resolve its group.");
            }

            this.OnVerifyResolvedConsistency();
        }
        private void CreateImplicitFolders(FrontendCompiler context, List <FileSystemResource> implicitPaths)
        {
            implicitPaths.Sort((x, y) => x.Path.CompareTo(y.Path));

            foreach (FileSystemResource r in implicitPaths)
            {
                string path         = String.Empty;
                Folder parentFolder = null;

                string[] splitPath = r.Path.Split(FileSystemResourceManager.DirectorySplitChars, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < splitPath.Length - 1; ++i)
                {
                    Folder   folder = null;
                    Resource found  = null;

                    path = IO.Path.Combine(path, splitPath[i]) + "\\";
                    if (path.EndsWith(":\\", StringComparison.Ordinal))
                    {
                        PackageItem item;
                        if (context.TryGetItemById(path.Substring(0, path.Length - 2), out item))
                        {
                            folder = (Folder)item;
                        }
                    }
                    else if (this.resolvedPaths.TryGetValue(path, out found))
                    {
                        folder = found as Folder;
                        if (folder == null)
                        {
                            CompilerException.ThrowInternalError("Failed to resolve path to Folder. The path: '{0}' should resolve to a Folder instead of: '{1}'.", path, found);
                        }
                        else if (folder.ParentFolder != parentFolder)
                        {
                            CompilerException.ThrowInternalError("Found Folder.ParentFolder does not match expected parent Folder. Ensure path: '{0}' is correctly rooted to Folder/@Id='{1}'.", path, folder.Id);
                        }
                    }
                    else // need to create the implicit folder.
                    {
                        folder       = new Folder();
                        folder.Group = r.Group;
                        folder.Name  = splitPath[i];
                        parentFolder.Items.Add(folder);
                        context.AddItem(r.LineNumber, folder);

                        // Since the folder was just created, we need to jump start its "resolving" since all
                        // of the other resources have already started resolve.
                        folder.ResolveGroup(context);
                        folder.BeginResolve(context);
                        this.ResolvePath(context, folder);
                    }

                    parentFolder = folder;
                }

                if (r.ParentFolder != parentFolder)
                {
                    r.ReparentFolder(parentFolder);
                }
            }
        }
コード例 #3
0
        protected override void OnVerifyResolvedConsistency()
        {
            base.OnVerifyResolvedConsistency();

            if (this.ParentFolder != null && this.ParentFolder.Deleted)
            {
                CompilerException.ThrowInternalError("Internal resolved consistency violation: File system ParentFolder was deleted.");
            }
        }
コード例 #4
0
 internal void SetPath(string path)
 {
     if (String.IsNullOrEmpty(this.Path))
     {
         this.Path = path;
     }
     else
     {
         CompilerException.ThrowInternalError("Path was already set on the Resource. Resource.SetPath() cannot be called when the Path has already been set. Attempting to overwrite path: '{0}' with path: '{1}'", this.Path, path);
     }
 }
コード例 #5
0
ファイル: Group.cs プロジェクト: lukaswinzenried/WixCustBa
        protected override void OnVerifyResolvedConsistency()
        {
            base.OnVerifyResolvedConsistency();

            foreach (PackageItem item in this.Items)
            {
                if (item.Deleted)
                {
                    CompilerException.ThrowInternalError("Internal resolved consistency violation: Item contained in Group was deleted.");
                }
            }
        }
        private Folder GetDefaultRoot(FrontendCompiler context)
        {
            PackageItem item;

            if (!context.TryGetItemById(this.defaultFolderId, out item))
            {
                CompilerException.ThrowInternalError("Failed to locate default root folder with Id: '{0}'.", this.defaultFolderId);
            }

            Folder folder = item as Folder;

            if (folder == null)
            {
                CompilerException.ThrowInternalError("Unexpected default root item type. Ensure Id: '{0}' resolves to a Folder instead of a: '{1}'.", this.defaultFolderId, item);
            }

            return(folder);
        }
        private void ReparentFolderChildren(FrontendCompiler context, Folder deleteFolder, Folder replacementFolder)
        {
            Debug.Assert(replacementFolder != deleteFolder);
            if (!String.IsNullOrEmpty(deleteFolder.Path) && !deleteFolder.Path.Equals(replacementFolder.Path, StringComparison.OrdinalIgnoreCase))
            {
                CompilerException.ThrowInternalError("Reparenting to folder with different path. That should not be possible.");
            }

            foreach (FileSystemResource child in new List <FileSystemResource>(deleteFolder.Items))
            {
                child.ReparentFolder(replacementFolder);
            }
            Debug.Assert(deleteFolder.Items.Count == 0);

            if (deleteFolder.ParentFolder != null)
            {
                deleteFolder.ParentFolder.Items.Remove(deleteFolder);
            }

            context.RemoveItem(deleteFolder);
        }
コード例 #8
0
        internal void ReparentFolder(Folder newParentFolder)
        {
            // Ensure this new parent folder will not change our path if we already calculated it.
            if (!String.IsNullOrEmpty(this.Path) && !this.Path.StartsWith(newParentFolder.Path, StringComparison.OrdinalIgnoreCase))
            {
                CompilerException.ThrowInternalError("Reparenting folder would change already calculated path. That is not allowed.");
            }

            // If the parent was the parent folder, update the parent to point to the replacement folder.
            if (this.Parent == this.ParentFolder)
            {
                this.Parent = newParentFolder;
            }

            if (this.ParentFolder != null)
            {
                this.ParentFolder.Items.Remove(this);
            }

            this.ParentFolder = newParentFolder;
            newParentFolder.Items.Add(this);
        }
        private string ResolvePath(FrontendCompiler context, FileSystemResource r)
        {
            if (String.IsNullOrEmpty(r.Path))
            {
                // If there is a parent folder resolve it's path.
                string parentPath = String.Empty;
                if (r.ParentFolder != null)
                {
                    parentPath = ResolvePath(context, r.ParentFolder); // recurse.
                }

                string path = IO.Path.Combine(parentPath, r.ParentRelativePathFromName ?? String.Empty, r.Name ?? String.Empty);
                Debug.Assert((r is Folder && path.EndsWith("\\", StringComparison.Ordinal)) || (r is File && !path.EndsWith("\\", StringComparison.Ordinal)));

                r.SetPath(path);
            }

            // If in the process of calculating this resource's path we reparented the folder (which deletes the
            // resource) then don't check for a conflicting resource because this resource would lose anyway.
            if (!r.Deleted)
            {
                Resource conflictingResource;
                if (this.resolvedPaths.TryGetValue(r.Path, out conflictingResource))
                {
                    if (conflictingResource == r)
                    {
                        // We found ourself so don't do anything.
                    }
                    else if (conflictingResource is Folder && r is Folder) // folders are special because the can be implicitly created.
                    {
                        // If our resource has an id that makes it a better candidate for the path.
                        if (!String.IsNullOrEmpty(r.Id))
                        {
                            // The conflicting resource cannot also have an Id or the backend compiler will be all confusimicated.
                            if (!String.IsNullOrEmpty(conflictingResource.Id))
                            {
                                // TODO: change this to an error message instead of an internal compiler error.
                                CompilerException.ThrowInternalError("Two named folders refer to the same path. That is not supported.");
                            }

                            this.ReparentFolderChildren(context, (Folder)conflictingResource, (Folder)r);

                            this.resolvedPaths[r.Path] = r; // this resource now owns the path.
                        }
                        else // the conflicting resource either has an Id or was here first so it's a better parent.
                        {
                            this.ReparentFolderChildren(context, (Folder)r, (Folder)conflictingResource);
                        }
                    }
                    else
                    {
                        // TODO: change this to an error message instead of an internal compiler error.
                        CompilerException.ThrowInternalError("Two files or a file and a folder ended up with the same path. That is not allowed.");
                    }
                }
                else // no one owns this path yet so take it over.
                {
                    Debug.Assert(r != r.ParentFolder);
                    this.resolvedPaths.Add(r.Path, r);
                }
            }

            return(r.Path);
        }