コード例 #1
0
        public static void Write(IObjectSerializer serializer, object writer, object receiver,
                                 string modelName, WriteSettings settings)
        {
            ObjectInfo info = ObjectInfo.Create(receiver, modelName);

            if (info.IsObjectContext)
            {
                TkDebug.ThrowIfNoGlobalVariable();
                BaseGlobalVariable.Current.ObjectContext.Push(receiver);
            }

            foreach (var attr in info.Attributes)
            {
                SerializerUtil.WritePropertyInfo(serializer, writer,
                                                 receiver, settings, attr, null);
            }
            if (info.Content != null)
            {
                SerializerUtil.WritePropertyInfo(serializer, writer,
                                                 receiver, settings, info.Content, null);
            }
            else
            {
                SerializerUtil.WriteElements(serializer, info, writer,
                                             receiver, settings);
            }
            if (info.IsObjectContext)
            {
                BaseGlobalVariable.Current.ObjectContext.Pop();
            }
        }
コード例 #2
0
        private void InternalWriteXml(object writer, object receiver, WriteSettings settings,
                                      XElement current, string modelName)
        {
            ObjectInfo info = ObjectInfo.Create(receiver, modelName);

            if (info.IsObjectContext)
            {
                TkDebug.ThrowIfNoGlobalVariable();
                BaseGlobalVariable.Current.ObjectContext.Push(receiver);
            }

            foreach (var attr in info.Attributes)
            {
                SerializerUtil.WritePropertyInfo(this, writer, receiver, settings, attr, current);
            }
            if (info.Content != null)
            {
                SerializerUtil.WritePropertyInfo(this, writer, receiver,
                                                 settings, info.Content, current);
            }
            else
            {
                SerializerUtil.WriteChildElement(this, writer, info.Elements, settings, receiver,
                                                 (objValue, propInfo) => propInfo.GetValue(objValue), current);
            }

            if (info.IsObjectContext)
            {
                BaseGlobalVariable.Current.ObjectContext.Pop();
            }
        }
コード例 #3
0
        public void ReadObject(object reader, object receiver, string modelName,
                               ReadSettings settings, QName root, object serializerData)
        {
            DataRow    row  = reader.Convert <DataRow>();
            ObjectInfo info = ObjectInfo.Create(receiver, modelName);

            if (info.IsObjectContext)
            {
                TkDebug.ThrowIfNoGlobalVariable();
                BaseGlobalVariable.Current.ObjectContext.Push(receiver);
            }
            DataColumnCollection cols = row.Table.Columns;

            foreach (DataColumn column in cols)
            {
                string columnName = column.ColumnName;

                SerializerUtil.ReadProperty(this, reader, receiver, settings,
                                            info, columnName, modelName);
            }
            SerializerUtil.ReadObjectCallBack(receiver);
            if (info.IsObjectContext)
            {
                BaseGlobalVariable.Current.ObjectContext.Pop();
            }
        }
コード例 #4
0
        private void WriteAObject(object writer, object receiver, string modelName,
                                  WriteSettings settings, JsonTextWriter jsonWriter)
        {
            ObjectInfo info = ObjectInfo.Create(receiver, modelName);

            if (info.IsObjectContext)
            {
                TkDebug.ThrowIfNoGlobalVariable();
                BaseGlobalVariable.Current.ObjectContext.Push(receiver);
            }
            jsonWriter.WriteStartObject();
            foreach (var attr in info.Attributes)
            {
                SerializerUtil.WritePropertyInfo(this, writer, receiver, settings, attr, null);
            }

            if (info.Content != null)
            {
                SerializerUtil.WritePropertyInfo(this, writer, receiver, settings, info.Content, null);
            }
            else
            {
                SerializerUtil.WriteElements(this, info, writer, receiver, settings);
            }
            jsonWriter.WriteEndObject();
            jsonWriter.Flush();

            if (info.IsObjectContext)
            {
                BaseGlobalVariable.Current.ObjectContext.Pop();
            }
        }
