Beispiel #1
0
        public static bool AddByAssembly(params string[] ModulePath)
        {
            if (ModulePath?.Length > 0)
            {
                Adding?.Invoke(Language["STR_LOG_CONTROLLER_INITING"], null);

                try
                {
                    for (int i = 0; i < ModulePath.Length; i++)
                    {
                        //나중에 함수 하나 만들기
                        Assembly asm = Assembly.LoadFrom(ModulePath[i]);

                        Adding?.Invoke(string.Format(Language["STR_LOG_CONTROLLER_LOADING"], ModulePath[i]), null);

                        foreach (Type type in asm.GetTypes())
                        {
                            if (type.IsImplement(ControllerType))
                            {
                                //컨트롤러 초기화
                                ((IController)Activator.CreateInstance(type)).Init(ref Language);
                                Adding?.Invoke($"[{Language["STR_SUCCESS"]}] Controller: {type.Name}", null);
                            }
                        }
                    }
                    Adding?.Invoke(string.Format(Language["STR_LOG_CONTROLLER_INITED"]), null);
                }
                catch (Exception ex) { Adding?.Invoke(Language["STR_LOG_CONTROLLER_ERROR"], ex); return(false); }
            }

            return(true);
        }
Beispiel #2
0
        //private static void InitErrorLog(Exception ex, string ModuleName) { Logger.LogSYSTEM(LogLevel.ERROR, LanguageManager.Language["STR_LOG_WEB_MODULE_ERROR"], ex, ModuleName); }

        public static bool Add(string WebPath, IRouter Module, string Name = null)
        {
            string name = Name ?? Module.GetType().Name;

            if (!Modules.ContainsKey(WebPath))
            {
                try
                {
                    Module.Attach(Language);
                    Modules.Add(WebPath, Module);
                    Adding?.Invoke(string.Format("[{0}] Router: [{1}] {2} ({3})", Language["STR_SUCCESS"], WebPath, Name, Module.GetType().Name), null);
                    return(true);
                }
                catch (Exception ex)
                {
                    Adding?.Invoke(string.Format("[{0}] Router: [{1}] {2} ({3})", Language["STR_ERROR"], WebPath, Name, Module.GetType().Name), ex);
                    return(false);
                }
            }
            else
            {
                Adding?.Invoke(string.Format("[{0}] Router: [{1}] {2} ({3})", Language["STR_EXIST"], WebPath, Name, Module.GetType().Name), null);
                return(false);
            }

            //if (Modules.ContainsKey(Path)) Modules[Path] = Module;
            //else Modules.Add(Path, Module);
        }
Beispiel #3
0
 public void Add(int n, int m)
 {
     Console.ForegroundColor = ConsoleColor.DarkRed;
     Adding?.Invoke($"You build {n} places to relax and {m} manholes.");
     Console.ResetColor();
     PlacesToRelax += n;
     Manholes      += m;
 }
