Exemple #1
0
        public RClient(Uri uri, int timeOut = 3000)
        {
            if (string.IsNullOrEmpty(uri.Scheme) || string.Compare(uri.Scheme, "rpc", true) != 0)
            {
                ExceptionCollector.Add("Consumer.RClient.Init Error", new RPCSocketException("当前连接协议不正确,请使用格式rpc://ip:port"));
                return;
            }

            _timeOut = timeOut;

            _disorderSyncHelper = new DisorderSyncHelper(_timeOut);

            var ipPort = DNSHelper.GetIPPort(uri);

            _rUnpacker = new RUnpacker();

            SocketOptionBuilder builder = SocketOptionBuilder.Instance;

            var option = builder.SetSocket()
                         .UseIocp <RUnpacker>()
                         .SetIP(ipPort.Item1)
                         .SetPort(ipPort.Item2)
                         .SetReadBufferSize(10240)
                         .SetWriteBufferSize(10240)
                         .SetTimeOut(_timeOut)
                         .Build();

            _client = SocketFactory.CreateClientSocket(option);

            _client.OnReceive += OnReceived;

            _client.OnDisconnected += _client_OnDisConnected;
        }
Exemple #2
0
        public RClient(Uri uri)
        {
            if (string.IsNullOrEmpty(uri.Scheme) || string.Compare(uri.Scheme, "rpc", true) != 0)
            {
                ExceptionCollector.Add("Consumer.RClient.Init Error", new RPCSocketException("当前连接协议不正确,请使用格式rpc://ip:port"));
                return;
            }

            var ipPort = DNSHelper.GetIPPort(uri);

            _RContext = new RContext();

            SocketOptionBuilder builder = SocketOptionBuilder.Instance;

            var option = builder.SetSocket()
                         .UseIocp(_RContext)
                         .SetIP(ipPort.Item1)
                         .SetPort(ipPort.Item2)
                         .SetReadBufferSize()
                         .SetWriteBufferSize()
                         .Build();

            _client = SocketFactory.CreateClientSocket(option);

            _client.OnReceive += OnReceived;

            _client.OnDisconnected += _client_OnDisConnected;
        }
Exemple #3
0
        private void TestDocumentClientMemoryLeakPrivateNoInline(ConnectionPolicy connectionPolicy, WeakReference reference)
        {
            Uri    globalEndpointUri     = new Uri(ConfigurationManager.AppSettings["GatewayEndpoint"]);
            Uri    configurationEndPoint = DNSHelper.GetResolvedUri(ConfigurationManager.AppSettings["GatewayEndpoint"]);
            string authKey = ConfigurationManager.AppSettings["MasterKey"];

            DocumentClient client = new DocumentClient(globalEndpointUri, authKey, connectionPolicy);

            // Holding a WeakReference to client to test whether it gets garbage collected eventually
            reference.Target = client;

            // Executing any request using this client
            client.CreateDatabaseAsync(new CosmosDatabaseSettings {
                Id = Guid.NewGuid().ToString()
            }).Wait();

            // Verify that the Write and Read Endpoints point to same endpoint(since no PreferredLocations was specified)
            Assert.AreEqual(client.WriteEndpoint, configurationEndPoint);
            Assert.AreEqual(client.ReadEndpoint, configurationEndPoint);

            // Adding a preferred read location, which should trigger the event handler to update the Read and Write endpoints
            connectionPolicy.PreferredLocations.Add(ConfigurationManager.AppSettings["Location2"]);

            client.CreateDatabaseAsync(new CosmosDatabaseSettings {
                Id = Guid.NewGuid().ToString()
            }).Wait();

            // Verify that the read endpoint now changes to this new preferred location
            Assert.AreEqual(client.WriteEndpoint, configurationEndPoint);
            Assert.AreEqual(client.ReadEndpoint, configurationEndPoint);

            // Disposing the client and setting it to null to enable garbage collection
            client.Dispose();
            client = null;
        }
Exemple #4
0
        private async Task TestPreferredRegionOrderAsync()
        {
            Uri    globalEndpointUri = new Uri(ConfigurationManager.AppSettings["GatewayEndpoint"]);
            string authKey           = ConfigurationManager.AppSettings["MasterKey"];

            ConnectionPolicy connectionPolicy = new ConnectionPolicy();

            connectionPolicy.PreferredLocations.Add(ConfigurationManager.AppSettings["Location"]);  //write region
            connectionPolicy.PreferredLocations.Add(ConfigurationManager.AppSettings["Location2"]); // read region

            DocumentClient client = new DocumentClient(globalEndpointUri, authKey, connectionPolicy);

            CosmosDatabaseSettings database = await client.CreateDatabaseAsync(new CosmosDatabaseSettings { Id = Guid.NewGuid().ToString() });

            CosmosContainerSettings collection = await client.CreateDocumentCollectionAsync(database.SelfLink, new CosmosContainerSettings { Id = Guid.NewGuid().ToString() });

            // todo: SessionToken container has a bug which prevent the session consistency read. So we sleep to make sure it is replicated.
            await Task.Delay(GlobalDatabaseAccountTests.WaitDurationForAsyncReplication);

            Document document =
                await client.CreateDocumentAsync(collection.SelfLink, new Document { Id = Guid.NewGuid().ToString() });

            Assert.AreEqual(client.WriteEndpoint, DNSHelper.GetResolvedUri(ConfigurationManager.AppSettings["GatewayEndpoint"]));
            // Ensure that the ReadEndpoint gets set to whatever is the first region in PreferredLocations irrespective whether it's read or write region
            Assert.AreEqual(client.ReadEndpoint, DNSHelper.GetResolvedUri(ConfigurationManager.AppSettings["GatewayEndpoint"]));
        }
