Пример #1
0
        public override void WriteToStream(System.IO.Stream stream)
        {
            ExtendedTextFrame frame  = (ExtendedTextFrame)this.FrameToWrite;
            List <Field>      fields = new List <Field>();

            // Declare the fields to write.
            fields.Add(new SingleByteField((byte)this.Encoding));
            if (frame.Language == LanguageCode.Unknown)
            {
                fields.Add(new FixedLengthAsciiTextField("XXX"));
            }
            else
            {
                fields.Add(new FixedLengthAsciiTextField(frame.Language.ToString()));
            }
            fields.Add(TextField.CreateTextField(frame.Description, this.Encoding));
            fields.Add(TextField.CreateTextField(frame.Text, this.Encoding));

            // Write the header
            int length = 0;

            foreach (Field f in fields)
            {
                length += f.Length;
            }
            HeaderWriter.WriteHeader(stream, new FrameHeader(this._frameID, length));

            // Write the fields
            foreach (Field f in fields)
            {
                f.WriteToStream(stream);
            }
        }
Пример #2
0
        public override void WriteToStream(System.IO.Stream stream)
        {
            //Owner identifier        <text string> $00
            //Identifier              <up to 64 bytes binary data>

            UniqueFileIdentifierFrame frame = (UniqueFileIdentifierFrame)this.FrameToWrite;
            List <Field> fields             = new List <Field>();

            // Declare the fields to write.
            fields.Add(TextField.CreateTextField(frame.Owner, EncodingScheme.Ascii));
            fields.Add(new BinaryField(frame.UniqueIdentifier, 0, frame.UniqueIdentifier.Length));

            // Write the header
            int length = 0;

            foreach (Field f in fields)
            {
                length += f.Length;
            }
            HeaderWriter.WriteHeader(stream, new FrameHeader(this.FrameID, length));

            // Write the fields
            foreach (Field f in fields)
            {
                f.WriteToStream(stream);
            }
        }
        public override void WriteToStream(System.IO.Stream stream)
        {
            //Text encoding          $xx
            //MIME type              <text string> $00
            //Filename               <text string according to encoding> $00 (00)
            //Content description    <text string according to encóding> $00 (00)
            //Encapsulated object    <binary data>

            GeneralEncapsulatedObjectFrame frame = (GeneralEncapsulatedObjectFrame)this.FrameToWrite;
            List <Field> fields = new List <Field>();

            // Declare the fields to write.
            fields.Add(new SingleByteField((byte)this.Encoding));
            fields.Add(TextField.CreateTextField(frame.MimeType, EncodingScheme.Ascii));
            fields.Add(TextField.CreateTextField(frame.Filename, this.Encoding));
            fields.Add(TextField.CreateTextField(frame.ContentDescription, this.Encoding));
            fields.Add(new BinaryField(frame.BinaryData, 0, frame.BinaryData.Length));

            // Write the header
            int length = 0;

            foreach (Field f in fields)
            {
                length += f.Length;
            }
            HeaderWriter.WriteHeader(stream, new FrameHeader(this.FrameID, length));

            // Write the fields
            foreach (Field f in fields)
            {
                f.WriteToStream(stream);
            }
        }
Пример #4
0
        public override void WriteToStream(System.IO.Stream stream)
        {
            LastPlayedOnFrame frame  = (LastPlayedOnFrame)this.FrameToWrite;
            List <Field>      fields = new List <Field>();

            // Declare the fields to write.
            fields.Add(new SingleByteField((byte)this.Encoding));  //Encoding identifier byte
            fields.Add(TextField.CreateTextField(frame.LastPlayedOn.ToShortDateString(),
                                                 EncodingScheme.Ascii));
            fields.Add(TextField.CreateTextField(frame.PlayCount.ToString(),
                                                 EncodingScheme.Ascii));
            fields.Add(TextField.CreateTextField(frame.Memo, this.Encoding));

            // Calculate the length and write the header
            int length = 0;

            foreach (Field f in fields)
            {
                length += f.Length;
            }
            HeaderWriter.WriteHeader(stream, new FrameHeader(this.FrameID, length));

            // Write the fields
            foreach (Field f in fields)
            {
                f.WriteToStream(stream);
            }
        }
