Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #16 from xpouyat/dev
Browse files Browse the repository at this point in the history
Fixes an issue with enum for job creation, better serialisation and null management
  • Loading branch information
xpouyat authored Nov 20, 2023
2 parents fac9473 + 096c6e4 commit 64f8bda
Show file tree
Hide file tree
Showing 161 changed files with 385 additions and 346 deletions.
2 changes: 1 addition & 1 deletion MK.IO/Account/Models/AccountProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class AccountProfile
{
public static AccountProfile FromJson(string json)
{
return JsonConvert.DeserializeObject<AccountProfile>(json, ConverterLE.Settings);
return JsonConvert.DeserializeObject<AccountProfile>(json, ConverterLE.Settings) ?? throw new Exception("Error with account profile deserialization");
}

public string ToJson()
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/Account/Models/AccountStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class AccountStats
{
public static AccountStats FromJson(string json)
{
return JsonConvert.DeserializeObject<AccountStats>(json, ConverterLE.Settings);
return JsonConvert.DeserializeObject<AccountStats>(json, ConverterLE.Settings) ?? throw new Exception("Error with account stats deserialization");
}

public string ToJson()
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/Account/Models/LocationListResponseSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public partial class LocationListResponseSchema
{
public static LocationListResponseSchema FromJson(string json)
{
return JsonConvert.DeserializeObject<LocationListResponseSchema>(json, ConverterLE.Settings);
return JsonConvert.DeserializeObject<LocationListResponseSchema>(json, ConverterLE.Settings) ?? throw new Exception("Error with location deserialization");
}

public string ToJson()
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/Account/Models/LocationResponseSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public partial class LocationResponseSchema
{
public static LocationResponseSchema FromJson(string json)
{
return JsonConvert.DeserializeObject<LocationResponseSchema>(json, ConverterLE.Settings);
return JsonConvert.DeserializeObject<LocationResponseSchema>(json, ConverterLE.Settings) ?? throw new Exception("Error with location response deserialization");
}

public string ToJson()
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/Account/Models/SubscriptionListResponseSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public partial class SubscriptionListResponseSchema
{
public static SubscriptionListResponseSchema FromJson(string json)
{
return JsonConvert.DeserializeObject<SubscriptionListResponseSchema>(json, ConverterLE.Settings);
return JsonConvert.DeserializeObject<SubscriptionListResponseSchema>(json, ConverterLE.Settings) ?? throw new Exception("Error with subscription list deserialization");
}

public string ToJson()
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/Account/Models/SubscriptionResponseSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class SubscriptionResponseSchema
{
public static SubscriptionResponseSchema FromJson(string json)
{
return JsonConvert.DeserializeObject<SubscriptionResponseSchema>(json, ConverterLE.Settings);
return JsonConvert.DeserializeObject<SubscriptionResponseSchema>(json, ConverterLE.Settings) ?? throw new Exception("Error with subscription deserialization");
}

public string ToJson()
Expand Down
10 changes: 6 additions & 4 deletions MK.IO/AccountFilter/AccountFiltersOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public async Task<List<AccountFilterSchema>> ListAsync()
{
var url = Client.GenerateApiUrl(_accountFiltersApiUrl);
string responseContent = await Client.GetObjectContentAsync(url);
return JsonConvert.DeserializeObject<AccountFilterListResponseSchema>(responseContent, ConverterLE.Settings).Value;

var objectToReturn = JsonConvert.DeserializeObject<AccountFilterListResponseSchema>(responseContent, ConverterLE.Settings);
return objectToReturn != null ? objectToReturn.Value : throw new Exception($"Error with account filter deserialization");
}

/// <inheritdoc/>
Expand All @@ -58,7 +60,7 @@ public async Task<AccountFilterSchema> GetAsync(string accountFilterName)

var url = Client.GenerateApiUrl(_accountFilterApiUrl, accountFilterName);
string responseContent = await Client.GetObjectContentAsync(url);
return JsonConvert.DeserializeObject<AccountFilterSchema>(responseContent, ConverterLE.Settings);
return JsonConvert.DeserializeObject<AccountFilterSchema>(responseContent, ConverterLE.Settings) ?? throw new Exception("Error with account filter deserialization");
}

/// <inheritdoc/>
Expand All @@ -81,8 +83,8 @@ public async Task<AccountFilterSchema> CreateOrUpdateAsync(string accountFilterN
Properties = properties
};

string responseContent = await Client.CreateObjectAsync(url, JsonConvert.SerializeObject(content, Formatting.Indented));
return JsonConvert.DeserializeObject<AccountFilterSchema>(responseContent, ConverterLE.Settings);
string responseContent = await Client.CreateObjectAsync(url, JsonConvert.SerializeObject(content, ConverterLE.Settings));
return JsonConvert.DeserializeObject<AccountFilterSchema>(responseContent, ConverterLE.Settings) ?? throw new Exception("Error with account filter deserialization");
}

/// <inheritdoc/>
Expand Down
50 changes: 34 additions & 16 deletions MK.IO/Asset/AssetsOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public async Task<List<AssetSchema>> ListAsync(string? orderBy = null, int? top
url = MKIOClient.AddParametersToUrl(url, "$top", top != null ? ((int)top).ToString() : null);
url = MKIOClient.AddParametersToUrl(url, "$filter", filter);
string responseContent = await Client.GetObjectContentAsync(url);
return JsonConvert.DeserializeObject<AssetListResponseSchema>(responseContent, ConverterLE.Settings).Value;

var objectToReturn = JsonConvert.DeserializeObject<AssetListResponseSchema>(responseContent, ConverterLE.Settings);
return objectToReturn != null ? objectToReturn.Value : throw new Exception($"Error with asset list deserialization");
}

/// <inheritdoc/>
Expand All @@ -70,11 +72,19 @@ public async Task<PagedResult<AssetSchema>> ListAsPageAsync(string? orderBy = nu
dynamic responseObject = JsonConvert.DeserializeObject(responseContent);
string? nextPageLink = responseObject["@odata.nextLink"];

return new PagedResult<AssetSchema>
var objectToReturn = JsonConvert.DeserializeObject<AssetListResponseSchema>(responseContent, ConverterLE.Settings);
if (objectToReturn == null)
{
NextPageLink = WebUtility.UrlDecode(nextPageLink),
Results = JsonConvert.DeserializeObject<AssetListResponseSchema>(responseContent, ConverterLE.Settings).Value
};
throw new Exception($"Error with asset list deserialization");
}
else
{
return new PagedResult<AssetSchema>
{
NextPageLink = WebUtility.UrlDecode(nextPageLink),
Results = objectToReturn.Value
};
}
}

/// <inheritdoc/>
Expand All @@ -94,11 +104,19 @@ public async Task<PagedResult<AssetSchema>> ListAsPageNextAsync(string? nextPage

nextPageLink = responseObject["@odata.nextLink"];

return new PagedResult<AssetSchema>
var objectToReturn = JsonConvert.DeserializeObject<AssetListResponseSchema>(responseContent, ConverterLE.Settings);
if (objectToReturn == null)
{
NextPageLink = WebUtility.UrlDecode(nextPageLink),
Results = JsonConvert.DeserializeObject<AssetListResponseSchema>(responseContent, ConverterLE.Settings).Value
};
throw new Exception($"Error with asset list deserialization");
}
else
{
return new PagedResult<AssetSchema>
{
NextPageLink = WebUtility.UrlDecode(nextPageLink),
Results = objectToReturn.Value
};
}
}

/// <inheritdoc/>
Expand All @@ -114,18 +132,18 @@ public async Task<AssetSchema> GetAsync(string assetName)

var url = Client.GenerateApiUrl(_assetApiUrl, assetName);
string responseContent = await Client.GetObjectContentAsync(url);
return JsonConvert.DeserializeObject<AssetSchema>(responseContent, ConverterLE.Settings);
return JsonConvert.DeserializeObject<AssetSchema>(responseContent, ConverterLE.Settings) ?? throw new Exception("Error with asset deserialization");
}

/// <inheritdoc/>
public AssetSchema CreateOrUpdate(string assetName, string containerName, string storageName, string description = null)
public AssetSchema CreateOrUpdate(string assetName, string containerName, string storageName, string? description = null)
{
Task<AssetSchema> task = Task.Run(async () => await CreateOrUpdateAsync(assetName, containerName, storageName, description));
return task.GetAwaiter().GetResult();
}

/// <inheritdoc/>
public async Task<AssetSchema> CreateOrUpdateAsync(string assetName, string containerName, string storageName, string description = null)
public async Task<AssetSchema> CreateOrUpdateAsync(string assetName, string containerName, string storageName, string? description = null)
{
Argument.AssertNotNullOrEmpty(assetName, nameof(assetName));
Argument.AssertNotNullOrEmpty(containerName, nameof(containerName));
Expand All @@ -137,13 +155,13 @@ public async Task<AssetSchema> CreateOrUpdateAsync(string assetName, string cont
Properties = new AssetProperties
{
Container = containerName,
Description = description,
Description = description!,
StorageAccountName = storageName
}
};

string responseContent = await Client.CreateObjectAsync(url, JsonConvert.SerializeObject(content, Formatting.Indented));
return JsonConvert.DeserializeObject<AssetSchema>(responseContent, ConverterLE.Settings);
string responseContent = await Client.CreateObjectAsync(url, JsonConvert.SerializeObject(content, ConverterLE.Settings));
return JsonConvert.DeserializeObject<AssetSchema>(responseContent, ConverterLE.Settings) ?? throw new Exception("Error with asset deserialization");
}

/// <inheritdoc/>
Expand Down Expand Up @@ -192,7 +210,7 @@ public async Task<AssetStorageResponseSchema> ListTracksAndDirListingAsync(strin

var url = Client.GenerateApiUrl(_assetListTracksAndDirectoryApiUrl, assetName);
string responseContent = await Client.GetObjectContentAsync(url);
return JsonConvert.DeserializeObject<AssetStorageResponseSchema>(responseContent, ConverterLE.Settings);
return JsonConvert.DeserializeObject<AssetStorageResponseSchema>(responseContent, ConverterLE.Settings) ?? throw new Exception("Error with asset storage deserialization");
}
}
}
4 changes: 2 additions & 2 deletions MK.IO/Asset/IAssetsOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public interface IAssetsOperations
/// <param name="storageName"></param>
/// <param name="description"></param>
/// <returns></returns>
AssetSchema CreateOrUpdate(string assetName, string containerName, string storageName, string description = null);
AssetSchema CreateOrUpdate(string assetName, string containerName, string storageName, string? description = null);

