Skip to content
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
2 changes: 1 addition & 1 deletion CSM Foundation Core.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 18
VisualStudioVersion = 18.0.11222.15 d18.0
VisualStudioVersion = 18.0.11222.15
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSM Foundation Core", "CSM Foundation Core\CSM Foundation Core.csproj", "{E39161C8-353E-40B7-B1E0-ED3E17DCC51F}"
EndProject
Expand Down
23 changes: 6 additions & 17 deletions CSM Foundation Core/Abstractions/Bases/ObjectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ namespace CSM_Foundation_Core.Abstractions.Bases;
/// Represents an inheritance link between datasource objects
/// that need specific equality comparisson between their properties.
/// </summary>
public abstract class ObjectBase<TObject> {
public class ObjectBase {

/// <inheritdoc/>
public override bool Equals(object? comparer) {
PropertyInfo[] exceptions = [];

Expand Down Expand Up @@ -77,7 +78,7 @@ public override bool Equals(object? comparer) {
return true;
}


/// <inheritdoc/>
public override string ToString() {
Dictionary<string, dynamic?> jsonReference = [];
PropertyInfo[] propReferences = GetType().GetProperties();
Expand All @@ -93,6 +94,8 @@ public override string ToString() {
}
);
}

/// <inheritdoc/>
public override int GetHashCode() {
return base.GetHashCode();
}
Expand All @@ -106,7 +109,7 @@ public override int GetHashCode() {
/// <returns>
/// Property reflected info.
/// </returns>
/// <exception cref="XGetProperty">
/// <exception cref="Exception">
/// If the Property wasn't find.
/// </exception>
public PropertyInfo GetProperty(string name) {
Expand All @@ -117,18 +120,4 @@ PropertyInfo tracedProperty

return tracedProperty;
}

public TObject Clone() {
Type ObjectType = typeof(TObject);

TObject? Cloned = (TObject?)Activator.CreateInstance(ObjectType)
?? throw new Exception("PENDING WRONG ACTIVATION");
PropertyInfo[] ObjectPropertiesInfo = ObjectType.GetProperties();
foreach (PropertyInfo PropertyInfo in ObjectPropertiesInfo) {
object? OriginalValue = PropertyInfo.GetValue(this);
PropertyInfo.SetValue(Cloned, OriginalValue);
}

return Cloned.GetHashCode() == GetHashCode() ? throw new Exception("PEDNING SAME HASH") : Cloned;
}
}
44 changes: 44 additions & 0 deletions CSM Foundation Core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
# CSM Foundation Core CHANGELOG


## [x.x.x] - xx.xx-xxxx
Comment thread
RMotive marked this conversation as resolved.
Resolved

### Added

- Added [ResourceType] enum to handle the resource types in CSM systems.
- Added [ScalarValue] enum to handle the scalar value types in CSM systems.

#### Dependencies

| Package | Previous Version | New Version |
|:----------------------------------------|:----------------:|:---------------:|
| | | |

## [4.0.0] - 19.05-2026

### Removed

- Removed [GenericUtils] class cause i only had a method for object clonation, replaced and moved to [ObjectUtils] with the method [Clone].

- Added new Error concepts and better error handling for some features that weren´t being handled correclty.

- Added a simplified [ObjectBase] abstraction for non used generic methods.

- Removed [ObjectBase{TEntity}] cause an utility method was created.

#### Dependencies

| Package | Previous Version | New Version |
|:----------------------------------------|:----------------:|:---------------:|
| | | |

## [3.0.0] - 25.12-2025

### Remved

- Removed from errors model [ErrorInfo] since it was only needed when internal errors are exposed to connected services with critical information.

#### Dependencies

| Package | Previous Version | New Version |
|:----------------------------------------|:----------------:|:---------------:|
| | | |

## [2.1.1] - 24.12-2025

### Changed
Expand Down
3 changes: 2 additions & 1 deletion CSM Foundation Core/CSM Foundation Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>CSM_Foundation_Core</RootNamespace>
<PackageId>CSM.Foundation.Core</PackageId>
<Version>2.1.1</Version>
<Version>4.0.0</Version>
<Authors>Renato Urrea</Authors>
<Company>Cosmos (CSM)</Company>
<RepositoryUrl>https://github.com/Cosmos-CSM/csm_foundation_core</RepositoryUrl>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageReadmeFile>CHANGELOG.md</PackageReadmeFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Text.Json.Serialization;

using CSM_Foundation_Core.Convertion.Abstractions.Interfaces;
using CSM_Foundation_Core.Core.Exceptions;
using CSM_Foundation_Core.Core.Errors;

namespace CSM_Foundation_Core.Convertion.Abstractions.Bases;

Expand Down Expand Up @@ -54,6 +54,7 @@ [.. wrongTypes]
}
}

/// <inheritdoc/>
public override TBase? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
JsonDocument document = JsonDocument.ParseValue(ref reader);
JsonElement element = document.RootElement;
Expand Down Expand Up @@ -83,6 +84,7 @@ [.. wrongTypes]
);
}

