Пример #1
0
        /// <summary>
        /// Processes the built in feature.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="runtimeContext">The runtime context.</param>
        /// <param name="isLocalhost">if set to <c>true</c> [is localhost].</param>
        /// <param name="contentType">Type of the content.</param>
        /// <returns></returns>
        protected virtual object ProcessBuiltInFeature(HttpApiContextContainer <TRequest, TResponse> context, RuntimeContext runtimeContext, bool isLocalhost, out string contentType)
        {
            object result = null;

            contentType = HttpConstants.ContentType.Json;

            switch (runtimeContext?.ResourceName.SafeToLower())
            {
            case "server":
                result = Framework.AboutService();
                break;

            case "psk":    //public secured key
                result = Framework.AboutService();
                break;

            case "configuration":
                result = isLocalhost ? Framework.ConfigurationValues : localhostTip as object;
                break;

            case "machine":
                result = SystemManagementExtension.GetMachineHealth();
                break;

            case "cache":
                result = CacheRealm.GetSummary();
                break;

            case "clearmemorycache":
                if (isLocalhost)
                {
                    CacheRealm.ClearAll();
                    result = "Done.";
                }
                else
                {
                    result = "This API is available at localhost machine.";
                }
                break;

            case "gravity":
                result =     //Gravity.GravityShell.Current?.Info;
                         "<Retired>";
                break;

            case "i18n":
                result = Framework.GetGlobalResourceAvailableCultureInfo() ?? new Collection <CultureInfo>();
                break;

            case "mirror":
                var apiContext = ContextHelper.ApiContext;
                var headers    = new Dictionary <string, string>();

                foreach (var key in context.RequestAllHeaderKeys)
                {
                    headers.Add(key, context.TryGetRequestHeader(key));
                }

                result = new
                {
                    RawUrl      = context.RawUrl,
                    HttpMethod  = context.HttpMethod,
                    Headers     = headers,
                    UserAgent   = apiContext.UserAgent,
                    IpAddress   = apiContext.IpAddress,
                    CultureCode = apiContext.CultureCode
                };
                break;

            case "assemblyhash":
                result = EnvironmentCore.GetAssemblyHash();
                break;

            case "dll":
                var dllName = context.QueryString.Get("name");
                if (!string.IsNullOrWhiteSpace(dllName) && context.HttpMethod.MeaningfulEquals(HttpConstants.HttpMethod.Post, StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        var dllPath = Path.Combine(EnvironmentCore.ApplicationBaseDirectory, dllName + ".dll");
                        if (File.Exists(dllPath))
                        {
                            result      = File.ReadAllBytes(dllPath);
                            contentType = HttpConstants.ContentType.BinaryDefault;
                        }
                    }
                    catch { }
                }
                break;

            default:
                break;
            }

            return(result);
        }