コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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));
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        public void testComparison()
        {
            Assert.AreEqual(0, SifVersion.SIF20.CompareTo(SifVersion.SIF20), "2.0<-->2.0");
            Assert.AreEqual(0, SifVersion.SIF20r1.CompareTo(SifVersion.SIF20r1), "2.0r1<-->2.0r1");
            Assert.AreEqual(0, SifVersion.SIF21.CompareTo(SifVersion.SIF21), "2.1<-->2.1");

            Assert.AreEqual(-1, SifVersion.SIF15r1.CompareTo(SifVersion.SIF20), "1.5r1<-->2.0");
            SifVersion custom = SifVersion.Parse("1.69r55");

            Assert.AreEqual(-1, custom.CompareTo(SifVersion.SIF20), "1.69r55<-->2.0");
            Assert.AreEqual(1, custom.CompareTo(SifVersion.SIF15r1), "1.69r55<-->1.5r1");

            custom = SifVersion.Parse("1.5r1");
            Assert.AreEqual(0, custom.CompareTo(SifVersion.SIF15r1), "1.5r1<-->1.5r1");

            custom = SifVersion.Parse("1.5r2");
            Assert.AreEqual(1, custom.CompareTo(SifVersion.SIF15r1), "1.5rr<-->1.5r1");

            custom = SifVersion.Parse("1.5r0");
            Assert.AreEqual(-1, custom.CompareTo(SifVersion.SIF15r1), "1.5r0<-->1.5r1");
        }
コード例 #5
0
        /// <summary>  Gets an ElementSorter for a given version of SIF</summary>
        /// <param name="version">The version of SIF to sort against
        /// </param>
        public static ElementSorter <T> GetInstance(SifVersion version)
        {
            if (version == null)
            {
                version = Adk.SifVersion;
            }

            if (version.CompareTo(SifVersion.SIF20) < 0)
            {
                return(new Sif1xElementSorter <T>(version));
            }
            return(new ElementSorter <T>(version));
        }
コード例 #6
0
        /// <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;
        }
コード例 #7
0
        /**
         *  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));
        }
コード例 #8
0
        /// <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;
        }