/// <summary>
        ///
        /// </summary>
        void RunStaffPersonalConsumer()
        {
            IStaffPersonalConsumer staffPersonalConsumer = new StaffPersonalConsumer("HITS", null, "0EE41AE6-C43F-11E3-9050-E0F4DBD909AB", "HITS");

            staffPersonalConsumer.Register();

            try
            {
                EqualCondition condition = new EqualCondition()
                {
                    Left = "TeachingGroups", Right = "597ad3fe-47e7-4b2c-b919-a93c564d19d0"
                };
                IList <EqualCondition> conditions = new List <EqualCondition>();
                conditions.Add(condition);
                ICollection <StaffPersonal> staffPersonals = staffPersonalConsumer.Retrieve(conditions);

                foreach (StaffPersonal staffPersonal in staffPersonals)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Staff name is " + staffPersonal.PersonInfo.Name.GivenName + " " + staffPersonal.PersonInfo.Name.FamilyName);
                    }
                }
            }
            finally
            {
                staffPersonalConsumer.Unregister();
            }
        }
        void RunStaffPersonalConsumer()
        {
            StaffPersonalConsumer staffPersonalConsumer = new StaffPersonalConsumer(SettingsManager.ConsumerSettings.ApplicationKey, SettingsManager.ConsumerSettings.InstanceId, SettingsManager.ConsumerSettings.UserToken, SettingsManager.ConsumerSettings.SolutionId);

            staffPersonalConsumer.Register();

            try
            {
                EqualCondition condition = new EqualCondition()
                {
                    Left = "TeachingGroups", Right = "597ad3fe-47e7-4b2c-b919-a93c564d19d0"
                };
                IList <EqualCondition> conditions = new List <EqualCondition>();
                conditions.Add(condition);
                IEnumerable <StaffPersonal> staffPersonals = staffPersonalConsumer.QueryByServicePath(conditions);

                foreach (StaffPersonal staffPersonal in staffPersonals)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Staff name is " + staffPersonal.PersonInfo.Name.GivenName + " " + staffPersonal.PersonInfo.Name.FamilyName);
                    }
                }

                if (log.IsInfoEnabled)
                {
                    log.Info("Staff count is " + staffPersonals.Count());
                }
            }
            finally
            {
                staffPersonalConsumer.Unregister();
            }
        }
        /// <summary>
        /// GET api/{object1}/{id1}/{controller}
        /// GET api/{object1}/{id1}/{object2}/{id2}/{controller}
        /// GET api/{object1}/{id1}/{object2}/{id2}/{object3}/{id3}/{controller}
        /// </summary>
        /// <param name="object1"></param>
        /// <param name="id1"></param>
        /// <param name="object2"></param>
        /// <param name="id2"></param>
        /// <param name="object3"></param>
        /// <param name="id3"></param>
        /// <returns>Objects that meet the associated object and ID combinations.</returns>
        public virtual List <T> Get(string object1, string id1, string object2 = null, string id2 = null, string object3 = null, string id3 = null)
        {
            if (!authService.VerifyAuthenticationHeader(Request.Headers.Authorization))
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }

            List <T> item;

            try
            {
                EqualCondition condition = new EqualCondition()
                {
                    Left = object1, Right = id1
                };
                IList <EqualCondition> conditions = new List <EqualCondition>()
                {
                    condition
                };

                if (!string.IsNullOrWhiteSpace(object2))
                {
                    conditions.Add(new EqualCondition()
                    {
                        Left = object2, Right = id2
                    });

                    if (!string.IsNullOrWhiteSpace(object3))
                    {
                        conditions.Add(new EqualCondition()
                        {
                            Left = object3, Right = id3
                        });
                    }
                }

                item = (List <T>)service.Retrieve(conditions);
            }
            catch (Exception e)
            {
                string errorMessage = "The GET request (based on Service Path parameters) failed for a " + typeof(T).Name + " due to the following error:\n " + e.Message;
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage));
            }

            if (item == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            return(item);
        }
Пример #4
0
        /// <summary>
        /// 等于条件解析;如果条件值为NULL或空字符串时则判断字段的空字符串或NULL值
        /// </summary>
        /// <param name="condition">需要解析的条件对象</param>
        /// <returns>返回解析后的条件字符串</returns>
        protected override string EqualParse(EqualCondition condition)
        {
            StringBuilder conditionStr = new StringBuilder(" ");
            string        queryColName = condition.SearchColumn.CurrentSearcher.TableName + "." + condition.SearchColumn.ColumnName;

            if (string.IsNullOrEmpty(condition.SearchColumn.ConditionString))
            {
                conditionStr.Append(queryColName);
            }
            else
            {
                conditionStr.Append(condition.SearchColumn.ConditionString.Replace(SQLPlaceholder.ColName, queryColName));
            }

            conditionStr.Append(" = ");

            if (condition.ParamValue is SearchColumn)
            {
                SearchColumn tmpColumn    = (SearchColumn)condition.ParamValue;
                string       valueColName = tmpColumn.CurrentSearcher.TableName + "." + tmpColumn.ColumnName;
                conditionStr.Append(valueColName);
            }
            else
            {
                if (condition.ParamValue != null && !condition.ParamValue.ToString().Equals(string.Empty))
                {
                    string paramName = "P" + Guid.NewGuid().ToString().ToLower().Replace("-", "");
                    conditionStr.Append("@" + paramName);
                    ParamCollection.Add(new MySqlParameter(paramName, condition.ParamValue));
                }
                else
                {
                    conditionStr.Insert(0, " (");
                    conditionStr.Append("'' ");
                    conditionStr.Append(" OR ");
                    conditionStr.Append(queryColName);
                    conditionStr.Append(" IS NULL) ");
                }
            }

            conditionStr.Append(" ");

            return(conditionStr.ToString());
        }