Exemple #5
0
        private bool DDNS(DNSPodClient client, string domainName, string subDomain)
        {
            if (!isLock)
            {
                isLock = true;
                Logger.Write("获取本地IP");
                var ip = DNSHelper.GetLocalIP();
                Logger.Write("本地IP为:{0},IP比对中...", ip);

                try {
                    Domain domain = client.GetDomain(domainName);
                    Record record = null;

                    try {
                        record = client.GetRecord(domain.Id.ToString(), subDomain);
                    }
                    catch (DNSPodException ex) {
                        // 如果记录不存在则创建一个
                        if (ex.Code == 22)
                        {
                            Logger.Write("主机头不存在,创建记录");
                            record = client.CreateRecord(domain.Id.ToString(), subDomain, ip);
                            client.Clear();
                            Logger.Write("已创建记录,ID为:{0}", record.Id);
                        }
                        else
                        {
                            throw ex;
                        }
                    }

                    // 如果本地IP与服务器不一样则更新
                    if (ip != record.Value)
                    {
                        Logger.Write("IP变动,刷新DNS。IP地址为:{0}", ip);
                        client.DDNS(domain.Id.ToString(), subDomain, record.Id);
                        client.Clear();
                        Logger.Write("已更换IP:{0}", ip);
                    }
                    else
                    {
                        Logger.Write("本地IP与服务器IP一致,无需更新");
                    }


                    isLock = false;
                    return(true);
                }
                catch (DNSPodException ex) {
                    Logger.Write("出错:{0}", ex.Message);
                    isLock = false;
                    return(false);
                }
            }

            return(true);
        }
Exemple #6
0
 public CreateOrder(
     IHttpContextAccessor accessor,
     AcmeContext acme,
     IAccountContext account,
     IMemoryCache cache,
     DNSHelper dnsHelper,
     ILogger <CreateOrder> logger
     ) : base(accessor)
 {
     this.acme      = acme;
     this.account   = account;
     this.cache     = cache;
     this.dnsHelper = dnsHelper;
     this.logger    = logger;
 }
Exemple #7
0
        private bool DDNS(DNSPodClient client, string domainName, string subDomain)
        {
            try {
                Domain domain = client.GetDomain(domainName);
                Record record = null;

                try {
                    record = client.GetRecord(domain.Id.ToString(), subDomain);
                }
                catch (DNSPodException ex) {
                    // 如果记录不存在则创建一个
                    if (ex.Code == 22)
                    {
                        record = client.CreateRecord(domain.Id.ToString(), subDomain, DNSHelper.GetLocalIP());
                        client.Clear();
                        Logger.Write("主机头不存在,创建记录");
                    }
                    else
                    {
                        throw ex;
                    }
                }

                // 如果本地IP与服务器不一样则更新
                var ip = DNSHelper.GetLocalIP();
                if (ip != record.Value)
                {
                    client.DDNS(domain.Id.ToString(), subDomain, record.Id);
                    client.Clear();
                    Logger.Write("IP变动,刷新DNS。IP地址为:{0}", ip);
                }
                else
                {
                    Logger.Write("本地IP与服务器IP一致,无需更新");
                }

                return(true);
            }
            catch (DNSPodException ex) {
                AppHelper.Alert(ex.Message);
                Logger.Write("出错:{0}", ex.Message);
                return(false);
            }
        }
Exemple #8
0
        public void TestGetIP()
        {
            try
            {
                string result;
                result = DNSHelper.GetIP("google.ch").ToString();
                result = DNSHelper.GetIP("asdsds.asdjuioiuo.ioiode").ToString();
                result = DNSHelper.GetIP("steuerungentfeuchter.prod.j1").ToString();
                result = DNSHelper.GetIP("iobrokerdatacollector.prod.j1").ToString();

            }

            catch (Exception ex)
            {
                Console.WriteLine("Fehler beim Testen der IP", ex);                
                //throw;
            }
            
        }
Exemple #9
0
 public SSLGenerate(AcmeContext acme, IAccountContext account, DNSHelper dnsHelper)
 {
     this.acme      = acme;
     this.account   = account;
     this.dnsHelper = dnsHelper;
 }
Exemple #10
0
        public void ChangeServer(string ipOrDomain, string tcp, string udp)
        {
            string ip = Regex.Match(ipOrDomain, @"^[a-zA-Z0-9]+([a-zA-Z0-9\-\.]+)?\.$").Success ? DNSHelper.ParseIPFromDomain(ipOrDomain) : ipOrDomain;

            CurrentServer = new IPPort {
                IP = ip, TcpPort = tcp, UdpPort = udp
            };
        }