//#region XML Serialization //public override System.Xml.XmlDocument XmlSerialize () { // System.Xml.XmlDocument eventDocument = new System.Xml.XmlDocument (); // System.Xml.XmlDeclaration xmlDeclaration = eventDocument.CreateXmlDeclaration ("1.0", "utf-8", String.Empty); // eventDocument.InsertBefore (xmlDeclaration, eventDocument.DocumentElement); // System.Xml.XmlElement eventNode = eventDocument.CreateElement ("ActivityEvent"); // System.Xml.XmlElement propertiesNode; // eventDocument.AppendChild (eventNode); // eventNode.SetAttribute ("ActivityEventId", activityEventId.ToString ()); // propertiesNode = eventDocument.CreateElement ("Properties"); // eventNode.AppendChild (propertiesNode); // #region Action Properties // CommonFunctions.XmlDocumentAppendPropertyNode (eventDocument, propertiesNode, "ActivityEventId", activityEventId.ToString ()); // CommonFunctions.XmlDocumentAppendPropertyNode (eventDocument, propertiesNode, "ScheduleType", ((Int32) scheduleType).ToString ()); // CommonFunctions.XmlDocumentAppendPropertyNode (eventDocument, propertiesNode, "ScheduleValue", scheduleValue.ToString ()); // CommonFunctions.XmlDocumentAppendPropertyNode (eventDocument, propertiesNode, "ScheduleQualifier", ((Int32) scheduleQualifier).ToString ()); // CommonFunctions.XmlDocumentAppendPropertyNode (eventDocument, propertiesNode, "AnchorDate", ((Int32) anchorDate).ToString ()); // CommonFunctions.XmlDocumentAppendPropertyNode (eventDocument, propertiesNode, "Reoccurring", reoccurring.ToString ()); // CommonFunctions.XmlDocumentAppendPropertyNode (eventDocument, propertiesNode, "PerformActionDateType", ((Int32) performActionDateType).ToString ()); // #endregion // System.Xml.XmlElement actionPropertyNode = eventDocument.CreateElement ("Property"); // actionPropertyNode.SetAttribute ("Name", "Action"); // if (action != null) { // System.Xml.XmlDocument actionDocument = action.XmlSerialize (); // actionPropertyNode.AppendChild (eventDocument.ImportNode (actionDocument.ChildNodes[1], true)); // } // propertiesNode.AppendChild (actionPropertyNode); // return eventDocument; //} //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 = "ActivityEvent"; // importResponse.Success = true; // if (importResponse.ObjectType == "ActivityEvent") { // try { // #region Activity Properties // foreach (System.Xml.XmlNode currentProperty in objectNode.ChildNodes[0]) { // String propertyName = currentProperty.Attributes["Name"].InnerText; // switch (propertyName) { // case "ScheduleType": scheduleType = (Mercury.Server.Core.Population.Enumerations.ActivityScheduleType) Convert.ToInt32 (currentProperty.InnerText); break; // case "ScheduleValue": scheduleValue = Convert.ToInt32 (currentProperty.InnerText); break; // case "ScheduleQualifier": scheduleQualifier = (Mercury.Server.Core.Enumerations.DateQualifier) Convert.ToInt32 (currentProperty.InnerText); break; // case "AnchorDate": anchorDate = (Mercury.Server.Core.Population.Enumerations.PopulationActivityEventAnchorDate) Convert.ToInt32 (currentProperty.InnerText); break; // case "Reoccurring": reoccurring = Convert.ToBoolean (currentProperty.InnerText); break; // case "PerformActionDateType": performActionDateType = (Mercury.Server.Core.Population.Enumerations.ActivityPerformActionDateType) Convert.ToInt32 (currentProperty.InnerText); break; // case "Action": // if (currentProperty.ChildNodes.Count > 0) { // 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 Population.")); } // response.Add (importResponse); // return response; //} //#endregion #region Validation Functions public override Dictionary <String, String> Validate() { Dictionary <String, String> validationResponse = new Dictionary <String, String> (); if ((scheduleType == Mercury.Server.Core.Population.Enumerations.PopulationActivityScheduleType.ByFrequency) && (scheduleValue == 0)) { validationResponse.Add("Schedule", "Invalid Schedule Value."); } if (action == null) { validationResponse.Add("Action", "No Action Defined for Activity."); } else { Dictionary <String, String> actionValidation = action.Validate(); foreach (String currentKey in actionValidation.Keys) { if (!validationResponse.ContainsKey(currentKey)) { validationResponse.Add(currentKey, actionValidation[currentKey]); } } } return(validationResponse); }
//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 = "TriggerEvent"; // importResponse.Success = true; // if (importResponse.ObjectType == "TriggerEvent") { // try { // #region Trigger Properties // foreach (System.Xml.XmlNode currentProperty in objectNode.ChildNodes[0]) { // String propertyName = currentProperty.Attributes["Name"].InnerText; // switch (propertyName) { // case "EventType": eventType = (Mercury.Server.Core.Population.Enumerations.TriggerEventType) Convert.ToInt32 (currentProperty.InnerText); break; // case "MetricType": metricType = (Mercury.Server.Core.Metrics.Enumerations.MetricType) Convert.ToInt32 (currentProperty.InnerText); break; // case "MetricMinimum": metricMinimum = Convert.ToDecimal (currentProperty.InnerText); break; // case "MetricMaximum": metricMaximum = Convert.ToDecimal (currentProperty.InnerText); break; // case "ProblemStatementId": problemStatementId = Convert.ToInt64 (currentProperty.InnerText); break; // case "Service": // #region Service // if (currentProperty.ChildNodes.Count > 0) { // System.Xml.XmlNode serviceNode = currentProperty.ChildNodes[0]; // String serviceName = serviceNode.Attributes["Name"].InnerText; // Core.MedicalServices.Service medicalService = base.application.MedicalServiceGet (serviceName); // if (medicalService != null) { // serviceId = medicalService.ServiceId; // } // else { // Core.MedicalServices.Enumerations.MedicalServiceType serviceType = (Mercury.Server.Core.MedicalServices.Enumerations.MedicalServiceType) Convert.ToInt32 (serviceNode.Attributes["ServiceType"].InnerText); // switch (serviceType) { // case Mercury.Server.Core.MedicalServices.Enumerations.MedicalServiceType.Singleton: // Core.MedicalServices.ServiceSingleton singleton = new Core.MedicalServices.ServiceSingleton (base.application); // response.AddRange (singleton.XmlImport (serviceNode)); // serviceId = singleton.ServiceId; // break; // case Mercury.Server.Core.MedicalServices.Enumerations.MedicalServiceType.Set: // Core.MedicalServices.ServiceSet serviceSet = new Core.MedicalServices.ServiceSet (base.application); // response.AddRange (serviceSet.XmlImport (serviceNode)); // serviceId = serviceSet.ServiceId; // break; // } // } // if ((currentProperty.Attributes["Name"].InnerText == "Service") && (serviceId == 0)) { throw new ApplicationException ("Unable to load Service."); } // } // #endregion // break; // case "Metric": // #region Metric // if (currentProperty.ChildNodes.Count > 0) { // System.Xml.XmlNode metricNode = currentProperty.ChildNodes[0]; // String metricName = metricNode.Attributes["Name"].InnerText; // Core.Metrics.Metric metric = base.application.MetricGet (metricName); // if (metric != null) { // metricId = metric.MetricId; // } // else { // metric = new Mercury.Server.Core.Metrics.Metric (base.application); // response.AddRange (metric.XmlImport (metricNode)); // metricId = metric.MetricId; // } // if (metricId == 0) { throw new ApplicationException ("Unable to import Metric."); } // } // #endregion // break; // case "AuthorizedService": // #region AuthorizedService // if (currentProperty.ChildNodes.Count > 0) { // System.Xml.XmlNode authorizedServiceNode = currentProperty.ChildNodes[0]; // String authorizedServiceName = authorizedServiceNode.Attributes["Name"].InnerText; // Core.AuthorizedServices.AuthorizedService authorizedService = base.application.AuthorizedServiceGet (authorizedServiceId); // if (authorizedService != null) { // authorizedServiceId = authorizedService.AuthorizedServiceId; // } // else { // authorizedService = new Mercury.Server.Core.AuthorizedServices.AuthorizedService (base.application); // response.AddRange (authorizedService.XmlImport (authorizedServiceNode)); // authorizedServiceId = authorizedService.AuthorizedServiceId; // } // if (authorizedServiceId == 0) { throw new ApplicationException ("Unable to import Authorized Service."); } // } // #endregion // break; // case "Action": // #region Action // if (currentProperty.ChildNodes.Count > 0) { // 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)); // } // } // #endregion // 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 Population.")); } // response.Add (importResponse); // return response; //} //#endregion #region Validation Functions public override Dictionary <String, String> Validate() { Dictionary <String, String> validationResponse = new Dictionary <String, String> (); if (action == null) { action = new Mercury.Server.Core.Action.Action(application); } switch (eventType) { case Mercury.Server.Core.Population.Enumerations.PopulationTriggerEventType.Metric: if (metricMinimum > metricMaximum) { validationResponse.Add("Metric Value Range", "Minimum (Floor) is greater than Maximum (Ceiling)."); } break; } if ((problemStatementId == 0) && (action.Id == 0)) { validationResponse.Add("Problem Statement or Action", "Triggers Requires a Problem Statement or Action."); } else if (action.Id != 0) { Dictionary <String, String> actionValidation = action.Validate(); foreach (String currentKey in actionValidation.Keys) { if (!validationResponse.ContainsKey(currentKey)) { validationResponse.Add(currentKey, actionValidation[currentKey]); } } } return(validationResponse); }