Пример #5
0
        private void LinkEqualVar(string[] condition, Variable _var1, Variable _var2, Variable _var3)
        {
            Variable var1 = new Variable();

            if (condition[0] == "$1")
            {
                var1 = _var1;
            }
            else if (condition[0] == "$2")
            {
                var1 = _var2;
            }
            else if (condition[0] == "$3")
            {
                var1 = _var3;
            }
            else
            {
                var1 = new Variable().Set(condition[0]);
            }

            Variable var2 = new Variable();

            if (condition[1] == "$1")
            {
                var2 = _var1;
            }
            else if (condition[1] == "$2")
            {
                var2 = _var2;
            }
            else if (condition[1] == "$3")
            {
                var2 = _var3;
            }
            else
            {
                var2 = new Variable().Set(condition[1]);
            }

            var newCondition = new EqualCondition(var1, var2);

            conditions.Add(newCondition as ICondition);
        }
Пример #6
0
        /// <summary>
        /// 等于条件解析;如果条件值为NULL或空字符串时则判断字段的空字符串或NULL值
        /// </summary>
        /// <param name="condition">需要解析的条件对象</param>
        /// <returns>返回解析后的条件字符串</returns>
        protected override string EqualParse(EqualCondition condition)
        {
            StringBuilder conditionStr = new StringBuilder(" ");
            string queryColName = condition.SearchColumn.CurrentSearcher.TableName + "." + condition.SearchColumn.ColumnName;

            if (string.IsNullOrEmpty(condition.SearchColumn.ConditionString))
            {
                conditionStr.Append(queryColName);
            }
            else
            {
                conditionStr.Append(condition.SearchColumn.ConditionString.Replace(SQLPlaceholder.ColName, queryColName));
            }

            conditionStr.Append(" = ");

            if (condition.ParamValue is SearchColumn)
            {
                SearchColumn tmpColumn = (SearchColumn)condition.ParamValue;
                string valueColName = tmpColumn.CurrentSearcher.TableName + "." + tmpColumn.ColumnName;
                conditionStr.Append(valueColName);
            }
            else
            {
                if (condition.ParamValue != null && !condition.ParamValue.ToString().Equals(string.Empty))
                {
                    string paramName = "P" + Guid.NewGuid().ToString().ToLower().Replace("-", "");
                    conditionStr.Append(":" + paramName);
                    ParamCollection.Add(new DBParam(paramName, condition.ParamValue));
                }
                else
                {
                    conditionStr.Insert(0, " (");
                    conditionStr.Append("'' ");
                    conditionStr.Append(" OR ");
                    conditionStr.Append(queryColName);
                    conditionStr.Append(" IS NULL) ");
                }
            }

            conditionStr.Append(" ");

            return conditionStr.ToString();
        }
        void RunStaffPersonalConsumer()
        {
            StaffPersonalConsumer staffPersonalConsumer = new StaffPersonalConsumer(SettingsManager.ConsumerSettings.ApplicationKey, SettingsManager.ConsumerSettings.InstanceId, SettingsManager.ConsumerSettings.UserToken, SettingsManager.ConsumerSettings.SolutionId);

            staffPersonalConsumer.Register();

            try
            {
                EqualCondition condition = new EqualCondition()
                {
                    Left = "TeachingGroups", Right = "597ad3fe-47e7-4b2c-b919-a93c564d19d0"
                };
                IList <EqualCondition> conditions = new List <EqualCondition>();
                conditions.Add(condition);
                IEnumerable <StaffPersonal> staffPersonals = staffPersonalConsumer.QueryByServicePath(conditions);

                if (log.IsInfoEnabled)
                {
                    log.Info("Staff count is " + (staffPersonals == null ? 0 : staffPersonals.Count()));
                }

                if (staffPersonals != null)
                {
                    foreach (StaffPersonal staffPersonal in staffPersonals)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info("Staff name is " + staffPersonal.PersonInfo.Name.GivenName + " " + staffPersonal.PersonInfo.Name.FamilyName);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Error running the StaffPersonal Consumer against HITS.\n" + ExceptionUtils.InferErrorResponseMessage(e), e);
                }
            }
            finally
            {
                staffPersonalConsumer.Unregister();
            }
        }
