Esempio n. 1
0
        private static ResponsePacketInfo DeserializeResponseFileName(String shortFileName)
        {
            ResponsePacketInfo responsePacket = new ResponsePacketInfo();

            //  Get SIF_DestinationId, SIF_RequestMsgId, and SIF_PacketNumber from
            //  the filename
            //	FORMAT: "{requestSourceId}.{requestMsgId}.{packet#}.{ver}.{morePackets}[.$].pkt"

            //  the filename "{requestSourceId}.{requestMsgId}.{packet#}.pkt"
            string [] tokens = shortFileName.Split('.');
            String    destId = tokens[0];

            destId = deserializeToken(destId);
            responsePacket.destinationId = destId;
            responsePacket.requestMsgId  = tokens[1];
            responsePacket.packetNumber  = int.Parse(tokens[2]);
            string ver = tokens[3];

            ver = ver.Replace('_', '.');
            responsePacket.version = SifVersion.Parse(ver);

            //  A leading $ on the filename indicates this is a response packet
            //  with a SIF_Error
            responsePacket.errorPacket = shortFileName.EndsWith("$.pkt");

            return(responsePacket);
        }
Esempio n. 2
0
        public void testSameInstance()
        {
            SifVersion v1 = SifVersion.Parse("2.0");

            Assert.IsTrue(v1 == SifVersion.SIF20, "2.0");
            Assert.IsTrue(v1.Equals(SifVersion.SIF20), "2.0");

            v1 = SifVersion.Parse("2.0r1");
            Assert.IsTrue(v1 == SifVersion.SIF20r1, "2.0r1");
            Assert.IsTrue(v1.Equals(SifVersion.SIF20r1), "2.0r1");

            v1 = SifVersion.Parse("2.1");
            Assert.IsTrue(v1 == SifVersion.SIF21, "2.1");
            Assert.IsTrue(v1.Equals(SifVersion.SIF21), "2.1");

            v1 = SifVersion.Parse("1.1");
            Assert.IsTrue(v1 == SifVersion.SIF11, "1.1");
            Assert.IsTrue(v1.Equals(SifVersion.SIF11), "1.1");

            v1 = SifVersion.Parse("1.5r1");
            Assert.IsTrue(v1 == SifVersion.SIF15r1, "1.5r1");
            Assert.IsTrue(v1.Equals(SifVersion.SIF15r1), "1.5r1");

            v1 = SifVersion.Parse("3.69r55");
            SifVersion v2 = SifVersion.Parse("3.69r55");

            Assert.IsTrue(v1 == v2, "3.69r55");
            Assert.IsTrue(v1.Equals(v2));
        }
Esempio n. 3
0
        public void ADKIntegrityTest()
        {
            SifVersion[] versions = Adk.SupportedSIFVersions;

            foreach (SifVersion version in versions)
            {
                Assert.IsTrue(Adk.IsSIFVersionSupported(version), version.ToString());
                Assert.AreEqual(version, SifVersion.Parse(version.ToString()), version.ToString());
            }
        }