Beispiel #4
0
        public static bool AddByAssembly(params string[] ModulePath)
        {
            for (int i = 0; i < ModulePath.Length; i++)
            {
                try
                {
                    if (ModulePath != null && ModulePath.Length > 0)
                    {
                        string path = ModulePath[i];
                        if (!File.Exists(path))
                        {
                            string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                            path = StringUtils.PathMaker(dir, path);
                            if (!File.Exists(path))
                            {
                                continue;
                            }
                        }
                        Adding?.Invoke(string.Format(Language["STR_LOG_WEB_ROUTER_LOADING"], ModulePath[i]), null);

                        Assembly asm = Assembly.LoadFrom(path);

                        /*
                         * IEnumerable<string> result = asm.GetTypes()
                         *  .Where(type =>
                         *  type.Namespace == NameSpace)
                         *  .Select(type => type.Name);
                         */

                        foreach (Type type in asm.GetTypes())
                        {
                            if (type.IsImplement(RouterType))
                            {
                                foreach (var attr in type.GetCustomAttributes(AttributeType))
                                {
                                    if (attr is RouterAttribute module)
                                    {
                                        if (module.AutoRegister)
                                        {
                                            try { Add(module.Path, (IRouter)Activator.CreateInstance(type), module.Name); }
                                            catch (Exception ex) { Adding?.Invoke(string.Format(Language["STR_LOG_WEB_ROUTER_ERROR"], module.Name), ex); return(false); }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    Adding?.Invoke(string.Format(Language["STR_LOG_WEB_ROUTER_LOADED"]), null);
                }
                catch (Exception ex) { Adding?.Invoke(Language["STR_LOG_WEB_ROUTER_ERROR"], ex); return(false); }
            }

            return(true);
        }
Beispiel #5
0
        public static bool AddByAssembly(params string[] ModulePath)
        {
            if (ModulePath != null && ModulePath.Length > 0)
            {
                for (int i = 0; i < ModulePath.Length; i++)
                {
                    try
                    {
                        //나중에 함수 하나 만들기
                        Assembly asm = Assembly.LoadFrom(ModulePath[i]);

                        Adding?.Invoke(string.Format(Language["STR_LOG_WEB_MIDDLEWARE_LOADING"], ModulePath[i]), null);
                        foreach (Type type in asm.GetTypes())
                        {
                            //Console.WriteLine("======");
                            //Console.WriteLine("TYPE: " + type.GetType());
                            //Console.WriteLine("NAME: " + type.Name);

                            if (type.IsImplement(MiddlwareType))
                            {
                                foreach (var attr in type.GetCustomAttributes(AttributeType))
                                {
                                    if (attr is MiddlewareAttribute module)
                                    {
                                        //Console.WriteLine("ATTR_NAME: " + mw.Name);
                                        //Console.WriteLine("ATTR_AUTO: " + mw.AutoRegister);
                                        if (module.AutoRegister)
                                        {
                                            try { Add((IMiddleware)Activator.CreateInstance(type), module.Name, module.Priority); }
                                            catch (Exception ex) { Adding(string.Format(Language["STR_LOG_WEB_MIDDLEWARE_ERROR"], type.Name), ex); return(false); }
                                            break;
                                        }
                                        else
                                        {
                                            Adding(string.Format("[Unload] WebMiddleWare: {{ {0} ({1}) }}, Priority={2}", module.Name, type.Name, module.Priority), null);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex) { Adding(Language["STR_LOG_WEB_MIDDLEWARE_ERROR"], ex); return(false); }
                }

                Adding?.Invoke(string.Format(Language["STR_LOG_WEB_MIDDLEWARE_LOADED"]), null);
            }

            return(true);
        }
Beispiel #6
0
        public static bool Add(IMiddleware MiddleWare, string Name, MiddlewarePriority Priority = MiddlewarePriority.Normal)
        {
            string name = Name == null?MiddleWare.GetType().Name : Name;

            try
            {
                MiddleWare.Attach(Language);
                if (!Middlewares.ContainsKey(Priority))
                {
                    Middlewares.Add(Priority, new List <IMiddleware>());
                }
                Middlewares[Priority].Add(MiddleWare);

                Adding?.Invoke(string.Format("[{0}] MiddleWare: {{ {1} ({2}) }}, Priority={3} }}", Language["STR_SUCCESS"], name, MiddleWare.GetType().Name, Priority), null);
                return(true);
            }
            catch (Exception ex)
            {
                Adding?.Invoke(string.Format("[{0}] MiddleWare: {{ {1} ({2}) }}, Priority={3} }} ({4})", Language["STR_ERROR"], name, MiddleWare.GetType().Name, Priority, ex.Message), null);
                return(false);
            }
        }
Beispiel #7
0
 /// <summary>Raises the <see cref="E:Adding"/> event.
 /// </summary>
 /// <param name="args">The <see cref="Dodoni.BasicComponents.Containers.ItemAddingEventArgs"/> instance containing the event data.</param>
 protected virtual void OnAdding(ItemAddingEventArgs args)
 {
     Adding?.Invoke(this, args);
 }
Beispiel #8
0
 public void Add(int n)
 {
     Adding?.Invoke($"You build {n} places to telax.");
     PlacesToRelax += n;
 }
Beispiel #9
0
 public void Add(int n)
 {
     Adding?.Invoke($"Вы добавляете в комнату {n} окон.");
     Windows += n;
 }
Beispiel #10
0
 public void Add(int n, int m)
 {
     Adding?.Invoke($"Вы добавляете в комнату {n} окон и {m} дверей.");
     Windows += n;
     Doors   += m;
 }
Beispiel #11
0
 private void Form1_Load(object sender, System.EventArgs e)
 {
     Adding.Invoke(this, e);
 }
Beispiel #12
0
 /* ----------------------------------------------------------------- */
 ///
 /// OnAdding
 ///
 /// <summary>
 /// Adding イベントを発生させます。
 /// </summary>
 ///
 /* ----------------------------------------------------------------- */
 protected virtual void OnAdding(ValueCancelEventArgs <int> e)
 => Adding?.Invoke(this, e);
Beispiel #13
0
 protected virtual void OnAdding(EventArgs ea) => Adding?.Invoke(this, ea);
Beispiel #14
0
 public void Put(int sum)
 {
     Adding?.Invoke($"На счёт добавляется {sum}"); //событие имеет те же параметры что и делегат который они представляют
     _sum += sum;
     Added?.Invoke($"На счёт пришло {sum}");
 }
Beispiel #15
0
 // Добавление средств на счёт
 public void Put(int sum)
 {
     Adding?.Invoke(this, new AccountEventArgs($"На счет добовляется: {sum}", sum));
     Sum += sum;
     Added?.Invoke(this, new AccountEventArgs($"На счет поступило: {sum}", sum));
 }