Example #1
0
 /// <summary>
 /// Checks web request method type
 /// </summary>
 public static bool IsMethod(string method, DefaultMethods methodType)
 {
     if (method == null) return false;
     string t = methodType.ToString().ToLower();
     if (method.Trim().ToLower() == t)
         return true;
     else
         return false;
 }
Example #2
0
 /// <inheritdoc cref="ISerializeObjectAsync.SerializeAsync(Stream, object, Type, CancellationToken)"/>
 public static ValueTask SerializeAsync(this ISerializeObject serializer, Stream target, object?item, Type type, CancellationToken cancellationToken = default)
 {
     if (serializer is null)
     {
         throw new ArgumentNullException(nameof(serializer));
     }
     return(serializer is ISerializeObjectAsync s
                         ? s.SerializeAsync(target, item, type, cancellationToken)
                         : DefaultMethods.SerializeAsync(serializer, target, item, type));
 }
Example #3
0
 /// <inheritdoc cref="ISerializeAsync.SerializeAsync{T}(Stream, T, CancellationToken)"/>
 public static ValueTask SerializeAsync <T>(this ISerialize serializer, Stream target, T item, CancellationToken cancellationToken = default)
 {
     if (serializer is null)
     {
         throw new ArgumentNullException(nameof(serializer));
     }
     return(serializer is ISerializeAsync s
                         ? s.SerializeAsync(target, item, cancellationToken)
                         : DefaultMethods.SerializeAsync(serializer, target, item));
 }
Example #4
0
 /// <inheritdoc cref="IDeserializeObjectAsync.DeserializeAsync(Stream, Type, CancellationToken)" />
 public static ValueTask <object?> DeserializeAsync(this IDeserializeObject deserializer, Stream source, Type type, CancellationToken cancellationToken = default)
 {
     if (deserializer is null)
     {
         throw new ArgumentNullException(nameof(deserializer));
     }
     return(deserializer is IDeserializeObjectAsync d
                         ? d.DeserializeAsync(source, type, cancellationToken)
                         : DefaultMethods.DeserializeAsync(deserializer, source, type));
 }
Example #5
0
 /// <inheritdoc cref="IDeserializeAsync{T}.DeserializeAsync(Stream, CancellationToken)"/>
 public static ValueTask <T> DeserializeAsync <T>(this IDeserialize <T> deserializer, Stream source, CancellationToken cancellationToken = default)
 {
     if (deserializer is null)
     {
         throw new ArgumentNullException(nameof(deserializer));
     }
     return(deserializer is IDeserializeAsync <T> d
                         ? d.DeserializeAsync(source, cancellationToken)
                         : DefaultMethods.DeserializeAsync(deserializer, source));
 }
