/// <summary> /// Creates a SimpleFieldPointer /// </summary> /// <param name="parentPointer">The parent of this pointer</param> /// <param name="element">The element being wrapped</param> /// <param name="version">The SifVersion to use for resolving XPaths</param> /// set of fields</param> internal SimpleFieldPointer( INodePointer parentPointer, Element element, SifVersion version ) : base(parentPointer, element, version) { }
/// <summary> /// Creates a new pointer to a SimpleField that is represented as an XML Attribute /// </summary> /// <param name="parentPointer">The parent pointer</param> /// <param name="element">The attribute being wrapped</param> /// <param name="version">The SifVersion</param> public SimpleFieldAttributePointer( INodePointer parentPointer, Element element, SifVersion version ) : base(parentPointer, element, version) { }
/// <summary> /// Adds a SIFElement parsed from a specific version of SIF to the parent. /// The formatter instance may use version-specific rules to ensure that the /// hierarchy is properly maintained when the source of the content is from /// this version of SIF /// </summary> /// <param name="contentParent"> The element to add content to</param> /// <param name="content">The element to add</param> /// <param name="version"> The version of SIF that the SIFElement is being constructed /// from</param> public override SifElement AddChild( SifElement contentParent, SifElement content, SifVersion version) { contentParent.RestoreImplementationDef(content); return GetContainer(contentParent, content.ElementDef, version).AddChild(content); }
/// <summary> /// Creates a new SifElementPointer /// </summary> /// <param name="parentPointer">The parent of this pointer</param> /// <param name="element">The element being wrapped</param> /// <param name="version">The SifVersion in effect</param> public SifElementPointer( INodePointer parentPointer, SifElement element, SifVersion version ) : base(parentPointer, element, version) { fSifElement = element; }
/** * @param mappings * @param direction * @param version * @param elementType */ private MappingsContext( Mappings mappings, MappingDirection direction, SifVersion version, IElementDef elementType) { fMappings = mappings; fDirection = direction; fSIFVersion = version; fElementDef = elementType; }
/// <summary> /// Constructs an ElementDefAlias /// </summary> /// <param name="parent">The parent of this element</param> /// <param name="name">The name of the element</param> /// <param name="tag">The name of the element</param> /// <param name="className">The name of the class to create</param> /// <param name="localPackage">The name of the package where the corresponding /// DataObject class is defined, excluding the <c>OpenADK.Library</c> prefix</param> /// <param name="sequence">The zero-based ordering of this element within its parent /// or -1 if a top-level element</param> /// <param name="earliestVersion">The earliest version of SIF supported by this element</param> public ElementDefAlias( IElementDef parent, string name, string tag, string className, int sequence, string localPackage, SifVersion earliestVersion ) : base(parent, name, tag, sequence, localPackage, sequence, earliestVersion, null) { fClassName = className; }
/// <summary> /// Gets the content from the SIFElement for the specified version of SIF. Only /// elements that apply to the requested version of SIF will be returned. /// </summary> /// <param name="element">The element to retrieve content from</param> /// <param name="version"></param> /// <returns></returns> public override IList<Element> GetContent(SifElement element, SifVersion version) { List<Element> returnValue = new List<Element>(); ICollection<SimpleField> fields = element.GetFields(); foreach (SimpleField val in fields) { IElementDef def = val.ElementDef; if (def.IsSupported(version) && !def.IsAttribute(version) && def.Field ) { returnValue.Add(val); } } IList<SifElement> children = element.GetChildList(); foreach (SifElement val in children) { IElementDef def = val.ElementDef; if (def.IsSupported(version)) { if (def.IsCollapsed(version)) { ICollection<Element> subElements = GetContent(val, version); // FIXUP the ElementDef for this version of SIF. // for example, StudentPersonal/EmailList/Email needs it's // ElementDef set to "StudentPersonal_Email" foreach (Element e in subElements) { IElementDef subElementDef = e.ElementDef; if (version.CompareTo(subElementDef.EarliestVersion) >= 0) { String tag = subElementDef.Tag(Adk.SifVersion); IElementDef restoredDef = Adk.Dtd.LookupElementDef(element.ElementDef, tag); if (restoredDef != null) { e.ElementDef = restoredDef; } returnValue.Add(e); } } } else { returnValue.Add(val); } } } MergeSort.Sort<Element>(returnValue, ElementSorter<Element>.GetInstance(version)); //returnValue.Sort(ElementSorter<Element>.GetInstance(version)); return returnValue; }
/// <summary> /// Creates a child element, if supported by this node /// </summary> /// <param name="parentPointer"></param> /// <param name="formatter"></param> /// <param name="version"></param> /// <param name="context"></param> /// <returns></returns> public INodePointer CreateChild( INodePointer parentPointer, SifFormatter formatter, SifVersion version, SifXPathContext context ) { // 1) Create an instance of the SimpleField with a null value (It's assigned later) // // STEP 2 // Find the actual field to set the value to // SifElement parent = (SifElement) ((SifElementPointer) parentPointer).Element; SifElement targetElement = parent; if ( !fElementDef.Field ) { // This indicates a child SifElement that needs to be created targetElement = SifElement.Create( parent, fElementDef ); formatter.AddChild( parent, targetElement, version ); } IElementDef fieldDef = null; if ( fValueXpath.Equals( "." ) ) { fieldDef = fElementDef; } else { String fieldName = fValueXpath; if ( fValueXpath.StartsWith( "@" ) ) { fieldName = fValueXpath.Substring( 1 ); } fieldDef = Adk.Dtd.LookupElementDef( fElementDef, fieldName ); } if ( fieldDef == null ) { throw new ArgumentException( "Support for value path {" + fValueXpath + "} is not supported by XPathSurrogate." ); } SifSimpleType ssf = fieldDef.TypeConverter.GetSifSimpleType( null ); SimpleField sf = ssf.CreateField( targetElement, fieldDef ); targetElement.SetField( sf ); // 2) built out a fake set of node pointers representing the SIF 1.5r1 path and // return the root pointer from that stack return BuildLegacyPointers( parentPointer, sf ); }
/// <summary> /// Define an attribute of a SIF Data Object. /// </summary> /// <param name="parent">The IElementDef constant identifying the parent data object</param> /// <param name="name">The tag name of the attribute</param> /// <param name="sequence">The zero-based sequence number of the attribute</param> /// <param name="earliestVersion">The earliest version of the specification this attribute should /// be recognized in</param> /// <returns>An IElementDef instance encapsulating metadata for this attribute</returns> public IElementDef DefineAttribute( IElementDef parent, String name, int sequence, SifVersion earliestVersion ) { if ( parent == null ) { throw new ArgumentException( "Parent cannot be null" ); } IElementDef ed = new ElementDefImpl ( parent, name, null, sequence, "custom", ElementDefImpl.FD_ATTRIBUTE, earliestVersion, SifVersion.LATEST ); SifDtd.sElementDefs.Add( parent.Name + "_" + name, ed ); return ed; }
/** * SIF_Register */ public SIF_Ack SifRegister(IZone zone) { ZoneImpl AdkZone = (ZoneImpl)zone; AgentProperties props = zone.Properties; SifVersion effectiveZISVersion = AdkZone.HighestEffectiveZISVersion; SIF_Register msg = new SIF_Register(effectiveZISVersion); msg.SIF_MaxBufferSize = props.MaxBufferSize; msg.SIF_Mode = props.MessagingMode == AgentMessagingMode.Pull ? "Pull" : "Push"; // Set the agent's name and version Agent agent = zone.Agent; msg.SIF_Name = agent.Name; String vendor = props.AgentVendor; if (vendor != null) { msg.SIF_NodeVendor = vendor; } String version = props.AgentVersion; if (version != null) { msg.SIF_NodeVersion = version; } SIF_Application applicationInfo = new SIF_Application(); String appName = props.ApplicationName; if (appName != null) { applicationInfo.SIF_Product = appName; } String appVersion = props.ApplicationVersion; if (appVersion != null) { applicationInfo.SIF_Version = appVersion; } String appVendor = props.ApplicationVendor; if (appVendor != null) { applicationInfo.SIF_Vendor = appVendor; } if (applicationInfo.FieldCount > 0) { // All three fields under SIF_Application are required by the // SIF_Specification. Determine if any are missing. If so, // create the field with an empty value if (applicationInfo.SIF_Product == null) { applicationInfo.SIF_Product = string.Empty; } if (applicationInfo.SIF_Version == null) { applicationInfo.SIF_Version = string.Empty; } if (applicationInfo.SIF_Vendor == null) { applicationInfo.SIF_Vendor = string.Empty; } msg.SIF_Application = applicationInfo; } String propVal = props.AgentIconUrl; if (propVal != null) { msg.SIF_Icon = propVal; } // // SIF_Version handling: // // * If the "Adk.provisioning.zisVersion" property is set to > SIF 1.1 // (the default), use SIF 1.1+ registration where multiple SIF_Version // elements are included in the SIF_Register message. Otherwise use // SIF 1.0 registration where only a single SIF_Version is included in // the SIF_Register message. // // For SIF 1.1 registrations: // // * If the "Adk.sifRegister.sifVersions" System property is set, // enumerate its comma-delimited list of SIF_Version values and use // those instead of building a list. This is primarily used for // testing wildcards (which the Adk doesn't normally use) or when an // agent wants to connect to a ZIS where wildcarding works better for // some reason. // // * Otherwise, build a list of SIF_Versions: Set the first SIF_Version // element to the version initialized by the Adk, then add a SIF_Version // element for each additional version of SIF supported by the Adk // String forced = zone.Properties.OverrideSifVersions; if (forced != null) { ((ZoneImpl)zone).Log.Debug("Using custom SIF_Register/SIF_Version: " + forced); foreach (String token in forced.Split(',')) { msg.AddSIF_Version(new SIF_Version(token.Trim())); } } else { SifVersion zisVer = SifVersion.Parse(zone.Properties.ZisVersion); if (zisVer.CompareTo(SifVersion.SIF11) >= 0) { // Add the Adk version first. This is the "default" // agent version, which has special meaning to the // ZIS msg.AddSIF_Version(new SIF_Version(effectiveZISVersion)); // TT 2007 // If the Adk Version is set to 1.1 or 1.5r1, only send those two // versions in the SIF_Register message. The downside to this is // that we can't connect to a 2.0 ZIS using SIF 1.5r1 and still // receive 2.0 events. However, this seems to be the best approach // because it ensures greater compatibility with older ZIS's that will // otherwise fail if they get a 2.0 version in the SIF_Register message SifVersion[] supported = Adk.SupportedSIFVersions; for (int i = 0; i < supported.Length; i++) { // Exclude the version added above if (supported[i].CompareTo(effectiveZISVersion) < 0) { msg.AddSIF_Version(new SIF_Version(supported[i])); } } } else { msg.AddSIF_Version(new SIF_Version(Adk.SifVersion)); } } // // Set the SIF_Protocol object as supplied by the Transport. Depending // on the transport protocol and the messaging mode employed by the // zone we may or may not get a SIF_Protocol object back // SIF_Protocol po = ((ZoneImpl)zone).ProtocolHandler.MakeSIF_Protocol(zone); if (po != null) { msg.SIF_Protocol = po; } return(AdkZone.Dispatcher.send(msg)); }
static AdkExamples() { Version = SifVersion.LATEST; }
public override SifSimpleType Evaluate(SifXPathContext context, SifVersion version) { SifDataObject sdo = (SifDataObject)context.ContextElement; return(Evaluate(sdo, version)); }
/// <summary> /// Determines if this metadata describes an element that is contained in the /// specified version of SIF. /// </summary> /// <param name="version">The version of the SIF Specification</param> /// <returns> <c>TRUE</c> if the metadata is included in the specified version of SIF</returns> public bool IsSupported(SifVersion version) { SifVersion earliestVersion = EarliestVersion; return (earliestVersion == null || earliestVersion.CompareTo( version ) < 1) && (fLatestVersion == null || fLatestVersion.CompareTo( version ) > -1); }
public virtual bool IsAttribute(SifVersion version) { return Info(version).GetFlag(AbstractVersionInfo.FLAG_ATTRIBUTE); }
/// <summary> /// Defines version-specific metadata /// </summary> /// <param name="version"></param> /// <param name="tag"></param> /// <param name="sequence"></param> /// <param name="flags"></param> public void DefineVersionInfo(SifVersion version, string tag, int sequence, int flags) { AbstractVersionInfo vi = null; for (int i = 0; i < sSifVersions.Length; i++) { if (version == sSifVersions[i]) { if (fInfo[i] == null) { fInfo[i] = vi = CreateVersionInfo(tag); } else { vi = fInfo[i]; } break; } } if (vi == null) { throw new ArgumentException ("SIF " + version + " is not supported by the Adk"); } if ((flags & FD_DEPRECATED) != 0) { vi.SetFlag(AbstractVersionInfo.FLAG_DEPRECATED, true); } if ((flags & FD_REPEATABLE) != 0) { vi.SetFlag(AbstractVersionInfo.FLAG_REPEATABLE, true); } if ((flags & FD_ATTRIBUTE) != 0) { vi.SetFlag(AbstractVersionInfo.FLAG_ATTRIBUTE, true); } if ((flags & FD_COLLAPSE) != 0) { vi.SetFlag(AbstractVersionInfo.FLAG_COLLAPSE, true); } vi.Sequence = sequence; }
/// <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 virtual int GetSequence(SifVersion version) { return(Info(version).Sequence); }
public IElementVersionInfo GetVersionInfo(SifVersion version) { return(GetAbstractVersionInfo(version, false)); }
/// <summary> Lookup the VersionInfo object for a specific version of SIF.</summary> private AbstractVersionInfo Info(SifVersion v) { return(GetAbstractVersionInfo(v, true)); }
public bool IsCollapsed(SifVersion version) { return(Info(version).GetFlag(AbstractVersionInfo.FLAG_COLLAPSE)); }
public virtual bool IsRepeatable(SifVersion version) { return(Info(version).GetFlag(AbstractVersionInfo.FLAG_REPEATABLE)); }
/// <summary> /// Returns the TagName for the specified element, using the specified version /// </summary> /// <param name="version"></param> /// <returns></returns> public virtual string Tag(SifVersion version) { return(Info(version).Tag); }
/// <summary> /// Constructs an ElementDef /// </summary> /// <param name="parent">The parent of this element</param> /// <param name="name">The version-independent name of the element</param> /// <param name="tag">The element or attribute tag (if different from the name)</param> /// <param name="sequence">The zero-based ordering of this element within its parent /// or -1 if a top-level element</param> /// <param name="localPackage">localPackage The name of the package where the corresponding /// DataObject class is defined, excluding the /// <code>OpenADK.Library</code> prefix</param> /// <param name="variant"></param> /// <param name="flags"></param> /// <param name="earliestVersion"></param> /// <param name="latestVersion"></param> /// <param name="typeConverter"></param> /// public ElementDefImpl(IElementDef parent, string name, string tag, int sequence, string localPackage, string variant, int flags, SifVersion earliestVersion, SifVersion latestVersion) : this(parent, name, tag, sequence, localPackage, variant, flags, earliestVersion, latestVersion, (TypeConverter)null) { }
/// <summary> /// Creates an instance of a SIF_Register /// </summary> /// <param name="sifVersion">The version of SIF to render this message in</param> /// public SIF_Register(SifVersion sifVersion) : base(sifVersion, InfraDTD.SIF_REGISTER) { }
public virtual string GetSQPPath(SifVersion version) { StringBuilder b = new StringBuilder(); if (IsAttribute(version)) { b.Append('@'); } b.Append(Tag(version)); ElementDefImpl p = fParent; while (p != null && !p.Object) { b.Insert(0, p.Tag(version) + "/"); p = p.fParent; } return b.ToString(); }
public ISchemaDefinition GetSchemaDefinition(SifVersion version) { return(getDB(version)); }
public virtual bool IsDeprecated(SifVersion version) { return Info(version).GetFlag(AbstractVersionInfo.FLAG_DEPRECATED); }
/// <summary> /// Creates an instance of a SIF_Response /// </summary> /// <param name="sifVersion">The version of SIF to render this message in</param> /// public SIF_Response(SifVersion sifVersion) : base(sifVersion, InfraDTD.SIF_RESPONSE) { }
/// <summary> /// Lookup the VersionInfo object for a specific version of SIF. /// </summary> /// <param name="version">v The version of SIF to search</param> /// <param name="throwIfNotExists">True if a RuntimeException should be thrown if the version information does not exist. /// If False, NULL will be returned</param> /// <returns>The AbstractVersionInfo instance or null</returns> private AbstractVersionInfo GetAbstractVersionInfo(SifVersion version, bool throwIfNotExists) { int last = -1; // Search the list of SIFVersions that the ADK supports. The list // is searched incrementally, starting with the oldest version. If // a version is found that directly matches the requested SIF Version, // return that entry. Otherwise, return the next previous entry from the list for (int i = 0; i < sSifVersions.Length; i++) { int comparison = sSifVersions[i].CompareTo( version ); if (comparison < 1 && fInfo[i] != null) { last = i; } if (comparison > -1) { // We have reached the SIFVersion in the list of supported versions that // is greater than or equal to the requested version. Return the last AbstractVersionInfo // from our array that we found break; } } if (last == -1) { if (throwIfNotExists) { throw new AdkSchemaException("Element or attribute \"" + Name + "\" is not supported in SIF " + version ); } else { return null; } } return fInfo[last]; }
private void SetRequestPolicy( SIF_Request request, IZone zone ) { SIF_Query query = request.SIF_Query; if( query == null ) { // SIF_ExtendedQuery and SIF_Example are not supported by ADK Policy yet return; } // // Object Request Policy // // Determine if there is policy in effect for this Query // String objectName = query.SIF_QueryObject.ObjectName; ObjectRequestPolicy requestPolicy = fPolicyFactory.GetRequestPolicy( zone, objectName ); if( requestPolicy != null ){ // // SIF_Request/SIF_Version policy // String requestVersions = requestPolicy.RequestVersion; if( requestVersions != null ){ if( (Adk.Debug & AdkDebugFlags.Policy ) > 0 ){ zone.Log.Info( "POLICY: Setting SIF_Request/SIF_Version to " + requestVersions ); } // Clear the list of SIF Versions foreach( SIF_Version existingVersion in request.GetSIF_Versions() ){ request.RemoveChild( existingVersion ); } // The version will be a comma-delimited list. Set each of these // as SIF_Version elements, but also try to derive the most logical // version element to set the SIF Message/@Version attribute to // NOTE: Someone could theoretically set versions incorrectly, such // as "1.1,1.5r1". Multiple SIF_Version elements are not supported in // SIF 1.x, but we won't bother with validating incorrect settings. Policy // is power in the configurator's hands to use or abuse. String[] versions = requestVersions.Split( ',' ); String lowestVersion = versions[0]; foreach( String version in versions ){ String ver = version.Trim(); request.AddSIF_Version(new SIF_Version(ver)); if (lowestVersion.CompareTo(ver) > 0) { lowestVersion = ver; } } // Determine how the SIF_Message/@Version should be set to // * If the policy is set to a single version, use it // * If a list, use the lowest // * If *, ignore // * if [major].*, use the lowest version supported if( lowestVersion.Length > 0 ){ SifVersion newMsgVersion = null; if( lowestVersion.EndsWith( "*" ) ){ try { // 2.*, requests go out with a message version of 2.0r1 int major = int.Parse( lowestVersion.Substring( 0, 1 ) ); newMsgVersion = SifVersion.GetEarliest( major ); } catch( FormatException iae ){ zone.Log.Warn( "POLICY: Error parsing ObjectRequestPolicy version '" + requestVersions + "' : " + iae.Message, iae ); } } else { try { newMsgVersion = SifVersion.Parse( lowestVersion ); } catch( FormatException iae ){ zone.Log.Warn( "POLICY: Error parsing ObjectRequestPolicy version '" + requestVersions + "' : " + iae.Message, iae ); } } if( newMsgVersion != null ){ if( (Adk.Debug & AdkDebugFlags.Policy ) > 0 ){ zone.Log.Info( "POLICY: Setting SIF_Messaage/@Version to " + newMsgVersion ); } request.SifVersion = newMsgVersion; } } } // // SIF_DestinationID policy // String requestSourceId = requestPolicy.RequestSourceId ; if( requestSourceId != null ){ if( (Adk.Debug & AdkDebugFlags.Policy) > 0 ){ zone.Log.Info( "POLICY: Setting SIF_Request SIF_DestinationID to " + requestPolicy.RequestSourceId ); } request.SIF_Header.SIF_DestinationId = requestSourceId; } } }
/// <summary> /// Creates an instance of a SIF_Event /// </summary> /// <param name="sifVersion">The version of SIF to render this message in</param> /// public SIF_Event(SifVersion sifVersion) : base(sifVersion, InfraDTD.SIF_EVENT) { }
public void RenderRaw( XmlWriter writer, SifVersion version, Element o, SifFormatter formatter ) { String elementName = fElementDef.Name; SifTime time = (SifTime) o.SifValue; if ( time.Value.HasValue ) { WriteSIFTime( writer, formatter, elementName, time.Value.Value ); } }
/// <summary> Parse the command-line. This method may be called repeatedly, usually /// once from the sample agent's <c>main</code> function prior to /// initializing the Adk and again from the <c>Agent.initialize</code> /// method after initializing the Agent superclass. When called without an /// Agent instance, only those options that do not rely on an AgentProperties /// object are processed (e.g. the /D option). /// <p> /// * /// If a file named 'agent.rsp' exists in the current directory, any command /// line options specified will be appended to the command-line arguments /// passed to this method. Each line of the agent.rsp text file may be /// comprised of one or more arguments separated by spaces, so that the /// entirely set of arguments can be on one line or broken up onto many /// lines.<p> /// * /// </summary> /// <param name="agent">An Agent instance that will be updated when certain /// command-line options are parsed /// </param> /// <param name="arguments">The string of arguments provided by the <c>main</code> /// function /// /// </param> public static NameValueCollection parseCL(Agent agent, string[] arguments) { if (args == null) { args = arguments; if (args.Length > 0 && args[0][0] != '/') { // Look for an agent.rsp response file FileInfo rsp = new FileInfo(args[0]); if (rsp.Exists) { try { ArrayList v = new ArrayList(); using (StreamReader reader = File.OpenText(rsp.FullName)) { string line = null; while ((line = reader.ReadLine()) != null) { // allow comment lines, starting with a ; if (!line.StartsWith(";")) { foreach (string token in line.Split(' ')) { v.Add(token); } } } reader.Close(); } // Append any arguments found to the args array if (v.Count > 0) { args = new string[args.Length + v.Count]; Array.Copy(arguments, 0, args, 0, arguments.Length); v.CopyTo(args, arguments.Length); Console.Out.Write ("Reading command-line arguments from " + args[0] + ": "); for (int i = 0; i < args.Length; i++) { Console.Out.Write(args[i] + " "); } Console.WriteLine(); Console.WriteLine(); } } catch (Exception ex) { Console.WriteLine ("Error reading command-line arguments from agent.rsp file: " + ex); } } } } if (agent == null) { // Look for options that do not affect the AgentProperties... for (int i = 0; i < args.Length; i++) { if (args[i].ToUpper().Equals("/debug".ToUpper())) { if (i < args.Length - 1) { try { Adk.Debug = AdkDebugFlags.None; int k = Int32.Parse(args[++i]); if (k == 1) { Adk.Debug = AdkDebugFlags.Minimal; } else if (k == 2) { Adk.Debug = AdkDebugFlags.Moderate; } else if (k == 3) { Adk.Debug = AdkDebugFlags.Detailed; } else if (k == 4) { Adk.Debug = AdkDebugFlags.Very_Detailed; } else if (k == 5) { Adk.Debug = AdkDebugFlags.All; } } catch (Exception) { Adk.Debug = AdkDebugFlags.All; } } else { Adk.Debug = AdkDebugFlags.All; } } else if (args[i].StartsWith("/D")) { string prop = args[i].Substring(2); if (i != args.Length - 1) { Properties.SetProperty(prop, args[++i]); } else { Console.WriteLine("Usage: /Dproperty value"); } } else if (args[i].ToUpper().Equals("/log".ToUpper()) && i != args.Length - 1) { try { Adk.SetLogFile(args[++i]); } catch (IOException ioe) { Console.WriteLine("Could not redirect debug output to log file: " + ioe); } } else if (args[i].ToUpper().Equals("/ver".ToUpper()) && i != args.Length - 1) { Version = SifVersion.Parse(args[++i]); } else if (args[i].Equals("/?")) { Console.WriteLine(); Console.WriteLine ( "These options are common to all Adk Example agents. For help on the usage"); Console.WriteLine ( "of this agent in particular, run the agent without any parameters. Note that"); Console.WriteLine ( "most agents support multiple zones if a zones.properties file is found in"); Console.WriteLine("the current directory."); Console.WriteLine(); printHelp(); Environment.Exit(0); } } return(null); } // Parse all other options... AgentProperties props = agent.Properties; NameValueCollection misc = new NameValueCollection(); int port = -1; string host = null; bool useHttps = false; string sslCert = null; string clientCert = null; int clientAuth = 0; for (int i = 0; i < args.Length; i++) { if (args[i].ToUpper().Equals("/sourceId".ToUpper()) && i != args.Length - 1) { agent.Id = args[++i]; } else if (args[i].ToUpper().Equals("/noreg".ToUpper())) { Reg = false; } else if (args[i].ToUpper().Equals("/unreg".ToUpper())) { Unreg = true; } else if (args[i].ToUpper().Equals("/pull".ToUpper())) { props.MessagingMode = AgentMessagingMode.Pull; } else if (args[i].ToUpper().Equals("/push".ToUpper())) { props.MessagingMode = AgentMessagingMode.Push; } else if (args[i].ToUpper().Equals("/port".ToUpper()) && i != args.Length - 1) { try { port = Int32.Parse(args[++i]); } catch (FormatException) { Console.WriteLine("Invalid port: " + args[i - 1]); } } else if (args[i].ToUpper().Equals("/https".ToUpper())) { useHttps = true; } else if (args[i].ToUpper().Equals("/sslCert".ToUpper())) { sslCert = args[++i]; } else if (args[i].ToUpper().Equals("/clientCert".ToUpper())) { clientCert = args[++i]; } else if (args[i].ToUpper().Equals("/clientAuth".ToUpper())) { try { clientAuth = int.Parse(args[++i]); } catch (FormatException) { clientAuth = 0; } } else if (args[i].ToUpper().Equals("/host".ToUpper()) && i != args.Length - 1) { host = args[++i]; } else if (args[i].ToUpper().Equals("/timeout".ToUpper()) && i != args.Length - 1) { try { props.DefaultTimeout = TimeSpan.FromMilliseconds(Int32.Parse(args[++i])); } catch (FormatException) { Console.WriteLine("Invalid timeout: " + args[i - 1]); } } else if (args[i].ToUpper().Equals("/freq".ToUpper()) && i != args.Length - 1) { try { props.PullFrequency = TimeSpan.FromMilliseconds(int.Parse(args[++i])); } catch (FormatException) { Console.WriteLine("Invalid pull frequency: " + args[i - 1]); } } else if (args[i].ToUpper().Equals("/opensif".ToUpper())) { // OpenSIF reports attempts to re-subscribe to objects as an // error instead of a success status code. The Adk would therefore // throw an exception if it encountered the error, so we can // disable that behavior here. props.IgnoreProvisioningErrors = true; } else if (args[i][0] == '/') { if (i == args.Length - 1 || args[i + 1].StartsWith("/")) { misc[args[i].Substring(1)] = null; } else { misc[args[i].Substring(1)] = args[++i]; } } } if (useHttps) { // Set transport properties (HTTPS) HttpsProperties https = agent.DefaultHttpsProperties; if (sslCert != null) { https.SSLCertName = sslCert; } if (clientCert != null) { https.ClientCertName = clientCert; } https.ClientAuthLevel = clientAuth; if (port != -1) { https.Port = port; } https.Host = host; https.PushHost = host; props.TransportProtocol = "https"; } else { // Set transport properties (HTTP) HttpProperties http = agent.DefaultHttpProperties; if (port != -1) { http.Port = port; } http.Host = host; props.TransportProtocol = "http"; } return(misc); }
/// <summary> /// Called by the ADK XPath traversal code when it is traversing the given element /// in a legacy version of SIF /// </summary> /// <param name="parentPointer">The parent element pointer</param> /// <param name="element">The Element to create a node pointer for</param> /// <param name="version">The SIFVersion in effect</param> /// <returns>A NodePointer representing the current element</returns> public INodePointer CreateNodePointer( INodePointer parentPointer, Element element, SifVersion version ) { return null; }
public virtual bool IsAttribute(SifVersion version) { return(Info(version).GetFlag(AbstractVersionInfo.FLAG_ATTRIBUTE)); }
/// <summary> Evaluates the SIF Version filter against a SifVersion instance.</summary> /// <param name="version">A SifVersion instance /// </param> /// <returns> true If the SIF Version filter is undefined, or if the /// <code>version</code> parameter evaluates true given the /// comparision operator and version of SIF specified by the /// current filter /// </returns> public bool EvalVersion(SifVersion version) { if (fVersion == null || version == null) { return true; } SifVersion flt = Library.SifVersion.Parse(fVersion.Substring(1)); if (flt != null) { if (fVersion[0] == '=') { return flt.CompareTo(version) == 0; } // Prefix of = means SIF_Version == filter version if (fVersion[0] == '+') { return version.CompareTo(flt) >= 0; } // Prefix of + means filter applies to messages with SIF_Version if (fVersion[0] == '-') { return version.CompareTo(flt) <= 0; } // Prefix of - means SIF_Version <= filter version } return false; }
private static void ParseGlobalProperties() { // Look for options that do not affect the AgentProperties... for (int i = 0; i < sArguments.Length; i++) { if (sArguments[i].ToUpper().Equals("/debug".ToUpper())) { if (i < sArguments.Length - 1) { try { Adk.Debug = AdkDebugFlags.None; int k = Int32.Parse(sArguments[++i]); if (k == 1) { Adk.Debug = AdkDebugFlags.Minimal; } else if (k == 2) { Adk.Debug = AdkDebugFlags.Moderate; } else if (k == 3) { Adk.Debug = AdkDebugFlags.Detailed; } else if (k == 4) { Adk.Debug = AdkDebugFlags.Very_Detailed; } else if (k == 5) { Adk.Debug = AdkDebugFlags.All; } } catch (Exception) { Adk.Debug = AdkDebugFlags.All; } } else { Adk.Debug = AdkDebugFlags.All; } } else if (sArguments[i].StartsWith("/D")) { string prop = sArguments[i].Substring(2); if (i != sArguments.Length - 1) { Properties.SetProperty(prop, sArguments[++i]); } else { Console.WriteLine("Usage: /Dproperty value"); } } else if (sArguments[i].ToUpper().Equals("/log".ToUpper()) && i != sArguments.Length - 1) { try { Adk.SetLogFile(sArguments[++i]); } catch (IOException ioe) { Console.WriteLine("Could not redirect debug output to log file: " + ioe); } } else if (sArguments[i].ToUpper().Equals("/ver".ToUpper()) && i != sArguments.Length - 1) { Version = SifVersion.Parse(sArguments[++i]); } else if (sArguments[i].Equals("/?")) { Console.WriteLine(); Console.WriteLine ("These options are common to all Adk Example agents. For help on the usage"); Console.WriteLine ("of this agent in particular, run the agent without any parameters. Note that"); Console.WriteLine ("most agents support multiple zones if a zones.properties file is found in"); Console.WriteLine("the current directory."); Console.WriteLine(); printHelp(); Environment.Exit(0); } } }
public virtual bool IsDeprecated(SifVersion version) { return(Info(version).GetFlag(AbstractVersionInfo.FLAG_DEPRECATED)); }
/// <summary> /// Creates a child element, if supported by this node /// </summary> /// <param name="parentPointer"></param> /// <param name="formatter"></param> /// <param name="version"></param> /// <param name="context"></param> /// <returns></returns> public INodePointer CreateChild( INodePointer parentPointer, SifFormatter formatter, SifVersion version, SifXPathContext context ) { // TODO Auto-generated method stub return null; }
private bool RunSingleTest( SifVersion parseVersion, SifVersion writeVersion, string fileName, TextWriter output, SchemaValidator sv) { sv.Clear(); if (VERBOSE) { output.Write("Running test on " + fileName + "\r\n"); } // 1) Read the object into memory SifElement se = null; try { se = AdkObjectParseHelper.ParseFile(fileName, parseVersion); } catch (AdkException adke) { // Parsing failed. However, since this unit test is a complete // test of all available objects, just emit the problem and allow // the test to continue (with a notification of false) output .WriteLine("Error parsing file " + fileName + "\r\n - " + adke); output.WriteLine(); return(false); } catch (Exception re) { output.WriteLine("Error parsing file " + fileName + "\r\n - " + re); output.WriteLine(); return(false); } // if (VERBOSE) // { // SifWriter writer = new SifWriter(output); // writer.Write(se,parseVersion); // output.Flush(); // } // Before we can validate with the schema, we need to ensure that the // data object is wrapped in a SIF_Message elements, because the SIF // Schema makes that assumption SifMessagePayload smp = SchemaValidator.MakeSIFMessagePayload(se); String tmpFileName = fileName + "." + writeVersion.ToString() + ".adk"; // 2) Write the message out to a file SchemaValidator.WriteObject(writeVersion, tmpFileName, smp); // 3) Validate the file bool validated = sv.Validate(tmpFileName); // 4) If validation failed, write the object out for tracing purposes if (!validated) { if (VERBOSE) { SifWriter outWriter = new SifWriter(output); outWriter.Write(se, writeVersion); outWriter.Flush(); } output.WriteLine("Validation failed on " + tmpFileName); sv.PrintProblems(output); return(false); } // 5) Read the object again into memory try { se = AdkObjectParseHelper.ParseFile(fileName, parseVersion); } catch (AdkException adke) { // Parsing failed. However, since this unit test is a complete // test of all available objects, just emit the problem and allow // the test to continue (with a notification of false) output.WriteLine("Error parsing file " + fileName + ": " + adke.Message); return(false); } catch (Exception re) { output.Write("Error parsing file " + fileName + ": " + re.Message + "\r\n"); return(false); } return(validated); }
public bool ReadRaw( XmlReader reader, SifVersion version, SifElement parent, SifFormatter formatter ) { String elementName = fElementDef.Name; if ( !reader.LocalName.Equals( elementName ) ) { return false; } String value = ConsumeElementTextValue( reader, version ); if ( value != null && value.Length > 0 ) { DateTime? time = formatter.ToTime( value ); SifTime sifTime = new SifTime( time ); parent.SetField( sifTime.CreateField( parent, fElementDef ) ); } return true; }
/// <summary> /// Creates an instance of a SIF_Request /// </summary> /// <param name="sifVersion">The version of SIF to render this message in</param> /// public SIF_Request(SifVersion sifVersion) : base(sifVersion, InfraDTD.SIF_REQUEST) { }
/// <summary> /// Constructs an ElementDefAlias with flag /// </summary> /// <param name="parent">The parent of this element</param> /// <param name="name">The name of the element</param> /// <param name="tag"></param> /// <param name="className"></param> /// <param name="sequence">The zero-based ordering of this element within its parent /// or -1 if a top-level element</param> /// <param name="localPackage">The name of the package where the corresponding /// DataObject class is defined, excluding the /// <c>OpenADK.Library</c> prefix</param> /// <param name="flags">One of the following: FD_ATTRIBUTE if this element should /// be rendered as an attribute of its parent rather than a child /// element; FD_FIELD if this element is a simple field with no child /// elements; or FD_OBJECT if this element is a SIF Data Object such /// as StudentPersonal or an infrastructure message such as SIF_Ack</param> /// <param name="earliestVersion">he earliest version of SIF supported by this element</param> /// <param name="latestVersion"></param> /// <param name="converter"></param> public ElementDefAlias( IElementDef parent, string name, string tag, string className, int sequence, string localPackage, string variant, int flags, SifVersion earliestVersion, SifVersion latestVersion, TypeConverter converter ) : base(parent, name, tag, sequence, localPackage, variant, flags, earliestVersion, latestVersion, converter) { fClassName = className; if ( parent != null ) { ((ElementDefImpl) parent).addChild( this ); } }
/// <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..."); Adk.Initialize(SifVersion.LATEST, SIFVariant.SIF_AU, (int)SdoLibraryType.Student); // Read the configuration file fCfg = new AgentConfig(); Console.WriteLine("Reading configuration file..."); fCfg.Read("agent.cfg", false); // Override the SourceId passed to the constructor with the SourceId // specified in the configuration file 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); // Establish the ODBC connection to the Students.mdb database file. // The JDBC driver and URL are specified in the agent.cfg configuration // file and were automatically added to the AgentProperties when the // apply method was called above. // Console.WriteLine("Opening database..."); AgentProperties props = Properties; string driver = props.GetProperty("Connection"); string url = props.GetProperty("ConnectionString"); Console.WriteLine("- Using driver: " + driver); Console.WriteLine("- Connecting to URL: " + url); // Load the DataDriver driver // Get a Connection fConn = new OleDbConnection(); fConn.ConnectionString = url; // Connect to each zone specified in the configuration file, registering // this agent as the Provider of Learner objects. Once connected, // send a request for LearnerPersonal. // Console.WriteLine("Connecting to zones and requesting LearnerPersonal objects..."); IZone[] allZones = ZoneFactory.GetAllZones(); for (int i = 0; i < allZones.Length; i++) { try { // Connect to this zone Console.WriteLine ("- Connecting to zone \"" + allZones[i].ZoneId + "\" at " + allZones[i].ZoneUrl); allZones[i].SetPublisher (this, StudentDTD.STUDENTPERSONAL, new PublishingOptions()); allZones[i].SetQueryResults(this); allZones[i].Connect(ProvisioningFlags.Register); // Request all students Query q = new Query(StudentDTD.STUDENTPERSONAL); q.UserData = "Mappings Demo"; allZones[i].Query(q); } catch (AdkException ex) { Console.WriteLine(" " + ex.Message); } } }
/// <summary> Constructs an IElementDef with flag /// /// </summary> /// <param name="parent">The parent of this element /// </param> /// <param name="name">The version-independent name of the element /// </param> /// <param name="tag">The element or attribute tag (if different from the name) /// </param> /// <param name="sequence">The zero-based ordering of this element within its parent /// or -1 if a top-level element /// </param> /// <param name="localPackage">The name of the package where the corresponding /// DataObject class is defined, excluding the /// <c>OpenADK.Library</c> prefix /// </param> /// <param name="earliestVersion">The earliest version of SIF supported by this /// element. If the element is supported in any other version of SIF - /// or is deprecated in a later version - the SdoLibrary class must /// define it by calling <c>DefineVersionInfo</c> /// </param> /// <param name="latestVersion">The latest version of SIF supported by this element</param> public ElementDefImpl(IElementDef parent, string name, string tag, int sequence, string localPackage, SifVersion earliestVersion, SifVersion latestVersion) : this(parent, name, tag, sequence, localPackage, (int) 0, earliestVersion, latestVersion) { }
/// <summary> Evaluates this rule against a SIFDataObject and returns the text value /// of the element or attribute that satisfied the query. /// /// </summary> /// <param name="context">The SifXPathcontext instance to use for object traversal </param> /// <param name="version">The SIF version that is in effect</param> /// <returns>The SimpleType representing the value of the element or attribute that /// satisfied the query, or null if no match found /// </returns> public abstract SifSimpleType Evaluate(SifXPathContext context, SifVersion version);
/// <summary> /// The real constructor /// </summary> /// <param name="parent"></param> /// <param name="name"></param> /// <param name="tag"></param> /// <param name="sequence"></param> /// <param name="localPackage"></param> /// <param name="variant"></param> /// <param name="flags"></param> /// <param name="earliestVersion"></param> /// <param name="latestVersion"></param> /// <param name="typeConverter"></param> public ElementDefImpl(IElementDef parent, string name, string tag, int sequence, string localPackage, string variant, int flags, SifVersion earliestVersion, SifVersion latestVersion, TypeConverter typeConverter) { fName = name; if ((flags & FD_ATTRIBUTE) != 0) { // If this is an attribute, it is also a simple field flags |= FD_FIELD; } fFlags = flags; fPackage = localPackage; fVariant = variant; fParent = (ElementDefImpl) parent; fTypeConverter = typeConverter; DefineVersionInfo(earliestVersion, tag == null ? name : tag, sequence, flags); fLatestVersion = latestVersion; if (fParent != null) { fParent.addChild(this); } }
/// <summary> /// Creates an instance of a SIF_ServiceOutput /// </summary> /// <param name="sifVersion">The version of SIF to render this message in</param> /// public SIF_ServiceOutput(SifVersion sifVersion) : base(sifVersion, InfraDTD.SIF_SERVICEOUTPUT) { }
public virtual int GetSequence(SifVersion version) { return Info(version).Sequence; }
public Sif1xElementSorter(SifVersion version) : base(version) { }
public IElementVersionInfo GetVersionInfo(SifVersion version) { return GetAbstractVersionInfo(version, false); }
/// <summary> /// Creates a child element, if supported by this node /// </summary> /// <param name="parentPointer"></param> /// <param name="formatter"></param> /// <param name="version"></param> /// <param name="context"></param> /// <returns></returns> public INodePointer CreateChild(INodePointer parentPointer, SifFormatter formatter, SifVersion version, SifXPathContext context) { return(null); }
public bool IsCollapsed(SifVersion version) { return Info(version).GetFlag(AbstractVersionInfo.FLAG_COLLAPSE); }
/// <summary> /// Called by the ADK XPath traversal code when it is traversing the given element /// in a legacy version of SIF /// </summary> /// <param name="parentPointer">The parent element pointer</param> /// <param name="element">The Element to create a node pointer for</param> /// <param name="version">The SIFVersion in effect</param> /// <returns>A NodePointer representing the current element</returns> public INodePointer CreateNodePointer(INodePointer parentPointer, Element element, SifVersion version) { return(null); }
public virtual bool IsRepeatable(SifVersion version) { return Info(version).GetFlag(AbstractVersionInfo.FLAG_REPEATABLE); }
/// <summary> /// Creates an instance of a SIF_ServiceNotify /// </summary> /// <param name="sifVersion">The version of SIF to render this message in</param> /// public SIF_ServiceNotify(SifVersion sifVersion) : base(sifVersion, InfraDTD.SIF_SERVICENOTIFY) { }
/// <summary> /// Returns the TagName for the specified element, using the specified version /// </summary> /// <param name="version"></param> /// <returns></returns> public virtual string Tag(SifVersion version) { return Info(version).Tag; }
/// <summary> /// Creates an instance of a SIF_Unsubscribe /// </summary> /// <param name="sifVersion">The version of SIF to render this message in</param> /// public SIF_Unsubscribe(SifVersion sifVersion) : base(sifVersion, InfraDTD.SIF_UNSUBSCRIBE) { }
/// <summary> Lookup the VersionInfo object for a specific version of SIF.</summary> private AbstractVersionInfo Info(SifVersion v) { return GetAbstractVersionInfo(v, true); }
/// <summary> /// Called by the ADK XPath traversal code when it is traversing the given element /// in a legacy version of SIF /// </summary> /// <param name="parentPointer">The parent element pointer</param> /// <param name="sourceElement">The Element to create a node pointer for</param> /// <param name="version">The SIFVersion in effect</param> /// <returns>A NodePointer representing the current element</returns> public INodePointer CreateNodePointer(INodePointer parentPointer, Element sourceElement, SifVersion version) { // 1) Find the field referenced by the XPathSurrogate expression // If it doesn't exist, return null Element referencedField = FindReferencedElement(sourceElement); if (referencedField == null) { return(null); } // 2) If it does exist, build out a fake set of node pointers representing the // SIF 1.5r1 path and return the root pointer. return(BuildLegacyPointers(parentPointer, referencedField)); }