Ejemplo n.º 1
0
        private void OnRequestIntroducerRegistrationMessageReceived(UnconnectedMessageEventArgs <RequestIntroducerRegistrationMessage> e)
        {
            string novaId = String.Empty;

            do
            {
                novaId = AlphaNumericGenerator.Generate(3, GeneratorOptions.AlphaNumeric);
            } while (MachineLookupTable.IdExists(novaId));

            e.Message.Machine.NovaId         = novaId;
            e.Message.Machine.PublicEndPoint = e.From; // For introduction, one method below
            MachineLookupTable.Add(novaId, new LookupMachine(e.Message.Machine));

            NumMachinesRegistered++;

            if (OnMachineRegistered != null)
            {
                OnMachineRegistered(this, new MachineRegisteredEventArgs {
                    Machine = e.Message.Machine
                });
            }

            Network.SendUnconnectedMessage(new ResponseIntroducerRegistrationSucceededMessage {
                Machine = e.Message.Machine
            }, e.From);
        }
Ejemplo n.º 2
0
        public Task <PasswordGeneratedEventArgs> GeneratePasswordAsTask()
        {
            Trace.WriteLine("Ran");
            var tcs = RegisterAsTask <PasswordGeneratedEventArgs>(ref OnNewPasswordGenerated);

            var childTask = Task <PasswordGeneratedEventArgs> .Factory.StartNew(() =>
            {
                Provider.ServerMachine.Identity     = MachineIdentity.GetCurrentIdentity();
                Provider.ServerMachine.Password     = AlphaNumericGenerator.Generate(2, GeneratorOptions.Numeric);
                Provider.ServerMachine.PasswordHash = HashUtil.ComputeHash(Provider.ServerMachine.Password, HashType.SHA512);

                var newPasswordEventArgs = new PasswordGeneratedEventArgs {
                    NewPassword = Provider.ServerMachine.Password
                };

                if (OnNewPasswordGenerated != null)
                {
                    OnNewPasswordGenerated(this, newPasswordEventArgs);
                }

                return(newPasswordEventArgs);
            }, TaskCreationOptions.AttachedToParent);

            return(tcs.Task);
        }
Ejemplo n.º 3
0
 public void AlphaNumericGenerator()
 {
     IGenerator<string> alphaNumericGen = new AlphaNumericGenerator(10);
     var alphaNumeric = alphaNumericGen.Generate();
     Assert.IsNotNull(alphaNumeric);
     Assert.AreEqual(10, alphaNumeric.Length);
 }
Ejemplo n.º 4
0
        public void AlphaNumericGenerator()
        {
            IGenerator <string> alphaNumericGen = new AlphaNumericGenerator(10);
            var alphaNumeric = alphaNumericGen.Generate();

            Assert.IsNotNull(alphaNumeric);
            Assert.AreEqual(10, alphaNumeric.Length);
        }