Example #1
0
        private static CoreServiceResponse GetApplicationRegistrationResponse(ClientApplicationFactory appFactory)
        {
            CoreServiceResponse <ApplicationRegistration.Data.Application> appResponse = appFactory.Execute();

            if (appResponse.Success)
            {
                return(GetApplicationRegistrationSuccessResult(appResponse));
            }
            return(appResponse);
        }
Example #2
0
        public virtual CoreServiceResponse RegisterApplication(ProcessDescriptor descriptor)
        {
            try
            {
                Args.ThrowIfNull(descriptor?.Application?.Name, "descriptor.Application.Name");
                Args.ThrowIfNull(descriptor?.Application?.Organization?.Name, "descriptor.Application.Organization.Name");

                string organizationName = descriptor.Application.Organization.Name;
                if (CurrentUser.Equals(UserAccounts.Data.User.Anonymous))
                {
                    return(new CoreServiceResponse <ApplicationRegistrationResult> {
                        Success = false, Message = "You must be logged in to do that", Data = new ApplicationRegistrationResult {
                            Status = ApplicationRegistrationStatus.Unauthorized
                        }
                    });
                }
                User user = CoreRegistryRepository.OneUserWhere(c => c.UserName == CurrentUser.UserName);
                if (user == null)
                {
                    user = new User()
                    {
                        UserName = CurrentUser.UserName,
                        Email    = CurrentUser.Email
                    };
                    user = CoreRegistryRepository.Save(user);
                }
                OrganizationFactory orgEnforcer             = new OrganizationFactory(CoreRegistryRepository, user, organizationName);
                CoreServiceResponse <Organization> response = orgEnforcer.Execute();
                if (!response.Success)
                {
                    return(response);
                }
                Organization             org         = response.TypedData();
                ClientApplicationFactory appEnforcer = new ClientApplicationFactory(this, user, organizationName, descriptor);
                CoreServiceResponse <ApplicationRegistration.Application> appResponse = appEnforcer.Execute();
                if (appResponse.Success)
                {
                    ApplicationRegistration.Application app = appResponse.TypedData();
                    return(new CoreServiceResponse <ApplicationRegistrationResult>(
                               new ApplicationRegistrationResult
                    {
                        Status = ApplicationRegistrationStatus.Success,
                        ClientId = app.Cuid,
                        ApiKey = app.ApiKeys.First().SharedSecret
                    })
                    {
                        Success = true
                    });
                }
                return(appResponse);
            }
            catch (Exception ex)
            {
                Logger.AddEntry("Exception occurred in {0}", ex, nameof(CoreApplicationRegistrationService.RegisterApplication));
                return(new CoreServiceResponse {
                    Success = false, Message = ex.Message
                });
            }
        }