コード例 #5
0
        public void WriteObject(object writer, object receiver, string modelName,
                                WriteSettings settings, QName root, object serializerData)
        {
            ObjectInfo info = ObjectInfo.Create(receiver, modelName);

            if (info.IsObjectContext)
            {
                TkDebug.ThrowIfNoGlobalVariable();
                BaseGlobalVariable.Current.ObjectContext.Push(receiver);
            }

            var elements      = info.Elements.CreateOrderPropertyInfoList();
            var writeElements = from item in elements
                                where item.IsSingle && IsSupport(item.Content.Attribute)
                                select item;

            foreach (var item in writeElements)
            {
                ObjectPropertyInfo property = item.Content;
                object             value    = property.GetValue(receiver);
                if (value == null)
                {
                    continue;
                }

                item.Content.Attribute.WriteObject(this, writer, value, settings,
                                                   item.Content, serializerData);
            }

            if (info.IsObjectContext)
            {
                BaseGlobalVariable.Current.ObjectContext.Pop();
            }
        }
コード例 #6
0
ファイル: DefaultUtil.cs プロジェクト: madiantech/tkcore
        public static string GetSimpleValue(string keyName, string defaultValue)
        {
            TkDebug.AssertArgumentNullOrEmpty(keyName, nameof(keyName), null);
            TkDebug.ThrowIfNoGlobalVariable();

            string configValue = BaseGlobalVariable.Current.DefaultValue.GetSimpleDefaultValue(keyName);

            return(configValue ?? defaultValue);
        }
コード例 #7
0
        public static T CreateInstance <T>(string factoryName, string regName) where T : class
        {
            TkDebug.AssertArgumentNullOrEmpty(factoryName, "factoryName", null);
            TkDebug.AssertArgumentNullOrEmpty(regName, "regName", null);

            TkDebug.ThrowIfNoGlobalVariable();
            BasePlugInFactory factory = BaseGlobalVariable.Current.FactoryManager.GetFactory(factoryName);

            return(factory.CreateInstance <T>(regName));
        }
コード例 #8
0
        public void ReadObject(object reader, object receiver, string modelName, ReadSettings settings,
                               QName root, object serializerData)
        {
            TkDebug.AssertArgumentNull(receiver, "receiver", this);
            TkDebug.AssertArgumentNull(settings, "settings", this);
            TkDebug.AssertArgumentNull(root, "root", this);

            XElementData currentData = reader.Convert <XElementData>();
            XElement     current     = currentData.Current;
            ObjectInfo   info        = ObjectInfo.Create(receiver, modelName);

            if (info.IsObjectContext)
            {
                TkDebug.ThrowIfNoGlobalVariable();
                BaseGlobalVariable.Current.ObjectContext.Push(receiver);
            }

            foreach (var item in info.Attributes)
            {
                item.Attribute.ReadObject(this, reader, receiver, settings, item, serializerData);
            }

            if (current.IsEmpty)
            {
                SerializerUtil.ReadObjectCallBack(receiver);
                if (info.IsObjectContext)
                {
                    BaseGlobalVariable.Current.ObjectContext.Pop();
                }
                return;
            }

            bool readElement = false;

            if (info.Content != null)
            {
                info.Content.Attribute.ReadObject(this, reader, receiver, settings,
                                                  info.Content, serializerData);
            }
            else
            {
                readElement = true;
                InternalReadElement(currentData, receiver, settings, root, info.Elements, modelName);
            }

            SerializerUtil.ReadObjectCallBack(receiver);
            if (readElement)
            {
                SerializerUtil.CheckElementRequired(info.Elements, receiver);
            }
            if (info.IsObjectContext)
            {
                BaseGlobalVariable.Current.ObjectContext.Pop();
            }
        }
