Skip to content

Small fixes #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Redmine.Net.Api.Serialization
internal sealed class XmlRedmineSerializer : IRedmineSerializer
{

public XmlRedmineSerializer(): this(new XmlWriterSettings
public XmlRedmineSerializer() : this(new XmlWriterSettings
{
OmitXmlDeclaration = true
}) { }
Expand Down Expand Up @@ -126,6 +126,11 @@ public string Serialize<T>(T entity) where T : class
var limit = xmlReader.ReadAttributeAsInt(RedmineKeys.LIMIT);
var result = xmlReader.ReadElementContentAsCollection<T>();

if (totalItems == 0 && result.Count > 0)
{
totalItems = result.Count;
}

return new PagedResults<T>(result, totalItems, offset, limit);
}
}
Expand Down
40 changes: 40 additions & 0 deletions src/redmine-net-api/Types/IssueAllowedStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ limitations under the License.
*/

using System.Diagnostics;
using System.Xml;
using System.Xml.Serialization;
using Newtonsoft.Json;
using Redmine.Net.Api.Extensions;

namespace Redmine.Net.Api.Types
{
Expand All @@ -26,6 +29,43 @@ namespace Redmine.Net.Api.Types
[XmlRoot(RedmineKeys.STATUS)]
public sealed class IssueAllowedStatus : IdentifiableName
{
/// <summary>
///
/// </summary>
public bool? IsClosed { get; internal set; }

/// <inheritdoc />
public override void ReadXml(XmlReader reader)
{
Id = reader.ReadAttributeAsInt(RedmineKeys.ID);
Name = reader.GetAttribute(RedmineKeys.NAME);
IsClosed = reader.ReadAttributeAsBoolean(RedmineKeys.IS_CLOSED);
reader.Read();
}

/// <inheritdoc />
public override void ReadJson(JsonReader reader)
{
while (reader.Read())
{
if (reader.TokenType == JsonToken.EndObject)
{
return;
}

if (reader.TokenType == JsonToken.PropertyName)
{
switch (reader.Value)
{
case RedmineKeys.ID: Id = reader.ReadAsInt(); break;
case RedmineKeys.NAME: Name = reader.ReadAsString(); break;
case RedmineKeys.IS_CLOSED: IsClosed = reader.ReadAsBoolean(); break;
default: reader.Read(); break;
}
}
}
}

private string DebuggerDisplay => $"[{nameof(IssueAllowedStatus)}: {ToString()}]";
}
}
4 changes: 1 addition & 3 deletions src/redmine-net-api/Types/TrackerCoreField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Redmine.Net.Api.Types
///
/// </summary>
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
[XmlRoot(RedmineKeys.TRACKER)]
[XmlRoot(RedmineKeys.FIELD)]
public sealed class TrackerCoreField: IXmlSerializable, IJsonSerializable, IEquatable<TrackerCoreField>
{
/// <summary>
Expand All @@ -40,7 +40,6 @@ public XmlSchema GetSchema()
///
/// </summary>
/// <param name="reader"></param>
/// <exception cref="NotImplementedException"></exception>
public void ReadXml(XmlReader reader)
{
reader.Read();
Expand All @@ -66,7 +65,6 @@ public void WriteJson(JsonWriter writer) { }
///
/// </summary>
/// <param name="reader"></param>
/// <exception cref="NotImplementedException"></exception>
public void ReadJson(JsonReader reader)
{
while (reader.Read())
Expand Down
61 changes: 53 additions & 8 deletions src/redmine-net-api/Types/WikiPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,16 @@ public override void ReadXml(XmlReader reader)
case RedmineKeys.TITLE: Title = reader.ReadElementContentAsString(); break;
case RedmineKeys.UPDATED_ON: UpdatedOn = reader.ReadElementContentAsNullableDateTime(); break;
case RedmineKeys.VERSION: Version = reader.ReadElementContentAsInt(); break;
case RedmineKeys.PARENT: ParentTitle = reader.GetAttribute(RedmineKeys.PARENT); break;
case RedmineKeys.PARENT:
{
if (reader.HasAttributes)
{
ParentTitle = reader.GetAttribute(RedmineKeys.TITLE);
reader.Read();
}

break;
}
default: reader.Read(); break;
}
}
Expand Down Expand Up @@ -206,14 +215,28 @@ public override bool Equals(WikiPage other)
{
if (other == null) return false;

return Id == other.Id
&& Title == other.Title
&& Text == other.Text
&& Comments == other.Comments
return base.Equals(other)
&& string.Equals(Title, other.Title, StringComparison.Ordinal)
&& string.Equals(Text, other.Text, StringComparison.Ordinal)
&& string.Equals(Comments, other.Comments, StringComparison.Ordinal)
&& Version == other.Version
&& Author == other.Author
&& CreatedOn == other.CreatedOn
&& UpdatedOn == other.UpdatedOn;
&& Equals(Author, other.Author)
&& CreatedOn.Equals(other.CreatedOn)
&& UpdatedOn.Equals(other.UpdatedOn)
&& Equals(Attachments, other.Attachments);
}

/// <summary>
///
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != GetType()) return false;
return Equals(obj as WikiPage);
}

/// <summary>
Expand All @@ -236,6 +259,28 @@ public override int GetHashCode()
return hashCode;
}
}

/// <summary>
///
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator ==(WikiPage left, WikiPage right)
{
return Equals(left, right);
}

/// <summary>
///
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator !=(WikiPage left, WikiPage right)
{
return !Equals(left, right);
}
#endregion

/// <summary>
Expand Down
Loading