Пример #1
0
/// <summary>
/// Deserialize
/// </summary>
/// <param name="serializedForm"></param>
/// <returns></returns>

        public static AccessControlList Deserialize(
            string serializedForm)
        {
            if (Lex.IsNullOrEmpty(serializedForm))
            {
                return(new AccessControlList());
            }

            XmlMemoryStreamTextReader mstr = new XmlMemoryStreamTextReader(serializedForm);

            XmlTextReader tr = mstr.Reader;

            tr.Read();             // get AccessControlList element
            tr.MoveToContent();
            if (!Lex.Eq(tr.Name, "AccessControlList"))
            {
                throw new Exception("\"AccessControlList\" element not found");
            }

            if (tr.IsEmptyElement)
            {
                return(new AccessControlList());                               // if nothing there return empty rule list
            }
            AccessControlList acl = Deserialize(mstr.Reader);

            mstr.Close();
            return(acl);
        }
Пример #2
0
/// <summary>
/// Deserialize
/// </summary>
/// <param name="serializedForm"></param>
/// <returns></returns>

        public static TargetSummaryOptions Deserialize(string serializedForm)
        {
            XmlMemoryStreamTextReader mstr = new XmlMemoryStreamTextReader(serializedForm);
            XmlTextReader             tr   = mstr.Reader;

            tr.Read();
            tr.MoveToContent();

            TargetSummaryOptions p = Deserialize(tr);

            mstr.Close();
            return(p);
        }
Пример #3
0
        /// <summary>
        /// Deserialize into an existing view
        /// </summary>
        /// <param name="serializedPropString"></param>
        /// <param name="q"></param>
        /// <param name="view"></param>

        public static void Deserialize(
            string serializedPropString,
            Query q,
            ResultsViewProps view)
        {
            XmlMemoryStreamTextReader mstr = new XmlMemoryStreamTextReader(serializedPropString);
            XmlTextReader             tr   = mstr.Reader;

            tr.MoveToContent();
            Deserialize(q, tr, view);
            tr.Close();
            return;
        }
Пример #4
0
        /// <summary>
        /// Deserialize XML into a ResultsFormat object
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>

        public static ResultsFormat Deserialize(
            string serializedForm)
        {
            XmlMemoryStreamTextReader mstr = new XmlMemoryStreamTextReader(serializedForm);

            XmlTextReader tr = mstr.Reader;

            tr.Read();             // get CondFormatRules element
            tr.MoveToContent();
            if (!Lex.Eq(tr.Name, "ResultsFormat"))
            {
                throw new Exception("ResultsFormat.Deserialize - No \"ResultsFormat\" element");
            }

            ResultsFormat rf = Deserialize(mstr.Reader);

            mstr.Close();
            return(rf);
        }
Пример #5
0
        /// <summary>
        /// Deserialize Spotfire link
        /// </summary>
        /// <param name="serializedForm"></param>
        /// <returns></returns>

        public static SpotfireViewProps Deserialize(
            string serializedForm)
        {
            XmlMemoryStreamTextReader mstr = new XmlMemoryStreamTextReader(serializedForm);

            XmlTextReader tr = mstr.Reader;

            tr.Read();             // get CalcField element
            tr.MoveToContent();
            if (!Lex.Eq(tr.Name, "SpotfireLink"))
            {
                throw new Exception("\"SpotfireLink\" element not found");
            }

            SpotfireViewProps sl = Deserialize(mstr.Reader);

            mstr.Close();
            return(sl);
        }
Пример #6
0
        /// <summary>
        /// Deserialize calculated field
        /// </summary>
        /// <param name="serializedForm"></param>
        /// <returns></returns>

        public static CalcField Deserialize(
            string serializedForm)
        {
            if (Lex.Contains(serializedForm, "<CalcField"))
            {
                XmlMemoryStreamTextReader mstr = new XmlMemoryStreamTextReader(serializedForm);

                XmlTextReader tr = mstr.Reader;
                tr.Read();                 // get CalcField element
                tr.MoveToContent();
                if (!Lex.Eq(tr.Name, "CalcField"))
                {
                    throw new Exception("CalcField.Deserialize - \"CalcField\" element not found");
                }

                CalcField cf = Deserialize(mstr.Reader);
                mstr.Close();
                return(cf);
            }

            return(DeserializeOld(serializedForm));            // must be old form
        }