Пример #8
0
        private void LinkEqualVar(string[] condition, Ray _var1, Ray _var2, Ray _var3)
        {
            Ray var1 = new Ray();

            if (condition[0] == "$1")
            {
                var1 = _var1;
            }
            else if (condition[0] == "$2")
            {
                var1 = _var2;
            }
            else if (condition[0] == "$3")
            {
                var1 = _var3;
            }
            else
            {
                var1 = new Ray().Set(condition[0]);
            }

            Ray var2 = new Ray();

            if (condition[1] == "$1")
            {
                var2 = _var1;
            }
            else if (condition[1] == "$2")
            {
                var2 = _var2;
            }
            else if (condition[1] == "$3")
            {
                var2 = _var3;
            }
            else
            {
                var2 = new Ray().Set(condition[1]);
            }

            var newCondition = new EqualCondition(var1, var2);

            conditions.Add(newCondition as ICondition);
        }
Пример #9
0
        /// <summary>
        /// 等于条件
        /// </summary>
        /// <param name="column">查询字段对象</param>
        /// <param name="paramVal">比较的值</param>
        /// <returns>返回等于条件对象</returns>
        public static EqualCondition Equal(SearchColumn column, object paramVal)
        {
            EqualCondition cond = new EqualCondition(column, paramVal);

            return(cond);
        }
Пример #10
0
 public IfStatement(EqualCondition cond, BlockStatement body, BlockStatement elseBody)
 {
     Condition = cond;
     Body      = body;
     ElseBody  = elseBody;
 }
        public void Test()
        {
            var condition = new EqualCondition("Name", "@Name");

            Assert.Equal("Name=@Name", condition.GetCondition());
        }
Пример #12
0
 /// <summary>
 /// 等于条件
 /// </summary>
 /// <param name="column">查询字段对象</param>
 /// <param name="paramVal">比较的值</param>
 /// <returns>返回等于条件对象</returns>
 public static EqualCondition Equal(SearchColumn column, object paramVal)
 {
     EqualCondition cond = new EqualCondition(column, paramVal);
     return cond;
 }
Пример #13
0
 /// <summary>
 /// 等于条件
 /// </summary>
 /// <param name="relation">条件关系</param>
 /// <param name="paramVal">比较的值</param>
 /// <returns>返回等于条件对象</returns>
 public static EqualCondition Equal(ConditionRelation relation, object paramVal)
 {
     EqualCondition cond = new EqualCondition(relation, paramVal);
     return cond;
 }
Пример #14
0
 /// <summary>
 /// 等于条件
 /// </summary>
 /// <param name="paramVal">比较的值</param>
 /// <returns>返回等于条件对象</returns>
 public static EqualCondition Equal(object paramVal)
 {
     EqualCondition cond = new EqualCondition(paramVal);
     return cond;
 }
