Exemplo n.º 1
0
        public override List <ImportExport.Result> XmlImport(System.Xml.XmlNode objectNode)
        {
            List <ImportExport.Result> response = base.XmlImport(objectNode);

            try {
                foreach (System.Xml.XmlNode currentNode in objectNode.ChildNodes)
                {
                    switch (currentNode.Name)
                    {
                    case "Dependencies":

                        #region Dependencies

                        foreach (System.Xml.XmlNode currentDependencyNode in currentNode.ChildNodes)
                        {
                            switch (currentDependencyNode.Name)
                            {
                            case "ConditionClass":

                                ConditionClass conditionClass = application.ConditionClassGet(currentDependencyNode.Attributes[Name].Value);

                                if (conditionClass == null)
                                {
                                    conditionClass = new Core.Condition.ConditionClass(application);

                                    response.AddRange(conditionClass.XmlImport(currentDependencyNode));
                                }

                                break;
                            }
                        }

                        #endregion

                        break;

                    case "Properties":

                        #region Properties

                        foreach (System.Xml.XmlNode currentPropertyNode in currentNode.ChildNodes)
                        {
                            switch (currentPropertyNode.Attributes["Name"].Value)
                            {
                            case "ConditionClassName":

                                conditionClassId = application.ConditionClassGetIdByName(currentPropertyNode.InnerText);

                                if (conditionClassId == 0)
                                {
                                    throw new ApplicationException("Unable to retreive Condition Type: " + currentPropertyNode.InnerText);
                                }

                                break;
                            }
                        }

                        #endregion

                        break;

                    case "ConditionCriteria":

                        #region Condition Criteria

                        foreach (System.Xml.XmlNode currentCriteriaNode in currentNode.ChildNodes)
                        {
                            switch (currentCriteriaNode.Name)
                            {
                            case "ConditionCriteriaDemographic":

                                ConditionCriteria.ConditionCriteriaDemographic conditionCriteriaDemographic = new ConditionCriteria.ConditionCriteriaDemographic(application);

                                response.AddRange(conditionCriteriaDemographic.XmlImport(currentCriteriaNode));

                                demographicCriteria.Add(conditionCriteriaDemographic);

                                break;

                            case "ConditionCriteriaEvent":

                                ConditionCriteria.ConditionCriteriaEvent conditionCriteriaEvent = new ConditionCriteria.ConditionCriteriaEvent(application);

                                response.AddRange(conditionCriteriaEvent.XmlImport(currentCriteriaNode));

                                eventCriteria.Add(conditionCriteriaEvent);

                                break;
                            }
                        }

                        #endregion

                        break;

                    case "ConditionEvents":

                        #region Condition Events

                        foreach (System.Xml.XmlNode currentEventNode in currentNode.ChildNodes)
                        {
                            String eventName = currentEventNode.Name;

                            Core.Action.Action eventAction = new Action.Action(application);

                            response.AddRange(eventAction.XmlImport(currentEventNode.FirstChild));

                            if (events.ContainsKey(eventName))
                            {
                                events.Remove(eventName);
                            }

                            events.Add(eventName, eventAction);
                        }

                        #endregion

                        break;
                    } // switch (currentNode.Name) {
                }     // foreach (System.Xml.XmlNode currentNode in objectNode.ChildNodes) {

                // SAVE IMPORTED OBJECT

                if (!Save())
                {
                    throw new ApplicationException("Unable to save " + ObjectType + ": " + Name + ".");
                }
            }

            catch (Exception importException) {
                response.Add(new ImportExport.Result(ObjectType, Name, importException));
            }

            return(response);
        }