Esempio n. 4
0
        public void testParse()
        {
            assertSIFVersion(SifVersion.Parse("1.0r1"), 1, 0, 1, "1.0r1");
            assertSIFVersion(SifVersion.Parse("1.0r2"), 1, 0, 2, "1.0r2");
            assertSIFVersion(SifVersion.Parse("1.1r3"), 1, 1, 3, "1.1r3");
            assertSIFVersion(SifVersion.Parse("1.1"), 1, 1, 0, "1.1");
            assertSIFVersion(SifVersion.Parse("1.5"), 1, 5, 0, "1.5");
            assertSIFVersion(SifVersion.Parse("1.5r1"), 1, 5, 1, "1.5r1");
            assertSIFVersion(SifVersion.Parse("2.0"), 2, 0, 0, "2.0");
            assertSIFVersion(SifVersion.Parse("2.0r1"), 2, 0, 1, "2.0r1");

            assertSIFVersion(SifVersion.Parse("3.0"), 3, 0, 0, "3.0");
            assertSIFVersion(SifVersion.Parse("5.0r77"), 5, 0, 77, "5.0r77");
        }
        private void assertTransactionInfo(Transaction trans)
        {
            Assert.AreEqual("Transaction", trans.ElementDef.Name, "version-independent name");

            // assert the tag name for SIF 1.1: “CircTx”
            Assert.AreEqual("CircTx", trans.ElementDef.Tag(SifVersion.SIF11), "SIF 1.1 Should be CircTx");

            // assert the tag name for SIF 1.5: “CircTx”
            Assert.AreEqual("CircTx", trans.ElementDef.Tag(SifVersion.Parse("1.5")), "SIF 1.5 Should be CircTx");

            // assert the tag name for SIF 1.5r1: “CircTx”
            Assert.AreEqual("CircTx", trans.ElementDef.Tag(SifVersion.SIF15r1), "SIF 1.5r1 Should be CircTx");

            // assert the tag name for SIF 2.0: “Transaction”
            Assert.AreEqual("Transaction", trans.ElementDef.Tag(SifVersion.SIF20), "SIF 2.0 Should be Transaction");

            // assert the tag name for SIF 2.1: “Transaction”
            Assert.AreEqual("Transaction", trans.ElementDef.Tag(SifVersion.SIF21), "SIF 2.1 Should be Transaction");
        }
Esempio n. 6
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");
        }
Esempio n. 7
0
// BEGIN EXTRA METHODS (C:/GitHub/rafidzal/OpenADK-java/adk-generator/../adk-generator/datadef/core/sif20/SIF_Request.txt.cs)

        /// <summary>
        /// Parses the list of SIF_Version elements and returns an array of SIFVersions
        /// </summary>
        /// <param name="failureLog">The log to write failures to, if any of the SIFVersions fail
        /// to be parsed.</param>
        /// <returns><An array of SIFVersion elements. This will never be null/returns>
        internal SifVersion[] parseRequestVersions(log4net.ILog failureLog)
        {
            if (failureLog == null)
            {
                failureLog = Adk.Log;
            }
            System.Collections.Generic.List <SifVersion> versionList = new System.Collections.Generic.List <SifVersion>();
            foreach (SifElement element in GetChildList(InfraDTD.SIF_REQUEST_SIF_VERSION))
            {
                SIF_Version candidate = (SIF_Version)element;
                SifVersion  version   = null;
                try {
                    // Check for "1.*" and "2.*"
                    String ver = candidate.Value;
                    if (ver != null)
                    {
                        if (ver.IndexOf(".*") > 0)
                        {
                            version = SifVersion.GetLatest(int.Parse(ver.Substring(0, 1)));
                        }
                        else
                        {
                            version = SifVersion.Parse(ver);
                        }
                    }
                } catch (ArgumentException exc) {
                    failureLog.Warn(String.Format("Unable to parse '{0}' from SIF_Request/SIF_Version as SIFVersion.", candidate.Value), exc);
                }
                catch (FormatException exc)
                {
                    failureLog.Warn(String.Format("Unable to parse '{0}' from SIF_Request/SIF_Version as SIFVersion.", candidate.Value), exc);
                }
                if (version != null && !versionList.Contains(version))
                {
                    versionList.Add(version);
                }
            }

            return(versionList.ToArray());
        }
Esempio n. 8
0
        protected internal virtual void onRoot(XmlElement node)
        {
            fLocalPackage = getAttr(node, "package");
            String ver = getAttr(node, "version");

            fNamespace = getAttr(node, "namespace");

            if (fLocalPackage == null || ver == null || fNamespace == null)
            {
                throw new ParseException
                          ("<adk> must specify the package=, version=, and namespace= attributes");
            }

            fVersion = SifVersion.Parse(ver);
            fPackage = "Edustructures.SifWorks." + fLocalPackage;

            Console.Out.WriteLine("    Package=" + fPackage);
            Console.Out.WriteLine("    Version=" + ver + " (" + this.fVersion + ")");
            Console.Out.WriteLine("    Namespace=" + fNamespace);

            fDB = MetaDataSchema.getDB(fVersion);
        }
