Exemplo n.º 1
0
 public void Handle(ProjectCreatedEvent e)
 {
     UserId       = e.UserId;
     Id           = e.Id;
     Company      = e.Company;
     Introduction = e.Introduction;
 }
Exemplo n.º 2
0
 protected override void Context()
 {
     base.Context();
     _project = A.Fake <IPKSimProject>();
     A.CallTo(() => _eventPublisher.PublishEvent(A <ProjectCreatedEvent> .Ignored)).Invokes(
         x => _event = x.GetArgument <ProjectCreatedEvent>(0));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Handles when a new project has been created.
 /// </summary>
 /// <param name="evt">Evt.</param>
 void HandleNewProject(ProjectCreatedEvent evt)
 {
     CreatedProjects++;
     ManualEventsCount = 0;
     DrawingsCount     = 0;
     openedProjectID   = evt.ProjectId;
 }
Exemplo n.º 4
0
        public void SaveEvent_Sends_Event_Via_EventAggregator()
        {
            var @event = new ProjectCreatedEvent { Id = "project/1234", ProjectName = "test", Version = 0 };

            _store.SaveEvents("project/1234", new[] { @event }, -1);

            _bus.ReceivedWithAnyArgs().Send<IEvent>(Arg.Is(@event));
        }
Exemplo n.º 5
0
        public Project(int userId, int id, string company, string introduction)
        {
            Viewers      = new List <ProjectViewer>();
            Contributors = new List <ProjectContributor>();
            var @event = new ProjectCreatedEvent(userId, id, company, introduction);

            AddDomainEvent(@event);
            Handle(@event);
        }
        public void Handle(ProjectCreatedEvent evt)
        {
            _logger.LogInformation(GetLogMessage("Project Created Event Triggered"));

            Parallel.Invoke(new List <Action>
            {
                () => ProjectCreatedSendProjectManagerEmail(evt.ProjectId),
                () => ProjectCreatedSendAccountManagerEmail(evt.ProjectId),
                () => ProjectCreatedSendAgencyOwnerEmail(evt.ProjectId)
            }.ToArray());
        }
Exemplo n.º 7
0
        public async Task CreateProject(ProjectCreatedEvent @event, ApplicationOptions applicationOptions)
        {
            string accountUrl = $"https://{@event.CMSAccountName}.visualstudio.com";

            int index = 0;

            while (true)
            {
                HttpClientWrapperAuthorizationModel authCredentials = new HttpClientWrapperAuthorizationModel();
                authCredentials.Schema = "Basic";
                authCredentials.Value  = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", @event.CMSAccessSecret)));

                string projectUrl      = $"{accountUrl}/_apis/projects?api-version={_vstsOptions.Value.ApiVersion}";
                var    projectResponse = await _httpClientWrapperService.GetAsync(projectUrl, authCredentials);

                projectResponse.EnsureSuccessStatusCode();

                var projects = await projectResponse.MapTo <CMSVSTSProjectListModel>();

                var project = projects.Items.FirstOrDefault(x => x.Name.Equals(@event.ProjectName, StringComparison.InvariantCultureIgnoreCase));
                if (project != null)
                {
                    var oAuthToken = await _httpClientWrapperService.GetTokenFromClientCredentials($"{applicationOptions.Url}/connect/token", applicationOptions.ClientId, applicationOptions.ClientSecret, applicationOptions.Scope);

                    HttpClientWrapperAuthorizationModel internalAuthCredentials = new HttpClientWrapperAuthorizationModel();
                    internalAuthCredentials.Schema = "Bearer";
                    internalAuthCredentials.Value  = oAuthToken.access_token;

                    //Patch Project External Id
                    string projectPatchUrl      = $"{applicationOptions.Url}/internalapi/organizations/{@event.OrganizationId}/projects/{@event.ProjectId}";
                    var    projectPatchResponse = await _httpClientWrapperService.PatchAsync(projectPatchUrl, new {
                        ProjectExternalId   = project.Id,
                        ProjectExternalName = project.Name
                    }, internalAuthCredentials);

                    projectPatchResponse.EnsureSuccessStatusCode();

                    break;
                }
                else
                {
                    index++;
                    //this means after 20 seconds it didn't create the project
                    if (index == 6)
                    {
                        throw new Exception($"After 20 seconds it could be possible to retreive the external project id: Ref: {@event.ProjectId} - {@event.ProjectName}");
                    }

                    Thread.Sleep(TimeSpan.FromSeconds(5));
                }
            }
        }
Exemplo n.º 8
0
        protected override void Context()
        {
            base.Context();
            _fileName   = "toto";
            _project    = A.Fake <PKSimProject>();
            sut.Project = _project;

            A.CallTo(() => _eventPublisher.PublishEvent(A <ProjectLoadingEvent> ._)).Invokes(
                x => _event = x.GetArgument <ProjectLoadingEvent>(0));

            A.CallTo(() => _eventPublisher.PublishEvent(A <ProjectLoadedEvent> ._)).Invokes(
                x => _event2 = x.GetArgument <ProjectLoadedEvent>(0));

            A.CallTo(() => _eventPublisher.PublishEvent(A <ProjectCreatedEvent> ._)).Invokes(
                x => _event3 = x.GetArgument <ProjectCreatedEvent>(0));
        }
Exemplo n.º 9
0
        public void Create(
            Guid id,
            string title,
            string description,
            User owner)
        {
            if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(description) || owner == null)
            {
                throw new ArgumentException("A title, description and owner needs to be provided.");
            }

            var payload     = new { Title = title, Description = description, OwnerId = owner.Id };
            var jsonPayload = JsonConvert.SerializeObject(payload);

            var projectCreatedEvent = new ProjectCreatedEvent(
                id,
                1,
                jsonPayload);

            Apply(projectCreatedEvent);
        }
