コード例 #1
0
ファイル: FProxyConfig.cs プロジェクト: gas3/twain
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(string.Format(MiscResources.ConfirmDelete, comboName.Text), MiscResources.Delete, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                var savedProxies = UserConfigManager.Config.SavedProxies;
                savedProxies.RemoveAll(x => x.Name == comboName.Text);
                UserConfigManager.Save();

                ProxyConfig = new ScanProxyConfig();
                UpdateDropdown();
                UpdateControls();
            }
        }
コード例 #2
0
ファイル: ClientContextFactory.cs プロジェクト: gas3/twain
        public ClientContext Create(ScanProxyConfig proxyConfig)
        {
            // TODO: Validate IP
            var uri             = new Uri($"net.tcp://{proxyConfig.Ip}:{proxyConfig.Port}/NAPS2.Server");
            var callback        = new ScanCallback();
            var instanceContext = new InstanceContext(callback);
            var channelFactory  = new DuplexChannelFactory <IScanService>(instanceContext,
                                                                          new NetTcpBinding
            {
                MaxReceivedMessageSize = 1024 * 1024 * 1024,
                Security = { Mode = SecurityMode.None }
            },
                                                                          new EndpointAddress(uri));
            var channel = channelFactory.CreateChannel();

            return(new ClientContext {
                Service = channel, Callback = callback
            });
        }
コード例 #3
0
ファイル: FProxyConfig.cs プロジェクト: gas3/twain
        protected override void OnLoad(object sender, EventArgs eventArgs)
        {
            new LayoutManager(this)
            .Bind(comboName)
            .WidthToForm()
            .Bind(txtIP)
            .WidthTo(() => Width * 2 / 3)
            .Bind(txtPort)
            .WidthTo(() => Width / 3)
            .Bind(lblPort)
            .LeftTo(() => txtPort.Left)
            .Bind(txtPort, btnCancel, btnOK, btnDelete)
            .RightToForm()
            .Activate();

            ProxyConfig        = ProxyConfig ?? new ScanProxyConfig();
            cbUseProxy.Checked = UseProxy;
            UpdateDropdown();
            UpdateControls();

            new Thread(() => ServerDiscovery.SendBroadcast((computerName, ep) =>
            {
                SafeInvoke(() =>
                {
                    if (string.IsNullOrWhiteSpace(txtIP.Text))
                    {
                        // TODO: Maybe add all responses to dropdown/saved
                        ProxyConfig = new ScanProxyConfig
                        {
                            Name = computerName,
                            Ip   = ep.Address.ToString(),
                            Port = ep.Port
                        };
                        UpdateControls();
                    }
                });
            })).Start();
        }
コード例 #4
0
ファイル: FProxyConfig.cs プロジェクト: gas3/twain
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!cbUseProxy.Checked)
            {
                ProxyConfig  = null;
                DialogResult = DialogResult.OK;
                Close();
                return;
            }

            const NumberStyles numberStyle = NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingSign;

            if (string.IsNullOrWhiteSpace(txtIP.Text) || txtIP.Text.Contains('/'))
            {
                txtIP.Focus();
                return;
            }
            if (!int.TryParse(txtPort.Text, numberStyle, CultureInfo.CurrentCulture, out int port))
            {
                txtPort.Focus();
                return;
            }
            ProxyConfig = new ScanProxyConfig
            {
                Name = comboName.Text,
                Ip   = txtIP.Text,
                Port = port
            };
            if (!string.IsNullOrWhiteSpace(comboName.Text))
            {
                var savedProxies = UserConfigManager.Config.SavedProxies;
                savedProxies.RemoveAll(x => x.Name == ProxyConfig.Name);
                savedProxies.Add(ProxyConfig);
                UserConfigManager.Save();
            }
            DialogResult = DialogResult.OK;
            Close();
        }