public static UserDataImportState Deserialize( UserObject uo) { try { UserDataImportState udis = new UserDataImportState(); udis.Id = uo.Id; string[] sa = uo.Description.Split('\t'); udis.UserDatabase = Boolean.Parse(sa[0]); udis.UserDataObjectId = int.Parse(sa[1]); udis.ClientFile = sa[2]; udis.CheckForFileUpdates = bool.Parse(sa[3]); udis.ClientFileModified = DateTimeUS.Parse(sa[4]); udis.FileName = sa[5]; udis.LastStarted = DateTimeUS.Parse(sa[6]); udis.LastCheckpoint = DateTimeUS.Parse(sa[7]); udis.StartedCount = int.Parse(sa[8]); udis.CompletedCount = int.Parse(sa[9]); return(udis); } catch (Exception ex) { throw new Exception("Error deserializing UserDataImportState: " + uo.Description, ex); } }
/// <summary> /// Deserialize UserObject XML into an actual UserObject. /// </summary> /// <param name="userObjectElement"></param> /// <returns></returns> public static UserObject Deserialize( XmlElement userObjectElement) { UserObject uo = new UserObject(); if (userObjectElement == null) { return(uo); } if (userObjectElement.Name != "UserObject") { throw new Exception("UserObject.Deserialize - \"UserObject\" element not found"); } foreach (XmlAttribute attribute in userObjectElement.Attributes) { switch (attribute.Name) { case "Id": uo.Id = int.Parse(attribute.Value); break; case "Name": uo.Name = attribute.Value; break; case "Owner": uo.Owner = attribute.Value; break; case "Description": uo.Description = attribute.Value; break; case "ParentFolder": uo.ParentFolder = attribute.Value; break; case "ACL": uo.ACL = attribute.Value; break; case "Count": uo.Count = int.Parse(attribute.Value); break; case "ParentFolderType": uo.ParentFolderType = (FolderTypeEnum)Enum.Parse(typeof(FolderTypeEnum), attribute.Value); break; case "Type": uo.Type = (UserObjectType)Enum.Parse(typeof(UserObjectType), attribute.Value); break; case "AccessLevel": uo.AccessLevel = (UserObjectAccess)Enum.Parse(typeof(UserObjectAccess), attribute.Value); break; case "CreationDateTime": uo.CreationDateTime = DateTimeUS.Parse(attribute.Value); break; case "UpdateDateTime": uo.UpdateDateTime = DateTimeUS.Parse(attribute.Value); break; default: throw new Exception("UserObject.Deserialize - UserObject property \"" + attribute.Name + "\" not found"); } } // Retrieve Content node XmlNode contentElement = userObjectElement.SelectSingleNode("Content"); if (contentElement == null) { return(uo); } // May be multiple CDATA segments. Add these data to the Content Prperty. foreach (XmlNode node in contentElement.ChildNodes) { if (node is XmlCDataSection) { uo.Content += node.Value; } } return(uo); }
/// <summary> /// Deserialize /// </summary> /// <param name="serializedForm"></param> /// <returns></returns> public static UserObject Deserialize( string serializedForm) { string txt = null; UserObject uo = new UserObject(); if (Lex.IsNullOrEmpty(serializedForm)) { return(uo); } XmlMemoryStreamTextReader mstr = new XmlMemoryStreamTextReader(serializedForm); XmlTextReader tr = mstr.Reader; tr.Read(); // get CalcField element tr.MoveToContent(); if (!Lex.Eq(tr.Name, "UserObject")) { throw new Exception("UserObject.Deserialize - \"UserObject\" element not found"); } XmlUtil.GetIntAttribute(tr, "Id", ref uo.Id); if (XmlUtil.GetStringAttribute(tr, "Type", ref txt)) { uo.Type = (UserObjectType)Enum.Parse(typeof(UserObjectType), txt); } XmlUtil.GetStringAttribute(tr, "Owner", ref uo.Owner); XmlUtil.GetStringAttribute(tr, "Name", ref uo.Name); XmlUtil.GetStringAttribute(tr, "Description", ref uo.Description); XmlUtil.GetStringAttribute(tr, "ParentFolder", ref uo.ParentFolder); if (XmlUtil.GetStringAttribute(tr, "ParentFolderType", ref txt)) { uo.ParentFolderType = (FolderTypeEnum)Enum.Parse(typeof(FolderTypeEnum), txt); } if (XmlUtil.GetStringAttribute(tr, "AccessLevel", ref txt)) { uo.AccessLevel = (UserObjectAccess)Enum.Parse(typeof(UserObjectAccess), txt); } XmlUtil.GetStringAttribute(tr, "ACL", ref uo.ACL); XmlUtil.GetIntAttribute(tr, "Count", ref uo.Count); if (XmlUtil.GetStringAttribute(tr, "CreationDateTime", ref txt)) { uo.CreationDateTime = DateTimeUS.Parse(txt); } if (XmlUtil.GetStringAttribute(tr, "UpdateDateTime", ref txt)) { uo.UpdateDateTime = DateTimeUS.Parse(txt); } tr.Read(); // get any content tr.MoveToContent(); if (Lex.Eq(tr.Name, "Content")) { tr.Read(); // get any CDATA content tr.MoveToContent(); uo.Content = ""; while (tr.NodeType == XmlNodeType.CDATA) // may be multiple CDATA segments { uo.Content += tr.Value; tr.Read(); // more CDATA or content end tag tr.MoveToContent(); } } tr.Read(); // UserObject end tag tr.MoveToContent(); mstr.Close(); return(uo); }