/// <summary>
/// Create or Update Asset.
Expand All @@ -107,7 +107,7 @@ public interface IAssetsOperations
/// <param name="storageName"></param>
/// <param name="description"></param>
/// <returns></returns>
Task<AssetSchema> CreateOrUpdateAsync(string assetName, string containerName, string storageName, string description = null);
Task<AssetSchema> CreateOrUpdateAsync(string assetName, string containerName, string storageName, string? description = null);

/// <summary>
/// List Streaming Locators for Asset. This API call is a convenience method to retrieve
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/Asset/Models/AssetListStreamingLocators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class AssetListStreamingLocators
{
public static AssetListStreamingLocators FromJson(string json)
{
return JsonConvert.DeserializeObject<AssetListStreamingLocators>(json, ConverterLE.Settings);
return JsonConvert.DeserializeObject<AssetListStreamingLocators>(json, ConverterLE.Settings) ?? throw new Exception("Error with asset list deserialization");
}

public string ToJson()
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/Asset/Models/AssetTracksAndDir.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class AssetTracksAndDir
{
public static AssetTracksAndDir FromJson(string json)
{
return JsonConvert.DeserializeObject<AssetTracksAndDir>(json, ConverterLE.Settings);
return JsonConvert.DeserializeObject<AssetTracksAndDir>(json, ConverterLE.Settings) ?? throw new Exception("Error with asset tracks deserialization");
}

public string ToJson()
Expand Down
9 changes: 5 additions & 4 deletions MK.IO/AssetFilter/AssetFiltersOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public async Task<List<AssetFilterSchema>> ListAsync(string assetName)

var url = Client.GenerateApiUrl(_assetFiltersApiUrl, assetName);
string responseContent = await Client.GetObjectContentAsync(url);
return JsonConvert.DeserializeObject<AssetFilterListResponseSchema>(responseContent, ConverterLE.Settings).Value;
var objectToReturn = JsonConvert.DeserializeObject<AssetFilterListResponseSchema>(responseContent, ConverterLE.Settings);
return objectToReturn != null ? objectToReturn.Value : throw new Exception($"Error with asset filter list deserialization");
}

/// <inheritdoc/>
Expand All @@ -64,7 +65,7 @@ public async Task<AssetFilterSchema> GetAsync(string assetName, string filterNam

var url = Client.GenerateApiUrl(_assetFilterApiUrl, assetName, filterName);
string responseContent = await Client.GetObjectContentAsync(url);
return JsonConvert.DeserializeObject<AssetFilterSchema>(responseContent, ConverterLE.Settings);
return JsonConvert.DeserializeObject<AssetFilterSchema>(responseContent, ConverterLE.Settings) ?? throw new Exception("Error with asset filter deserialization");
}

/// <inheritdoc/>
Expand All @@ -88,8 +89,8 @@ public async Task<AssetFilterSchema> CreateOrUpdateAsync(string assetName, strin
Properties = properties
};

string responseContent = await Client.CreateObjectAsync(url, JsonConvert.SerializeObject(content, Formatting.Indented));
return JsonConvert.DeserializeObject<AssetFilterSchema>(responseContent, ConverterLE.Settings);
string responseContent = await Client.CreateObjectAsync(url, JsonConvert.SerializeObject(content, ConverterLE.Settings));
return JsonConvert.DeserializeObject<AssetFilterSchema>(responseContent, ConverterLE.Settings) ?? throw new Exception("Error with asset filter deserialization");
}

