r7: method

This commit is contained in:
Sergey Linnik 2019-02-13 17:39:16 +03:00
parent 90b9e0da61
commit 73c58ad844
6 changed files with 551 additions and 12 deletions

View File

@ -0,0 +1,179 @@
/*
*
* (c) Copyright Ascensio System Limited 2010-2017
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Web;
using System.Web.Caching;
using ASC.Api.Collections;
[DataContract(Namespace = "")]
public class TypeDescription : ICloneable
{
[DataMember]
public string Description { get; set; }
[DataMember]
public string Example { get; set; }
[DataMember(EmitDefaultValue = false)]
public string Note { get; set; }
public bool IsOptional { get; set; }
public bool IsCollection { get; set; }
public TypeDescription(string description, string example)
{
Description = description;
Example = example;
}
public TypeDescription Clone()
{
return new TypeDescription(Description, Example);
}
object ICloneable.Clone()
{
return Clone();
}
}
[DataContract(Namespace = "")]
public class TypeDescriptor
{
internal const string SystemNullable = "System.Nullable`1[";
internal const string SystemIEnumerable = "System.Collections.Generic.IEnumerable`1[";
[DataMember(Name = "Names")]
public ItemDictionary<string, TypeDescription> Names = new ItemDictionary<string, TypeDescription>();
public TypeDescriptor()
{
}
public TypeDescription Get(string typeName)
{
if (!string.IsNullOrEmpty(typeName))
{
if (Names.ContainsKey(typeName))
return Names[typeName];
if (typeName.StartsWith(SystemNullable))
{
var optionalDescription =
Get(typeName.Substring(SystemNullable.Length, typeName.Length - 1 - SystemNullable.Length)).
Clone();
optionalDescription.IsOptional = true;
return optionalDescription;
}
if (typeName.StartsWith(SystemIEnumerable))
{
var optionalDescription =
Get(typeName.Substring(SystemIEnumerable.Length, typeName.Length - 1 - SystemIEnumerable.Length))
.Clone();
optionalDescription.IsCollection = true;
optionalDescription.Description = string.Format("Collection of {0}s",
optionalDescription.Description);
return optionalDescription;
}
}
return new TypeDescription(typeName, string.Empty);
}
}
public static class ClassNamePluralizer
{
private static TypeDescriptor _descriptor;
public static void LoadClassNames(Stream data)
{
var serializer = new DataContractSerializer(typeof(TypeDescriptor));
_descriptor = serializer.ReadObject(data) as TypeDescriptor;
}
public static bool IsOptional(string typeName)
{
if (!string.IsNullOrEmpty(typeName))
return typeName.StartsWith(TypeDescriptor.SystemNullable);
return false;
}
public static bool IsCollection(string typeName)
{
if (!string.IsNullOrEmpty(typeName))
return typeName.StartsWith(TypeDescriptor.SystemIEnumerable);
return false;
}
public static TypeDescription ToHumanName(string typeName)
{
return _descriptor == null ? new TypeDescription(typeName, "") : _descriptor.Get(typeName);
}
public static void LoadAndWatch(string path)
{
if (!string.IsNullOrEmpty(path))
{
using (var fs = File.OpenRead(path))
{
LoadClassNames(fs);
}
HttpRuntime.Cache.Add("classnamesfile", path, new CacheDependency(path), Cache.NoAbsoluteExpiration,
Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, OnRemove);
}
}
private static void OnRemove(string key, object value, CacheItemRemovedReason reason)
{
if (reason == CacheItemRemovedReason.DependencyChanged)
{
//need http context to reload:(
try
{
LoadAndWatch(value as string);
}
catch (Exception)
{
}
}
else
{
if (!string.IsNullOrEmpty(value as string))
{
//Insert again
HttpRuntime.Cache.Add("classnamesfile", value, new CacheDependency(value.ToString()),
Cache.NoAbsoluteExpiration,
Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, OnRemove);
}
}
}
}

View File

@ -7,6 +7,18 @@ public class Global : HttpApplication
private static readonly object Locker = new object();
private static volatile bool _initialized;
protected void Application_Start()
{
try
{
ClassNamePluralizer.LoadAndWatch(HttpContext.Current.Server.MapPath("~/App_Data/class_descriptions.xml"));
}
catch (Exception error)
{
LogManager.GetLogger("ASC").Error(error);
}
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (!_initialized)

View File

@ -0,0 +1,187 @@
<TypeDescriptor xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Names>
<entry>
<key>System.Boolean</key>
<value>
<Description>Bool value</Description>
<Example>true</Example>
</value>
</entry>
<entry>
<key>System.DateTime</key>
<value>
<Description>Date and Time</Description>
<Example>2011-10-1</Example>
</value>
</entry>
<entry>
<key>System.String</key>
<value>
<Description>string</Description>
<Example>some text</Example>
</value>
</entry>
<entry>
<key>System.Int32</key>
<value>
<Description>number</Description>
<Example>1234</Example>
</value>
</entry>
<entry>
<key>System.Single</key>
<value>
<Description>number</Description>
<Example>1234</Example>
</value>
</entry>
<entry>
<key>System.Int64</key>
<value>
<Description>number</Description>
<Example>1234</Example>
</value>
</entry>
<entry>
<key>System.Int64[]</key>
<value>
<Description>array of numbers</Description>
<Example>[1234,123]</Example>
</value>
</entry>
<entry>
<key>System.String[]</key>
<value>
<Description>array of strings</Description>
<Example>[some string,another string]</Example>
</value>
</entry>
<entry>
<key>System.Float</key>
<value>
<Description>floating point number</Description>
<Example>123.45</Example>
</value>
</entry>
<entry>
<key>System.Guid</key>
<value>
<Description>guid</Description>
<Example>9924256A-739C-462b-AF15-E652A3B1B6EB</Example>
</value>
</entry>
<entry>
<key>ASC.Projects.Core.Domain.TaskPriority</key>
<value>
<Description>task priority</Description>
<Example>High = 1, Normal = 0, Low = -1</Example>
</value>
</entry>
<entry>
<key>ASC.Projects.Core.Domain.TaskStatus</key>
<value>
<Description>task status</Description>
<Example>NotAccept = 0,Open = 1, Closed = 2,Disable = 3,Unclassified = 4,NotInMilestone = 5</Example>
</value>
</entry>
<entry>
<key>ASC.Projects.Core.Domain.ProjectStatus</key>
<value>
<Description>project status</Description>
<Example>Open = 0, Closed = 1</Example>
</value>
</entry>
<entry>
<key>ASC.Projects.Core.Domain.MilestoneStatus</key>
<value>
<Description>milestone status</Description>
<Example>Open = 0, Closed = 1, Late = 2, Disable = 3</Example>
</value>
</entry>
<entry>
<key>ASC.Forum.TopicType</key>
<value>
<Description>topic type</Description>
<Example>Informational=0,Poll=1</Example>
<Note>What is this?</Note>
</value>
</entry>
<entry>
<key>System.IO.Stream</key>
<value>
<Description>A stream for uploading files without multipart request</Description>
<Example>N/A</Example>
<Note></Note>
</value>
</entry>
<entry>
<key>System.Net.Mime.ContentType</key>
<value>
<Description>A content type for stream when uploading files without multipart request</Description>
<Example>application/octet-stream</Example>
<Note>Set Content-Type header</Note>
</value>
</entry>
<entry>
<key>System.Net.Mime.ContentDisposition</key>
<value>
<Description>A Content Disposition with file name for stream when uploading files without multipart request</Description>
<Example>attachment; filename="file1.png"</Example>
<Note>Set Content-Disposition header</Note>
</value>
</entry>
<entry>
<key>System.Collections.Generic.IEnumerable`1[System.Web.HttpPostedFileBase]</key>
<value>
<Description>Files for adding using multipart/form-data</Description>
<Example>N/A</Example>
</value>
</entry>
<entry>
<key>ASC.Api.Employee.Contact</key>
<value>
<Description>Contact</Description>
<Example>contacts[0][Type]=GTalk&amp;contacts[0][Value]=my@gmail.com</Example>
</value>
</entry>
<entry>
<key>System.Guid[]</key>
<value>
<Description>Collection of Guids</Description>
<Example></Example>
</value>
</entry>
<entry>
<key>ASC.Specific.ApiDateTime</key>
<value>
<Description>Date and Time</Description>
<Example>Roundtrip format: 2008-04-10T06-30-00.000Z</Example>
</value>
</entry>
<entry>
<key>System.Collections.Generic.List`1[ASC.Api.Calendar.CalendarApi+SharingParam]</key>
<value>
<Description>list of sharing options</Description>
<Example></Example>
</value>
</entry>
<entry>
<key>ASC.Api.Documents.FileShareParams</key>
<value>
<Description>FileShareParams</Description>
<Example>share[0].ShareTo=9924256A-739C-462b-AF15-E652A3B1B6EB&amp;share[0].Access=0</Example>
</value>
</entry>
<entry>
<key>ASC.Web.Studio.Core.Backup.BackupAjaxHandler+StorageParams</key>
<value>
<Description>Object with fields: AccessKeyId, SecretAccessKey, Bucket, FolderId, FilePath, Region</Description>
<Example></Example>
</value>
</entry>
</Names>
</TypeDescriptor>

View File

@ -0,0 +1,143 @@
<%@ Control Language="C#" Inherits="BaseContentUserControls" %>
<script runat="server">
protected override void Init()
{
PageTitle = PageCaption = "";
MetaKeyWords = "";
MetaDescription = "";
}
</script>
<div class="MainHelpCenter PageGuides">
<% var section = Request["section"];
var type = Request["type"];
var url = Request["url"];
MsDocEntryPoint docsSection = null;
MsDocEntryPointMethod method = null;
if (!string.IsNullOrEmpty(section)
&& (docsSection = Documentation.GetDocs(section)) != null
&& !string.IsNullOrEmpty(type)
&& !string.IsNullOrEmpty(url))
{
method = docsSection.Methods.SingleOrDefault(x => x.Path.Equals(url, StringComparison.OrdinalIgnoreCase) && x.HttpMethod.Equals(type, StringComparison.OrdinalIgnoreCase));
}
if (method != null)
{ %>
<h1>
<a href="<%= VirtualPathUtility.ToAbsolute("~/portals/section.aspx?section=" + docsSection.Name + (string.IsNullOrEmpty(method.Category) ? null : ("&category=" + method.Category))) %>" class="up"></a>
<span class="hdr"><%= method.HttpMethod + " " + method.Path %></span>
<% if (method.Authentification)
{ %>
<span class="comment">This function requires authentication</span>
<% } %>
</h1>
<% if (!string.IsNullOrEmpty(method.Summary))
{ %>
<div class="header-gray">Description</div>
<p class="dscr"><%= method.Summary %></p>
<% } %>
<div class="header-gray">Parameters</div>
<% if (method.Params.Any(x => x.Visible))
{ %>
<table class="table">
<colgroup>
<col style="width: 20%" />
<col />
<col style="width: 110px" />
<col style="width: 20%" />
</colgroup>
<thead>
<tr class="tablerow">
<td>Name</td>
<td>Description</td>
<td>Type</td>
<td>Example</td>
</tr>
</thead>
<tbody>
<% foreach (var param in method.Params.OrderByDescending(x => x.Method).Where(x => x.Visible))
{
var paramModel = ClassNamePluralizer.ToHumanName(param.Type); %>
<tr class="tablerow">
<td>
<%= param.Name %>
<div class="infotext">sent in <%= param.Method %></div>
</td>
<td>
<%= param.Description %>
<% if (ClassNamePluralizer.IsOptional(param.Type) || param.IsOptional)
{ %>
<div class="infotext">optional</div>
<% } %>
</td>
<td>
<%= paramModel.Description %>
<% if (ClassNamePluralizer.IsCollection(param.Type) || paramModel.IsCollection)
{ %>
<div class="infotext">collection</div>
<% } %>
</td>
<td>
<% if (!string.IsNullOrEmpty(paramModel.Example))
{ %><%= paramModel.Example %><% } %>
<% if (!string.IsNullOrEmpty(paramModel.Note))
{ %>
<div class="infotext"><%= paramModel.Note %></div>
<% } %>
</td>
</tr>
<% } %>
</tbody>
</table>
<% }
else
{ %>
<p>This method doesn't have any parameters</p>
<%} %>
<%if (!string.IsNullOrEmpty(method.Remarks))
{ %>
<div class="header-gray">Remark</div>
<p><%= method.Remarks %></p>
<% } %>
<%if (!string.IsNullOrEmpty(method.Notes))
{ %>
<div class="header-gray">Notes</div>
<p><%= method.Notes %></p>
<% } %>
<%if (!string.IsNullOrEmpty(method.Example))
{ %>
<div class="header-gray">Example</div>
<pre><%= method.Example%></pre>
<% } %>
<div class="header-gray">Returns</div>
<p><%= method.Returns %></p>
<% if (method.Response.Any())
{ %>
<div class="header-gray">Example Response</div>
<% foreach (var output in method.Response.First().Outputs)
{ %>
<p><%= HttpUtility.HtmlEncode(output.Key) %></p>
<pre><%= HttpUtility.HtmlEncode(output.Value) %></pre>
<% }
} %>
<% }
else
{ %>
<h2>Method Not Found</h2>
<p>You can search in documentation</p>
<% }
%>
</div>

View File

@ -41,11 +41,14 @@
<span class="hdr"><%= docsSection.Name %></span>
</h1>
<% if (!string.IsNullOrEmpty(docsSection.Summary))
{ %><p><%= docsSection.Summary %></p><% } %>
{ %><p><%= docsSection.Summary %></p>
<% } %>
<% if (!string.IsNullOrEmpty(docsSection.Remarks))
{ %><p><%= docsSection.Remarks %></p><% } %>
{ %><p><%= docsSection.Remarks %></p>
<% } %>
<% if (!string.IsNullOrEmpty(docsSection.Example))
{ %><p><%= docsSection.Example %></p><% } %>
{ %><p><%= docsSection.Example %></p>
<% } %>
<% }
else
{ %>
@ -71,7 +74,7 @@
<tbody>
<% foreach (var method in methods.OrderBy(x => x.Path.Length))
{
var url = VirtualPathUtility.ToAbsolute("~/portals/method.aspx?section=" + docsSection.Name + "&category=" + method.Category + "&method=" + method.HttpMethod + "&path=" + method.Path); %>
var url = VirtualPathUtility.ToAbsolute("~/portals/method.aspx?section=" + docsSection.Name + "&type=" + method.HttpMethod + "&url=" + method.Path); %>
<tr class="tablerow">
<td>
<a href="<%= url %>"><%= !string.IsNullOrEmpty(method.FunctionName) ? method.FunctionName : method.ShortName %></a>

View File

@ -0,0 +1,15 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/PortalsList.master" %>
<%@ Register Namespace="TeamLab.Controls" Assembly="__Code" TagPrefix="cc" %>
<asp:Content ID="Content4" ContentPlaceHolderID="pagebodyidpage" runat="Server">
<body class="">
</asp:Content>
<asp:Content ID="content3" ContentPlaceHolderID="breadstop" runat="server">
<h5><a href="<%= VirtualPathUtility.ToAbsolute("~/portals/index.aspx") %>">Community server</a></h5>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="content" runat="Server">
<cc:LocalizeContent runat="Server" ControlName="~/Controls/Help/Portals/method.ascx" />
</asp:Content>
<asp:Content ID="content2" ContentPlaceHolderID="leftmenupage" runat="server">
<div class="">
</asp:Content>