private static void FreeCachedWriter(IDataWriter writer)
        {
            lock (CACHE_LOCK)
            {
                object cache;

                if (CacheMappings.TryGetValue(writer, out cache))
                {
                    CacheMappings.Remove(writer);

                    if (writer.GetType() == typeof(BinaryDataWriter))
                    {
                        Cache <BinaryDataWriter> .Release((Cache <BinaryDataWriter>) cache);
                    }
                    else if (writer.GetType() == typeof(JsonDataWriter))
                    {
                        Cache <JsonDataWriter> .Release((Cache <JsonDataWriter>) cache);
                    }
                    else
                    {
                        throw new NotImplementedException(writer.GetType().FullName);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 获取数据写入器的数据源。
        /// </summary>
        /// <param name="dataWriter">数据写入器</param>
        /// <returns>返回该数据源</returns>
        public static object GetContent(IDataWriter dataWriter)
        {
            if (dataWriter is IDirectContent directContent)
            {
                return(directContent.DirectContent);
            }

            throw new NotSupportedException(StringHelper.Format("Unable Get Content By '{0}' RW.", dataWriter.GetType().FullName));
        }
Esempio n. 3
0
        /// <summary>
        /// 获取数据写入器的数据源。
        /// </summary>
        /// <typeparam name="T">数据源类型</typeparam>
        /// <param name="dataWriter">数据写入器</param>
        /// <returns>返回该数据源</returns>
        public static T GetContent <T>(IDataWriter dataWriter)
        {
            if (dataWriter is IInitialize <T> initialize)
            {
                return(initialize.Content);
            }

            if (dataWriter is IDirectContent directContent)
            {
                return((T)directContent.DirectContent);
            }

            throw new NotSupportedException(StringHelper.Format("Unable Get Content By '{0}' RW.", dataWriter.GetType().FullName));
        }