Пример #5
0
        public override void WriteToStream(System.IO.Stream stream)
        {
            PictureFrame frame  = (PictureFrame)this.FrameToWrite;
            List <Field> fields = new List <Field>();

            string imageMimeType = Utils.ImagingHelpers.ImageFormatToMimeType(frame.Picture.RawFormat);

            // Declare the fields to write.
            fields.Add(new SingleByteField((byte)this.Encoding));
            fields.Add(TextField.CreateTextField(imageMimeType, EncodingScheme.Ascii));
            fields.Add(new SingleByteField((byte)frame.PictureType));
            fields.Add(TextField.CreateTextField(frame.Description, this.Encoding));
            fields.Add(new BinaryField(frame.RawData, 0, (int)frame.RawData.Length));

            // Write the header
            int length = 0;

            foreach (Field f in fields)
            {
                length += f.Length;
            }
            HeaderWriter.WriteHeader(stream, new FrameHeader(this.FrameID, length));

            // Write the fields
            foreach (Field f in fields)
            {
                f.WriteToStream(stream);
            }
        }
Пример #6
0
        public override void WriteToStream(System.IO.Stream stream)
        {
            PlayCounterFrame frame  = (PlayCounterFrame)this.FrameToWrite;
            List <Field>     fields = new List <Field>();

            // Declare the fields to write.
            byte[] data = new byte[4];
            int    c    = frame.Counter;

            data[3] = (byte)(c % 0x100);
            c     >>= 8;
            data[2] = (byte)(c % 0x100);
            c     >>= 8;
            data[1] = (byte)(c % 0x100);
            c     >>= 8;
            data[0] = (byte)(c % 0x100);
            fields.Add(new BinaryField(data, 0, data.Length));

            // Write the header
            int length = 0;

            foreach (Field f in fields)
            {
                length += f.Length;
            }
            HeaderWriter.WriteHeader(stream, new FrameHeader(this.FrameID, length));

            // Write the fields
            foreach (Field f in fields)
            {
                f.WriteToStream(stream);
            }
        }
Пример #7
0
        public IXLWorkbook Write(IEnumerable <T> datasoure)
        {
            var workbook = new XLWorkbook();


            var workSheet = workbook.AddWorksheet("test");

            HeaderWriter.WriteHeader(workSheet);
            WriteAllRows(workSheet, datasoure);
            return(workbook);
        }
