我正在寻找一种算法,将不同大小的项目列表分成"N"个类似大小的组.
具体来说,我正在使用C#中的ASP.NET站点,在那里我有一个(数据库检索的)字符串列表.琴弦的长度各不相同.我有一组需要显示字符串的列.我需要一种算法来找到最平衡的集合(项目顺序无关紧要),以允许最终的列尽可能平衡.
创建3列.
要分发的项目:
- Item A - height 5
- Item B - height 3
- Item C - height 7
- Item D - height 2
- Item E - height 3
Run Code Online (Sandbox Code Playgroud)
期望的输出:
Column 1: Item A, Item D
Column 2: Item C
Column 3: Item B, Item E
Run Code Online (Sandbox Code Playgroud) 如何使用Azure SDK从守护程序(技术上是队列处理器)在资源组中创建新的Azure SQL Server?我遇到的问题是尝试创建时的授权错误.这是例外:
Hyak.Common.CloudException AuthorizationFailed:对象ID为"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"的客户端"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"无权执行"Microsoft.Sql/servers/write"操作超范围'/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/{myResourceGroupName}/providers/Microsoft.Sql/servers/{newServerName}'.
(实际异常在每个占位符中都有实际值.)
我正在使用Microsoft.Azure.Management.SqlNuGet软件包,版本0.38.0-prerelease(最新版本).
我以前曾试图用来CertificateCloudCredentials进行更改 - 但它产生了以下异常:
Hyak.Common.CloudException AuthenticationFailed:身份验证失败."授权"标题不存在或以无效格式提供.
现在我正在使用TokenCloudCredentials,通过以下方式获得:
AuthenticationContext aContext = new AuthenticationContext(string.Format(
anApiConfiguration.LoginUriFormat,
anApiConfiguration.TenantId));
ClientCredential aClientCredential = new ClientCredential(
anApiConfiguration.ClientId,
anApiConfiguration.ClientSecretKey);
AuthenticationResult aTokenResponse = await aContext.AcquireTokenAsync(
anApiConfiguration.BaseResourceUrl,
aClientCredential);
Run Code Online (Sandbox Code Playgroud)
从此我成功获得了一个令牌.然后我使用该令牌如下:
SqlManagementClient sql = new SqlManagementClient(anAuthToken);
ServerCreateOrUpdateProperties someProperties =
new ServerCreateOrUpdateProperties {
AdministratorLogin = someSettings.AdminAccountName,
AdministratorLoginPassword = someSettings.AdminPassword,
Version = "12.0"
};
ServerGetResponse aCreateResponse =
await sql.Servers.CreateOrUpdateAsync(
someSettings.GetResourceGroup(aRegionType),
aServerName,
new ServerCreateOrUpdateParameters(someProperties, aRegion));
Run Code Online (Sandbox Code Playgroud)
最后一行,即CreateOrUpdateAsync调用,是在这篇文章的顶部产生异常的原因.
在Azure Active Directory中,客户端应用程序被授予Windows …