Esempio n. 1
0
        private void Init(PackagePart parentPart)
        {
            SortedList <string, PackagePart> sortedList = new SortedList <string, PackagePart>();

            foreach (PackagePart packagePart in this._package.GetParts())
            {
                sortedList.Add(packagePart.Uri.OriginalString.TrimStart(new char[1]
                {
                    '/'
                }), packagePart);
            }
            VsixPackageNode vsixPackageNode = new VsixPackageNode(this._fileName, (VsixFileNode)null, this._package, parentPart);

            vsixPackageNode.Nodes = new SortedObservableCollection <VsixFileNode>((IEnumerable <VsixFileNode>) this.CreateFileTree((IEnumerable <KeyValuePair <string, PackagePart> >)sortedList, (VsixFileNode)vsixPackageNode));
            this.Nodes.Add((VsixFileNode)vsixPackageNode);
        }
Esempio n. 2
0
        public void AddFile(VsixFileNode targetNode, string fileName, Stream fileStream)
        {
            string       str = "/";
            VsixFileNode vsixFileNode;

            for (vsixFileNode = targetNode; vsixFileNode != null && !(vsixFileNode is VsixPackageNode); vsixFileNode = vsixFileNode.Parent)
            {
                str = "/" + vsixFileNode.Name + str;
            }
            if (vsixFileNode == null)
            {
                return;
            }
            VsixPackageNode vsixPackageNode = vsixFileNode as VsixPackageNode;
            Uri             partUri         = PackUriHelper.CreatePartUri(new Uri(str + fileName, UriKind.Relative));

            if (vsixPackageNode.Package.PartExists(partUri))
            {
                Enumerable.FirstOrDefault <VsixFileNode>((IEnumerable <VsixFileNode>)targetNode.Nodes, (Func <VsixFileNode, bool>)(node =>
                {
                    if (node is VsixPackagePartNode)
                    {
                        return((node as VsixPackagePartNode).Part.Uri == partUri);
                    }
                    else
                    {
                        return(false);
                    }
                })).Remove(true);
            }
            PackagePart part   = vsixPackageNode.Package.CreatePart(partUri, "application/octet-stream", CompressionOption.Maximum);
            Stream      stream = part.GetStream(FileMode.OpenOrCreate, FileAccess.Write);

            byte[] buffer = new byte[4096];
            fileStream.Seek(0L, SeekOrigin.Begin);
            int count;

            while ((count = fileStream.Read(buffer, 0, 4096)) > 0)
            {
                stream.Write(buffer, 0, count);
            }
            stream.Close();
            fileStream.Seek(0L, SeekOrigin.Begin);
            targetNode.Nodes.Add(this.CreateFileNodeFromPart(part, targetNode));
        }