Example #1
0
 protected override void ProcessRecord()
 {
     base.ProcessRecord();
     try
     {
         client?.Dispose();
         int timeout = GetPreferredTimeout();
         WriteDebug($"Cmdlet Timeout : {timeout} milliseconds.");
         client = new LinkClient(AuthProvider, new Oci.Common.ClientConfiguration
         {
             RetryConfiguration = retryConfig,
             TimeoutMillis      = timeout,
             ClientUserAgent    = PSUserAgent
         });
         string region = GetPreferredRegion();
         if (region != null)
         {
             WriteDebug("Choosing Region:" + region);
             client.SetRegion(region);
         }
         if (Endpoint != null)
         {
             WriteDebug("Choosing Endpoint:" + Endpoint);
             client.SetEndpoint(Endpoint);
         }
     }
     catch (Exception ex)
     {
         TerminatingErrorDuringExecution(ex);
     }
 }
Example #2
0
        private void btnSend_Click(Object sender, EventArgs e)
        {
            if (_Client == null || !_Client.Active)
            {
                return;
            }

            var count = (Int32)numThreads.Value;

            if (count <= cs.Count)
            {
                return;
            }

            //var sc = _Client.Client.GetService<ISocketClient>();
            //if (sc == null) return;

            var uri = new NetUri(cbAddr.Text);

            Task.Run(() =>
            {
                var cc = _Client;
                for (var i = 0; i < count; i++)
                {
                    var ac = new LinkClient(uri.ToString())
                    {
                        //ac.Received += OnReceived;

                        UserName     = cc.UserName,
                        Password     = cc.Password,
                        ActionPrefix = cc.ActionPrefix
                    };

                    //ac.Encrypted = cc.Encrypted;
                    //ac.Compressed = cc.Compressed;

                    cs.Add(ac);

                    Task.Run(() =>
                    {
                        for (var k = 0; k < 10; k++)
                        {
                            if (ac.Open())
                            {
                                break;
                            }
                            Thread.Sleep(1000);
                        }

                        //// 共用统计对象
                        //if (ac.Active)
                        //{
                        //    var sc2 = ac.Client.GetService<ISocketClient>();
                        //    sc2.StatSend = sc.StatSend;
                        //    sc2.StatReceive = sc.StatReceive;
                        //}
                    });
                }
            });
        }
Example #3
0
 private void button1_Click(object sender, EventArgs e)
 {
     link              = new LinkClient(textBox3.Text);
     link.DataRenewed += Link_DataRenewed;
     label1.Text       = "Connected";
     button1.Enabled   = false;
     button2.Enabled   = true;
 }
Example #4
0
 private void button2_Click(object sender, EventArgs e)
 {
     link.DataRenewed -= Link_DataRenewed;
     link.Close();
     link = null;
     GC.Collect();
     label1.Text     = "Not connected";
     button1.Enabled = true;
     button2.Enabled = false;
 }
Example #5
0
        private ControllerParameter(LinkConnectionType connectionType, LinkClient client, byte[] buffer, IPEndPoint endpoint, NetworkStream stream, CancellationToken cancellationToken)
        {
            Debug.Assert(endpoint != null);
            Debug.Assert(connectionType != LinkConnectionType.Tcp || stream != null);
            this.endpoint = endpoint;

            ConnectionType    = connectionType;
            Client            = client;
            Stream            = stream;
            Packet            = new LinkPacket(client.Generator, buffer);
            CancellationToken = cancellationToken;
            SenderProfile     = client.Contracts.FindProfile(Packet.SenderId);
        }
Example #6
0
        public void Setup()
        {
            Server = new LinkServer();
            TestContractInstance = new TestContract();
            Server.RegisterContractImplementation <ITestContract, TestContract>(TestContractInstance);
            Server.Start(8080);

            // Give the server a second to fire up.
            Thread.Sleep(1000);

            Client = new LinkClient();
            Client.Setup("127.0.0.1", 8080);
            TestContract = Client.GetContract <ITestContract>();
        }