/// <inheritdoc/>
public override void Write(Utf8JsonWriter writer, TBase value, JsonSerializerOptions options) {
foreach (Type variation in Variants) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace CSM_Foundation_Core.Convertion.Abstractions.Bases;
public abstract class ConverterVariantBase
: IConverterVariant {

/// <inheritdoc/>
public string Discriminator { get; init; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using CSM_Foundation_Core.Convertion.Abstractions.Interfaces;
using CSM_Foundation_Core.Errors.Abstractions.Bases;

namespace CSM_Foundation_Core.Core.Exceptions;
namespace CSM_Foundation_Core.Core.Errors;

/// <summary>
/// <see cref="ConverterBaseError"/> Exception situations enumerator.
Expand Down Expand Up @@ -34,15 +34,17 @@ public class ConverterBaseError
/// <summary>
/// Creates a new <see cref="ConverterBaseError"/> instance.
/// </summary>
/// <param name="situation">
/// Exception situation.
/// <param name="event">
/// Error event.
/// </param>
/// <param name="wrongVariations">
/// Wrong variations found.
/// </param>
///
/// <param name="discriminator">
/// Discriminator when the variation convertion fails.
/// </param>
public ConverterBaseError(ConverterBaseErrorEvents situation, Type[]? wrongVariations = null, string discriminator = "")
: base("CSM Converter Exception", situation) {
public ConverterBaseError(ConverterBaseErrorEvents @event, Type[]? wrongVariations = null, string discriminator = "")
: base("CSM Converter Exception", @event) {

wrongVariations ??= [];
Data = new Dictionary<string, object?> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CSM_Foundation_Core.Errors.Abstractions.Bases;
using CSM_Foundation_Core.Errors.Models;

namespace CSM_Foundation_Core.Core.Exceptions;
namespace CSM_Foundation_Core.Core.Errors;


/// <summary>
Expand Down
18 changes: 16 additions & 2 deletions CSM Foundation Core/Core/Extensions/DateTimeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
namespace CSM_Foundation_Core.Core.Extensions;


/// <summary>
/// Extends <see cref="DateTime"/> class.
/// </summary>
public static class DateTimeExtensions {

public static DateTime Trim(this DateTime Current) {
return new DateTime(Current.Year, Current.Month, Current.Day, Current.Hour, Current.Minute, Current.Second);
/// <summary>
/// Trims the given <paramref name="obj"/> to seconds.
/// </summary>
/// <param name="obj">
/// Current object.
/// </param>
/// <returns>
/// Trimmed <see cref="DateTime"/> to seconds.
/// </returns>
public static DateTime Trim(this DateTime obj) {
return new DateTime(obj.Year, obj.Month, obj.Day, obj.Hour, obj.Minute, obj.Second);
}

}
22 changes: 20 additions & 2 deletions CSM Foundation Core/Core/Extensions/EnumerableExtension.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
namespace CSM_Foundation_Core.Core.Extensions;


/// <summary>
/// Extends <see cref="IEnumerable{T}"/> class.
/// </summary>
public static class EnumerableExtension {
public static bool Empty<T>(this IEnumerable<T> List) {
return !List.Any();

/// <summary>
/// Checks if the <paramref name="obj"/> is empty.
/// </summary>
/// <typeparam name="T">
/// Type of the <see cref="IEnumerable{T}"/> content.
/// </typeparam>
/// <param name="obj">
/// Current object.
/// </param>
/// <returns>
/// Whether the collection is empty or not.
/// </returns>
public static bool Empty<T>(this IEnumerable<T> obj) {
return !obj.Any();
}
}
16 changes: 16 additions & 0 deletions CSM Foundation Core/Core/Resources/ResourceType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace CSM_Foundation_Core.Core.Resources;

/// <summary>
/// Resource types enumeration.
/// </summary>
public enum ResourceType {
/// <summary>
/// When the resource has a remote access Link.
/// </summary>
HLINK,

/// <summary>
/// When the resource has local or network access data.
/// </summary>
FILE,
}
31 changes: 31 additions & 0 deletions CSM Foundation Core/Core/Resources/ScalarValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace CSM_Foundation_Core.Core.Resources;

/// <summary>
/// Scalar values enumerator.
/// </summary>
public enum ScalarValue {
/// <summary>
/// Double precision floating point number.
/// </summary>
DOUBLE,

/// <summary>
/// Integer number.
/// </summary>
INT,

/// <summary>
/// String value.
/// </summary>
STRING,

/// <summary>
/// Boolean value.
/// </summary>
BOOL,

/// <summary>
/// Enumeration value.
/// </summary>
ENUM,
}
45 changes: 38 additions & 7 deletions CSM Foundation Core/Core/Utils/FileUtils.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,52 @@
using System.Text.Json;

namespace CSM_Foundation_Core.Core.Utils;


/// <summary>
/// Provide system files utility methods.
/// </summary>
public class FileUtils {
public static string FormatLocation(string Location) {

/// <summary>
/// Formats the given <paramref name="path"/> for system sensitive '/' or '\\' usage.
/// </summary>
/// <param name="path">
/// System file path.
/// </param>
/// <returns>
/// Formatted system file path.
/// </returns>
public static string FormatPath(string path) {
string wd = Directory.GetCurrentDirectory();
if (wd.Contains('/')) {
Location = Location.Replace("\\", "/");
path = path.Replace("\\", "/");
}

return Location;
return path;
}
public static TModel Deserealize<TModel>(string Location) {
if (!File.Exists(Location)) {
throw new FileNotFoundException(Location);

/// <summary>
/// Gets the given <paramref name="path"/> file content as an <typeparamref name="TModel"/> instance.
/// </summary>
/// <typeparam name="TModel">
/// Type of the converted data model.
/// </typeparam>
/// <param name="path">
/// File system path.
/// </param>
/// <returns>
/// Converted file content into a <typeparamref name="TModel"/> instance.
/// </returns>
/// <exception cref="FileNotFoundException">
/// Thrown when the given <paramref name="path"/> does not exist.
/// </exception>
public static TModel Deserealize<TModel>(string path) {
if (!File.Exists(path)) {
throw new FileNotFoundException(path);
}

Stream fs = File.OpenRead(Location);
Stream fs = File.OpenRead(path);
TModel m = JsonSerializer.Deserialize<TModel>(fs)!;
return m;
}
Expand Down
Loading
Loading