コード例 #1
0
        /// <summary>
        /// 新建一个连接
        /// </summary>
        /// <param name="item">连接配置</param>
        /// <returns>连接</returns>
        private static ISuperGMSRpcClient Register(ClientItem item)
        {
            try
            {
                ISuperGMSRpcClient client = null;
                switch (item.ServerType)
                {
                case ServerType.Thrift:
                    client = new ThriftClient(item);
                    break;

                case ServerType.HttpWebApi:
                    client = new WebApiClient(item);
                    break;

                default:
                    throw new Exception($"ClientConnectionManager.Register(), ClientItem.ServerType:'{item.ServerType}' is invalid");
                }
                return(client);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"ClientConnectionManager.register.Error,ServerInfo={item.ToString()}");
                return(null);
            }
        }
コード例 #2
0
ファイル: Global.asax.cs プロジェクト: fjwgrace/MLRMS
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            //连接SDK
            try
            {
                ECProcess.ECIPaddress   = ConfigurationManager.AppSettings["eyecloudServerIP"];
                ECProcess.ECPort        = int.Parse(ConfigurationManager.AppSettings["eyecloudServerPort"]);
                FtpHelper.VideoFtpURL   = ConfigurationManager.AppSettings["videoFtpBase"];
                FtpHelper.PackageFtpURL = ConfigurationManager.AppSettings["packageFtpBase"];
                FtpHelper.NeedUpToEC    = bool.Parse(ConfigurationManager.AppSettings["needUpToEC"]);

                //替换默认的JSON序列化器
                HttpConfiguration fConfig = GlobalConfiguration.Configuration;
                fConfig.Formatters.Remove(fConfig.Formatters.JsonFormatter);
                fConfig.Formatters.Insert(0, new JilFormatter());
                //TokenHelper.InitStatus();  //状态初始化
                //GlobalInfo.InitTask();     //初始化还未下发的任务列表

                _client = new ThriftClient(); //初始化Thrift连接
                LogHelper.Info("网站启动:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            }
            catch (Exception ex)
            {
                LogHelper.Error("获取EyeCloud Server配置信息失败", ex);
            }
        }
コード例 #3
0
        private static void Main()
        {
            var client = new ThriftClient();

            client.RunAsync();

            const int requestCount = 1000;

            var elapsed   = Enumerable.Repeat(Int64.MaxValue, requestCount).ToArray();
            var stopwatch = new Stopwatch();

            Action <TProtocol> request = null;

            request = (input) =>
            {
                stopwatch.Restart();
                input.WriteString("Hello, world!");
                input.Transport.Flush();
            };

            Action <TProtocol, Exception, int> response = null;

            response = (output, exception, n) =>
            {
                elapsed[n - 1] = stopwatch.ElapsedMilliseconds;

                if (exception != null)
                {
                    throw exception;
                }

                output.ReadString();

                if (n < requestCount)
                {
                    client.Send(i => request(i), (o, e) => response(o, e, n + 1));
                }
                else
                {
                    output.Transport.Close();
                }
            };

            client.Send((i) => request(i), (o, e) => response(o, e, 1));

            Thread.Sleep(3000);

            var elapsedAscending = elapsed.OrderBy(x => x).ToArray();

            Console.WriteLine("Count {0}", requestCount);
            Console.WriteLine("20% {0}", elapsedAscending[(int)(requestCount * .2)]);
            Console.WriteLine("50% {0}", elapsedAscending[(int)(requestCount * .5)]);
            Console.WriteLine("85% {0}", elapsedAscending[(int)(requestCount * .85)]);
            Console.WriteLine("95% {0}", elapsedAscending[(int)(requestCount * .95)]);
            Console.WriteLine("99% {0}", elapsedAscending[(int)(requestCount * .99)]);

            client.Stop();
        }
コード例 #4
0
        public void CarWashConsumer()
        {
            string defaultDeviceName        = Environment.MachineName;
            string defaultDeviceDescription =
                $".net wrapper unit test.  Class: {this.GetType().Name}.  Method: {System.Reflection.MethodBase.GetCurrentMethod().Name}";

            ThriftClient.SetupDevice(defaultDeviceName, defaultDeviceDescription);
            foreach (ServiceMessage service in ThriftClient.DeviceDiscovery(20000))
            {
                Log.InfoFormat("Found service: ", service);
            }
        }
コード例 #5
0
        public T CreateScribeClient <T>(
            ThriftClientManager manager, ScopedServer server, TProtocolFactory protocolFactory)
            where T : class
        {
            ThriftClientConfig config = new ThriftClientConfig();

            config.ConnectTimeout = TimeSpan.FromSeconds(600);
            config.ReceiveTimeout = TimeSpan.FromSeconds(600);
            config.ReadTimeout    = TimeSpan.FromSeconds(600);
            config.WriteTimeout   = TimeSpan.FromSeconds(600);

            var thriftClient = new ThriftClient(manager, typeof(T), config, typeof(T).Name);

            return(thriftClient.OpenAsync(
                       new FramedClientConnector("localhost", server.Port, protocolFactory))
                   .GetAwaiter().GetResult() as T);
        }
コード例 #6
0
        public void SendSimpleMessage()
        {
            ThriftClient.SetupDevice("DotNet RPC client", "This is coming from C# via Thrift RPC.");
            Log.Info("Initialising Producer");
            ThriftClient.InitProducer("cl_key", "srv_key");
            ThriftClient.StartServiceBroadcast(2000);
            var svcMsgs = ThriftClient.DeviceDiscovery(2000);

            if (svcMsgs != null)
            {
                foreach (ServiceMessage svcMsg in svcMsgs)
                {
                    Log.InfoFormat("{0} - {1} - {2} - {3}", svcMsg.DeviceDescription, svcMsg.Hostname, svcMsg.PortNumber,
                                   svcMsg.ServerId);
                }
            }
            else
            {
                Log.Info("Broadcast ok, but no services found");
            }
            Log.Info("All done, closing transport");
        }
コード例 #7
0
 public void DisposeClient()
 {
     ThriftClient.Dispose();
 }
コード例 #8
0
    // Use this for initialization
    void Start()
    {
        using (ThriftClient clientService = new ThriftClient("User.v1"))
        {
            User.Client client   = (User.Client)clientService.GetClient();
            UserModel   user     = null;
            string      username = "******";
            string      password = "******";
            bool        success  = client.login(username, password);
            if (success)
            {
                Debug.Log("Login Success!");
            }
            else
            {
                Debug.Log("Login failed!");
                Debug.Log("Trying to create user");
                // try to create and login
                user = client.create(username, password);
                if (user.User_id != 0)
                {
                    Debug.Log("Created user!");
                    Debug.Log(user.ToString());
                    Debug.Log("Trying a login now.");
                    success = client.login(user.Username, user.Password);
                    if (success)
                    {
                        Debug.Log("Login succeeded!");
                    }
                    else
                    {
                        Debug.Log("login failed!");
                    }
                }
                else
                {
                    Debug.Log("User creation failed!");
                }
            }

            user = client.get(username);
            if (user.User_id != 0)
            {
                Debug.Log("Got user from client:");
                Debug.Log(user.ToString());

                bool removed = client.remove(user.User_id);
                if (removed)
                {
                    Debug.Log("Successfully removed user with id: " + user.User_id);
                }
                else
                {
                    Debug.Log("Failed to remove user!");
                }
            }
            else
            {
                Debug.Log("Failed to get user with username: " + username);
            }
        }
    }