Esempio n. 9
0
        public void TestOperatorOverloads()
        {
            // > operator
            Assert.IsTrue(SifVersion.SIF22 > SifVersion.SIF21);

            // < operator
            Assert.IsTrue(SifVersion.SIF21 < SifVersion.SIF22);

            // >= operator
            Assert.IsTrue(SifVersion.SIF22 >= SifVersion.SIF21);
            Assert.IsTrue(SifVersion.SIF22 >= SifVersion.SIF21);
            Assert.IsFalse(SifVersion.SIF21 >= SifVersion.SIF22);

            // <= operator
            Assert.IsTrue(SifVersion.SIF21 <= SifVersion.SIF22);
            Assert.IsTrue(SifVersion.SIF21 <= SifVersion.SIF22);
            Assert.IsFalse(SifVersion.SIF22 <= SifVersion.SIF21);

            // == operator
            Assert.IsTrue(SifVersion.Parse("2.2") == SifVersion.SIF22, "==");
            Assert.IsFalse(SifVersion.Parse("2.1") == SifVersion.SIF22, "==");
        }
Esempio n. 10
0
        public void testAllOfficiallySupportedVersions()
        {
            SifVersion[] versions = Adk.SupportedSIFVersions;

            assertSIFVersion(SifVersion.Parse("1.1"), 1, 1, 0, "1.1");
            Assert.AreEqual(SifVersion.SIF11, SifVersion.Parse("1.1"));
            Assert.IsTrue(Adk.IsSIFVersionSupported(SifVersion.SIF11));
            Assert.AreEqual(0, Array.BinarySearch(versions, SifVersion.SIF11), "1.1");


            assertSIFVersion(SifVersion.Parse("1.5r1"), 1, 5, 1, "1.5r1");
            Assert.AreEqual(SifVersion.SIF15r1, SifVersion.Parse("1.5r1"));
            Assert.IsTrue(Adk.IsSIFVersionSupported(SifVersion.SIF15r1));
            Assert.AreEqual(1, Array.BinarySearch(versions, SifVersion.SIF15r1), "1.5r1");

            assertSIFVersion(SifVersion.Parse("2.0"), 2, 0, 0, "2.0");
            Assert.AreEqual(SifVersion.SIF20, SifVersion.Parse("2.0"));
            Assert.IsTrue(Adk.IsSIFVersionSupported(SifVersion.SIF20));
            Assert.AreEqual(2, Array.BinarySearch(versions, SifVersion.SIF20), "2.0");

            assertSIFVersion(SifVersion.Parse("2.0r1"), 2, 0, 1, "2.0r1");
            Assert.AreEqual(SifVersion.SIF20r1, SifVersion.Parse("2.0r1"));
            Assert.IsTrue(Adk.IsSIFVersionSupported(SifVersion.SIF20r1));
            Assert.AreEqual(3, Array.BinarySearch(versions, SifVersion.SIF20r1), "2.0r1");

            assertSIFVersion(SifVersion.Parse("2.1"), 2, 1, 0, "2.1");
            Assert.AreEqual(SifVersion.SIF21, SifVersion.Parse("2.1"));
            Assert.IsTrue(Adk.IsSIFVersionSupported(SifVersion.SIF21));
            Assert.AreEqual(4, Array.BinarySearch(versions, SifVersion.SIF21), "2.1");

            assertSIFVersion(SifVersion.Parse("2.2"), 2, 2, 0, "2.2");
            Assert.AreEqual(SifVersion.SIF22, SifVersion.Parse("2.2"));
            Assert.IsTrue(Adk.IsSIFVersionSupported(SifVersion.SIF22));
            Assert.AreEqual(4, Array.BinarySearch(versions, SifVersion.SIF21), "2.2");

            Assert.AreEqual(SifVersion.LATEST, SifVersion.Parse("2.4"));

            Assert.IsTrue(SifVersion.Parse("2.4").Equals(SifVersion.LATEST), "Latest");
        }
