public static async Task <Guid?> CreateCasterWorkspaceAsync(CasterApiClient casterApiClient, EventEntity eventEntity, Guid directoryId, string varsFileContent, bool useDynamicHost, CancellationToken ct)
        {
            try
            {
                // remove special characters from the user name, use lower case and replace spaces with underscores
                var userName = Regex.Replace(eventEntity.Username.ToLower().Replace(" ", "_"), "[@&'(\\s)<>#]", "", RegexOptions.None);
                // create the new workspace
                var workspaceCommand = new CreateWorkspaceCommand()
                {
                    Name        = $"{userName}-{eventEntity.UserId.ToString()}",
                    DirectoryId = directoryId,
                    DynamicHost = useDynamicHost
                };
                var workspaceId = (await casterApiClient.CreateWorkspaceAsync(workspaceCommand, ct)).Id;
                // create the workspace variable file
                var createFileCommand = new CreateFileCommand()
                {
                    Name        = $"{workspaceCommand.Name}.auto.tfvars",
                    DirectoryId = directoryId,
                    WorkspaceId = workspaceId,
                    Content     = varsFileContent
                };
                await casterApiClient.CreateFileAsync(createFileCommand, ct);

                return(workspaceId);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
 public NewWorkspaceInvestigationWizardVm(IDirectoryInfoFactory directoryInfoManager, IWindsorContainer applicationWindsorContainer, Workspace model,
                                          InvestigationInfo investigationInfo, IInvestigationFactory investigationFactory, IDetectiveMessenger detectiveMessenger,
                                          CreateWorkspaceCommand createWorkspaceCommand, CreateInvestigationCommand createInvestigationCommand) : this(directoryInfoManager,
                                                                                                                                                       applicationWindsorContainer, investigationInfo, investigationFactory, detectiveMessenger, createWorkspaceCommand, createInvestigationCommand)
 {
     // workaround: in some cases this constructor is executed even though it should not be
     if (!string.IsNullOrEmpty(model.Name))
     {
         this.Workspace                  = model;
         this.InvestigationName          = "Initial investigation";
         this.WorkspaceName              = model.Name;
         this.SqlConnectionStringBuilder = new SqlConnectionStringBuilder(model.ConnectionString);
     }
 }
        public NewWorkspaceInvestigationWizardVm(IDirectoryInfoFactory directoryInfoManager, IWindsorContainer applicationWindsorContainer,
                                                 InvestigationInfo investigationInfo, IInvestigationFactory investigationFactory,
                                                 IDetectiveMessenger detectiveMessenger, CreateWorkspaceCommand createWorkspaceCommand, CreateInvestigationCommand createInvestigationCommand) : base(applicationWindsorContainer)
        {
            _createInvestigationCommand = createInvestigationCommand;
            _createWorkspaceCommand     = createWorkspaceCommand;
            _detectiveMessenger         = detectiveMessenger;
            _investigationFactory       = investigationFactory;
            _directoryInfoManager       = directoryInfoManager ?? throw new ArgumentNullException(nameof(directoryInfoManager));
            this.InvestigationInfo      = investigationInfo;
            this.ViewType = typeof(INewWorkspaceInvestionWizardView);
            var ts = DateTime.Now.Millisecond;

            this.SqlConnectionStringBuilder = this.CreateDefaultConnectionStringBuilder();
            this.InvestigationName          = $"Initial investigation - {ts}";
            this.WorkspaceName = $"NFX workspace - {ts}";
        }
        public void Execute(CreateWorkspaceCommand command)
        {
            var workspace = Activator.CreateInstance(command.WorkspaceType) as Workspace;

            if (workspace == null)
            {
                throw new Exception("Workspace cannot be created! If you are using custom workspace type, make sure it derives from Workspace class.");
            }
            workspace.Name = command.Name;
            command.Result = workspace;
            Repository.Add(workspace);
            Execute(new OpenWorkspaceCommand()
            {
                Workspace = workspace
            });

            InvertApplication.SignalEvent <INotify>(_ => _.Notify(command.Name + " workspace has been created!", NotificationIcon.Info));
        }
        public void ExecuteAsync_WithArguments_Creates()
        {
            IDbContext       dbContext        = Substitute.For <IDbContext>();
            string           name             = Guid.NewGuid().ToString();
            WorkspaceDbModel workspaceDbModel = new WorkspaceDbModel();


            dbContext.When(x => x.InsertAsync(DbSchema.WorkspaceContainer, Arg.Any <WorkspaceDbModel>())).Do((callInfo) =>
            {
                Assert.AreEqual(DbSchema.WorkspaceContainer, callInfo.ArgAt <string>(0));
                workspaceDbModel = callInfo.ArgAt <WorkspaceDbModel>(1);
            });

            CreateWorkspaceCommand cmd = new CreateWorkspaceCommand();

            cmd.ExecuteAsync(dbContext, name).Wait();

            dbContext.Received(1).InsertAsync(DbSchema.WorkspaceContainer, Arg.Any <WorkspaceDbModel>());
            Assert.AreEqual(name, workspaceDbModel.Name);
        }