示例#1
0
        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);
            }
        }
示例#2
0
        public int CompletedCount;               // number of times completed

        public string Serialize()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(UserDatabase.ToString());                 // [0]
            sb.Append("\t");
            sb.Append(UserDataObjectId.ToString());             // [1]
            sb.Append("\t");
            sb.Append(ClientFile);                              // [2]
            sb.Append("\t");
            sb.Append(CheckForFileUpdates.ToString());          // [3]
            sb.Append("\t");
            sb.Append(DateTimeUS.ToString(ClientFileModified)); // [4]
            sb.Append("\t");
            sb.Append(FileName);                                // [5]
            sb.Append("\t");
            sb.Append(DateTimeUS.ToString(LastStarted));        // [6]
            sb.Append("\t");
            sb.Append(DateTimeUS.ToString(LastCheckpoint));     // [7]
            sb.Append("\t");
            sb.Append(StartedCount.ToString());                 // [8]
            sb.Append("\t");
            sb.Append(CompletedCount.ToString());               // [9]

            return(sb.ToString());
        }
示例#3
0
/// <summary>
/// Create an instance from the specified internal or external format string
/// </summary>
/// <param name="s"></param>

        public DateTimeMx(
            String s)
        {
            if (DateTimeUS.TryParseDate(s, out Value))
            {
                return;                                  // try external format
            }
            Value = NormalizedToDateTime(s);             // try internal format
            return;
        }
示例#4
0
        /// <summary>
        /// Custom Compact deserialization
        /// </summary>
        /// <param name="sa"></param>
        /// <param name="sai"></param>
        /// <returns></returns>

        public static DateTimeMx Deserialize(string[] sa, int sai)
        {
            DateTimeMx dtx = new DateTimeMx();

            if (!Lex.IsNullOrEmpty(sa[sai]))
            {
                dtx.Value = DateTimeUS.ParseDate(sa[sai]);
            }
            return(dtx);
        }
示例#5
0
        /// <summary>
        /// Custom compact serialization
        /// </summary>
        /// <returns></returns>

        public override StringBuilder Serialize()
        {
            if (IsNull)
            {
                return(new StringBuilder("<D>"));
            }
            StringBuilder sb = BeginSerialize("D");

            sb.Append(NormalizeForSerialize(DateTimeUS.ToDateString(Value)));
            sb.Append(">");
            return(sb);
        }
示例#6
0
/// <summary>
/// Serialize
/// </summary>
/// <returns></returns>

        public string Serialize()
        {
            XmlMemoryStreamTextWriter mstw = new XmlMemoryStreamTextWriter();

            mstw.Writer.Formatting = Formatting.Indented;
            XmlTextWriter tw = mstw.Writer;

            tw.WriteStartElement("UserObject");

            tw.WriteAttributeString("Id", Id.ToString());
            tw.WriteAttributeString("Type", Type.ToString());
            tw.WriteAttributeString("Owner", Owner);
            tw.WriteAttributeString("Name", Name);
            XmlUtil.WriteAttributeIfDefined(tw, "Description", Description);
            tw.WriteAttributeString("ParentFolder", ParentFolder);
            tw.WriteAttributeString("ParentFolderType", ParentFolderType.ToString());
            tw.WriteAttributeString("AccessLevel", AccessLevel.ToString());
            XmlUtil.WriteAttributeIfDefined(tw, "ACL", ACL);
            tw.WriteAttributeString("Count", Count.ToString());
            if (CreationDateTime != DateTime.MinValue)
            {
                tw.WriteAttributeString("CreationDateTime", DateTimeUS.ToString(CreationDateTime));
            }
            if (UpdateDateTime != DateTime.MinValue)
            {
                tw.WriteAttributeString("UpdateDateTime", DateTimeUS.ToString(UpdateDateTime));
            }

            if (!Lex.IsNullOrEmpty(Content))
            {
                tw.WriteStartElement("Content");
                string cdataClose = "]]>";
                string content    = Content;
                while (Lex.Contains(content, cdataClose))
                {
                    int p = Lex.IndexOf(content, cdataClose);
                    tw.WriteCData(content.Substring(0, p + 2));
                    content = content.Substring(p + 2);
                }
                tw.WriteCData(content);
                tw.WriteEndElement();                 // end of DataRows
            }

            tw.WriteEndElement();
            string xml = mstw.GetXmlAndClose();

            return(xml);
        }
示例#7
0
        /// <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);
        }
示例#8
0
        /// <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);
        }