Пример #8
0
        public void WriteTestMethod()
        {
            ushort           _length = 16;
            HeaderWriterTest _htw    = new HeaderWriterTest(x => { });
            HeaderWriter     _hw     = new HeaderWriter(_htw, _length);

            _htw.Write((byte)0x1);
            _htw.Write((byte)0x1);
            _htw.Write((byte)0x1);
            _htw.Write((byte)0x1);
            _hw.WriteHeader((x, y) => { });
            Assert.AreEqual <long>(_length + 4, _htw.Position);
            _htw.Write((byte)0x1);
            _htw.Write((byte)0x1);
            _htw.Write((byte)0x1);
            _htw.Write((byte)0x1);
            Assert.AreEqual <long>(_length + 8, _htw.Position);
            _hw.WriteHeader((x, y) => { });
            Assert.AreEqual <long>(_length + 8, _htw.Position);
        }
        /// <inheritdoc />
        public async Task WriteEntries(IReadOnlyCollection <TDbcWriteType> entries)
        {
            //The reason we don't do anything if we encounter no entires
            //is someone could have a partial database. It is not their fault if they don't want to
            //maintain some DBC types
            //So we must just skip writing emptyones
            if (entries.Count == 0)
            {
                if (Logger.IsEnabled(LogLevel.Warning))
                {
                    Logger.LogWarning($"Skipping TableType: {entries.Count} because it has no entries. If this is not desired you must populate the table somehow.");
                }

                return;
            }

            if (Logger.IsEnabled(LogLevel.Information))
            {
                Logger.LogDebug($"Writing: {entries.Count} Type: {typeof(TDbcWriteType).Name}");
            }

            //TODO: Make this more efficient
            DbcStringDatabase stringDatabase = StringDatabaseProvider.BuildDatabase();

            //We must move the writer ahead to leave room for the header
            //which we must write at the end.
            //TODO: This is a hack, we put a fake header in the stream at first so we can rewrite it later.
            await HeaderWriter.WriteHeader(new DBCHeader(1, 1, 1, 1));

            int entrySize = await EntryWriter.WriteContents(entries);

            //We have to order this otherwise the strings may be out of order based on their
            //offset that we set the original members to.
            var stringCollection = stringDatabase.StringToOffsetMap
                                   .OrderBy(pair => pair.Value)
                                   .Select(s => s.Key)
                                   .ToArray();

            await StringWriter.WriteStringContents(stringCollection);

            DBCHeader header = new DBCHeader(entries.Count, CalculateFieldCount(entrySize), entrySize, (int)stringDatabase.Currentoffset);

            if (Logger.IsEnabled(LogLevel.Debug))
            {
                Logger.LogDebug($"Generating Header for Type: {typeof(TDbcWriteType).Name} with HeaderValue: {header}");
            }

            //Now write the real header
            await HeaderWriter.WriteHeader(header);
        }
        void ProcessFile(string sourceFile, MarkdownProcessor markdownProcessor)
        {
            log($"Processing {sourceFile}");
            var target = GetTargetFile(sourceFile, targetDirectory);

            using (var reader = File.OpenText(sourceFile))
                using (var writer = File.CreateText(target))
                {
                    if (writeHeader)
                    {
                        HeaderWriter.WriteHeader(sourceFile, targetDirectory, writer);
                    }

                    var result  = markdownProcessor.Apply(reader, writer);
                    var missing = result.MissingSnippets;
                    if (missing.Any())
                    {
                        throw new MissingSnippetsException(missing);
                    }
                }
        }
Пример #11
0
        public async Task <MemoryStream> SpeakToMemoryStreamWithHeaderAdded(string text)
        {
            var speechConfig = configuration.GetSection("CognitiveSpeech").Get <CognitiveSpeechConfig>();
            var config       = SpeechConfig.FromSubscription(speechConfig.SubscriptionKey, speechConfig.Region);

            config.SetSpeechSynthesisOutputFormat(SpeechSynthesisOutputFormat.Riff16Khz16BitMonoPcm);

            byte[] data = await SynthesisWithByteStreamToByteArrayAsync(ssmlFactory.CreateSsmlForText(text), config);

            if (data == null)
            {
                return(null);
            }
            MemoryStream ms = new MemoryStream();

            HeaderWriter.WriteHeader(ms, data.Length, 1, 16000);
            ms.Write(data);

            ms.Position = 0;

            return(ms);
        }
        /// <summary>
        /// Open the stream for the provided ExecutionContext.
        /// </summary>
        /// <param name="executionContext">current step's ExecutionContext.  Will be the
        /// executionContext from the last run of the step on a restart.</param>
        /// <exception cref="ItemStreamException">&nbsp;</exception>
        /// <exception cref="ArgumentException">&nbsp;if execution context is null</exception>
        public override void Open(ExecutionContext executionContext)
        {
            Assert.NotNull(Resource, "The resource must be set.");
            Assert.IsTrue(!Resource.Exists() || (Resource.GetFileInfo().Attributes & FileAttributes.Directory) == 0,
                          "Cannot write write, resource is a directory: " + Resource);

            if (_initialized)
            {
                return;
            }

            if (executionContext.ContainsKey(Restart) && (bool)executionContext.Get(Restart))
            {
                if ((executionContext.ContainsKey(WriteInProcess) && (bool)executionContext.Get(WriteInProcess)))
                {
                    executionContext.Put(WriteInProcess, false);
                    if (executionContext.ContainsKey(ProcessWriterPreFix + GetExecutionContextKey(RestartDataName)))
                    {
                        RestoreWriteInProcessFrom(executionContext);
                    }
                }
                else
                {
                    if (executionContext.ContainsKey(GetExecutionContextKey(RestartDataName)))
                    {
                        RestoreFrom(executionContext);
                    }
                }
            }

            InitializeWriter();

            if (_lastMarkedByteOffsetPosition == 0 && !_appending && HeaderWriter != null)
            {
                HeaderWriter.WriteHeader(_writer);
                Write(LineSeparator);
            }
        }
        public override void WriteToStream(System.IO.Stream stream)
        {
            MusicCDIdentifierFrame frame  = (MusicCDIdentifierFrame)this.FrameToWrite;
            List <Field>           fields = new List <Field>();

            // Declare the fields to write.
            fields.Add(new BinaryField(frame.Identifier, 0, frame.Identifier.Length));

            // Write the header
            int length = 0;

            foreach (Field f in fields)
            {
                length += f.Length;
            }
            HeaderWriter.WriteHeader(stream, new FrameHeader(this.FrameID, length));

            // Write the fields
            foreach (Field f in fields)
            {
                f.WriteToStream(stream);
            }
        }
