Ejemplo n.º 1
0
        /// <summary>
        /// 根据插件ID查找编辑中的插件
        /// </summary>
        /// <param name="addonID">插件ID</param>
        /// <returns></returns>
        public static PaoObject GetEditiongAddonByID(string addonID)
        {
            if (RootEditingObject == null)
            {
                return(null);
            }
            PaoObject addonEditing = null;

            AddonPublic.TraverseAddon((addon) =>
            {
                if (addon is PaoObject)
                {
                    var paoObj = addon as PaoObject;
                    if (paoObj.ID == addonID)
                    {
                        addonEditing = paoObj;
                        return(false);
                    }
                }

                return(true);
            }, RootEditingObject);

            return(addonEditing);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 应用插件扩展属性
        /// </summary>
        /// <param name="dataTable">扩展数据表</param>
        /// <param name="addon">插件</param>
        public static void GetAddonExtendProperties(PaoObject addon)
        {
            if (addon == null)
            {
                return;
            }

            var keys = ConfigStoragePublic.FindConfigKeys(ExtendAddonStorageName
                                                          , (key) => {
                return(key.IndexOf(addon.ID + "&") == 0);
            });

            if (keys.IsNullOrEmpty())
            {
                return;
            }

            foreach (var key in keys)
            {
                string[] ids           = key.Split(new char[] { '&' }, 2);
                string   propertyName  = ids[1];
                var      propertyValue = ConfigStoragePublic.GetConfig(ExtendAddonStorageName, key);
                AddonPublic.SetPropertyValueByPath(addon, propertyName, propertyValue);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建默认编辑器
        /// </summary>
        /// <param name="type">类型</param>
        /// <returns>编辑器</returns>
        private static Type GetDefaultEditorType(Type type)
        {
            Type editorType;

            if (type == typeof(string))
            {
                editorType = typeof(TextEditController);
            }
            else if (type.IsEnum)
            {
                editorType = typeof(EnumEditController);
            }
            else if (type == typeof(Color))
            {
                editorType = typeof(ColorPickEditController);
            }
            else if (type == typeof(Font))
            {
                editorType = typeof(FontEditController);
            }
            else if (type == typeof(DateTime))
            {
                editorType = typeof(DateEditController);
            }
            else if (type == typeof(bool))
            {
                editorType = typeof(CheckEditController);
            }
            else if (type == typeof(Image))
            {
                editorType = typeof(ImageEditController);
            }
            else if (type.IsNumberType())
            {
                editorType = typeof(TextEditController);
            }
            else if (type == typeof(Guid))
            {
                editorType = typeof(GuidEditController);
            }
            else if (AddonPublic.IsAddonDictionaryType(type))
            {
                editorType = typeof(DictionaryEditController);
            }
            else if (AddonPublic.IsAddonListType(type))
            {
                editorType = typeof(ListEditController);
            }
            else if (AddonPublic.IsAddon(type))
            {
                editorType = typeof(ObjectPropertyEditController);
            }
            else
            {
                return(null);
            }
            return(editorType);
        }
Ejemplo n.º 4
0
 protected override T OnCreateInstance()
 {
     return((T)AddonPublic.GetPropertyValueByPath(PaoApplication.Default, PropertyPath));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 启动应用程序
        /// </summary>
        /// <param name="loadFromConfig">从配置加载</param>
        /// <param name="configFileName">配置文件名,此文件应该放于应用程序目录</param>
        /// <param name="createApplicationFunc">应用创建函数</param>
        /// <param name="applicationPrepareFunc">准备应用程序</param>
        /// <param name="overwriteConfigFile">覆盖配置文件</param>
        public static void StartApplication(bool loadFromConfig
                                            , string configFileName
                                            , Func <PaoApplication> createApplicationFunc
                                            , Action <PaoApplication> applicationPrepareFunc
                                            , bool overwriteConfigFile = false)
        {
            _AppDirectory = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            string configFilePath = Path.Combine(_AppDirectory, configFileName);

            //首先添加默认的日志记录器
            EventPublic.ClearEventProcessor();
            EventPublic.AddEventProcessor(DebugLogger.Default);
            EventPublic.AddEventProcessor(EventLogger.Default);
            PaoApplication app = null;

            TransactionPublic.Run("插件引擎启动", () => {
                TransactionPublic.Run("加载插件库", () =>
                {
                    AddonPublic.AddDirectory(AppDirectory);
                    string libPathString = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath;
                    if (!libPathString.IsNullOrEmpty())
                    {
                        string[] libPaths = libPathString.Split(';');
                        foreach (var libDir in libPaths)
                        {
                            var libPath = GetAbsolutePath(libDir);
                            AddonPublic.AddDirectory(libPath);
                        }
                    }
                    // 重建插件类型列表
                    AddonPublic.RebuildAddonTypeList();
                });

                TransactionPublic.Run("加载配置", () =>
                {
                    if (createApplicationFunc == null)
                    {
                        throw new Exception("创建配置的方法不能为空");
                    }

                    if (loadFromConfig && !File.Exists(configFilePath))
                    {
                        app = IOPublic.ReadObjectFromFile(configFilePath).As <PaoApplication>();
                    }
                    else
                    {
                        // 用应用创建函数启动应用
                        app = createApplicationFunc();
                        if (overwriteConfigFile || !File.Exists(configFilePath))
                        {
                            // 保存配置文件
                            IOPublic.WriteObjectToFile(configFilePath, app);
                        }
                    }

                    if (applicationPrepareFunc != null)
                    {
                        applicationPrepareFunc(app);
                    }
                });
            });

            app.Start();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 运行
        /// </summary>
        public void Start()
        {
            // 一个应用中只能有一个默认应用程序
            Default = this;
            TransactionPublic.Run("主应用程序", () =>
            {
                TransactionPublic.Run("应用程序初始化", () =>
                {
                    TransactionPublic.Run("准备启动", OnPreparing);

                    TransactionPublic.Run("本地配置加载", () =>
                    {
                        // 加载本地配置存储
                        if (ConfigStorageDirName.IsNotNullOrEmpty())
                        {
                            ConfigStoragePublic.LoadConfigStorages(AppPublic.GetAbsolutePath(ConfigStorageDirName));
                        }

                        // 加载Application扩展属性
                        ExtendAddonPublic.GetAddonExtendProperties(this);
                    });

                    TransactionPublic.Run("检索全局插件", () => {
                        AddonPublic.SearchRuntimeAddons(this);
                    });

                    #region 事件
                    TransactionPublic.Run("事件处理机准备", () =>
                    {
                        if (!EventProcessorList.IsNullOrEmpty())
                        {
                            EventPublic.ClearEventProcessor();
                            foreach (var EventProcessor in EventProcessorList)
                            {
                                var logObj = EventProcessor.Value;
                                EventPublic.AddEventProcessor(logObj);
                            }
                        }
                    });
                    #endregion 日志

                    #region  务器
                    TransactionPublic.Run("启动服务器列表", () =>
                    {
                        if (ServerList.IsNotNullOrEmpty())
                        {
                            foreach (var server in ServerList)
                            {
                                var serverObj = server.Value;
                                if (serverObj == null)
                                {
                                    throw new Exception("服务创建失败");
                                }
                                serverObj.Start();
                                EventPublic.Information("服务{0}启动完毕.", serverObj.ObjectToString());
                            }
                        }
                    });
                    #endregion  务
                });

                #region  序
                TransactionPublic.Run("启动程序", Run);
                #endregion  序

                TransactionPublic.Run("应用程序退出", () =>
                {
                    TransactionPublic.Run("扩展属性保存", () =>
                    {
                        // 保存本地配置存储
                        if (ConfigStorageDirName.IsNotNullOrEmpty())
                        {
                            ConfigStoragePublic.SaveConfigStorages(AppPublic.GetAbsolutePath(ConfigStorageDirName));
                        }
                    });
                });
            }, OnException);
        }