Skip to content
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

fixes for the serializer #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
45 changes: 0 additions & 45 deletions Api/API.csproj

This file was deleted.

8 changes: 6 additions & 2 deletions Api/Entities/OneDriveCreateFolder.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
using System.Text.Json.Serialization;
using KoenZomers.OneDrive.Api.Enums;
using System.Text.Json.Serialization;

namespace KoenZomers.OneDrive.Api.Entities
{
internal class OneDriveCreateFolder : OneDriveItemBase
public class OneDriveCreateFolder : OneDriveItemBase
{
[JsonPropertyName("name")]
public string Name { get; set; }

[JsonPropertyName("folder")]
public object Folder { get; set; }

[JsonPropertyName("@microsoft.graph.conflictBehavior")]
public NameConflictBehavior? NameConflictBehahiorAnnotation { get; set; }
}
}
2 changes: 1 addition & 1 deletion Api/Entities/OneDriveItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public class OneDriveItem : OneDriveItemBase
/// <summary>
/// The conflict resolution behavior for actions that create a new item. An item will never be returned with this annotation. Write-only.
/// </summary>
[JsonPropertyName("@name.conflictBehavior")]
[JsonPropertyName("@microsoft.graph.conflictBehavior")]
public NameConflictBehavior? NameConflictBehahiorAnnotation { get; set; }

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Api/Entities/OneDriveUploadSessionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace KoenZomers.OneDrive.Api.Entities
{
internal class OneDriveUploadSessionItem
{
[JsonPropertyName("@name.conflictBehavior")]
[JsonPropertyName("@microsoft.graph.conflictBehavior")]
public NameConflictBehavior FilenameConflictBehavior { get; set; }

[JsonPropertyName("name")]
Expand Down
Binary file removed Api/KoenZomers.OneDrive.Api.snk
Binary file not shown.
28 changes: 28 additions & 0 deletions Api/OneDrive.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net9.0</TargetFrameworks>
<AssemblyName>KoenZomers.OneDrive.Api</AssemblyName>
<Version>2.5.0.0</Version>
<Authors>Koen Zomers</Authors>
<Company>Koen Zomers</Company>
<Description>API in .NET 9.0 to communicate with OneDrive Personal and OneDrive for Business</Description>
<PackageProjectUrl>https://github.com/ispysoftware/OneDriveAPI</PackageProjectUrl>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageReleaseNotes>- Recompiled to support .NET Framework 9.0</PackageReleaseNotes>
<PackageLicenseUrl>https://github.com/KoenZomers/OneDriveAPI/blob/master/LICENSE.md</PackageLicenseUrl>
<Copyright>Koen Zomers</Copyright>
<RootNamespace>KoenZomers.OneDrive.Api</RootNamespace>
<AssemblyVersion>2.5.0.0</AssemblyVersion>
<FileVersion>2.5.0.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>KoenZomers.OneDrive.Api.xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>KoenZomers.OneDrive.Api.xml</DocumentationFile>
</PropertyGroup>

</Project>
18 changes: 11 additions & 7 deletions Api/OneDriveApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ namespace KoenZomers.OneDrive.Api
/// </summary>
public abstract class OneDriveApi
{
public static JsonSerializerOptions JSONOptions = new JsonSerializerOptions
{
WriteIndented = true,
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) },
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};

#region Properties

/// <summary>
Expand Down Expand Up @@ -1620,7 +1627,8 @@ protected virtual async Task<OneDriveItem> UploadFileViaResumableUploadInternal(
// Trigger event
UploadProgressChanged?.Invoke(this, new OneDriveUploadProgressChangedEventArgs(totalBytesSent, fileStream.Length));
break;

case HttpStatusCode.Unauthorized:
throw new ApplicationException("unauthorized");
// All fragments have been received, the file did already exist and has been overwritten
case HttpStatusCode.OK:
// All fragments have been received, the file has been created
Expand Down Expand Up @@ -1913,7 +1921,7 @@ protected virtual async Task<bool> RenameItemInternal(OneDriveItem oneDriveSourc
/// <returns>Typed OneDrive entity with the result from the webservice</returns>
protected virtual async Task<T> SendMessageReturnOneDriveItem<T>(OneDriveItemBase oneDriveItem, HttpMethod httpMethod, string url, HttpStatusCode? expectedHttpStatusCode = null) where T : OneDriveItemBase
{
var bodyText = oneDriveItem != null ? JsonSerializer.Serialize(oneDriveItem) : null;
var bodyText = oneDriveItem != null ? JsonSerializer.Serialize(oneDriveItem, oneDriveItem.GetType(), JSONOptions) : null;

return await SendMessageReturnOneDriveItem<T>(bodyText, httpMethod, url, expectedHttpStatusCode);
}
Expand Down Expand Up @@ -1983,11 +1991,7 @@ protected virtual async Task<string> SendMessageReturnString(string bodyText, Ht
/// <returns>Bool indicating if the HTTP response status from the webservice matched the provided expectedHttpStatusCode</returns>
protected virtual async Task<bool> SendMessageReturnBool(OneDriveItemBase oneDriveItem, HttpMethod httpMethod, string url, HttpStatusCode expectedHttpStatusCode, bool preferRespondAsync = false)
{
string bodyText = null;
if (oneDriveItem != null)
{
bodyText = JsonSerializer.Serialize(oneDriveItem);
}
var bodyText = oneDriveItem != null ? JsonSerializer.Serialize(oneDriveItem, oneDriveItem.GetType(), JSONOptions) : null;

using (var response = await SendMessageReturnHttpResponse(bodyText, httpMethod, url, preferRespondAsync))
{
Expand Down