Exemplo n.º 10
0
        public async Task <IActionResult> CreateProject([FromBody] Domain.AggregatesModel.Project project)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            project.UserId = project.UserId;

            var command = new CreateProjectCommand {
                Project = project
            };

            Domain.AggregatesModel.Project projectResponse = null;

            using (var transaction = await _projectContext.Database.BeginTransactionAsync())
            {
                var eventHandler = new ProjectCreatedDomainEventHandler(_cabPublisher);
                var createdEvent = new ProjectCreatedEvent()
                {
                    Project = project
                };
                //发布用户属性变更的消息
                await eventHandler.Handle(createdEvent, new System.Threading.CancellationToken());

                projectResponse = await _mediator.Send(command);

                transaction.Commit();
            }

            if (projectResponse == null)
            {
                return(BadRequest("创建项目失败"));
            }

            return(Ok(projectResponse));
        }
Exemplo n.º 11
0
 public void Handle(ProjectCreatedEvent eventToHandle)
 {
     updateProjectInfo(eventToHandle.Project, enabled: true);
     updateUndefinedJournalInfo();
 }
Exemplo n.º 12
0
 public void Apply(ProjectCreatedEvent e)
 {
     _id = e.Id;
     _name = e.ProjectName;
     _description = e.Description;
 }
Exemplo n.º 13
0
 public void Handle(ProjectCreatedEvent eventToHandle)
 {
     projectItemsAreEnabled = true;
 }
