这是代码。我获得一个访问令牌,并使用该访问令牌创建一个客户端。如果访问令牌过期会发生什么?我需要创建另一个客户端吗?只创建一个客户端?或者每次我需要用户时,我应该调用 GetGraphServiceClient()?这将解决令牌因需要新令牌而过期的问题。如果不是,我如何验证令牌是否过期?
public async Task<GraphServiceClient> GetGraphServiceClient()
{
var token = await GetAccessToken();
var client = new GraphServiceClient(new DelegateAuthenticationProvider(
(requestMessage) =>
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
return Task.FromResult(0);
}));
return client;
}
private async Task<string> GetAccessToken()
{
var app = ConfidentialClientApplicationBuilder.Create(_connectionData.ClientId)
.WithAuthority(AzureCloudInstance.AzurePublic, _connectionData.TenantId)
.WithClientSecret(_connectionData.ClientSecret)
.Build();
AuthenticationResult result = null;
try
{
result = await app.AcquireTokenForClient(scopes)
.ExecuteAsync();
}
catch (MsalServiceException ex)
{
// Case when ex.Message contains: invalid scope
}
return result?.AccessToken;
}
Run Code Online (Sandbox Code Playgroud) 这将计算椭圆上的顶点坐标:
function calculateEllipse(a, b, angle)
{
var alpha = angle * (Math.PI / 180) ;
var sinalpha = Math.sin(alpha);
var cosalpha = Math.cos(alpha);
var X = a * cosalpha - b * sinalpha;
var Y = a * cosalpha + b * sinalpha;
}
Run Code Online (Sandbox Code Playgroud)
但是如何计算“角度”以获得相等或大致相等的圆周段?
如何从过滤范围中引用上一个可见行中同一列中的单元格?
我已经找到了很多关于这个错误的讨论,但到目前为止我没有尝试过.
基本上我正在使用动态数组创建一个模板矢量类,但是当我尝试重载"+"运算符时,它只适用于2个加数(v3 = v1 + v2),当我尝试3个加数时(v4 = v1 + v2) + v3),它返回最后一个加数(v3).我发现这是因为当第二次调用重载+运算符的函数时,第一个加数的指针值为0xcccccccc.这意味着它可能会对不再存在的东西产生兴趣.但是,我不知道如何从重载函数返回向量对象.这是我尝试过的,但这些都不起作用:
//this works only for two addends
template <class T> Vector<T>& operator+(Vector<T>& v1, Vector<T>& v2)
{
Vector<T> v;
//calculations
return v;
};
//this causes above mentioned error
template <class T> Vector<T> operator+(Vector<T>& v1, Vector<T>& v2)
{
Vector<T> v;
//calculations
return v;
};
//this causes above mentioned error too
template <class T> Vector<T> operator+(Vector<T>& v1, Vector<T>& v2)
{
Vector<T>* v= new Vector<T>;
//calculations
return (*v);
};
Run Code Online (Sandbox Code Playgroud)
任何想法如何返回矢量对象,所以它也适用于3个加数?
是否可以以一种始终占用已定义类型大小的一半的方式定义类型?
typedef int16_t myType;
typedef int8_t myTypeHalf;
Run Code Online (Sandbox Code Playgroud)
所以,当我决定改变的myType从int16_t到int32_t,myTypeHalf会自动更改为int16_t,所以我就不需要担心,我会忘记更改myTypeHalf.
typedef int32_t myType;
typedef int16_t myTypeHalf;
Run Code Online (Sandbox Code Playgroud) 假设我有一节课:
class C
{
public int uniqueField;
public int otherField;
}
Run Code Online (Sandbox Code Playgroud)
这是实际问题的非常简化的版本.我想存储此类的多个实例,其中"uniqueField"对于每个实例应该是唯一的.
在这种情况下更好的是什么?
a)以uniqueField为关键字的字典
Dictionary<int, C> d;
Run Code Online (Sandbox Code Playgroud)
或b)清单?
List<C> l;
Run Code Online (Sandbox Code Playgroud)
在第一种情况(a)中,相同的数据将被存储两次(作为键和作为类实例的字段).但问题是:在字典中查找元素比在列表中更快吗?还是同样快?
一个)
d[searchedUniqueField]
Run Code Online (Sandbox Code Playgroud)
b)
l.Find(x=>x.uniqueField==searchedUniqueField);
Run Code Online (Sandbox Code Playgroud)