Exemplo n.º 1
0
    static TransportMessage TranslateToSqlTransportMessage(TransportMessage msmqMessage)
    {
        var headers = msmqMessage.Headers;
        var msmqId  = headers["NServiceBus.MessageId"];
        var sqlId   = msmqId;

        // Set the Id to a deterministic guid, as Sql message Ids are Guids and
        // Msmq message ids are guid\nnnn. Newer versions of NServiceBus already
        // return just a guid for the messageId. So, check to see if the Id is
        // a valid Guid and if not, only then create a valid Guid. This check
        // is important as it affects the retries if the message is rolled back.
        // If the Ids are different, then the recoverability won't know its the same message.
        Guid msmqGuid;

        if (!Guid.TryParse(msmqId, out msmqGuid))
        {
            sqlId = GuidBuilder.BuildDeterministicGuid(msmqId).ToString();
            headers["NServiceBus.MessageId"] = sqlId;
        }

        return(new TransportMessage(sqlId, headers)
        {
            Body = msmqMessage.Body,
            // MSMQ and SQL Server transports signal lack of TimeToBeReceived differently.
            // MSMQ uses Message.InfiniteTimeout value to indicate that a message should
            // never be discarded. SQL Server transport expects TimeSpan.MaxValue to
            // indicate the same behaviour. This would normally be handled by NServiceBus
            // pipeline when transforming a transport message into a logical message.
            // This sample skips the pipeline and deals with transport messages directly,
            // thus making this translation required.
            TimeToBeReceived = (msmqMessage.TimeToBeReceived < Message.InfiniteTimeout) ? msmqMessage.TimeToBeReceived : TimeSpan.MaxValue
        });
    }
Exemplo n.º 2
0
    // Will get invoked, whenever a new event is published by the Msmq publishers
    // and when they notify the bridge. The bridge is a MSMQ and the publishers
    // have an entry for this queue in their subscription storage.
    public bool Handle(TransportMessage message)
    {
        var headers = message.Headers;

        Type[] eventTypes =
        {
            Type.GetType(headers["NServiceBus.EnclosedMessageTypes"])
        };

        var msmqId = headers["NServiceBus.MessageId"];

        // Set the Id to a deterministic guid, as Sql message Ids are Guids and
        // Msmq message ids are guid\nnnn. Newer versions of NServiceBus already
        // return just a guid for the messageId. So, check to see if the Id is
        // a valid Guid and if not, only then create a valid Guid. This check
        // is important as it affects the retries if the message is rolled back.
        // If the Ids are different, then the recoverability won't know its the same message.
        Guid newGuid;

        if (!Guid.TryParse(msmqId, out newGuid))
        {
            headers["NServiceBus.MessageId"] = GuidBuilder.BuildDeterministicGuid(msmqId).ToString();
        }
        log.Info("Forwarding message to all the SQL subscribers via a Publish");
        publisher.Publish(message, new PublishOptions(eventTypes.First()));
        return(true);
    }
Exemplo n.º 3
0
 public void Documentation_Wiki_ForNumbers()
 {
     Assert.That(GuidBuilder.Build(1), Is.EqualTo(new Guid("11111111-1111-1111-1111-111111111111")));
     Assert.That(GuidBuilder.Build(11), Is.EqualTo(new Guid("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb")));
     Assert.That(GuidBuilder.Build(0x3), Is.EqualTo(new Guid("33333333-3333-3333-3333-333333333333")));
     Assert.That(GuidBuilder.Build(0xd), Is.EqualTo(new Guid("dddddddd-dddd-dddd-dddd-dddddddddddd")));
 }
Exemplo n.º 4
0
        public void Encode_Guid_CompactGuidRepresentation()
        {
            string compact     = CompactGuid.Encode(GuidBuilder.Build(1));
            string compactOnes = "EREREREREREREREREREREQ";

            Assert.That(compact, Is.EqualTo(compactOnes));
        }
Exemplo n.º 5
0
        public void Ctor_FromGuid_ShorterGuidRepresentation()
        {
            Guid ones    = GuidBuilder.Build(1);
            var  subject = new CompactGuid(ones);

            Assert.That(subject.Guid, Is.EqualTo(ones));
            Assert.That(subject.Value, Has.Length.LessThan(shortestRepresentation(ones).Length));
        }
