예제 #1
0
        /**
         * Test CR and LF in values.
         * @throws XmpException Forwards exceptions
         */
        private static void CoverLinefeedValues()
        {
            writeMajorLabel("Test CR and LF in values");

            string valueWithCR   = "ASCII \r CR";
            string valueWithLF   = "ASCII \n LF";
            string valueWithCRLF = "ASCII \r\n CRLF";

            var meta = XmpMetaFactory.ParseFromString(TestData.NEWLINE_RDF);

            meta.SetProperty(TestData.NS2, "HasCR", valueWithCR);
            meta.SetProperty(TestData.NS2, "HasLF", valueWithLF);
            meta.SetProperty(TestData.NS2, "HasCRLF", valueWithCRLF);

            string result = XmpMetaFactory.SerializeToString(meta, new SerializeOptions {
                OmitPacketWrapper = true
            });

            log.WriteLine(result);

            var hasCR    = meta.GetPropertyString(TestData.NS1, "HasCR");
            var hasCR2   = meta.GetPropertyString(TestData.NS2, "HasCR");
            var hasLF    = meta.GetPropertyString(TestData.NS1, "HasLF");
            var hasLF2   = meta.GetPropertyString(TestData.NS2, "HasLF");
            var hasCRLF  = meta.GetPropertyString(TestData.NS1, "HasCRLF");
            var hasCRLF2 = meta.GetPropertyString(TestData.NS2, "HasCRLF");

            if (hasCR == valueWithCR && hasCR2 == valueWithCR &&
                hasLF == valueWithLF && hasLF2 == valueWithLF &&
                hasCRLF == valueWithCRLF && hasCRLF2 == valueWithCRLF)
            {
                log.WriteLine();
                log.WriteLine("\n## HasCR and HasLF and HasCRLF correctly retrieved\n");
            }
        }
예제 #2
0
        public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding encoding)
        {
            var xmp = XmpMetaFactory.SerializeToString(context.Object as IXmpMeta, new SerializeOptions());

            using (var writer = context.WriterFactory(context.HttpContext.Response.Body, encoding))
            {
                return(writer.WriteAsync(xmp));
            }
        }
예제 #3
0
        public void TestLayer()
        {
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            var     resPath = Path.Combine(Environment.CurrentDirectory, @"..\..\Res");
            var     path    = Path.Combine(resPath, "test.psd");
            PsdFile psd     = new PsdFile(path, new LoadContext());

            foreach (var image in psd.ImageResources)
            {
                var info = image;
                if (info is XmpResource xmp)
                {
                    var x = xmp.XmpMeta;
                    foreach (var property in x.Properties)
                    {
                        var l = $"Path={property.Path} Namespace={property.Namespace} Value={property.Value}";
                    }

                    var s = XmpMetaFactory.SerializeToString(x, new SerializeOptions());
                }
            }
        }
예제 #4
0
        /**
         * Covers the serialization of an <code>XmpMeta</code> object with different options.
         * @throws Exception Forwards exceptions
         */
        private static void CoverSerialization()
        {
            writeMajorLabel("Test serialization with various options");

            var meta = XmpMetaFactory.ParseFromString(TestData.SIMPLE_RDF);

            meta.SetProperty(TestData.NS2, "Another", "Something in another schema");
            meta.SetProperty(TestData.NS2, "Yet/pdf:More", "Yet more in another schema");

            printXmpMeta(meta, "Parse simple RDF, serialize with various options");

            writeMinorLabel("Default serialize");
            log.WriteLine(XmpMetaFactory.SerializeToString(meta, null));

            writeMinorLabel("Compact RDF, no packet serialize");
            log.WriteLine(XmpMetaFactory.SerializeToString(meta, new SerializeOptions {
                UseCompactFormat = true, OmitPacketWrapper = true
            }));

            writeMinorLabel("Read-only serialize");
            log.WriteLine(XmpMetaFactory.SerializeToString(meta, new SerializeOptions {
                ReadOnlyPacket = true
            }));

            writeMinorLabel("Alternate newline serialize");
            log.WriteLine(XmpMetaFactory.SerializeToString(meta, new SerializeOptions {
                Newline = "<--newline-->\n", OmitPacketWrapper = true
            }));

            writeMinorLabel("Alternate indent serialize");
            log.WriteLine(XmpMetaFactory.SerializeToString(meta, new SerializeOptions {
                Indent = "-->", BaseIndent = 5, OmitPacketWrapper = true
            }));

            writeMinorLabel("Small padding serialize");
            log.WriteLine(XmpMetaFactory.SerializeToString(meta, new SerializeOptions {
                Padding = 10
            }));

            writeMinorLabel("Serialize with exact packet size");
            int s = XmpMetaFactory.SerializeToBuffer(meta, new SerializeOptions {
                ReadOnlyPacket = true
            }).Length;

            log.WriteLine("Minimum packet size is " + s + " bytes\n");

            // with the flag "exact packet size" the padding becomes the overall length of the packet
            byte[] buffer = XmpMetaFactory.SerializeToBuffer(meta, new SerializeOptions {
                ExactPacketLength = true, Padding = s
            });
            log.WriteLine(Encoding.UTF8.GetString(buffer, 0, buffer.Length));

            try
            {
                XmpMetaFactory.ParseFromString(XmpMetaFactory.SerializeToString(meta, new SerializeOptions {
                    ExactPacketLength = true, Padding = s - 1
                }));
            }
            catch (XmpException e)
            {
                log.WriteLine("\nExact packet size smaller than minimal packet length - threw XmpException #{0} :   {1}", e.GetErrorCode(), e.Message);
            }
        }