-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new InputFormatter to format input data
- Loading branch information
1 parent
0add24b
commit 09b4919
Showing
30 changed files
with
972 additions
and
700 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
libraries/MTConnect.NET-Common/Formatters/FormatReadResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright (c) 2023 TrakHound Inc., All Rights Reserved. | ||
// TrakHound Inc. licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace MTConnect.Formatters | ||
{ | ||
public struct FormatReadResult<T> | ||
{ | ||
public T Content { get; set; } | ||
|
||
public bool Success { get; set; } | ||
|
||
public IEnumerable<string> Messages { get; set; } | ||
|
||
public IEnumerable<string> Warnings { get; set; } | ||
|
||
public IEnumerable<string> Errors { get; set; } | ||
|
||
public double ResponseDuration { get; set; } | ||
|
||
|
||
public FormatReadResult(T content, bool success = true, IEnumerable<string> messages = null, IEnumerable<string> warnings = null, IEnumerable<string> errors = null) | ||
{ | ||
Content = content; | ||
Success = success; | ||
Messages = messages; | ||
Warnings = warnings; | ||
Errors = errors; | ||
ResponseDuration = 0; | ||
} | ||
|
||
|
||
public static FormatReadResult<T> Successful(T content, string message = null) | ||
{ | ||
var messages = new List<string>(); | ||
if (!string.IsNullOrEmpty(message)) messages = new List<string> { message }; | ||
|
||
return new FormatReadResult<T>(content, true, messages); | ||
} | ||
|
||
public static FormatReadResult<T> Successful(T content, IEnumerable<string> messages) | ||
{ | ||
return new FormatReadResult<T>(content, true, messages); | ||
} | ||
|
||
|
||
public static FormatReadResult<T> Warning(T content, string warning = null) | ||
{ | ||
var warnings = new List<string>(); | ||
if (!string.IsNullOrEmpty(warning)) warnings = new List<string> { warning }; | ||
|
||
return new FormatReadResult<T>(content, true, null, warnings); | ||
} | ||
|
||
public static FormatReadResult<T> Warning(T content, IEnumerable<string> warnings) | ||
{ | ||
return new FormatReadResult<T>(content, true, null, warnings); | ||
} | ||
|
||
|
||
public static FormatReadResult<T> Error(T content, string error = null) | ||
{ | ||
var errors = new List<string>(); | ||
if (!string.IsNullOrEmpty(error)) errors = new List<string> { error }; | ||
|
||
return new FormatReadResult<T>(content, false, null, null, errors); | ||
} | ||
|
||
public static FormatReadResult<T> Error(T content, IEnumerable<string> errors) | ||
{ | ||
return new FormatReadResult<T>(content, false, null, null, errors); | ||
} | ||
|
||
public static FormatReadResult<T> Error(IEnumerable<string> errors = null) | ||
{ | ||
return new FormatReadResult<T>(default, false, null, null, errors); | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
libraries/MTConnect.NET-Common/Formatters/FormatWriteResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright (c) 2023 TrakHound Inc., All Rights Reserved. | ||
// TrakHound Inc. licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace MTConnect.Formatters | ||
{ | ||
public struct FormatWriteResult | ||
{ | ||
public byte[] Content { get; set; } | ||
|
||
public string ContentType { get; set; } | ||
|
||
public bool Success { get; set; } | ||
|
||
public IEnumerable<string> Messages { get; set; } | ||
|
||
public IEnumerable<string> Warnings { get; set; } | ||
|
||
public IEnumerable<string> Errors { get; set; } | ||
|
||
public double ResponseDuration { get; set; } | ||
|
||
|
||
public FormatWriteResult(byte[] content, string contentType, bool success = true, IEnumerable<string> messages = null, IEnumerable<string> warnings = null, IEnumerable<string> errors = null) | ||
{ | ||
Content = content; | ||
ContentType = contentType; | ||
Success = success; | ||
Messages = messages; | ||
Warnings = warnings; | ||
Errors = errors; | ||
ResponseDuration = 0; | ||
} | ||
|
||
|
||
public static FormatWriteResult Successful(byte[] content, string contentType, string message = null) | ||
{ | ||
var messages = new List<string>(); | ||
if (!string.IsNullOrEmpty(message)) messages = new List<string> { message }; | ||
|
||
return new FormatWriteResult(content, contentType, true, messages); | ||
} | ||
|
||
public static FormatWriteResult Successful(byte[] content, string contentType, IEnumerable<string> messages) | ||
{ | ||
return new FormatWriteResult(content, contentType, true, messages); | ||
} | ||
|
||
|
||
public static FormatWriteResult Warning(byte[] content, string contentType, string warning = null) | ||
{ | ||
var warnings = new List<string>(); | ||
if (!string.IsNullOrEmpty(warning)) warnings = new List<string> { warning }; | ||
|
||
return new FormatWriteResult(content, contentType, true, null, warnings); | ||
} | ||
|
||
public static FormatWriteResult Warning(byte[] content, string contentType, IEnumerable<string> warnings) | ||
{ | ||
return new FormatWriteResult(content, contentType, true, null, warnings); | ||
} | ||
|
||
|
||
public static FormatWriteResult Error(byte[] content, string contentType, string error = null) | ||
{ | ||
var errors = new List<string>(); | ||
if (!string.IsNullOrEmpty(error)) errors = new List<string> { error }; | ||
|
||
return new FormatWriteResult(content, contentType, false, null, null, errors); | ||
} | ||
|
||
public static FormatWriteResult Error(byte[] content, string contentType, IEnumerable<string> errors) | ||
{ | ||
return new FormatWriteResult(content, contentType, false, null, null, errors); | ||
} | ||
|
||
public static FormatWriteResult Error(IEnumerable<string> errors = null) | ||
{ | ||
return new FormatWriteResult(null, null, false, null, null, errors); | ||
} | ||
} | ||
} |
Oops, something went wrong.