Exemplo n.º 6
0
        public void Ctor_FromValue_ReconstructsGuid()
        {
            var compact = "EREREREREREREREREREREQ";
            var subject = new CompactGuid(compact);

            Assert.That(subject.Guid, Is.EqualTo(GuidBuilder.Build(1)));
            Assert.That(subject.Value, Is.EqualTo(compact));
        }
Exemplo n.º 7
0
        public void Encode_String_CompactsGuidRepresentation()
        {
            string representation = shortestRepresentation(GuidBuilder.Build(1));

            string compact     = CompactGuid.Encode(representation);
            string compactOnes = "EREREREREREREREREREREQ";

            Assert.That(compact, Is.EqualTo(compactOnes));
        }
Exemplo n.º 8
0
        public void Inequality_FalseIfDifferentGuid()
        {
            CompactGuid one = new CompactGuid(GuidBuilder.Build(1)),
                        two = new CompactGuid(GuidBuilder.Build(2));

            Assert.That(one.Equals(two), Is.False);
            Assert.That(two == one, Is.False);
            Assert.That(one != two, Is.True);
        }
Exemplo n.º 9
0
        public void Equality_TrueIfSameGuid()
        {
            CompactGuid one        = new CompactGuid(GuidBuilder.Build(1)),
                        anotherOne = new CompactGuid(GuidBuilder.Build(1));

            Assert.That(one.Equals(anotherOne), Is.True);
            Assert.That(anotherOne == one, Is.True);
            Assert.That(one != anotherOne, Is.False);
        }
