SharePoint Add-in Model (App Model) 介绍 – 概念、托管方式、开发语言
SharePoint Add-in Model 是自 2013 版本以來引入的新的擴展性開發模型, SharePoint 開發者可以利用這種新模型來實現往常利用場解決方案 (Farm Solution)或沙盒解決方案 (Sandbox Solution)進行的站點定制化 (Customizations)。提到站點定制化,常見的用戶場景包括:
- 實現一個自定義的Web 組件 (WebPart), 使得用戶在編輯網站頁面時可以添加該 Web 組件到頁面上。
- 實現一個事件接收器 (Event Receiver),使得文檔或列表發生新增、刪除、更新等操作時觸發相應的邏輯。
- 實現一個計時器任務 (TimerJob), 定期執行某項任務。
- 通過程序化的方式定義一個列表,并對其進行增刪改
- 定義網站欄( Site Column)、內容類型(Content Types)
- 程序化的方式創建網站集 (Site Collection)、網站 (Site),并創建新的文檔庫(Document Libarary),為網站設置主題(Theme),
- 程序化的方式部署母版頁(Master Page)、網頁布局(Page Layouts)
- 更多...
這些定制化在 Add-in Model 中絕大多數都是被支持的, 我們會在后續的文章中深入探討。具體如何實現,可以參考 GitHub 上的開源代碼實現: O365 Patterns and Practices (PnP) 項目
什么是 Add-in Model?
它是 SharePoint 提供的用來讓開發者擴展自身功能的一種開發模型, 基于這種模型開發出的定制化解決方案, 通常稱作 SharePoint Add-ins(我們暫且稱它為定制化程序)。
Add-in 模型提供了一種機制, 讓開發者像開發普通 Web 應用程序一樣開發 SharePoint 定制化程序。這使得圍繞 SharePoint 定制化的開發變得更加開放, 開發者可以使用更多的 Web 技術、框架快速構建出自己想要的解決方案。所以,簡單說來: 基于 Add-in Model 的開發, 就是 Web 應用程序的開發。
簡單說來, Add-ins 就是 Web 應用程序。
“如果你了解如何開發常見 Web 應用程序, 那么,你已經了解了如何基于 Add-in 模型去開發 SharePoint 定制化方案了…”
如何托管定制化方案(Add-ins)
既然基于 Add-in 模型的開發,更多的是 Web 應用程序的開發,那么開發出來的 Add-ins 如何部署, 托管在哪呢?
Add-in 模型提供了兩種方式: SharePoint 自托管、Provider-Hosted 方式。
基于 SharePoint自托管( SharePoint-hosted) 方式實現的 Add-ins
| Add-ins 入口 | 安裝后,網站內容(Site Content)中包含入口瓷塊(tile) |
| 可以包含哪些 UI 組件 | add-in 組件(parts) 和 自定義按鈕(Custom Actions. that is, custom ribbon buttons or menu items)。 可以通過 XML 文件的方式在 Add-ins 中包含如下組件:
|
| 可用的編程語言 |
|
基于 Provider-Hosted 方式實現的 Add-ins
SharePoint 自托管方式支持的組件, 基于 provider-hosted 方式的 Add-ins 中也支持。
Provider-Hosted 方式, 是指將開發出來的 Add-ins 托管在 SharePoint farm 外部的任何服務器上, 這些服務器從硬件的角度上可以是開發者指定的一臺物理機或者 Windows Azure 上的虛擬機。 而從軟件的角度上, 它可以是由 Microsoft IIS 做支撐,也可有由開源的 Apache、Nginx、Tomcat等等。開發者可以利用這些 Web 服務器支持的開發語言如 C#、 JS、HTML、PHP、JAVA 等等來進行開發。
由于 Add-ins 托管在 Farm 外面, 所以如果實現和 SharePoint 網站風格一致,可以利用 SharePoint 提供的 Chrome 控件。代碼如下:
$(document).ready(function () {//Get the URI decoded SharePoint site url from the SPHostUrl parameter.var spHostUrl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));//Get the URI decoded SharePoint app web url from the SPAppWebUrl parameter.var appWebUrl = decodeURIComponent(getQueryStringParameter('SPAppWebUrl'));//Get the isDialog from url parametersvar isDialog = decodeURIComponent(getQueryStringParameter('IsDlg'));//Build absolute path to the layouts root with the spHostUrlvar layoutsRoot = spHostUrl + '/_layouts/15/';//load all appropriate scripts for the page to function$.getScript(layoutsRoot + 'SP.Runtime.js',function () {$.getScript(layoutsRoot + 'SP.js',function () {//Create a Link element for the defaultcss.ashx //resourcevar linkElement = document.createElement('link');linkElement.setAttribute('rel', 'stylesheet');linkElement.setAttribute('href', layoutsRoot + 'defaultcss.ashx');Add the linkElement as a child to the head //section of the htmlvar headElement = document.getElementsByTagName('head');headElement[0].appendChild(linkElement);//Load the SP.UI.Controls.js file to render the App Chrome$.getScript(layoutsRoot + 'SP.UI.Controls.js', renderSPChrome);});});function chromeLoaded() {$('body').show();}//function callback to render chrome after SP.UI.Controls.js loadsfunction renderSPChrome() {//Set the chrome options for launching Help, Account, // and Contact pagesvar options = {'appTitle': document.title,'onCssLoaded': 'chromeLoaded()'};//Load the Chrome Control in the divSPChrome element of the pagevar chromeNavigation = new SP.UI.Controls.Navigation('divSPChrome', options);chromeNavigation.setVisible(true);}Remote data can be blobs, caches, message queues, content delivery networks (CDN), and databases, among others. And databases can be any type including relational and object-oriented. The remote data can be accessed in a variety of ways. For example, you can use Business Connectivity Services (BCS) to surface the data in a SharePoint list. Another option is to expose data in a grid on a page of a remote web application.
Add-ins 可以利用 APIs 來和 SharePoint 資源進行交互, 主要包括以下幾種:
- 利用 .NET 開發時, 可使用 SharePoint 客戶端對象模型 (Client-Side Object Model 簡稱 CSOM)
- REST/OData APIs
SharePoint Add-ins use SharePoint APIs to connect and integrate with SharePoint features—search, workflow, social networking, taxonomy, user profiles, BCS, and more. This lets them read documents, do searches, connect people, and perform CRUD operations.
內容同步發布在 simpeng.net 和 http://www.cnblogs.com/simpeng/p/4900591.html
轉載于:https://www.cnblogs.com/simpeng/p/4900591.html
總結
以上是生活随笔為你收集整理的SharePoint Add-in Model (App Model) 介绍 – 概念、托管方式、开发语言的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 简明Vim练级攻略(转载)
- 下一篇: R语言中strptime返回值永远为NA