Esempio n. 1
0
        /// <summary>
        /// Append the ThreadingInfo element
        /// </summary>
        /// <param name="filePath">Target excel faile path</param>
        /// <param name="log">Logger</param>
        public void AddElements(string filePath, VerifiableLog log)
        {
            using (PresentationDocument package = PresentationDocument.Open(filePath, true))
            {
                try
                {
                    Comment          comment          = GetComment(package.PresentationPart.SlideParts, 1);
                    CommentExtension commentExtension = new CommentExtension()
                    {
                        Uri = this.ThreadingInfoExtUri
                    };
                    P15.ThreadingInfo threadingInfo = new P15.ThreadingInfo()
                    {
                        TimeZoneBias = this.timeZoneBiasValue
                    };
                    commentExtension.AppendChild <P15.ThreadingInfo>(threadingInfo);
                    comment.CommentExtensionList.AppendChild <CommentExtension>(commentExtension);

                    log.Pass("Added ThreadingInfo element.");
                }
                catch (Exception e)
                {
                    log.Fail(e.Message);
                }
            }
        }
        protected override void Execute(CodeActivityContext context)
        {
            CommentExtension ext = context.GetExtension <CommentExtension>();

            ext.AddComment(Comment.Get(context));
            Comments.Set(context, ext.Comments);
        }
Esempio n. 3
0
        /// <summary>
        /// Populates the Comment Extension byte[] from the source image, and grabs the comment.
        /// </summary>
        /// <param name="bytes"></param>
        public static CommentExtension ParseCommentExtension(byte[] bytes)
        {
            CommentExtension e = new CommentExtension()
            {
                TotalBlockLength = bytes.Length,
                Bytes            = (byte[])bytes.Clone(),
                CommentLength    = bytes.Length - 4
            };

            return(e);
        }
    private static void SetCommentExtension(byte[] gifBytes, ref int byteIndex, ref GifData gifData)
    {
        CommentExtension commentEx = new CommentExtension();

        // Extension Introducer(1 Byte)
        // 0x21
        commentEx.m_extensionIntroducer = gifBytes[byteIndex];
        byteIndex++;

        // Comment Label(1 Byte)
        // 0xfe
        commentEx.m_commentLabel = gifBytes[byteIndex];
        byteIndex++;

        // Block Size & Comment Data List
        while (true)
        {
            // Block Size(1 Byte)
            byte blockSize = gifBytes[byteIndex];
            byteIndex++;

            if (blockSize == 0x00)
            {
                // Block Terminator(1 Byte)
                break;
            }

            var commentDataBlock = new CommentExtension.CommentDataBlock();
            commentDataBlock.m_blockSize = blockSize;

            // Comment Data(n Byte)
            commentDataBlock.m_commentData = new byte[commentDataBlock.m_blockSize];
            for (int i = 0; i < commentDataBlock.m_commentData.Length; i++)
            {
                commentDataBlock.m_commentData[i] = gifBytes[byteIndex];
                byteIndex++;
            }

            if (commentEx.m_commentDataList == null)
            {
                commentEx.m_commentDataList = new List <CommentExtension.CommentDataBlock>();
            }
            commentEx.m_commentDataList.Add(commentDataBlock);
        }

        if (gifData.m_commentExList == null)
        {
            gifData.m_commentExList = new List <CommentExtension>();
        }
        gifData.m_commentExList.Add(commentEx);
    }
