Beispiel #1
0
        protected void DoRequest(ResourceGroupRequest request)
        {
            var  list      = new List <Request>();
            bool available = true;

            RequestedResourceLoop((rr, resource) => {
                if (resource.Remaining < rr.Quantity)
                {
                    available = false;
                }
            }, request);

            if (available)
            {
                RequestedResourceLoop((rr, resource) => {
                    list.Add(resource.Request(rr.Quantity));
                }, request);
            }

            request.Requests = list;
            if (available)
            {
                base.DoRequest(request);
            }
        }
Beispiel #2
0
        protected void DoRelease(Release release)
        {
            ResourceGroupRequest req = release.Request as ResourceGroupRequest;

            foreach (var request in req.Requests)
            {
                request.Dispose();
            }
            base.DoRelease(release);
        }
Beispiel #3
0
        public ResourceGroupRequest RequestGroup(IEnumerable <ResourceQuantity> requestedResources, double quantity = 1)
        {
            if (this.Resources.Count == 0)
            {
                throw new InvalidOperationException("No resources in ResourceGroup.");
            }
            if (this.Resources.Count != requestedResources.Count())
            {
                throw new InvalidOperationException("Not all resources requested.");
            }
            ResourceGroupRequest request = new ResourceGroupRequest(Environment, TriggerRelease, base.DisposeCallback, requestedResources, quantity);

            RequestQueue.Enqueue(request);
            TriggerRequest();
            return(request);
        }
Beispiel #4
0
        static async Task Main(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Environment.CurrentDirectory)
                                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                                .AddEnvironmentVariables()
                                .Build();

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddClientDependencies(configuration);
            var serviceProvider = serviceCollection.BuildServiceProvider();

            var resourceGroupRequest = new ResourceGroupRequest()
            {
                Location = "westus",
            };

            var resourceGroupClient = serviceProvider.GetRequiredService <IResourceGroupClient>();
            var resourceGroup       = await resourceGroupClient.CreateResourceGroupAsync("27339114-1084-4083-91c5-eecdd911de26", "TestGroup", resourceGroupRequest).ConfigureAwait(false);

            Console.WriteLine($"Created resource group {resourceGroup.Name}");
        }
        public async Task <ActionResult <EmployeeResourceGroupEntity> > UpdateEmployeeResourceGroupAsync(string id, [FromBody] ResourceGroupRequest employeeResourceGroupEntity, [FromQuery] string groupId)
        {
            try
            {
                if (employeeResourceGroupEntity == null)
                {
                    this.logger.LogError("Employee resource group entity is null.");
                    return(this.BadRequest(this.localizer.GetString("ResourceGroupNullOrEmptyErrorMessage")));
                }

                var updateEntity = await this.employeeResourceGroupRepository.GetAsync(Constants.ResourceGroupTablePartitionKey, id);

                if (updateEntity == null)
                {
                    this.logger.LogError("The employee resource group entity that user is trying to update does not exist.");
                    return(this.NotFound(this.localizer.GetString("ResourceGroupNotExistsErrorMessage")));
                }
                else
                {
                    var userId = this.HttpContext.User.FindFirstValue(Constants.ClaimTypeUserId);

                    // Validating if resource group type is 'Teams', user must be member of that group and they should belongs to same tenant.
                    if (employeeResourceGroupEntity.GroupType == (int)ResourceGroupType.Teams)
                    {
                        string tenantId = ParseTeamIdExtension.GetTenantIdFromDeepLink(updateEntity.GroupLink);

                        if (!this.options.Value.AllowedTenants.Contains(tenantId))
                        {
                            this.logger.LogError($"Tenant is not valid: {tenantId}");
                            return(this.BadRequest(this.localizer.GetString("InvalidTenantErrorMessage")));
                        }

                        string teamId             = ParseTeamIdExtension.GetTeamIdFromDeepLink(updateEntity.GroupLink);
                        var    groupMembersDetail = await this.groupMembersService.GetGroupMembersAsync(groupId);

                        var groupMemberAadIds = groupMembersDetail.Select(row => row.Id).ToList();

                        if (!groupMemberAadIds.Contains(userId))
                        {
                            this.logger.LogError($"User {userId} is not a member of the team {teamId}");
                            return(this.Forbid(this.localizer.GetString("InvalidGroupMemberErrorMessage")));
                        }

                        updateEntity.TeamId = teamId;
                    }
                    else
                    {
                        updateEntity.TeamId = string.Empty;
                    }

                    updateEntity.GroupType                = employeeResourceGroupEntity.GroupType;
                    updateEntity.GroupName                = employeeResourceGroupEntity.GroupName;
                    updateEntity.GroupDescription         = employeeResourceGroupEntity.GroupDescription;
                    updateEntity.GroupLink                = employeeResourceGroupEntity.GroupLink;
                    updateEntity.ImageLink                = employeeResourceGroupEntity.ImageLink;
                    updateEntity.Tags                     = employeeResourceGroupEntity.Tags;
                    updateEntity.Location                 = employeeResourceGroupEntity.Location;
                    updateEntity.IncludeInSearchResults   = employeeResourceGroupEntity.IncludeInSearchResults;
                    updateEntity.IsProfileMatchingEnabled = employeeResourceGroupEntity.IsProfileMatchingEnabled;
                    updateEntity.MatchingFrequency        = employeeResourceGroupEntity.MatchingFrequency;
                    updateEntity.UpdatedByObjectId        = userId;
                    updateEntity.UpdatedOn                = DateTime.UtcNow;

                    await this.employeeResourceGroupRepository.InsertOrMergeAsync(updateEntity);
                }

                return(this.Ok(updateEntity));
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex, "Error while updating employee resource group entity.");
                throw;
            }
        }
Beispiel #6
0
 private void RequestedResourceLoop(Action <ResourceQuantity, Resource> action, ResourceGroupRequest request)
 {
     foreach (var rr in request.RequestedResources)
     {
         var resource = this.Resources.FirstOrDefault(x => x.Id.ToLower() == rr.ResourceId);
         if (resource != null)
         {
             action(rr, resource);
         }
     }
 }