Esempio n. 11
0
        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);
                }
            }
        }
Esempio n. 12
0
 public void test2DotStar()
 {
     Assert.AreEqual(SifVersion.GetLatest(2), SifVersion.Parse("2.*"));
 }
Esempio n. 13
0
        /**
         *  SIF_Request
         */
        public SIF_Ack SifRequest(IZone zone, Query query, String destinationId, String sifMsgId)
        {
            //  Send SIF_Request...
            SIF_Request msg = new SIF_Request();
            // Find the maxmimum requested version and set the version of the message to lower
            // if the version is currently higher than the highest requested version.
            // In other words, if the Adk is initialized to 2.0, but the highest requested version
            // is 1.5r1, set the message version to 1.5r1
            SifVersion highestRequestVersion = SifVersion.SIF11;

            if (query.ObjectType == InfraDTD.SIF_ZONESTATUS)
            {
                // This query will be satisfied by the ZIS. Use the ZIS compatibility
                // version, which returns the highest version supported by the ZIS
                // (Default to Adk.SIFVersion() if not specified in the config)
                highestRequestVersion = ((ZoneImpl)zone).HighestEffectiveZISVersion;
                msg.AddSIF_Version(new SIF_Version(highestRequestVersion));
            }
            else
            {
                SifVersion[] requestVersions = query.SifVersions;
                if (requestVersions.Length > 0)
                {
                    // If the Query has one or more SIFVersions set, use them,
                    // and also add [major].*
                    foreach (SifVersion version in requestVersions)
                    {
                        msg.AddSIF_Version(new SIF_Version(version));
                        if (version.CompareTo(highestRequestVersion) > 0)
                        {
                            highestRequestVersion = version;
                        }
                    }
                }
                else
                {
                    highestRequestVersion = Adk.SifVersion;
                    if (highestRequestVersion.Major == 1)
                    {
                        msg.AddSIF_Version(new SIF_Version(highestRequestVersion));
                    }
                    else
                    {
                        // 2.0 and greater, request all data using
                        // [major].*, with 2.0r1 as the message version
                        // This allows for maximum compatibility will all 2.x providers
                        msg.AddSIF_Version(new SIF_Version(highestRequestVersion.Major + ".*"));
                        msg.SifVersion = SifVersion.GetEarliest(highestRequestVersion.Major);
                    }
                }
            }

            AgentProperties zoneProperties = zone.Properties;

            if (zoneProperties.OverrideSifMessageVersionForSifRequests != null)
            {
                //There is a property in Agent.cfg that can be used to override the message version from the
                //default of 2.0r1 This is needed to pass the test harness for 2.3
                msg.SifVersion = SifVersion.Parse(zoneProperties.OverrideSifMessageVersionForSifRequests);
            }

            else if (msg.SifVersion.CompareTo(highestRequestVersion) > 0)
            {
                // The current version of the SIF_Message is higher than the highest
                // requested version. Back the version number of message down to match
                msg.SifVersion = highestRequestVersion;
            }

            msg.SIF_MaxBufferSize = zone.Properties.MaxBufferSize;

            SIF_Query sifQ = CreateSIF_Query(query, highestRequestVersion, zone);

            msg.SIF_Query = sifQ;

            SIF_Header msgHeader = msg.Header;

            if (destinationId != null)
            {
                msgHeader.SIF_DestinationId = destinationId;
            }
            if (sifMsgId != null)
            {
                msgHeader.SIF_MsgId = sifMsgId;
            }

            // Set the SIF_Context
            msgHeader.SIF_Contexts = new SIF_Contexts(
                new SIF_Context(query.SifContext.Name));

            return(((ZoneImpl)zone).Dispatcher.send(msg));
        }
Esempio n. 14
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));
        }
Esempio n. 15
0
    /// <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);
    }
Esempio n. 16
0
	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;
			}
		}
	}