Skip to content

Commit

Permalink
Fix Nyris.CodeAnalysis.CSharp.CodeStyle to 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmad2smile committed May 11, 2022
1 parent a1ca461 commit 835935e
Show file tree
Hide file tree
Showing 164 changed files with 4,935 additions and 5,026 deletions.
5 changes: 0 additions & 5 deletions samples/ConsoleApp/ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,4 @@
<PackageReference Include="System.Linq.Async" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../Nyris.Crdt.AspNetExample/Nyris.Crdt.AspNetExample.csproj" />
<ProjectReference Include="../../src/Nyris.Crdt.Distributed/Nyris.Crdt.Distributed.csproj" />
</ItemGroup>

</Project>
19 changes: 9 additions & 10 deletions samples/ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;

namespace ConsoleApp
namespace ConsoleApp;

internal static class Program
{
internal static class Program
private static readonly BufferBlock<int> Block = new(new DataflowBlockOptions { BoundedCapacity = 1 });

public static async Task Main(string[] args)
{
private static readonly BufferBlock<int> Block = new(new DataflowBlockOptions{BoundedCapacity = 1});
var tasks = Enumerable.Range(0, 200).Select(i => Block.SendAsync(i)).ToList();

public static async Task Main(string[] args)
for (var i = 0; i < 10; ++i)
{
var tasks = Enumerable.Range(0, 200).Select(i => Block.SendAsync(i)).ToList();

for (var i = 0; i < 10; ++i)
{
Console.WriteLine(await Block.ReceiveAsync(CancellationToken.None));
}
Console.WriteLine(await Block.ReceiveAsync(CancellationToken.None));
}
}
}
13 changes: 6 additions & 7 deletions samples/Node1/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace Node1
namespace Node1;

internal static class Program
{
internal static class Program
public static void Main(string[] args)
{
public static void Main(string[] args)
{
Nyris.Crdt.AspNetExample.Program.Main(args);
}
Nyris.Crdt.AspNetExample.Program.Main(args);
}
}
}
13 changes: 6 additions & 7 deletions samples/Node2/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace Node2
namespace Node2;

internal static class Program
{
internal static class Program
public static void Main(string[] args)
{
public static void Main(string[] args)
{
Nyris.Crdt.AspNetExample.Program.Main(args);
}
Nyris.Crdt.AspNetExample.Program.Main(args);
}
}
}
159 changes: 79 additions & 80 deletions samples/Nyris.Crdt.AspNetExample/CollectionId.cs
Original file line number Diff line number Diff line change
@@ -1,106 +1,105 @@
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;
using Nyris.Crdt.Distributed.Model.Converters;
using Nyris.Crdt.Model;
using ProtoBuf;
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;

namespace Nyris.Crdt.AspNetExample;