Example #7
0
        void Connect()
        {
            _Client = null;

            var uri  = new NetUri(cbAddr.Text);
            var cfg  = Setting.Current;
            var mode = cbMode.Text;

            var ac = new LinkClient(uri.ToString())
            {
                Log        = cfg.ShowLog ? XTrace.Log : Logger.Null,
                EncoderLog = cfg.ShowEncoderLog ? XTrace.Log : Logger.Null
            };

            //ac.Received += OnReceived;
            ac.UserName     = cfg.UserName;
            ac.Password     = cfg.Password;
            ac.ActionPrefix = mode;

            //ac.Encrypted = cfg.Encrypted;
            //ac.Compressed = cfg.Compressed;

            if (!ac.Open())
            {
                return;
            }

            ac.CreateCallback = sc =>
            {
                sc.Log        = cfg.ShowLog ? XTrace.Log : Logger.Null;
                sc.LogSend    = cfg.ShowSend;
                sc.LogReceive = cfg.ShowReceive;
            };

            "已连接服务器".SpeechTip();

            _Client = ac;

            pnlSetting.Enabled = false;
            pnlAction.Enabled  = true;
            btnConnect.Text    = "关闭";

            // 添加地址
            cfg.AddAddresss(uri.ToString());

            cfg.Save();

            BizLog = TextFileLog.Create("DeviceLog");
        }
Example #8
0
        void Disconnect()
        {
            if (_Client != null)
            {
                _Client.Dispose();
                _Client = null;

                "关闭连接".SpeechTip();
            }

            pnlSetting.Enabled = true;
            pnlAction.Enabled  = false;
            btnConnect.Text    = "打开";

            LoadConfig();
        }
Example #9
0
        /// <summary>
        /// 启动连接 (与 <see cref="Shutdown"/> 方法为非完全线程安全的关系, 不过两个方法不可能同时调用)
        /// </summary>
        public static async Task <Task> Start(int id, IPEndPoint endpoint)
        {
            var clt = await LinkClient.Connect(id, endpoint, _RequestHandler);

            void _OnReceived(object sender, LinkEventArgs <LinkPacket> args) => RouteModule.Invoke(args.Object);

            void _OnDisposed(object sender, LinkEventArgs <Exception> args)
            {
                clt.Received -= _OnReceived;
                clt.Disposed -= _OnDisposed;

                // 置空
                lock (s_ins._locker)
                    s_ins._client = null;
                var obj = args.Object;

                if (obj == null || obj is OperationCanceledException)
                {
                    return;
                }
                Entrance.ShowError("连接中断", obj);
            }

            clt.Received += _OnReceived;
            clt.Disposed += _OnDisposed;

            lock (s_ins._locker)
            {
                if (s_ins._client != null)
                {
                    clt.Dispose();
                    throw new InvalidOperationException();
                }
                s_ins._client = clt;
            }

            HistoryModule.Handled += _HistoryHandled;
            ShareModule.PendingList.ListChanged += _PendingListChanged;

            ProfileModule.SetId(id);

            PostModule.UserProfile(Links.Id);
            PostModule.UserRequest();
            PostModule.UserGroups();

            return(clt.Start());
        }
Example #10
0
        private void btnSend_Click(Object sender, EventArgs e)
        {
            if (_Client == null || !_Client.Active)
            {
                return;
            }

            var count = (Int32)numThreads.Value;

            if (count <= cs.Count)
            {
                return;
            }

            var uri = new NetUri(cbAddr.Text);

            Task.Run(() =>
            {
                var cc = _Client;
                for (var i = 0; i < count; i++)
                {
                    var ac = new LinkClient(uri.ToString())
                    {
                        UserName     = cc.UserName,
                        Password     = cc.Password,
                        ActionPrefix = cc.ActionPrefix
                    };

                    cs.Add(ac);

                    Task.Run(() =>
                    {
                        for (var k = 0; k < 10; k++)
                        {
                            if (ac.Open())
                            {
                                break;
                            }
                            Thread.Sleep(1000);
                        }
                    });
                }
            });
        }
Example #11
0
        public async Task ConnectionIdMultipleClients()
        {
            // The connection Id is global, so we don't have a reliable way to check if the value is correct
            // as the connection counter is shared between Server instances.
            Assert.IsNull(TestContractInstance.LatestConnectionId);
            TestContract.SimpleMethod();
            var connId = TestContractInstance.LatestConnectionId;

            Assert.IsNotNull(connId);
            using (var client = new LinkClient())
            {
                client.Setup("127.0.0.1", 8080);
                await Task.Delay(1000);

                client.GetContract <ITestContract>().SimpleMethod();
                await Task.Delay(1000);

                Assert.AreNotEqual(connId, TestContractInstance.LatestConnectionId);
            }
        }
