Exemplo n.º 1
0
        public void TestStableSortInGetContent()
        {
            if( !Adk.Initialized )
            {
                Adk.Initialize();
            }

            SIF_Register sr = new SIF_Register();

            sr.SIF_Icon = "test.ico";

            // Create the original list of SIF_Version strings
            string[] list = new string[5];
            list[0] = "1.1";
            list[1] = "2.*";
            list[2] = "2.0r1";
            list[3] = "2.5";
            list[4] = "1.0r1";

            for( int a = 0; a < 5; a++ )
            {
                sr.AddSIF_Version( new SIF_Version( list[a] ) );
            }

            sr.SIF_Name = "AgentName";
            sr.SIF_Mode = "Push";

            IList<Element> elements = Adk.Dtd.GetFormatter( SifVersion.SIF11 ).GetContent( sr, SifVersion.SIF11 );

            // We should have gotten back a list of elements like this:
            // SIF_Name
            // 5 SIF_Version elements
            // SIF_Mode
            // SIF_Icon (only if the version is 2.0 or greater)

            Assert.AreEqual( "AgentName", elements[0].TextValue );
            // Assert that the SIF_Version elements returned are still in the order they went in
            for (int a = 0; a < 5; a++)
            {
                Assert.AreEqual( list[a], elements[a+1].TextValue );
            }
            Assert.AreEqual("Push", elements[6].TextValue);
            // NOTE: SIF_Icon is not present in SIF 1.1

            elements = Adk.Dtd.GetFormatter(SifVersion.SIF21).GetContent(sr, SifVersion.SIF21);

            Assert.AreEqual("AgentName", elements[0].TextValue);
            // Assert that the SIF_Version elements returned are still in the order they went in
            for (int a = 0; a < 5; a++)
            {
                Assert.AreEqual(list[a], elements[a + 1].TextValue);
            }
            Assert.AreEqual("Push", elements[6].TextValue);
            Assert.AreEqual("test.ico", elements[7].TextValue);
        }
Exemplo n.º 2
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);
        }