public App() { AssemblyInfo = new AssemblyInformation(); // Configure log4net ConfigureLog4Net(); // Handle unhandled exceptions DispatcherUnhandledException += App_DispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; // Initialize Collection MangaCacheObjects = new ObservableCollection <MangaCacheObject>(); // Create a File System Watcher for Manga Objects MangaObjectArchiveWatcher = new FileSystemWatcher(CORE.MANGA_ARCHIVE_DIRECTORY, CORE.MANGA_ARCHIVE_FILTER); MangaObjectArchiveWatcher.EnableRaisingEvents = false; // Create a File System Watcher for Manga Chapter Objects ChapterObjectArchiveWatcher = new FileSystemWatcher(CORE.CHAPTER_ARCHIVE_DIRECTORY, CORE.CHAPTER_ARCHIVE_FILTER); ChapterObjectArchiveWatcher.IncludeSubdirectories = true; ChapterObjectArchiveWatcher.EnableRaisingEvents = false; // Load UserConfig LoadUserConfig(); SerializeType = CORE.UserConfiguration.SerializeType; // Initialize the ContentDownloadManager v2 ContentDownloadManager = new ContentDownloadManager(CORE: CORE); Startup += App_Startup; Exit += App_Exit; InitializeComponent(); }
public void ResetStream(SerializeType arType) { m_nSize = 0; m_nPos = 0; m_arType = arType; m_bLittleByte = System.BitConverter.IsLittleEndian; }
public MMFManager(string fileName, Type dt, object obj, SerializeType st) { FileName = fileName; DataType = dt; SaveMMF(obj, st); }
public RabbitAdvancedBus( IConnectionConfiguration connectionConfiguration, IConnectionFactory connectionFactory, SerializeType serializeType, ISerializer serializer, IConsumerFactory consumerFactory, IEasyNetQLogger logger, Func <string> getCorrelationId, IConventions conventions, IMessageValidationStrategy messageValidationStrategy) { Preconditions.CheckNotNull(connectionConfiguration, "connectionConfiguration"); Preconditions.CheckNotNull(connectionFactory, "connectionFactory"); Preconditions.CheckNotNull(serializeType, "serializeType"); Preconditions.CheckNotNull(serializer, "serializer"); Preconditions.CheckNotNull(consumerFactory, "consumerFactory"); Preconditions.CheckNotNull(logger, "logger"); Preconditions.CheckNotNull(getCorrelationId, "getCorrelationId"); Preconditions.CheckNotNull(conventions, "conventions"); Preconditions.CheckNotNull(messageValidationStrategy, "messageValidationStrategy"); this.connectionConfiguration = connectionConfiguration; this.serializeType = serializeType; this.serializer = serializer; this.consumerFactory = consumerFactory; this.logger = logger; this.getCorrelationId = getCorrelationId; this.conventions = conventions; this.messageValidationStrategy = messageValidationStrategy; connection = new PersistentConnection(connectionFactory, logger); connection.Connected += OnConnected; connection.Disconnected += consumerFactory.ClearConsumers; connection.Disconnected += OnDisconnected; }
public CachedObject(Func <Task <object> > loader, string key, TimeSpan expireTime, SerializeType serializeType) { _loader = loader; _cacheKey = key; _expireTime = expireTime; _serializeType = serializeType; }
private static void OnNotify(object sender, SerializeType type, string file) { var arg = new SerializationNotifyEventArgs(sender, type, file); Notify?.Invoke(sender, arg); Helper.OnSerializeNotify(sender, arg); }
public RabbitBus( SerializeType serializeType, IEasyNetQLogger logger, IConventions conventions, IAdvancedBus advancedBus) { if (serializeType == null) { throw new ArgumentNullException("serializeType"); } if (logger == null) { throw new ArgumentNullException("logger"); } if (conventions == null) { throw new ArgumentNullException("conventions"); } this.serializeType = serializeType; this.logger = logger; this.conventions = conventions; this.advancedBus = advancedBus; advancedBus.Connected += OnConnected; advancedBus.Disconnected += OnDisconnected; }
public void Close() { Flush(); m_bCreate = false; m_arType = SerializeType.read; m_szFileName = string.Empty; }
/// <summary> /// 序列化指定对象 /// </summary> /// <param name="type">序列化类型</param> /// <param name="obj">需要序列化的对象</param> /// <param name="path">序列文件保存的路径</param> /// <returns>返回执行状态</returns> public static bool Serialize(SerializeType type, Object obj, string path) { bool flag = false; switch (type) { case SerializeType.Xml: flag = XmlSerialize(obj, path); break; case SerializeType.Soap: flag = SoapSerialize(obj, path); break; case SerializeType.Binary: flag = BinarySerialize(obj, path); break; default: flag = BinarySerialize(obj, path); break; } return(flag); }
public static void MainBase(string _identify) { if (IsStartBase == true) { return; } IsStartBase = true;//设置为开启 //SetUpPluginUpgrade(); IsRootMNode = HostSettingConfig.GetValue("rootmnode") == "1" ? true : false; IsDebug = HostSettingConfig.GetValue("debug") == "1" ? true : false; Identify = _identify; HostName = HostSettingConfig.GetValue("hostname"); IsCompressJson = HostSettingConfig.GetValue("compress") == "1" ? true : false; IsEncryptionJson = HostSettingConfig.GetValue("encryption") == "1" ? true : false; serializeType = (SerializeType)Convert.ToInt32(HostSettingConfig.GetValue("serializetype")); IsOverTime = HostSettingConfig.GetValue("overtime") == "1" ? true : false; OverTime = Convert.ToInt32(HostSettingConfig.GetValue("overtimetime")); IsToken = HostSettingConfig.GetValue("token") == "1" ? true : false; MongoConnStr = HostSettingConfig.GetValue("mongodb_conn"); WcfGlobal.Run(StartType.BaseService); WcfGlobal.Run(StartType.FileService); WcfGlobal.Run(StartType.HttpService); WcfGlobal.Run(StartType.SuperClient); WcfGlobal.Run(StartType.MiddlewareTask); //定时任务 CoreFrame.SSO.SsoHelper.Start(); //单点登录启动 GetAllConfig(); //获取所有配置 }
public static string SerializeToString(object data, SerializeType type) { if (data is Encoding) { return((data as Encoding).BodyName); } else if (data is Uri) { return((data as Uri).AbsolutePath); } else if (data is byte[]) { return(Settings.Encoding.GetString(data as byte[])); } else if (data is Stream) { return(new StreamReader(data as Stream).ReadToEnd()); } else { switch (type) { case SerializeType.Json: return(JsonUtils.Serialize(data)); case SerializeType.Xml: return(XmlUtils.XmlSerialize(data)); default: return(data.ToString()); } } }
/// <summary> /// 初始化 /// </summary> /// <param name="options"></param> /// <param name="defaultSerializeType"></param> public static void Initialize(Action <ConfigurationOptions> options, SerializeType defaultSerializeType = SerializeType.Json) { _options = new ConfigurationOptions(); _options.EndPoints.Clear(); options?.Invoke(_options); _defaultSerializeType = defaultSerializeType; }
/// <summary> /// Imports collection by reading its data from a <see cref="BinaryReader"/> provided. /// </summary> /// <param name="type"><see cref="SerializeType"/> type of importing collection.</param> /// <param name="br"><see cref="BinaryReader"/> to read data with.</param> public override void Import(SerializeType type, BinaryReader br) { var position = br.BaseStream.Position; var header = new SerializationHeader(); header.Read(br); if (header.ID != BinBlockID.Nikki) { throw new Exception($"Missing serialized header in the imported collection"); } if (header.Game != this.GameINT) { throw new Exception($"Stated game inside collection is {header.Game}, while should be {this.GameINT}"); } var manager = this.GetManager(header.Name); if (manager == null) { throw new Exception($"Cannot find manager named {header.Name}"); } br.BaseStream.Position = position; manager.Import(type, br); }
/// <summary> /// Deserializes file located at Resources folder. /// </summary> /// <param name="fileName">Name of input file.</param> /// <param name="serializationType">Type of serrialization.</param> /// <returns>Deserialized object if file exists or new instance if doesn't.</returns> public static T DeserializeFromResourses <T>(string fileName, SerializeType serializationType = SerializeType.Binary) where T : new() { switch (serializationType) { case SerializeType.Binary: { return(BinaryDeserializeFromResourses <T>(fileName)); } case SerializeType.Xml: { return(XmlDeserializeFromResourses <T>(fileName)); } case SerializeType.Json: { return(JsonDeserializeFromResourses <T>(fileName)); } default: { Debug.LogError("Serialization type is not found."); return(BinaryDeserializeFromResourses <T>(fileName)); } } }
/// <summary> /// 序列化 /// </summary> /// <param name="target"></param> /// <returns></returns> public static string Serialize <T>(T target, SerializeType type) where T : class { using (var ms = new MemoryStream()) { switch (type) { case SerializeType.Binary: new BinaryFormatter().Serialize(ms, target); break; case SerializeType.Json: new DataContractJsonSerializer(typeof(T)).WriteObject(ms, target); break; case SerializeType.Xml: new XmlSerializer(typeof(T)).Serialize(ms, target); break; default: throw new ArgumentException($"无效的序列化类型:{type}", nameof(type)); } ms.Seek(0, SeekOrigin.Begin); return(Convert.ToBase64String(ms.ToArray())); } }
// ******************************************************************************************** // #region SerializeMethods // /////////////////////////////////////////////////////////////////////////////////////////////// // General public methods which define path and serialization type /// <summary> /// Serializes file to Persistent Data Path. /// </summary> /// <param name="serializationType">Type of serrialization.</param> /// <param name="fileName">Name of output file.</param> /// <param name="objectToSerialize">Reference to object that should be serialized.</param> public static void SerializeToPDP <T>(T objectToSerialize, string fileName, SerializeType serializationType = SerializeType.Binary, string secureKey = "") { switch (serializationType) { case SerializeType.Binary: { BinarySerializeToPath(objectToSerialize, persistentDataPath + fileName); break; } case SerializeType.Xml: { XmlSerializeToPath(objectToSerialize, persistentDataPath + fileName); break; } case SerializeType.Json: { JsonSerializeToPath(objectToSerialize, persistentDataPath + fileName, secureKey); break; } default: { Debug.LogError("Serialization type is not found."); BinarySerializeToPath(objectToSerialize, persistentDataPath + fileName); break; } } }
// ******************************************************************************************** // #region DeserializeMethods /// <summary> /// Deserializes file located at Persistent Data Path. /// </summary> /// <param name="fileName">Name of input file.</param> /// <param name="serializationType">Type of serrialization.</param> /// <returns>Deserialized object if file exists or new instance if doesn't.</returns> public static T DeserializeFromPDP <T>(string fileName, SerializeType serializationType = SerializeType.Binary, string secureKey = "", bool logIfFileNotExists = true) where T : new() { switch (serializationType) { case SerializeType.Binary: { return(BinaryDeserializeFromPath <T>(persistentDataPath + fileName, logIfFileNotExists)); } case SerializeType.Xml: { return(XmlDeserializeFromPath <T>(persistentDataPath + fileName, logIfFileNotExists)); } case SerializeType.Json: { return(JsonDeserializeFromPath <T>(persistentDataPath + fileName, secureKey, logIfFileNotExists)); } default: { Debug.LogError("Serialization type is not found."); return(BinaryDeserializeFromPath <T>(persistentDataPath + fileName, logIfFileNotExists)); } } }
public string Serialize(IHuman[] humans, SerializeType type) { //var concreteHumans = humans as List<Human>; var serializer = SerializerFactory.Create(type); return(serializer.Serialize(humans)); }
public T Deserialize <T>(String value, SerializeType SerType) { List <Type> currentTypes = ExtensionManager.GetObjectTypes(); if (!currentTypes.Contains(typeof(T))) { currentTypes.Add(typeof(T)); } switch (SerType) { case SerializeType.JSON: return(JsonConvert.DeserializeObject <T>(value)); case SerializeType.XML: using (var stringReader = new StringReader(value)) { var reader = XmlReader.Create(stringReader); var dataContractSerializer = new DataContractSerializer(typeof(T), currentTypes); return((T)dataContractSerializer.ReadObject(reader)); } default: return(default(T)); } }
public String Serialize <T>(T value, SerializeType SerType) { List <Type> currentTypes = ExtensionManager.GetObjectTypes(); if (!currentTypes.Contains(typeof(T))) { currentTypes.Add(typeof(T)); } switch (SerType) { case SerializeType.JSON: return(JsonConvert.SerializeObject(value, Newtonsoft.Json.Formatting.Indented)); case SerializeType.XML: using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture)) { var writer = XmlWriter.Create(stringWriter, new XmlWriterSettings { Indent = true, IndentChars = "\t" }); var dataContractSerializer = new DataContractSerializer(typeof(T), currentTypes); dataContractSerializer.WriteObject(writer, value); writer.Flush(); return(stringWriter.ToString()); } default: return(value.ToString()); } }
/// <summary> /// 反序列化 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="target"></param> /// <returns></returns> public static T Derialize <T>(string target, SerializeType type) { using (var ms = new MemoryStream(Convert.FromBase64String(target))) { object result; switch (type) { case SerializeType.Binary: result = new BinaryFormatter().Deserialize(ms); break; case SerializeType.Json: result = new DataContractJsonSerializer(typeof(T)).ReadObject(ms); break; case SerializeType.Xml: result = new XmlSerializer(typeof(T)).Deserialize(ms); break; default: throw new ArgumentException($"无效的序列化类型:{type}", nameof(type)); } return((T)result); } }
public void SendMessage <T>(string qName, T msg, SerializeType type = SerializeType.Json) where T : class { if (string.IsNullOrEmpty(qName) || msg == null) { return; } var body = SerializeObject(type, msg); Action a1 = () => { using (var channel = connHelper.GetConnection().CreateModel()) { channel.QueueDeclare(qName, durable: true, false, false, null); var basicProperties = new BasicProperties { Persistent = true }; //RabbitMQ有一个默认的exchange="",此时qName即为routingKey channel.BasicPublish("", qName, basicProperties, body); } }; PolicyHelper.GetRetryTimesPolicy(3, ex => { var task = new Task(a1); TasksCache.Enqueue(task); }).Execute(() => { a1.Invoke(); }); }
/// <summary> /// 反序列化 /// </summary> /// <typeparam name="T">需要序列化的实体类型</typeparam> /// <param name="type">序列化类型</param> /// <param name="strUrl">存储地址</param> /// <returns>返回实体</returns> public static T DeSerialize <T>(SerializeType type, string strUrl) where T : class, new() { using (FileStream fs = new FileStream(strUrl, FileMode.Open)) { T model = new T(); switch (type) { case SerializeType.BinaryFormatter: { BinaryFormatter formatter = new BinaryFormatter(); model = (T)formatter.Deserialize(fs); break; } case SerializeType.Soap: { SoapFormatter formatter = new SoapFormatter(); model = (T)formatter.Deserialize(fs); break; } case SerializeType.Xml: { XmlSerializer formatter = new XmlSerializer(typeof(T)); model = (T)formatter.Deserialize(fs); break; } default: break; } return(model); } }
public void Listen <T>(string qName, Func <T, bool> allwaysRunAction, SerializeType type = SerializeType.Json) where T : class { if (allwaysRunAction == null) { return; } var listenChannel = connHelper.GetConnection().CreateModel(); listenChannel.QueueDeclare(qName, true, false, false, null); var consumer = new EventingBasicConsumer(listenChannel); consumer.Received += (model, ea) => { var message = DeSerialize <T>(type, ea.Body); if (MQConnectHelper.IsTask > 0) { Execute(listenChannel, allwaysRunAction, message, ea.DeliveryTag); } else { var task = new Task( () => { Execute(listenChannel, allwaysRunAction, message, ea.DeliveryTag, qName); }); TasksCache.Enqueue(task); } }; //公平分发,不要同一时间给一个工作者发送多于一个消息 listenChannel.BasicQos(0, 50, false); // 消费消息;false 为手动应答 listenChannel.BasicConsume(qName, false, consumer); }
public static string Serialize <T>(T value, SerializeType type) { switch (type) { case SerializeType.Xml: if (value == null) { return(string.Empty); } var xmlserializer = new XmlSerializer(typeof(T)); var stringWriter = new StringWriter(); using (var writer = XmlWriter.Create(stringWriter)) { xmlserializer.Serialize(writer, value); return(stringWriter.ToString()); } case SerializeType.Json: var result = JsonConvert.SerializeObject(value); return(result); default: return(string.Empty); } }
/// <summary> /// Object's serializing method /// </summary> /// <param name="data">Data</param> /// <param name="filename"></param> /// <param name="serializeType"></param> /// <returns></returns> public static bool Serialize(T data, string filename, SerializeType serializeType) { //try //{ switch (serializeType) { case SerializeType.BinaryFile: { SerializeInBinaryFile(data, filename); break; } case SerializeType.XmlFile: { SerializeInXmlFile(data, filename); break; } case SerializeType.JsonFile: { SerializeInJsonFile(data, filename); break; } } return(true); //} //catch(Exception ex) //{ // string str = ex.GetType().Name.ToString(); // return false; //} }
private bool ServerConfigRequestState = false; //获取服务端配置读取状态 /// <summary> /// 创建连接 /// </summary> public void CreateConnection() { IWCFHandlerService wcfHandlerService = mChannelFactory.CreateChannel(); mConn.WcfService = wcfHandlerService; string serverConfig = null; AddMessageHeader(wcfHandlerService as IContextChannel, "", (() => { mConn.ClientID = wcfHandlerService.CreateDomain(mConn.ClientName);//创建连接获取ClientID if (ServerConfigRequestState == false) { //重新获取服务端配置,如:是否压缩Json、是否加密Json serverConfig = wcfHandlerService.ServerConfig(); ServerConfigRequestState = true; } })); if (!string.IsNullOrEmpty(serverConfig)) { IsHeartbeat = serverConfig.Split(new char[] { '#' })[0] == "1" ? true : false; HeartbeatTime = Convert.ToInt32(serverConfig.Split(new char[] { '#' })[1]); IsMessage = serverConfig.Split(new char[] { '#' })[2] == "1" ? true : false; MessageTime = Convert.ToInt32(serverConfig.Split(new char[] { '#' })[3]); IsCompressJson = serverConfig.Split(new char[] { '#' })[4] == "1" ? true : false; IsEncryptionJson = serverConfig.Split(new char[] { '#' })[5] == "1" ? true : false; serializeType = (SerializeType)Convert.ToInt32(serverConfig.Split(new char[] { '#' })[6]); if (IsHeartbeat) { //开启发送心跳 if (timer == null) { StartTimer(); } else { timer.Start(); } } else { if (timer != null) { timer.Stop(); } } } if (backConfig != null) { backConfig(IsMessage, MessageTime); } //创建连接成功后回调 if (createconnAction != null) { createconnAction.BeginInvoke(null, null); } }
//--------------------------------------------------------------------- public GenericValue(SerializeType type, object val) { m_Type = type; if (val != null) { value = val; } }
public ServiceResponseData(bool IsCompress, bool IsEncrytion, SerializeType SerializeType) { _iscompressjson = IsCompress; _isencryptionjson = IsEncrytion; _serializetype = SerializeType; _listjson = new List <string>(); }
/// <summary> /// 初始化 /// </summary> /// <param name="IsCustomWcfConfig">是否自定义Wcf配置</param> /// <param name="IsCompress">是否压缩</param> /// <param name="IsEncrytion">是否加密</param> /// <param name="SerializeType">序列化方式</param> public ClientRequestData(bool IsCompress, bool IsEncrytion, SerializeType SerializeType) { _iscompressjson = IsCompress; _isencryptionjson = IsEncrytion; _serializetype = SerializeType; _listjson = new List <string>(); }
public DbConfigurationAttribute(string TableName, string KeyFieldName, string TypeFieldname, string ValueFieldName, SerializeType sType) { this.tableName = TableName; this.keyFieldName = KeyFieldName; this.typeFieldName = TypeFieldname; this.valueFieldName = ValueFieldName; this.sType = sType; }
public DbConfigurationAttribute(string TableName, SerializeType sType) { this.tableName = TableName; this.keyFieldName = "key"; this.typeFieldName = "type"; this.valueFieldName = "value"; this.sType = sType; }
protected override void GetWriteObjectData(object obj, out SerializeType objSerializeType, out DataType dataType, out uint objId) { DataNode node = obj as DataNode; if (node == null) throw new InvalidOperationException("The BinaryMetaFormatter can't serialize objects that do not derive from DataNode"); objSerializeType = null; objId = 0; dataType = node.NodeType; if (node is ObjectNode) objId = (node as ObjectNode).ObjId; else if (node is ObjectRefNode) objId = (node as ObjectRefNode).ObjRefId; }
protected override void WriteObjectBody(DataType dataType, object obj, SerializeType objSerializeType, uint objId) { if (dataType.IsPrimitiveType()) this.WritePrimitive((obj as PrimitiveNode).PrimitiveValue); else if (dataType == DataType.String) this.WriteString((obj as StringNode).StringValue); else if (dataType == DataType.Enum) this.WriteEnum(obj as EnumNode); else if (dataType == DataType.Struct) this.WriteStruct(obj as StructNode); else if (dataType == DataType.ObjectRef) this.writer.Write((obj as ObjectRefNode).ObjRefId); else if (dataType == DataType.Array) this.WriteArray(obj as ArrayNode); else if (dataType == DataType.Class) this.WriteStruct(obj as StructNode); else if (dataType == DataType.Delegate) this.WriteDelegate(obj as DelegateNode); else if (dataType.IsMemberInfoType()) this.WriteMemberInfo(obj as MemberInfoNode); }
/// <summary> /// Serializes the specified feed. /// </summary> /// <param name="feed">The feed.</param> /// <param name="type">The type.</param> /// <returns></returns> public static XmlDocument Serialize(IFeed feed, SerializeType type) { XmlDocument doc = new XmlDocument(); switch (type) { case SerializeType.Rss2: SerializeRss2(doc, (IRssFeed)feed); break; default: throw new NotImplementedException(); } return doc; }
public void Serializer_Serializes_Correctly() { var serializer = new JsonCacheSerializer(); var instance = new SerializeType { Age = 25, Birthday = new DateTime(1, 2, 3), Name = "Some Name", }; var expected = "{\"Age\":25,\"Birthday\":\"\\/Date(-62132724000000-0600)\\/\",\"Name\":\"Some Name\"}"; var actual = serializer.Serialize(instance); Assert.AreEqual(expected, actual); }
public static ISerializeObject CreateSerializer(SerializeType type, Type[] includeTypes) { switch (type) { case SerializeType.XML: return new XmlSerializerObject(includeTypes); case SerializeType.Binary: return new BinarySerializerObject(); case SerializeType.JSON: return new JSONSerializerObject(); } return null; }
public void Serializer_Serializes_Correctly() { var serializer = new XmlCacheSerializer(); var instance = new SerializeType { Age = 25, Birthday = new DateTime(1, 2, 3), Name = "Some Name", }; var expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<SerializeType xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + "<Name>Some Name</Name><Age>25</Age><Birthday>0001-02-03T00:00:00</Birthday></SerializeType>"; var actual = serializer.Serialize(instance); Assert.AreEqual(expected, actual); }
public static object Deserialize(SerializeType serType, Type type, string path) { object obj = null; switch (serType) { case SerializeType.Xml: obj = XmlDeserialize(type, path); break; case SerializeType.Soap: break; case SerializeType.Binary: obj = BinaryDeserialize(type, path); break; default: obj = BinaryDeserialize(type, path); break; } return obj; }
/// <summary> /// Serializes to string. /// </summary> /// <param name="feed">The feed.</param> /// <param name="type">The type.</param> /// <returns></returns> public static string SerializeToString(IFeed feed, SerializeType type) { return Serialize(feed, type).OuterXml; }
/// <summary> /// 初始化DataFieldAttribute。 /// </summary> public DataFieldAttribute(string DbFieldName, string DisplayName, SerializeType SerializeType = Burst.SerializeType.None) { this.DbFieldName = DbFieldName; this.SerializeType = SerializeType; this.DisplayName = DisplayName; }
/// <summary> /// 序列化指定对象 /// </summary> /// <param name="type">序列化类型</param> /// <param name="obj">需要序列化的对象</param> /// <param name="path">序列文件保存的路径</param> /// <returns>返回执行状态</returns> public static bool Serialize(SerializeType type, Object obj, string path) { bool flag = false; switch (type) { case SerializeType.Xml: flag = XmlSerialize(obj, path); break; case SerializeType.Soap: flag = SoapSerialize(obj, path); break; case SerializeType.Binary: flag = BinarySerialize(obj, path); break; default: flag = BinarySerialize(obj, path); break; } return flag; }
public AnalyzeStructInfo(JSSerializer.AnalyzeType at, string name, Type type, object v = null, JSSerializer.UnitType ut = JSSerializer.UnitType.ST_Unknown) { analyzeType = at; Name = name; this.type = type; value = v; unitType = ut; eSerialize = SerializeType.String; }
public void Alloc(JSSerializer serializer) { eSerialize = SerializeType.String; switch (analyzeType) { case JSSerializer.AnalyzeType.ArrayBegin: AllocString("ArrayBegin/" + this.Name + "/"); break; case JSSerializer.AnalyzeType.ArrayEnd: AllocString("ArrayEnd/" + this.Name + "/"); break; case JSSerializer.AnalyzeType.StructBegin: AllocString("StructBegin/" + this.Name + "/" + JSNameMgr.GetTypeFullName(this.type)); break; case JSSerializer.AnalyzeType.StructEnd: AllocString("StructEnd/" + this.Name + "/" + JSNameMgr.GetTypeFullName(this.type)); break; case JSSerializer.AnalyzeType.ListBegin: AllocString("ListBegin/" + this.Name + "/" + JSNameMgr.GetTypeFullName(typeof(List<>))); break; case JSSerializer.AnalyzeType.ListEnd: AllocString("ListEnd/" + this.Name + "/" + JSNameMgr.GetTypeFullName(typeof(List<>))); break; case JSSerializer.AnalyzeType.Unit: { var sb = new StringBuilder(); // this.value could be null Type objectType = this.type; // this.value.GetType(); if (this.unitType == JSSerializer.UnitType.ST_JavaScriptMonoBehaviour || this.unitType == JSSerializer.UnitType.ST_UnityEngineObject) { eSerialize = SerializeType.Object; if (this.unitType == JSSerializer.UnitType.ST_JavaScriptMonoBehaviour) { if (!typeof(UnityEngine.MonoBehaviour).IsAssignableFrom(objectType) || !WillTypeBeTranslatedToJavaScript(objectType)) { Debug.LogError("unitType is ST_JavaScriptMonoBehaviour, but objectType is not MonoBehaviour or not having JsType attribute."); } // if a monobehaviour is referenced // and this monobehaviour will be translated to js later // ST_MonoBehaviour // add game object var index = AllocObject(((MonoBehaviour)this.value).gameObject); // UnitType / Name / object Index / MonoBehaviour Name sb.AppendFormat("{0}/{1}/{2}/{3}", (int)this.unitType, this.Name, index, JSNameMgr.GetTypeFullName(objectType)); AllocString(sb.ToString()); } else { // UnitType / Name / object Index sb.AppendFormat("{0}/{1}/{2}", (int)this.unitType, this.Name, AllocObject((UnityEngine.Object)this.value)); AllocString(sb.ToString()); } } else { sb.AppendFormat("{0}/{1}/{2}", (int)this.unitType, this.Name, ValueToString(this.value, this.type)); AllocString(sb.ToString()); } } break; } }