public void Print(IntelligentEntity intelligentEntity, EnvironmentEntity environmentEntity)
 {
     foreach (var simulator in _simulators)
     {
         simulator.Print(intelligentEntity, environmentEntity);
     }
 }
Exemple #2
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Name,Url,Id,CreatedOn,CreatedBy,LastModifiedOn,LastModifiedBy")] EnvironmentEntity environmentEntity)
        {
            if (id != environmentEntity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(environmentEntity);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EnvironmentEntityExists(environmentEntity.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(environmentEntity));
        }
 public SceneLogic(IEventFormat eventFormat = null, IObservable <IIterationData> parent = null) : base(eventFormat, parent)
 {
     EventManager.AddListener(this, controllerSpawn, this.eventFormat, this.eventFormat.EventTypeBirth, typeof(SceneController));
     _environment          = new EnvironmentEntity();
     _environment.parent   = this;
     _environment.position = Vector3.zero;
 }
        /// <summary>
        /// Gets list of mailboxes from the on permise environment.
        /// </summary>
        /// <param name="entity">An instance of <see cref="EnvironmentEntity"/> that represents the on permise environment.</param>
        /// <returns>A list of mailboxes from the on permise environment.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="entity"/> is null.
        /// </exception>
        public async Task <List <MailboxEntity> > GetMailboxesAsync(EnvironmentEntity entity)
        {
            Command command;
            CommandParameterCollection parameters;
            Collection <PSObject>      results;
            List <MailboxEntity>       mailboxes;
            PSCredential        credential;
            WSManConnectionInfo connectionInfo;
            string password;

            entity.AssertNotNull(nameof(entity));

            try
            {
                password = await service.Vault.GetAsync(entity.Password);

                credential = new PSCredential(entity.Username, password.ToSecureString());

                connectionInfo = GetConnectionInfo(new Uri(entity.Endpoint), MigrationConstants.SchemaUri, credential);

                command = new Command("Get-Mailbox");

                parameters = new CommandParameterCollection
                {
                    { "ResultSize", "Unlimited" }
                };

                using (Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo))
                {
                    results = scriptManager.InvokeCommand(runspace, command, parameters);
                }

                mailboxes = results.Select(m => new MailboxEntity
                {
                    DisplayName        = m.Properties["DisplayName"].Value.ToString(),
                    ETag               = "*",
                    Name               = m.Properties["Name"].Value.ToString(),
                    PartitionKey       = entity.RowKey,
                    PrimarySmtpAddress = m.Properties["PrimarySmtpAddress"].Value.ToString(),
                    RowKey             = m.Properties["Guid"].Value.ToString(),
                    SamAccountName     = m.Properties["SamAccountName"].Value.ToString(),
                    UserPrincipalName  = m.Properties["UserPrincipalName"].Value.ToString()
                }).ToList();

                return(mailboxes);
            }
            finally
            {
                command        = null;
                connectionInfo = null;
                credential     = null;
                parameters     = null;
                results        = null;
            }
        }
Exemple #5
0
        public async Task <IActionResult> Create([Bind("Name,Url,Id,CreatedOn,CreatedBy,LastModifiedOn,LastModifiedBy")] EnvironmentEntity environmentEntity)
        {
            if (ModelState.IsValid)
            {
                environmentEntity.Id = Guid.NewGuid();
                _context.Add(environmentEntity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(environmentEntity));
        }
        /// <summary>
        /// Creates a new migration endpoint in Exchange Online.
        /// </summary>
        /// <param name="entity">An instance of <see cref="EnvironmentEntity"/> that represents the new migration endpoint.</param>
        /// <returns>An instance of <see cref="Task"/> that represents the asynchronous operation.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="entity"/> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="entity"/> is null.
        /// </exception>
        public async Task CreateMigrationEndpointAsync(EnvironmentEntity entity)
        {
            Command command;
            CommandParameterCollection parameters;
            PSCredential        credential;
            PSCredential        onPermiseCredential;
            Uri                 connectionUri;
            WSManConnectionInfo connectionInfo;
            string              onPermisePassword;

            entity.AssertNotNull(nameof(entity));

            try
            {
                credential = new PSCredential(
                    service.Configuration.ExchangeOnlineUsername,
                    service.Configuration.ExchangeOnlinePassword.ToSecureString());

                onPermisePassword = await service.Vault.GetAsync(entity.Password);

                onPermiseCredential = new PSCredential(entity.Username, onPermisePassword.ToSecureString());

                connectionUri  = new Uri($"{MigrationConstants.ExchangeOnlineEndpoint}{entity.Organization}");
                connectionInfo = GetConnectionInfo(connectionUri, MigrationConstants.SchemaUri, credential);

                command = new Command("New-MigrationEndpoint");

                parameters = new CommandParameterCollection
                {
                    { "Autodiscover" },
                    { "Credentials", onPermiseCredential },
                    { "EmailAddress", entity.Username },
                    { "ExchangeRemoteMove" },
                    { "Name", entity.Name }
                };

                using (Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo))
                {
                    scriptManager.InvokeCommand(runspace, command, parameters);
                }
            }
            finally
            {
                command             = null;
                connectionInfo      = null;
                connectionUri       = null;
                credential          = null;
                onPermiseCredential = null;
                parameters          = null;
            }
        }