Пример #15
0
        /// <summary>
        /// 等于条件
        /// </summary>
        /// <param name="paramVal">比较的值</param>
        /// <returns>返回等于条件对象</returns>
        public static EqualCondition Equal(object paramVal)
        {
            EqualCondition cond = new EqualCondition(paramVal);

            return(cond);
        }
        void RunLearnerPersonalConsumer()
        {
            LearnerPersonalConsumer learnerPersonalConsumer = new LearnerPersonalConsumer(SettingsManager.ConsumerSettings.ApplicationKey);

            learnerPersonalConsumer.Register();
            if (log.IsInfoEnabled)
            {
                log.Info("Registered the Consumer.");
            }

            try
            {
                // Retrieve Bart Simpson using QBE.
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Retrieve Bart Simpson using QBE.");
                }
                LearnerPersonal exampleLearner = new LearnerPersonal {
                    PersonalInformation = new PersonalInformationType
                    {
                        Name = new NameType
                        {
                            FamilyName = "Simpson",
                            GivenName  = "Bart"
                        }
                    }
                };
                IEnumerable <LearnerPersonal> filteredLearners = learnerPersonalConsumer.QueryByExample(exampleLearner);

                foreach (LearnerPersonal learner in filteredLearners)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Filtered learner name is " + learner.PersonalInformation.Name.GivenName + " " + learner.PersonalInformation.Name.FamilyName);
                    }
                }

                // Create a new learner.
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Create a new learner.");
                }
                LearnerPersonal newLearner          = ConsumerApp.CreateBruceWayne();
                LearnerPersonal retrievedNewLearner = learnerPersonalConsumer.Create(newLearner);
                if (log.IsInfoEnabled)
                {
                    log.Info("Created new learner " + newLearner.PersonalInformation.Name.GivenName + " " + newLearner.PersonalInformation.Name.FamilyName);
                }

                // Create multiple new learners.
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Create multiple new learners.");
                }
                List <LearnerPersonal> newLearners            = CreateLearners(5);
                MultipleCreateResponse multipleCreateResponse = learnerPersonalConsumer.Create(newLearners);
                int count = 0;

                foreach (CreateStatus status in multipleCreateResponse.StatusRecords)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Create status code is " + status.StatusCode);
                    }
                    newLearners[count++].RefId = status.Id;
                }

                // Update multiple learners.
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Update multiple learners.");
                }
                foreach (LearnerPersonal learner in newLearners)
                {
                    learner.PersonalInformation.Name.GivenName += "o";
                }

                MultipleUpdateResponse multipleUpdateResponse = learnerPersonalConsumer.Update(newLearners);

                foreach (UpdateStatus status in multipleUpdateResponse.StatusRecords)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Update status code is " + status.StatusCode);
                    }
                }

                // Delete multiple learners.
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Delete multiple learners.");
                }
                ICollection <string> refIds = new List <string>();

                foreach (CreateStatus status in multipleCreateResponse.StatusRecords)
                {
                    refIds.Add(status.Id);
                }

                MultipleDeleteResponse multipleDeleteResponse = learnerPersonalConsumer.Delete(refIds);

                foreach (DeleteStatus status in multipleDeleteResponse.StatusRecords)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Delete status code is " + status.StatusCode);
                    }
                }

                // Retrieve all learners from zone "Gov" and context "Curr".
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Retrieve all learners from zone \"Gov\" and context \"Curr\".");
                }
                IEnumerable <LearnerPersonal> learners = learnerPersonalConsumer.Query(zoneId: "Gov", contextId: "Curr");

                foreach (LearnerPersonal learner in learners)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Learner name is " + learner.PersonalInformation.Name.GivenName + " " + learner.PersonalInformation.Name.FamilyName);
                    }
                }

                if (learners.Count() > 1)
                {
                    // Retrieve a single learner.
                    if (log.IsInfoEnabled)
                    {
                        log.Info("*** Retrieve a single learner.");
                    }
                    string          learnerId     = learners.ElementAt(1).RefId;
                    LearnerPersonal secondLearner = learnerPersonalConsumer.Query(learnerId);
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Name of second learner is " + secondLearner.PersonalInformation.Name.GivenName + " " + secondLearner.PersonalInformation.Name.FamilyName);
                    }

                    // Update that learner and confirm.
                    if (log.IsInfoEnabled)
                    {
                        log.Info("*** Update that learner and confirm.");
                    }
                    secondLearner.PersonalInformation.Name.GivenName  = "Homer";
                    secondLearner.PersonalInformation.Name.FamilyName = "Simpson";
                    learnerPersonalConsumer.Update(secondLearner);
                    secondLearner = learnerPersonalConsumer.Query(learnerId);
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Name of second learner has been changed to " + secondLearner.PersonalInformation.Name.GivenName + " " + secondLearner.PersonalInformation.Name.FamilyName);
                    }

                    // Delete that learner and confirm.
                    if (log.IsInfoEnabled)
                    {
                        log.Info("*** Delete that learner and confirm.");
                    }
                    learnerPersonalConsumer.Delete(learnerId);
                    LearnerPersonal deletedLearner = learnerPersonalConsumer.Query(learnerId);
                    bool            learnerDeleted = (deletedLearner == null ? true : false);

                    if (learnerDeleted)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info("Learner " + secondLearner.PersonalInformation.Name.GivenName + " " + secondLearner.PersonalInformation.Name.FamilyName + " was successfully deleted.");
                        }
                    }
                    else
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info("Learner " + secondLearner.PersonalInformation.Name.GivenName + " " + secondLearner.PersonalInformation.Name.FamilyName + " was NOT deleted.");
                        }
                    }
                }

                // Retrieve learners based on Teaching Group using Service Paths.
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Retrieve learners based on Teaching Group using Service Paths.");
                }
                EqualCondition condition = new EqualCondition()
                {
                    Left = "TeachingGroups", Right = "597ad3fe-47e7-4b2c-b919-a93c564d19d0"
                };
                IList <EqualCondition> conditions = new List <EqualCondition>();
                conditions.Add(condition);
                IEnumerable <LearnerPersonal> teachingGroupLearners = learnerPersonalConsumer.QueryByServicePath(conditions);

                foreach (LearnerPersonal learner in teachingGroupLearners)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Learner name is " + learner.PersonalInformation.Name.GivenName + " " + learner.PersonalInformation.Name.FamilyName);
                    }
                }
            }
            catch (Exception e)
            {
                //if (log.IsInfoEnabled) log.Fatal(e.StackTrace);
                throw new Exception(this.GetType().FullName, e);
            }
            finally
            {
                learnerPersonalConsumer.Unregister();
                if (log.IsInfoEnabled)
                {
                    log.Info("Unregistered the Consumer.");
                }
            }
        }
