Beispiel #1
0
        /// <summary>构造函数:TaskWorkService()</summary>
        public TaskWorkService()
        {
            // 创建对象构建器(Spring.NET)
            string springObjectFile = TasksConfigurationView.Instance.Configuration.Keys["SpringObjectFile"].Value;

            SpringObjectBuilder objectBuilder = SpringObjectBuilder.Create(TasksConfiguration.ApplicationName, springObjectFile);

            // 创建数据提供器
            this.provider = objectBuilder.GetObject <ITaskWorkProvider>(typeof(ITaskWorkProvider));

            // 创建提醒程序
            var list = TasksConfigurationView.Instance.Configuration.Notifications;

            for (var i = 0; i < list.AllKeys.Length; i++)
            {
                var type = list[list.AllKeys[i]].Value;

                if (!string.IsNullOrEmpty(type))
                {
                    var obj = KernelContext.CreateObject(type);

                    if (obj != null && obj is INotificationProvider)
                    {
                        this.notifications.Add(list.AllKeys[i], (INotificationProvider)obj);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>执行任务</summary>
        /// <param name="options"></param>
        static void RunTask(Options options)
        {
            DataDumpTask task = DataDumpConfiguration.Instance.Tasks[options.TaskName];

            if (task == null)
            {
                Console.WriteLine("task : " + options.TaskName + " is null");
            }
            else
            {
                Console.WriteLine("task : " + options.TaskName + " running...");

                IDataDumpProvider provider = (IDataDumpProvider)KernelContext.CreateObject(task.DataDumpProvider);

                provider.Init(task);

                var result = provider.Generate();

                Console.WriteLine("result => " + result);

                // 输出位置
                string path = StringHelper.NullTo(options.OutputFile, task.OutputFile);

                if (!string.IsNullOrEmpty(path))
                {
                    path = Path.Combine(KernelConfigurationView.Instance.ApplicationPathRoot, path);

                    File.WriteAllText(path, result, Encoding.UTF8);
                }
            }
        }
        /// <summary>初始化</summary>
        protected void Initialize()
        {
            // 绑定存储策略信息
            this.storageStrategy = (IStorageStrategy)KernelContext.CreateObject(this.storageSchema.StrategyClassName);

            // 绑定存储节点信息
            this.storageNodes = StorageContext.Instance.StorageNodeService.FindAllBySchemaId(storageSchema.Id);
        }
Beispiel #4
0
        /// <summary>执行</summary>
        /// <returns></returns>
        public override object Execute()
        {
            // entityClassName
            this.target = KernelContext.CreateObject(this.className);

            Type type = this.target.GetType();

            return(type.InvokeMember(this.methodName, BindingFlags.InvokeMethod, null, target, new object[] { doc }));
        }
        public void TestParseHtml()
        {
            IWidget widget = (IWidget)KernelContext.CreateObject(KernelContext.ParseObjectType(typeof(BugWidget)));

            widget.Load("{}");

            string result = widget.ParseHtml();

            Assert.IsNotNull(result);
        }
Beispiel #6
0
        /// <summary>构造函数</summary>
        public SMSService()
        {
            // 创建对象构建器(Spring.NET)
            string springObjectFile = SMSConfigurationView.Instance.Configuration.Keys["SpringObjectFile"].Value;

            SpringObjectBuilder objectBuilder = SpringObjectBuilder.Create(SMSConfiguration.ApplicationName, springObjectFile);

            this.provider = objectBuilder.GetObject <ISMSProvider>(typeof(ISMSProvider));

            this.client = (IShortMessageClientProvider)KernelContext.CreateObject(SMSConfigurationView.Instance.ClientProvider);
        }
Beispiel #7
0
        /// <summary>创建模板生成器对象 <summary>
        public static TemplateGenerator CreateObject(string taskName, string className, CodeBuilderConfiguration configuration)
        {
            TemplateGenerator template = (TemplateGenerator)KernelContext.CreateObject(className);

            if (template == null)
            {
                throw new Exception("创建[" + className + "]类型对象失败,请确认此类型是否存在.");
            }


            template.Init(taskName, configuration);

            return(template);
        }
        /// <summary>执行</summary>
        /// <returns></returns>
        public override object Execute()
        {
            this.target = KernelContext.CreateObject(this.className);

            Type type = this.target.GetType();

            // 设置映射参数
            Mapping();

            // 验证必填参数
            Validate();

            // 执行方法
            return(type.InvokeMember(this.methodName, BindingFlags.InvokeMethod, null, target, new object[] { doc }));
        }
        public void Load()
        {
            configuration = WebConfigurationView.Instance.Configuration;

            NameValueConfigurationCollection collection = configuration.Navigation;

            INavigationBuilder builder = null;

            foreach (NameValueConfigurationElement element in collection)
            {
                builder = (INavigationBuilder)KernelContext.CreateObject(element.Value);

                if (builder != null)
                {
                    list.Add(builder);
                }
            }
        }
        // -------------------------------------------------------
        // 执行方法
        // -------------------------------------------------------

        #region 属性:Invoke(string methodName, XmlDocument doc)
        /// <summary>执行方法</summary>
        /// <param name="methodName">方法名称</param>
        /// <param name="doc">Xml 文档元素</param>
        /// <param name="logger">日志对象</param>
        public static string Invoke(string methodName, XmlDocument doc, ILog logger)
        {
            IMethod method = null;

            // 应用方法信息
            ApplicationMethodInfo param = AppsContext.Instance.ApplicationMethodService.FindOneByName(methodName);

            if (param == null)
            {
                logger.Warn(string.Format(I18n.Exceptions["text_web_api_method_not_exists"], methodName));

                throw new GenericException(I18n.Exceptions["code_web_api_method_not_exists"],
                                           string.Format(I18n.Exceptions["text_web_api_method_not_exists"], methodName));
            }

            // 应用方法所属的应用信息
            ApplicationInfo application = param.Application;

            if (param.Status == 0)
            {
                throw new GenericException(I18n.Exceptions["code_web_api_method_is_disabled"],
                                           string.Format(I18n.Exceptions["text_web_api_method_is_disabled"], methodName));
            }

            if (param.EffectScope == 1)
            {
                // 允许所有人可以访问
            }
            else
            {
                // 当前用户信息
                IAccountInfo account = KernelContext.Current == null ? null : KernelContext.Current.User;

                if (param.EffectScope == 2 && account == null)
                {
                    // 需要【登录用户】以上级别权限才能调用此方法
                    throw new GenericException(I18n.Exceptions["code_web_api_method_need_elevated_privileges"],
                                               string.Format(I18n.Exceptions["text_web_api_method_need_elevated_privileges"], methodName, "登录用户"));
                }
                else if (param.EffectScope == 4 && !(AppsSecurity.IsMember(account, application.ApplicationName) || AppsSecurity.IsReviewer(account, application.ApplicationName) || AppsSecurity.IsAdministrator(account, application.ApplicationName)))
                {
                    // 需要【应用可访问成员】以上级别权限才能调用此方法
                    throw new GenericException(I18n.Exceptions["code_web_api_method_need_elevated_privileges"],
                                               string.Format(I18n.Exceptions["text_web_api_method_need_elevated_privileges"], methodName, "应用可访问成员"));
                }
                else if (param.EffectScope == 8 && !(AppsSecurity.IsReviewer(account, application.ApplicationName) || AppsSecurity.IsAdministrator(account, application.ApplicationName)))
                {
                    // 需要【应用审查员】以上级别权限才能调用此方法
                    throw new GenericException(I18n.Exceptions["code_web_api_method_need_elevated_privileges"],
                                               string.Format(I18n.Exceptions["text_web_api_method_need_elevated_privileges"], methodName, "应用审查员"));
                }
                else if (param.EffectScope == 16 && !AppsSecurity.IsAdministrator(account, application.ApplicationName))
                {
                    // 需要【应用管理员】以上级别权限才能调用此方法
                    throw new GenericException(I18n.Exceptions["code_web_api_method_need_elevated_privileges"],
                                               string.Format(I18n.Exceptions["text_web_api_method_need_elevated_privileges"], methodName, "应用管理员"));
                }
            }

            Dictionary <string, string> options = new Dictionary <string, string>();

            JsonObject optionObjects = null;

            try
            {
                optionObjects = JsonObjectConverter.Deserialize(param.Options);
            }
            catch (Exception ex)
            {
                logger.Error("methodName:" + methodName + ",options:" + param.Options);
                logger.Error(ex);
                throw;
            }

            foreach (string key in optionObjects.Keys)
            {
                if (optionObjects[key] is JsonPrimary)
                {
                    options.Add(key, ((JsonPrimary)optionObjects[key]).Value.ToString());
                }
                else if (optionObjects[key] is JsonObject)
                {
                    StringBuilder outString = new StringBuilder();

                    JsonObject obj = (JsonObject)optionObjects[key];

                    outString.Append("{");

                    foreach (string objkey in obj.Keys)
                    {
                        outString.AppendFormat("\"{0}\":\"{1}\",", objkey, ((JsonPrimary)obj[objkey]).Value.ToString());
                    }

                    outString = StringHelper.TrimEnd(outString, ",");

                    outString.Append("}");

                    options.Add(key, outString.ToString());
                }
                else if (optionObjects[key] is JsonArray)
                {
                    StringBuilder outString = new StringBuilder();

                    JsonArray list = (JsonArray)optionObjects[key];

                    outString.Append("[");

                    for (int i = 0; i < list.Count; i++)
                    {
                        if (list[i] is String || list[i] is DateTime)
                        {
                            outString.AppendFormat("\"{0}\",", list[i].ToString());
                        }
                        else
                        {
                            outString.AppendFormat("{0},", list[i].ToString());
                        }
                    }

                    outString = StringHelper.TrimEnd(outString, ",");

                    outString.Append("]");

                    options.Add(key, outString.ToString());
                }
            }

            IDictionary <string, string> types = APIsConfigurationView.Instance.Configuration.APIMethodTypes;

            if (param.Type == "generic")
            {
                method = new GenericMethod(options, doc);
            }
            else if (types.ContainsKey(param.Type))
            {
                method = (IMethod)KernelContext.CreateObject(types[param.Type], options, doc);;
            }
            ;

            if (method != null)
            {
                object result = method.Execute();

                return(result == null ? string.Empty : result.ToString());
            }

            return(string.Empty);
        }
Beispiel #11
0
        public string Generate()
        {
            StringBuilder outString = new StringBuilder();

            // 执行依赖任务
            if (!string.IsNullOrEmpty(task.Depends))
            {
                string[] depends = task.Depends.Split(',');

                foreach (string depend in depends)
                {
                    // 任务不能自身依赖 避免发生循环引用
                    if (depend == task.Name)
                    {
                        continue;
                    }

                    DataDumpTask dependTask = DataDumpConfiguration.Instance.Tasks[depend];

                    // 重写依赖任务的参数选项和输出数据库类型
                    dependTask.Options      = task.Options;
                    dependTask.OutputDbType = task.OutputDbType;

                    IDataDumpProvider dependProvider = (IDataDumpProvider)KernelContext.CreateObject(dependTask.DataDumpProvider);

                    dependProvider.Init(dependTask);

                    outString.AppendLine(dependProvider.Generate());
                }
            }

            // 执行任务
            string comment, result;

            foreach (TaskStatement statement in task.Statements)
            {
                comment = null;
                result  = null;

                if (!string.IsNullOrEmpty(statement.Description))
                {
                    string[] descriptionLines = statement.Description.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

                    foreach (string descriptionLine in descriptionLines)
                    {
                        if (!string.IsNullOrEmpty(descriptionLine.Trim()))
                        {
                            comment += "-- " + descriptionLine.Trim() + Environment.NewLine;
                        }
                    }
                }

                GenericSqlCommand command = new GenericSqlCommand(task.DataSourceName);

                string sql = statement.Sql;

                foreach (KeyValuePair <string, string> option in options)
                {
                    sql = sql.Replace("$" + option.Key + "$", option.Value);
                }

                DataTable table = command.ExecuteQueryForDataTable(sql);

                if (table.Rows.Count == 0)
                {
                    continue;
                }

                result = SqlScriptHelper.GenerateDateTableScript(task.OutputDbType, statement.DestTable, table);

                outString.Append(comment);
                outString.AppendLine(result);
            }

            return(outString.ToString());
        }
        public void TestLoad()
        {
            IWidget widget = (IWidget)KernelContext.CreateObject(KernelContext.ParseObjectType(typeof(BugWidget)));

            widget.Load("{}");
        }
Beispiel #13
0
 /// <summary>获取存储策略对象</summary>
 public IStorageStrategy GetStrategyClass()
 {
     return((IStorageStrategy)KernelContext.CreateObject(this.StrategyClassName, new object[] { this }));
 }
Beispiel #14
0
 /// <summary>获取存储适配对象</summary>
 public IStorageAdapter GetAdapterClass()
 {
     return((IStorageAdapter)KernelContext.CreateObject(this.AdapterClassName));
 }