namespace Nyris.Crdt.AspNetExample
/// <summary>
/// Encapsulates Guid
/// </summary>
[JsonConverter(typeof(InternalIdJsonConverter<CollectionId, Factory>))]
[TypeConverter(typeof(InternalIdTypeConverter<CollectionId, Factory>))]
[ProtoContract]
public readonly struct CollectionId : IEquatable<CollectionId>, IFormattable, IComparable<CollectionId>, IAs<Guid>,
IHashable
{
/// <summary>
/// Encapsulates Guid
/// Converts guid into NodeId.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[ProtoConverter]
public static CollectionId FromGuid(Guid id) => new(id);

/// <summary>
/// Generates new random Id.
/// </summary>
/// <returns></returns>
public static CollectionId New() => new(Guid.NewGuid());

/// <summary>
/// Converts the string representation of an NodeId to the equivalent NodeId structure.
/// </summary>
/// <param name="input">input – The string to convert.</param>
/// <returns></returns>
public static CollectionId Parse(string input) => new(Guid.Parse(input));

/// <summary>
/// A read-only instance of the NodeId structure, that can represent default or uninitialized value.
/// </summary>
[JsonConverter(typeof(InternalIdJsonConverter<CollectionId, Factory>))]
[TypeConverter(typeof(InternalIdTypeConverter<CollectionId, Factory>))]
[ProtoContract]
public readonly struct CollectionId : IEquatable<CollectionId>, IFormattable, IComparable<CollectionId>, IAs<Guid>,
IHashable
public static readonly CollectionId Empty = new(Guid.Empty);

/// <summary>
/// Converts the string representation of an NodeId to the equivalent NodeId structure.
/// </summary>
/// <param name="input">A string containing the NodeId to convert</param>
/// <param name="collectionId">An NodeId instance to contain the parsed value. If the method returns true,
/// result contains a valid NodeId. If the method returns false, result equals Empty.</param>
/// <returns>true if the parse operation was successful; otherwise, false.</returns>
public static bool TryParse(string input, [NotNullWhen(true)] out CollectionId collectionId)
{
/// <summary>
/// Converts guid into NodeId.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[ProtoConverter]
public static CollectionId FromGuid(Guid id) => new(id);

/// <summary>
/// Generates new random Id.
/// </summary>
/// <returns></returns>
public static CollectionId New() => new(Guid.NewGuid());

/// <summary>
/// Converts the string representation of an NodeId to the equivalent NodeId structure.
/// </summary>
/// <param name="input">input – The string to convert.</param>
/// <returns></returns>
public static CollectionId Parse(string input) => new(Guid.Parse(input));

/// <summary>
/// A read-only instance of the NodeId structure, that can represent default or uninitialized value.
/// </summary>
public static readonly CollectionId Empty = new(Guid.Empty);

/// <summary>
/// Converts the string representation of an NodeId to the equivalent NodeId structure.
/// </summary>
/// <param name="input">A string containing the NodeId to convert</param>
/// <param name="collectionId">An NodeId instance to contain the parsed value. If the method returns true,
/// result contains a valid NodeId. If the method returns false, result equals Empty.</param>
/// <returns>true if the parse operation was successful; otherwise, false.</returns>
public static bool TryParse(string input, [NotNullWhen(true)] out CollectionId collectionId)
if (Guid.TryParse(input, out var guid))
{
if (Guid.TryParse(input, out var guid))
{
collectionId = FromGuid(guid);
return true;
}

collectionId = Empty;
return false;
collectionId = FromGuid(guid);
return true;
}

[ProtoMember(1)] private readonly Guid _id;
collectionId = Empty;
return false;
}

private CollectionId(Guid id)
{
_id = id;
}
[ProtoMember(1)] private readonly Guid _id;

/// <inheritdoc />
public Guid Value => _id;
private CollectionId(Guid id)
{
_id = id;
}

/// <inheritdoc />
public bool Equals(CollectionId other) => _id.Equals(other._id);
/// <inheritdoc />
public Guid Value => _id;

/// <inheritdoc />
public override bool Equals(object? obj) => obj is CollectionId other && Equals(other);
/// <inheritdoc />
public bool Equals(CollectionId other) => _id.Equals(other._id);

/// <inheritdoc />
public override int GetHashCode() => _id.GetHashCode();
/// <inheritdoc />
public override bool Equals(object? obj) => obj is CollectionId other && Equals(other);

/// <inheritdoc />
public string ToString(string? format, IFormatProvider? formatProvider) => _id.ToString(format, formatProvider);
/// <inheritdoc />
public override int GetHashCode() => _id.GetHashCode();

/// <inheritdoc />
public override string ToString() => _id.ToString("N");
/// <inheritdoc />
public string ToString(string? format, IFormatProvider? formatProvider) => _id.ToString(format, formatProvider);

/// <inheritdoc />
public ReadOnlySpan<byte> CalculateHash() => _id.ToByteArray();
/// <inheritdoc />
public override string ToString() => _id.ToString("N");

/// <inheritdoc />
public int CompareTo(CollectionId other) => _id.CompareTo(other._id);
/// <inheritdoc />
public ReadOnlySpan<byte> CalculateHash() => _id.ToByteArray();

public static bool operator ==(CollectionId left, CollectionId right) => left.Equals(right);
/// <inheritdoc />
public int CompareTo(CollectionId other) => _id.CompareTo(other._id);

public static bool operator !=(CollectionId left, CollectionId right) => !(left == right);
public static bool operator ==(CollectionId left, CollectionId right) => left.Equals(right);

private class Factory : IFactory<CollectionId>
{
CollectionId IFactory<CollectionId>.Empty => Empty;
CollectionId IFactory<CollectionId>.Parse(string value) => CollectionId.Parse(value);
}
public static bool operator !=(CollectionId left, CollectionId right) => !(left == right);

private class Factory : IFactory<CollectionId>
{
CollectionId IFactory<CollectionId>.Empty => Empty;
CollectionId IFactory<CollectionId>.Parse(string value) => CollectionId.Parse(value);
}
}
29 changes: 14 additions & 15 deletions samples/Nyris.Crdt.AspNetExample/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
using Microsoft.AspNetCore.Mvc;
using Nyris.Crdt.Distributed.Model;

namespace Nyris.Crdt.AspNetExample.Controllers
namespace Nyris.Crdt.AspNetExample.Controllers;

[ApiController]
[Route("/")]
public class HomeController : ControllerBase
{
[ApiController]
[Route("/")]
public class HomeController: ControllerBase
{
private readonly NodeId _thisNodeId;
private readonly NodeId _thisNodeId;

public HomeController(NodeInfo nodeInfo)
{
_thisNodeId = nodeInfo.Id;
}
public HomeController(NodeInfo nodeInfo)
{
_thisNodeId = nodeInfo.Id;
}

[HttpGet]
public IActionResult Index()
{
return Ok(_thisNodeId);
}
[HttpGet]
public IActionResult Index()
{
return Ok(_thisNodeId);
}
}
Loading

0 comments on commit 835935e

Please sign in to comment.