Пример #17
0
        private void RunStudentPersonalConsumer()
        {
            StudentPersonalConsumer studentPersonalConsumer = new StudentPersonalConsumer(
                SettingsManager.ConsumerSettings.ApplicationKey,
                SettingsManager.ConsumerSettings.InstanceId,
                SettingsManager.ConsumerSettings.UserToken,
                SettingsManager.ConsumerSettings.SolutionId);

            studentPersonalConsumer.Register();
            if (log.IsInfoEnabled)
            {
                log.Info("Registered the Consumer.");
            }

            try
            {
                IEnumerable <StudentPersonal> queriedStudents = studentPersonalConsumer.DynamicQuery("[@id=1234]");

                foreach (StudentPersonal student in queriedStudents)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Queried student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName);
                    }
                }

                // Retrieve Bart Simpson using QBE.
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Retrieve Bart Simpson using QBE.");
                }
                NameOfRecordType name = new NameOfRecordType {
                    FamilyName = "Simpson", GivenName = "Bart"
                };
                PersonInfoType personInfo = new PersonInfoType {
                    Name = name
                };
                StudentPersonal studentPersonal = new StudentPersonal {
                    PersonInfo = personInfo
                };
                IEnumerable <StudentPersonal> filteredStudents = studentPersonalConsumer.QueryByExample(studentPersonal);

                foreach (StudentPersonal student in filteredStudents)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Filtered student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName);
                    }
                }

                // Create a new student.
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Create a new student.");
                }
                string[] text = new string[]
                {
                    @"
                        <MedicalCondition>
                            <ConditionID>Unique Medical Condition ID</ConditionID>
                            <Condition>Condition</Condition>
                            <Severity>Condition Severity</Severity>
                            <Details>Condition Details</Details>
                        </MedicalCondition>
                    "
                };
                SIF_ExtendedElementsTypeSIF_ExtendedElement extendedElement = new SIF_ExtendedElementsTypeSIF_ExtendedElement {
                    Name = "MedicalConditions", Text = text
                };
                SIF_ExtendedElementsTypeSIF_ExtendedElement[] extendedElements = new SIF_ExtendedElementsTypeSIF_ExtendedElement[] { extendedElement };
                NameOfRecordType newStudentName = new NameOfRecordType {
                    FamilyName = "Wayne", GivenName = "Bruce", Type = NameOfRecordTypeType.LGL
                };
                PersonInfoType newStudentInfo = new PersonInfoType {
                    Name = newStudentName
                };
                string          studentID  = Guid.NewGuid().ToString();
                StudentPersonal newStudent = new StudentPersonal {
                    RefId = studentID, LocalId = "555", PersonInfo = newStudentInfo, SIF_ExtendedElements = extendedElements
                };

                try
                {
                    StudentPersonal retrievedNewStudent = studentPersonalConsumer.Create(newStudent, true);
                    if (log.IsInfoEnabled)
                    {
                        log.Info($"Created new student {newStudent.PersonInfo.Name.GivenName} {newStudent.PersonInfo.Name.FamilyName} with ID of {studentID}.");
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info($"Access to create a new student is rejected.");
                    }
                }

                // Create multiple new students.
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Create multiple new students.");
                }
                List <StudentPersonal> newStudents = CreateStudents(5);

                try
                {
                    MultipleCreateResponse multipleCreateResponse = studentPersonalConsumer.Create(newStudents);
                    int count = 0;

                    foreach (CreateStatus status in multipleCreateResponse.StatusRecords)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info("Create status code is " + status.StatusCode);
                        }
                        newStudents[count++].RefId = status.Id;
                    }

                    // Update multiple students.
                    if (log.IsInfoEnabled)
                    {
                        log.Info("*** Update multiple students.");
                    }
                    foreach (StudentPersonal student in newStudents)
                    {
                        student.PersonInfo.Name.GivenName += "o";
                    }

                    try
                    {
                        MultipleUpdateResponse multipleUpdateResponse = studentPersonalConsumer.Update(newStudents);

                        foreach (UpdateStatus status in multipleUpdateResponse.StatusRecords)
                        {
                            if (log.IsInfoEnabled)
                            {
                                log.Info("Update status code is " + status.StatusCode);
                            }
                        }
                    }
                    catch (UnauthorizedAccessException)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info($"Access to update multiple students is rejected.");
                        }
                    }

                    // Delete multiple students.
                    if (log.IsInfoEnabled)
                    {
                        log.Info("*** Delete multiple students.");
                    }
                    ICollection <string> refIds = new List <string>();

                    foreach (CreateStatus status in multipleCreateResponse.StatusRecords)
                    {
                        refIds.Add(status.Id);
                    }

                    try
                    {
                        MultipleDeleteResponse multipleDeleteResponse = studentPersonalConsumer.Delete(refIds);

                        foreach (DeleteStatus status in multipleDeleteResponse.StatusRecords)
                        {
                            if (log.IsInfoEnabled)
                            {
                                log.Info("Delete status code is " + status.StatusCode);
                            }
                        }
                    }
                    catch (UnauthorizedAccessException)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info($"Access to delete multiple students is rejected.");
                        }
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info($"Access to create multiple new students is rejected.");
                    }
                }

                // Retrieve all students from zone "Gov" and context "Curr".
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Retrieve all students from zone \"Gov\" and context \"Curr\".");
                }
                IEnumerable <StudentPersonal> students = studentPersonalConsumer.Query(zoneId: "Gov", contextId: "Curr");

                foreach (StudentPersonal student in students)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName);
                    }
                }

                if (students.Count() > 1)
                {
                    // Retrieve a single student.
                    if (log.IsInfoEnabled)
                    {
                        log.Info("*** Retrieve a single student.");
                    }
                    string          studentId     = students.ElementAt(1).RefId;
                    StudentPersonal secondStudent = studentPersonalConsumer.Query(studentId);
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Name of second student is " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName);
                    }

                    // Update that student and confirm.
                    if (log.IsInfoEnabled)
                    {
                        log.Info("*** Update that student and confirm.");
                    }
                    secondStudent.PersonInfo.Name.GivenName  = "Homer";
                    secondStudent.PersonInfo.Name.FamilyName = "Simpson";

                    try
                    {
                        studentPersonalConsumer.Update(secondStudent);
                        secondStudent = studentPersonalConsumer.Query(studentId);
                        if (log.IsInfoEnabled)
                        {
                            log.Info("Name of second student has been changed to " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName);
                        }
                    }
                    catch (UnauthorizedAccessException)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info($"Access to update a student is rejected.");
                        }
                    }

                    // Delete that student and confirm.
                    if (log.IsInfoEnabled)
                    {
                        log.Info("*** Delete that student and confirm.");
                    }

                    try
                    {
                        studentPersonalConsumer.Delete(studentId);
                        StudentPersonal deletedStudent = studentPersonalConsumer.Query(studentId);
                        bool            studentDeleted = (deletedStudent == null ? true : false);

                        if (studentDeleted)
                        {
                            if (log.IsInfoEnabled)
                            {
                                log.Info("Student " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName + " was successfully deleted.");
                            }
                        }
                        else
                        {
                            if (log.IsInfoEnabled)
                            {
                                log.Info("Student " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName + " was NOT deleted.");
                            }
                        }
                    }
                    catch (UnauthorizedAccessException)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info($"Access to delete a student is rejected.");
                        }
                    }
                }

                // Retrieve students based on Teaching Group using Service Paths.
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Retrieve students based on Teaching Group using Service Paths.");
                }
                EqualCondition condition = new EqualCondition()
                {
                    Left = "TeachingGroups", Right = "597ad3fe-47e7-4b2c-b919-a93c564d19d0"
                };
                IList <EqualCondition> conditions = new List <EqualCondition>
                {
                    condition
                };

                try
                {
                    IEnumerable <StudentPersonal> teachingGroupStudents = studentPersonalConsumer.QueryByServicePath(conditions);

                    foreach (StudentPersonal student in teachingGroupStudents)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName);
                        }

                        if (student.SIF_ExtendedElements != null && student.SIF_ExtendedElements.Length > 0)
                        {
                            foreach (SIF_ExtendedElementsTypeSIF_ExtendedElement element in student.SIF_ExtendedElements)
                            {
                                foreach (string content in element.Text)
                                {
                                    if (log.IsInfoEnabled)
                                    {
                                        log.Info("Extended element text is ...\n" + content);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Access to query students by Service Path TeachingGroups/{}/StudentPersonals is rejected.");
                    }
                }

                // Retrieve student changes since a particular point as defined by the Changes Since marker.
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Retrieve student changes since a particular point as defined by the Changes Since marker.");
                }
                string changesSinceMarker = studentPersonalConsumer.GetChangesSinceMarker();
                IEnumerable <StudentPersonal> changedStudents = studentPersonalConsumer.QueryChangesSince(changesSinceMarker, out string nextChangesSinceMarker);
                if (log.IsInfoEnabled)
                {
                    log.Info("Iteration 1 - Student changes based on Changes Since marker - " + changesSinceMarker);
                }

                if (changedStudents == null || changedStudents.Count() == 0)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("No student changes");
                    }
                }
                else
                {
                    foreach (StudentPersonal student in changedStudents)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName);
                        }
                    }
                }

                changesSinceMarker     = nextChangesSinceMarker;
                nextChangesSinceMarker = null;
                changedStudents        = studentPersonalConsumer.QueryChangesSince(changesSinceMarker, out nextChangesSinceMarker);
                if (log.IsInfoEnabled)
                {
                    log.Info("Iteration 2 - Student changes based on Changes Since marker - " + changesSinceMarker);
                }

                if (changedStudents == null || changedStudents.Count() == 0)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("No student changes");
                    }
                }
                else
                {
                    foreach (StudentPersonal student in changedStudents)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName);
                        }
                    }
                }

                changesSinceMarker     = nextChangesSinceMarker;
                nextChangesSinceMarker = null;
                changedStudents        = studentPersonalConsumer.QueryChangesSince(changesSinceMarker, out nextChangesSinceMarker);
                if (log.IsInfoEnabled)
                {
                    log.Info("Iteration 3 - Student changes based on Changes Since marker - " + changesSinceMarker);
                }

                if (changedStudents == null || changedStudents.Count() == 0)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("No student changes");
                    }
                }
                else
                {
                    foreach (StudentPersonal student in changedStudents)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName);
                        }
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
                if (log.IsInfoEnabled)
                {
                    log.Info($"Access to query students is rejected.");
                }
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Error running the StudentPersonal Consumer.\n" + ExceptionUtils.InferErrorResponseMessage(e), e);
                }
            }
            finally
            {
                studentPersonalConsumer.Unregister();
                if (log.IsInfoEnabled)
                {
                    log.Info("Unregistered the Consumer.");
                }
            }
        }
