Example #1
0
        public void UlidCanConvertFromGuid()
        {
            var guid = _testUlid.ToGuid();

            var converted = _ulidConverter.ConvertFrom(guid);

            Assert.Equal(_testUlid, converted);
        }
Example #2
0
        public void Guid_CanConvertTo_Ulid()
        {
            var g = Guid.NewGuid();
            var u = new Ulid(g);
            var t = new Ulid(Guid.Empty);

            Assert.AreEqual(g, u.ToGuid());
            Assert.AreEqual(Ulid.Empty, t);
            Assert.AreEqual(Guid.Empty, t.ToGuid());
        }
Example #3
0
        public void Guid_CanConvertTo_Ulid()
        {
            var g = Guid.NewGuid();
            var u = new Ulid(g);
            var t = new Ulid(Guid.Empty);

            Assert.AreEqual(g, u.ToGuid());
            Assert.AreEqual(Ulid.Empty, t);
            Assert.AreEqual(Guid.Empty, t.ToGuid());
        }
Example #4
0
        public void GuidComparison()
        {
            var data_smaller = new byte[] { 0, 255, 255, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var data_larger  = new byte[] { 1, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var ulid_smaller = new Ulid(data_smaller);
            var ulid_larger  = new Ulid(data_larger);

            var guid_smaller = ulid_smaller.ToGuid();
            var guid_larger  = ulid_larger.ToGuid();

            ulid_smaller.CompareTo(ulid_larger).Should().BeLessThan(0, "a Ulid comparison should compare byte to byte");
            guid_smaller.CompareTo(guid_larger).Should().BeLessThan(0, "a Ulid to Guid cast should preserve order");
        }
        private async Task DetectLongRunningTaskStatus(ChannelWriter <string> writer, Ulid grainId, int delay, CancellationToken cancellationToken)
        {
            try
            {
                using (var client = OrleansClientBuilder.CreateClient(_logger, _clusterInfo, _providerOption,
                                                                      new[] { typeof(IMyReminder) }))
                {
                    await client.ConnectWithRetryAsync();

                    var grain = client.GetGrain <IMyReminder>(grainId.ToGuid());

                    string status;
                    do
                    {
                        // Check the cancellation token regularly so that the server will stop
                        // producing items if the client disconnects.
                        cancellationToken.ThrowIfCancellationRequested();

                        status = await grain.GetCurrentStatus();

                        await writer.WriteAsync(status, cancellationToken);

                        if (status == "stopped")
                        {
                            break;
                        }

                        await Task.Delay(TimeSpan.FromSeconds(delay), cancellationToken);
                    } while (status == "running");

                    await client.Close();
                }
            }
            catch (Exception ex)
            {
                _logger.Error(400, "Runtime error", ex);
                writer.TryComplete(ex);
                return;
            }

            writer.TryComplete();
        }
Example #6
0
 public async Task JoinGame(Ulid leaderBoardId)
 {
     _leaderBoardGrain       = GrainFactory.GetGrain <ILeaderBoard>(leaderBoardId.ToGuid());
     State.CurrentJoinedGame = leaderBoardId;
     await WriteStateAsync();
 }