Exemplo n.º 10
0
        public async Task <CallBackUrl> Register(string email, string password)
        {
            if (!Validate.EmailValidation(email))
            {
                throw new ValidationException("Invalid inputs");
            }

            if (!Validate.PasswordValidation(password))
            {
                throw new ValidationException("Invalid inputs");
            }

            ApplicationUser user = new ApplicationUser {
                UserName = email, Email = email
            };
            IdentityResult result = await _userManager.CreateAsync(user, password);

            if (result.Succeeded)
            {
                try
                {
                    _accountsRepository.AddAccount(GuidBuilder.Create().ToString(), user.Id);
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    string code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    string callbackUrl = Url.Action("ConfirmEmail", "Profile", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    await _emailSender.SendEmailAsync(email, "Please confirm your email address",
                                                      $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a> or by entering this code in the app: " + code);

                    return(new CallBackUrl()
                    {
                        Url = callbackUrl
                    });
                }
                catch (Exception ex)
                {
                    await _userManager.DeleteAsync(user);

                    throw new ValidationException("Could not create user:"******"Could not create user");
            }
        }
Exemplo n.º 11
0
        public void Roundtrip_IsPossible()
        {
            Guid oneKey = GuidBuilder.Build(1), twoKey = GuidBuilder.Build(2);

            using (var ctx = new TestDbContext(_dbFile))
            {
                ctx
                .Add(id: oneKey, number: 1, text: "uno", monetaryQuantity: 11.1m.Dkk())
                .Add(id: twoKey, number: 2, text: "dos", monetaryQuantity: 22.222m.Eur());

                ctx.SaveChanges();
            }

            using (var ctx = new TestDbContext(_dbFile))
            {
                TestEntity one = ctx.Entities.SingleOrDefault(e => e.Id == oneKey);

                Assert.That(one, Is.Not.Null);
                Assert.That(one, Must.Match.Expected(new
                {
                    Number   = 1,
                    Quantity = new
                    {
                        Amount   = 11.1m,
                        Currency = CurrencyIsoCode.DKK.AlphabeticCode()
                    }
                }));

                TestEntity two = ctx.Entities.SingleOrDefault(e => e.Id == twoKey);

                Assert.That(two, Is.Not.Null);
                Assert.That(two, Must.Match.Expected(new
                {
                    Number   = 2,
                    Quantity = new
                    {
                        Amount   = 22.222m,
                        Currency = CurrencyIsoCode.EUR.AlphabeticCode()
                    }
                }));
            }
        }
Exemplo n.º 12
0
        public void Explore()
        {
            var subject = new CompactGuid(Guid.Empty);

            subject = new CompactGuid("EREREREREREREREREREREQ");

            Guid ones = GuidBuilder.Build(1);

            subject = new CompactGuid(ones);
            Assert.That(subject.Value, Is.EqualTo("EREREREREREREREREREREQ"));

            subject = new CompactGuid(ones);
            Assert.That(subject.Value, Is.EqualTo("EREREREREREREREREREREQ"));

            subject = new CompactGuid("EREREREREREREREREREREQ");
            Assert.That(subject.Guid, Is.EqualTo(ones));

            string representation = CompactGuid.Encode(ones);

            Assert.That(representation, Is.EqualTo("EREREREREREREREREREREQ"));
            Assert.That(CompactGuid.Decode(representation), Is.EqualTo(ones));
        }
Exemplo n.º 13
0
 public void Build_Number_GuidCreated(int number, string guid)
 {
     // weird casting as NUnit cannot direcly convert the int literal into a byte
     Assert.That(GuidBuilder.Build((byte)number), Is.EqualTo(new Guid(guid)));
 }
Exemplo n.º 14
0
 public void Build_NotACharFigure_Exception()
 {
     Assert.That(() => GuidBuilder.Build('q'), throwsNotHexException('q', "q"));
 }
Exemplo n.º 15
0
 public void Build_CharLetter_GuidCreatedRegardlessOfCase(char lowerCaseFigure, string guid)
 {
     Assert.That(GuidBuilder.Build(lowerCaseFigure), Is.EqualTo(new Guid(guid)));
     Assert.That(GuidBuilder.Build(char.ToUpperInvariant(lowerCaseFigure)), Is.EqualTo(new Guid(guid)));
 }
Exemplo n.º 16
0
 public void Build_CharNumber_GuidCreated(char number, string guid)
 {
     Assert.That(GuidBuilder.Build(number), Is.EqualTo(new Guid(guid)));
 }
Exemplo n.º 17
0
        public void Decode_CompactRepresentation_Guid()
        {
            string compactOnes = "EREREREREREREREREREREQ";

            Assert.That(CompactGuid.Decode(compactOnes), Is.EqualTo(GuidBuilder.Build(1)));
        }
Exemplo n.º 18
0
 public void Build_Letter_GuidCreated(int lowerCaseFigure, string guid)
 {
     // weird casting as NUnit cannot direcly convert the int literal into a byte
     Assert.That(GuidBuilder.Build((byte)lowerCaseFigure), Is.EqualTo(new Guid(guid)));
 }
Exemplo n.º 19
0
 public void Build_OutOfBoundsANumber_Exception()
 {
     Assert.That(() => GuidBuilder.Build(16), throwsNotHexException(16, "16"));
 }
Exemplo n.º 20
0
 public void Documentation_Wiki_ForCharacters()
 {
     Assert.That(GuidBuilder.Build('7'), Is.EqualTo(new Guid("77777777-7777-7777-7777-777777777777")));
     Assert.That(GuidBuilder.Build('a'), Is.EqualTo(new Guid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")));
     Assert.That(GuidBuilder.Build('B'), Is.EqualTo(new Guid("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb")));
 }
Exemplo n.º 21
0
 public static string String()
 {
     return(GuidBuilder.Build());
 }
Exemplo n.º 22
0
 private string PresentBarcode(string accountToPresent)
 {
     if (tr != null)
     {
         barcodeValue = BuildQRCodeValue(tr.GetAmountAuthorized_9F02(), accountToPresent, GuidBuilder.Create());
         if (!String.IsNullOrEmpty(barcodeValue))
         {
             zxingBIV.BarcodeOptions.Hints.Clear();
             zxingBIV.BarcodeOptions.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");
             zxingBIV.BarcodeValue          = barcodeValue;
             zxingBIV.BarcodeOptions.Width  = 600;
             zxingBIV.BarcodeOptions.Height = 600;
         }
     }
     return(barcodeValue);
 }