public S2CRequest(SerialFormat format, long id, object objectToSerialize) : this(format, id) { this.m_objectToSerialize = objectToSerialize; Data = objectToSerialize; ContentType = S2CContentType.Obj; }
public S2CRes(SerialFormat format, double execTime, ErrorCodes res, ICollection <object> objectsToSerialize) : this(format, execTime, res) { ContentType = S2CContentType.ListObj; //guess the content of the enumeration: if (objectsToSerialize != null) { foreach (object obj in objectsToSerialize) { if (obj is BaseEntity) { ContentType = S2CContentType.ListS2CEntity; } break; } } if (ContentType == S2CContentType.ListObj) { this.m_objectsToSerialize = objectsToSerialize; } else { //build the list of BaseEntities: List <BaseEntity> tmp = new List <BaseEntity>(); foreach (object obj in objectsToSerialize) { tmp.Add((BaseEntity)obj); } this.m_entitiesToSerialize = tmp; } Data = objectsToSerialize; }
public S2CRequest(SerialFormat format, long id, BaseEntity entityToSerialize) : this(format, id) { this.m_entityToSerialize = entityToSerialize; Data = entityToSerialize; ContentType = S2CContentType.S2CEntity; }
public S2CRequest(SerialFormat format, long id, ICollection <BaseEntity> entitiesToSerialize) : this(format, id) { this.m_entitiesToSerialize = entitiesToSerialize; Data = entitiesToSerialize; ContentType = S2CContentType.ListS2CEntity; }
public S2CRes(SerialFormat format, double execTime, ErrorCodes res, ICollection <BaseEntity> entitiesToSerialize) : this(format, execTime, res) { this.m_entitiesToSerialize = entitiesToSerialize; Data = entitiesToSerialize; ContentType = S2CContentType.ListS2CEntity; }
// constructors /// <summary> /// /// </summary> /// <param name="moduleInfo"></param> /// <param name="cryptoManager"></param> /// <param name="itemKind"></param> /// <param name="transient"></param> /// <param name="appScope"></param> /// <param name="name"></param> /// <param name="props"></param> /// <param name="data"></param> /// <param name="dataType"></param> /// <param name="serialFormat"></param> /// <param name="lifetime"></param> public ServerItem( IModuleInfo moduleInfo, ICryptoManager cryptoManager, ItemKind itemKind, bool transient, string appScope, string name, NamedValueSet props, object data, Type dataType, SerialFormat serialFormat, TimeSpan lifetime) : base(itemKind, transient, name, appScope) { _moduleInfo = moduleInfo ?? throw new ArgumentNullException(nameof(moduleInfo)); _cryptoManager = cryptoManager ?? throw new ArgumentNullException(nameof(cryptoManager)); if (dataType == null) { throw new ArgumentNullException(nameof(dataType)); } SysProps.Set(SysPropName.SAlg, (int)serialFormat); AppProps.Add(props); _data = data; _dataTypeType = dataType; DataTypeName = dataType.FullName; _lifetime = lifetime; }
public S2CRequest(SerialFormat format, long id, ICollection<object> objectsToSerialize) : this(format, id) { ContentType = S2CContentType.ListObj; //guess the content of the enumeration: if (objectsToSerialize != null) { foreach (object obj in objectsToSerialize) { if (obj is BaseEntity) ContentType = S2CContentType.ListS2CEntity; break; } } if (ContentType == S2CContentType.ListObj) this.m_objectsToSerialize = objectsToSerialize; else { //build the list of BaseEntities: List<BaseEntity> tmp = new List<BaseEntity>(); foreach (object obj in objectsToSerialize) { tmp.Add((BaseEntity)obj); } this.m_entitiesToSerialize = tmp; } Data = objectsToSerialize; }
public S2CRes(SerialFormat format, double execTime, ErrorCodes res, object objectToSerialize) : this(format, execTime, res) { this.m_objectToSerialize = objectToSerialize; Data = objectToSerialize; ContentType = S2CContentType.Obj; }
/// <summary> /// 串口发送数据处理函数 /// </summary> /// <param name="spb">串口助手对象</param> /// <param name="data">发送数据</param> /// <param name="format">发送数据格式</param> private void SerialPortDataWriteProcess(SerialPortHelper spb, string data, SerialFormat format = SerialFormat.None) { if (data == "" || !spb.IsOpen) { return; } if (format == SerialFormat.None) { format = SerialData.IsStringHex(data) ? SerialFormat.Hex : SerialFormat.String; } byte[] arrData; switch (format) { case SerialFormat.Hex: arrData = SerialData.ToHexByteArray(data); Console.WriteLine("发送数据:" + SerialData.ToHexString(arrData)); break; case SerialFormat.String: arrData = SerialData.ToByteArray(data); Console.WriteLine("发送数据:" + data); break; case SerialFormat.None: default: return; } spb.Write(arrData); }
public S2CRes(SerialFormat format, double execTime, ErrorCodes res, BaseEntity entityToSerialize) : this(format, execTime, res) { this.m_entityToSerialize = entityToSerialize; Data = entityToSerialize; ContentType = S2CContentType.S2CEntity; }
public S2CSerializer(SerialFormat format, double execTime, ErrorCodes res, int totNum) { m_isClientSide = false; m_format = format; m_execTime = execTime; m_res = res; m_totNum = totNum; }
public static S2CResListObj <string> DeserializeObjList(string content, SerialFormat format) { if (string.IsNullOrEmpty(content)) { log.Error("Content is empty"); return(null); } switch (format) { case SerialFormat.JSON: try { return(jsonUtils.ToObject <S2CResListObj <string> >(content)); } catch (Exception ex) { log.ErrorFormat("Error while parsing content {0} due to {1}", content.PrintNull(), ex.Message); return(new S2CResListObj <string>(0.0F, ErrorCodes.FAIL, new string[] { "Generic Error" }, 0)); } case SerialFormat.XML: //parse content: XElement data = ParseContent(content); if (data == null) { return(null); } //parse single elements: float execTime = -1; data.ParseNode("ExecTime", ref execTime, false); ErrorCodes status = ErrorCodes.FAIL; data.ParseNode <ErrorCodes>("Status", ref status, false); int totNum = 0; data.ParseNode("TotNum", ref totNum, false); //parse actual data depending on content type: XElement dataContent = data.GetNode("Data", false); List <string> objs = new List <string>(); List <XElement> nodes = dataContent.GetNodes("Obj", false); if (nodes != null) { foreach (XElement node in nodes) { objs.Add(node.Value); } } return(new S2CResListObj <string>(execTime, status, objs.ToArray(), totNum)); } log.Error("Unknown SerialFormat"); return(null); }
/// <summary> /// Builds the string serialization of this object depending on the given format /// </summary> /// <param name="format">serialization format</param> /// <returns>string serialization of this object if no error occurred; string.Empty otherwise</returns> public string Serialize(SerialFormat format) { switch (format) { case SerialFormat.JSON: return(jsonUtils.ToJSON(ToJSONEntity())); case SerialFormat.XML: return(ToXML(false).ToString()); default: return(string.Empty); } }
/// <summary> /// Retrieves the MIME type associated to the given format /// </summary> /// <param name="format">format which the MIME type should be taken for</param> /// <returns></returns> public static string GetMIMEType(this SerialFormat format) { switch (format) { case SerialFormat.JSON: return(JSON_MIMETYPE); case SerialFormat.HTML: return(HTML_MIMETYPE); case SerialFormat.XML: return(XML_MIMETYPE); } return(string.Empty); }
/// <summary> /// The Deserialize. /// </summary> /// <param name="fromstream">The fromstream<see cref="Stream"/>.</param> /// <param name="serialFormat">The serialFormat<see cref="SerialFormat"/>.</param> /// <returns>The <see cref="object"/>.</returns> public object Deserialize(Stream fromstream, SerialFormat serialFormat = SerialFormat.Binary) { if (serialFormat == SerialFormat.Binary) { return(this.GetBinary(fromstream)); } else if (serialFormat == SerialFormat.Json) { return(this.GetJson(fromstream)); } else { return(null); } }
/// <summary> /// The Serialize. /// </summary> /// <param name="buffer">The buffer<see cref="ISerialBuffer"/>.</param> /// <param name="offset">The offset<see cref="int"/>.</param> /// <param name="batchSize">The batchSize<see cref="int"/>.</param> /// <param name="serialFormat">The serialFormat<see cref="SerialFormat"/>.</param> /// <returns>The <see cref="int"/>.</returns> public int Serialize(ISerialBuffer buffer, int offset, int batchSize, SerialFormat serialFormat = SerialFormat.Binary) { if (serialFormat == SerialFormat.Binary) { return(this.SetBinary(buffer)); } else if (serialFormat == SerialFormat.Json) { return(this.SetJson(buffer)); } else { return(-1); } }
/// <summary> /// The Deserialize. /// </summary> /// <param name="buffer">The buffer<see cref="ISerialBuffer"/>.</param> /// <param name="serialFormat">The serialFormat<see cref="SerialFormat"/>.</param> /// <returns>The <see cref="object"/>.</returns> public object Deserialize(ISerialBuffer buffer, SerialFormat serialFormat = SerialFormat.Binary) { if (serialFormat == SerialFormat.Binary) { return(this.GetBinary(buffer)); } else if (serialFormat == SerialFormat.Json) { return(this.GetJson(buffer)); } else { return(null); } }
/// <summary> /// The Serialize. /// </summary> /// <param name="tostream">The tostream<see cref="Stream"/>.</param> /// <param name="offset">The offset<see cref="int"/>.</param> /// <param name="batchSize">The batchSize<see cref="int"/>.</param> /// <param name="serialFormat">The serialFormat<see cref="SerialFormat"/>.</param> /// <returns>The <see cref="int"/>.</returns> public int Serialize(Stream tostream, int offset, int batchSize, SerialFormat serialFormat = SerialFormat.Binary) { if (serialFormat == SerialFormat.Binary) { return(this.SetBinary(tostream)); } else if (serialFormat == SerialFormat.Json) { return(this.SetJson(tostream)); } else { return(-1); } }
///////////////////////////////////////////////////////////////////////////////////////////////////// #region DeSerialization S2CRes ///////////////////////////////////////////////////////////////////////////////////////////////////// public static S2CResBaseEntity <T> DeserializeBaseEntity <T>(string content, SerialFormat format) where T : BaseEntity, new() { if (string.IsNullOrEmpty(content)) { log.Error("Content is empty"); return(null); } switch (format) { case SerialFormat.JSON: try { return(jsonUtils.ToObject <S2CResBaseEntity <T> >(content)); } catch (Exception ex) { log.ErrorFormat("Error while parsing content {0} due to {1}", content.PrintNull(), ex.Message); return(new S2CResBaseEntity <T>(0.0F, ErrorCodes.FAIL, null)); } case SerialFormat.XML: //parse content: XElement data = ParseContent(content); if (data == null) { return(null); } //parse single elements: float execTime = -1; data.ParseNode("ExecTime", ref execTime, false); ErrorCodes status = ErrorCodes.FAIL; data.ParseNode <ErrorCodes>("Status", ref status, false); //parse actual data: XElement dataContent = data.GetNode("Data", false); T tmp = new T(); tmp.Parse((XElement)dataContent.FirstNode); return(new S2CResBaseEntity <T>(execTime, status, tmp)); } log.Error("Unknown SerialFormat"); return(null); }
/// <summary> /// Builds a new object from a string formatted in one /// of the SerialFormat enum values /// </summary> /// <param name="content"></param> /// <param name="format"></param> protected BaseEntity(string content, SerialFormat format) : base() { switch (format) { case SerialFormat.JSON: IsValid = ParseFromJson(content); break; case SerialFormat.XML: IsValid = Parse(XElement.Parse(content)); break; default: IsValid = false; break; } }
public static S2CRequestObj <string> DeserializeReqObj(string content, SerialFormat format) { if (string.IsNullOrEmpty(content)) { log.Error("Content is empty"); return(null); } switch (format) { case SerialFormat.JSON: try { return(jsonUtils.ToObject <S2CRequestObj <string> >(content)); } catch (Exception ex) { log.ErrorFormat("Error while parsing content {0} due to {1}", content.PrintNull(), ex.Message); return(new S2CRequestObj <string>(-1, null)); } case SerialFormat.XML: //parse content: XElement data = ParseContent(content); if (data == null) { return(null); } //parse single elements: long id = -1; data.ParseNode("ID", ref id, false); //parse actual data: XElement dataContent = data.GetNode("Data", false); return(new S2CRequestObj <string>(id, dataContent.Value)); } log.Error("Unknown SerialFormat"); return(null); }
/// <summary> /// 串口接收数据处理 /// </summary> /// <param name="arrData">接收数据数组</param> private void SerialPortDataReceivedProcess(object sender, byte[] arrData) { SerialPortHelper spb = (SerialPortHelper)sender; try { this.Invoke(new Action(() => { SerialFormat sf = (spb.SerialMark == "串口1") ? ComboToSerialFormat(cbReceiveFormat1) : ComboToSerialFormat(cbReceiveFormat2); if ((sf == SerialFormat.String) || ((sf == SerialFormat.None) && SerialData.IsBytesToString(arrData))) { OutputInfo(SerialData.ToString(arrData), "接收", spb.SerialMark); } else { OutputInfo(SerialData.ToHexString(arrData), "接收", spb.SerialMark); } })); } catch (Exception e) { Console.WriteLine(spb.SerialMark + ":接收数据异常," + e.Message); } }
/// <summary> /// ComboBox转SerialFormat /// </summary> /// <param name="cb"></param> /// <returns></returns> public static SerialFormat ComboToSerialFormat(ComboBox cb) { SerialFormat format = SerialFormat.None; if (cb.Items.Count == 3) { switch (cb.SelectedIndex) { case 1: format = SerialFormat.String; break; case 2: format = SerialFormat.Hex; break; case 0: default: format = SerialFormat.None; break; } } return(format); }
/// <summary> /// SerialFormat转Combo /// </summary> /// <param name="cb"></param> /// <param name="format"></param> public static void SerialFormatToCombo(ComboBox cb, SerialFormat format) { if (cb.Items.Count == 3) { switch (format) { case SerialFormat.None: cb.SelectedIndex = 0; break; case SerialFormat.Hex: cb.SelectedIndex = 2; break; case SerialFormat.String: cb.SelectedIndex = 1; break; default: cb.SelectedIndex = 0; break; } } }
private WebConnector() { m_isLogged = false; m_requestFormat = AppConfig.Current.SerialFormat; }
/// <summary> /// Builds a new object from a string formatted in one /// of the SerialFormat enum values /// </summary> /// <param name="content"></param> /// <param name="format"></param> protected SnippetComment(string content, SerialFormat format) : base(content, format) { }
/// <summary> /// Builds a new object from a string formatted in one /// of the SerialFormat enum values /// </summary> /// <param name="content"></param> /// <param name="format"></param> protected GroupUserInfo(string content, SerialFormat format) : base(content, format) { }
/// <summary> /// Builds a new object from a string formatted in one /// of the SerialFormat enum values /// </summary> /// <param name="content"></param> /// <param name="format"></param> public Tag(string content, SerialFormat format) : base(content, format) { }
public S2cWebClient(int timeout) { this.Timeout = timeout; this.AcceptType = SerialFormat.JSON; }
/// <summary> /// Builds a new object from a string formatted in one /// of the SerialFormat enum values /// </summary> /// <param name="content"></param> /// <param name="format"></param> protected OneAllToken(string content, SerialFormat format) : base(content, format) { }
//only one of these members will get a value != null: //private object m_objectToSerialize = null; //private object[] m_objectsToSerialize = null; //private BaseEntity m_entityToSerialize = null; //private BaseEntity[] m_entitiesToSerialize = null; #endregion ///////////////////////////////////////////////////////////////////////////////////////////////////// #region Constructors ///////////////////////////////////////////////////////////////////////////////////////////////////// public S2CSerializer(SerialFormat format, long id) { m_isClientSide = true; m_format = format; m_id = id; }
/// <summary> /// Builds a new object from a string formatted in one /// of the SerialFormat enum values /// </summary> /// <param name="content"></param> /// <param name="format"></param> public DefaultProperty(string content, SerialFormat format) : base(content, format) { }
/// <summary> /// Builds a new object from a string formatted in one /// of the SerialFormat enum values /// </summary> /// <param name="content"></param> /// <param name="format"></param> public SnippetBCKCollection(string content, SerialFormat format) : base(content, format) { }
/// <summary> /// Builds a new object from a string formatted in one /// of the SerialFormat enum values /// </summary> /// <param name="content"></param> /// <param name="format"></param> protected User(string content, SerialFormat format) : base(content, format) { }
/// <summary> /// Builds a new object from a string formatted in one /// of the SerialFormat enum values /// </summary> /// <param name="content"></param> /// <param name="format"></param> public SnippetProperty(string content, SerialFormat format) : base(content, format) { }
public S2CRes(SerialFormat format, double execTime, ErrorCodes res, ICollection<BaseEntity> entitiesToSerialize) : this(format, execTime, res) { this.m_entitiesToSerialize = entitiesToSerialize; Data = entitiesToSerialize; ContentType = S2CContentType.ListS2CEntity; }
public static S2CRequestListBaseEntity <T> DeserializeReqBaseEntityList <T>(string content, SerialFormat format) where T : BaseEntity, new() { if (string.IsNullOrEmpty(content)) { log.Error("Content is empty"); return(null); } switch (format) { case SerialFormat.JSON: try { return(jsonUtils.ToObject <S2CRequestListBaseEntity <T> >(content)); } catch (Exception ex) { log.ErrorFormat("Error while parsing content {0} due to {1}", content.PrintNull(), ex.Message); return(new S2CRequestListBaseEntity <T>(-1, null)); } case SerialFormat.XML: //parse content: XElement data = ParseContent(content); if (data == null) { return(null); } //parse single elements: long id = -1; data.ParseNode("ID", ref id, false); //parse actual data: XElement dataContent = data.GetNode("Data", false); IEnumerable <XElement> nodes = dataContent.Elements(); List <BaseEntity> entities = new List <BaseEntity>(); if (nodes != null) { foreach (XElement node in nodes) { T tmp = new T(); tmp.Parse(node); entities.Add(tmp); } } return(new S2CRequestListBaseEntity <T>(id, entities.ToArray())); } log.Error("Unknown SerialFormat"); return(null); }
public static S2CRes Deserialize(string content, SerialFormat format) { if (string.IsNullOrEmpty(content)) { log.Error("Content is empty"); return new S2CRes(format, -1.0, ErrorCodes.FAIL, content); } switch (format) { case SerialFormat.JSON: return jsonUtils.ToObject<S2CRes>(content); case SerialFormat.XML: //parse content: XElement data = null; try { data = XElement.Parse(content); } catch (Exception e) { log.ErrorFormat("Cannot parse XML:{0} due to {1}", content, e.Message); return null; } if (data == null) { log.ErrorFormat("Cannot parse XML:{0}", content); return null; } //parse single elements: double execTime = -1; data.ParseNode("ExecTime", ref execTime, false); ErrorCodes status = ErrorCodes.FAIL; data.ParseNode<ErrorCodes>("Status", ref status, false); S2CContentType contType = S2CContentType.Obj; data.ParseNode<S2CContentType>("ContType", ref contType, false); //parse actual data depending on content type: XElement dataContent = data.GetNode("Data", false); switch (contType) { case S2CContentType.S2CEntity: S2CRes singleEntity = new S2CRes(SerialFormat.XML, execTime, status, dataContent.ToString()); singleEntity.ContentType = S2CContentType.S2CEntity; return singleEntity; case S2CContentType.ListS2CEntity: S2CRes multEntity = new S2CRes(SerialFormat.XML, execTime, status, dataContent.ToString()); multEntity.ContentType = S2CContentType.S2CEntity; return multEntity; case S2CContentType.Obj: return new S2CRes(SerialFormat.XML, execTime, status, dataContent.Value); case S2CContentType.ListObj: List<object> objs = new List<object>(); List<XElement> nodes = dataContent.GetNodes("Obj", false); if (nodes != null) { foreach (XElement node in nodes) { objs.Add(node.Value); } } return new S2CRes(SerialFormat.XML, execTime, status, objs); } log.Error("Unknown S2CContentType"); return new S2CRes(format, -1.0, ErrorCodes.FAIL, "Unknown S2CContentType"); case SerialFormat.HTML: return new S2CRes(format, -1.0, ErrorCodes.FAIL, "Unsupported SerialFormat"); //TODO??? } log.Error("Unknown SerialFormat"); return new S2CRes(format, -1.0, ErrorCodes.FAIL, "Unknown SerialFormat"); }
public static S2CRequestListObj <string> DeserializeReqObjList(string content, SerialFormat format) { if (string.IsNullOrEmpty(content)) { log.Error("Content is empty"); return(null); } switch (format) { case SerialFormat.JSON: try { return(jsonUtils.ToObject <S2CRequestListObj <string> >(content)); } catch (Exception ex) { log.ErrorFormat("Error while parsing content {0} due to {1}", content.PrintNull(), ex.Message); return(new S2CRequestListObj <string>(-1, null)); } case SerialFormat.XML: //parse content: XElement data = ParseContent(content); if (data == null) { return(null); } //parse single elements: long id = -1; data.ParseNode("ID", ref id, false); //parse actual data depending on content type: XElement dataContent = data.GetNode("Data", false); List <string> objs = new List <string>(); List <XElement> nodes = dataContent.GetNodes("Obj", false); if (nodes != null) { foreach (XElement node in nodes) { objs.Add(node.Value); } } return(new S2CRequestListObj <string>(id, objs.ToArray())); } log.Error("Unknown SerialFormat"); return(null); }
private S2CRes(SerialFormat format, double execTime, ErrorCodes res) { Format = format; ExecTime = execTime; Status = res; }
public S2cWebClient(int timeout, SerialFormat acceptType) { this.Timeout = timeout; this.AcceptType = acceptType; }
private S2CRequest(SerialFormat format, long id) { Format = format; ID = id; }
/// <summary> /// Builds a new object from a string formatted in one /// of the SerialFormat enum values /// </summary> /// <param name="content"></param> /// <param name="format"></param> protected Group(string content, SerialFormat format) : base(content, format) { }
/// <summary> /// Builds a new object from a string formatted in one /// of the SerialFormat enum values /// </summary> /// <param name="content"></param> /// <param name="format"></param> public RankingAction(string content, SerialFormat format) : base(content, format) { }
public S2CRequest(SerialFormat format, long id, ICollection<BaseEntity> entitiesToSerialize) : this(format, id) { this.m_entitiesToSerialize = entitiesToSerialize; Data = entitiesToSerialize; ContentType = S2CContentType.ListS2CEntity; }
/// <summary> /// Builds a new object from a string formatted in one /// of the SerialFormat enum values /// </summary> /// <param name="content"></param> /// <param name="format"></param> protected Snippet(string content, SerialFormat format) : base(content, format) { IsTemporary = false; Relevance = (byte)SnippetRelevance.S2C; NumOfVisits = 1; VisitsRanking = 0; VisitsRanking = 0; NumOfCopyActions = 0; NumOfCopyEmbedActions = 0; }