Пример #1
0
        internal static void UpdateProperties(object target, Builtin builtin, IEnumerable <string> ignoredProperties)
        {
            if (target == null || builtin == null)
            {
                return;
            }

            foreach (string propertyName in builtin.Properties.AllKeys)
            {
                //如果当前属性名为忽略属性则忽略设置
                if (ignoredProperties != null && ignoredProperties.Contains(propertyName, StringComparer.OrdinalIgnoreCase))
                {
                    continue;
                }

                try
                {
                    var propertyType = Tiandao.Common.Converter.GetMemberType(target, propertyName);
                    Tiandao.Common.Converter.SetValue(target, propertyName, builtin.Properties.GetValue(propertyName, propertyType, null));
                }
                catch (Exception ex)
                {
                    StringBuilder message = new StringBuilder();

                    message.AppendFormat("{0}[{1}]", ex.Message, ex.Source);
                    message.AppendLine();

                    if (ex.InnerException != null)
                    {
                        message.AppendFormat("\t{0}: {1}[{2}]", ex.GetType().FullName, ex.Message, ex.Source);
                        message.AppendLine();
                    }

                    message.AppendFormat("\tOccurred an exception on set '{1}' property of '{0}' builtin, it's raw value is \"{2}\", The target type of builtin is '{3}'.",
                                         builtin.ToString(),
                                         propertyName,
                                         builtin.Properties[propertyName].RawValue,
                                         target.GetType().AssemblyQualifiedName);

                    //输出错误日志
                    Tiandao.Diagnostics.Logger.Error(null, message.ToString(), ex);

                    throw new PluginException(FailureCodes.BuiltinBuildFailed, message.ToString(), ex);
                }
            }
        }
Пример #2
0
        private void ResolveBuiltinBehavior(XmlReader reader, Builtin builtin, string behaviorName)
        {
            var behavior = builtin.Behaviors.Add(behaviorName);

            for (int i = 0; i < reader.AttributeCount; i++)
            {
                reader.MoveToAttribute(i);
                behavior.Properties[reader.Name] = reader.Value;
            }

            if (reader.NodeType == XmlNodeType.Attribute)
            {
                reader.MoveToElement();
            }

            if (!reader.IsEmptyElement)
            {
                int depth = reader.Depth;

                if (reader.Read() && reader.Depth > depth)
                {
                    if (reader.NodeType == XmlNodeType.Text)
                    {
                        behavior.Text = reader.Value;
                    }
                    else if (reader.NodeType == XmlNodeType.Element)
                    {
                        throw new PluginException(string.Format("This '{0}' builtin behavior element be contants child elements in '{1}'.", behaviorName, builtin.ToString()));
                    }
                }
            }
        }
Пример #3
0
        private void ResolveExtendedElement(XmlReader reader, Builtin builtin)
        {
            if (builtin == null)
            {
                throw new ArgumentNullException("builtin");
            }

            var parts = reader.Name.Split('.');

            if (parts.Length != 2)
            {
                throw new PluginException(string.Format("Invalid '{0}' ExtendElement in '{1}'.", reader.Name, builtin.ToString()));
            }

            if (string.Equals(parts[0], builtin.BuilderName, StringComparison.OrdinalIgnoreCase))
            {
                switch (parts[1].ToLowerInvariant())
                {
                case "constructor":
                    if (builtin.BuiltinType == null)
                    {
                        throw new PluginException(string.Format("This '{0}' ExtendElement dependencied builtin-type is null.", reader.Name));
                    }

                    this.ResolveBuiltinConstructor(reader, builtin.BuiltinType.Constructor);
                    break;

                default:
                    this.ResolveBuiltinBehavior(reader, builtin, parts[1]);
                    break;
                }
            }
            else if (string.Equals(parts[0], builtin.Name, StringComparison.OrdinalIgnoreCase))
            {
                string propertyName = string.Join(".", parts, 1, parts.Length - 1);
                builtin.Properties.Set(propertyName, this.ResolveExtendedProperty(reader, builtin.Plugin, builtin.FullPath));
            }
            else
            {
                throw new PluginException(string.Format("Invalid '{0}' ExtendElement in '{1}'.", reader.Name, builtin.ToString()));
            }
        }