コード例 #9
0
ファイル: DefaultUtil.cs プロジェクト: madiantech/tkcore
        public static object GetFactoryObject(string sectionName, string objectName)
        {
            TkDebug.AssertArgumentNullOrEmpty(sectionName, nameof(sectionName), null);
            TkDebug.AssertArgumentNullOrEmpty(objectName, nameof(objectName), null);
            TkDebug.ThrowIfNoGlobalVariable();

            object result = BaseGlobalVariable.Current.DefaultValue.GetFactoryDefaultObject(
                sectionName, objectName);

            return(result);
        }
コード例 #10
0
ファイル: TimingJob.cs プロジェクト: madiantech/tkcore
        public void Process()
        {
            if (Status == JobStatus.Running)
            {
                return;
            }

            TkDebug.ThrowIfNoGlobalVariable();
            TkTrace.LogInfo($"'{fJob}'准备启动-{DateTime.Now}");
            Status = JobStatus.Running;
            BaseGlobalVariable.Current.BeginInvoke(EndProcess, fAction, null, null);
        }
コード例 #11
0
ファイル: FileUtil.cs プロジェクト: madiantech/tkcore
        public static void WriteFileUseWorkThread(string fileName, string content)
        {
            TkDebug.ThrowIfNoAppSetting();
            if (!BaseAppSetting.Current.UseWorkThread)
            {
                return;
            }

            TkDebug.ThrowIfNoGlobalVariable();

            BaseGlobalVariable.Current.BeginInvoke(new Action <string, string>(FileUtil.VerifySaveFile),
                                                   fileName, content);
        }
コード例 #12
0
ファイル: ObjectUtil_Type.cs プロジェクト: madiantech/tkcore
        public static Type GetRegType(string regName)
        {
            TkDebug.AssertArgumentNullOrEmpty(regName, "regName", null);

            TkDebug.ThrowIfNoGlobalVariable();
            RegTypeFactory factory = BaseGlobalVariable.Current.FactoryManager.
                                     GetCodeFactory(RegTypeFactory.REG_NAME).Convert <RegTypeFactory>();
            Type type = factory.GetType(regName);

            TkDebug.AssertNotNull(type, string.Format(ObjectUtil.SysCulture,
                                                      "没有找到注册名为{0}的注册类型", regName), null);

            return(type);
        }
コード例 #13
0
        private void AddPlugInXmlItem(IXmlPlugInItem item, string fileName)
        {
            Type baseClassType = GetBaseClassType(item.BaseClass);

            if (Contains(item.RegName))
            {
                TkDebug.ThrowIfNoGlobalVariable();
                BaseGlobalVariable.Current.AddXmlError(item.RegName, fileName, PlugInErrorType.Duplicate);
            }
            else
            {
                TkTrace.LogInfo($"工厂[{Description}]添加注册名为{item.RegName}的插件");
                fXmlPlugIns.Add(item.RegName, new XmlRegItem(item.RegName, item, baseClassType, fileName));
                Add(item.RegName, item, baseClassType);
            }
        }
コード例 #14
0
ファイル: ExceptionUtil.cs プロジェクト: madiantech/tkcore
        internal static void HandleStartExecption(string startName, Type errorType, Exception ex)
        {
            string type = errorType != null?errorType.ToString() : string.Empty;

            ExceptionData exData = new ExceptionData(null, type, null, ex);

            TkDebug.ThrowIfNoAppSetting();
            if (!BaseAppSetting.Current.UseWorkThread)
            {
                return;
            }

            TkDebug.ThrowIfNoGlobalVariable();
            string   fileName = WebAppSetting.WebCurrent.GetStartLogName(startName, exData.Exception);
            string   content  = exData.WriteXml();
            Encoding encoding = WriteSettings.Default.Encoding;

            SaveFile(fileName, content, encoding);
            //BaseGlobalVariable.Current.BeginInvoke(new Action<string, string, Encoding>(SaveFile),
            //    fileName, content, encoding);
        }
