Skip to content

Commit 3c139d5

Browse files
committed
[ECO-4567] Added cake script to format the code
- Formatted Main solution with all relevant C# files - Fixed import issues in MsgPack serializer/deserializers
1 parent 14423cd commit 3c139d5

33 files changed

+232
-166
lines changed

.editorconfig

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ root = true
88
indent_style = space
99
indent_size = 4
1010
trim_trailing_whitespace = true
11-
insert_final_newline = false
11+
insert_final_newline = true
1212

1313
# SA1200: Using directives should be placed correctly
1414
dotnet_diagnostic.SA1200.severity = none
1515

16+
[*.cake]
17+
indent_style = space
18+
indent_size = 4
19+
trim_trailing_whitespace = true
20+
insert_final_newline = true
21+
1622
[*.{xaml,xml,config,manifest}]
1723
indent_style = space
1824
indent_size = 2
1925
trim_trailing_whitespace = true
20-
insert_final_newline = false
26+
insert_final_newline = false

IMPLEMENTATION_PLAN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public AblyRequest(string path, HttpMethod method, Protocol protocol = Defaults.
185185

186186
**Fix required:**
187187
```csharp
188-
public AblyRequest(string path, HttpMethod method, Protocol protocol = Defaults.DefaultProtocol)
188+
public AblyRequest(string path, HttpMethod method, Protocol protocol = Defaults.Protocol)
189189
```
190190

191191
#### 3.2 Update AblyHttpClient.cs

cake-build/tasks/build.cake

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,29 @@ Task("Build.Xamarin")
190190
Task("Update.AblyUnity")
191191
.Description("Update Ably DLLs inside unity project")
192192
.IsDependentOn("_Build_Ably_Unity_Dll");
193+
194+
// Public task: Format code using dotnet-format
195+
Task("Format.Code")
196+
.Description("Format code using dotnet-format")
197+
.Does(() =>
198+
{
199+
Information("Formatting code with dotnet-format...");
200+
201+
// Using 'whitespace' mode for fast formatting without building the project
202+
// This applies .editorconfig rules for whitespace, indentation, etc. without semantic analysis
203+
// Much faster than default mode which requires compilation
204+
var exitCode = StartProcess("dotnet", new ProcessSettings
205+
{
206+
Arguments = $"format {paths.MainSolution.FullPath} whitespace --no-restore"
207+
});
208+
209+
if (exitCode == 0)
210+
{
211+
Information("✓ Code formatted successfully");
212+
}
213+
else
214+
{
215+
throw new Exception($"dotnet format failed with exit code {exitCode}");
216+
}
217+
});
218+

examples/AndroidSample/AblyService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ public void Init()
1818
_ably = new AblyRealtime(new ClientOptions("lNj80Q.iGyVcQ:2QKX7FFASfX-7H9H")
1919
{
2020
LogHandler = this,
21-
LogLevel = LogLevel.Debug,
21+
LogLevel = LogLevel.Debug,
2222
AutoConnect = false,
2323
UseBinaryProtocol = false
2424
});
2525
_ably.Connection.On(change =>
2626
{
27-
if(change.Current == ConnectionState.Connected)
28-
foreach(var channel in _ably.Channels)
27+
if (change.Current == ConnectionState.Connected)
28+
foreach (var channel in _ably.Channels)
2929
channel.Attach();
3030

3131
_connectionSubject.OnNext(change.Current.ToString());
@@ -48,7 +48,7 @@ public IObservable<Message> SubsrcibeToChannel(string channelName)
4848
_ably.Channels.Get(channelName).Subscribe(subject.OnNext);
4949
return subject;
5050
}
51-
51+
5252
public void LogEvent(LogLevel level, string message)
5353
{
5454
Android.Util.Log.Debug("ably", $"[{level}] {message}");
@@ -66,6 +66,6 @@ public IDisposable Subscribe(IObserver<string> observer)
6666
}
6767
}
6868

69-
69+
7070

7171
}

examples/AndroidSample/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public App(AblyService ably)
3434