Exemple #7
0
 public void Print(IntelligentEntity intelligentEntity, EnvironmentEntity environmentEntity)
 {
     File.AppendAllText(_filename,
                        (_time++) +
                        "," +
                        //(intelligentEntity.Input.Object ?? "0") +
                        //"," +
                        (intelligentEntity.Output.Object == null ? "0" : ((bool)(intelligentEntity.Output.Object) ? "1" : "0")) +
                        "," +
                        //intelligentEntity.Input.Contentment.Value +
                        //","+
                        intelligentEntity.Contentment.Value +
                        "\n");
 }
        public Intelligence Run(
            ISimulatorPrinter printer,
            IntelligentEntity intelligentEntity,
            EnvironmentEntity environmentEntity)
        {
            for (var t = 0; t < _timeSteps; t++)
            {
                var output = intelligentEntity.Output;
                var input  = environmentEntity.Input;

                intelligentEntity.Step(input);
                environmentEntity.Step(output);
                printer.Print(intelligentEntity, environmentEntity);
            }

            printer.PrintIntelligence(intelligentEntity);

            return(intelligentEntity.Contentment.Value);
        }
Exemple #9
0
        public async Task <EnvironmentViewModel> CreateAsync([FromBody] EnvironmentViewModel environmentViewModel)
        {
            CustomerPrincipal           principal;
            DateTime                    startTime;
            Dictionary <string, double> eventMetrics;
            Dictionary <string, string> eventProperties;
            EnvironmentEntity           entity;
            string password;

            environmentViewModel.AssertNotNull(nameof(environmentViewModel));

            try
            {
                startTime = DateTime.Now;
                principal = (CustomerPrincipal)HttpContext.Current.User;

                if (string.IsNullOrEmpty(environmentViewModel.Id))
                {
                    environmentViewModel.Id = Guid.NewGuid().ToString();
                }

                password = Guid.NewGuid().ToString();
                await Service.Vault.StoreAsync(password, environmentViewModel.Password);

                entity = new EnvironmentEntity(principal.CustomerId, environmentViewModel.Id)
                {
                    Endpoint     = environmentViewModel.Endpoint,
                    ETag         = "*",
                    Name         = environmentViewModel.Name,
                    Organization = principal.Organization,
                    Password     = password,
                    Username     = environmentViewModel.Username
                };

                await Service.Storage.WriteToTableAsync(MigrationConstants.EnvironmentTableName, entity);

                await Service.ServiceBus.WriteToQueueAsync(MigrationConstants.EnvironmentQueueName, entity);

                // Capture the request for the customer summary for analysis.
                eventProperties = new Dictionary <string, string>
                {
                    { "Email", principal.Email },
                    { "EnvironmentId", environmentViewModel.Id },
                    { "EnvironmentName", environmentViewModel.Name },
                    { "PrincipalCustomerId", principal.CustomerId }
                };

                // Track the event measurements for analysis.
                eventMetrics = new Dictionary <string, double>
                {
                    { "ElapsedMilliseconds", DateTime.Now.Subtract(startTime).TotalMilliseconds }
                };

                Service.Telemetry.TrackEvent("/api/environment/create", eventProperties, eventMetrics);

                return(environmentViewModel);
            }
            finally
            {
                entity          = null;
                eventMetrics    = null;
                eventProperties = null;
                principal       = null;
            }
        }
 public void Print(IntelligentEntity intelligentEntity, EnvironmentEntity environmentEntity)
 {
     Console.Write(environmentEntity.Input.Object + ": ");
     Console.WriteLine(intelligentEntity + ", " + intelligentEntity.Contentment);
 }