コード例 #15
0
ファイル: ExceptionUtil.cs プロジェクト: madiantech/tkcore
        public static string LogException(ExceptionData logData)
        {
            if (logData == null)
            {
                return(null);
            }

            TkDebug.ThrowIfNoAppSetting();
            if (!BaseAppSetting.Current.UseWorkThread)
            {
                return(null);
            }

            TkDebug.ThrowIfNoGlobalVariable();
            string   fileName = WebAppSetting.WebCurrent.GetExceptionLogName(logData.Exception);
            string   content  = logData.WriteXml();
            Encoding encoding = BaseAppSetting.Current.WriteSettings.Encoding;

            BaseGlobalVariable.Current.BeginInvoke(new Action <string, string, Encoding>(SaveFile),
                                                   fileName, content, encoding);

            return(fileName);
        }
コード例 #16
0
        public void WriteObject(object writer, object receiver, string modelName,
                                WriteSettings settings, QName root, object serializerData)
        {
            XmlWriter xmlWriter   = writer.Convert <XmlWriter>();
            var       prefixTable = serializerData.Convert <PrefixTable>();

            WriteStartElement(xmlWriter, root, prefixTable);
            ObjectInfo info = ObjectInfo.Create(receiver, modelName);

            if (info.IsObjectContext)
            {
                TkDebug.ThrowIfNoGlobalVariable();
                BaseGlobalVariable.Current.ObjectContext.Push(receiver);
            }

            foreach (var attr in info.Attributes)
            {
                SerializerUtil.WritePropertyInfo(this, writer, receiver,
                                                 settings, attr, prefixTable);
            }
            if (info.Content != null)
            {
                SerializerUtil.WritePropertyInfo(this, writer, receiver,
                                                 settings, info.Content, prefixTable);
            }
            else
            {
                SerializerUtil.WriteChildElement(this, writer, info.Elements, settings, receiver,
                                                 (objValue, propInfo) => propInfo.GetValue(objValue), prefixTable);
            }

            if (info.IsObjectContext)
            {
                BaseGlobalVariable.Current.ObjectContext.Pop();
            }
            xmlWriter.WriteEndElement();
        }
コード例 #17
0
        private void InternalRead(JsonTextReader reader, object receiver, string modelName, ReadSettings settings)
        {
            ObjectInfo info = ObjectInfo.Create(receiver, modelName);

            if (info.IsObjectContext)
            {
                TkDebug.ThrowIfNoGlobalVariable();
                BaseGlobalVariable.Current.ObjectContext.Push(receiver);
            }

            bool readElement = false;

            while (reader.Read())
            {
                if (reader.TokenType == JsonToken.EndObject)
                {
                    break;
                }

                AssertReadState(reader, JsonToken.PropertyName, null);
                string localName = reader.Value.Convert <string>();

                ObjectPropertyInfo property = info.GetAttribute(localName);
                if (property != null)
                {
                    property.Attribute.ReadObject(this, reader, receiver, settings, property, null);
                }
                else
                {
                    property = info.Elements[localName];
                    if (property != null)
                    {
                        readElement = true;
                        property.Attribute.ReadObject(this, reader, receiver, settings, property, null);
                    }
                    else
                    {
                        if (localName == CONTENT_NAME && info.Content != null)
                        {
                            property = info.Content;
                            property.Attribute.ReadObject(this, reader, receiver, settings, property, null);
                        }
                        else
                        {
                            property = SerializerUtil.CustomRead(receiver, localName, modelName, () => null);
                            if (property != null)
                            {
                                property.Attribute.ReadObject(this, reader, receiver, settings, property, null);
                            }
                            else
                            {
                                SkipProperty(reader);
                            }
                        }
                    }
                }
            }
            SerializerUtil.ReadObjectCallBack(receiver);

            if (readElement)
            {
                SerializerUtil.CheckElementRequired(info.Elements, receiver);
            }
            if (info.IsObjectContext)
            {
                BaseGlobalVariable.Current.ObjectContext.Pop();
            }
        }
コード例 #18
0
        public static string ResolveUrl(string url)
        {
            TkDebug.ThrowIfNoGlobalVariable();

            return(BaseGlobalVariable.Current.ResolveUrl(url));
        }