从C#Web API方法中创建Office365邮箱 [英] Create an Office365 mailbox from within C# Web API method

查看:316
本文介绍了从C#Web API方法中创建Office365邮箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文

我有一个由ASP.NET MVC应用程序调用的ASP.NET Web API应用程序.

I have an ASP.NET Web API application invoked by an ASP.NET MVC application.

在Web API中,我有一种方法需要在其他内容中创建Office365邮箱(创建文件夹,创建联系人,创建签名等...)

Inside the Web API, I have a method that will need to create an Office365 mailbox amongst other stuff (create folders, create a contact, create a signature etc.…)

该邮箱的创建实际上隐藏了一些需要按特定顺序进行的步骤:

The creation of that mailbox actually hides few steps that need to occur in a particular order:

  1. 在本地Active Directory中创建用户(返回true或 错误).
  2. 强制AD Connect在本地AD和 Azure AD,因为默认延迟为30分钟,我们等不及了 因此,为什么我们需要强制进行同步(返回void).
  3. 验证Office365帐户是否存在(返回true或 错误).
  4. 验证我们是否仍有可用的Office365许可证分配给 该用户.
  1. Create a User in the local Active Directory (return true or false).
  2. Force AD Connect to synchronize between the local AD and the Azure AD because there is a default 30 min delay which we can’t wait for, hence why we need to force the synchronization (return void).
  3. Verify if the Office365 account exist or not (return true or false).
  4. Verify if we still have available Office365 licenses to assign to that user.

(注意:如果许可证不足,则会发送一封电子邮件 购买更多许可证...)

(NOTE: if not enough licenses, an email will be sent to purchase more licenses...)

  1. 将Office365许可证分配给该用户.

(注意:我相信 向用户分配许可证的操作实际上会创建 邮箱...如果我写错了请纠正我)

(NOTE: I believe the action of assigning a license to a user actually creates the mailbox...correct me if I’m wrong)

  1. 在该用户的邮箱下创建几个文件夹(返回空白).
  2. 创建两个新的联系人(返回空).
  3. 创建签名(返回无效).

问题

我对一些事情有些困惑……首先,其中某些任务(不是全部)可以通过使用Microsoft Graph来完成,而其他任务根本无法实现,因为Graph不支持它(还).

I’m a bit confused with a few things...firstly, some of these tasks (not all) can be achieved by using Microsoft Graph while other tasks simply can’t because Graph doesn’t support it (yet).

其次,我可以使用某些PowerShell cmdlets来完成其中一些任务(例如:强制AD Connect同步).实际上,我确信可以使用多个cmdlets(或简单地将其合并到一个大型PowerShell脚本中)完成上述所有步骤.

Secondly, I can achieve some of these tasks (for example: force AD Connect to sync) by using some PowerShell cmdlets. In fact, I’m sure the entire steps above can be achieved using multiple cmdlets (or simply combined within one big PowerShell script).

第三,我正在抓紧稻草以了解什么是解决此问题的最佳方法.

Thirdly, I’m grasping at straws to understand what is the best way to tackle this.

例如,考虑到我在HttpRequest的上下文中,我的Web API方法是否应该同时使用某些PowerShell cmdlets和某些Microsoft Graph?

For example, considering I’m in the context of an HttpRequest, should my Web API method use a mixture of some PowerShell cmdlets and some Microsoft Graph?

我应该同时混合两者吗?还是不?

Should I be mixing both? Or not?

我应该找到所有cmdlets,将它们按顺序放在一个大PS1文件中,然后从我的Web API方法中简单地执行一个大PS1文件吗?

Should I instead, find all the cmdlets, place them in order inside one big PS1 file and simply execute that one big PS1 file from within my Web API method?

我是否应该查找每个cmdlets中隐藏的所有Web API,并改用这些Web API调用?

Should I instead find all the Web API hidden inside each cmdlets and use those Web API calls instead?

我似乎在每种方法中都发现了一些优点和缺点,无法确定最好的方法.

I seem to find a little bit of Pros and Cons in each and can’t settle on what’s best.

我担心如果尝试从我的C#代码中直接运行cmdlets,如果cmdlets之一失败或引发异常,那么该如何处理?同样,如果我将所有内容都放在一个大文件中...

I have concerns that if I try to run cmdlets directly from within my C# code that if one of the cmdlets fails or throws an exception, then how to handle that? Likewise if I put everything in one big file...

不幸的是,我的问题似乎多于答案,也许有人可以帮助我阐明一下:-)

Unfortunately, I seem to have more questions than answers and perhaps someone can help me shed some light on this :-)

真诚的

PS:虽然也许更好的解决方案是将Azure Functions与某种队列一起使用,但是不幸的是,我对Azure Functions不够熟悉,也没有时间实现更好的方法.如果可能的话,我想坚持在Web API方法中做到这一点.

PS: Although maybe a better solution would be to use Azure Functions with some kind of Queue but unfortunately, I’m not familiar enough with Azure Functions nor do I have the time to implement a nicer way. If possible, I’d like to stick with making this happen within the Web API method.

推荐答案

根据我的理解,Microsoft Graph仅允许我们操纵Microsoft云资源,如Office 365等.

Based on my understanding, the Microsoft Graph only allow us to manipulate the Microsoft cloud resource like Office 365, etc.

它无法使用它或其他REST服务来强制Azure AD连接同步从本地到云的更改(Start-ADSyncSyncCycle -PolicyType Delta).我不想将业务逻辑混合到不同的位置(C#和Powershell代码),而是希望将其保留在相同的位置(在这种情况下为PowerShell脚本),以便于维护.并且我们需要在PowerShell脚本中编写异常/错误处理.

It is not able to using it or other REST service to force Azure AD connect to synchronize the changing from local to cloud(Start-ADSyncSyncCycle -PolicyType Delta). Instead of mixing the business logic to different places(C# and Powershell code), I'd like to keep it in the same place(PowerShell script in this scenario) to easy to maintain. And we need to write the the exception/error handling in the PowerShell script.

希望这会有所帮助.

这篇关于从C#Web API方法中创建Office365邮箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