Example #6
0
        /// <summary>
        /// Checks web request method type
        /// </summary>
        public static bool IsMethod(string method, DefaultMethods methodType)
        {
            if (method == null)
            {
                return(false);
            }
            string t = methodType.ToString().ToLower();

            if (method.Trim().ToLower() == t)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #7
0
        public static string ValidateMethod(string method, DefaultMethods defaultMethod)
        {
            if (method == null)
            {
                return(method);
            }
            string testMethod = method.Trim().ToUpper();

            if (testMethod == GET)
            {
                return(method);
            }
            else if (testMethod == POST)
            {
                return(method);
            }
            else if (testMethod == PUT)
            {
                return(method);
            }
            else if (testMethod == DELETE)
            {
                return(method);
            }
            else if (testMethod == TRACE)
            {
                return(method);
            }
            else if (testMethod == CONNECT)
            {
                return(method);
            }
            else if (testMethod == OPTIONS)
            {
                return(method);
            }
            else
            {
                return(defaultMethod.ToString());
            }
        }
Example #8
0
        /// <summary>
        /// Detects method by starting characters
        /// </summary>
        public static string DetectMethod(string method, DefaultMethods defaultMethods)
        {
            if (method == null)
            {
                return(method);
            }
            string testMethod = method.Trim().ToUpper();

            if (GET.StartsWith(testMethod))
            {
                return(GET);
            }
            else if (POST.StartsWith(testMethod))
            {
                return(POST);
            }
            else if (PUT.StartsWith(testMethod))
            {
                return(PUT);
            }
            else if (DELETE.StartsWith(testMethod))
            {
                return(DELETE);
            }
            else if (TRACE.StartsWith(testMethod))
            {
                return(TRACE);
            }
            else if (CONNECT.StartsWith(testMethod))
            {
                return(CONNECT);
            }
            else if (OPTIONS.StartsWith(testMethod))
            {
                return(OPTIONS);
            }
            else
            {
                return(defaultMethods.ToString());
            }
        }
Example #9
0
        /// <summary>
        /// Detects method by starting characters
        /// </summary>
        public static string DetectMethod(string method, DefaultMethods defaultMethods)
        {
            if (method == null) return method;
            string testMethod = method.Trim().ToUpper();

            if (GET.StartsWith(testMethod))
                return GET;
            else if (POST.StartsWith(testMethod))
                return POST;
            else if (PUT.StartsWith(testMethod))
                return PUT;
            else if (DELETE.StartsWith(testMethod))
                return DELETE;
            else if (TRACE.StartsWith(testMethod))
                return TRACE;
            else if (CONNECT.StartsWith(testMethod))
                return CONNECT;
            else if (OPTIONS.StartsWith(testMethod))
                return OPTIONS;
            else
                return defaultMethods.ToString();
        }
Example #10
0
		public static string ValidateMethod(string method, DefaultMethods defaultMethod)
		{
			if (method == null) return method;
			string testMethod = method.Trim().ToUpper();

			if (testMethod == GET)
				return method;
			else if (testMethod == POST)
				return method;
			else if (testMethod == PUT)
				return method;
			else if (testMethod == DELETE)
				return method;
			else if (testMethod == TRACE)
				return method;
			else if (testMethod == CONNECT)
				return method;
			else if (testMethod == OPTIONS)
				return method;
			else
				return defaultMethod.ToString();
		}
Example #11
0
        public ScriptContext Init()
        {
            if (HasInit)
            {
                return(this);
            }
            HasInit = true;

            if (InsertScriptMethods.Count > 0)
            {
                ScriptMethods.InsertRange(0, InsertScriptMethods);
            }
            if (InsertScriptBlocks.Count > 0)
            {
                ScriptBlocks.InsertRange(0, InsertScriptBlocks);
            }
            if (InsertPlugins.Count > 0)
            {
                Plugins.InsertRange(0, InsertPlugins);
            }

            foreach (var assembly in ScanAssemblies.Safe())
            {
                foreach (var type in assembly.GetTypes())
                {
                    if (typeof(IScriptPlugin).IsAssignableFrom(type))
                    {
                        if (Plugins.All(x => x.GetType() != type))
                        {
                            Container.AddSingleton(type);
                            var plugin = (IScriptPlugin)Container.Resolve(type);
                            Plugins.Add(plugin);
                        }
                    }
                }
            }

            Args[ScriptConstants.Debug] = DebugMode;

            Container.AddSingleton(() => this);
            Container.AddSingleton(() => Pages);

            var beforePlugins = Plugins.OfType <IScriptPluginBefore>();

            foreach (var plugin in beforePlugins)
            {
                plugin.BeforePluginsLoaded(this);
            }
            foreach (var plugin in Plugins)
            {
                plugin.Register(this);
            }

            OnAfterPlugins?.Invoke(this);

            foreach (var type in ScanTypes)
            {
                ScanType(type);
            }

            foreach (var assembly in ScanAssemblies.Safe())
            {
                foreach (var type in assembly.GetTypes())
                {
                    ScanType(type);
                }
            }

            foreach (var method in ScriptMethods)
            {
                InitMethod(method);
            }

            foreach (var block in ScriptBlocks)
            {
                InitBlock(block);
                blocksMap[block.Name] = block;
            }

            ScriptNamespaces = ScriptNamespaces.Distinct().ToList();

            var allTypes = new List <Type>(ScriptTypes);

            foreach (var asm in ScriptAssemblies)
            {
                allTypes.AddRange(asm.GetTypes());
            }

            foreach (var type in allTypes)
            {
                if (!ScriptTypeNameMap.ContainsKey(type.Name))
                {
                    ScriptTypeNameMap[type.Name] = type;
                }

                var qualifiedName = DefaultMethods.typeQualifiedName(type);
                if (!ScriptTypeQualifiedNameMap.ContainsKey(qualifiedName))
                {
                    ScriptTypeQualifiedNameMap[qualifiedName] = type;
                }
            }

            var afterPlugins = Plugins.OfType <IScriptPluginAfter>();

            foreach (var plugin in afterPlugins)
            {
                plugin.AfterPluginsLoaded(this);
            }

            return(this);
        }