예제 #1
0
        public void testRegisterSIF20()
        {
            Adk.SifVersion = (SifVersion.SIF20);
            String          iconURL = "http://acme.foo.bar/ico";
            AgentProperties props   = Agent.Properties;

            props.AgentIconUrl = iconURL;

            Agent.Name         = "acmeAgent";
            props.AgentVendor  = "acmeVendor";
            props.AgentVersion = "2.6.5.8";

            props.ApplicationName    = "acmeApp";
            props.ApplicationVendor  = "acme<>AppVendor";
            props.ApplicationVersion = "10.2";

            Zone.Connect(ProvisioningFlags.Register);
            InMemoryProtocolHandler handler = (InMemoryProtocolHandler)Zone.ProtocolHandler;

            SIF_Register sr = (SIF_Register)handler.readMsg();

            Assert.AreEqual(Agent.Id, sr.SourceId, "SourceID");
            Assert.AreEqual("acmeAgent", sr.SIF_Name, "Name");
            Assert.AreEqual("acmeVendor", sr.SIF_NodeVendor, "Agent Vendor");
            Assert.AreEqual("2.6.5.8", sr.SIF_NodeVersion, "Agent Version");
            SIF_Application appInfo = sr.SIF_Application;

            Assert.IsNotNull(appInfo);
            Assert.AreEqual("acmeApp", appInfo.SIF_Product, "App Name");
            Assert.AreEqual("acme<>AppVendor", appInfo.SIF_Vendor, "App Vendor");
            Assert.AreEqual("10.2", appInfo.SIF_Version, "App Version");
            Assert.AreEqual(iconURL, sr.SIF_Icon, "Icon");
        }
예제 #2
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);
        }
예제 #3
0
        public void testSIFRegisterZISVersion15r1()
        {
            Adk.SifVersion = (SifVersion.LATEST);
            String          iconURL = "http://acme.foo.bar/ico";
            AgentProperties props   = Agent.Properties;

            // Set the ZIS Version to 1.5r1
            props.ZisVersion = SifVersion.SIF15r1.ToString();

            props.AgentIconUrl = iconURL;

            Agent.Name               = "acmeAgent";
            props.AgentVendor        = "acmeVendor";
            props.AgentVersion       = "2.6.5.8";
            props.ApplicationName    = "acmeApp";
            props.ApplicationVendor  = "acme<>AppVendor";
            props.ApplicationVersion = "10.2";


            Zone.Connect(ProvisioningFlags.Register);
            InMemoryProtocolHandler handler = (InMemoryProtocolHandler)Zone.ProtocolHandler;

            SIF_Register sr = (SIF_Register)handler.readMsg();

            Assert.AreEqual(SifVersion.SIF15r1, sr.SifVersion, "SifVersion");
            Assert.AreEqual(SifVersion.SIF15r1.Xmlns, sr.GetXmlns(), "SifVersion->Xmlns");

            Assert.AreEqual(Agent.Id, sr.SourceId, "SourceID");
            Assert.AreEqual("acmeAgent", sr.SIF_Name, "Name");
            Assert.IsNull(sr.SIF_NodeVendor, "Agent Vendor");
            Assert.IsNull(sr.SIF_NodeVersion, "Agent Version");
            SIF_Application appInfo = sr.SIF_Application;

            Assert.IsNull(appInfo);
            Assert.IsNull(sr.SIF_Icon, "Icon");


            // Assert the versions in the message. If the ADK is initialized to
            // SIF 1.5r1, it should not be sending any versions that start with a
            // "2"
            SifVersion messageVersion = sr.SifVersion;

            Assert.AreEqual(SifVersion.SIF15r1, messageVersion, "Should be version 1.5r1");
            foreach (SIF_Version version in sr.GetSIF_Versions())
            {
                String versionString = version.TextValue;
                Assert.IsTrue(versionString.StartsWith("1"), "Should start with 1 but was " + versionString);
            }
        }
예제 #4
0
        public void testRegisterOverrideZISVersion()
        {
            Adk.SifVersion = (SifVersion.SIF20);
            AgentProperties props = Agent.Properties;

            props.OverrideSifVersions = "1.1, 2.5";

            Zone.Connect(ProvisioningFlags.Register);
            InMemoryProtocolHandler handler = (InMemoryProtocolHandler)Zone.ProtocolHandler;

            SIF_Register sr = (SIF_Register)handler.readMsg();

            SIF_Version[] versions = sr.GetSIF_Versions();
            Assert.IsNotNull(versions);
            Assert.AreEqual(2, versions.Length);
            Assert.AreEqual("1.1", versions[0].Value);
            Assert.AreEqual("2.5", versions[1].Value);
        }
예제 #5
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));
        }