Exemplo n.º 14
0
 public void Handle(ProjectCreatedEvent eventToHandle)
 {
     updateProjectItems(isEnabled: true, observedDataEnabled: compoundsAvailableIn(eventToHandle.Project));
 }
 public virtual void Handle(ProjectCreatedEvent eventToHandle)
 {
     AddProjectToTree(eventToHandle.Project);
 }
        public async Task ProjectCreated(ProjectCreatedEvent @event)
        {
            await _recommendContext.AddAsync(new RecommendProject { Avatar = @event.Avatar, Company = @event.Company, UserId = @event.UserId, ProjectId = @event.Id });

            await _recommendContext.SaveChangesAsync();
        }
        public async Task CreateProject(Guid organizationId, ProjectPostRp resource)
        {
            string loggedUserId = _identityService.GetUserId();

            User user = await _userRepository.GetUser(loggedUserId);

            Organization organization = user.FindOrganizationById(organizationId);

            if (organization == null)
            {
                await _domainManagerService.AddNotFound($"The organzation with id {organizationId} does not exists.");

                return;
            }

            OrganizationCMS organizationCMS = organization.GetConfigurationManagementServiceById(resource.OrganizationCMSId);

            if (organizationCMS == null)
            {
                await _domainManagerService.AddNotFound($"The configuration management service with id {resource.OrganizationCMSId} does not exists.");

                return;
            }

            if (organizationCMS.Type == ConfigurationManagementService.VSTS && resource.projectVisibility == ProjectVisibility.None)
            {
                await _domainManagerService.AddConflict($"The project visibility should be Private or Public.");

                return;
            }

            OrganizationCPS organizationCPS = null;

            if (resource.OrganizationCPSId.HasValue)
            {
                organizationCPS = organization.GetCloudProviderServiceById(resource.OrganizationCPSId.Value);

                if (organizationCPS == null)
                {
                    await _domainManagerService.AddNotFound($"The cloud provider service with id {resource.OrganizationCPSId} does not exists.");

                    return;
                }
            }
            else
            {
                organizationCPS = new OrganizationCPS {
                    Type = CloudProviderService.None
                };
            }

            ProjectTemplate projectTemplate = null;

            if (resource.ProjectTemplateId.HasValue)
            {
                projectTemplate = await _projectTemplateRepository.GetProjectTemplateById(resource.ProjectTemplateId.Value);

                if (projectTemplate == null)
                {
                    await _domainManagerService.AddNotFound($"The project template with id {resource.ProjectTemplateId.Value} does not exists.");

                    return;
                }
            }

            Project existingProject = organization.GetProjectByName(resource.Name);

            if (existingProject != null)
            {
                await _domainManagerService.AddConflict($"The project name {resource.Name} has already been taken.");

                return;
            }

            //Auth
            CMSAuthCredentialModel cmsAuthCredential = this._cmsCredentialService(organizationCMS.Type).GetToken(
                _dataProtectorService.Unprotect(organizationCMS.AccountId),
                _dataProtectorService.Unprotect(organizationCMS.AccountName),
                _dataProtectorService.Unprotect(organizationCMS.AccessSecret),
                _dataProtectorService.Unprotect(organizationCMS.AccessToken));

            CMSProjectAvailabilityResultModel cmsProjectAvailability = await _cmsService(organizationCMS.Type).ValidateProjectAvailability(cmsAuthCredential, resource.TeamId, resource.Name);

            if (!cmsProjectAvailability.Success)
            {
                await _domainManagerService.AddConflict($"The CMS data is not valid. {cmsProjectAvailability.GetReasonForNoSuccess()}");

                return;
            }

            Project newProject = user.CreateProject(organizationId, resource.TeamId, resource.Name, resource.Description, resource.ProjectType, resource.OrganizationCMSId, resource.OrganizationCPSId, resource.ProjectTemplateId, resource.AgentPoolId, resource.projectVisibility, organizationCPS.Type, organizationCMS.Type);

            //SaveChanges in CSM
            CMSProjectCreateModel projectCreateModel = CMSProjectCreateModel.Factory.Create(organization.Name, resource.Name, resource.Description, resource.projectVisibility);

            projectCreateModel.TeamId = resource.TeamId;

            CMSProjectCreateResultModel cmsProjectCreate = await _cmsService(organizationCMS.Type).CreateProject(cmsAuthCredential, projectCreateModel);

            if (!cmsProjectCreate.Success)
            {
                await _domainManagerService.AddConflict($"The CMS data is not valid. {cmsProjectCreate.GetReasonForNoSuccess()}");

                return;
            }

            newProject.UpdateExternalInformation(cmsProjectCreate.ProjectExternalId, resource.Name);

            _userRepository.Update(user);

            await _userRepository.SaveChanges();

            await _domainManagerService.AddResult("ProjectId", newProject.ProjectId);

            //send event
            var @event = new ProjectCreatedEvent(_correlationId)
            {
                OrganizationId      = organization.OrganizationId,
                ProjectId           = newProject.ProjectId,
                ProjectName         = newProject.Name,
                InternalProjectName = newProject.InternalName,
                ProjectVSTSFake     = this._slugService.GetSlug($"{organization.Owner.Email} {organization.Name} {newProject.Name}"),
                AgentPoolId         = newProject.AgentPoolId,

                CMSType         = organizationCMS.Type,
                CMSAccountId    = _dataProtectorService.Unprotect(organizationCMS.AccountId),
                CMSAccountName  = _dataProtectorService.Unprotect(organizationCMS.AccountName),
                CMSAccessId     = _dataProtectorService.Unprotect(organizationCMS.AccessId),
                CMSAccessSecret = _dataProtectorService.Unprotect(organizationCMS.AccessSecret),
                CMSAccessToken  = _dataProtectorService.Unprotect(organizationCMS.AccessToken),

                CPSType            = organizationCPS.Type,
                CPSAccessId        = organizationCPS.Type != CloudProviderService.None ? _dataProtectorService.Unprotect(organizationCPS.AccessId) : string.Empty,
                CPSAccessName      = organizationCPS.Type != CloudProviderService.None ? _dataProtectorService.Unprotect(organizationCPS.AccessName) : string.Empty,
                CPSAccessSecret    = organizationCPS.Type != CloudProviderService.None ? _dataProtectorService.Unprotect(organizationCPS.AccessSecret) : string.Empty,
                CPSAccessAppId     = organizationCPS.Type != CloudProviderService.None ? _dataProtectorService.Unprotect(organizationCPS.AccessAppId) : string.Empty,
                CPSAccessAppSecret = organizationCPS.Type != CloudProviderService.None ? _dataProtectorService.Unprotect(organizationCPS.AccessAppSecret) : string.Empty,
                CPSAccessDirectory = organizationCPS.Type != CloudProviderService.None ? _dataProtectorService.Unprotect(organizationCPS.AccessDirectory) : string.Empty,
                UserId             = loggedUserId
            };

            if (resource.ProjectTemplateId.HasValue)
            {
                @event.ProjectTemplate          = new ProjectTemplateCreatedEvent();
                @event.ProjectTemplate.Services = projectTemplate.Services.Select(x => new ProjectTemplateServiceCreatedEvent()
                {
                    Name = x.Name,
                    ProjectServiceTemplateId = x.ProjectServiceTemplateId
                }).ToList();
            }

            await _eventBusService.Publish(queueName : "ProjectCreatedEvent", @event : @event);
        }
Exemplo n.º 18
0
 public void Handle(ProjectCreatedEvent eventToHandle)
 {
     updateLoadedProjectItem(eventToHandle);
 }
Exemplo n.º 19
0
 public void Handle(ProjectCreatedEvent eventToHandle)
 {
     refreshHistory();
 }
Exemplo n.º 20
0
 public void Apply(ProjectCreatedEvent e)
 {
     _projects.Add(new Entities.Project(e.ProjectId, e.Name));
 }