Ejemplo n.º 1
0
        /// <summary>Initializes a new instance of the <see cref="WebServerMethod" /> class.</summary>
        /// <param name="instance">The instance.</param>
        /// <param name="method">The method.</param>
        /// <param name="path">The path.</param>
        public WebServerMethod(object instance, MethodInfo method, string path)
        {
            this.instance = instance;
            Method        = method;
            PageAttribute = GetPageAttribute(Method);

            if (PageAttribute == null)
            {
                throw new InvalidDataException($"Page attribute missing at method {Method.Name}!");
            }

            int count = Method.GetParameters().Count(p => p.ParameterType == typeof(WebData));

            if (count != 1)
            {
                throw new InvalidDataException(string.Format("Method {0} needs exact one parameter of type {1}!", Method, nameof(WebData)));
            }

            var fullPaths = new Set <string>();

            foreach (string sub in PageAttribute.GetPaths())
            {
                try { fullPaths.Add(FileSystem.Combine('/', path, sub)); }
                catch (Exception ex) { throw new InvalidDataException($"{sub} path cannot be added to method {Method.Name}", ex); }
            }
            if (fullPaths.Count == 0)
            {
                try { fullPaths.Add(FileSystem.Combine('/', path, method.Name)); }
                catch (Exception ex) { throw new InvalidDataException($"{path} path cannot be added to method {Method.Name}", ex); }
            }
            FullPaths = fullPaths;

            foreach (ParameterInfo p in method.GetParameters())
            {
                try
                {
                    if (!p.IsOptional)
                    {
                        continue;
                    }
#if NET45 || NET46 || NET47 || NETSTANDARD20
                    if (p.HasDefaultValue)
#elif NET20 || NET35 || NET40
#else
#error No code defined for the current framework or NETXX version define missing!
#endif
                    {
                        if (p.DefaultValue != null && Convert.ToInt64(p.DefaultValue) != 0)
                        {
                            Trace.TraceError("Method <red>{0}<default> Parameter <red>{1}<default> has a not null default value!", method.Name, p);
                        }
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("Invalid default value at method {0} parameter {1}!", method.Name, p), ex);
                }
            }
        }
Ejemplo n.º 2
0
        void AddBadges(Bootstrap4 bootstrap, WebPageAttribute pageAttribute)
        {
            string badgeType;

            switch (pageAttribute.AuthType)
            {
            case WebServerAuthType.Basic: badgeType = "badge-danger"; break;

            case WebServerAuthType.Session: badgeType = "badge-primary"; break;

            default: badgeType = "badge-default"; break;
            }
            bootstrap.AddHtml(Bootstrap4.GetBadge(pageAttribute.AuthType.ToString(), badgeType));
            if (pageAttribute.AuthData != null)
            {
                bootstrap.AddHtml(" ");
                bootstrap.AddHtml(Bootstrap4.GetBadge(pageAttribute.AuthData, "badge-info"));
            }
        }