public static ComplexType ParseComplexType(this XmlNodeReader reader) { ComplexType newComplexType = new ComplexType(); XmlReader subtree = reader.ReadSubtree(); while (subtree.Read()) { if (subtree.NodeType == XmlNodeType.Element) { if (subtree.Name.Equals("xsd:element")) { Element element = subtree.ParseElement(); newComplexType.Items.Add(element); //Console.WriteLine(element.Name); } } } if (reader.MoveToAttribute("name")) { newComplexType.Name = reader.ReadContentAsString(); } return(newComplexType); }
/// <summary> /// Get latest GateRecords for a user. /// </summary> /// <param name="iUserID">ID of the user.</param> /// <param name="bFilterNotUsed">Get only records created by the current device mapping.</param> /// <returns>List of XmlGateMessge representations.</returns> public List <GateMessage> GetLatestGateRecords(int iUserID, bool bFilterNotUsed) { List <GateMessage> retMessages = new List <GateMessage>(); // Call Directory WebService GetLatestGateRecords XmlNode xmlResponse = m_Directory.GetLatestGateRecords(m_strSessionID, m_iApplicationID, iUserID, bFilterNotUsed); // Check Repsone for errors. CheckError(xmlResponse); // Deserialize the result into XmlGateMessage using (XmlReader reader = new XmlNodeReader(xmlResponse)) { while (reader.Read()) { // Found a new gateMessage node to deserialize. if (reader.Name == "gateMessage") { XmlSerializer serializer = new XmlSerializer(typeof(GateMessage)); // Add gateMessage representation to return list. retMessages.Add((GateMessage)serializer.Deserialize(reader.ReadSubtree())); } } } return(retMessages); }
/// <summary> /// Get track info for a list of users. /// </summary> /// <param name="userIDs">Array of user id's for which TrackInfo's should be returned.</param> /// <param name="dtUtcStart">Start UTC time stamp</param> /// <param name="dtUtcEnd">End UTC time stamp</param> /// <returns>List of XmlTrackInfo representations.</returns> public List <TrackInfo> GetTracksByUsers(int[] userIDs, DateTime dtUtcStart, DateTime dtUtcEnd) { List <TrackInfo> retTracks = new List <TrackInfo>(); // Call Track WebService GetTracksByUsers XmlNode xmlResponse = m_Tracks.GetTracksByUsers(m_strSessionID, m_iApplicationID, userIDs, dtUtcStart, dtUtcEnd); // Check response for errors. CheckError(xmlResponse); // Deserialize the result into XmlTrackInfo representations. using (XmlReader reader = new XmlNodeReader(xmlResponse)) { while (reader.Read()) { // Found a new trackInfo node to deserialize. if (reader.Name == "trackInfo") { XmlSerializer serializer = new XmlSerializer(typeof(TrackInfo)); // Add the XmlTrackInfo representation to return list. retTracks.Add((TrackInfo)serializer.Deserialize(reader.ReadSubtree())); } } } return(retTracks); }
/// <summary> /// Get all views. /// </summary> /// <returns>List of XmlView representations.</returns> public List <View> GetViews() { List <View> retViews = new List <View>(); // Call Directory WebService GetViews XmlNode xmlResponse = m_Directory.GetViews(m_strSessionID, m_iApplicationID); // Check response for errors. CheckError(xmlResponse); // Desserialize the result into XmlViews using (XmlReader reader = new XmlNodeReader(xmlResponse)) { while (reader.Read()) { // Found a new view node to desserialize. if (reader.Name == "view") { XmlSerializer serializer = new XmlSerializer(typeof(View)); // Add view repsentation to return list. retViews.Add((View)serializer.Deserialize(reader.ReadSubtree())); } } } return(retViews); }
/// <summary> /// Return <see cref="Trip">Trips</see> for the given user and timespan. /// /// The <see cref="Trip">Trips</see> returned are splitted based by <see cref="XmlFatPoint" /> and <see cref="TrackInfo" /> data. /// </summary> /// <param name="iUserID">DB id of the user for which to get trips.</param> /// <param name="dtUtcStart">Start UTC date and time.</param> /// <param name="dtUtcEnd">End UTC date and time.</param> /// <returns></returns> public List <Trip> GetTripsByUser(int iUserID, DateTime dtUtcStart, DateTime dtUtcEnd) { List <Trip> retTrips = new List <Trip>(); // Call Track WebService GetTripsByUser XmlNode xmlResponse = m_Tracks.GetTripsByUser(m_strSessionID, m_iApplicationID, iUserID, dtUtcStart, dtUtcEnd); // Check response for errors. CheckError(xmlResponse); // Deserialize the result into XmlTrip representations. using (XmlReader reader = new XmlNodeReader(xmlResponse)) { XmlSerializer serializer = new XmlSerializer(typeof(Trip)); while (reader.Read()) { // Found a new trip node to deserialize. if (reader.Name == "trip") { Trip trip = (Trip)serializer.Deserialize(reader.ReadSubtree()); retTrips.Add(trip); } } } return(retTrips); }
/// <summary> /// Get users for a given user template ID. /// </summary> /// <param name="iUserTemplateID">IDs of user template.</param> /// <returns>List of XmlUser representations.</returns> public List <User> GetUsersInUserTemplate(int iUserTemplateID) { List <User> retUsers = new List <User>(); XmlNode xmlResponse = m_Directory.GetUsersInUserTemplate(m_strSessionID, m_iApplicationID, iUserTemplateID); // Check response for errors. CheckError(xmlResponse); // Desserialize the result into XmlUsers using (XmlReader reader = new XmlNodeReader(xmlResponse)) { while (reader.Read()) { // Found a new user node to deserialize. if (reader.Name == "user") { XmlSerializer serializer = new XmlSerializer(typeof(User)); // Add user representation to return list. retUsers.Add((User)serializer.Deserialize(reader.ReadSubtree())); } } } return(retUsers); }
private TItemInfo CreateItemInfo <TItemInfo>() where TItemInfo : WsItem { XmlReader subReader = _xmlReader.ReadSubtree(); DataContractSerializer serializer = new DataContractSerializer(typeof(TItemInfo)); TItemInfo item = (TItemInfo)serializer.ReadObject(subReader); item.Init(_apiClient, _folderPath.IsPrivate); _xmlReader.Read(); return(item); }
/// <summary> /// Get users for a given group with optional filtering by view. /// </summary> /// <param name="strGroupName">Name of group for which to receive users from.</param> /// <param name="iViewID">ID of the view to filter by.</param> /// <returns>List of XmlUser representations.</returns> public List <User> GetUsers(string strGroupName, int iViewID) { List <User> retUsers = new List <User>(); // Call the Directory WebService GetUsersInGroup XmlNode xmlResponse = m_Directory.GetUsersInGroup(m_strSessionID, m_iApplicationID, strGroupName, iViewID); // Check response for errors. CheckError(xmlResponse); // Desserialize the result into XmlUsers using (XmlReader reader = new XmlNodeReader(xmlResponse)) { while (reader.Read()) { // Found a new user node to deserialize. if (reader.Name == "user") { var serializer = new XmlSerializer(typeof(User)); serializer.UnknownElement += (sender, args) => { if (args.Element.Name.Equals("dctCustomFieldsValue", StringComparison.InvariantCultureIgnoreCase)) { foreach (XmlNode node in args.Element.ChildNodes) { if (node.ChildNodes.Count > 1) { var key = node.ChildNodes[0].InnerText; var value = node.ChildNodes[1].InnerText; ((User)args.ObjectBeingDeserialized).CustomFields[key] = value; } } } }; // Add user representation to return list. retUsers.Add((User)serializer.Deserialize(reader.ReadSubtree())); } } } return(retUsers); }
/// <summary> /// Get all gate messages for a given track info. /// </summary> /// <param name="iTrackInfoID">ID of the track info for which gate messages should be returned.</param> /// <param name="dtUtcStart">UTC start time stamp.</param> /// <param name="dtUtcEnd">UTC end time stamp.</param> /// <param name="iStartIndex">Start index.</param> /// <param name="iStopIndex">End index.</param> /// <param name="bFilterInvalid">Filter gateMessages with track points marked as invalid.</param> /// <param name="fieldNames">string array of field names. E.g {"Speed", "SOS", "Engine on", "Fuel level"}</param> /// <returns>List of XmlGateMessage representations.</returns> public List <GateMessage> GetGateMessageByTrackInfoId(int iTrackInfoID, DateTime dtUtcStart, DateTime dtUtcEnd, int iStartIndex, int iStopIndex, bool bFilterInvalid, string[] fieldNames) { List <GateMessage> retMessages = new List <GateMessage>(); // Call Directory WebService GetGateMessagesByTrackInfoId XmlNode xmlResponse = m_Directory.GetGateMessagesByTrackInfoId( m_strSessionID, m_iApplicationID, iTrackInfoID, dtUtcStart, dtUtcEnd, iStartIndex, iStopIndex, bFilterInvalid, fieldNames ); // Check response for errors. CheckError(xmlResponse); // Deserialize the response into gateMessage representations. using (XmlReader reader = new XmlNodeReader(xmlResponse)) { while (reader.Read()) { // Found new gateMessage node to deserialize. if (reader.Name == "gateMessage") { XmlSerializer serializer = new XmlSerializer(typeof(GateMessage)); // Add gateMessage representation to return list. retMessages.Add((GateMessage)serializer.Deserialize(reader.ReadSubtree())); } } } return(retMessages); }
/// <summary> /// Address lookup an array of positions. /// </summary> /// <param name="positions"></param> /// <returns></returns> public List <Location> ReverseGeocode(Position[] positions) { List <Location> retLocations = new List <Location>(); decimal[] arrLats = new decimal[positions.Length]; decimal[] arrLngs = new decimal[positions.Length]; for (int i = 0; i < positions.Length; i++) { arrLats[i] = (decimal)positions[i].Latitude; arrLngs[i] = (decimal)positions[i].Longitude; } // Call Geocoder WebService ReverseGeocode XmlNode xmlResponse = m_Geocoder.ReverseGeocode(m_strSessionID, m_iApplicationID, arrLats, arrLngs); // Check response for errors. CheckError(xmlResponse); // Deserialize the result into XmlLocation representations. using (XmlReader reader = new XmlNodeReader(xmlResponse)) { while (reader.Read()) { // Found a new loc node to deserialize. if (reader.Name == "loc") { XmlSerializer serializer = new XmlSerializer(typeof(Location)); // Add the XmlLocation representation to return list. retLocations.Add((Location)serializer.Deserialize(reader.ReadSubtree())); } } } return(retLocations); }
/// <summary> /// Get users for a given group with optional filtering by view and who has been sending since the given timestamp. /// </summary> /// <param name="strGroupName">Name of group for which to receive users from.</param> /// <param name="iStartIndex">Start index to limit the result.</param> /// <param name="iEndIndex">End index to limit the result.</param> /// <param name="iViewID">ID of the view to filter by.</param> /// <param name="dtUtcSince">UTC TimeStamp</param> /// <returns>List of XmlUer representations.</returns> public List <User> GetUpdatedUsers(string strGroupName, int iStartIndex, int iEndIndex, int iViewID, DateTime dtUtcSince) { List <User> retUsers = new List <User>(); // Call Directory WebService GetUpdatedUsersInGroup XmlNode xmlResponse = m_Directory.GetUpdatedUsersInGroup( m_strSessionID, m_iApplicationID, strGroupName, iStartIndex, iEndIndex, iViewID, dtUtcSince ); // Chekc response for errors. CheckError(xmlResponse); // Desserialize the result into XmlUsers using (XmlReader reader = new XmlNodeReader(xmlResponse)) { while (reader.Read()) { // Found a new user node to deserialize. if (reader.Name == "user") { XmlSerializer serializer = new XmlSerializer(typeof(User)); // Add user representation to return list. retUsers.Add((User)serializer.Deserialize(reader.ReadSubtree())); } } } return(retUsers); }
public Object ToObjct <T>(String binaryString) { XmlReader reader_tmp; MethodInfo method; MethodInfo generic; XmlNode xmlDoc = xml.CreateElement("root"); xmlDoc.InnerXml = binaryString; XmlReader reader = new XmlNodeReader(xmlDoc); reader.MoveToContent(); reader.Read(); if (reader.Value == "null") { return(null); } if (typeof(T) == typeof(DateTime)) { while (reader.Name == "Value" || reader.NodeType != XmlNodeType.Text) { reader.Read(); } return (Convert.ChangeType( DateTime.ParseExact(reader.Value, "yyyy-MM-ddTHH:mm:ss.fffffffzzz", CultureInfo.InvariantCulture), typeof(T))); } if (typeof(T).IsPrimitive || typeof(T) == typeof(String)) { while (reader.NodeType != XmlNodeType.Text && reader.GetAttribute("IsEmptyStr") != "true") { reader.Read(); } T tmpVar = (T)Convert.ChangeType(reader.Value, typeof(T)); var asStr = tmpVar as string; if (asStr != null && (tmpVar as string) == "null") { tmpVar = default(T); } //reader.ReadToFollowing("Value"); //reader.Read(); return(tmpVar); } if (typeof(T).IsArray) { while (reader.GetAttribute("IsArray") == null) { reader.Read(); } int size = Convert.ToInt32(reader.GetAttribute("Len")); reader.Read(); var array = Array.CreateInstance(typeof(T).GetElementType(), size); for (int i = 0; i < size; i++) { reader_tmp = reader.ReadSubtree(); reader_tmp.MoveToContent(); method = typeof(Serial).GetMethod("ToObjct"); generic = method.MakeGenericMethod(Type.GetType(reader.GetAttribute("Type"))); var tmpint = generic.Invoke(this, new object[] { reader_tmp.ReadOuterXml() }); array.SetValue(tmpint, i); reader.Read(); } Convert.ChangeType(array, typeof(T)); return(array); } T ReturnObject; ReturnObject = (T)Activator.CreateInstance(typeof(T)); if (reader.Name == "RefToId" || reader.GetAttribute("IsToId") == "true") { if (reader.Name == "RefToId") { var tmp = relList[Convert.ToInt32(reader.Value)]; reader.Skip(); return(tmp); } else if (reader.GetAttribute("IsToId") == "true") { var tmp = relList[Convert.ToInt32(reader.GetAttribute("ToId"))]; reader.Skip(); reader.Read(); return(tmp); } } if (Id == 0) { relList.Add(0, ReturnObject); Id = -1; } else { if (Convert.ToInt32(reader.GetAttribute("Id")) == 0) { return(null); } if (!relList.ContainsKey(Convert.ToInt32(reader.GetAttribute("Id")))) { relList.Add(Convert.ToInt32(reader.GetAttribute("Id")), ReturnObject); } } FieldInfo[] fi = ReturnObject.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); for (int i = 0; i < fi.Length; i++) { while (reader.NodeType == XmlNodeType.EndElement || reader.Name != GetCleanFieldName(fi[i])) { reader.Read(); } if (IsReferenceType(fi[i].FieldType) && fi[i].FieldType != typeof(DateTime)) { bool RefFlag = false; bool ToIdFlag = false; int id; int toId; while (!(reader.GetAttribute("IsReference") == "true" || reader.GetAttribute("IsToId") == "true" || reader.Name == "RefToId" || reader.Value == "null") || reader.NodeType == XmlNodeType.EndElement) { reader.Read(); } if (reader.Value == "null") { return(null); } RefFlag = reader.Name == "RefToId"; ToIdFlag = reader.GetAttribute("IsToId") == "true"; id = Convert.ToInt32(reader.GetAttribute("Id")); toId = Convert.ToInt32(reader.GetAttribute("ToId")); method = typeof(Serial).GetMethod("ToObjct"); generic = method.MakeGenericMethod(fi[i].FieldType); if (RefFlag) { var tmp = relList[Convert.ToInt32(reader.Value)]; fi[i].SetValue(ReturnObject, tmp); reader.Skip(); reader.Read(); } else if (ToIdFlag) { var tmp = relList[toId]; fi[i].SetValue(ReturnObject, tmp); reader.Skip(); } else { reader_tmp = reader.ReadSubtree(); reader_tmp.MoveToContent(); var tmp = generic.Invoke(this, new object[] { reader_tmp.ReadOuterXml() }); fi[i].SetValue(ReturnObject, tmp); } continue; } if (reader.Name != GetCleanFieldName(fi[i])) { reader.ReadToFollowing(GetCleanFieldName(fi[i])); } reader_tmp = reader.ReadSubtree(); reader_tmp.MoveToContent(); method = typeof(Serial).GetMethod("ToObjct"); generic = method.MakeGenericMethod(fi[i].FieldType); var tmpint = generic.Invoke(this, new object[] { reader_tmp.ReadOuterXml() }); fi[i].SetValue(ReturnObject, tmpint); } return(ReturnObject); }
private abstract_Element process_element(XmlNodeReader nodeReader, int current_page_count) { string type = String.Empty; string subtype = String.Empty; // Step through all the attributes until the type is found nodeReader.MoveToFirstAttribute(); do { // Get the type attribute if (nodeReader.Name.ToUpper().Trim() == "TYPE") { type = nodeReader.Value; } // Get the subtype attribute if (nodeReader.Name.ToUpper().Trim() == "SUBTYPE") { subtype = nodeReader.Value; } } while (nodeReader.MoveToNextAttribute()); // Make sure a type was specified if (type == String.Empty) { return(null); } // Build the element abstract_Element newElement = Element_Factory.getElement(type, subtype); // If thie element was null, return null if (newElement == null) { return(null); } // Set the page number for post back reasons newElement.Template_Page = current_page_count; // Now, step through all the attributes again nodeReader.MoveToFirstAttribute(); do { switch (nodeReader.Name.ToUpper().Trim()) { case "REPEATABLE": bool repeatable; if (Boolean.TryParse(nodeReader.Value, out repeatable)) { newElement.Repeatable = repeatable; } break; case "MANDATORY": bool mandatory; if (Boolean.TryParse(nodeReader.Value, out mandatory)) { newElement.Mandatory = mandatory; } break; case "READONLY": bool isReadOnly; if (Boolean.TryParse(nodeReader.Value, out isReadOnly)) { newElement.Read_Only = isReadOnly; } break; case "ACRONYM": newElement.Acronym = nodeReader.Value; break; } } while (nodeReader.MoveToNextAttribute()); // Move back to the element, if there were attributes (should be) nodeReader.MoveToElement(); // Is there element_data? if (!nodeReader.IsEmptyElement) { nodeReader.Read(); if ((nodeReader.NodeType == XmlNodeType.Element) && (nodeReader.Name.ToLower() == "element_data")) { // Let the element process this inner data newElement.Read_XML(nodeReader.ReadSubtree()); } } // Return this built element return(newElement); }