Пример #18
0
        /// <summary>
        ///
        /// </summary>
        void RunStudentPersonalConsumer()
        {
            IStudentPersonalConsumer studentPersonalConsumer = new StudentPersonalConsumer("Sif3DemoApp");

            studentPersonalConsumer.Register();
            if (log.IsInfoEnabled)
            {
                log.Info("Registered the Consumer.");
            }

            try
            {
                // Retrieve Bart Simpson.
                Name name = new Name {
                    FamilyName = "Simpson", GivenName = "Bart"
                };
                PersonInfo personInfo = new PersonInfo {
                    Name = name
                };
                StudentPersonal studentPersonal = new StudentPersonal {
                    PersonInfo = personInfo
                };
                ICollection <StudentPersonal> filteredStudents = studentPersonalConsumer.Retrieve(studentPersonal);

                foreach (StudentPersonal student in filteredStudents)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Filtered student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName);
                    }
                }

                // Create and then retrieve a new student.
                Name newStudentName = new Name()
                {
                    FamilyName = "Wayne", GivenName = "Bruce", Type = NameType.LGL
                };
                PersonInfo newStudentInfo = new PersonInfo()
                {
                    Name = newStudentName
                };
                StudentPersonal newStudent = new StudentPersonal()
                {
                    LocalId = "555", PersonInfo = newStudentInfo
                };
                Guid newStudentId = studentPersonalConsumer.Create(newStudent);
                if (log.IsInfoEnabled)
                {
                    log.Info("Created new student " + newStudent.PersonInfo.Name.GivenName + " " + newStudent.PersonInfo.Name.FamilyName);
                }
                StudentPersonal retrievedNewStudent = studentPersonalConsumer.Retrieve(newStudentId);
                if (log.IsInfoEnabled)
                {
                    log.Info("Retrieved new student " + retrievedNewStudent.PersonInfo.Name.GivenName + " " + retrievedNewStudent.PersonInfo.Name.FamilyName);
                }

                // Retrieve all students.
                ICollection <StudentPersonal> students = studentPersonalConsumer.Retrieve();

                foreach (StudentPersonal student in students)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName);
                    }
                }

                // Retrieve a single student.
                Guid            studentId     = students.ElementAt(1).Id;
                StudentPersonal secondStudent = studentPersonalConsumer.Retrieve(studentId);
                if (log.IsInfoEnabled)
                {
                    log.Info("Name of second student is " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName);
                }

                // Update that student and confirm.
                secondStudent.PersonInfo.Name.GivenName  = "Homer";
                secondStudent.PersonInfo.Name.FamilyName = "Simpson";
                studentPersonalConsumer.Update(secondStudent);
                secondStudent = studentPersonalConsumer.Retrieve(studentId);
                if (log.IsInfoEnabled)
                {
                    log.Info("Name of second student has been changed to " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName);
                }

                // Delete that student and confirm.
                studentPersonalConsumer.Delete(studentId);
                students = studentPersonalConsumer.Retrieve();
                bool studentDeleted = true;

                foreach (StudentPersonal student in students)
                {
                    if (studentId == student.Id)
                    {
                        studentDeleted = false;
                        break;
                    }
                }

                if (studentDeleted)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Student " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName + " was successfully deleted.");
                    }
                }
                else
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Student " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName + " was NOT deleted.");
                    }
                }

                // Retrieve students based on Teaching Group.
                EqualCondition condition = new EqualCondition()
                {
                    Left = "TeachingGroups", Right = "597ad3fe-47e7-4b2c-b919-a93c564d19d0"
                };
                IList <EqualCondition> conditions = new List <EqualCondition>();
                conditions.Add(condition);
                ICollection <StudentPersonal> teachingGroupStudents = studentPersonalConsumer.Retrieve(conditions);

                foreach (StudentPersonal student in teachingGroupStudents)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                studentPersonalConsumer.Unregister();
                if (log.IsInfoEnabled)
                {
                    log.Info("Unregistered the Consumer.");
                }
            }
        }