/// <inheritdoc/>
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/ContentKeyPolicy/Models/ContentKeyPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ContentKeyPolicy(string description, List<ContentKeyPolicyOption> content

public static ContentKeyPolicy FromJson(string json)
{
return JsonConvert.DeserializeObject<ContentKeyPolicy>(json, ConverterLE.Settings);
return JsonConvert.DeserializeObject<ContentKeyPolicy>(json, ConverterLE.Settings) ?? throw new Exception("Error with content key policy deserialization");
}

public string ToJson()
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/ContentKeyPolicy/Models/ListContentKeyPolicies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ListContentKeyPolicies
{
public static ListContentKeyPolicies FromJson(string json)
{
return JsonConvert.DeserializeObject<ListContentKeyPolicies>(json, ConverterLE.Settings);
return JsonConvert.DeserializeObject<ListContentKeyPolicies>(json, ConverterLE.Settings) ?? throw new Exception("Error with content key policies deserialization");
}

public string ToJson()
Expand Down
1 change: 1 addition & 0 deletions MK.IO/ConverterLE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal static class ConverterLE
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore,
Formatting = Formatting.Indented,
//DateParseHandling = DateParseHandling.None,
Converters =
{
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/CsharpDotNet2/Model/Accessibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override string ToString()
/// <returns>JSON string presentation of the object</returns>
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this, ConverterLE.Settings);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override string ToString()
/// <returns>JSON string presentation of the object</returns>
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this, ConverterLE.Settings);
}

}
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/CsharpDotNet2/Model/AccountFilterSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public override string ToString()
/// <returns>JSON string presentation of the object</returns>
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this, ConverterLE.Settings);
}

}
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/CsharpDotNet2/Model/AdaptationSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public override string ToString()
/// <returns>JSON string presentation of the object</returns>
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this, ConverterLE.Settings);
}

}
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/CsharpDotNet2/Model/AkamiHeaderAuthKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override string ToString()
/// <returns>JSON string presentation of the object</returns>
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this, ConverterLE.Settings);
}

}
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/CsharpDotNet2/Model/AnyValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override string ToString()
/// <returns>JSON string presentation of the object</returns>
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this, ConverterLE.Settings);
}

}
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/CsharpDotNet2/Model/AssetFilterListResponseSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override string ToString()
/// <returns>JSON string presentation of the object</returns>
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this, ConverterLE.Settings);
}

}
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/CsharpDotNet2/Model/AssetFilterSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public override string ToString()
/// <returns>JSON string presentation of the object</returns>
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this, ConverterLE.Settings);
}

}
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/CsharpDotNet2/Model/AssetIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override string ToString()
/// <returns>JSON string presentation of the object</returns>
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this, ConverterLE.Settings);
}

}
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/CsharpDotNet2/Model/AssetListResponseSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override string ToString()
/// <returns>JSON string presentation of the object</returns>
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this, ConverterLE.Settings);
}

}
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/CsharpDotNet2/Model/AssetProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public override string ToString()
/// <returns>JSON string presentation of the object</returns>
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this, ConverterLE.Settings);
}

}
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/CsharpDotNet2/Model/AssetSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public override string ToString()
/// <returns>JSON string presentation of the object</returns>
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this, ConverterLE.Settings);
}

}
Expand Down
Loading

0 comments on commit 64f8bda

Please sign in to comment.