Exemple #1
0
        //public override System.Xml.XmlDocument XmlSerialize () {

        //    if (thresholdType == Mercury.Server.Core.Action.Enumerations.ActionThresholdType.NotSpecified) { throw new ApplicationException ("Invalid Threshold Type Specified."); }


        //    System.Xml.XmlDocument thresholdDocument = base.XmlSerialize ();


        //    System.Xml.XmlElement thresholdNode = thresholdDocument.CreateElement (thresholdType.ToString () + "Threshold");

        //    System.Xml.XmlElement propertiesNode;


        //    thresholdDocument.AppendChild (thresholdNode);

        //    thresholdNode.SetAttribute ("ThresholdId", Id.ToString ());

        //    propertiesNode = thresholdDocument.CreateElement ("Properties");

        //    thresholdNode.AppendChild (propertiesNode);


        //    #region Properties

        //    CommonFunctions.XmlDocumentAppendPropertyNode (thresholdDocument, propertiesNode, "ThresholdId", thresholdId.ToString ());

        //    CommonFunctions.XmlDocumentAppendPropertyNode (thresholdDocument, propertiesNode, "ThresholdType", thresholdType.ToString ());

        //    CommonFunctions.XmlDocumentAppendPropertyNode (thresholdDocument, propertiesNode, "ThresholdTypeInt32", ((Int32) thresholdType).ToString ());

        //    CommonFunctions.XmlDocumentAppendPropertyNode (thresholdDocument, propertiesNode, "RelativeDateValue", relativeDateValue.ToString ());

        //    CommonFunctions.XmlDocumentAppendPropertyNode (thresholdDocument, propertiesNode, "RelativeDateQualifier", ((Int32) relativeDateQualifier).ToString ());

        //    CommonFunctions.XmlDocumentAppendPropertyNode (thresholdDocument, propertiesNode, "Status", ((Int32) status).ToString ());

        //    #endregion


        //    System.Xml.XmlElement actionPropertyNode = thresholdDocument.CreateElement ("Property");

        //    actionPropertyNode.SetAttribute ("Name", "Action");

        //    if (action != null) {

        //        System.Xml.XmlDocument actionDocument = action.XmlSerialize ();

        //        actionPropertyNode.AppendChild (thresholdDocument.ImportNode (actionDocument.ChildNodes[1], true));

        //    }

        //    propertiesNode.AppendChild (actionPropertyNode);


        //    return thresholdDocument;

        //}

        //public override List<Services.Responses.ConfigurationImportResponse> XmlImport (System.Xml.XmlNode objectNode) {

        //    List<Services.Responses.ConfigurationImportResponse> response = new List<Mercury.Server.Services.Responses.ConfigurationImportResponse> ();

        //    Services.Responses.ConfigurationImportResponse importResponse = new Mercury.Server.Services.Responses.ConfigurationImportResponse ();


        //    importResponse.ObjectType = objectNode.Name;

        //    importResponse.ObjectName = "Threshold";

        //    importResponse.Success = true;


        //    if (importResponse.ObjectType.EndsWith ("Threshold")) {

        //        try {

        //            #region Service Event Threshold Properties

        //            foreach (System.Xml.XmlNode currentProperty in objectNode.ChildNodes[0]) {

        //                switch (currentProperty.Attributes["Name"].InnerText) {

        //                    case "ThresholdTypeInt32": thresholdType = (Mercury.Server.Core.Action.Enumerations.ActionThresholdType) Convert.ToInt32 (currentProperty.InnerText); break;

        //                    case "RelativeDateValue": relativeDateValue = Convert.ToInt32 (currentProperty.InnerText); break;

        //                    case "RelativeDateQualifier": relativeDateQualifier = (Mercury.Server.Core.Enumerations.DateQualifier) Convert.ToInt32 (currentProperty.InnerText); break;

        //                    case "Status": status = (Enumerations.ActionThresholdStatus) Convert.ToInt32 (currentProperty.InnerText); break;

        //                    case "Action":

        //                        System.Xml.XmlNode actionNode = currentProperty.ChildNodes[0];

        //                        Int32 actionId = Convert.ToInt32 (actionNode.Attributes["ActionId"].InnerText);

        //                        String actionName = actionNode.Attributes["Name"].InnerText;

        //                        if (actionId != 0) {

        //                            action = new Mercury.Server.Core.Action.Action (base.application, actionId, actionName);

        //                            response.AddRange (action.XmlImport (actionNode));

        //                        }

        //                        break;

        //                }

        //            }

        //            #endregion


        //            if (!importResponse.Success) { importResponse.SetException (base.application.LastException); }


        //        }

        //        catch (Exception importException) {

        //            importResponse.SetException (importException);

        //        }


        //    }

        //    else { importResponse.SetException (new ApplicationException ("Invalid Object Type Parsed as Threshold.")); }


        //    response.Add (importResponse);

        //    return response;

        //}

        #endregion


        #region Database Functions

        public override Boolean Load(Int64 forId)
        {
            if (thresholdType == Mercury.Server.Core.Action.Enumerations.ActionThresholdType.NotSpecified)
            {
                throw new ApplicationException("Invalid Threshold Type Specified.");
            }


            Boolean success = false;

            StringBuilder selectStatement = new StringBuilder();

            System.Data.DataTable thresholdTable;


            if (application.EnvironmentDatabase == null)
            {
                return(false);
            }

            selectStatement.Append("SELECT * FROM dbo." + thresholdType.ToString() + "Threshold WHERE " + thresholdType.ToString() + "ThresholdId = " + forId.ToString());

            thresholdTable = application.EnvironmentDatabase.SelectDataTable(selectStatement.ToString(), 0);

            if (thresholdTable.Rows.Count == 1)
            {
                MapDataFields(thresholdTable.Rows[0]);

                success = true;
            }

            else
            {
                success = false;
            }

            return(success);
        }