Пример #19
0
        /// <summary>
        /// 等于条件
        /// </summary>
        /// <param name="relation">条件关系</param>
        /// <param name="paramVal">比较的值</param>
        /// <returns>返回等于条件对象</returns>
        public static EqualCondition Equal(ConditionRelation relation, object paramVal)
        {
            EqualCondition cond = new EqualCondition(relation, paramVal);

            return(cond);
        }
Пример #20
0
        void RunStudentPersonalConsumer()
        {
            StudentPersonalConsumer studentPersonalConsumer = new StudentPersonalConsumer("Sif3DemoApp");

            studentPersonalConsumer.Register();
            if (log.IsInfoEnabled)
            {
                log.Info("Registered the Consumer.");
            }

            try
            {
                // Retrieve Bart Simpson using QBE.
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Retrieve Bart Simpson using QBE.");
                }
                NameOfRecordType name = new NameOfRecordType {
                    FamilyName = "Simpson", GivenName = "Bart"
                };
                PersonInfoType personInfo = new PersonInfoType {
                    Name = name
                };
                StudentPersonal studentPersonal = new StudentPersonal {
                    PersonInfo = personInfo
                };
                IEnumerable <StudentPersonal> filteredStudents = studentPersonalConsumer.QueryByExample(studentPersonal);

                foreach (StudentPersonal student in filteredStudents)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Filtered student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName);
                    }
                }

                // Create a new student.
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Create a new student.");
                }
                string[] text = new string[]
                {
                    @"
                        <MedicalCondition>
                            <ConditionID>Unique Medical Condition ID</ConditionID>
                            <Condition>Condition</Condition>
                            <Severity>Condition Severity</Severity>
                            <Details>Condition Details</Details>
                        </MedicalCondition>
                    "
                };
                SIF_ExtendedElementsTypeSIF_ExtendedElement extendedElement = new SIF_ExtendedElementsTypeSIF_ExtendedElement {
                    Name = "MedicalConditions", Text = text
                };
                SIF_ExtendedElementsTypeSIF_ExtendedElement[] extendedElements = new SIF_ExtendedElementsTypeSIF_ExtendedElement[] { extendedElement };
                NameOfRecordType newStudentName = new NameOfRecordType {
                    FamilyName = "Wayne", GivenName = "Bruce", Type = NameOfRecordTypeType.LGL
                };
                PersonInfoType newStudentInfo = new PersonInfoType {
                    Name = newStudentName
                };
                StudentPersonal newStudent = new StudentPersonal {
                    LocalId = "555", PersonInfo = newStudentInfo, SIF_ExtendedElements = extendedElements
                };
                StudentPersonal retrievedNewStudent = studentPersonalConsumer.Create(newStudent);
                if (log.IsInfoEnabled)
                {
                    log.Info("Created new student " + newStudent.PersonInfo.Name.GivenName + " " + newStudent.PersonInfo.Name.FamilyName);
                }

                // Create multiple new students.
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Create multiple new students.");
                }
                List <StudentPersonal> newStudents            = CreateStudents(5);
                MultipleCreateResponse multipleCreateResponse = studentPersonalConsumer.Create(newStudents);
                int count = 0;

                foreach (CreateStatus status in multipleCreateResponse.StatusRecords)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Create status code is " + status.StatusCode);
                    }
                    newStudents[count++].RefId = status.Id;
                }

                // Update multiple students.
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Update multiple students.");
                }
                foreach (StudentPersonal student in newStudents)
                {
                    student.PersonInfo.Name.GivenName += "o";
                }

                MultipleUpdateResponse multipleUpdateResponse = studentPersonalConsumer.Update(newStudents);

                foreach (UpdateStatus status in multipleUpdateResponse.StatusRecords)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Update status code is " + status.StatusCode);
                    }
                }

                // Delete multiple students.
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Delete multiple students.");
                }
                ICollection <string> refIds = new List <string>();

                foreach (CreateStatus status in multipleCreateResponse.StatusRecords)
                {
                    refIds.Add(status.Id);
                }

                MultipleDeleteResponse multipleDeleteResponse = studentPersonalConsumer.Delete(refIds);

                foreach (DeleteStatus status in multipleDeleteResponse.StatusRecords)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Delete status code is " + status.StatusCode);
                    }
                }

                // Retrieve all students from zone "Gov" and context "Curr".
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Retrieve all students from zone \"Gov\" and context \"Curr\".");
                }
                IEnumerable <StudentPersonal> students = studentPersonalConsumer.Query(zone: "Gov", context: "Curr");

                foreach (StudentPersonal student in students)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName);
                    }
                }

                if (students.Count() > 1)
                {
                    // Retrieve a single student.
                    if (log.IsInfoEnabled)
                    {
                        log.Info("*** Retrieve a single student.");
                    }
                    string          studentId     = students.ElementAt(1).RefId;
                    StudentPersonal secondStudent = studentPersonalConsumer.Query(studentId);
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Name of second student is " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName);
                    }

                    // Update that student and confirm.
                    if (log.IsInfoEnabled)
                    {
                        log.Info("*** Update that student and confirm.");
                    }
                    secondStudent.PersonInfo.Name.GivenName  = "Homer";
                    secondStudent.PersonInfo.Name.FamilyName = "Simpson";
                    studentPersonalConsumer.Update(secondStudent);
                    secondStudent = studentPersonalConsumer.Query(studentId);
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Name of second student has been changed to " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName);
                    }

                    // Delete that student and confirm.
                    if (log.IsInfoEnabled)
                    {
                        log.Info("*** Delete that student and confirm.");
                    }
                    studentPersonalConsumer.Delete(studentId);
                    StudentPersonal deletedStudent = studentPersonalConsumer.Query(studentId);
                    bool            studentDeleted = (deletedStudent == null ? true : false);

                    if (studentDeleted)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info("Student " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName + " was successfully deleted.");
                        }
                    }
                    else
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info("Student " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName + " was NOT deleted.");
                        }
                    }
                }

                // Retrieve students based on Teaching Group using Service Paths.
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Retrieve students based on Teaching Group using Service Paths.");
                }
                EqualCondition condition = new EqualCondition()
                {
                    Left = "TeachingGroups", Right = "597ad3fe-47e7-4b2c-b919-a93c564d19d0"
                };
                IList <EqualCondition> conditions = new List <EqualCondition>();
                conditions.Add(condition);
                IEnumerable <StudentPersonal> teachingGroupStudents = studentPersonalConsumer.QueryByServicePath(conditions);

                foreach (StudentPersonal student in teachingGroupStudents)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName);
                    }

                    if (student.SIF_ExtendedElements != null && student.SIF_ExtendedElements.Length > 0)
                    {
                        foreach (SIF_ExtendedElementsTypeSIF_ExtendedElement element in student.SIF_ExtendedElements)
                        {
                            foreach (string content in element.Text)
                            {
                                if (log.IsInfoEnabled)
                                {
                                    log.Info("Extended element text is ...\n" + content);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                studentPersonalConsumer.Unregister();
                if (log.IsInfoEnabled)
                {
                    log.Info("Unregistered the Consumer.");
                }
            }
        }