Example #12
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            IsEnabled = false;
            var exists = File.Exists(settingsPath);
            var result = exists
                ? await Op.TryAsync(Op.UsingAsync(new StreamReader(settingsPath, Encoding.UTF8), LinkSettings.CreateAsync))
                : default;

            if (exists && result.IsError)
            {
                MessageBox.Show(result.UnwrapError().Message, "Error while loading settings", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            client = new LinkClient(result.UnwrapOrDefault() ?? LinkSettings.Create(), TaskScheduler.FromCurrentSynchronizationContext());
            if (exists == false || result.IsError)
            {
                client.Profile.Name = string.Concat(Environment.UserName, "@", Environment.MachineName);
            }

            DataContext = client.Profile;
            IsEnabled   = true;
        }
Example #13
0
        void Connect()
        {
            _Client = null;

            var uri  = new NetUri(cbAddr.Text);
            var cfg  = Setting.Current;
            var mode = cbMode.Text;

            var url = uri.ToString();
            var ac  = mode == "Device" ? new DeviceClient(url) : new LinkClient(url)
            {
                Log        = cfg.ShowLog ? XTrace.Log : Logger.Null,
                EncoderLog = cfg.ShowEncoderLog ? XTrace.Log : Logger.Null
            };

            ac.UserName     = cfg.UserName;
            ac.Password     = cfg.Password;
            ac.ActionPrefix = mode;

            if (!ac.Open())
            {
                return;
            }

            "已连接服务器".SpeechTip();

            _Client = ac;

            pnlSetting.Enabled = false;
            pnlAction.Enabled  = true;
            btnConnect.Text    = "关闭";

            // 添加地址
            cfg.AddAddresss(uri.ToString());

            cfg.Save();

            //BizLog = TextFileLog.Create("DeviceLog");
        }
Example #14
0
 public FileReceiver(LinkClient client, LinkProfile profile, NetworkStream stream, string name, long length) : base(client, profile, stream, length)
 {
     Name     = name ?? throw new ArgumentNullException(nameof(name));
     FullName = name;
 }
Example #15
0
 public DirectorySender(LinkClient client, LinkProfile profile, NetworkStream stream, string fullPath) : base(client, profile, stream)
 {
     Name     = Path.GetDirectoryName(fullPath);
     FullName = fullPath;
 }
Example #16
0
 public DirectoryReceiver(LinkClient client, LinkProfile profile, NetworkStream stream, string name) : base(client, profile, stream)
 {
     Name     = name ?? throw new ArgumentNullException(nameof(name));
     FullName = name;
 }
Example #17
0
 protected DirectoryObject(LinkClient client, LinkProfile profile, NetworkStream stream) : base(client, profile, stream)
 {
     // nothing
 }
Example #18
0
 public static ControllerParameter CreateTcpParameter(LinkClient client, byte[] buffer, IPEndPoint endpoint, NetworkStream stream, CancellationToken cancellationToken)
 {
     return(new ControllerParameter(LinkConnectionType.Tcp, client, buffer, endpoint, stream, cancellationToken));
 }
Example #19
0
 public static ControllerParameter CreateUdpParameter(LinkClient client, byte[] buffer, IPEndPoint endpoint)
 {
     return(new ControllerParameter(LinkConnectionType.Udp, client, buffer, endpoint, null, CancellationToken.None));
 }
Example #20
0
 public MessageEventArgs(LinkClient client, LinkProfile profile, Message message)
 {
     Client  = client ?? throw new ArgumentNullException(nameof(client));
     Profile = profile ?? throw new ArgumentNullException(nameof(profile));
     Message = message ?? throw new ArgumentNullException(nameof(message));
 }
Example #21
0
 public FileSender(LinkClient client, LinkProfile profile, NetworkStream stream, string fullName, long length) : base(client, profile, stream, length)
 {
     Name     = Path.GetFileName(fullName);
     FullName = fullName;
 }