Exemplo n.º 2
0
        public override Boolean Save()
        {
            Boolean success = false;

            StringBuilder sqlStatement;

            String criteriaIds;

            if (!application.HasEnvironmentPermission(Server.EnvironmentPermissions.ConditionManage))
            {
                throw new ApplicationException("Permission Denied");
            }


            modifiedAccountInfo = new Mercury.Server.Data.AuthorityAccountStamp(application.Session);


            try {
                application.EnvironmentDatabase.BeginTransaction();



                conditionClassId = application.ConditionClassGetIdByName(conditionClassName);

                if (conditionClassId == 0)
                {
                    ConditionClass conditionClass = new ConditionClass(application);

                    conditionClass.Name = conditionClassName;

                    conditionClass.Description = conditionClassName;

                    conditionClass.Enabled = true;

                    conditionClass.Visible = true;

                    conditionClass.Save();

                    conditionClassId = conditionClass.Id;
                }


                sqlStatement = new StringBuilder();

                sqlStatement.Append("EXEC dbo.Condition_InsertUpdate ");

                sqlStatement.Append(Id.ToString() + ", ");

                sqlStatement.Append("'" + NameSql + "', ");

                sqlStatement.Append("'" + DescriptionSql + "', ");

                sqlStatement.Append(conditionClassId.ToString() + ", ");

                sqlStatement.Append(Convert.ToInt32(Enabled).ToString() + ", ");

                sqlStatement.Append(Convert.ToInt32(Visible).ToString() + ", ");


                //sqlStatement.Append (IdSqlAllowNull (OnBeforeMembershipAddWorkflowId) + ", ");

                //sqlStatement.Append (events["OnMembershipAdd"].Id.ToString () + ", ");

                //sqlStatement.Append ("'" + events["OnMembershipAdd"].ActionParametersXmlSqlParsedString + "', ");

                //sqlStatement.Append ("'" + events["OnMembershipAdd"].Description + "', ");


                //sqlStatement.Append (IdSqlAllowNull (OnBeforeMembershipTerminateWorkflowId) + ", ");

                //sqlStatement.Append (events["OnMembershipTerminate"].Id.ToString () + ", ");

                //sqlStatement.Append ("'" + events["OnMembershipTerminate"].ActionParametersXmlSqlParsedString + "', ");

                //sqlStatement.Append ("'" + events["OnMembershipTerminate"].Description + "', ");


                sqlStatement.Append("'" + ExtendedPropertiesSql + "', ");

                sqlStatement.Append("'" + modifiedAccountInfo.SecurityAuthorityNameSql + "', '" + modifiedAccountInfo.UserAccountIdSql + "', '" + modifiedAccountInfo.UserAccountNameSql + "'");


                success = application.EnvironmentDatabase.ExecuteSqlStatement(sqlStatement.ToString(), 0);

                if (!success)
                {
                    application.SetLastException(application.EnvironmentDatabase.LastException);

                    throw application.EnvironmentDatabase.LastException;
                }


                SetIdentity();


                #region Demographic Criteria

                if (success)
                {
                    criteriaIds = String.Empty;

                    foreach (ConditionCriteria.ConditionCriteriaDemographic currentCriteria in demographicCriteria)
                    {
                        currentCriteria.ConditionId = id;

                        success = success && currentCriteria.Save(application);

                        criteriaIds = criteriaIds + currentCriteria.Id.ToString() + ",";

                        if (!success)
                        {
                            break;
                        }
                    }

                    if (success)
                    {
                        sqlStatement = new StringBuilder("DELETE FROM ConditionCriteriaDemographic WHERE ConditionId = " + id.ToString());

                        if (criteriaIds.Length != 0)
                        {
                            criteriaIds = criteriaIds.Substring(0, criteriaIds.Length - 1);

                            sqlStatement.Append(" AND ConditionCriteriaDemographicId NOT IN (" + criteriaIds + ")");
                        }

                        success = application.EnvironmentDatabase.ExecuteSqlStatement(sqlStatement.ToString(), 0);
                    }
                }

                #endregion


                #region Event Criteria

                if (success)
                {
                    criteriaIds = String.Empty;

                    foreach (ConditionCriteria.ConditionCriteriaEvent currentCriteria in eventCriteria)
                    {
                        currentCriteria.ConditionId = id;

                        success = success && currentCriteria.Save(application);

                        criteriaIds = criteriaIds + currentCriteria.Id.ToString() + ",";

                        if (!success)
                        {
                            break;
                        }
                    }

                    if (success)
                    {
                        sqlStatement = new StringBuilder("DELETE FROM ConditionCriteriaEvent WHERE ConditionId = " + id.ToString());

                        if (criteriaIds.Length != 0)
                        {
                            criteriaIds = criteriaIds.Substring(0, criteriaIds.Length - 1);

                            sqlStatement.Append(" AND ConditionCriteriaEventId NOT IN (" + criteriaIds + ")");
                        }

                        success = application.EnvironmentDatabase.ExecuteSqlStatement(sqlStatement.ToString(), 0);
                    }
                }

                #endregion


                if (!success)
                {
                    application.SetLastException(application.EnvironmentDatabase.LastException);

                    throw application.EnvironmentDatabase.LastException;
                }


                success = true;

                application.EnvironmentDatabase.CommitTransaction();
            }

            catch (Exception applicationException) {
                success = false;

                application.EnvironmentDatabase.RollbackTransaction();

                application.SetLastException(applicationException);
            }

            return(success);
        }
Exemplo n.º 3
0
        public override System.Xml.XmlDocument XmlSerialize()
        {
            System.Xml.XmlDocument document = base.XmlSerialize();

            System.Xml.XmlNode propertiesNode = document.ChildNodes[1].ChildNodes[0];


            #region Properties

            CommonFunctions.XmlDocumentAppendPropertyNode(document, propertiesNode, "ConditionClassId", conditionClassId.ToString());

            CommonFunctions.XmlDocumentAppendPropertyNode(document, propertiesNode, "ConditionClassName", ((ConditionClass != null) ? ConditionClass.Name : String.Empty));

            #endregion


            #region Criteria

            System.Xml.XmlNode criteriaNode = document.CreateElement("ConditionCriteria");

            document.LastChild.AppendChild(criteriaNode);

            foreach (ConditionCriteria.ConditionCriteriaDemographic currentDemographicCriteria in demographicCriteria)
            {
                criteriaNode.AppendChild(document.ImportNode(currentDemographicCriteria.XmlSerialize().LastChild, true));
            }

            foreach (ConditionCriteria.ConditionCriteriaEvent currentEventCriteria in eventCriteria)
            {
                criteriaNode.AppendChild(document.ImportNode(currentEventCriteria.XmlSerialize().LastChild, true));
            }

            #endregion


            #region Condition Events

            System.Xml.XmlNode conditionEventNode = document.CreateElement("ConditionEvents");

            document.LastChild.AppendChild(conditionEventNode);

            foreach (String currentConditionEventName in events.Keys)
            {
                if (events[currentConditionEventName] != null)
                {
                    System.Xml.XmlNode conditionEventActionNode = document.CreateElement(currentConditionEventName);

                    conditionEventActionNode.AppendChild(document.ImportNode(events[currentConditionEventName].XmlSerialize().LastChild, true));

                    conditionEventNode.AppendChild(conditionEventActionNode);
                }
            }

            #endregion


            #region Dependencies Nodes

            System.Xml.XmlNode dependenciesNode = document.CreateElement("Dependencies");

            document.LastChild.InsertBefore(dependenciesNode, propertiesNode);

            if (ConditionClass != null)
            {
                dependenciesNode.AppendChild(document.ImportNode(ConditionClass.XmlSerialize().LastChild, true));
            }

            #endregion


            return(document);
        }