Пример #7
0
/// <summary>
/// Deserialize root table information
/// </summary>
/// <param name="txt"></param>

        public static void Deserialize(string txt)
        {
            if (txt == null || txt == "")
            {
                return;
            }

            try
            {
                XmlMemoryStreamTextReader mstr = new XmlMemoryStreamTextReader(txt);
                XmlTextReader             tr   = mstr.Reader;
                Deserialize(tr);
                mstr.Close();
            }
            catch (Exception ex)
            {
                DebugLog.Message(ex.Message);
                return;
            }

            return;
        }
Пример #8
0
        /// <summary>
        /// Deserialize conditional formatting rules.
        /// </summary>
        /// <param name="serializedForm"></param>
        /// <returns></returns>

        public static CondFormatRules Deserialize(
            string serializedForm)
        {
            XmlMemoryStreamTextReader mstr = new XmlMemoryStreamTextReader(serializedForm);

            XmlTextReader tr = mstr.Reader;

            tr.Read();             // get CondFormatRules element
            tr.MoveToContent();
            if (!Lex.Eq(tr.Name, "CondFormatRules"))
            {
                throw new Exception("CondFormatRules.Deserialize - No \"CondFormatRules\" element found");
            }

            if (tr.IsEmptyElement)
            {
                return(new CondFormatRules());                               // if nothing there return empty rule list
            }
            CondFormatRules rules = Deserialize(mstr.Reader);

            mstr.Close();
            return(rules);
        }
Пример #9
0
        /// <summary>
        /// Deserialize conditional formatting.
        /// </summary>
        /// <param name="serializedForm"></param>
        /// <returns></returns>

        public static CondFormat Deserialize(
            string serializedForm)
        {
            if (!Lex.Contains(serializedForm, "<Condformat "))
            {
                return(DeserializeOld(serializedForm));
            }

            XmlMemoryStreamTextReader mstr = new XmlMemoryStreamTextReader(serializedForm);

            XmlTextReader tr = mstr.Reader;

            tr.Read();             // get CondFormat element
            tr.MoveToContent();
            if (!Lex.Eq(tr.Name, "CondFormat"))
            {
                throw new Exception("CondFormat.Deserialize - \"CondFormat\" element not found");
            }

            CondFormat cf = Deserialize(mstr.Reader);

            mstr.Close();
            return(cf);
        }
Пример #10
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);
        }
