/// <summary>Writes the nbt's content to the <see cref="Stream"/></summary> /// <param name="tag">The tag to write to the <see cref="Stream"/></param> /// <param name="Context">The context to write to</param> public void WriteContent(NBTTagList tag, SerializationContext Context) { NBTTagType SubTagType = tag.SubType; ITagWriter Writer = NBTWriter.GetWriter(SubTagType); if (Writer == null) { throw new Exception($"Cannot find writer for {SubTagType}"); } Int32 Count = tag.Count; if (SubTagType == NBTTagType.List) { /*SubTag = new NBTTagList(SubTagType); * SubTag.SetInformation(NBTTagInformation.ListSubtype, (NBTTagType)Context.Stream.ReadByte()); * SubTag.SetInformation(NBTTagInformation.ListSize, Context.ReadInt32()); * Reader.ReadContent(SubTag, Context); * tag[I] = SubTag;*/ Context.Stream.WriteByte((Byte)tag.GetInformation(NBTTagInformation.ListSubtype)); Context.WriteInt32((Int32)tag.GetInformation(NBTTagInformation.ListSize)); } else { for (Int32 I = 0; I < Count; I++) { Writer.WriteContent(tag[I], Context); } } }
private void Init() { IStreamableFileFactory scopeService = ScopeUtils.GetScopeService(this._scope, typeof(IStreamableFileFactory)) as IStreamableFileFactory; string directoryName = Path.GetDirectoryName(this._file.FullName); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } if (!this._file.Exists) { using (this._file.Create()) { } } IStreamableFile streamableFile = scopeService.GetService(this._file).GetStreamableFile(this._file); if ((this._mode == null) || this._mode.Equals("record")) { this._writer = streamableFile.GetWriter(); } else { if (!this._mode.Equals("append")) { throw new NotSupportedException("Illegal mode type: " + this._mode); } this._writer = streamableFile.GetAppendWriter(); } }
/// <summary> /// Reset /// </summary> private void Uninit() { lock (this.SyncRoot) { if (_writer != null) { _writer.Close(); _writer = null; } } }
public TagWriteEditor(ITagWriter tag) { InitializeComponent(); _tag = tag; if (!string.IsNullOrEmpty(_tag.TagWriteText)) { foreach (var item in _tag.TagWriteText.GetListFromText()) { _list.Add(new TagValue { Tag = item.Key, Value = item.Value }); } } bindingSource1.DataSource = new SortableBindingList <TagValue>(_list); var list = TagList.GetTagNameList(); chkPulse.Checked = tag.IsPulse; foreach (var item in list) { combo1.Items.Add(item); } }
/// <summary>Writes the nbt's content to the <see cref="Stream"/></summary> /// <param name="tag">The tag to write to the <see cref="Stream"/></param> /// <param name="Context">The context to write to</param> public void WriteContent(ITag tag, SerializationContext Context) { Object O = tag.GetInformation(NBTTagInformation.ListSubtype); if (O == null) { throw new Exception("Cannot read list sub type"); } var SubTagType = (NBTTagType)O; ITagWriter Writer = NBTWriter.GetWriter(SubTagType); if (Writer == null) { throw new Exception($"Cannot find writer for {SubTagType}"); } Int32 Count = tag.Count; if (SubTagType == NBTTagType.List) { for (Int32 I = 0; I < Count; I++) { ITag Item = tag[I]; Context.Stream.WriteByte((Byte)Item.GetInformation(NBTTagInformation.ListSubtype)); Context.WriteInt32((Int32)Item.GetInformation(NBTTagInformation.ListSize)); Writer.WriteContent(Item, Context); } } else { for (Int32 I = 0; I < Count; I++) { Writer.WriteContent(tag[I], Context); } } }
private void Init() { IStreamableFileFactory factory = ScopeUtils.GetScopeService(_scope, typeof(IStreamableFileFactory)) as IStreamableFileFactory; string directory = Path.GetDirectoryName(_file.FullName); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } if (!_file.Exists) { // Maybe the (previously existing) file has been deleted using (FileStream fs = _file.Create()){} } /* * else if (_file.IsReadOnly) * { * throw new IOException("The file is read-only"); * } */ IStreamableFileService service = factory.GetService(_file); IStreamableFile flv = service.GetStreamableFile(_file); if (_mode == null || _mode.Equals(Constants.ClientStreamModeRecord)) { _writer = flv.GetWriter(); } else if (_mode.Equals(Constants.ClientStreamModeAppend)) { _writer = flv.GetAppendWriter(); } else { throw new NotSupportedException("Illegal mode type: " + _mode); } }
private void Init() { IStreamableFileFactory factory = ScopeUtils.GetScopeService(_scope, typeof(IStreamableFileFactory)) as IStreamableFileFactory; string directory = Path.GetDirectoryName(_file.FullName); if (!Directory.Exists(directory)) Directory.CreateDirectory(directory); if (!_file.Exists) { // Maybe the (previously existing) file has been deleted using( FileStream fs = _file.Create()){} } /* else if (_file.IsReadOnly) { throw new IOException("The file is read-only"); } */ IStreamableFileService service = factory.GetService(_file); IStreamableFile flv = service.GetStreamableFile(_file); if (_mode == null || _mode.Equals(Constants.ClientStreamModeRecord)) { _writer = flv.GetWriter(); } else if (_mode.Equals(Constants.ClientStreamModeAppend)) { _writer = flv.GetAppendWriter(); } else { throw new NotSupportedException("Illegal mode type: " + _mode); } }
public TagAdapter(ITagWriter tagWriter) { _tagWriter = tagWriter; }