Ejemplo n.º 1
0
        public static IATSSCD CreateProxy(ScuOptions options)
        {
            IATSSCD proxy;

            if (options.ServiceUrl.StartsWith("https://"))
            {
                proxy = GenerateHttpsProxy(options);
            }
            else if (options.ServiceUrl.StartsWith("http://"))
            {
                proxy = GenerateHttpProxy(options);
            }
            else if (options.ServiceUrl.StartsWith("net.pipe://"))
            {
                proxy = GenerateNetPipeProxy(options);
            }
            else if (options.ServiceUrl.StartsWith("net.tcp://"))
            {
                proxy = GenerateNetTcpProxy(options);
            }
            else
            {
                throw new ArgumentException();
            }

            return(proxy);
        }
Ejemplo n.º 2
0
        public static IATSSCD GenerateHttpProxy(ScuOptions options)
        {
            IATSSCD proxy;
            //var binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
            //var factory = new ChannelFactory<IATSSCD>(binding, new EndpointAddress(url));
            //proxy = factory.CreateChannel();
            var binding = new BasicHttpBinding
            {
                Security =
                {
                    Mode      = BasicHttpSecurityMode.TransportCredentialOnly,
                    Transport =
                    {
                        ClientCredentialType = HttpClientCredentialType.None
                                               //ClientCredentialType= HttpClientCredentialType.Basic
                    }
                }
            };
            var factory = new ChannelFactory <IATSSCD>(binding, new EndpointAddress(options.ServiceUrl));

            factory.Credentials.UserName.UserName = options.CashboxId.ToString();
            factory.Credentials.UserName.Password = options.AccessToken;
            proxy = factory.CreateChannel();
            return(proxy);
        }
Ejemplo n.º 3
0
        public static IATSSCD GenerateNetTcpProxy(ScuOptions options)
        {
            IATSSCD proxy;
            var     binding = new NetTcpBinding(SecurityMode.None);
            var     factory = new ChannelFactory <IATSSCD>(binding, new EndpointAddress(options.ServiceUrl));

            proxy = factory.CreateChannel();
            return(proxy);
        }
Ejemplo n.º 4
0
        public static ScuOptions GetScuOptionsFromCommandLine(string[] args)
        {
            var option = new ScuOptions();

            Parser.Default.ParseArguments <ScuOptions>(args)
            .WithParsed(opts => { option = opts; })
            .WithNotParsed((errs) =>
            {
                option = GetScuOptionsFromReadLineLoop();
            });
            return(option);
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            try
            {
                ServicePointManager.DefaultConnectionLimit = 65535;
                var options = ScuOptions.GetScuOptionsFromCommandLine(args);
                var proxy   = ProxyFactory.CreateProxy(options);

                CheckSCU(proxy);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            Console.ReadLine();
        }
Ejemplo n.º 6
0
        public static ScuOptions GetScuOptionsFromReadLineLoop()
        {
            var option     = new ScuOptions();
            var properties = typeof(ScuOptions).GetProperties();

            foreach (var property in properties)
            {
                OptionAttribute attr = property.GetCustomAttributes(typeof(OptionAttribute), true).FirstOrDefault() as OptionAttribute;
                if (attr != null)
                {
                    string value = "";
                    while (value == string.Empty)
                    {
                        if (attr.Default != null)
                        {
                            Console.Write($"{attr.LongName} ({attr.Default}):");
                        }
                        else
                        {
                            Console.Write($"{attr.LongName}:");
                        }

                        value = ReadLine();
                        if (string.IsNullOrWhiteSpace(value) && attr.Default != null)
                        {
                            Console.Error.WriteLine($"No value given for {attr.LongName}. Using Default Value: {attr.Default}");
                            value = attr.Default.ToString();
                        }

                        if (string.IsNullOrEmpty(value))
                        {
                            Console.Error.WriteLine($"Error. Please provide a value for {attr.LongName}.");
                        }
                    }

                    property.SetValue(option, TypeDescriptor.GetConverter(property.PropertyType).ConvertFromInvariantString(value));
                }
            }
            return(option);
        }