Пример #11
0
        /// <summary>
        /// Deserialize an alert header in a user object
        /// </summary>
        /// <param name="uo"></param>
        /// <returns></returns>

        private static Alert DeserializeHeader(
            UserObject uo)
        {
            Alert alert = new Alert();

            alert.Id = uo.Id;

            string serializedForm = uo.Description;

            if (String.IsNullOrEmpty(serializedForm))
            {
                return(alert);
            }

            if (!Lex.Contains(serializedForm, "<Alert"))
            {
                return(DeserializeHeaderOld(uo));
            }

            XmlMemoryStreamTextReader mstr = new XmlMemoryStreamTextReader(serializedForm);
            XmlTextReader             tr   = mstr.Reader;

            tr.Read();             // get CondFormat element
            tr.MoveToContent();
            if (!Lex.Eq(tr.Name, "Alert"))
            {
                throw new Exception("\"Alert\" element not found");
            }

            XmlUtil.GetStringAttribute(tr, "Owner", ref alert.Owner);
            XmlUtil.GetIntAttribute(tr, "QueryObjId", ref alert.QueryObjId);
            XmlUtil.GetIntAttribute(tr, "Interval", ref alert.Interval);
            XmlUtil.GetStringAttribute(tr, "MailTo", ref alert.MailTo);
            XmlUtil.GetDateAttribute(tr, "LastCheck", ref alert.LastCheck);
            XmlUtil.GetIntAttribute(tr, "LastCheckElapsedTime", ref alert.LastCheckExecutionTime);
            XmlUtil.GetIntAttribute(tr, "NewCompounds", ref alert.NewCompounds);
            XmlUtil.GetIntAttribute(tr, "ChangedCompounds", ref alert.ChangedCompounds);
            XmlUtil.GetIntAttribute(tr, "NewRows", ref alert.NewRows);
            XmlUtil.GetIntAttribute(tr, "TotalRows", ref alert.TotalRows);
            XmlUtil.GetIntAttribute(tr, "TotalCompounds", ref alert.TotalCompounds);
            XmlUtil.GetBoolAttribute(tr, "CheckTablesWithCriteriaOnly", ref alert.CheckTablesWithCriteriaOnly);
            XmlUtil.GetDateAttribute(tr, "LastNewData", ref alert.LastNewData);
            XmlUtil.GetBoolAttribute(tr, "HighlightChangedCompounds", ref alert.HighlightChangedCompounds);
            XmlUtil.GetBoolAttribute(tr, "RunImmediately", ref alert.RunImmediately);

            XmlUtil.GetStringAttribute(tr, "Days", ref alert.Days);
            XmlUtil.GetIntAttribute(tr, "DayInterval", ref alert.DayInterval);
            XmlUtil.GetDateAttribute(tr, "StartTime", ref alert.StartTime);
            alert.StartTime = GetLocalFromEasternStandardTime(alert.StartTime);
            XmlUtil.GetStringAttribute(tr, "Pattern", ref alert.Pattern);
            if (string.IsNullOrEmpty(alert.Pattern))
            {
                alert.Pattern = PatternEnum.Daily.ToString();
            }

            if (!tr.IsEmptyElement)
            {
                tr.Read();                 // move to Export options or end of Alert element
                tr.MoveToContent();

                if (tr.NodeType == XmlNodeType.Element && Lex.Eq(tr.Name, "ResultsFormat"))
                {
                    alert.ExportParms = ResultsFormat.Deserialize(tr);
                    tr.Read();                     // get Alert end element
                    tr.MoveToContent();
                }

                if (!Lex.Eq(tr.Name, "Alert") || tr.NodeType != XmlNodeType.EndElement)
                {
                    throw new Exception("Alert.Deserialize - Expected Alert end element");
                }
            }

            mstr.Close();

            double daysSinceLastCheckwithDecimal = (alert.LastCheck == DateTime.MinValue) ? alert.Interval : (DateTime.Now - alert.LastCheck).TotalDays;
            double daysSinceNewDatawithDecimal   = (alert.LastNewData == DateTime.MinValue) ? 0 : (DateTime.Now - alert.LastNewData).TotalDays;

            //Round these calculations so .5 days will become 1 day, effectively 12 hours or more will count as a whole day.
            alert.DaysSinceLastCheck = (int)Math.Round(daysSinceLastCheckwithDecimal, MidpointRounding.AwayFromZero);
            alert.DaysSinceNewData   = (int)Math.Round(daysSinceNewDatawithDecimal, MidpointRounding.AwayFromZero);

            //DebugLog.Message("Alert: " + alert.Id + " daysSinceLastCheckwithDecimal: " + daysSinceLastCheckwithDecimal);
            //DebugLog.Message("Alert: " + alert.Id + " new DaysSinceLastCheck: " + alert.DaysSinceLastCheck);
            //DebugLog.Message("Alert: " + alert.Id + " daysSinceNewDatawithDecimal: " + daysSinceNewDatawithDecimal);
            //DebugLog.Message("Alert: " + alert.Id + " DaysSinceNewData: " + alert.DaysSinceNewData);

            return(alert);
        }