From 73c58ad844d1c02c415e0041144fd759f9341e97 Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Wed, 13 Feb 2019 17:39:16 +0300 Subject: [PATCH] r7: method --- .../DocumentGenerator/ClassNamePluralizer.cs | 179 +++++++++++++++++ .../Web/App_Code/Global.cs | 12 ++ .../Web/App_Data/class_descriptions.xml | 187 ++++++++++++++++++ .../Web/Controls/Help/Portals/method.ascx | 143 ++++++++++++++ .../Web/Controls/Help/Portals/section.ascx | 27 +-- .../Web/portals/Method.aspx | 15 ++ 6 files changed, 551 insertions(+), 12 deletions(-) create mode 100644 helpcenter.r7-office.ru/Web/App_Code/DocumentGenerator/ClassNamePluralizer.cs create mode 100644 helpcenter.r7-office.ru/Web/App_Data/class_descriptions.xml create mode 100644 helpcenter.r7-office.ru/Web/Controls/Help/Portals/method.ascx create mode 100644 helpcenter.r7-office.ru/Web/portals/Method.aspx diff --git a/helpcenter.r7-office.ru/Web/App_Code/DocumentGenerator/ClassNamePluralizer.cs b/helpcenter.r7-office.ru/Web/App_Code/DocumentGenerator/ClassNamePluralizer.cs new file mode 100644 index 000000000..3f038b44f --- /dev/null +++ b/helpcenter.r7-office.ru/Web/App_Code/DocumentGenerator/ClassNamePluralizer.cs @@ -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 Names = new ItemDictionary(); + + 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); + } + } + } +} \ No newline at end of file diff --git a/helpcenter.r7-office.ru/Web/App_Code/Global.cs b/helpcenter.r7-office.ru/Web/App_Code/Global.cs index 8563c6868..fc176e4c6 100644 --- a/helpcenter.r7-office.ru/Web/App_Code/Global.cs +++ b/helpcenter.r7-office.ru/Web/App_Code/Global.cs @@ -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) diff --git a/helpcenter.r7-office.ru/Web/App_Data/class_descriptions.xml b/helpcenter.r7-office.ru/Web/App_Data/class_descriptions.xml new file mode 100644 index 000000000..8d654b454 --- /dev/null +++ b/helpcenter.r7-office.ru/Web/App_Data/class_descriptions.xml @@ -0,0 +1,187 @@ + + + + System.Boolean + + Bool value + true + + + + System.DateTime + + Date and Time + 2011-10-1 + + + + System.String + + string + some text + + + + System.Int32 + + number + 1234 + + + + System.Single + + number + 1234 + + + + System.Int64 + + number + 1234 + + + + System.Int64[] + + array of numbers + [1234,123] + + + + System.String[] + + array of strings + [some string,another string] + + + + System.Float + + floating point number + 123.45 + + + + System.Guid + + guid + 9924256A-739C-462b-AF15-E652A3B1B6EB + + + + ASC.Projects.Core.Domain.TaskPriority + + task priority + High = 1, Normal = 0, Low = -1 + + + + ASC.Projects.Core.Domain.TaskStatus + + task status + NotAccept = 0,Open = 1, Closed = 2,Disable = 3,Unclassified = 4,NotInMilestone = 5 + + + + ASC.Projects.Core.Domain.ProjectStatus + + project status + Open = 0, Closed = 1 + + + + ASC.Projects.Core.Domain.MilestoneStatus + + milestone status + Open = 0, Closed = 1, Late = 2, Disable = 3 + + + + ASC.Forum.TopicType + + topic type + Informational=0,Poll=1 + What is this? + + + + + System.IO.Stream + + A stream for uploading files without multipart request + N/A + + + + + + System.Net.Mime.ContentType + + A content type for stream when uploading files without multipart request + application/octet-stream + Set Content-Type header + + + + + System.Net.Mime.ContentDisposition + + A Content Disposition with file name for stream when uploading files without multipart request + attachment; filename="file1.png" + Set Content-Disposition header + + + + + System.Collections.Generic.IEnumerable`1[System.Web.HttpPostedFileBase] + + Files for adding using multipart/form-data + N/A + + + + ASC.Api.Employee.Contact + + Contact + contacts[0][Type]=GTalk&contacts[0][Value]=my@gmail.com + + + + System.Guid[] + + Collection of Guids + + + + + ASC.Specific.ApiDateTime + + Date and Time + Roundtrip format: 2008-04-10T06-30-00.000Z + + + + System.Collections.Generic.List`1[ASC.Api.Calendar.CalendarApi+SharingParam] + + list of sharing options + + + + + ASC.Api.Documents.FileShareParams + + FileShareParams + share[0].ShareTo=9924256A-739C-462b-AF15-E652A3B1B6EB&share[0].Access=0 + + + + ASC.Web.Studio.Core.Backup.BackupAjaxHandler+StorageParams + + Object with fields: AccessKeyId, SecretAccessKey, Bucket, FolderId, FilePath, Region + + + + + \ No newline at end of file diff --git a/helpcenter.r7-office.ru/Web/Controls/Help/Portals/method.ascx b/helpcenter.r7-office.ru/Web/Controls/Help/Portals/method.ascx new file mode 100644 index 000000000..716500180 --- /dev/null +++ b/helpcenter.r7-office.ru/Web/Controls/Help/Portals/method.ascx @@ -0,0 +1,143 @@ +<%@ Control Language="C#" Inherits="BaseContentUserControls" %> + + + +
+ <% 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) + { %> + +

+ + <%= method.HttpMethod + " " + method.Path %> + <% if (method.Authentification) + { %> + This function requires authentication + <% } %> +

+ + <% if (!string.IsNullOrEmpty(method.Summary)) + { %> +
Description
+

<%= method.Summary %>

+ <% } %> + +
Parameters
+ <% if (method.Params.Any(x => x.Visible)) + { %> + + + + + + + + + + + + + + + + + <% foreach (var param in method.Params.OrderByDescending(x => x.Method).Where(x => x.Visible)) + { + var paramModel = ClassNamePluralizer.ToHumanName(param.Type); %> + + + + + + + <% } %> + +
NameDescriptionTypeExample
+ <%= param.Name %> +
sent in <%= param.Method %>
+
+ <%= param.Description %> + <% if (ClassNamePluralizer.IsOptional(param.Type) || param.IsOptional) + { %> +
optional
+ <% } %> +
+ <%= paramModel.Description %> + <% if (ClassNamePluralizer.IsCollection(param.Type) || paramModel.IsCollection) + { %> +
collection
+ <% } %> +
+ <% if (!string.IsNullOrEmpty(paramModel.Example)) + { %><%= paramModel.Example %><% } %> + <% if (!string.IsNullOrEmpty(paramModel.Note)) + { %> +
<%= paramModel.Note %>
+ <% } %> +
+ <% } + else + { %> +

This method doesn't have any parameters

+ <%} %> + + <%if (!string.IsNullOrEmpty(method.Remarks)) + { %> +
Remark
+

<%= method.Remarks %>

+ <% } %> + + <%if (!string.IsNullOrEmpty(method.Notes)) + { %> +
Notes
+

<%= method.Notes %>

+ <% } %> + + <%if (!string.IsNullOrEmpty(method.Example)) + { %> +
Example
+
<%= method.Example%>
+ <% } %> + +
Returns
+

<%= method.Returns %>

+ + <% if (method.Response.Any()) + { %> +
Example Response
+ <% foreach (var output in method.Response.First().Outputs) + { %> +

<%= HttpUtility.HtmlEncode(output.Key) %>

+
<%= HttpUtility.HtmlEncode(output.Value) %>
+ <% } + } %> + + <% } + else + { %> +

Method Not Found

+

You can search in documentation

+ <% } + %> +
diff --git a/helpcenter.r7-office.ru/Web/Controls/Help/Portals/section.ascx b/helpcenter.r7-office.ru/Web/Controls/Help/Portals/section.ascx index 14fff7d86..9b98e1e43 100644 --- a/helpcenter.r7-office.ru/Web/Controls/Help/Portals/section.ascx +++ b/helpcenter.r7-office.ru/Web/Controls/Help/Portals/section.ascx @@ -36,19 +36,22 @@ { %> <% if (string.IsNullOrEmpty(category)) - { %> + { %>

<%= docsSection.Name %>

<% if (!string.IsNullOrEmpty(docsSection.Summary)) - { %>

<%= docsSection.Summary %>

<% } %> + { %>

<%= docsSection.Summary %>

+ <% } %> <% if (!string.IsNullOrEmpty(docsSection.Remarks)) - { %>

<%= docsSection.Remarks %>

<% } %> + { %>

<%= docsSection.Remarks %>

+ <% } %> <% if (!string.IsNullOrEmpty(docsSection.Example)) - { %>

<%= docsSection.Example %>

<% } %> + { %>

<%= docsSection.Example %>

+ <% } %> <% } - else - { %> + else + { %>

<%= category %> @@ -57,9 +60,9 @@ - - - + + + @@ -71,7 +74,7 @@ <% 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); %>
<%= !string.IsNullOrEmpty(method.FunctionName) ? method.FunctionName : method.ShortName %> @@ -86,8 +89,8 @@
<% } - else - { + else + { %>

Section Not Found

You can search in documentation

diff --git a/helpcenter.r7-office.ru/Web/portals/Method.aspx b/helpcenter.r7-office.ru/Web/portals/Method.aspx new file mode 100644 index 000000000..132d8a75e --- /dev/null +++ b/helpcenter.r7-office.ru/Web/portals/Method.aspx @@ -0,0 +1,15 @@ +<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/PortalsList.master" %> +<%@ Register Namespace="TeamLab.Controls" Assembly="__Code" TagPrefix="cc" %> + + + + + +
">Community server
+
+ + + + +
+ \ No newline at end of file