public void AddFieldRestriction() { Query q = new Query( StudentDTD.STUDENTPERSONAL ); q.AddFieldRestriction( StudentDTD.STUDENTPERSONAL_NAME ); q.AddFieldRestriction( StudentDTD.STUDENTPERSONAL_ADDRESSLIST ); IElementDef[] restrictions = q.FieldRestrictions; Assert.AreEqual( 2, restrictions.Length, "Should have two field restrictions" ); Assert.AreEqual( StudentDTD.STUDENTPERSONAL_NAME, restrictions[0], "Should be StudentPersonal_Name" ); Assert.AreEqual( StudentDTD.STUDENTPERSONAL_ADDRESSLIST, restrictions[1], "Should be StudentPersonal_StudentAddress" ); }
private bool AddSelectFields(Query q, String selectClause ) { if( selectClause.Length == 0 || selectClause.IndexOf( "*" ) > -1 ){ return true; } string[] fields = selectClause.Split(new char[] { ',' }); foreach(string field in fields){ string val = field.Trim(); if( val.Length > 0 ){ IElementDef restriction = Adk.Dtd.LookupElementDefBySQP( q.ObjectType, val ); if( restriction == null ){ Console.WriteLine( "ERROR: Unrecognized SELECT field: " + val ); PrintSQLHelp(); return false; } else { q.AddFieldRestriction(restriction); } } } return true; }
/// <summary> Initialize and start the agent /// </summary> /// <param name="args">Command-line arguments (run with no arguments to display help) /// </param> public virtual void StartAgent(string[] args) { Console.WriteLine("Initializing agent..."); // Read the configuration file fCfg = new AgentConfig(); Console.Out.WriteLine("Reading configuration file..."); fCfg.Read("agent.cfg", false); // Override the SourceId passed to the constructor with the SourceId // specified in the configuration file this.Id = fCfg.SourceId; // Inform the ADK of the version of SIF specified in the sifVersion= // attribute of the <agent> element SifVersion version = fCfg.Version; Adk.SifVersion = version; // Now call the superclass initialize once the configuration file has been read base.Initialize(); // Ask the AgentConfig instance to "apply" all configuration settings // to this Agent; for example, all <property> elements that are children // of the root <agent> node are parsed and applied to this Agent's // AgentProperties object; all <zone> elements are parsed and registered // with the Agent's ZoneFactory, and so on. // fCfg.Apply(this, true); // Create the logging object fLogger = new ObjectLogger(this); Query zoneQuery = new Query(InfraDTD.SIF_ZONESTATUS); zoneQuery.AddFieldRestriction(InfraDTD.SIF_ZONESTATUS_SIF_PROVIDERS); //zoneQuery.AddFieldRestriction( SifDtd.SIF_ZONESTATUS_SIF_SIFNODES ); zoneQuery.UserData = fRequestState; ITopic zoneTopic = TopicFactory.GetInstance(InfraDTD.SIF_ZONESTATUS); zoneTopic.SetQueryResults(this); // Now, connect to all zones and just get the zone status foreach (IZone zone in this.ZoneFactory.GetAllZones()) { if (getChameleonProperty(zone, "logRaw", false)) { zone.Properties.KeepMessageContent = true; zone.AddMessagingListener(fLogger); } zone.Connect(ProvisioningFlags.Register); zoneTopic.Join(zone); } Console.WriteLine(); Console.WriteLine("Requesting SIF_ZoneStatus from all zones..."); zoneTopic.Query(zoneQuery); }
public void TestToXml020() { Query q = new Query(StudentDTD.SECTIONINFO); q.AddFieldRestriction( "@RefId"); q.AddFieldRestriction( "@SchoolCourseInfoRefId" ); q.AddFieldRestriction( "@SchoolYear" ); q.AddFieldRestriction( "LocalId" ); q.AddFieldRestriction("ScheduleInfoList/ScheduleInfo/@TermInfoRefId"); q.AddFieldRestriction( "Description" ); q.AddFieldRestriction( "LanguageOfInstruction" ); q.AddFieldRestriction("LanguageOfInstruction"); q.AddFieldRestriction("LanguageOfInstruction/Code"); assertSectionInfoQueryXML(q); }
public void TestToXml010() { Query q = new Query(StudentDTD.SECTIONINFO); q.AddFieldRestriction(StudentDTD.SECTIONINFO_REFID); q.AddFieldRestriction( StudentDTD.SECTIONINFO_SCHOOLCOURSEINFOREFID ); q.AddFieldRestriction( StudentDTD.SECTIONINFO_SCHOOLYEAR ); q.AddFieldRestriction( StudentDTD.SECTIONINFO_LOCALID ); q.AddFieldRestriction( "ScheduleInfoList/ScheduleInfo/@TermInfoRefId" ); q.AddFieldRestriction( StudentDTD.SECTIONINFO_DESCRIPTION ); q.AddFieldRestriction( StudentDTD.SECTIONINFO_LANGUAGEOFINSTRUCTION); q.AddFieldRestriction( StudentDTD.LANGUAGEOFINSTRUCTION_CODE ); assertSectionInfoQueryXML( q ); }
public void TestToXml() { // From the javadoc example ... // Query for student where the Last Name is Jones and the First Name is // Bob, and the graduation year is 2004, 2005, or 2006 ConditionGroup root = new ConditionGroup( GroupOperator.And ); ConditionGroup grp1 = new ConditionGroup( GroupOperator.And ); ConditionGroup grp2 = new ConditionGroup( GroupOperator.Or ); // For nested elements, you cannot reference a SifDtd constant. Instead, use // the lookupElementDefBySQL function to lookup an IElementDef constant // given a SIF Query Pattern (SQP) IElementDef lname = Adk.Dtd.LookupElementDefBySQP( StudentDTD.STUDENTPERSONAL, "Name/LastName" ); IElementDef fname = Adk.Dtd.LookupElementDefBySQP( StudentDTD.STUDENTPERSONAL, "Name/FirstName" ); grp1.AddCondition( lname, ComparisonOperators.EQ, "Jones" ); grp1.AddCondition( fname, ComparisonOperators.EQ, "Bob" ); grp2.AddCondition( StudentDTD.STUDENTPERSONAL_ONTIMEGRADUATIONYEAR, ComparisonOperators.EQ, "2004" ); grp2.AddCondition( StudentDTD.STUDENTPERSONAL_ONTIMEGRADUATIONYEAR, ComparisonOperators.EQ, "2005" ); grp2.AddCondition( StudentDTD.STUDENTPERSONAL_ONTIMEGRADUATIONYEAR, ComparisonOperators.EQ, "2006" ); // Add condition groups to the root group root.AddGroup( grp1 ); root.AddGroup( grp2 ); // Query for student with the conditions prepared above by passing the // root ConditionGroup to the constructor Query query = new Query( StudentDTD.STUDENTPERSONAL, root ); query.AddFieldRestriction( StudentDTD.STUDENTPERSONAL_NAME ); // Now, call toXML() on the query object, reparse back into a Query object and assert all values String sifQueryXML = query.ToXml( SifVersion.LATEST ); Console.WriteLine( sifQueryXML ); SifParser parser = SifParser.NewInstance(); SIF_Request sifR = (SIF_Request) parser.Parse( "<SIF_Request>" + sifQueryXML + "</SIF_Request>", null ); Query reparsedQuery = new Query( sifR.SIF_Query ); Assert.AreEqual( StudentDTD.STUDENTPERSONAL, reparsedQuery.ObjectType, "Object Type should be StudentPersonal" ); Assert.AreEqual( 1, reparsedQuery.FieldRestrictions.Length, "Should have one field restriction" ); Assert.AreEqual( StudentDTD.STUDENTPERSONAL_NAME, reparsedQuery.FieldRestrictions[0], "Should be for StudentPersonal/Name" ); ConditionGroup newRoot = reparsedQuery.RootConditionGroup; Assert.AreEqual( StudentDTD.STUDENTPERSONAL, reparsedQuery.ObjectType, "Should be StudentPersonal" ); Assert.AreEqual( GroupOperator.And, newRoot.Operator, "Root should be an AND conditon" ); ConditionGroup[] groups = reparsedQuery.RootConditionGroup.Groups; Assert.AreEqual( 2, groups.Length, "Should have two groups" ); Assert.AreEqual( GroupOperator.And, groups[0].Operator, "First group should be AND" ); Assert.AreEqual( GroupOperator.Or, groups[1].Operator, "Second group should be OR" ); // Assert the first group conditions Condition[] newGrp1Conditions = groups[0].Conditions; Assert.AreEqual( 2, newGrp1Conditions.Length, "First group should have two conditions" ); // Assert the first condition Assert.AreEqual( ComparisonOperators.EQ, newGrp1Conditions[1].Operators, "First Condition EQ" ); Assert.AreEqual( lname, newGrp1Conditions[0].Field, "First Condition Field" ); Assert.AreEqual( "Jones", newGrp1Conditions[0].Value, "First Condition Value" ); // Assert the second condition Assert.AreEqual( ComparisonOperators.EQ, newGrp1Conditions[0].Operators, "Second Condition EQ" ); Assert.AreEqual( fname, newGrp1Conditions[1].Field, "First Condition Field" ); Assert.AreEqual( "Bob", newGrp1Conditions[1].Value, "First Condition Value" ); // Assert the second group conditions Condition[] newGrp2Conditions = groups[1].Conditions; Assert.AreEqual( 3, newGrp2Conditions.Length, "Second group should have three conditions" ); // Assert the first condition Assert.AreEqual( ComparisonOperators.EQ, newGrp2Conditions[0].Operators, "First Condition EQ" ); Assert.AreEqual( StudentDTD.STUDENTPERSONAL_ONTIMEGRADUATIONYEAR, newGrp2Conditions[0].Field, "First Condition Field" ); Assert.AreEqual( "2004", newGrp2Conditions[0].Value, "First Condition Value" ); // Assert the second condition Assert.AreEqual( ComparisonOperators.EQ, newGrp2Conditions[1].Operators, "Second Condition EQ" ); Assert.AreEqual( StudentDTD.STUDENTPERSONAL_ONTIMEGRADUATIONYEAR, newGrp2Conditions[1].Field, "Second Condition Field" ); Assert.AreEqual( "2005", newGrp2Conditions[1].Value, "Second Condition Value" ); // Assert the third condition Assert.AreEqual( ComparisonOperators.EQ, newGrp2Conditions[2].Operators, "Third Condition EQ" ); Assert.AreEqual( StudentDTD.STUDENTPERSONAL_ONTIMEGRADUATIONYEAR, newGrp2Conditions[2].Field, "Third Condition Field" ); Assert.AreEqual( "2006", newGrp2Conditions[2].Value, "Third Condition Value" ); }