Пример #14
0
        public override void WriteToStream(System.IO.Stream stream)
        {
            UrlFrame     frame  = (UrlFrame)this.FrameToWrite;
            List <Field> fields = new List <Field>();

            // Declare the fields to write.
            fields.Add(TextField.CreateTextField(frame.Url, EncodingScheme.Ascii));

            // Write the header
            int length = 0;

            foreach (Field f in fields)
            {
                length += f.Length;
            }
            HeaderWriter.WriteHeader(stream, new FrameHeader(this.FrameID, length));

            // Write the fields
            foreach (Field f in fields)
            {
                f.WriteToStream(stream);
            }
        }
Пример #15
0
        public override void WriteToStream(System.IO.Stream stream)
        {
            TextFrame    frame  = (TextFrame)this.FrameToWrite;
            List <Field> fields = new List <Field>();

            // Declare the fields to write.
            fields.Add(new SingleByteField((byte)this.Encoding));
            fields.Add(TextField.CreateTextField(frame.Text, this.Encoding));

            // Write the header
            int length = 0;

            foreach (Field f in fields)
            {
                length += f.Length;
            }
            HeaderWriter.WriteHeader(stream, new FrameHeader(this.FrameID, length));

            // Write the fields
            foreach (Field f in fields)
            {
                f.WriteToStream(stream);
            }
        }
Пример #16
0
        public override void WriteToStream(System.IO.Stream stream)
        {
            PrivateFrame frame  = (PrivateFrame)this.FrameToWrite;
            List <Field> fields = new List <Field>();

            // Declare the fields to write.
            fields.Add(TextField.CreateTextField(frame.OwnerIdentifier, EncodingScheme.Ascii));
            fields.Add(new BinaryField(frame.PrivateData, 0, frame.PrivateData.Length));

            // Write the header
            int length = 0;

            foreach (Field f in fields)
            {
                length += f.Length;
            }
            HeaderWriter.WriteHeader(stream, new FrameHeader(this.FrameID, length));

            // Write the fields
            foreach (Field f in fields)
            {
                f.WriteToStream(stream);
            }
        }
Пример #17
0
 public Task WriteHeaderHeaderCustom()
 {
     return(Verifier.Verify(HeaderWriter.WriteHeader("thePath", @"line1\nline2", "\r\n")));
 }
Пример #18
0
 public Task WriteHeaderDefaultHeader()
 {
     return(Verifier.Verify(HeaderWriter.WriteHeader("thePath", null, "\r\n")));
 }