Esempio n. 5
0
        /// <summary>
        /// Deleting ThreadingInfo element
        /// </summary>
        public void DeleteElements(Stream stream, VerifiableLog log)
        {
            using (PresentationDocument package = PresentationDocument.Open(stream, true))
            {
                Comment           comment          = GetComment(package.PresentationPart.SlideParts, 1);
                CommentExtension  commentExtension = comment.CommentExtensionList.Descendants <CommentExtension>().Where(e => e.Uri == ThreadingInfoExtUri).Single();
                P15.ThreadingInfo threadingInfo    = commentExtension.Descendants <P15.ThreadingInfo>().Single();

                threadingInfo.Remove();
                log.Pass("Deleted ThreadingInfo element.");

                commentExtension.Remove();
                log.Pass("Deleted ThreadingInfo extension element.");
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Constructor
        /// Get URI attribute value of CommentExtension
        /// </summary>
        public TestEntities(Stream stream)
        {
            using (PresentationDocument package = PresentationDocument.Open(stream, false))
            {
                // Get Extension Uri value
                Comment           comment          = GetComment(package.PresentationPart.SlideParts, 1);
                P15.ThreadingInfo threadingInfo    = comment.CommentExtensionList.Descendants <P15.ThreadingInfo>().Single();
                CommentExtension  commentExtension = (CommentExtension)threadingInfo.Parent;
                ThreadingInfoExtUri = commentExtension.Uri;

                if (string.IsNullOrEmpty(ThreadingInfoExtUri))
                {
                    throw new Exception("Uri attribute value in Extension element is not set.");
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Append the ThreadingInfo element
        /// </summary>
        public void AddElements(Stream stream, VerifiableLog log)
        {
            using (PresentationDocument package = PresentationDocument.Open(stream, true))
            {
                Comment          comment          = GetComment(package.PresentationPart.SlideParts, 1);
                CommentExtension commentExtension = new CommentExtension()
                {
                    Uri = ThreadingInfoExtUri
                };
                P15.ThreadingInfo threadingInfo = new P15.ThreadingInfo()
                {
                    TimeZoneBias = timeZoneBiasValue
                };
                commentExtension.AppendChild <P15.ThreadingInfo>(threadingInfo);
                comment.CommentExtensionList.AppendChild <CommentExtension>(commentExtension);

                log.Pass("Added ThreadingInfo element.");
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Deleting ThreadingInfo element
        /// </summary>
        /// <param name="filePath">Target Excel faile path</param>
        /// <param name="log">Logger</param>
        public void DeleteElements(string filePath, VerifiableLog log)
        {
            using (PresentationDocument package = PresentationDocument.Open(filePath, true))
            {
                try
                {
                    Comment           comment          = GetComment(package.PresentationPart.SlideParts, 1);
                    CommentExtension  commentExtension = comment.CommentExtensionList.Descendants <CommentExtension>().Where(e => e.Uri == this.ThreadingInfoExtUri).Single();
                    P15.ThreadingInfo threadingInfo    = commentExtension.Descendants <P15.ThreadingInfo>().Single();

                    threadingInfo.Remove();
                    log.Pass("Deleted ThreadingInfo element.");

                    commentExtension.Remove();
                    log.Pass("Deleted ThreadingInfo extension element.");
                }
                catch (Exception e)
                {
                    log.Fail(e.Message);
                }
            }
        }
Esempio n. 9
0
    static void SetCommentExtension (byte[] gifBytes, ref int byteIndex, ref GifData gifData)
    {
        CommentExtension commentEx = new CommentExtension ();

        // Extension Introducer(1 Byte)
        // 0x21
        commentEx.extensionIntroducer = gifBytes[byteIndex];
        byteIndex++;

        // Comment Label(1 Byte)
        // 0xfe
        commentEx.commentLabel = gifBytes[byteIndex];
        byteIndex++;

        // Block Size & Comment Data List
        while (true) {
            // Block Size(1 Byte)
            byte blockSize = gifBytes[byteIndex];
            byteIndex++;

            if (blockSize == 0x00) {
                // Block Terminator(1 Byte)
                break;
            }

            var commentDataBlock = new CommentExtension.CommentDataBlock ();
            commentDataBlock.blockSize = blockSize;

            // Comment Data(n Byte)
            commentDataBlock.commentData = new byte[commentDataBlock.blockSize];
            for (int i = 0; i < commentDataBlock.commentData.Length; i++) {
                commentDataBlock.commentData[i] = gifBytes[byteIndex];
                byteIndex++;
            }

            if (commentEx.commentDataList == null) {
                commentEx.commentDataList = new List<CommentExtension.CommentDataBlock> ();
            }
            commentEx.commentDataList.Add (commentDataBlock);
        }

        if (gifData.commentExList == null) {
            gifData.commentExList = new List<CommentExtension> ();
        }
        gifData.commentExList.Add (commentEx);
    }
Esempio n. 10
0
        /// <summary>
        /// Tokenizes the GIF image's byte[] into constituent components.
        /// </summary>
        public static DataStream ParseDataStream(byte[] data)
        {
            DataStream ds = new DataStream();

            using (MemoryStream ms = new MemoryStream(data))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    ds.Header = VcvjParser.ParseHeader(br.ReadBytes(Header.TotalBlockLength));

                    ds.LogicalScreen = new LogicalScreen()
                    {
                        LogicalScreenDescriptor = VcvjParser.ParseLogicalScreenDescriptor(br.ReadBytes(LogicalScreenDescriptor.TotalBlockLength))
                    };

                    if (ds.LogicalScreen.LogicalScreenDescriptor.HasGlobalColorTable)
                    {
                        ds.LogicalScreen.GlobalColorTable = VcvjParser.ParseGlobalColorTable(
                            br.ReadBytes(ds.LogicalScreen.LogicalScreenDescriptor.GlobalColorTableLength)
                            );
                    }

                    while (br.PeekChar() != -1)
                    {
                        long currentIndex = br.BaseStream.Position;
                        byte currentByte  = data[currentIndex];
                        byte?nextByte     = currentIndex + 1 < data.Length ? (byte?)data[currentIndex + 1] : (byte?)null;

                        if (ParserUtils.IsTrailerMarker(currentByte))
                        {
                            ds.Trailer = new Trailer(br.ReadByte());
                            continue;
                        }
                        else if (ParserUtils.IsApplicationExtensionBlock(currentByte, nextByte))
                        {
                            ApplicationExtension ae = VcvjParser.ParseApplicationExtension(
                                br.ReadBytes(VcvjParser.GetApplicationExtensionBlockLength(currentIndex, ref data))
                                );

                            ds.DataBlocks.Add(ae);
                            continue;
                        }
                        else if (ParserUtils.IsCommentExtensionBlock(currentByte, nextByte))
                        {
                            int totalBlockLength = data[currentIndex + 2] + 4;
                            CommentExtension ce  = VcvjParser.ParseCommentExtension(br.ReadBytes(totalBlockLength));

                            ds.DataBlocks.Add(ce);
                            continue;
                        }
                        else
                        {
                            GraphicBlock gb = new GraphicBlock();

                            if (ParserUtils.IsGraphicControlExtensionBlock(currentByte, nextByte))
                            {
                                gb.GraphicControlExtension = VcvjParser.ParseGraphicControlExtension(
                                    br.ReadBytes(8)
                                    );

                                currentIndex = br.BaseStream.Position;
                                currentByte  = data[currentIndex];
                                nextByte     = data[currentIndex + 1];
                            }

                            if (ParserUtils.IsImageDescriptor(currentByte))
                            {
                                TableBasedImage tbi = new TableBasedImage()
                                {
                                    ImageDescriptor = VcvjParser.ParseImageDescriptor(
                                        br.ReadBytes(10)
                                        )
                                };

                                if (tbi.ImageDescriptor.LocalColorTableFlag)
                                {
                                    tbi.LocalColorTable = VcvjParser.ParseLocalColorTable(
                                        br.ReadBytes(tbi.ImageDescriptor.LocalColorTableLength)
                                        );
                                }

                                currentIndex = br.BaseStream.Position;
                                currentByte  = data[currentIndex];
                                nextByte     = data[currentIndex + 1];

                                tbi.ImageData = VcvjParser.ParseImageData(
                                    br.ReadBytes(VcvjParser.GetImageDataBlockLength(currentIndex, ref data))
                                    );

                                gb.GraphicRenderingBlock = tbi;

                                ds.DataBlocks.Add(gb);
                                continue;
                            }
                            else if (ParserUtils.IsPlaintextExtension(currentByte, nextByte))
                            {
                                //GraphicBlock gb = new GraphicBlock()
                                //{
                                //};
                            }
                            else if (ParserUtils.IsApplicationExtensionBlock(currentByte, nextByte))
                            {
                                ApplicationExtension ae = VcvjParser.ParseApplicationExtension(
                                    br.ReadBytes(VcvjParser.GetApplicationExtensionBlockLength(currentIndex, ref data))
                                    );

                                ds.DataBlocks.Add(ae);
                                continue;
                            }
                            else if (ParserUtils.IsCommentExtensionBlock(currentByte, nextByte))
                            {
                                int totalBlockLength = data[currentIndex + 2] + 4;
                                CommentExtension ce  = VcvjParser.ParseCommentExtension(br.ReadBytes(totalBlockLength));

                                ds.DataBlocks.Add(ce);
                                continue;
                            }
                            else
                            {
                                throw new UnidentifiedBlockException(
                                          string.Format(
                                              "The current byte is {0} and the next one is {1}. Not really sure what to make of this.",
                                              currentByte.ToString(),
                                              String.IsNullOrEmpty(nextByte.ToString()) ? "null" : nextByte.ToString()
                                              )
                                          );
                            }
                        }
                    }
                }
            }
            return(ds);
        }
Esempio n. 11
0
        /// <summary>
        /// Returns the length of the parsed data stream byte[].
        /// </summary>
        /// <returns></returns>
        public int GetLength()
        {
            int length = 0;

            length += Header.TotalBlockLength + LogicalScreenDescriptor.TotalBlockLength + Trailer.TotalBlockLength;

            if (LogicalScreen.GlobalColorTable != null)
            {
                length += LogicalScreen.GlobalColorTable.TotalBlockLength;
            }

            foreach (DataBlock db in DataBlocks)
            {
                if (db is GraphicBlock)
                {
                    GraphicBlock gb = (GraphicBlock)db;

                    if (gb.GraphicControlExtension != null)
                    {
                        length += GraphicControlExtension.TotalBlockLength;
                    }

                    if (gb.GraphicRenderingBlock is PlainTextExtension)
                    {
                        PlainTextExtension pte = (PlainTextExtension)gb.GraphicRenderingBlock;

                        length += pte.TotalBlockLength;
                    }
                    else if (gb.GraphicRenderingBlock is TableBasedImage)
                    {
                        TableBasedImage tbi = (TableBasedImage)gb.GraphicRenderingBlock;

                        length += tbi.ImageData.TotalBlockLength + ImageDescriptor.TotalBlockLength;

                        if (tbi.LocalColorTable != null)
                        {
                            length += tbi.LocalColorTable.TotalBlockLength;
                        }
                    }
                }
                else if (db is SpecialPurposeBlock)
                {
                    SpecialPurposeBlock spb = (SpecialPurposeBlock)db;

                    if (spb is ApplicationExtension)
                    {
                        ApplicationExtension ae = (ApplicationExtension)spb;

                        length += ae.TotalBlockLength;
                    }
                    else if (spb is CommentExtension)
                    {
                        CommentExtension ce = (CommentExtension)spb;

                        length += ce.TotalBlockLength;
                    }
                }
            }

            return(length);
        }
Esempio n. 12
0
        private static List <Block> ReadBlocks(byte[] bytes, ref int startIndex)
        {
            var blocks = new List <Block>();
            var index  = startIndex;

            while (true)
            {
                switch (bytes[index])
                {
                case Block.ExtensionIntroducer:
                {
                    Block extension;

                    switch (bytes[index + 1])
                    {
                    case Block.PlainTextExtensionLabel:
                        extension = new PlainTextExtension(bytes, ref index);
                        break;

                    case Block.GraphicControlExtensionLabel:
                        extension = new GraphicControlExtension(bytes, ref index);
                        break;

                    case Block.CommentExtensionLabel:
                        extension = new CommentExtension(bytes, ref index);
                        break;

                    case Block.ApplicationExtensionLabel:
                        extension = new ApplicationExtension(bytes, ref index);
                        break;

                    default:
                        throw new NotSupportedException("Unknown extension!");
                    }

                    blocks.Add(extension);
                    break;
                }

                case Block.ImageDescriptorLabel:
                {
                    var descriptor = new ImageDescriptor(bytes, ref index);

                    blocks.Add(descriptor);

                    if (descriptor.LocalColorTableFlag == 1)
                    {
                        var localColorTable = new ColorTable(descriptor.LocalColorTableSize, bytes, ref index);

                        blocks.Add(localColorTable);
                    }

                    var data = new TableBasedImageData(bytes, ref index);

                    blocks.Add(data);

                    break;
                }

                case 0x3B:                         // End
                {
                    return(blocks);
                }

                default:
                    throw new NotSupportedException($"Unsupported GIF block: {bytes[index]:X}.");
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Compiles the parsed tokens/components back into a byte array.
        /// </summary>
        public void CompileByteArray()
        {
            List <byte> output = new List <byte>();

            output.AddRange(DataStream.Header.Bytes);
            output.AddRange(DataStream.LogicalScreen.LogicalScreenDescriptor.Bytes);

            if (DataStream.LogicalScreen.GlobalColorTable != null)
            {
                output.AddRange(DataStream.LogicalScreen.GlobalColorTable.Bytes);
            }

            foreach (DataBlock db in DataStream.DataBlocks)
            {
                if (db is GraphicBlock)
                {
                    GraphicBlock gb = (GraphicBlock)db;

                    if (gb.GraphicControlExtension != null)
                    {
                        output.AddRange(gb.GraphicControlExtension.Bytes);
                    }

                    if (gb.GraphicRenderingBlock is PlainTextExtension)
                    {
                        PlainTextExtension pte = (PlainTextExtension)gb.GraphicRenderingBlock;

                        output.AddRange(pte.Bytes);
                    }
                    else if (gb.GraphicRenderingBlock is TableBasedImage)
                    {
                        TableBasedImage tbi = (TableBasedImage)gb.GraphicRenderingBlock;

                        output.AddRange(tbi.ImageDescriptor.Bytes);

                        if (tbi.LocalColorTable != null)
                        {
                            output.AddRange(tbi.LocalColorTable.Bytes);
                        }

                        output.AddRange(tbi.ImageData.Bytes);
                    }
                }
                else if (db is SpecialPurposeBlock)
                {
                    SpecialPurposeBlock spb = (SpecialPurposeBlock)db;

                    if (spb is ApplicationExtension)
                    {
                        ApplicationExtension ae = (ApplicationExtension)spb;

                        output.AddRange(ae.Bytes);
                    }
                    else if (spb is CommentExtension)
                    {
                        CommentExtension ce = (CommentExtension)spb;

                        output.AddRange(ce.Bytes);
                    }
                }
            }

            output.AddRange(DataStream.Trailer.Bytes);

            DataStream.Bytes = output.ToArray();
        }