Example #1
0
        public bool Parse(string[] args, SessionConfiguration sc)
        {
            try
            {
                for (int i = 0; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                    case "-h":
                        i++;
                        sc.IpPort = IpPort.Parse(args[i]);
                        break;

                    case "-u":
                        i++;
                        sc.SetRouterUsername(UserVpn.Parse(args[i]));
                        break;

                    case "-w":
                        i++;
                        sc.SetUserPassword(args[i]);
                        break;

                    case "-z":
                        sc.Compression = true;
                        break;

                    case "-t":
                        i++;
                        string dm = args[i].ToLower();
                        MessageDeliveryMode?dmobj = ParseDeliveryMode(dm);
                        if (dmobj != null)
                        {
                            sc.DeliveryMode = dmobj.Value;
                        }
                        else
                        {
                            return(false);                                // err
                        }
                        break;

                    case "-l":
                        i++;
                        setLogLevel(args[i]);
                        break;

                    case "--durable":
                        sc.UseDurableEndpoint = true;
                        break;

                    case "-help":
                        return(false);    // err: print help

                    default:
                        string str_key   = args[i];
                        string str_value = "";
                        if (i + 1 < args.Length)
                        {
                            string str_tmpvalue = args[i + 1];                                 // lookahead
                            if (!str_tmpvalue.StartsWith("-"))
                            {
                                // we have a value!
                                i++;
                                str_value = args[i];
                            }
                        }
                        sc.ArgBag.Add(str_key, str_value);
                        break;
                    }
                }
            }
            catch (Exception)
            {
                return(false);                // err
            }

            bool clientCertUsed = false;

            if (sc.ArgBag.ContainsKey("-a"))
            {
                if (sc.ArgBag["-a"].Equals("CLIENT_CERTIFICATE"))
                {
                    clientCertUsed = true;
                }
            }

            if (sc.IpPort == null)
            {
                return(false);                // err
            }

            if (!clientCertUsed)
            {
                //Required when client certificates aren't used.
                if (sc.RouterUserVpn == null)
                {
                    return(false);
                }

                //Required when client certificates aren't used.
                if (sc.RouterUserVpn.user.Length == 0)
                {
                    return(false);
                }
            }

            // Disable certificate validation for all samples (Except secureSession which
            // will set this value from its own argument parser).
            sc.validateCertificate = false;

            return(true);            // success
        }
Example #2
0
        public bool ParseCacheSampleArgs(string[] args)
        {
            CacheSessionConfiguration cf = new CacheSessionConfiguration();

            this.sc = cf;
            Parse(args, this.sc);             //Parse common arguments

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "-c":
                    i++;
                    if (i >= args.Length)
                    {
                        return(false);
                    }
                    cf.CacheName = args[i];
                    break;

                case "-m":
                    i++;
                    if (i >= args.Length)
                    {
                        return(false);
                    }
                    cf.MaxMsgs = System.Int32.Parse(args[i]);
                    break;

                case "-a":
                    i++;
                    if (i >= args.Length)
                    {
                        return(false);
                    }
                    cf.MaxAge = Int32.Parse(args[i]);
                    break;

                case "-l":
                    i++;
                    setLogLevel(args[i]);
                    break;

                case "-o":
                    i++;
                    if (i >= args.Length)
                    {
                        return(false);
                    }
                    cf.Timeout = System.Int32.Parse(args[i]);
                    break;

                case "-s":
                    i++;
                    if (i >= args.Length)
                    {
                        return(false);
                    }
                    cf.Subscribe = Boolean.Parse(args[i]);
                    break;

                case "-d":
                    i++;
                    if (i >= args.Length)
                    {
                        return(false);
                    }
                    cf.Action = ParseCacheLiveDataAction(args[i]);
                    break;

                default:
                    break;
                }
            }

            if (cf.CacheName == null)
            {
                System.Console.Error.WriteLine("No cache name specified");
                return(false);
            }
            return(true);
        }
Example #3
0
        /// <summary>
        /// Creates a SessionProperties instance based on parsed SessionConfiguration
        /// </summary>
        /// <param name="sc"></param>
        /// <returns></returns>
        public static SessionProperties NewSessionPropertiesFromConfig(SessionConfiguration sc)
        {
            SessionProperties sessionProps = new SessionProperties();

            // Message backbone IP
            sessionProps.Host = sc.IpPort.ip;
            // User name
            if (sc.RouterUserVpn != null)
            {
                sessionProps.UserName = sc.RouterUserVpn.user;
                if (sc.RouterUserVpn.vpn != null)
                {
                    sessionProps.VPNName = sc.RouterUserVpn.vpn;  // applies to SolOS-TR only
                }
            }
            // Turn ReapplySubscriptions on to enable api-based subscription management
            sessionProps.ReapplySubscriptions = true;

            sessionProps.Password = sc.UserPassword;
            if (sc.Compression)
            {
                //
                // Compression is set as a number from 0-9. 0 means
                // "disable compression" (the default), and 9 means maximum compression.
                // Selecting a non-zero compression level auto-selects the
                // compressed SMF port on the appliance, as long as no SMF port is
                // explicitly specified.

                sessionProps.CompressionLevel = 9;
            }
            // To enable session reconnect
            sessionProps.ReconnectRetries            = 100;  // retry 100 times
            sessionProps.ReconnectRetriesWaitInMsecs = 3000; // 3 seconds

            //SSL properties.
            sessionProps.SSLTrustStoreDir                = sc.trustStoreDirectory;
            sessionProps.SSLTrustedCommonNameList        = sc.commonNames;
            sessionProps.SSLCipherSuites                 = sc.cipherSuites;
            sessionProps.SSLExcludedProtocols            = sc.excludedProtocols;
            sessionProps.SSLValidateCertificate          = sc.validateCertificate;
            sessionProps.SSLValidateCertificateDate      = sc.validateCertificateDate;
            sessionProps.AuthenticationScheme            = sc.authenticationScheme;
            sessionProps.SSLClientPrivateKeyFile         = sc.clientPrivateKeyFile;
            sessionProps.SSLClientPrivateKeyFilePassword = sc.clientPrivateKeyPassword;
            sessionProps.SSLClientCertificateFile        = sc.clientCertificateFile;
            sessionProps.SSLConnectionDowngradeTo        = sc.sslConnectionDowngradeTo;

            // Uncomment the following statement to enable automatic timestamp generation on sent messages.
            // When enabled, a send timestamp is automatically generated as a message property for each message sent.
            // This adds a binary meta part to the message which can reduce performance.
            // sessionProps.GenerateSendTimestamps = true;

            // Uncomment the following statement to enable automatic sequence number generation on sent messages.
            // When enabled, a sequence number is automatically included in the Solace-defined fields for each message sent.
            // This adds a binary meta part to the message which can reduce performance.
            // sessionProps.GenerateSequenceNumber = true;

            // Uncomment the following statement to enable the inclusion of senderId on sent messages.
            // When enabled, a sender ID is automatically included in the Solace-defined fields for each message sent.
            // This adds a binary meta part to the message which can reduce performance.
            // sessionProps.IncludeSenderId = true;

            return(sessionProps);
        }