3535
protected override void OnStart()
3636
{
37-
37+
3838
// Handle when your app starts
3939
}
4040

format-code.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dotnet cake cake-build/build.cake -- --target=Format.Code

format-code.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dotnet cake cake-build/build.cake -- --target=Format.Code

src/IO.Ably.Shared.MsgPack/CustomSerialisers/GeneratedSerializers/IO_Ably_Types_ProtocolMessageSerializer.cs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ protected override void PackToCore(MsgPack.Packer packer, IO.Ably.Types.Protocol
8686
objectTree.ChannelSerial.IsNotEmpty(),
8787
objectTree.ConnectionDetails != null,
8888
objectTree.ConnectionId.IsNotEmpty(),
89-
objectTree.ConnectionSerial != null,
9089
objectTree.Count != null,
9190
objectTree.Error != null,
9291
objectTree.Flags != null,
@@ -119,11 +118,6 @@ protected override void PackToCore(MsgPack.Packer packer, IO.Ably.Types.Protocol
119118
this._serializer0.PackTo(packer, "connectionId");
120119
this._serializer0.PackTo(packer, objectTree.ConnectionId);
121120
}
122-
if (objectTree.ConnectionSerial != null)
123-
{
124-
this._serializer0.PackTo(packer, "connectionSerial");
125-
this._serializer3.PackTo(packer, objectTree.ConnectionSerial);
126-
}
127121
if (objectTree.Count != null)
128122
{
129123
this._serializer0.PackTo(packer, "count");
@@ -409,15 +403,9 @@ protected override IO.Ably.Types.ProtocolMessage UnpackFromCore(MsgPack.Unpacker
409403
{
410404
if ((key == "connectionSerial"))
411405
{
412-
System.Nullable<long> nullable21 = default(System.Nullable<long>);
413-
nullable21 =
414-
MsgPack.Serialization.UnpackHelpers.UnpackNullableInt64Value(
415-
unpacker, typeof(IO.Ably.Types.ProtocolMessage),
416-
"System.Nullable`1[System.Int64] connectionSerial");
417-
if (nullable21.HasValue)
418-
{
419-
result.ConnectionSerial = nullable21;
420-
}
406+
// ConnectionSerial was removed in PR #1199
407+
// Skip this field if present in older messages
408+
unpacker.Skip();
421409
}
422410
else
423411
{
@@ -569,7 +557,6 @@ protected override IO.Ably.Types.ProtocolMessage UnpackFromCore(MsgPack.Unpacker
569557
}
570558
}
571559
}
572-
573560
}
574561
}
575562
}
@@ -595,4 +582,4 @@ private static T @__Conditional<T>(bool condition, T whenTrue, T whenFalse)
595582
}
596583
}
597584
#pragma warning restore SA1600 // Elements should be documented
598-
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
585+
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member

src/IO.Ably.Shared/AblyAuth.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ private static TokenRequest GetTokenRequest(object callbackResult)
483483
private async Task<AblyResponse> CallAuthUrl(AuthOptions mergedOptions, TokenParams @params)
484484
{
485485
var url = mergedOptions.AuthUrl;
486-
var protocol = Options.UseBinaryProtocol == false ? Protocol.Json : Protocol.MsgPack;
486+
var protocol = Options.UseBinaryProtocol ? Protocol.MsgPack : Defaults.Protocol;
487487
var authRequest = new AblyRequest(url.ToString(), mergedOptions.AuthMethod, protocol);
488488

489489
if (mergedOptions.AuthMethod == HttpMethod.Get)

src/IO.Ably.Shared/AblyRest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public LocalDevice Device
115115
internal set => _device = value; // The setting is only for testing purposes
116116
}
117117

118-
internal Protocol Protocol => Options.UseBinaryProtocol == false ? Protocol.Json : Defaults.Protocol;
118+
internal Protocol Protocol => Options.UseBinaryProtocol ? Protocol.MsgPack : Defaults.Protocol;
119119

120120
internal ClientOptions Options { get; }
121121

0 commit comments

Comments
 (0)