void OnWriterState(Writer writer, WriterState writerState) { if (writerState == WriterState.Start && correctTagCount != 0) { IntegrationTest.Fail(); } if (writerState == WriterState.Pause && correctTagCount != 2) { IntegrationTest.Fail(); } if (writerState == WriterState.Resume && correctTagCount != 2) { IntegrationTest.Fail(); } else if (writerState == WriterState.End && correctTagCount != 4) { IntegrationTest.Fail(); } if (writerState == WriterState.End) { if (!receivedInput) { IntegrationTest.Fail(); } if (glyphCount != 6) { IntegrationTest.Fail(); } IntegrationTest.Pass(); } }
public Sgml.ISgmlWriter Attribute(string name, object value) { if (_state == WriterState.startElem) _writer.Object(); _writer.Prop("@" + name, value); _state = WriterState.elemData; return this; }
public GraphVizWriter(System.IO.StreamWriter streamwriter) { if (streamwriter == null) { throw new System.ArgumentNullException("streamwriter"); } this.streamwriter = streamwriter; this.state = WriterState.Begin; }
private void Initialize(XamlXmlWriter xamlXmlWriter) { this.xamlXmlWriter = xamlXmlWriter; this.settings = xamlXmlWriter.Settings; this.meSettings = this.meSettings ?? new XamlMarkupExtensionWriterSettings(); this.currentState = Start.State; this.sb = new StringBuilder(); this.nodes = new Stack<Node>(); this.failed = false; }
public Sgml.ISgmlWriter Element(string name) { if (!(_tags.Count > 0 && _tags.Peek().Group && _tags.Peek().Name == name)) { if (_state == WriterState.startElem) _writer.Object(); _writer.Prop(name); } _tags.Push(new Tag() { Group = false, Name = name }); _state = WriterState.startElem; return this; }
private void ExitBracket() { this._state = this.States.Pop(); if (this._state.Bracket == JsonWriterBracket.Pending) { this._state.Bracket = JsonWriterBracket.Closed; } else { this.OnValueWritten(); } }
public WriterState Pop() { if (_count == 0) throw new InvalidOperationException(); WriterState state = _states[--_count]; if (_count == 0) _states = null; return state; }
public static void WriteAll <TKey, TValue>(WriterState writer, object obj) { var dictionary = (IDictionary <TKey, TValue>)obj; writer.Write((byte)SerializedType.Dictionary); writer.Write(dictionary.Count); foreach (var(key, value) in dictionary) { Serializer.WriteValue(writer, key); Serializer.WriteValue(writer, value); } }
public void WriteTableRow(params string[] data) { if (this.lastTableColumns == null && !this.state.HasBitFlags(WriterState.TableHeader)) { this.lastTableColumns = data; } ValidateWriteTableRow(data); WriteTableRow(data, WriteCol); this.state &= ~WriterState.Property; this.state &= ~WriterState.TableHeader; this.state |= WriterState.TableRow; }
protected override void HandleInternal(WriterState writer, object val) { if (val == null) { WriteNull(writer, MemberName); } else { WriteMemberName(writer, MemberName); Serializer.WriteNonPrimitive(writer, (T)val); } }
public void WriteTypeTagEnd() { CheckWriterState(WriterState.TypeTag); // write null terminator Write((byte)0); WritePadding(); Flush(); state = WriterState.Arguments; }
private static void WriteList(WriterState writer, ICollection list) { writer.Write((byte)SerializedType.List); writer.Write(list.Count); if (GenericWriter.WriteList(writer, list)) { return; } // fallback to non-generic version WriteListFallback(writer, list); }
public void EndObject() { if (state != WriterState.ExpectingProperty) { throw new InvalidOperationException("EndObject was called in an unappropriate place."); } //writer.WriteEndElement(); writer.WriteEndElement(); state = stateStack.Pop(); OnWritingValue(); pathBuilder.OnEndObject(); }
private void ExitBracket() { _state = States.Pop(); if (_state.Bracket == JsonWriterBracket.Pending) { _state.Bracket = JsonWriterBracket.Closed; } else { OnValueWritten(); } }
private static void WriteEnumerable(WriterState writer, IEnumerable enumerable) { // ReSharper disable once PossibleMultipleEnumeration if (GenericWriter.WriteEnumerable(writer, enumerable)) { return; } // fallback to non-generic version (we are not enumerating twice) writer.Write((byte)SerializedType.Enumerable); // ReSharper disable once PossibleMultipleEnumeration WriteEnumerableFallback(writer, enumerable); }
private void WriteTableCellAfter(bool lastCellInRow = false) { tw.Write(Consts.IonSpecialChars.WriteSpaceCharacter); tw.Write(Consts.IonSpecialChars.TableOpeningCharacter); if (lastCellInRow) { WriteLine(); this.firstTableCell = true; } this.state &= ~WriterState.Property; this.state &= ~WriterState.TableHeader; this.state |= WriterState.TableRow; }
/** * Ends a pi section */ public bool endPI() { if (_state != WriterState.PI) { return(false); } _state = WriterState.ELEMENT_BODY; _s.append("?>"); return(true); }
private static void WriteDictionaryAsObject(WriterState writer, IDictionary <string, object> dictionary) { writer.Write((byte)SerializedType.Object); foreach (var(key, value) in dictionary.Keys.Zip(dictionary.Values)) { writer.Write((byte)EnumerableType.HasItem); writer.WriteString(key); WriteValue(writer, value); } writer.Write((byte)EnumerableType.End); }
/** * Starts a CData section */ public bool endCData() { if (_state != WriterState.CDATA) { return(false); } _state = WriterState.ELEMENT_BODY; _s.append("]]>"); return(true); }
/** * Starts an attribute */ public bool startAttribute(Env env, StringValue name) { if (_state != WriterState.ELEMENT_HEADER) { return(false); } _s.append(" ").append(env, name).append("=\""); _state = WriterState.ATTRIBUTE; return(true); }
public void EndArray() { if (arrayTypeStack.Peek() != TrwValueType.Undefined) { structuredArrayBuilder.Append("]"); writer.WriteString(structuredArrayBuilder.ToString()); } writer.WriteEndElement(); state = stateStack.Pop(); arrayTypeStack.Pop(); OnWritingValue(); pathBuilder.OnEndArray(); }
/** * Starts a comment section */ public bool endComment() { if (_state != WriterState.COMMENT) { return(false); } _state = WriterState.ELEMENT_BODY; _s.append("-->"); return(true); }
public void WriteProperty(string name, Action <TextWriter> writeValueAction) { if (writeValueAction == null) { throw new ArgumentNullException($"Provide {nameof(writeValueAction)} parameter"); } ValidateWriteProperty(name); ClearState(); this.tw.Write(name); this.tw.Write(Consts.IonSpecialChars.EqualsCharacter); writeValueAction(this.tw); WriteLine(); this.state |= WriterState.Property; }
public WriterState Pop() { if (_count == 0) { throw new InvalidOperationException(); } WriterState result = _states[--_count]; if (_count == 0) { _states = null; } return(result); }
public void Push(WriterState state) { if (_states == null) { _states = new WriterState[6]; } else if (_count == _states.Length) { WriterState[] array = new WriterState[_states.Length * 2]; _states.CopyTo(array, 0); _states = array; } _states[_count++] = state; }
public void StartObject() { if (state == WriterState.ExpectingStartRootObject) { writer.WriteStartElement("Root"); } else if (state == WriterState.ExpectingArrayElement) { writer.WriteStartElement(ArrayElemStr); } stateStack.Push(state); state = WriterState.ExpectingProperty; pathBuilder.OnStartObject(); }
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.HtmlMobileTextWriter"]/*' /> public HtmlMobileTextWriter(TextWriter writer, MobileCapabilities device) : base(writer, device) { RenderBold = device.SupportsBold; RenderItalic = device.SupportsItalic; RenderFontSize = device.SupportsFontSize; RenderFontName = device.SupportsFontName; RenderFontColor = device.SupportsFontColor; RenderBodyColor = device.SupportsBodyColor; RenderDivAlign = device.SupportsDivAlign; RenderDivNoWrap = device.SupportsDivNoWrap; RequiresNoBreakInFormatting = device.RequiresNoBreakInFormatting; _currentState = new WriterState(this); }
public void WriteSection(string name) { if (state != WriterState.None) { WriteLine(); this.state = WriterState.Section; } ValidateWriteSection(name); ClearState(); this.tw.Write(Consts.IonSpecialChars.HeaderOpeningCharacter); this.tw.Write(name); WriteLine(Consts.IonSpecialChars.HeaderClosingCharacter); this.state |= WriterState.Section; }
/** * Opens the writer for a memory target */ public bool openMemory(Env env) { StringValue s = env.createUnicodeBuilder(); _s = new MemoryXMLWriterStream(s); _nsMap.clear(); _elementStack.clear(); _nsStack.clear(); _state = WriterState.TOP; return(true); }
public ISampleWriter StartSample(string suffix = "") { ValidateState(nameof(StartSample), WriterState.MetricStarted | WriterState.HelpWritten | WriterState.TypeWritten | WriterState.ValueWritten | WriterState.TimestampWritten); if (_hasData) { Write(_newLine); } _hasData = true; Write(_currentMetricName); Write(suffix); _state = WriterState.SampleStarted; return(this); }
protected virtual void OnWriterState(Writer writer, WriterState writerState) { if (writerState == WriterState.End) { var sd = SayDialog.GetSayDialog(); if (sd != null) { NarrativeLogEntry entry = new NarrativeLogEntry() { name = sd.NameText, text = sd.StoryText }; AddLine(entry); } } }
public ILabelWriter WriteLabel(string name, string value) { ValidateState(nameof(WriteLabel), WriterState.LabelsStarted | WriterState.LabelWritten); if (_state == WriterState.LabelWritten) { Write(_labelsSeparator); } Write(name); Write(_labelsEq); Write(_labelTextQualifier); Write(EscapeValue(value)); Write(_labelTextQualifier); _state = WriterState.LabelWritten; return(this); }
private void EnterScope(WriterState newState, ODataItem item) { this.InterceptException(() => this.ValidateTransition(newState)); bool skipWriting = this.SkipWriting; Scope currentScope = this.CurrentScope; if (((currentScope.State == WriterState.Entry) && (newState == WriterState.NavigationLink)) && !skipWriting) { ProjectedPropertiesAnnotation projectedProperties = currentScope.Item.GetAnnotation<ProjectedPropertiesAnnotation>(); ODataNavigationLink link = (ODataNavigationLink) item; skipWriting = projectedProperties.ShouldSkipProperty(link.Name); } else if ((currentScope.State == WriterState.Feed) && (newState == WriterState.Entry)) { FeedScope scope1 = (FeedScope) currentScope; scope1.EntryCount++; } this.PushScope(newState, item, skipWriting); }
public ISampleWriter StartSample(string suffix = "") { ValidateState(nameof(StartSample), WriterState.MetricStarted | WriterState.HelpWritten | WriterState.TypeWritten | WriterState.SampleClosed); if (_currentMetricEncoded == default) { _currentMetricEncoded = Write(_currentMetricName); } else { Write(_currentMetricEncoded.AsSpan()); } Write(suffix); _state = WriterState.SampleStarted; return(this); }
/** * Opens the writer for a uri target */ public bool openURI(Env env, string path) { try { WriteStream @out = path.openWrite(); _s = new PathXMLWriterStream(out); _nsMap.clear(); _elementStack.clear(); _nsStack.clear(); _state = WriterState.TOP; } catch (IOException e) { log.log(Level.WARNING, e.ToString(), e); } return(true); }
/** * Starts an attribute with a namespace */ public bool startAttributeNS(Env env, StringValue prefix, StringValue name, StringValue uri) { if (_state != WriterState.ELEMENT_HEADER) { return(false); } pushNamespace(env, prefix, uri); _s.append(" ").append(env, prefix).append(":").append(env, name); _s.append("=\""); _state = WriterState.ATTRIBUTE; return(true); }
public void WriteAddress(string address) { CheckWriterState(WriterState.Address); // write the address WriteDirect(Encoding.UTF8.GetBytes(address)); // write null terminator Write((byte)0); WritePadding(); // write the comma for the type-tag Write((byte)','); Flush(); state = WriterState.TypeTag; }
private void EnterScope(WriterState newState, ODataItem item) { this.InterceptException(() => this.ValidateTransition(newState)); // If the parent scope was marked for skipping content, the new child scope should be as well. bool skipWriting = this.SkipWriting; Scope currentScope = this.CurrentScope; // When writing a navigation link, check if the link is being projected. // If we are projecting properties, but the nav. link is not projected mark it to skip its content. if (currentScope.State == WriterState.Entry && newState == WriterState.NavigationLink && !skipWriting) { Debug.Assert(currentScope.Item is ODataEntry, "If the current state is Entry the current Item must be entry as well (and not null either)."); Debug.Assert(item is ODataNavigationLink, "If the new state is NavigationLink the new item must be a navigation link as well (and not null either)."); ProjectedPropertiesAnnotation projectedProperties = currentScope.Item.GetAnnotation<ProjectedPropertiesAnnotation>(); ODataNavigationLink navigationLink = (ODataNavigationLink)item; skipWriting = projectedProperties.ShouldSkipProperty(navigationLink.Name); } else if (currentScope.State == WriterState.Feed && newState == WriterState.Entry) { // When we're entering an entry scope on a feed, increment the count of entries on that feed. ((FeedScope)currentScope).EntryCount++; } this.PushScope(newState, item, skipWriting); }
/// <summary> /// Verify that the transition from the current state into new state is valid . /// </summary> /// <param name="newState">The new writer state to transition into.</param> private void ValidateTransition(WriterState newState) { if (!IsErrorState(this.State) && IsErrorState(newState)) { // we can always transition into an error state if we are not already in an error state return; } switch (this.State) { case WriterState.Start: if (newState != WriterState.DeltaFeed) { throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromStart(this.State.ToString(), newState.ToString())); } break; case WriterState.DeltaEntry: case WriterState.DeltaDeletedEntry: case WriterState.DeltaLink: case WriterState.DeltaDeletedLink: if (this.CurrentScope.Item == null) { throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromNullEntry(this.State.ToString(), newState.ToString())); } break; case WriterState.DeltaFeed: if (newState != WriterState.DeltaEntry && newState != WriterState.DeltaDeletedEntry && newState != WriterState.DeltaLink && newState != WriterState.DeltaDeletedLink) { throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromFeed(this.State.ToString(), newState.ToString())); } break; case WriterState.Completed: // we should never see a state transition when in state 'Completed' throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromCompleted(this.State.ToString(), newState.ToString())); case WriterState.Error: if (newState != WriterState.Error) { // No more state transitions once we are in error state except for the fatal error throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromError(this.State.ToString(), newState.ToString())); } break; default: throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataWriterCore_ValidateTransition_UnreachableCodePath)); } }
/// <summary> /// Constructor to create a new delta link scope. /// </summary> /// <param name="state">The writer state of this scope.</param> /// <param name="link">The link for the new scope.</param> /// <param name="serializationInfo">The serialization info for the current entry.</param> /// <param name="navigationSource">The navigation source we are going to write entities for.</param> /// <param name="entityType">The entity type for the entries in the feed to be written (or null if the entity set base type should be used).</param> /// <param name="writerBehavior">The <see cref="ODataWriterBehavior"/> instance controlling the behavior of the writer.</param> /// <param name="selectedProperties">The selected properties of this scope.</param> /// <param name="odataUri">The ODataUri info of this scope.</param> internal JsonLightDeltaLinkScope(WriterState state, ODataItem link, ODataDeltaSerializationInfo serializationInfo, IEdmNavigationSource navigationSource, IEdmEntityType entityType, ODataWriterBehavior writerBehavior, SelectedPropertiesNode selectedProperties, ODataUri odataUri) : base(state, link, serializationInfo, navigationSource, entityType, writerBehavior, selectedProperties, odataUri) { }
/// <summary> /// Constructor to create a new delta link scope. /// </summary> /// <param name="state">The writer state of this scope.</param> /// <param name="link">The link for the new scope.</param> /// <param name="serializationInfo">The serialization info for the current entry.</param> /// <param name="navigationSource">The navigation source we are going to write entities for.</param> /// <param name="entityType">The entity type for the entries in the feed to be written (or null if the entity set base type should be used).</param> /// <param name="writerBehavior">The <see cref="ODataWriterBehavior"/> instance controlling the behavior of the writer.</param> /// <param name="selectedProperties">The selected properties of this scope.</param> /// <param name="odataUri">The ODataUri info of this scope.</param> protected DeltaLinkScope(WriterState state, ODataItem link, ODataDeltaSerializationInfo serializationInfo, IEdmNavigationSource navigationSource, IEdmEntityType entityType, ODataWriterBehavior writerBehavior, SelectedPropertiesNode selectedProperties, ODataUri odataUri) : base(state, link, navigationSource, entityType, selectedProperties, odataUri) { Debug.Assert(link != null, "link != null"); Debug.Assert( state == WriterState.DeltaLink && link is ODataDeltaLink || state == WriterState.DeltaDeletedLink && link is ODataDeltaDeletedLink, "link must be either DeltaLink or DeltaDeletedLink."); Debug.Assert(writerBehavior != null, "writerBehavior != null"); this.serializationInfo = DeltaConverter.ToFeedAndEntrySerializationInfo(serializationInfo); }
public void Reset() { this.currentState = Start.State; this.sb = new StringBuilder(); this.nodes.Clear(); this.failed = false; }
private void ExitBracket() { _state = States.Pop(); if (_state.Bracket == JsonWriterBracket.Pending) _state.Bracket = JsonWriterBracket.Closed; else OnValueWritten(); }
protected JsonWriterBase() { _state = new WriterState(JsonWriterBracket.Pending); }
/// <summary> /// Create a new delta link scope. /// </summary> /// <param name="state">The writer state of the scope to create.</param> /// <param name="link">The link for the new scope.</param> /// <param name="navigationSource">The navigation source we are going to write entities for.</param> /// <param name="entityType">The entity type for the entries in the feed to be written (or null if the entity set base type should be used).</param> /// <param name="selectedProperties">The selected properties of this scope.</param> /// <param name="odataUri">The ODataUri info of this scope.</param> /// <returns>The newly create scope.</returns> private DeltaLinkScope CreateDeltaLinkScope(WriterState state, ODataItem link, IEdmNavigationSource navigationSource, IEdmEntityType entityType, SelectedPropertiesNode selectedProperties, ODataUri odataUri) { return new JsonLightDeltaLinkScope( state, link, this.GetLinkSerializationInfo(link), navigationSource, entityType, this.jsonLightOutputContext.MessageWriterSettings.WriterBehavior, selectedProperties, odataUri); }
/// <summary> /// Create a new writer scope. /// </summary> /// <param name="state">The writer state of the scope to create.</param> /// <param name="item">The item attached to the scope to create.</param> /// <param name="navigationSource">The navigation source we are going to write entities for.</param> /// <param name="entityType">The entity type for the entries in the feed to be written (or null if the entity set base type should be used).</param> /// <param name="selectedProperties">The selected properties of this scope.</param> /// <param name="odataUri">The OdataUri info of this scope.</param> private void PushScope(WriterState state, ODataItem item, IEdmNavigationSource navigationSource, IEdmEntityType entityType, SelectedPropertiesNode selectedProperties, ODataUri odataUri) { Debug.Assert( state == WriterState.Error || state == WriterState.DeltaEntry && item is ODataEntry || state == WriterState.DeltaDeletedEntry && item is ODataDeltaDeletedEntry || state == WriterState.DeltaFeed && item is ODataDeltaFeed || state == WriterState.DeltaLink && item is ODataDeltaLink || state == WriterState.DeltaDeletedLink && item is ODataDeltaDeletedLink || state == WriterState.Start && item == null || state == WriterState.Completed && item == null, "Writer state and associated item do not match."); Scope scope; switch (state) { case WriterState.DeltaEntry: scope = this.CreateDeltaEntryScope(WriterState.DeltaEntry, item, navigationSource, entityType, selectedProperties, odataUri); break; case WriterState.DeltaDeletedEntry: scope = this.CreateDeltaEntryScope(WriterState.DeltaDeletedEntry, item, navigationSource, entityType, selectedProperties, odataUri); break; case WriterState.DeltaFeed: scope = this.CreateDeltaFeedScope(item, navigationSource, entityType, selectedProperties, odataUri); break; case WriterState.DeltaLink: scope = this.CreateDeltaLinkScope(WriterState.DeltaLink, item, navigationSource, entityType, selectedProperties, odataUri); break; case WriterState.DeltaDeletedLink: scope = this.CreateDeltaLinkScope(WriterState.DeltaDeletedLink, item, navigationSource, entityType, selectedProperties, odataUri); break; case WriterState.Start: // fall through case WriterState.Completed: // fall through case WriterState.Error: scope = new Scope(state, item, navigationSource, entityType, selectedProperties, odataUri); break; default: string errorMessage = Strings.General_InternalError(InternalErrorCodes.ODataWriterCore_Scope_Create_UnreachableCodePath); Debug.Assert(false, errorMessage); throw new ODataException(errorMessage); } this.scopes.Push(scope); }
/// <summary> /// Enter a new writer scope; verifies that the transition from the current state into new state is valid /// and attaches the item to the new scope. /// </summary> /// <param name="newState">The writer state to transition into.</param> /// <param name="item">The item to associate with the new scope.</param> private void EnterScope(WriterState newState, ODataItem item) { Debug.Assert(item != null, "item != null"); this.InterceptException(() => this.ValidateTransition(newState)); Scope currentScope = this.CurrentScope; IEdmNavigationSource navigationSource = null; IEdmEntityType entityType = null; SelectedPropertiesNode selectedProperties = currentScope.SelectedProperties; ODataUri odataUri = currentScope.ODataUri.Clone(); if (newState == WriterState.DeltaEntry || newState == WriterState.DeltaDeletedEntry || newState == WriterState.DeltaLink || newState == WriterState.DeltaDeletedLink || newState == WriterState.DeltaFeed) { navigationSource = currentScope.NavigationSource; entityType = currentScope.EntityType; } WriterState currentState = currentScope.State; if ((newState == WriterState.DeltaEntry || newState == WriterState.DeltaDeletedEntry || newState == WriterState.DeltaLink || newState == WriterState.DeltaDeletedLink) && currentState == WriterState.DeltaFeed) { this.CurrentDeltaFeedScope.EntryAndLinkCount++; } this.PushScope(newState, item, navigationSource, entityType, selectedProperties, odataUri); }
/// <summary> /// Constructor to create a new JSON Light navigation link scope. /// </summary> /// <param name="writerState">The writer state for the new scope.</param> /// <param name="navLink">The navigation link for the new scope.</param> /// <param name="navigationSource">The navigation source we are going to write entities for.</param> /// <param name="entityType">The entity type for the entries in the feed to be written (or null if the entity set base type should be used).</param> /// <param name="skipWriting">true if the content of the scope to create should not be written.</param> /// <param name="selectedProperties">The selected properties of this scope.</param> /// <param name="odataUri">The ODataUri info of this scope.</param> internal JsonLightNavigationLinkScope(WriterState writerState, ODataNavigationLink navLink, IEdmNavigationSource navigationSource, IEdmEntityType entityType, bool skipWriting, SelectedPropertiesNode selectedProperties, ODataUri odataUri) : base(writerState, navLink, navigationSource, entityType, skipWriting, selectedProperties, odataUri) { }
/// <summary> /// Creates a new JSON Light navigation link scope. /// </summary> /// <param name="writerState">The writer state for the new scope.</param> /// <param name="navLink">The navigation link for the new scope.</param> /// <param name="navigationSource">The navigation source we are going to write entities for.</param> /// <param name="entityType">The entity type for the entries in the feed to be written (or null if the entity set base type should be used).</param> /// <param name="skipWriting">true if the content of the scope to create should not be written.</param> /// <param name="selectedProperties">The selected properties of this scope.</param> /// <param name="odataUri">The ODataUri info of this scope.</param> /// <returns>The newly created JSON Light navigation link scope.</returns> protected override NavigationLinkScope CreateNavigationLinkScope(WriterState writerState, ODataNavigationLink navLink, IEdmNavigationSource navigationSource, IEdmEntityType entityType, bool skipWriting, SelectedPropertiesNode selectedProperties, ODataUri odataUri) { return new JsonLightNavigationLinkScope(writerState, navLink, navigationSource, entityType, skipWriting, selectedProperties, odataUri); }
/// <summary> /// Clones this JSON Light navigation link scope and sets a new writer state. /// </summary> /// <param name="newWriterState">The writer state to set.</param> /// <returns>The cloned navigation link scope with the specified writer state.</returns> internal override NavigationLinkScope Clone(WriterState newWriterState) { return new JsonLightNavigationLinkScope(newWriterState, (ODataNavigationLink)this.Item, this.NavigationSource, this.EntityType, this.SkipWriting, this.SelectedProperties, this.ODataUri) { EntityReferenceLinkWritten = this.entityReferenceLinkWritten, FeedWritten = this.feedWritten, }; }
/// <summary> /// Determines whether a given writer state is considered an error state. /// </summary> /// <param name="state">The writer state to check.</param> /// <returns>True if the writer state is an error state; otherwise false.</returns> protected static bool IsErrorState(WriterState state) { return state == WriterState.Error; }
/// <summary> /// Constructor to create a new navigation link scope. /// </summary> /// <param name="writerState">The writer state for the new scope.</param> /// <param name="navLink">The navigation link for the new scope.</param> /// <param name="skipWriting">true if the content of the scope to create should not be written.</param> internal NavigationLinkScope(WriterState writerState, ODataNavigationLink navLink, bool skipWriting) : base(writerState, navLink, skipWriting) { DebugUtils.CheckNoExternalCallers(); }
/// <summary> /// Constructor creating a new writer scope. /// </summary> /// <param name="state">The writer state of this scope.</param> /// <param name="item">The item attached to this scope.</param> /// <param name="skipWriting">true if the content of this scope should not be written.</param> internal Scope(WriterState state, ODataItem item, bool skipWriting) { DebugUtils.CheckNoExternalCallers(); this.state = state; this.item = item; this.skipWriting = skipWriting; }
public void Push(WriterState state) { if (_states == null) { _states = new WriterState[6]; } else if (_count == _states.Length) { WriterState[] items = new WriterState[_states.Length * 2]; _states.CopyTo(items, 0); _states = items; } _states[_count++] = state; }
/// <summary> /// Constructor to create a new entry scope. /// </summary> /// <param name="state">The writer state of this scope.</param> /// <param name="entry">The entry for the new scope.</param> /// <param name="serializationInfo">The serialization info for the current entry.</param> /// <param name="navigationSource">The navigation source we are going to write entities for.</param> /// <param name="entityType">The entity type for the entries in the feed to be written (or null if the entity set base type should be used).</param> /// <param name="writerBehavior">The <see cref="ODataWriterBehavior"/> instance controlling the behavior of the writer.</param> /// <param name="selectedProperties">The selected properties of this scope.</param> /// <param name="odataUri">The ODataUri info of this scope.</param> protected DeltaEntryScope(WriterState state, ODataItem entry, ODataFeedAndEntrySerializationInfo serializationInfo, IEdmNavigationSource navigationSource, IEdmEntityType entityType, ODataWriterBehavior writerBehavior, SelectedPropertiesNode selectedProperties, ODataUri odataUri) : base(state, entry, navigationSource, entityType, selectedProperties, odataUri) { Debug.Assert(entry != null, "entry != null"); Debug.Assert( state == WriterState.DeltaEntry && entry is ODataEntry || state == WriterState.DeltaDeletedEntry && entry is ODataDeltaDeletedEntry, "entry must be either DeltaEntry or DeltaDeletedEntry."); Debug.Assert(writerBehavior != null, "writerBehavior != null"); this.duplicatePropertyNamesChecker = new DuplicatePropertyNamesChecker(writerBehavior.AllowDuplicatePropertyNames, /*writingResponse*/ true); this.serializationInfo = serializationInfo; }
/// <summary> /// Determines whether a given writer state is considered an error state. /// </summary> /// <param name="state">The writer state to check.</param> /// <returns>True if the writer state is an error state; otherwise false.</returns> private static bool IsErrorState(WriterState state) { return state == WriterState.Error; }
private void ValidateTransition(WriterState newState) { if (!IsErrorState(this.State) && IsErrorState(newState)) { // we can always transition into an error state if we are not already in an error state return; } switch (this.State) { case WriterState.Start: if (newState != WriterState.Feed && newState != WriterState.Entry) { throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromStart(this.State.ToString(), newState.ToString())); } if (newState == WriterState.Feed && !this.writingFeed) { throw new ODataException(Strings.ODataWriterCore_CannotWriteTopLevelFeedWithEntryWriter); } if (newState == WriterState.Entry && this.writingFeed) { throw new ODataException(Strings.ODataWriterCore_CannotWriteTopLevelEntryWithFeedWriter); } break; case WriterState.Entry: { if (this.CurrentScope.Item == null) { throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromNullEntry(this.State.ToString(), newState.ToString())); } if (newState != WriterState.NavigationLink) { throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromEntry(this.State.ToString(), newState.ToString())); } } break; case WriterState.Feed: if (newState != WriterState.Entry) { throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromFeed(this.State.ToString(), newState.ToString())); } break; case WriterState.NavigationLink: if (newState != WriterState.NavigationLinkWithContent) { throw new ODataException(Strings.ODataWriterCore_InvalidStateTransition(this.State.ToString(), newState.ToString())); } break; case WriterState.NavigationLinkWithContent: if (newState != WriterState.Feed && newState != WriterState.Entry) { throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromExpandedLink(this.State.ToString(), newState.ToString())); } break; case WriterState.Completed: // we should never see a state transition when in state 'Completed' throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromCompleted(this.State.ToString(), newState.ToString())); case WriterState.Error: if (newState != WriterState.Error) { // No more state transitions once we are in error state except for the fatal error throw new ODataException(Strings.ODataWriterCore_InvalidTransitionFromError(this.State.ToString(), newState.ToString())); } break; default: throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataWriterCore_ValidateTransition_UnreachableCodePath)); } }
/// <summary> /// Constructor creating a new writer scope. /// </summary> /// <param name="state">The writer state of this scope.</param> /// <param name="item">The item attached to this scope.</param> /// <param name="navigationSource">The navigation source we are going to write entities for.</param> /// <param name="entityType">The entity type for the entries in the feed to be written (or null if the entity set base type should be used).</param> /// <param name="selectedProperties">The selected properties of this scope.</param> /// <param name="odataUri">The ODataUri info of this scope.</param> internal Scope(WriterState state, ODataItem item, IEdmNavigationSource navigationSource, IEdmEntityType entityType, SelectedPropertiesNode selectedProperties, ODataUri odataUri) { this.state = state; this.item = item; this.EntityType = entityType; this.NavigationSource = navigationSource; this.selectedProperties = selectedProperties; this.odataUri = odataUri; }
private void PushScope(WriterState state, ODataItem item, bool skipWriting) { Debug.Assert( state == WriterState.Error || state == WriterState.Entry && (item == null || item is ODataEntry) || state == WriterState.Feed && item is ODataFeed || state == WriterState.NavigationLink && item is ODataNavigationLink || state == WriterState.NavigationLinkWithContent && item is ODataNavigationLink || state == WriterState.Start && item == null || state == WriterState.Completed && item == null, "Writer state and associated item do not match."); Scope scope; switch (state) { case WriterState.Entry: scope = this.CreateEntryScope((ODataEntry)item, skipWriting); break; case WriterState.Feed: scope = this.CreateFeedScope((ODataFeed)item, skipWriting); break; case WriterState.NavigationLink: // fall through case WriterState.NavigationLinkWithContent: scope = new NavigationLinkScope(state, (ODataNavigationLink)item, skipWriting); break; case WriterState.Start: // fall through case WriterState.Completed: // fall through case WriterState.Error: scope = new Scope(state, item, skipWriting); break; default: string errorMessage = Strings.General_InternalError(InternalErrorCodes.ODataWriterCore_Scope_Create_UnreachableCodePath); Debug.Assert(false, errorMessage); throw new ODataException(errorMessage); } this.scopes.Push(scope); }