Beispiel #1
0
        public static CopyBuffer ExtractCopyBufferFromClipboardStream(Stream clipboardStream)
        {
            CopyBuffer result;

            using (Package package = Package.Open(clipboardStream, FileMode.Open, FileAccess.Read))
            {
                result = new CopyBuffer();
                foreach (PackageRelationship packageRelationship in package.GetRelationshipsByType("http://schemas.microsoft.com/cfxaml/2006/06/relationships/metadata/core-properties"))
                {
                    Uri         partUri = PackUriHelper.ResolvePartUri(new Uri("/", UriKind.Relative), packageRelationship.TargetUri);
                    PackagePart part    = package.GetPart(partUri);
                    Container.ParseCorePropertyPart(result, part);
                }
                foreach (PackageRelationship packageRelationship in package.GetRelationshipsByType("http://schemas.microsoft.com/cfxaml/2006/06/selected-item"))
                {
                    Uri      partUri     = PackUriHelper.ResolvePartUri(new Uri("/", UriKind.Relative), packageRelationship.TargetUri);
                    CopyItem itemToPaste = (CopyItem) new MemoryCopyItem(Container.GetBytes(package.GetPart(partUri)));
                    result.AddSelectedItem(itemToPaste);
                }
                foreach (PackageRelationship packageRelationship1 in package.GetRelationshipsByType("http://schemas.microsoft.com/cfxaml/2006/06/referenced-item"))
                {
                    Uri         partUri1 = PackUriHelper.ResolvePartUri(new Uri("/", UriKind.Relative), packageRelationship1.TargetUri);
                    PackagePart part     = package.GetPart(partUri1);
                    CopyItem    copyItem = (CopyItem) new MemoryCopyItem(Container.GetBytes(part));
                    result.AddReferencedItem(copyItem);
                    foreach (PackageRelationship packageRelationship2 in part.GetRelationshipsByType("http://schemas.microsoft.com/cfxaml/2006/06/item-attributes"))
                    {
                        Uri partUri2 = PackUriHelper.ResolvePartUri(new Uri("/", UriKind.Relative), packageRelationship2.TargetUri);
                        Container.ReadAttributes(package.GetPart(partUri2), copyItem);
                    }
                }
            }
            return(result);
        }
Beispiel #2
0
        private static void ParseCorePropertyPart(CopyBuffer result, PackagePart corePropertyPart)
        {
            XmlDocument xmlDocument = new XmlDocument();

            using (Stream stream = corePropertyPart.GetStream())
                xmlDocument.Load(stream);
            Container.GetTagNameValueAsString(xmlDocument, "contentType");
            string nameValueAsString1 = Container.GetTagNameValueAsString(xmlDocument, "version");
            double result1            = -1.0;

            double.TryParse(nameValueAsString1, NumberStyles.Any, (IFormatProvider)CultureInfo.InvariantCulture, out result1);
            result.Version = result1;
            string nameValueAsString2 = Container.GetTagNameValueAsString(xmlDocument, "dc:creator");

            result.Creator = nameValueAsString2;
        }
Beispiel #3
0
        public static MemoryStream CreateClipboardStream(CopyBuffer itemsToPaste)
        {
            Uri          partUri      = PackUriHelper.CreatePartUri(new Uri("CoreProperties", UriKind.Relative));
            MemoryStream memoryStream = new MemoryStream();

            using (Package package = Package.Open((Stream)memoryStream, FileMode.Create))
            {
                PackagePart part = package.CreatePart(partUri, "text/Xml");
                using (Stream stream = part.GetStream())
                {
                    using (StreamWriter streamWriter = new StreamWriter(stream, Encoding.UTF8))
                        streamWriter.Write("<?xml version='1.0' encoding='utf-8'?>\r\n<coreProperties\r\n  xmlns='http://schemas.microsoft.com/cfxaml/2006/06/metadata/core-properties'\r\n  xmlns:dc='http://purl.org/dc/elements/1.1'>\r\n  <contentType>cfXaml</contentType>\r\n  <dc:creator>Expression</dc:creator>\r\n  <version>0.71</version>\r\n</coreProperties>");
                }
                package.CreateRelationship(part.Uri, TargetMode.Internal, "http://schemas.microsoft.com/cfxaml/2006/06/relationships/metadata/core-properties");
                List <PackagePart> itemPackageParts1 = new List <PackagePart>();
                for (int index = 0; index < itemsToPaste.SelectedItemCount; ++index)
                {
                    CopyItem copyItem = itemsToPaste.SelectedItem(index);
                    Container.CreatePackageItem(package, itemPackageParts1, "/CopiedItem" + (object)index, "http://schemas.microsoft.com/cfxaml/2006/06/selected-item", copyItem);
                }
                List <PackagePart> itemPackageParts2 = new List <PackagePart>();
                for (int index = 0; index < itemsToPaste.ReferencedItemCount; ++index)
                {
                    CopyItem copyItem = itemsToPaste.ReferencedItem(index);
                    Container.CreatePackageItem(package, itemPackageParts2, "/ReferencedItem" + (object)index, "http://schemas.microsoft.com/cfxaml/2006/06/referenced-item", copyItem);
                }
            }
            if (Container.SaveClipboardContentsToFile)
            {
                using (FileStream fileStream = new FileStream("clipboardContents.zip", FileMode.Create, FileAccess.ReadWrite))
                {
                    memoryStream.Seek(0L, SeekOrigin.Begin);
                    Container.CopyStream((Stream)memoryStream, (Stream)fileStream);
                }
            }
            return(memoryStream);
        }