helpcenter/Web/Controls/Help/Server/Community/CommunityServerCreateAPI/CommunityServerCreateAPI.ru.ascx
2017-12-23 11:32:35 +03:00

98 lines
6.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<%@ Control Language="C#" Inherits="BaseContentUserControls"%>
<%@ Register Namespace="TeamLab.Controls" Assembly="__Code" TagPrefix="cc" %>
<script runat="server">
protected override void Init()
{
PageTitle = PageCaption = "Создание API для пользовательских модулей Сервера совместной работы";
MetaKeyWords = "";
MetaDescription = "Узнайте, как создать API для пользовательских модулей Сервера совместной работы.";
}
</script>
<div class="main_buscall_container dataBackup">
<div class="MainHelpCenter">
<h1 class="subHeaderFeaturesCaption TipsCaption">Создание API для пользовательских модулей Сервера совместной работы</h1>
<cc:LocalizeContent runat="Server" ControlName="~/Controls/Help/VariousControls/Versions/CommunityServer/CommunityServer_Current.ascx" />
<div class="keyword_block">
<ul>
<li><cc:LocalizeContent runat="Server" ControlName="~/Controls/Help/Tags/server-version/server-version.ascx" /></li>
<li><cc:LocalizeContent runat="Server" ControlName="~/Controls/Help/Tags/community-server/community-server.ascx" /></li>
</ul>
</div>
<h2 id="introduction">Введение</h2>
<div class="block_of_step">
<div class="screen_text">
<p>Если вы создали свой собственный модуль для ONLYOFFICE и добавили его в <b>Сервер совместной работы</b>, следуя <a target="_blank" href="<%=VirtualPathUtility.ToAbsolute("~/server/community/community-server-custom-modules.aspx")%>">этим инструкциям</a>, вы также можете создать API для этого модуля.</p>
</div>
</div>
<h2 id="CreateAPI">Как создать API для своего собственного модуля</h2>
<div class="block_of_step">
<div class="screen_text">
<ol>
<li>Создайте проект для библиотеки классов (<code>ASC.Api.Sample</code>) и поместите его в папку <code>...module\ASC.Api\ASC.Api.Sample</code>.
<div class="notehelp nh_important"><span class="important_notice_label">ВАЖНО!!!</span> Выходной dll-файл должен называться "ASC.Api.*.dll";</div>
</li>
<li>Подключите необходимые ссылки из <code>...\web\studio\ASC.Web.Studio\bin\</code>:
<pre><code>ASC.Api.dll
ASC.Web.Sample.dll
</code></pre>
</li>
<li>Создайте класс <code>SampleApi</code> и реализуйте интерфейс <code>IApiEntryPoint</code>:
<pre><code>public class SampleApi : IApiEntryPoint
{
public string Name
{
get { return "sample"; }
}
}
</code></pre>
</li>
<li>Создайте публичные методы с заданными атрибутами:
<pre><code>[Attributes.Create("create", false)]
public SampleClass Create(string value)
{
return SampleDao.Create(value);
}
</code></pre>
<p>Атрибуты задают тип метода, путь, по которому будет вызываться этот метод, авторизацию, проверку тарифного плана. Возможные опции приведены ниже:</p>
<pre><code>CreateAttribute(string path, bool requiresAuthorization = true, bool checkPayment = true) //corresponds to the "POST" request
UpdateAttribute(string path, bool requiresAuthorization = true, bool checkPayment = true) //corresponds to the "PUT" request
DeleteAttribute(string path, bool requiresAuthorization = true, bool checkPayment = true) //corresponds to the "DELETE" request
ReadAttribute(string path, bool requiresAuthorization = true, bool checkPayment = true) //corresponds to the "GET" request
</code></pre>
<p>параметры <code>requiresAuthorization</code> и <code>checkPayment</code> являются необязательными и по умолчанию имеют значение <code>true</code>.</p>
</li>
<li>Задайте выходной путь в свойствах проекта следующим образом:
<pre><code>&lt;OutputPath&gt;..\..\..\web\studio\ASC.Web.Studio\bin\&lt;/OutputPath&gt;
&lt;DocumentationFile&gt;..\..\..\web\studio\ASC.Web.Studio\bin\ASC.Api.Sample.XML&lt;/DocumentationFile&gt;
</code></pre>
<p>чтобы сборки создавались в папке <code>web\studio\ASC.Web.Studio\bin</code>.</p>
</li>
<li>Проект можно собрать вручную или с помощью инструмента автоматической сборки. Во втором случае добавьте следующие строки в файл <code>build\msbuild\build.proj</code>:
<pre><code>&lt;ProjectToBuild Include="$(ASCDir)module\ASC.Api\ASC.Api.Sample\ASC.Api.Sample.csproj"/&gt;
</code></pre>
<p>и запустите файл <code>build\Build.bat</code>.</p>
</li>
<li><div class="notehelp nh_important"><span class="important_notice_label">ВАЖНО!!!</span> Добавьте <code>ASC.Api.Sample.SampleApi</code> в файл <code>web\studio\ASC.Web.Studio\web.autofac.config</code>:</div>
<pre><code>&lt;component
type="ASC.Api.Sample.SampleApi, ASC.Api.Sample"
service="ASC.Api.Interfaces.IApiEntryPoint, ASC.Api"
name="sample"/&gt;
</code></pre>
</li>
<li>Соберите проект, запустите сайт и протестируйте метод, выполнив запрос с помощью jQuery:
<pre><code>$.ajax({
type: "POST",
url: "http://localhost:port/api/2.0/sample/create.json",
data: {value: "create"}
});
</code></pre>
</li>
</ol>
</div>
</div>
</div>
</div>